Skip to content

fix: Prevent color corruption when mixing local and global GIF palettes #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

skidder
Copy link
Contributor

@skidder skidder commented Jun 3, 2025

Summary

Fixes a color corruption issue in animated GIFs where frames with local color palettes would display incorrect colors in Discord and other viewers.

Problem

The issue was introduced in commit 52ba7f4 where transparency optimization logic incorrectly compared color indices from different color maps:

  • gcb.TransparentColor refers to an index in the current frame's color map (local or global)
  • e->gif->SBackGroundColor refers to an index in the global color map

When a frame used a local color map, these indices could point to completely different colors, but the code incorrectly assumed they referenced the same palette. This caused transparency to be incorrectly removed, leading to visible color corruption.

Solution

Added a check !e->frame_color_map to only perform the transparency optimization when using the global color map, preventing index mismatches between local and global palettes.

Testing

  • All existing tests pass
  • Verified fix with the problematic GIF reported by Discord users
  • Re-encoded GIFs now display correctly without color corruption

Files Changed

  • giflib.cpp: Added palette type check in transparency optimization logic

Resolves the regression reported by Discord users where GIFs processed by Lilliput showed "colors completely warped, flashing wildly" during playback.

@skidder skidder marked this pull request as ready for review June 3, 2025 16:17
@skidder skidder merged commit 48d1d17 into master Jun 3, 2025
5 checks passed
@skidder skidder deleted the skidder/fix-gif-palette-corruption branch June 23, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants