image/gif: Mention the uselessness of BackgroundIndex in the docs #20694
Labels
Documentation
Issues describing a change to documentation.
help wanted
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version: Go 1.8 (but this is a documentation issue)
Quick introduction to GIF disposal methods:
In an animated GIF, a disposal method can be set for each frame. It specifies to which state the canvas should be set before displaying the next frame when the current frame is finished being shown. There are three disposal methods, represented in
image/gif
byDisposalNone
,DisposalBackground
andDisposalPrevious
.DisposalNone
means that the following frame is drawn on top of the current frame, so that transparent areas of the next frame continue to show this frame's content.DisposalPrevious
means that the canvas is reset to the last frame that didn't have its disposal method set toDisposalPrevious
.DisposalBackground
means something else and I will come to that in a moment.In Go, an animated GIF can be written by
EncodeAll()
inimage/gif
, which accepts aGIF
struct that describes the animated GIF. This struct has a memberBackgroundIndex byte
whose inline documentation reads:This gives the impression that
DisposalBackground
means "the canvas is restored to the color given byBackgroundIndex
.However, in all modern browsers
DisposalBackground
is interpreted as "clear the canvas to fully transparent".It turns out that this is indeed an ambiguity in the GIF89a specification which in the past has been interpreted as "clear to
BackgroundIndex
" but is apparently interpreted as "clear to transparent" since about 15 years ago, as this comment from the Mozilla bugtracker shows.Since I just spent an hour figuring out why Chrome (as I thought) doesn't reset the canvas to
BackgroundIndex
, I would appreciate if the fact thatBackgroundIndex
is essentially ignored by all browsers would be mentioned in the docs.The text was updated successfully, but these errors were encountered: