Search code examples
compressionlossless-compression

Does JPEG allow lossless encoding?


As far as I know, a modern JPEG decoder produces the same image when given the same input JPEG file.

Normally, we create JPEG files in such a way that the decoded image is an approximation of some input image.

Is the JPEG format flexible enough to allow lossless encoding of arbitrary input images with a custom encoder?

I'd image you'd at least have to fiddle with how quantization tables are used to essentially disable them? Perhaps something else?

(To be clear, I don't mean the special 'lossless' mode in JPEG that many decoders don't support. I am talking about using the default, mainstream code path through the decoder.)


Solution

  • No. Even with no quantization, the RGB to YCbCr transformation is lossy in the low few bits. Also the chroma channels are then downsampled, but that step can be skipped. While the DCT is mathematically lossless, in reality it is lossy in the least significant bit or two in the integer representation.