/* getqtbl.c Get the quantization table from a jpeg file and write it to a data file */ #include #include #include "jpeglib.h" int main(int argc, char *argv[]) { /* variable declaration */ register int i, j; FILE *JpgFile; /* jpeg image file */ FILE *QuanTableFile; /* quantization table file */ struct jpeg_decompress_struct dinfo; /* jpeg decompression object */ struct jpeg_error_mgr jerr; /* jpeg error object */ /* parse the command line */ if (argc!=3) { fprintf(stderr, "Wrong number of command line arguments!\n"); fprintf(stderr, "Usage: getqtbl jpeg_file quant_table_file\n"); exit(1); } else { if ( !(JpgFile=fopen(argv[1], "rb")) ) { fprintf(stderr, "Can't open input jpeg file!\n"); exit(1); } if ( !(QuanTableFile=fopen(argv[2], "wb")) ) { fprintf(stderr, "Can't open output quantization table file!\n"); exit(1); } } /* allocate and initializing jpeg decompression object */ dinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&dinfo); /* specify data input source and read the header */ jpeg_stdio_src(&dinfo, JpgFile); jpeg_read_header(&dinfo, TRUE); /* get the quantization table and write to a file */ for (i=0;iquantval[i], QuanTableFile); /* destory the jpeg object */ jpeg_destroy_decompress(&dinfo); /* close all the files */ fclose(JpgFile); fclose(QuanTableFile); }