Photoshop JPEG files (Quantization Tables)

TB
Posted By
Tim_Bate
Oct 30, 2007
Views
1741
Replies
3
Status
Closed
Hi. If anyone knows about the JPEG standard, perhaps you can help me.

I noticed that when Photoshop saves JPEG files in the baseline standard, it will include Quantization tables starting with FF DB 00 84 00. To me, this seems incorrect. FF DB declares that a quantization table is about to follow, 00 84 declares that it will be 131 bytes – which is correct for a 16 bit precision quantization table. The following byte, 00, is required to be 00 by the standard, section B.2.4.1. However, I cannot see how an 8-bit greyscale baseline JPEG can be using 16 bit precision quantization tables!

All in all, there were 3 tables, 2 were 16 bit precision. The image was the standard 512×512 greyscale (green channel) Lena. I saved as Quality ‘9’, using Photoshop CS (version 8.0).

If anyone can explain, or has an idea of another place I can ask, I would be really very grateful!

Thanks in advance,
Tim

(referance is the INFORMATION TECHNOLOGY – DIGITAL COMPRESSION AND CODING OF CONTINUOUS-TONE STILL IMAGES – REQUIREMENTS AND GUIDELINES, ITU-CCITT Recommendation T.81)

How to Master Sharpening in Photoshop

Give your photos a professional finish with sharpening in Photoshop. Learn to enhance details, create contrast, and prepare your images for print, web, and social media.

MD
Michael_D_Sullivan
Oct 30, 2007
You made one error, which turns out to be critical: 00 84 represents a length of 132 bytes, not 131.

As shown below, the length would be 131 for a DQT segment containing a 16-bit table. However, the length would be 132 for a DQT segment containing two 8-bit tables. This appears to be what you are seeing.

A DQT segment is not limited to containing a single quantization table. At the bottom of Figure B.6 is a curved line showing the table data representation; the notation below that says, "Multiple (t = 1, …, n)." Likewise, below Table B.4 is the notation, "The value n in Table B.4 is the number of quantization tables specified in the DQT marker segment."

If Pq (precision) is 0, that means 8 bit precision, consistent with the baseline standard. The formula for Lq (length of the table data) evaluates to 2 + (65 + 64 * 0) + (65 + 64 * 0) = 132. If there were a single 16-bit table in the segment (non-baseline), Pq would have a value of 1, and the formula for Lq would evaluate to 2 + (65 + 64 * 1) = 131. In each case, this represents the total number of bytes needed to hold 64 entries (whether 8 or 16 bytes) plus 1 byte to contain both Pq and Tq, plus 2 bytes to hold the length Lq.

As a result, it would seem that your JPEG baseline file actually contains five quantization tables. Since there are only four destinations for quantization tables, at least one of these is a replacement of a prior table for a certain segment of the scan. Tq (the second 4 bits of the 00 byte preceding the table data) will tell you which destination: 0, 1, 2, or 3. Since two of your DQT segments contain two tables, you will have to look in the middle to find this for the second table in each.

I used the 09/92 edition of the T.81 standard, available free here <http://eu.sabotage.org/www/ITU/T/T0081e.pdf>. I doubt the figure, table, and section numbers have changed much in other editions.

I hope this is helpful.
TB
Tim_Bate
Oct 31, 2007
Thanks! Your reply really helps. No idea how I made that mistake, except maybe miscounting the bytes with the rubbish at the start.

Now I just need to figure out why an 8bit greyscale image needs 5 quantization tables, 3 of which (at least) were assigned to table 0!

Oh, and I’m using the same version of the T.81.

Cheers again!
MD
Michael_D_Sullivan
Oct 31, 2007
Standards documents are hell to work your way through.

I suspect you image needs so many quantization tables because you saved it at quality level 9 (of 12). If you saved it at quality level 1 it probably would have used a single table for the entire image and produced a much smaller file. By using more tables, including multiple tables for the same "destination", the JPEG can have much better quality representation of the image and fewer artifacts.

It would be interesting to see how the file changes as different quality levels are used to create it.

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

Related Discussion Topics

Nice and short text about related topics in discussion sections