![]() |
![]() |
|
![]() |
More on IconsAuthor: Joshua "Flobi" Hatfield I. Contents
II. floIcon - PHP Class for reading/writing ICO filesfloIcon makes and reads ICO files for Windows XP (which includes backwards compatibility). II.a. Determining Bit Count (when formatting an image for ICO format):
II.b. Transparency (when formatting an image for ICO format):
III. XP ICO File FormatIII.a. File HeaderEach ICO file begins with a 6 byte header. This tells the system: A. This is an icon file (not that there wasn't a guess in that direction from the .ico extension); and B. How many images are in the icon.
III.b. Image CatalogEach image has an entry in a catalog at the beginning of the file. These entries follow the header above immediately (so begin at byte offset 6). This should have enough information for the reading agent to determine which image is needed without parsing each individually. This is repeated as many times as "Image Count" above.
Despite 0 being an invalid number for width and height, there seems to be no indication that 0 would infer 256 as a value as it does for color count. (This may not be true for Vista images.) Some icon creators are not diligent in duplicating this section with the section below and vice versa, so a check is prudent. III.c. Image HeaderPositioned at the offset indicated at the end of the entry in the catalog above, begins the image header. Mostly a duplicate of the entry itself, this is stored in a format almost identical to Windows bitmap (BMP) images. Some of the values not used here may be used in BMP images.
III.d. PaletteIf the bit count is less than 24, the palette is stored otherwise, skip this section entirely. The number of palette entries is always 2 to the power of bit count. So, in 1 bit images, there are 2 palette entries, in 4 bit there are 16 entries, etc. This is stored as 32 bit colors one after the other as follows:
III.e. The XOR MapImmediately proceeding the palette (or header if no palette is included), each pixel is stored using the number of bits specified in "Bit Count", bottom up, left to right. If the image is 8bit or less, the bits specify the palette entry offset above (0 is the first one). 24 bit images store 3 bytes per pixel, each containing the red, green and blue components respecively. 32 bit images store 4 bytes containing red, green, blue and alpha components respectively. No matter which bit depth is used, each row must be padded to 32 bits with 0's (this is irrelevant in 32 bit images which are already ending at the 32 bit mark). III.f. The AND MapThe AND Map is a 1 bit pixel map stored just like the XOR map where 0 indicates off and 1 indicates on. 1 is usually used to store transparency, but see below in Transparency vs. Inversion Method why this is not always true. Normally, the AND Map is not used in 32 bit images. However, it should still be stored. If no 24 bit image is available and the icon is used in a 24 bit environment by Windows, the 32 bit image may be converted into a 24 bit image. This is done by removing the alpha component and applying the AND map. Also, the AND map may be used for Inversion (see below) in 32 bit images III.g. Transparency vs. Inversion MethodBy placing the pixel a non-black color in the XOR map and setting the pixel on in the AND map, inversion is interpreted by Windows. This causes the background color to show through, however, inverted (to varying degrees based on the color in the XOR map). This could be very useful, I'm sure, but because PHP GD image resources do not support inversion, and neither do any of the image types supported by GD, that is not supported in floIcon. III. Credits
|
|
|