00001 /****************************************************************************** 00002 * 00003 * Copyright (c) 2002-2005 Palm, Inc. or its subsidiaries. 00004 * All rights reserved. 00005 * 00006 * File: BmpRsrc.h 00007 * 00008 * Description: 00009 * This file defines structures for bitmap objects which can be stored 00010 * in resources. The bitmap format for these is well defined and 00011 * supported, and you have access to the internals. This header is 00012 * intended for 68K code, the structures should be assumed to be 00013 * "big endian" and 2-byte aligned. 00014 * 00015 *****************************************************************************/ 00016 /***************************************************************************** 00017 * 00018 * $RCSfile: BitmapRsrc_8h-source.html,v $ 00019 * 00020 * $Author: mp $ 00021 * 00022 * $Date: 2007-10-08 20:40:32 $ 00023 * 00024 * $Revision: 1.1.2.1 $ 00025 * 00026 * $Log: BitmapRsrc_8h-source.html,v $ 00026 * Revision 1.1.2.1 2007-10-08 20:40:32 mp 00026 * updated for gps4palm V0.9.5 beta 00026 * 00027 * Revision 1.1 2005-04-08 14:44:39 mp 00028 * imported from 'Bitmap Resource' sample code by PalmSource 00029 * 00030 * 00031 ****************************************************************************/ 00032 00033 #ifndef __BMPRSRC_H__ 00034 #define __BMPRSRC_H__ 00035 00036 #include <PalmTypes.h> 00037 00038 00039 // BmpRsrc version numbers 00040 #define BmpRsrcVersionZero 0 00041 #define BmpRsrcVersionOne 1 00042 #define BmpRsrcVersionTwo 2 00043 #define BmpRsrcVersionThree 3 00044 00045 00046 // Compression Types for BmpRsrcVersionTwo 00047 typedef enum BmpRsrcCompressionTag 00048 { 00049 BmpRsrcCompressionTypeScanLine = 0, 00050 BmpRsrcCompressionTypeRLE, 00051 BmpRsrcCompressionTypePackBits, 00052 00053 BmpRsrcCompressionTypeEnd // must follow last compression algorithm 00054 } BmpRsrcCompressionType; 00055 00056 00057 /* 00058 // pixel format defined with BmpRsrcVersionThree 00059 typedef enum PixelFormatTag 00060 { 00061 pixelFormatIndexed, // standard for Palm 68k; standard for BMPs 00062 pixelFormat565, // standard for Palm 68k 00063 pixelFormat565LE, // standard for BMPs; popular on ARM hardware 00064 pixelFormatIndexedLE // popular on ARM hardware 00065 } PixelFormatType; 00066 00067 00068 // constants used by density field 00069 typedef enum DensityTag { 00070 kDensityLow = 72, 00071 kDensityOneAndAHalf = 108, 00072 kDensityDouble = 144, 00073 kDensityTriple = 216, 00074 kDensityQuadruple = 288 00075 } DensityType; 00076 */ 00077 00078 00079 typedef enum BmpRsrcFlag 00080 { 00081 // These flags enumerate the BmpRsrcFlagsType bitfield 00082 kCompressedFlag = 0, 00083 kHasColorTableFlag, 00084 kHasTransparencyFlag, 00085 kIndirectFlag, 00086 kPrivate4Flag, 00087 kDirectColorFlag, 00088 kIndirectColorTableFlag, 00089 kNoDitherFlag 00090 } BmpRsrcFlagEnum; 00091 00092 00093 typedef struct BmpRsrcFlagsType 00094 { 00095 UInt16 compressed:1; // Data format: 0=raw; 1=compressed 00096 UInt16 hasColorTable:1; // if true, color table stored before bits[], only for >= v1 00097 UInt16 hasTransparency:1; // true if transparency is used, only for >= v2 00098 UInt16 indirect:1; // true if bits are stored indirectly, only for >= v2 00099 UInt16 private:1; // system use only, must be 0 00100 UInt16 directColor:1; // direct color bitmap (16 bit color, for example) 00101 UInt16 indirectColorTable:1; // if true, color table pointer follows BitmapType structure 00102 UInt16 noDither:1; // if true, blitter does not dither 00103 UInt16 reserved:8; 00104 } BmpRsrcFlagsType; 00105 00106 00107 typedef struct BmpRsrcV0Type { 00108 Int16 width; // >= 0 00109 Int16 height; // >= 0 00110 UInt16 rowBytes; // (width*pixelSize+15)>>4<<1 00111 BmpRsrcFlagsType flags; // defigned in Bitmap.h 00112 00113 UInt16 reserved[4]; // set all elements to 0 00114 00115 // UInt8 bits[] 00116 00117 } BmpRsrcV0Type; 00118 00119 00120 typedef struct BmpRsrcV1Type 00121 { 00122 Int16 width; // >= 0 00123 Int16 height; // >= 0 00124 UInt16 rowBytes; // (width*pixelSize+15)>>4<<1 00125 BmpRsrcFlagsType flags; 00126 UInt8 pixelSize; // 1, 2, 4, 8, 16 00127 UInt8 version; // 1 00128 00129 UInt16 nextDepthOffset; // longword offset to next member in family 00130 UInt16 reserved[2]; 00131 00132 // ColorTableType (if flags.hasColorTable) 00133 00134 // BitmapDirectInfoType (if pixelSize == 16) 00135 00136 // UInt8 bits[] // actual bits start here, rowBytes * height bytes total. 00137 00138 } BmpRsrcV1Type; 00139 00140 00141 typedef struct BmpRsrcV2Type 00142 { 00143 Int16 width; // >= 0 00144 Int16 height; // >= 0 00145 UInt16 rowBytes; // (width*pixelSize+15)>>4<<1 00146 BmpRsrcFlagsType flags; 00147 UInt8 pixelSize; // 1, 2, 4, 8, 16 00148 UInt8 version; // 2 00149 00150 UInt16 nextDepthOffset; // longword offset to next member in family, 0 for none/last 00151 UInt8 transparentIndex; 00152 UInt8 compressionType; 00153 UInt16 reserved; 00154 00155 // ColorTableType (if flags.hasColorTable) 00156 00157 // BitmapDirectInfoType (if pixelSize==16) 00158 00159 // if (flags.indirect) 00160 // UInt8* bitsP // 4 bytes with pointer to actual bits 00161 // else 00162 // UInt8 bits[] // actual bits start here, rowBytes * height bytes total. 00163 00164 } BmpRsrcV2Type; 00165 00166 00167 typedef struct BmpRsrcV3Type 00168 { 00169 Int16 width; // >= 0 00170 Int16 height; // >= 0 00171 UInt16 rowBytes; // (width*pixelSize+15)>>4<<1 00172 BmpRsrcFlagsType flags; 00173 UInt8 pixelSize; // 1, 2, 4, 8, 16 00174 UInt8 version; // 3 00175 00176 UInt8 size; // size of this structure in bytes (0x16) 00177 UInt8 pixelFormat; // format of the pixel data, see pixelFormatType 00178 UInt8 unused; 00179 UInt8 compressionType; // see BitmapCompressionType 00180 UInt16 density; // used by the blitter to scale bitmaps 00181 UInt32 transparentValue; // the index or RGB value of the transparent color 00182 UInt32 nextBitmapOffset; // byte (not longword!) offset to next member in family 00183 00184 // if (flags.hasColorTable) 00185 // { 00186 // if (flags.indirectColorTable) 00187 // ColorTableType* colorTableP; // pointer to color table 00188 // else 00189 // ColorTableType colorTable; // color table, could have 0 entries (2 bytes long) 00190 // } 00191 // 00192 // if (flags.indirect) 00193 // UInt8* bitsP // 4 bytes with pointer to actual bits 00194 // else 00195 // UInt8 bits[] // actual bits start here, rowBytes * height bytes total. 00196 00197 } BmpRsrcV3Type; 00198 00199 00200 typedef union BmpRsrcType 00201 { 00202 BmpRsrcV0Type v0; 00203 BmpRsrcV2Type v1; 00204 BmpRsrcV2Type v2; 00205 BmpRsrcV3Type v3; 00206 } BmpRsrcType; 00207 00208 00209 // BitmapFamily is a series of BmpRsrcTypes in ascending order of depth. 00210 // if there are high density images, then there is a dummy (BmpRsrcV1Type with pixelSize = 0xFF) 00211 // followed by the high density images in ascending order of depth. 00212 00213 00214 00215 00216 #ifdef __cplusplus 00217 extern "C" 00218 { 00219 #endif 00220 00221 // these are all just convenience routines -- you can do everything yourself with the above declarations 00222 00223 BmpRsrcType * BmpRsrcCreate(Int16 width, Int16 height, 00224 Int16 pixelSize, // 1, 2, 4, 8, 16 00225 const ColorTableType * ct, // null for no color table (preferred) 00226 Int16 density, // only kDensityLow, kDensityDouble supported 00227 PixelFormatType pixelFormat); 00228 00229 void BmpRsrcDelete(BmpRsrcType * bmp); 00230 00231 00232 // constructors for specific formats (cross-device compatibility) 00233 BmpRsrcType * BmpRsrcV0Create(Int16 width, Int16 height); 00234 BmpRsrcType * BmpRsrcV2Create(Int16 width, Int16 height, 00235 Int16 pixelSize, // 1, 2, 4, 8, 16 00236 const ColorTableType * ct, // null for no color table (preferred) 00237 const UInt8 * indirectBits // null for inline bitmap 00238 ); 00239 BmpRsrcType * BmpRsrcV3Create(Int16 width, Int16 height, 00240 Int16 pixelSize, // 1, 2, 4, 8, 16 00241 const ColorTableType * ct, // null for no color table (preferred) 00242 const UInt8 * indirectBits, // null for inline bitmap 00243 Int16 density, // only kDensityLow, kDensityDouble supported 00244 PixelFormatType pixelFormat 00245 ); 00246 00247 // copy constructor, sorta 00248 BmpRsrcType * BmpRsrcCreateIndirectCopy(const BmpRsrcType * bmp); 00249 00250 00251 // simple accessors 00252 static inline Int16 BmpRsrcGetWidth(const BmpRsrcType * bmp) { return bmp->v0.width; } 00253 static inline Int16 BmpRsrcGetHeight(const BmpRsrcType * bmp) { return bmp->v0.height; } 00254 static inline Int16 BmpRsrcGetRowBytes(const BmpRsrcType * bmp) { return bmp->v0.rowBytes; } 00255 static inline Boolean BmpRsrcGetFlag(const BmpRsrcType * bmp, BmpRsrcFlagEnum which) { return (*(UInt16*)(&bmp->v0.flags) & (0x8000>>which)) ? 1 : 0; } 00256 static inline Int16 BmpRsrcGetVersion(const BmpRsrcType * bmp) { return bmp->v2.version; } 00257 static inline Int16 BmpRsrcGetPixelSize(const BmpRsrcType * bmp) { return bmp->v2.pixelSize==0 ? 1 : bmp->v2.pixelSize; } 00258 00259 // complex accessors 00260 Int32 BmpRsrcGetTotalSize(const BmpRsrcType * bmp); 00261 UInt8 * BmpRsrcGetBits(const BmpRsrcType * bmp); 00262 UInt32 BmpRsrcGetTransparentValue(const BmpRsrcType * bmp); 00263 ColorTableType * BmpRsrcGetColorTable(const BmpRsrcType * bmp); 00264 static inline Int16 BmpRsrcGetDensity(const BmpRsrcType * bmp) { return bmp->v3.version==3 ? bmp->v3.density : 72; } 00265 PixelFormatType BmpRsrcGetPixelFormat(const BmpRsrcType * bmp); 00266 00267 void BmpRsrcSetFlag(BmpRsrcType * bmp, BmpRsrcFlagEnum which, Boolean value); 00268 void BmpRsrcSetTransparentValue(BmpRsrcType * bmp, UInt32 value); 00269 void BmpRsrcSetDensity(BmpRsrcType * bmp, Int16 density); 00270 00271 00272 // accessing pixels 00273 UInt32 BmpRsrcBlackPixelValue(const BmpRsrcType * bmp); 00274 UInt32 BmpRsrcWhitePixelValue(const BmpRsrcType * bmp); 00275 IndexedColorType BmpRsrcBlackPixelIndex(const BmpRsrcType * bmp); 00276 IndexedColorType BmpRsrcWhitePixelIndex(const BmpRsrcType * bmp); 00277 UInt32 BmpRsrcGetPixel(const BmpRsrcType * bmp, Int16 x, Int16 y); 00278 void BmpRsrcSetPixel(BmpRsrcType * bmp, Int16 x, Int16 y, UInt32 value); 00279 00280 00281 // bitmap families 00282 const BmpRsrcType * BmpRsrcGetNextMemberFromFamily(const BmpRsrcType * bmpFamily); 00283 BmpRsrcType * BmpRsrcBestMemberFromFamily(const BmpRsrcType * bmpFamily); 00284 00285 00286 #ifdef __cplusplus 00287 } 00288 #endif 00289 00290 00291 #endif // __BMPRSRC_H__ 00292