Fix qtables and quality scaling by Kyliroco · Pull Request #8879 · python-pillow/Pillow
added 2 commits
April 10, 2025 07:31When both `qtables` and `quality` are provided, Pillow previously passed the raw `quality` value directly to `jpeg_add_quant_table()` as the scale factor, which caused incorrect quantization. This commit corrects the behavior by using `jpeg_quality_scaling(quality)` to compute the proper JPEG quantization scaling factor, consistent with `jpeg_set_quality()`. This ensures expected compression behavior when custom qtables are used alongside a specified quality level.
When both a custom quantization table and a quality value are provided, the quantization table should be scaled using the JPEG quality scaling factor. If quality is not explicitly set, the default base quality of 50 is used to preserve the original table. This ensures consistent behavior when saving JPEGs with custom qtables. Fixes part of the issue with applying 'quality' to 'qtables'.
radarhere
changed the title
Fix-qtables-and-quality-scaling
Fix qtables and quality scaling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters