#include #include #include "morecfg.h" #include "jpeglib.h" #include "dct.h" #include "bmpjpeg.h" #include "bmp.h" #include "jpeg.h" #define ENCODE 0 #define DECODE 1 #define MAXROWS 1200 #define MAXCOLS 800 #define HEADER 54 unsigned char Image1[MAXCOLS*3*MAXROWS+HEADER]; unsigned char Image2[MAXCOLS*3*MAXROWS+HEADER]; JQUANT_TBL qtbl; unsigned char quan_data[64] = { 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51, 52, 50 }; int main(int argc, char *argv[]) { int retval, i,j; unsigned char blok8x8_2[64]; int blok8x8[64]; unsigned char type; unsigned int x_size, y_size, offset; unsigned char depth; char *fileIn, *fileOut; FILE *fI, *fO; memcpy(quan_data, qtbl.quantval, (size_t)64 * sizeof(UINT16)); qtbl.sent_table = FALSE; /*******************************************************************************************/ /* Just for testing on the PC */ if(argc != 4) { printf("need more arguments, 0|1 for de/encrypt and 2 more for the in/ouput files"); return 0; } type = atoi(argv[1]); fileIn = argv[2]; fileOut = argv[3]; 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; } /* Read the max possible size to the memory */ fread(Image1, sizeof(unsigned char), (MAXROWS*MAXCOLS*3+HEADER), fI); /*******************************************************************************************/ /* The image must be in the memory by now */ switch(type) { case ENCODE: GetBMPHeaderInfo (Image1,&offset,&x_size,&y_size,&depth); printf("Image Resolution: %d x %d x %i Offset: %i\n", x_size, y_size, depth, offset); for(i=0;i YUV & Convert to 8x8 BMPto8x8AndYCbCr(i,j,x_size,y_size,offset,Image1,blok8x8); /****************************************/ /********* Forward *********/ /****************************************/ jpeg_fdct_ifast(blok8x8,quan_data); /****************************************/ /********* Back *********/ /****************************************/ // Dequantization and IDCT of the blok dequanize_data_IDCT(blok8x8,quan_data,blok8x8_2); YCbCrAnd8x8toBMP(i,j,x_size,y_size,offset,Image2,blok8x8_2); } } WriteBMPHeaderInfo(Image2,offset,x_size,y_size, depth); break; case DECODE: GetJPEGHeaderInfo (Image1,&offset,&x_size,&y_size,&depth); for(i=0;i RGB & Convert 8x8 to BMP style & YCbCrAnd8x8toBMP(i,j,x_size,y_size,offset,Image2,blok8x8_2); } } WriteBMPHeaderInfo(Image2,offset,x_size,y_size, depth); break; } //Write Image to the output file. fwrite(Image2, sizeof(unsigned char), (x_size*y_size*(depth/8))+offset, fO); fclose(fI); fclose(fO); return retval; }