<center>'''Icons''' and '''Cursors''' are image files with ICO or CUR filename extensions.</center>
{| align="right"
| __TOC__
|}
* Both can use 1 BPP(B & W), 4 BPP(16), 8 BPP(256) or 24/32 BPP(16 million) colors.
* They are formatted similar to bitmaps, but each file can hold more than one image.
* Images can be different sizes and use different color palettes. The image width and depth are usually the same and multiples of 16 up to 128. Use [[_UNSIGNED]] [[_BYTE]] values in the Entry header.
* Normal Icon and Cursor sizes are multiples of 16 such as 16 X 16, 32 X 32, 48 X 48 and 64 X 64.
* Each image has an XOR and an AND image mask to allow background transparency in the white pixel areas. Change background areas to white in the [[AND]] mask for irregular shapes.
* The [[XOR]] mask is normally different colors while the [[AND]] mask is 1 BPP where black is translucent(solid) and white transparent.
* The AND image mask is placed on a background using a process like [[PUT (graphics statement)|PUT]] with the AND action by the Operating System.
* Then the [[XOR]] mask is placed on top of the blackened areas to display the image colors.
* The resulting image can allow any background to be seen through the [[AND]] mask parts of the image that are white.
::* The Icon header is only six bytes. The first [[INTEGER]] value is reserved and is always 0.
::* The second [[INTEGER]] indicates the type of file:
:::* 1 indicates that the file is an ICO Icon file which may hold more than one image.
:::* 2 indicates that the file is a CUR Cursor file which may hold more than one image.
::* The third [[INTEGER]] value indicates the number of images contained in the file. This will also tell you the number of Icon Entry information headers follow. A [[TYPE]] array can be used to reference the entry and BMP header information later when there is more than one image. The start of all bitmap header and image data information is after 6 + (count * 16) bytes.
: The Entry header information for all icon images contained in the icon file follow the icon header. No image data will be found until after all of the Entry information. Each entry contains the dimensions, size of data and the location of the start of image data.
::* The image width and height are [[_BYTE]] numerical values or [[ASC]] [[ASCII]] code [[STRING]] values.
::* The number of colors is a [[_BYTE]] value which may be zero. Use the Bitmap header's BPP value instead.
::* The reserved [[_BYTE]] value is always zero.
::* The 2 Hotspot [[INTEGER]] values are always 0 unless the file is a CUR cursor file. Cursor files position the click spot.
::* The [[LONG]] Data Size value should indicate the size of the image data including bitmap header, palette and pixel data.
::* The [[LONG]] Data Offset value will indicate the byte position of the image bitmap header. Add one byte in QB and QB64.
: The Bitmap header information is located one byte after the Data Offset position because QBasic sets the first byte of a file as 1 instead of zero. This bitmap image information is identical to a bitmap image header's last 40 bytes, but the height is doubled.
│ 6B │ │16 B │ │ 40 B │ │½ byte │ │32*32*½│ │32*32\8│
└──────┘ └─────┘ └──────┘ │ 64 B │ │ 512 B │ │ 128 B │
└───────┘ └───────┘ └───────┘
'''Multiple Image (3)'''
┌──────┐ ┌───────┐ ┌───────┐ ┌───────┐
│ ICON │ │ Entry │ │ Entry │ │ Entry │
│Header├─6─┤ [1] ├─22─┤ [2] ├─38─┤ [3] ├─54─┐ Entry precedes all data
│ 6B │ │ 16 B │ │ 16 B │ │ 16 B │ │
└──────┘ └───────┘ └───────┘ └───────┘ │
┌───◄ GET Offset + 1 = 55◄─────────┘
┌───┴───┐ ┌───────┐ ┌───────┐
│ BMP[1]│ │ BMP[2]│ │ BMP[3]│
│Header │ ┌─┤Header │ ┌─┤Header │ Image settings
│ 40 B │ │ │ 40 B │ │ │ 40 B │
└───┬───┘ │ └───┬───┘ │ └───┬───┘
┌───┴───┐ ▲ ┌───┴───┐ ▲ │
│PALETTE│ O │PALETTE│ O │
│ 4 BPP │ f │ 8 BPP │ f 24 BPP RGB color intensities
│½ byte │ f │1 byte │ f 3 byte
│ 64 B │ s │1024 B │ s │
└───┬───┘ e └───┬───┘ e │
┌───┴───┐ t ┌───┴───┐ t ┌───┴───┐
│ XOR │ + │ XOR │ + │ XOR │
│16*16*½│ 1 │32*32*1│ 1 │48*48*3│ Image color data
│ 128 B │ ▲ │1024 B │ ▲ │6912 B │
└───┬───┘ │ └───┬───┘ │ └───┬───┘
┌────┴───┐ │ ┌───┴───┐ │ ┌───┴────┐
│ AND │ │ │ AND │ │ │ AND │
│ 1 BPP ├──┘ │ 1 BPP ├──┘ │ 1 BPP │ B & W mask
│16*(2+2)│ │32*32\8│ │48*(6+2)│
│ 64 B │ │ 128 B │ │ 384 B │
└────────┘ └───────┘ └────────┘
Add one to Offset position when using one TYPE definition GET for the BMP Header data!
BPP = bits per pixel B = bytes +2 = padder bytes
{{WhiteEnd}}
<center>'''Palette Data'''</center>
:The Palette is only used in '''4 BPP''' and '''8 BPP''' Icons or Cursors. It is exactly the same format as a bitmap. The number of available colors determines the size of palette data. The data is read as blue, green, red [[_BYTE|byte]]s with a zero([[CHR$]](0)) spacer so the palette size is 4 times the number of available colors: 4 BPP = 4 * (2 ^ 4) = 64 bytes and 8 BPP = 4 * (2 ^ 8) = 1024 bytes.
: The palette sets the Blue, Green and Red color intensities before each color attribute value is read in the image's pixel data.
<center>'''XOR Mask Image Data'''</center>
:The [[XOR]] mask is found after the Palette in 4 BPP or 8 BPP or immediately after the icon BMP Header if 1 BPP or 24 BPP colors. The XOR data is also read the same as a bitmap. The BPP determines the size of the data as bits per pixel:
:::* 1 BPP is one bit per pixel (on white or off black) or bytes = (width * height) / 8 bits
:::* 4 BPP is four bits per pixel attribute or bytes = (4 * width * height) / 8 bits
:::* 8 BPP is one byte per pixel attribute or bytes = (8 * width * height) /8 bits
:::* 24 BPP is 3 bytes per pixel (blue, green, red) or bytes = (24 * width * height) / 8 bits
: All color settings use 4 byte padding to prevent image skewing although most icons use multiples of 8 pixels and won't need it.
: The color intensity of each 24 bit pixel is read as blue, green and red bytes. See the [[Bitmaps]] page for more information.
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p>
==AND Mask Data==
:The AND mask is read as a '''one BPP''' black and white image with each [[_BIT]] being on(white) or off(black). It is white where the background may show and black where the colors (including black) from the XOR mask will show. It is placed using the AND action by Windows first. Then the XOR mask is placed on top using an XOR action. The following SUB procedure can adapt to 24 bit colors so that colors will not be affected. Make sure that the BPP value is [[SHARED]] or pass it using a parameter!
: A [[CHR$|zero]] byte or [[SPACE$|space]] padder is used in the AND mask for image widths that are not multiples of 4 bytes(32 pixels).
{{CodeStart}} '' ''
{{Cl|SUB}} ANDMask 'MASK is B & W. Black area holds {{Cl|XOR}} colors, white displays background
BitsOver = Entry(i).PWidth& {{Cl|MOD}} 32
{{Cl|IF}} BitsOver {{Cl|THEN}} ZeroPAD$ = {{Cl|SPACE$}}((32 - BitsOver) \ 8) 'look for sizes not multiples of 32 bits
{{Cl|_DEST}} bmp& 'destination handle if used
y = Entry(i).PDepth - 1: a$ = " ": p$ = " "
{{Cl|DO}}
x = 0
{{Cl|DO}}
{{Cl|GET}} #1, , a$ 'position is immediately AFTER XOR mask data
ByteVAL = {{Cl|ASC}}(a$) 'MSBit is left when calculating 16 X 16 cursor map 2 byte integer