Icon And Cursor Graphics Files |
The Windows Icon And Cursor Files... |
Microsoft icons/cursors are stored in .ICO/.CUR files, are (in the default configuration) 32x32 pixels, and support 2,16 and 256 colors with masking. There are three main components to the windows icon/cursor files : The Icon/Cursor File Header, Icon/Cursor Directory, and Device Independent Bitmap section. Following table shows a high-level view of the windows icon/cursor format.
|
|
Icon/Cursor File Header |
Icon/Cursor Directory |
Device Independent Bitmap
Device Independent Bitmap Data |
Icon/Cursor Data |
Icon/Cursor Mask 128 Bytes |
|
|
|
The File Header... |
The Resource File Header, IcoCurFileHdr, starts the icon/cursor file. This section is common to all windows resource files. The Resource File Header (Given Below) identifies the type of resource contained in the file (ResourceType ) and the number of resources (icons/cursors) contained in the file (ResourceCount ). For simplicity, I am going to deal with files containing only one 32x32 of 2,16 or 256 colour icon/cursor. Icon files will default to 0,1 and 1, cursor files will default to 0,2 and 1 for the Reserved, ResourceType, and ResourceCount fields, respectively.
|
|
Windows Resource File Header C Structure.
|
| | |
Struct | | |
{ | | |
unsigned int | Reserved, | |
| ResourceType, | /* 1 For Ico And 2 For Cur */ |
| ResourceCount; | /* Always 01 */ |
} IcoCurFileHdr; | | |
|
|
|
The Icon/Cursor Directory... |
The Icon/Cursor Directory, IcoCurDirectory, follows the Resource File Header. The directory structure precedes the icon/cursor data in all icon/cursor definitions. This structure first defines the icon's/cursor's Width and Height in pixels. Then comes one byte information for ColourCount which specifies the number of colours supported, this byte is 0 if maximum number of colours are used. Next is one byte Reserved1 information, Microsoft has not yet come up with information to put in. Next four bytes represents the HotSpotPosX and HotSpotPosY of Cursor image, but these four bytes are reserved in Icon files. and last but one is Four byte information about the size of Device Independent Bitmap. Finally Last four bytes are the offset value of Device Independent Bitmap.
|
|
Windows Icon/Cursor Directory C Structure.
|
| | |
Struct | | |
{ | | |
unsigned char | Width, | /*Width Of Icon/Cursor*/ |
| Height, | /*Height Of Icon/Cursor*/ |
| ColourCount, | /*0 If Max Colours Used*/ |
| Reserved1; | /* Always 0 */ |
unsigned int | HotSpotPosX, | /*Reserved2=0 If Icon*/ |
| HotSpotPosY; | /*Reserved3=0 If Icon*/ |
unsigned long int | DIBSize, | /*Size Of DIB*/ |
| DIBOffset; | /*DIB Memory Offset*/ |
} IcoCurDirectory; | | |
|
|
|
Following Icon/Cursor Directory we have information about the image. I have not yet totally mastered it. I am going to have many Reserved bytes in this section, all these Reserved bytes are not mastered by me. first comes 4-bytes long PaletteOffset , this value points to the begining of palette information, be carefull this offset should be seeked from the current file pointer position. then comes 4 bytes Reserved information which is always 20 00 00 00, and the next four bytes are again Reserved bytes which are always equal to 40 00 00 00. Next comes an integer(2 bytes) value which I allways found to be 1, most probably it may be number of planes. Then comes single byte value which represent BitsPerPixel , this can be either 1,4, or 8. Again next five bytes of information are Reserved just put 0 in these bytes, next comes 4 byte value which represent the SizeOfImageData . Finally we have 20 Reserved bytes, again put these values to 0, inserting the constant value's which I have given for Reserved Bytes wont harm the Icon/Cursor File's data, so... just go with the flow.
|
|
Palettes Information... |
All Icon/Cursor Images have colour palette information. Length of colour palette is 4, 60 and 1020 for 1, 4 and 8 bit colour for all .CUR/.ICO files. Since Microsoft takes the default palette of index 0 as BLACK(Red=0 : Green=0 : Blue=0), this is because to keep a seperate option for background view when masked. For the rest of the index we can define the palette information, that is we can define palette information for Maximum Number Of Colours -1 indexes.The first byte of palette Information is blue component of the colour, the second is the green component, the third is the red component, and the fourth is reserved---it is not used and should always be set to 0. Perhaps in some future version this byte may hold intensity information.
|
|
Icon/Cursor Image Data... |
The .ICO/.CUR image data is stored begining at the bottom-left corner of the picture and working upward a line at a time. The 2 colour .ICO/.CUR images(1-BitsPerPixel) are stored sequentially, eight pixels per byte, that is each bit in the image data byte represent the colour of the index represented in colour palette. The 16 colour .ICO/.CUR images(4-BitsPerPixel) are stored sequentially, two pixels per byte, that is every four bit in the image data byte represent the colour of the index represented in colour palette. The 256 colour .ICO/.CUR images(8-BitsPerPixel) are stored sequentially, one pixel per byte, that is every byte in the image data represents the colour of the index shown in colour palette. No Padding Bytes are present in these images, because my research is limited to the standard size that is 32x32.
|
|
Icon/Cursor Masking... |
Microsoft Windows Offers Masking for Icon and Cursor files. one bit mask is allocated for each pixel in image data. one bit per pixel will indicate the transparency or solidity of the pixel i.e. each pixel in image has a coressponding mask bit, if the mask bit is 1, then the pixel is masked with the background pixel, othervise solidity is maintained in pixel. Only one bit per pixel is required, so 4 bytes can store 32 pixels of mask information and 128 bytes can hold the mask information for the entire Icon/ Cursor. Below table shows the layout of the mask byte containing the mask for the pixel at (0,31). As with pixel colour data, the mask data corresponds to pixels starting at the lower left corner of the icon/cursor.
|
|
Mask Data Follows The Icon/Cursor Data Section One Bit Per Pixel. |
Mask Bit For Pixel at (0,31) stored in highest bit in first byte of mask data | ==> |
|
First Byte Of Mask Data |
|
|
|
|