In the GIF specifications noted here:
http://www.w3.org/Graphics/GIF/spec-gif89a.txt
It gives the following formula for calculating the color table size:
3 x 2^(Size of Global Color Table+1).
Given this they use 'x' instead of '*', am I correct in assuming '^' does not mean XOR? If that is the ca开发者_高级运维se, what does '^' mean?
Thank you.
^
is commonly used for exponentiation, and 2
is a very common base for that.
The Size of Color Table
variable is noted as a three-bit value, with in combination with the +1 means that the color table is between 2 and 256 colors. That indeed matches the GIF format.
(In C, you'd write this as 6 << Size_of_global_color_table
)
^ means power. So, it is 2 raise to the power of size of global colour table + 1. Basically, something as a base 2 can be powered to a value easily by left shift operation. So, you don't need pow() API. Just do the following . 2 << ( global_colour_table_size). For example, 2^3 is equal to 2 << 2. In general the formula is the following, 2^n is equal to 2<< (n-1). You can download the decoder logic and details from the following link - http://www.tune2wizard.com/gif-decoder/
C# code to get the number of colors and bytes from the Global Color Table
byte byt = imgBytes[10]; // get the first packed field byte
byt = (byte)(byt & 7); // low 3 bits only for the global color table size
int gctColors = (int)Math.Pow(2, byt + 1); // calculate number of colors
int gtcBytes = gctColors * 3; // 3 bytes per color
精彩评论