GIF89a 通过将索引分配为透明图块来支持透明度。它只支持完全透明,这意味着不支持可变透明度(如 PNG 的情况)。
我试着阅读 Pseudo RFC对于 GIF89a 格式,在整个文档中仅包含两次提及透明度。即:-
而以上两个的描述,并不是最直观的。
维基百科页面 GIF指出,索引 = 16(在 256 调色板中)的透明图块总是被指定为透明图块/索引。但随后它指出,“图像数据中出现的唯一颜色索引是十进制 40 和 255,全局颜色表分别映射到黑色和白色”,这让我相信我可能误解了页面中的可用信息(正如我之前在图像中看到的 索引 < 40 的像素值)。
问题:-
.gif
中如何纳入透明度(89a) 图像?是一个调色板中的常量索引总是赋予透明值?
透明区域,这是否意味着我们只能使用 255 个唯一的
索引(因为 1 索引总是被赋予透明瓷砖)?
PS:- 如果有人会补充透明度如何包括在内,我将不胜感激?是使用 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 == false
和 TI
value 通常是垃圾,所以它不会被 GIF 加载器解释。作为一名自称为 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?
不可以。即使是单帧 GIF 也允许包含 Graphics Control 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。
调色板大小由 bits 0 to 2 of the flags field 控制在全局 GIF header 中。
关于image - Gif 图像格式中如何包含透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57111553/