Fix animated GIF transparency and frame ghosting#25
Merged
Conversation
GIF only supports 1-bit alpha and the JDK encoder maps every pixel with alpha below 255 to the transparent palette slot, so semi-transparent artwork (such as resource pack tooltip backgrounds) silently vanished from encoded GIFs. Frames were also written with disposal method "none", which makes viewers draw each frame on top of the previous one, so animations with transparent regions accumulated stale pixels between frames (visible as ghosting on obfuscated text). Normalize every frame to TYPE_INT_ARGB with binary alpha before encoding: visible pixels become fully opaque, fully transparent pixels stay transparent, and caller frames are never mutated since they are reused for WebP encoding, which keeps real alpha. Derive the encoder metadata from ARGB so palettization uses the right color table, and dispose each frame to the background color so the canvas clears between frames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Animated GIFs produced by
GifSequenceWriterhad two problems that showed up together on themed tooltip renders with obfuscated text:none, so viewers draw each frame over the previous one. With transparency in the frames, stale pixels from earlier frames stayed visible, which made animated (magic) text pile up into an unreadable smear.Changes
TYPE_INT_ARGB, visible pixels forced fully opaque, fully transparent pixels left transparent. Caller frames are never mutated because they are reused for WebP encoding, which keeps real alpha.TYPE_INT_ARGBto match the normalized frames; deriving it from other image types made the encoder palettize against the wrong color table and lose colors.nonetorestoreToBackgroundColorso the canvas clears between frames.Testing
ImageUtilGifTestpins the encoding contract: semi-transparent pixels survive as opaque, transparent pixels stay transparent, every frame disposes to the background, input frames are not mutated, and opaque frames round-trip their colors.