Skip to content

GIF encoding: Transparency incorrectly parsed in latest update? #267

@edelkas

Description

@edelkas

Context

A couple of days ago the GIFs I'm encoding in my application stopped being displayed correctly in Discord, though my code hasn't changed noticeably in over a year.

As an example, you can try pasting the following GIF into a Discord chat, and you'll likely see the tiles in the map change color. Paste it again and you might get different, still incorrect, colors. The color is even different when you hover vs when you click on the GIF. Before you hover on the GIF (assuming you have auto-play disabled) the tiles actually appear transparent.

Image

Details

The GIF above is encoded in the following way:

  • Has a Global Color Table and no Local Color Tables; also no disposal method.
  • The first image contains no transparency, and in fact no Graphic Control extension (GCE); it acts as the initial background.
  • All subsequent frames have a GCE that specifies the frame delay and the transparent color to enable the animation.

Issue

The problematic color appears to be at index 0 in the palette. I've found two fixes:

  • Putting an unused color at index 0 solves the issue.
  • Alternatively, if I add a GCE to the first image specifying an unused transparent color, the issue is also solved.

This is also corroborated in the small parts of the tiles that get redrawn later, this time with the correct color, as shown by this Discord screenshot of the above GIF where the tiles had been initially (wrongly) rendered yellow:

Image

Thus, it seems that in the absence of a GCE (at least for frame 0) the encoder assumes color 0 should be transparent, or simply fails to encode it correctly. Funny enough, if I add the GCE and set color 0 to transparent manually, it's rendered correctly (it remains transparent for the entirety of the GIF, instead of rendering with a seemingly random color).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions