google / brunsli

Practical JPEG Repacker
MIT License
738 stars 51 forks source link

Mode without preserving structure of the original JPEG file #80

Open vrubleg opened 4 years ago

vrubleg commented 4 years ago

As far as I can see, JXL created by Brunsli can be extracted exactly to the same (byte-by-byte) JPEG file. Could compression ratio be a bit better if we recompress just JPEG image data losslessly, without storing additional information how original JPEG was encoded?

eustas commented 4 years ago

Yes, that is also possible: just carefully retouch JPEGData object after ReadJpeg, but before BrunsliEncodeJpeg. Later we will provide utility function that will do exactly that.

vrubleg commented 4 years ago

If this additional information is removed, will it be possible to convert this image data back to JPEG without losing quality? It is clear that the JPEG data will be encoded in some different way in this case, and the JPEG file won't be equal to the original JPEG, but it is OK until the image data is still the same.

eustas commented 4 years ago

There are 2 parts (modulo ICC profiles) that contain the complete information about image (pixels) - DCT coefficients and quantisation table. Everything else (Huffman tables, scan scheme, reset points) are details of encoding. So if we drop / replace those and serialise JPEG we will get different file, but same image.