Parent document is top of "JPEG image compression FAQ, part 1/2"
Previous document is "[12] Can I make a transparent JPEG?"
Next document is "[14] Why all the argument about file formats?"

[13] Isn't there a lossless JPEG?

There's a great deal of confusion on this subject, which is not surprising
because there are several different compression methods all known as "JPEG".
The commonly used method is "baseline JPEG" (or its variant "progressive
JPEG").  The same ISO standard also defines a very different method called
"lossless JPEG".  And if that's not confusing enough, a new lossless
standard called "JPEG-LS" is about to hit the streets.

When I say "lossless", I mean mathematically lossless: a lossless
compression algorithm is one that guarantees its decompressed output is
bit-for-bit identical to the original input.  This is much stronger than
"visually indistinguishable from the original".  Baseline JPEG can reach
visual indistinguishability for most images, but it can never be truly
lossless.

Lossless JPEG is a completely different method that really is lossless.
However, it doesn't compress nearly as well as baseline JPEG; it typically
can compress full-color data by around 2:1.  And lossless JPEG works well
only on continuous-tone images.  It does not provide useful compression of
palette-color images or low-bit-depth images.

Lossless JPEG has never been popular --- in fact, no common applications
support it --- and it is now largely obsolete.  (For example, the new PNG
standard outcompresses lossless JPEG on most images.)  Recognizing this,
the ISO JPEG committee recently finished an all-new lossless compression
standard called JPEG-LS (you may have also heard of it under the name LOCO).
JPEG-LS gives better compression than original lossless JPEG, but still
nowhere near what you can get with a lossy method.  It's anybody's guess
whether this new standard will achieve any popularity.

It's worth repeating that cranking a regular JPEG implementation up to its
maximum quality setting *does not* get you lossless storage; even at the
highest possible quality setting, baseline JPEG is lossy because it is
subject to roundoff errors in various calculations.  Roundoff errors alone
are nearly always too small to be seen, but they will accumulate if you put
the image through multiple cycles of compression (see section 10).

Many implementations won't even let you get to the maximum possible setting,
because it's such an inefficient way to use regular JPEG.  With the IJG JPEG
software, for example, you have to not only select "quality 100" but also
turn off chroma downsampling to prevent all deliberate loss of information.
The resulting files are far larger and of only fractionally better quality
than files generated at more reasonable settings.  And they're still
slightly lossy!  If you really need lossless storage, don't try to
approximate it with regular JPEG.

Parent document is top of "JPEG image compression FAQ, part 1/2"
Previous document is "[12] Can I make a transparent JPEG?"
Next document is "[14] Why all the argument about file formats?"