9.5.1 GIF Palette Overview
GIF is an indexed color format. Each pixel color is specified via an index
pointing to an RGB entry in a palette.
Each GIF image contains at least one palette. Usually, there is a single global palette
which applies to each frame of the image. In some cases, a frame has its own local palette
which takes precedence over the global palette within that frame but does not apply to any other frames.
If each frame has its own local palette, a global palette is usually not present at all.
GIF format requires that a palette contain 2, 4, 8, 16, 32, 64, 128, or 256 colors.
Each color entry in a palette contains exactly three bytes: the R, G, and B values.
9.5.2 Accessing and Modifying Palettes
The Gif object offers a number of properties and methods to access and modify
the global and local palettes of an image.
To specify an entire palette (global or local) in a single step, the SetPalette
method should be used. This method expects a Boolean flag indicating
whether the palette is global (True) or local (False), and a Variant-packed
array of numbers specifying the RGB values of the entire palette. The array must contain
a valid number of colors (2, 4, 8, etc.) multiplied by 3. If the first argument is False (indicating
a local palette) the image must already contain at least one frame, and
the palette pertaining to the current frame will be affected.
The following code snippet sets the global palette to contain 4 colors: black (0, 0, 0), white (255, 255, 255),
green (0, 255, 0) and yellow (255, 255, 0):
VB Script:
Colors = Array(0,0,0, 255,255,255, 0,255,0, 255,255,0)
Gif.SetPalette True, Colors
|
C#:
Object [] Colors = new Object[]
{0,0,0, 255,255,255, 0,255,0, 255,255,0};
objGif.SetPalette( true, Colors );
|
To set or obtain the size of a palette, use the property PaletteSize which expects the same global/local
flag as the SetPalette method. The size of a palette is the number of colors, not the
total number of color components. Valid values are 2, 4, 8, ..., 256. Setting this property to 0 effectively
removes the palette entirely. Examples of using this parameterized property are as follows:
VB Script:
Gif.PaletteSize( False ) = 256
N = Gif.PaletteSize( False )
|
C#:
objGif.set_PaletteSize( false, 256 );
int N = objGif.get_PaletteSize( false );
|
To set or get an individual color component of a palette, use the property PaletteItem
which expects two parameters: the global/local flag and the address (0-based index) of the desired color
component within the palette. The three RGB components of the 1st color have the addresses 0, 1 and 2, the 2nd color
-- 3, 4, and 5, etc. The address parameter must be in the range [0, PaletteColor * 3 - 1].
9.5.3 Stock Palettes
The Gif object enables you to specify one of several built-in palettes via the SetStockPalette
method. This method expects two arguments: the global/local flag, and the palette number.
Currently, 3 stock palettes are available:
Palette #1: Web-safe colors (default palette, 216 actual colors, 40 reserved slots);
Palette #2: Standard HTML colors (16 colors);
Palette #3: Grayscale colors (256 colors).
Palette #1 is the default global palette in all new images created with the Gif object.
This palette contains the standard Web-safe colors as described in the HTML specifications.
There are 216 standard Web-safe colors, and the indices 216 to 255 are not used and set to black.
These unused slots can be set to any arbitrary colors, if necessary.
The standard Web-safe color palette looks as follows:
| 0 | 1 | 2 | 3 | 4 | 5 |
0 |
000000 |
000033 |
000066 |
000099 |
0000CC |
0000FF |
6 |
003300 |
003333 |
003366 |
003399 |
0033CC |
0033FF |
12 |
006600 |
006633 |
006666 |
006699 |
0066CC |
0066FF |
18 |
009900 |
009933 |
009966 |
009999 |
0099CC |
0099FF |
24 |
00CC00 |
00CC33 |
00CC66 |
00CC99 |
00CCCC |
00CCFF |
30 |
00FF00 |
00FF33 |
00FF66 |
00FF99 |
00FFCC |
00FFFF |
36 |
330000 |
330033 |
330066 |
330099 |
3300CC |
3300FF |
42 |
333300 |
333333 |
333366 |
333399 |
3333CC |
3333FF |
48 |
336600 |
336633 |
336666 |
336699 |
3366CC |
3366FF |
54 |
339900 |
339933 |
339966 |
339999 |
3399CC |
3399FF |
60 |
33CC00 |
33CC33 |
33CC66 |
33CC99 |
33CCCC |
33CCFF |
66 |
33FF00 |
33FF33 |
33FF66 |
33FF99 |
33FFCC |
33FFFF |
72 |
660000 |
660033 |
660066 |
660099 |
6600CC |
6600FF |
78 |
663300 |
663333 |
663366 |
663399 |
6633CC |
6633FF |
84 |
666600 |
666633 |
666666 |
666699 |
6666CC |
6666FF |
90 |
669900 |
669933 |
669966 |
669999 |
6699CC |
6699FF |
96 |
66CC00 |
66CC33 |
66CC66 |
66CC99 |
66CCCC |
66CCFF |
102 |
66FF00 |
66FF33 |
66FF66 |
66FF99 |
66FFCC |
66FFFF |
108 |
990000 |
990033 |
990066 |
990099 |
9900CC |
9900FF |
114 |
993300 |
993333 |
993366 |
993399 |
9933CC |
9933FF |
120 |
996600 |
996633 |
996666 |
996699 |
9966CC |
9966FF |
126 |
999900 |
999933 |
999966 |
999999 |
9999CC |
9999FF |
132 |
99CC00 |
99CC33 |
99CC66 |
99CC99 |
99CCCC |
99CCFF |
138 |
99FF00 |
99FF33 |
99FF66 |
99FF99 |
99FFCC |
99FFFF |
144 |
CC0000 |
CC0033 |
CC0066 |
CC0099 |
CC00CC |
CC00FF |
150 |
CC3300 |
CC3333 |
CC3366 |
CC3399 |
CC33CC |
CC33FF |
156 |
CC6600 |
CC6633 |
CC6666 |
CC6699 |
CC66CC |
CC66FF |
162 |
CC9900 |
CC9933 |
CC9966 |
CC9999 |
CC99CC |
CC99FF |
168 |
CCCC00 |
CCCC33 |
CCCC66 |
CCCC99 |
CCCCCC |
CCCCFF |
174 |
CCFF00 |
CCFF33 |
CCFF66 |
CCFF99 |
CCFFCC |
CCFFFF |
180 |
FF0000 |
FF0033 |
FF0066 |
FF0099 |
FF00CC |
FF00FF |
186 |
FF3300 |
FF3333 |
FF3366 |
FF3399 |
FF33CC |
FF33FF |
192 |
FF6600 |
FF6633 |
FF6666 |
FF6699 |
FF66CC |
FF66FF |
198 |
FF9900 |
FF9933 |
FF9966 |
FF9999 |
FF99CC |
FF99FF |
204 |
FFCC00 |
FFCC33 |
FFCC66 |
FFCC99 |
FFCCCC |
FFCCFF |
210 |
FFFF00 |
FFFF33 |
FFFF66 |
FFFF99 |
FFFFCC |
FFFFFF |
To obtain the index for a given color, add the numbers in the leftmost column and top row corresponding
to this color.
Palette #2 contains the standard 16 HTML colors (alphabetically ordered by name), as follows:
Index | Color | Name | Index | Color | Name |
0 | 00FFFF | aqua | 8 | 000080 | navy |
1 | 000000 | black | 9 | 808000 | olive |
2 | 0000FF | blue | 10 | 800080 | purple |
3 | FF00FF | fuchsia | 11 | FF0000 | red |
4 | 008000 | green | 12 | C0C0C0 | silver |
5 | 808080 | grey | 13 | 008080 | teal |
6 | 00FF00 | lime | 14 | FFFFFF | white |
7 | 800000 | maroon | 15 | FFFF00 | yellow |
Palette #3 contains 256 grayscale colors from RGB(0, 0, 0) to RGB(255, 255, 255) and is not shown here.