|  |  |  |  | 
 24
 Bitmaps
  
24
 BitmapsBitmap.h declares the API that this chapter describes. For more information on windows, see the section "Bitmaps"  in the Palm OS Programmer's Companion. 
BitmapCompressionType enum specifies possible bitmap compression types. These are the possible values for the compressionType field of typedef enum {    BitmapCompressionTypeScanLine = 0,    BitmapCompressionTypeRLE,    BitmapCompressionTypeNone = 0xFF} BitmapCompressionType;
BitmapFlagsType bit field defines the flags field of typedef struct BitmapFlagsType {    UInt16 compressed:1;    UInt16 hasColorTable:1;    UInt16 hasTransparency:1;    UInt16 indirect:1;    UInt16 forScreen:1;    UInt16 reserved:11;} BitmapFlagsType;
compressed and hasColorTable are only defined if 3.5 New Feature Set is present. Note that the size of this structure did not change. 
BitmapPtr type defines a pointer to a typedef BitmapType *BitmapPtr;BitmapType structure represents a bitmap. This structure defines both the bitmaps representing the window display and bitmap resources ('Tbmp' and 'tAIB') that you create using Constructor or some other application and load into your program. 
typedef struct BitmapType {    Int16	 	 	 	 	 	 	 	 width;    Int16  	 	 	 	 	 	 	 	 height;    UInt16  	 	 	 	 	 	 	 	 rowBytes;    BitmapFlagsType	 	 	 	 	 	 	 	 flags;    UInt8	 	 	 	 	 	 	 	 pixelSize;    UInt8	 	 	 	 	 	 	 	 version;    UInt16	  	 	 	 	 	 	 	 nextDepthOffset;    UInt8	 	 	 	 	 	 	 	 transparentIndex;    UInt8	 	 	 	 	 	 	 	 compressionType;    UInt16	  	 	 	 	 	 	 	 reserved;} BitmapType;
| width | The width of the bitmap in pixels. You specify this value when you create the bitmap. | 
| height | The height of the bitmap in pixels. You specify this value when you create the bitmap. | 
| rowBytes | The number of bytes stored for each row of the bitmap where heightis the number of rows. | 
| flags | The bitmap's attributes. See BitmapFlagsType. | 
| pixelSize | The pixel depth. Currently supported pixel depths are 1, 2, 4, and 8-bit. You specify this value when you create the bitmap. | 
| version | The version of bitmap encoding used. See Bitmap Constants. | 
| nextDepthOffset | For bitmap families, this field specifies the start of the next bitmap in the family. The value it contains is the number of 4-byte words to the next BitmapTypefrom the beginning of this one. If the bitmap is not part of a bitmap family or it is the last bitmap in the family, thenextDepthOffsetis 0. | 
| transparentIndex | The color index for the transparent color. Only used for version 2 bitmaps and only when the transparentflag is set inflags. You specify this value when you create the bitmap using Constructor. | 
| compressionType | The compression type used. Only used for version 2 bitmaps and only when the compressedflag is set inflags. SeeBitmapCompressionTypefor possible values. TheBmpCompressfunction sets this field. | 
| reserved | Reserved for future use. Must be set to 0. | 
BitmapType structure: 
BitmapType header structure. If the bitmap has its own color table, the color table is stored in between the header and the data. You can retrieve a bitmap's data by passing its BitmapType structure to BitmapType does not store the bitmap's location on the screen. The BitmapType represents a bitmap family, the nextDepthOffset field contains the offset from the start of this bitmap to the next bitmap in the family. transparentIndex and compressionType flags are defined only if 3.5 New Feature Set is present.
ColorTableType structure defines a color table. Bitmaps can have color tables attached to them; however, doing so is not recommended for performance reasons. 
typedef struct ColorTableType {    UInt16	 	 	 	 	 	 	 	 numEntries;    // RGBColorType	 	 	 	 	 	 	 	 entry[];} ColorTableType;
numEntries. Use the macro RGBColorType structure defines a color. It is used as an entry in the color table. RGBColorTypes can also be created manually and passed to several user interface functions. 
typedef struct RGBColorType {    UInt8 index;    UInt8 r;    UInt8 g;    UInt8 b;} RGBColorType;
'Tbmp' for most images and the resource type 'tAIB' for application icons. Symbolically, these two resource types are bitmapRsc an iconType, respectively. 
 
'tbmf' resource (or 'taif' resource for icons) and one or more 'PICT' images, and the PalmRez post linker converts them into a single 'Tbmp' or 'tAIB' resource. Note that the PalmRez post linker takes PICT images even on the Microsoft Windows operating system. 
UInt16 BmpBitsSize (BitmapType *bitmapP)
indirect flag is set. (See UInt16 BmpColortableSize (BitmapType *bitmapP)
Err BmpCompress (BitmapType *bitmapP, BitmapCompressionType compType)
|   | ->  | Pointer to the bitmap to compress. (See BitmapType.) | 
|   | ->  | The type of compression to use. (See BitmapCompressionType.) If set toBitmapCompressionTypeNoneandbitmapPis compressed, this function uncompresses the bitmap. | 
|   |  | Success. | 
|   |  | Either the compTypeparameter does not specify a compression type or the bitmap is already compressed, is in the storage heap, or represents the screen. | 
|   |  | There is not enough memory available to complete the operation. | 
BitmapType *BmpCreate (Coord width, Coord height, UInt8 depth, ColorTableType *colortableP, UInt16 *error)
|   | ->  | The width of the bitmap in pixels. Must not be 0. | 
|   | ->  | The height of the bitmap in pixels. Must not be 0. | 
|   | ->  | The pixel depth of the bitmap. Must be 1, 2, 4 or 8. This value is used as the pixelSizefield ofBitmapType. | 
|   | <-  | Contains the error code if an error occurs. | 
NULL if an error occurs. The parameter error contains one of the following:
|   |  | Success. | 
|   |  | The width,height,depth, orcolorTablePparameter is invalid. See the descriptions above for acceptable values. | 
|   |  | There is not enough memory available to allocate the structure. | 
BitmapVersionTwo bitmap with the width, height, and depth that you specify. 
 
hasColorTable flag is set. For performance reasons, attaching a custom color table to a bitmap is strongly discouraged. An alternative is to use the BitmapType *bmpP;WinHandle win;Err error;RectangleType onScreenRect;bmpP = BmpCreate(10, 10, 8, NULL, &error);if (bmpP) {    win = WinCreateBitmapWindow(bmpP, &error);    if (win) {    	 WinSetDrawWindow(win);    	 WinDrawLines(win, ...);    	 /* etc */    	 WinSetWindowBounds(win, onScreenRect);    }}BmpCreate to load a bitmap stored in a resource. Instead, you simply load the resource and lock its handle. The returned pointer is a pointer to a BitmapType. For example: 
MemHandle resH =     DmGetResource (bitmapRsc, rscID);BitmapType *bitmap = MemHandleLock (resH);Err BmpDelete (BitmapType *bitmapP)
errNone upon success, sysErrParamErr if the bitmap's forScreen flag is set or the bitmap resides in the storage heap. Returns one of the memory errors if the freeing the pointer fails. 
void *BmpGetBits (BitmapType *bitmapP)
indirect flag is set. (See ColorTableType *BmpGetColortable (BitmapType *bitmapP)
NULL if the bitmap uses the system color table. 
UInt16 BmpSize (BitmapType *bitmapP)
indirect flag set (see ColorTableEntries (ctP)
BitmapType *bmpP;RGBColorType *tableP =     ColorTableEntries(BmpGetColorTable(bmpP));RGBColorType table;Err e;/* allocate space for table */e = WinPalette(winPaletteGet, 0, 256, &table);|   |  |  |  |  |   |