Originally Posted by
revi
I never denied that re-encoding a jpeg several times causes quality loss.
My problem with the way you stated the case was that it went too far towards "TIFF is the only good format, and JPEG is rubbish",
and some parts were phrased in a way that could very well be misunderstood, notably anything concerning block size and changes to same,
and in a lesser degree the changes that happen during editing.
From the information I have, TIFF isn't always the best format to use, and JPEG is very useful when employed properly.
You might have noticed that I actually suggest not using JPEG as an intermediate format.
Now I'll have to get technical, as well.
First off (to get that out of the way), the part that really causes image degradation is the DCT (Discrete Cosine Transform) with quantization.
The YUV↔RGB conversions can also cause some degradation, but this will be (mostly) independent of quality settings, and hopefully negligable.
The entropy and Hufman compressions are both lossless, so can be ignored when looking at image quality.
Now, the DCT is a form of Fourier transform. One of the characteristics of any Fourier transform is that it doesn't like any kind of discontinuity in the data (a.ka. sharp edges),
and shows what's called 'ringing' around any sharp edge. (That's what you see when storing any kind of line image as JPEG, and no need for colour, B/W shows it quite well.)
But, to completely describe our data after a DCT we would need as many coefficients as we have data points.
Well, the whole point of using the DCT in the first place is that we want to get rid of some of the coefficients, and we discard the high-frequency ones
(the least important ones, and otherwise the next entropy encoding step won't work well). That means we will introduce edges when we restore the image. So any re-encoding
will add to the degradation, and this error will actually not tend to zero.
So I guess we agree that repeated JPEG encoding is bad, we just disagree on how bad exactly.
Now, as to why the quality setting of 100% increases file size. That's mostly due to the fact we actually have to add data to the file to allow decoding.
There's three steps that affect JPEG compression:
- DCT transform and quantization (i.e. deciding which coefficients we keep)
- entropy encoding: this replaces the stretches of zero values we got after quantization by a count of the zero values
- Huffman encoding: replaces repeated stretches of bytes with a shorter code. Huffman encoding of image data typically doesn't work well
(a few % reduction in size), here it works as we have structured data after the entropy encoding. But it produces a table needed for decoding that needs
to be stored with the data
As there are different programs (or rather libraries) to decode JPEGs, the quantisation tables will also need to be stored with the data.
So, if we use a 100% quality setting, we do no discard any DCT coefficients. Therefore, we don't have any repeated stretches of zeros for our entropy encoding,
and no reduction in data size. We actually might have to add data to indicate the that the odd zero value we find is a single zero. Also, the Huffman encoding has
no repetitive structure to work on (and can't reduce the data), but will still produce its decoding tables.
So, at a 100% quality, we can't reduce the volume of the interesting data, but we still have to add our bookkeeping information => the file after compression is larger.