Repository navigation
Conversation
Assisted-by: OpenAI Codex
This seems like a problem to me. If there are two similar colours in the original image, but one has transparency, I think making them both have transparency after applying One alternative could be to raise an error if there is transparency. I don't think Pillow is behaving perfectly in this scenario, but I'd like to hear from someone who is actually using this functionality before making a decision. It also seems like you would take issues with |
|
Thanks for pointing out the color collision. If an opaque pixel and a transparent pixel map to the same posterized color, updating the color key would make both pixels transparent. Returning RGBA could preserve the per-pixel alpha, but it would change the output mode callers receive. |
Changes proposed in this pull request:
LandRGBimages. Before this change the pixels changed, but the key still held the original color.ImageOps.invert()(Update 1, L and RGB info transparency when inverting images #10722), preserving palette-based transparency and the output mode.For example, posterizing an RGB pixel keyed as
(250, 10, 10)to four bits yields(240, 0, 0). The output now uses that value as the transparency key. If colors map to the same value, they share the resulting key.Validation on Linux / Python 3.12: selftest (59 passed), ImageOps tests (78 passed), and the full test suite (6,082 passed, 225 skipped, 3 xfailed). Both regression cases failed before the change. Applicable pre-commit hooks passed for the changed files.
AI disclosure: OpenAI Codex helped investigate, implement, and test the change and draft this description.