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