Skip to content

Update 1, L and RGB info transparency when inverting images - #10722

Merged
radarhere merged 3 commits into
python-pillow:mainfrom
Ap-95671:codex/pillow-preserve-invert-transparency
Dec 4, 2026
Merged

radarhere merged 3 commits into
python-pillow:mainfrom
Ap-95671:codex/pillow-preserve-invert-transparency

Conversation

@Ap-95671

@Ap-95671 Ap-95671 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Problem

ImageOps.invert() inverts pixel samples but carries the old color key forward. A PNG with a transparent sample and its opaque complement can go from alpha bytes [0, 255] to [255, 0] after inversion.

Change

Apply the inversion lookup table to the transparency key for modes 1, L, and RGB. This preserves the mode and transparent pixels, including when saving the result to PNG. Palette inversion continues to preserve its existing alpha handling. The input image metadata is preserved.

Verification

  • Reproduced both bilevel keys, a grayscale key, and an RGB key before the fix. All four regression cases pass with the fix.
  • Tested 384 grayscale and RGB PNG round trips.
  • ImageOps/PNG tests: 159 passed. Pillow selftest: 59 passed.
  • Broad suite: 6,176 passed, 116 skipped, 3 xfailed, and one macOS screen-capture test deselected after it failed in the headless environment.
  • Ruff, Black, Sphinx lint, and git diff --check passed.

Prepared with OpenAI Codex.

@radarhere radarhere added the 🤖-assisted AI-assisted label Dec 3, 2026
@radarhere
radarhere force-pushed the codex/pillow-preserve-invert-transparency branch from 982c545 to d802c57 Compare December 4, 2026 01:22
@radarhere radarhere changed the title Preserve color-key transparency when inverting images Update 1, L and RGB info transparency when inverting images Dec 4, 2026
@radarhere
radarhere enabled auto-merge (squash) December 4, 2026 01:25
@radarhere
radarhere disabled auto-merge December 4, 2026 01:54
@radarhere
radarhere merged commit b624366 into python-pillow:main Dec 4, 2026
70 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants