Skip to content

Fix animated GIF transparency and frame ghosting#25

Merged
Aerhhh merged 1 commit into
masterfrom
fix/animated-gif-transparency
Jul 10, 2026
Merged

Fix animated GIF transparency and frame ghosting#25
Aerhhh merged 1 commit into
masterfrom
fix/animated-gif-transparency

Conversation

@Aerhhh

@Aerhhh Aerhhh commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Animated GIFs produced by GifSequenceWriter had two problems that showed up together on themed tooltip renders with obfuscated text:

  • Semi-transparent artwork disappeared. GIF only supports 1-bit alpha, and the JDK encoder maps every pixel with alpha below 255 to the transparent palette slot. Resource pack tooltip backgrounds are semi-transparent, so the entire background and border vanished from the encoded GIF.
  • Frames stacked on top of each other. Frames were written with disposal method 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

  • Frames are normalized before encoding: converted to 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.
  • Encoder metadata is derived from TYPE_INT_ARGB to match the normalized frames; deriving it from other image types made the encoder palettize against the wrong color table and lose colors.
  • Disposal method changed from none to restoreToBackgroundColor so the canvas clears between frames.

Testing

  • New ImageUtilGifTest pins 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.
  • Full suite: 188 tests green.
  • Verified end to end from MinecraftImageGenerator against this branch: full suite green (466 tests), and a real Hypixel-pack animated tooltip renders with the themed background intact, a transparent page background, and no ghosting between frames.

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.
@Aerhhh
Aerhhh merged commit 325fa59 into master Jul 10, 2026
2 checks passed
@Aerhhh
Aerhhh deleted the fix/animated-gif-transparency branch July 10, 2026 19:41
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.

1 participant