[ICON格式的资料] what's in an icon? an icon resource can contain multiple icon images. for example, one icon resource--in this case, a single .ico file--can contain images in several sizes and color depths: the ico file an icon file, which usually has the ico extension, contains one icon resource. given that an icon resource can contain multiple images, it is no surprise that the file begins with an icon directory: typedef struct { word idreserved; // reserved (must be 0) word idtype; // resource type (1 for icons) word idcount; // how many images? icondirentry identries[1]; // an entry for each image (idcount of 'em) } icondir, *lpicondir; the idcount member indicates how many images are present in the icon resource. the size of the identries array is determined by idcount. there exists one icondirentry for each icon image in the file, providing details about its location in the file, size and color depth. the icondirentry structure is defined as: typedef struct { byte bwidth; // width, in pixels, of the image byte bheight; // height, in pixels, of the image byte bcolorcount; // number of colors in image (0 if >=8bpp) byte breserved; // reserved ( must be 0) word wplanes; // color planes word wbitcount; // bits per pixel dword dwbytesinres; // how many bytes in this resource? dword dwimageoffset; // where in the file is this image? } icondirentry, *lpicondirentry; for each icondirentry, the file contains an icon image. the dwbytesinres member indicates the size of the image data. this image data can be found dwimageoffset bytes from the beginning of the file, and is stored in the following format: typdef struct { bitmapinfoheader icheader; // dib header rgbquad iccolors[1]; // color table byte icxor[1]; // dib bits for xor mask byte icand[1]; // dib bits for and mask } iconimage, *lpiconimage;the icheader member has the form of a dib bitmapinfoheader. only the following members are used: bisize, biwidth, biheight, biplanes, bibitcount, bisizeimage. all other members must be 0. the biheight member specifies the combined height of the xor and and masks. the members of icheader define the contents and sizes of the other elements of the iconimage structure in the same way that the bitmapinfoheader structure defines a cf_dib format dib. the iccolors member is an array of rgbquads. the number of elements in this array is determined by examining the icheader member. the icxor member contains the dib bits for the xor mask of the image. the number of bytes in this array is determined by examining the icheader member. the xor mask is the color portion of the image and is applied to the destination using the xor operation after the application of the and mask. the icand member contains the bits for the monochrome and mask. the number of bytes in this array is determined by examining the icheader member, and assuming 1bpp. the dimensions of this bitmap must be the same as the dimensions of the xor mask. the and mask is applied to the destination using the and operation, to preserve or remove destination pixels before applying the xor mask. note the biheight member of the icheader structure represents the combined height of the xor and and masks. remember to divide this number by two before using it to perform calculations for either of the xor or and masks. also remember that the and mask is a monochrome dib, with a color depth of 1 bpp. //-------------------------------------------------
what's in an icon?
an icon resource can contain multiple icon images. for example, one icon resource--in this case, a single .ico file--can contain images in several sizes and color depths:
the ico file
an icon file, which usually has the ico extension, contains one icon resource. given that an icon resource can contain multiple images, it is no surprise that the file begins with an icon directory:
typedef struct
{
word idreserved; // reserved (must be 0)
word idtype; // resource type (1 for icons)
word idcount; // how many images?
icondirentry identries[1]; // an entry for each image (idcount of 'em)
} icondir, *lpicondir;
the idcount member indicates how many images are present in the icon resource. the size of the identries array is determined by idcount. there exists one icondirentry for each icon image in the file, providing details about its location in the file, size and color depth. the icondirentry structure is defined as:
typedef struct
{
byte bwidth; // width, in pixels, of the image
byte bheight; // height, in pixels, of the image
byte bcolorcount; // number of colors in image (0 if >=8bpp)
byte breserved; // reserved ( must be 0)
word wplanes; // color planes
word wbitcount; // bits per pixel
dword dwbytesinres; // how many bytes in this resource?
dword dwimageoffset; // where in the file is this image?
} icondirentry, *lpicondirentry;
for each icondirentry, the file contains an icon image. the dwbytesinres member indicates the size of the image data. this image data can be found dwimageoffset bytes from the beginning of the file, and is stored in the following format:
typdef struct
{
bitmapinfoheader icheader; // dib header
rgbquad iccolors[1]; // color table
byte icxor[1]; // dib bits for xor mask
byte icand[1]; // dib bits for and mask
} iconimage, *lpiconimage;the icheader member has the form of a dib bitmapinfoheader. only the following members are used: bisize, biwidth, biheight, biplanes, bibitcount, bisizeimage. all other members must be 0. the biheight member specifies the combined height of the xor and and masks. the members of icheader define the contents and sizes of the other elements of the iconimage structure in the same way that the bitmapinfoheader structure defines a cf_dib format dib.
the iccolors member is an array of rgbquads. the number of elements in this array is determined by examining the icheader member.
the icxor member contains the dib bits for the xor mask of the image. the number of bytes in this array is determined by examining the icheader member. the xor mask is the color portion of the image and is applied to the destination using the xor operation after the application of the and mask.
the icand member contains the bits for the monochrome and mask. the number of bytes in this array is determined by examining the icheader member, and assuming 1bpp. the dimensions of this bitmap must be the same as the dimensions of the xor mask. the and mask is applied to the destination using the and operation, to preserve or remove destination pixels before applying the xor mask.
note the biheight member of the icheader structure represents the combined height of the xor and and masks. remember to divide this number by two before using it to perform calculations for either of the xor or and masks. also remember that the and mask is a monochrome dib, with a color depth of 1 bpp.
//-------------------------------------------------