#include #include "dct.h" #include "bmpjpeg.h" #include "bmp.h" #include "jpeg.h" #define ENCODE 0 #define DECODE 1 #define MAXROWS 1024 #define MAXCOLS 768 #define HEADER 54 unsigned char Image1[MAXCOLS*3*MAXROWS+HEADER]; /*------------------------------------------*/ /* some constants for on-the-fly IQ and IZZ */ /*------------------------------------------*/ static const int G_ZZ[] = { 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 }; int main(int argc, char *argv[]) { int retval, i; int workspace[DCTSIZE_BLOCK]; unsigned char blok8x8[64*3]; unsigned char type; unsigned int x_size, y_size, offset; unsigned char depth; char *fileIn, *fileOut; FILE *fI, *fO; /*******************************************************************************************/ /* 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 */ // retval = 0; 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); // RGB -> YUV ---> done // Convert to 8x8 --> done //BMPto8x8AndYCbCr(0,0,x_size,y_size,offset,depth,Image1,blok8x8); // DCT fdct(workspace); // ZZ // Q // VLC (huffman) break; case DECODE: GetJPEGHeaderInfo (Image1,&offset,&x_size,&y_size,&depth); // VLD (huffman) // IQ // ZZ // IDCT //idct(workspace); // Convert 8x8 to BMP style -> done // YUV -> RGB // YCbCrAnd8x8toBMP() // WriteBMPHeaderInfo(Image1,offset,x_size,y_size, depth); break; } printf("Before:"); for(i=0;i<(x_size*y_size*3);i++) { if((i%24)==0) printf("\n"); printf("%02x ",Image1[i+offset]); } printf("\nBMPto8x8 functie\n"); BMPto8x8AndYCbCr(0,0,x_size,y_size,offset,depth,Image1,blok8x8); printf("\n8x8 Blok:\n"); for(i=0;i<64;i++) { printf("%02x",blok8x8[i]); } for(i=0;i<(x_size*y_size*3);i++) { Image1[i+offset] = 0; } printf("\n8x8toBMP functie\n"); YCbCrAnd8x8toBMP(0,0,x_size,y_size,offset,depth,Image1,blok8x8); printf("\nAfter:\n"); for(i=0;i<(x_size*y_size*3);i++) { if((i%24)==0) printf("\n"); printf("%02x ",Image1[i+offset]); } //Write Image to the output file. fwrite(Image1, sizeof(unsigned char), (x_size*y_size*(depth/8))+offset, fO); fclose(fI); fclose(fO); return retval; }