From b3bceeefd41d45662bf342a834a5163cb07fae51 Mon Sep 17 00:00:00 2001 From: Oliver Schinagl Date: Tue, 5 Apr 2005 16:09:50 +0000 Subject: BMP file is opened and header is readed en the file is written in Image1 array --- src/main.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index 7e260da..39d5bfc 100644 --- a/src/main.c +++ b/src/main.c @@ -3,25 +3,76 @@ #define ENCODE 0 #define DECODE 1 +#define MAXROWS 1024 +#define MAXCOLS 768 -int main(int argc, char argv[]) { - int retval; +unsigned char Image1[MAXCOLS*3*MAXROWS]; + +int main(int argc, char *argv[]) { + int retval, i; int workspace[DCTSIZE_BLOCK]; int type; + int x, y, offset, depth; + char *fileIn, *fileOut; FILE *fI, *fO; + unsigned char ch, mrgb[3]; + +/* Just for testing on the PC */ + if(argc != 4) + { + printf("need more arguments"); + return 0; + } + type = atoi(argv[1]); + fileIn = argv[2]; + fileOut = argv[3]; - fI = fopen(fileIn,"rb"); - if (fI == NULL) { - printf("unable to open the file",fileIn); - return 0; - } - fO = fopen(fileOut,"wb"); - if (fO == NULL) { - printf("unable to open the file",fileOut); - return 0; - } + if (NULL == (fI = fopen(fileIn, "rb"))){ + printf("unable to open the file to read from (%s)",fileIn); + return 0; + } + if ((fO = fopen(fileOut,"wb")) == NULL) { + printf("unable to open the file to write (%s)",fileOut); + return 0; + } + + switch(type) { + case ENCODE: + fseek(fI, 10L, SEEK_SET); + fread(mrgb, 1, 4, fI); + offset = mrgb[3]; + offset <<= 8; + offset += mrgb[2]; + offset <<= 8; + offset += mrgb[1]; + offset <<= 8; + offset += mrgb[0]; + + + fseek(fI, 18L, SEEK_SET); + fread(mrgb, 1, 4, fI); + x = ((int)mrgb[3] << 24) + ((int)mrgb[2] << 16) + ((int)mrgb[1] << 8) + mrgb[0]; + fseek(fI, 22L, SEEK_SET); + fread(mrgb, 1, 4, fI); + y = ((int)mrgb[3] << 24) + ((int)mrgb[2] << 16) + ((int)mrgb[1] << 8) + mrgb[0]; + fseek(fI, 28L, SEEK_SET); + fread(mrgb, 1, 2, fI); + depth = ((int)mrgb[1] << 8) + mrgb[0]; + + printf("Image Resolution: %d x %d x %i \n", x, y, depth); + + fseek(fI, offset, SEEK_SET); + + fread(Image1, sizeof(unsigned char), (x*y*(depth/3)), fI); + + break; + case DECODE: + + break; + } +/* End for just for testing on the PC */ retval = 0; -- cgit v0.12