Make .quantize(palette=...) use exact colors when possible, and improve dithering quality - #9829
Make .quantize(palette=...) use exact colors when possible, and improve dithering quality#9829akx wants to merge 11 commits into
.quantize(palette=...) use exact colors when possible, and improve dithering quality#9829Conversation
7708c8a to
3eb5509
Compare
Merging this PR will degrade performance by 7.15%
|
3fd1f54 to
7fa4a06
Compare
|
I think we'll have to accept some performance degradation in exchange for actually making conversions accurate... |
| /* The c array now contains the closest match for each | ||
| * cache slot in the box. Update the cache. */ |
There was a problem hiding this comment.
| /* The c array now contains the closest match for each | |
| * cache slot in the box. Update the cache. */ | |
| /* The C array now contains the closest match for each | |
| * cache slot in the box. Update the cache. */ |
There was a problem hiding this comment.
This is also from 2006 and was just moved over to this file...
This affects `.quantize(palette=...)`. Refs python-pillow#1852
They were used nowhere else. Keeping them together, as a private API, allows for future improvements to the palette cache's shape.
This is a cherry-pick of python-pillow#9338, applied on top of the changes in this branch. Co-authored-by: Aarni Koskela <akx@iki.fi> Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
.quantize(palette=...) use exact colors when possible.quantize(palette=...) use exact colors when possible, and improve dithering quality
Refs #1852 (fixes the reproducer bug: we now select exact colors when available, but we're still not necessarily selecting the mathematically nearest color when quantizing to a given palette).
topalette()conversion function to a separate file for ease of understandingtopalette()function to multiple functions for less nesting and ease of reading... and then the main thing:
ImagingPaletteCache*functions are made private, since the structure of the cache was undocumented and private anyway; we need to add a new flag in the cache entries to have a better guess of when we might have an exact match for a color.EDIT: this now also includes the changes from #9338 as the last commit, since that touches the same files as this jiggles around.