00001
00007 #ifndef CTLDEF_H
00008 #include "ctl/ctldef.h"
00009 #endif
00010 #ifndef OPC_H
00011 #include "opc/opc.h"
00012 #endif
00013
00014 #if !defined(_WINGDI_)
00015 #pragma pack(push,1)
00016 #define BI_RGB 0L
00017 #define BI_RLE8 1L
00018 #define BI_RLE4 2L
00019 #define BI_BITFIELDS 3L
00020 typedef struct tagBITMAPINFOHEADER
00021 {
00022 uint32 biSize;
00023 int32 biWidth;
00024 int32 biHeight;
00025 uint16 biPlanes;
00026 uint16 biBitCount;
00027 uint32 biCompression;
00028 uint32 biSizeImage;
00029 int32 biXPelsPerMeter;
00030 int32 biYPelsPerMeter;
00031 uint32 biClrUsed;
00032 uint32 biClrImportant;
00033 } BITMAPINFOHEADER;
00034 typedef struct tagRGBQUAD
00035 {
00036 uint8 rgbBlue;
00037 uint8 rgbGreen;
00038 uint8 rgbRed;
00039 uint8 rgbReserved;
00040 } RGBQUAD;
00041 typedef struct tagBITMAPINFO
00042 {
00043 BITMAPINFOHEADER bmiHeader;
00044 RGBQUAD bmiColors[1];
00045 } BITMAPINFO;
00046 typedef struct tagBITMAPFILEHEADER
00047 {
00048 uint16 bfType __attribute__ ((packed));
00049 uint32 bfSize __attribute__ ((packed));
00050 uint16 bfReserved1 __attribute__ ((packed));
00051 uint16 bfReserved2 __attribute__ ((packed));
00052 uint32 bfOffBits __attribute__ ((packed));
00053 } BITMAPFILEHEADER;
00054 #pragma pack(pop)
00055 #endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #define BMI_SIZE (sizeof(BITMAPINFO) + (255 * sizeof(RGBQUAD)))
00083 #define BMI_Alloc() ((BITMAPINFO *)calloc( 1, BMI_SIZE ))
00084 #define BMI_Free(bmi) free(bmi)
00085 #define BMI_BMI_Copy(bmi) memcpy( BMI_Alloc(), bmi, BMI_BMI_Size(bmi) )
00086 #define BMI_UpsideDown(bmi) ((bmi)->bmiHeader.biHeight > 0)
00087 #define BMI_Wide(bmi) (abs((bmi)->bmiHeader.biWidth))
00088 #define BMI_High(bmi) (abs((bmi)->bmiHeader.biHeight))
00089 #define BMI_Depth(bmi) ((bmi)->bmiHeader.biBitCount)
00090 #define BMI_Compressed(bmi) !((bmi)->bmiHeader.biCompression==BI_RGB||(bmi)->bmiHeader.biCompression==BI_BITFIELDS)
00091 #define BMI_LineSize(bmi) ((((BMI_Wide(bmi)*BMI_Depth(bmi))+31)&~31)>>3)
00092 #define BMI_BitmapSize(bmi) (BMI_Compressed(bmi)?(bmi)->bmiHeader.biSizeImage:(BMI_LineSize(bmi)*BMI_High(bmi)))
00093 #define BMI_ColorCount(bmi) ((bmi)->bmiHeader.biClrUsed ? (bmi)->bmiHeader.biClrUsed : (1 << BMI_Depth(bmi)))
00094 #define BMI_Header(bmi) (&(bmi)->bmiHeader)
00095 #define BMI_ColorData(bmi) ((bmi)->bmiColors)
00096 #define BMI_Origin(bmi,bits) ( BMI_UpsideDown(bmi) ? (void*)(((uint8 *)(bits)) + (BMI_LineSize(bmi)*(BMI_High(bmi)-1))) : (void*)(bits) )
00097 #define BMI_LineOffset(bmi) (BMI_UpsideDown(bmi)?-(int)BMI_LineSize(bmi):(int)BMI_LineSize(bmi))
00098 #define BMI_LinePtr(bmi,bits,line) ((void *)((uint8 *)BMI_Origin(bmi,bits)+((line)*BMI_LineOffset(bmi))))
00099 #define BMI_Clip(bmi,rect) (((rect).left = (rect).top = 0),(rect).right=BMI_Wide(bmi),(rect).bottom=BMI_High(bmi))
00100 #define BMI_BMI_Size(bmi) ( (bmi)->bmiHeader.biSize + \
00101 ( ( (bmi)->bmiHeader.biBitCount <= 8 ) ? \
00102 ( ((bmi)->bmiHeader.biClrUsed ? (bmi)->bmiHeader.biClrUsed : (1 << (bmi)->bmiHeader.biBitCount)) * sizeof(RGBQUAD) ) : \
00103 ( ((bmi)->bmiHeader.biBitCount == 24 || (bmi)->bmiHeader.biCompression != BI_BITFIELDS) ? 0 : (3 * sizeof(uint32)) ) ) )
00104 #define BMI_SetColorIndexes( bmi ) \
00105 { \
00106 uint16 *pData = (uint16 *)BMI_ColorData(bmi); \
00107 int curr; \
00108 for( curr = 0; curr < 256; ++curr ) \
00109 *pData++ = curr; \
00110 }
00111
00118 #define BMI_ParseData( image, bmi, bits )\
00119 {\
00120 if( *((uint16 *)(image)) == *((uint16 *)"BM") ) \
00121 {\
00122 \
00123 (bmi) = (BITMAPINFO *)( (uint8 *)(image) + sizeof(BITMAPFILEHEADER) );\
00124 (bits) = (uint8 *)(image) + ((BITMAPFILEHEADER *)image)->bfOffBits;\
00125 }\
00126 else \
00127 {\
00128 \
00129 (bmi) = (BITMAPINFO *)(image);\
00130 (bits) = (uint8 *)(bmi) + BMI_BMI_Size( bmi );\
00131 }\
00132 }
00133
00140 #define BMI_Init( bmi, wide, high, bpp ) \
00141 {\
00142 BITMAPINFOHEADER* pbmi = &(bmi)->bmiHeader;\
00143 pbmi->biSize = sizeof(BITMAPINFOHEADER);\
00144 pbmi->biWidth = (wide);\
00145 pbmi->biHeight = (high);\
00146 pbmi->biPlanes = 1;\
00147 pbmi->biBitCount = (bpp);\
00148 pbmi->biCompression = BI_RGB;\
00149 pbmi->biSizeImage = 0;\
00150 pbmi->biXPelsPerMeter = 0;\
00151 pbmi->biYPelsPerMeter = 0;\
00152 pbmi->biClrUsed = 0;\
00153 pbmi->biClrImportant = 0;\
00154 }
00155
00160 #define BMI_Create( bmi, bits ) { (bits) = calloc( BMI_LineSize(bmi), BMI_High(bmi) ); }
00161
00166 #define BMI_Release( bmi, bits ) { free( bits ); }
00167
00168
00169
00170
00171 #define BMI_foreach( bmi, bits, pixel ) \
00172 RGBQUAD pixel##_buff[2048];\
00173 int pixel##_row;\
00174 const RGBQUAD* pixel##_end = pixel##_buff + BMI_Wide(bmi);\
00175 RGBQUAD* pixel;\
00176 assert( BMI_Wide(bmi) < countof(pixel##_buff) );\
00177 for( pixel##_row = 0; BMI_ReadRow( pixel##_buff, bmi, bits, pixel##_row ); ++pixel##_row )\
00178 for( pixel = pixel##_buff; pixel < pixel##_end; ++pixel )\
00179
00180 int RGBQUAD_Nearest( const RGBQUAD* clut, size_t count, const RGBQUAD* color );
00181 bool BMI_ReadRow( RGBQUAD* pixel, const BITMAPINFO* bmi, const void* bits, int row );
00182 bool BMI_WriteRow( const BITMAPINFO* bmi, void* bits, const RGBQUAD* pixel, int row );
00183 void BMI_Translate( const BITMAPINFO* dst, void* bdst, const BITMAPINFO* src, const void* bsrc );
00184 void* BMI_Unpack( const BITMAPINFO* bmi, const void* bits );
00185 size_t BMI_MakeClut( RGBQUAD* dstlut, size_t clut, const BITMAPINFO* bmi, const void* bits );
00186
00187 struct BMIClutEntry
00188 {
00189 uint32 count;
00190 RGBQUAD rgb;
00191 };
00192 typedef struct BMIClut
00193 {
00194 struct BMIClutEntry cluts[32768];
00195 } BMIClut;
00196 void BMI_Clut_Begin( BMIClut* clut );
00197 void BMI_Clut_AddColor( BMIClut* clut, const RGBQUAD* rgb );
00198 size_t BMI_Clut_Make( BMIClut* clut, RGBQUAD* dstlut, size_t cClut );
00199
00200 bool BMI_Save( const char* path, const BITMAPINFO* bmi, const void* bits );
00201 bool BMI_Load( const char* path, BITMAPINFO** bmi, void** bits );
00202
00203
00204
00205 void BMI_OPC( OPC* opc, const BITMAPINFO* bmi, void* bits );
00206