gpt4 book ai didi

gif - GIF89a 规范中的 "Color Resolution"和 "Size of Global Color Table"有什么区别?

转载 作者:行者123 更新时间:2023-12-02 19:53:53 25 4
gpt4 key购买 nike

我无法弄清楚 gif89a 规范中的“颜色分辨率”字段和“全局颜色表大小”字段之间的区别 https://www.w3.org/Graphics/GIF/spec-gif89a.txt (第 9-10 页):

Color Resolution - Number of bits per primary color [...], minus 1. This value represents the size of the entire palette [...]

Size of Global Color Table - [...] To determine that actual size of the color table, raise 2 to [the value of the field + 1].

...

[The Global Color Table] is a sequence of bytes representing red-green-blue color triplets [...] and contains a number of bytes equal to 3 x 2^(Size of Global Color Table+1).

假设我们想要创建一个具有 3 种颜色(红色、绿色和蓝色)的图像。在这种情况下,我们至少需要 ceil(log2(3)) = 每种颜色 2 位(00 = 红色,01 = 绿色,10 = 蓝色)。然后,根据规范,颜色分辨率 (CR) 字段必须设置为 ceil(log2(3)) - 1 = 2 - 1 = 1:

packed fields = X001XXXX
---
CR field

更一般地,如果 N 是颜色数量,则 CR = ceil(log2(N)) - 1。

关于全局颜色表(GCT)的大小,1种颜色需要3个RGB字节,因此条目数=字节数/3=2^(GCT的大小+1)。因为我们想要存储 3 种颜色,所以我会选择紧随 3 之后的 2 的幂,即 2 的 ceil(log2(3)) = 2^2 = 4。然后,2^(GCT 的大小 + 1) = 2^ceil(log2(3)),GCT 的大小 + 1 = ceil(log2(3)) 和 GCT 的大小 = ceil(log2(3)) - 1 = 2 - 1 = 1:

packed fields = XXXXX001
---
Size of GCT field

同样,如果 N 是颜色数量,则 GCT 的大小 = ceil(log2(N)) - 1。

如您所见,CR = GCT 的大小 = ceil(log2(N)) - 1。看起来 CR 字段和 GCT 字段的大小始终保持相同的值。我想我错了,因为如果我是对的,这两个字段之一将毫无用处,但到目前为止我在规范中没有找到任何说明。

我并不是唯一一个感到困惑的人:http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html 。本文将Size of GCT字段的定义应用到CR字段上,而Size of GCT字段根本就没有定义:

[...] the color resolution [...] allow you to compute [the] size [of the GCT]. If the value of this filed is N, the number of entries in the global color table will be 2 ^ (N+1) [...]. Thus, the 001 in the sample image represents 2 bits/pixel; 111 would represent 8 bits/pixel.

有人知道这两个字段不同的情况吗?

最佳答案

来自规范:

iv) Color Resolution - Number of bits per primary color available
to the original image, minus 1. This value represents the size of
the entire palette from which the colors in the graphic were
selected, not the number of colors actually used in the graphic.
For example, if the value in this field is 3, then the palette of
the original image had 4 bits per primary color available to create
the image. This value should be set to indicate the richness of
the original palette, even if not every color from the whole
palette is available on the source machine.

因此,需要明确的是,颜色分辨率应该是生成 GIF 的原始图像中每种颜色的位数(小于 1)。

关于gif - GIF89a 规范中的 "Color Resolution"和 "Size of Global Color Table"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57210687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com