GIF89a supports Transparency, by assigning an index as transparent tile. It does only support full transparency, meaning variable transparency (like in the case of PNG) is not supported.
I tried reading Pseudo RFC for GIF89a format, which contains only two mentions of transparency in the whole document. Namely:-
and the description of the above two, isn't the most intuitive.
The Wikipedia page of GIF states that, a transparent tile having index = 16 (in the 256 palette) is always assigned as the transparent tile/index. But then it states, "The only color indexes appearing in the image data are decimal 40 and 255, which the Global Color Table maps to black and white, respectively", which made me believe that I am probably misinterpreting the info available in the page (as i have previously seen pixel values of index < 40 in images).
Question:-
.gif
(89a) images? Is a
constant index in the palette always given a value of transparent?P.S.:- I would appreciate if anyone would add how is transparency included? Does that use a Alpha tile (like in RGBA or LA) or does that remove the color from that pixel to make it transparent?
How is transparency incorporated in .gif (89a) images? Is a constant index in the palette always given a value of transparent?
No.
The Transparency Flag TF
just indicates whether the Transparency Index TI
has any meaning for the frame.
If TF == true
then a certain color index in the current (either global or local) palette is treated as transparent while combining the current frame with the rest of the image. This index is stored in TI
.
If yes, then does the palette stays the same when an image has no transparent regions, and does that mean we only get to use 255 unique index (as 1 index is always given to transparent tile)?
When the image has no transparent regions, TF == false
and TI
value is usually garbage, so it doesn`t get interpreted by GIF loaders.
As a self-proclaimed GIF expert I tried to document the inner workings of GIF as tersely as I could in the docs and the source code of this tiny loader.
[UPD:]
So, does that mean transparency is only included if the .gif file has frames. Meaning it is not a single image, but a sequence of images?
No. Even a single-frame GIF is allowed to contain a Graphics Control header, so no.
Does GIF have a fixed palette of 256 colors, meaning the palette could not store more/less then that color range. I am asking this as you mentioned, that in a B/W image, only two color exists black and white, then what happens to the rest of the palette index? or like how does GIF format manages lower color spaces?
GIF supports palettes of any size that is a power of 2 and is between 2 and 256, which results in: 2, 4, 8, 16, 32, 64, 128, or 256.
Palette size is controlled by bits 0 to 2 of the flags field in the global GIF header.