Creating a new Image Type - An Example

SSch I needed some high performance image type for Windows which supports transparency. I achieved up to 100 fps on my Pentium III/500 using device independant bitmaps (DIB's) and the BitBlt() API function.

Here is the source code:

For each image there are two bitmaps, one palettized 8 color image (there is space for 256 colors but only the first eight entries are set). And a 32 bits per pixel RGB bitmap. For the indexed bitmap the colors are defined as follows:

 0 #000 (black)
 1 #F00 (red)
 2 #0F0 (green)
 3 #FF0 (yellow)
 4 #00F (blue)
 5 #F0F (magenta)
 6 #0FF (cyan)
 7 #FFF (white)

For the RGB Bitmap the 32 bit values are formatted as 0RGB (One byte for red, green and blue, the first (most significant) byte is unused)

The image data can be accessed directly via pImageData/pMaskData. Example:

 pMaster->pImageData[ 20 + 30 * pMaster->nImagePitch ] = 0x00ff0000;
 (set the pixel at position 20/30 red)

The Bit-blitting can be influenced by specifying the operation mode (-rgb / -mask flags). See MSDN reference for details. If said flags are set to 'unused' the corresponding bitmap will be ignored (and destroyed).

Using both bitmaps (the mask is blitted first) allows setting up images with transparency via the 'black source methode'. But many other effects are possible as well (see DimgDemo.tcl).

I know there should be many more access functions in addition to fill and oval (especially copying from and to photo images would be useful), but i prefer to keep this simple in order to demonstrate how to build an new image type in general.