Gif图片格式如何加入透明度

How is transparency incorporated in Gif Image format

GIF89a 通过将索引指定为透明图块来支持透明度。它仅支持完全透明,这意味着不支持可变透明度(如 PNG 的情况)。

我尝试阅读 Pseudo RFC GIF89a 格式,整个文档中只提到了两次透明度。即:-

还有上面两个的描述,不是最直观的

GIF 的维基百科页面指出,索引 = 16(在 256 调色板中)的透明图块始终指定为透明图块 tile/index。但随后它指出,“图像数据中出现的唯一颜色索引是十进制 40 和 255,全局颜色 Table 分别映射到黑色和白色 ”,它让我相信我可能误解了页面中可用的信息(因为我之前在图像中看到 index < 40 的像素值)。

问题:-

P.S.:- 如果有人能补充一下透明度是如何包含的,我将不胜感激?是使用 Alpha 图块(如 RGBA 或 LA)还是从该像素中移除颜色以使其透明?

How is transparency incorporated in .gif (89a) images? Is a constant index in the palette always given a value of transparent?

没有

透明度标志 TF 仅指示透明度索引 TI 是否对框架有任何意义。

如果 TF == true 则当前(全局或局部)调色板中的特定颜色索引在将当前帧与图像的其余部分组合时被视为透明。此索引存储在 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)?

当图像没有透明区域时,TF == falseTI 值通常是垃圾,因此不会被 GIF 加载器解释。

作为一名 self-proclaimed GIF 专家,我试图尽可能简洁地在文档和 this 微型加载器的源代码中记录 GIF 的内部工作原理。

[更新:]

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?

没有。即使 single-frame GIF 也允许包含图形控件 header,所以不可以。

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 支持任何大小为 2 的幂且介于 2 和 256 之间的调色板,结果为:2、4、8、16、32、64、128 或 256。

调色板大小由全局 GIF header 中的 bits 0 to 2 of the flags field 控制。