If you look in the GIF specification and search for "Background Color Index", you see the following description:
vii) Background Color Index - Index into the Global Color Table for the Background Color. The Background Color is the color used for those pixels on the screen that are not covered by an image. If the Global Color Table Flag is set to (zero), this field should be zero and should be ignored.
There is an ambiguity here, which is that if the "Global Color Table Flag" is set to zero and this field is ignored, then it is undefined what background colour of a GIF actually should be if the image data itself does not cover the entire image area. This possible because every image data block specifies left/right/width/height independently and there is no requirement that every pixel must be encoded by the image data.
Am I misinterpreting this? If not, then in the presence of this ambiguity, what is the de facto behaviour of GIF implementations today?
The background color index is often ignored by decoders (including some modern browsers), whereas GDI+ (eg. Windows Paint or .NET WinForms controls) respect it. GDI+ handles it like this:
To demonstrate its effect I created a simple animation of two frames with my encoder, and then played with some settings (feel free to download the images and see their content in a file viewer because I added some textual hint in the files). You can use this app to see the animations in a Win32 app using GDI+ rendering.
Common properties:
The animation rendered by your browser | The 2nd frame by GDI+ | Description |
---|---|---|
![]() |
![]() |
None of the frames are transparent, there is no clear. |
![]() |
![]() |
Both frames are transparent, there is no clear. |
![]() |
![]() |
Only the 2nd frame is transparent, there is a clear after the first frame. |
For the example, Safari uses black as the background. With Win10 photo viewer it's hard to tell, as it uses a black background anyway. Chrome, IE and Edge use white. The spec doesn't define the behaviour when there's no background colour and you need one, so I guess arbitrary choices is what you'll get, though I vote for transparent being the most sensible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With