3 * Purpose: BMP Image Class Loader and Writer
\r
5 /* ==========================================================
\r
6 * CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
\r
7 * For conditions of distribution and use, see copyright notice in ximage.h
\r
9 * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
\r
11 * original CImageBMP and CImageIterator implementation are:
\r
12 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
\r
14 * ==========================================================
\r
17 #if !defined(__ximaBMP_h)
\r
22 const int RLE_COMMAND = 0;
\r
23 const int RLE_ENDOFLINE = 0;
\r
24 const int RLE_ENDOFBITMAP = 1;
\r
25 const int RLE_DELTA = 2;
\r
27 #if !defined(BI_RLE8)
\r
30 #if !defined(BI_RLE4)
\r
34 #if CXIMAGE_SUPPORT_BMP
\r
36 class CxImageBMP: public CxImage
\r
39 CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {};
\r
41 bool Decode(CxFile * hFile);
\r
42 bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
\r
44 #if CXIMAGE_SUPPORT_ENCODE
\r
45 bool Encode(CxFile * hFile);
\r
46 bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
\r
47 #endif // CXIMAGE_SUPPORT_ENCODE
\r
50 bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib);
\r
53 #define BFT_ICON 0x4349 /* 'IC' */
\r
54 #define BFT_BITMAP 0x4d42 /* 'BM' */
\r
55 #define BFT_CURSOR 0x5450 /* 'PT' */
\r
58 #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
\r
63 #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
\r
64 #define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount)
\r
66 #define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
\r
67 ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
\r
68 : (lpbi)->biSizeImage)
\r
70 #define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
\r
71 ? (int)(1 << (int)(lpbi)->biBitCount) \
\r
72 : (int)(lpbi)->biClrUsed)
\r
74 #define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
\r
75 (lpbi)->biSizeImage = DibSizeImage(lpbi); \
\r
76 if ((lpbi)->biClrUsed == 0) \
\r
77 (lpbi)->biClrUsed = DibNumColors(lpbi); \
\r