Fix qtables and quality scaling by Kyliroco · Pull Request #8879 · python-pillow/Pillow

added 2 commits

April 10, 2025 07:31
When 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 radarhere changed the title Fix-qtables-and-quality-scaling Fix qtables and quality scaling

Apr 10, 2025
…equivalent to specifying only a quality

@pre-commit-ci

@Kyliroco

…en giving a quality and a qantization table

@pre-commit-ci

@Kyliroco

@pre-commit-ci

@Kyliroco

@Kyliroco

@radarhere

@radarhere

@radarhere