Add support for 16-bit precision JPEG quantization values#4918
Add support for 16-bit precision JPEG quantization values#4918hugovk merged 6 commits intopython-pillow:masterfrom gofr:4825-jpeg-16-bit-qt
Conversation
|
Do you think Pillow needs its own These 16-bit precision quantization values are apparently something you'd normally only get in low quality JPEGs, and they are optional in the standard according to https://github.com/libjpeg-turbo/libjpeg-turbo/blob/6d8caa9f88184ad1698e91c94b37acb9506dacf0/usage.txt#L123 so some decoders may not support them. Even with libjpeg (and Pillow) will emit the JTRC_16BIT_TABLES warning ("Caution: quantization tables are too coarse for baseline JPEG") when the only thing that prevents a JPEG from being "baseline" is the 16-bit quantization values. |
|
Are you able to add tests that fail without your changes and pass with them? |
Don't force JPEG quantization to be baseline-compatible Quantization values will not be limited to values 1..255 and may be 16 bits if needed. This may cause compatibility issues.
16-bit quantization tables can appear at quality values below about 25. These may cause compatibility problems. Maintain baseline compatibility and avoid confusing users with warning messages.
|
I can add tests... |
|
I've made one change to my earlier implementation. When using the
So my fix will only create 16-bit values if you specify your own tables or if you use I also ran into #4962 while writing the tests. I can fix that one too if you agree that it needs fixing. |
This only adds the support on the Python side. This won't really do anything without further changes to forward this to the C code.
This is a partial fix for #4825.
I've changed the
TRUEtoFALSEinPillow/src/libImaging/JpegEncode.c
Line 164 in 2e029d9
To fully address the issue I guess the
qtablesproperty of theJPEGENCODERSTATEneeds to be expanded to include the precision info so we can tell the encoder which format to use.