image - Gif 图像格式中如何包含透明度

标签 image image-processing gif animated-gif file-format

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 == falseTI 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/

    相关文章:

    image - 使用指定边界裁剪非常大的适合文件

    image - (Crystal Reports)如何减小RPT文件的大小

    ios - 将图像设置为用蓝色填充的 UIButton

    c# - 如何从 Controller 方法返回多个图像?

    apache-flex - Flash 中的快速双三次或双线性图像调整大小 - Flex - actionscript 3

    image - 挂载 docker 主机卷但用容器的内容覆盖

    image-processing - 检查一张图片是否在另一张图片上的某处/相似的最佳方法是什么?

    html - 我的 gif 对于我的无序列表来说太大了吗?有什么建议吗?

    python - 将枕头 Gif 复制到 Windows 剪贴板

    animation - gif 动画的总持续时间