fix: Preserve GIF transparent color across frames #255
+40
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses an issue where transparency information from GIF files was being discarded during the decoding process, resulting in incorrect background and transparency color values in GIF-to-GIF conversions.
Change
TransparentColor = NO_TRANSPARENT_COLOR
in thegiflib_get_frame_gcb
functionImpact
Testing
Analysis of GIF frame data shows that this change correctly preserves the original background color while the production version incorrectly defaults to black.
Source
Development (this branch) version
Stable (prod) version
Extracted background, transparency, and dispose data for a source image against images from created from this development branch and stable:
I then compared that data for the dev and stable (prod) branches against the source. The stable prod branch is mangling the background and transparent color, making them different from the source.
Technical Details
The issue was that we were unconditionally initializing the GraphicsControlBlock's
TransparentColor
field to-1
(no transparency) before reading the actual GCB data from extension blocks. This inadvertently caused the loss of transparency information when no specific transparency data was present in the GIF's extension blocks. As far as I can tell, this issue has always existed in Lilliput.