2004.05.28 06:26 "[Tiff] Tiff JPEG compression quality factor", by Albert Adell

2004.06.01 18:04 "RE: [Tiff] Tiff JPEG compression quality factor", by Phillip Crews


I haven't used the equation directly with JPEG-compressed TIFF files, only with JPEG files directly.

From looking at tif_jpeg.c and the JPEG code, I *think* what you'll see in the buffer returned using TIFFTAG_JPEGTABLES is:

SOI (0xff, 0xd8), DQT (0xff, 0xdb), (2 byte length of quant table+3), (table number & precision, 0x00 or 0x10), table data in zig-zag order, each value as a 16-bit word in network byte order if the previous byte & 0x10 is true, or 8-bit bytes if the previous byte & 0x10 is false.

It may be simplest to use libjpeg to parse the tables from the JPEGTABLES return data. This will parse the JPEG markers and return the table in natural (rather than zig-zag) order, something like this:

void *buf;
unsigned short len;
jpeg_decompress_struct cinfo = {0};
jpeg_source_mgr src;

TIFFVGetField(tif, TIFFTAG_JPEGTABLES, &len, &buf);
cinfo.src = &src;

/* Set up the libjpeg source manager to read from buffer
    (crib code from TIF_JPEG.c) */

jpeg_read_header(&cinfo, FALSE);

At this point, cinfo.quant_table_ptrs should work for the code I provided.

Don't forget to jpeg_destroy_decompres(&cinfo) when you're done.

I'm sorry I don't have time to provide actual working code today. I hope this helps. ¡Buena suerte!

Kind regards,