cgohlke / imagecodecs

Image transformation, compression, and decompression codecs
https://pypi.org/project/imagecodecs
BSD 3-Clause "New" or "Revised" License
111 stars 21 forks source link

Cannot set JPEGXL effort lower than 3 in `jpegxl_encode`? #91

Closed duncanterray closed 6 months ago

duncanterray commented 6 months ago

Hi there!

I have been experimenting with jpegxl for lossless encoding, and noticed that setting the effort level below 3 does not seem to change the file size or time required to compress the image.

It looks like the effort is clamped between 3 and 9 with _default_value() here https://github.com/cgohlke/imagecodecs/blob/2ddadafd413c8b035b8f6339e8ea603bb416f011/imagecodecs/_jpegxl.pyx#L186

libjpxl does detail different techniques used for lossless encoding, though levels below 3 are not supported for lossy encoding.

Effort Modular (lossless) VarDCT (lossy)
e1 fast-lossless, fixed YCoCg RCT, fixed ClampedGradient predictor, simple palette detection, no MA tree (one context for everything), Huffman, simple rle-only lz77
e2 global channel palette, fixed MA tree (context based on Gradient-error), ANS, otherwise same as e1
e3 same as e2 but fixed Weighted predictor and fixed MA tree with context based on WP-error only 8x8, basically XYB jpeg with ANS

Would it make sense to clamp to different effort ranges depending on the lossless encoding flag?

cgohlke commented 6 months ago

You are right, the effort should be clamped between 1 and 10. It'll be in the next release.

duncanterray commented 6 months ago

Thanks for looking into it! I'll keep an eye out for the next release.