]> Creatis software - clitk.git/blob - utilities/CxImage/ximabmp.h
Debug RTStruct conversion with empty struc
[clitk.git] / utilities / CxImage / ximabmp.h
1 /*
2  * File:        ximabmp.h
3  * Purpose:     BMP Image Class Loader and Writer
4  */
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
8  *
9  * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
10  *
11  * original CImageBMP  and CImageIterator implementation are:
12  * Copyright:   (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
13  *
14  * ==========================================================
15  */
16
17 #if !defined(__ximaBMP_h)
18 #define __ximaBMP_h
19
20 #include "ximage.h"
21
22 const int RLE_COMMAND     = 0;
23 const int RLE_ENDOFLINE   = 0;
24 const int RLE_ENDOFBITMAP = 1;
25 const int RLE_DELTA       = 2;
26
27 #if !defined(BI_RLE8)
28  #define BI_RLE8  1L
29 #endif
30 #if !defined(BI_RLE4)
31  #define BI_RLE4  2L
32 #endif
33
34 #if CXIMAGE_SUPPORT_BMP
35
36 class CxImageBMP: public CxImage
37 {
38 public:
39         CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {};
40
41         bool Decode(CxFile * hFile);
42         bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
43
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
48
49 protected:
50         bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib);
51 };
52
53 #define BFT_ICON   0x4349   /* 'IC' */
54 #define BFT_BITMAP 0x4d42   /* 'BM' */
55 #define BFT_CURSOR 0x5450   /* 'PT' */
56
57 #ifndef WIDTHBYTES
58 #define WIDTHBYTES(i)           ((unsigned)((i+31)&(~31))/8)  /* ULONG aligned ! */
59 #endif
60
61 #endif
62
63 #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
64 #define DibWidthBytes(lpbi)     DibWidthBytesN(lpbi, (lpbi)->biBitCount)
65
66 #define DibSizeImage(lpbi)      ((lpbi)->biSizeImage == 0 \
67                                     ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
68                                     : (lpbi)->biSizeImage)
69
70 #define DibNumColors(lpbi)      ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
71                                     ? (int)(1 << (int)(lpbi)->biBitCount)          \
72                                     : (int)(lpbi)->biClrUsed)
73
74 #define FixBitmapInfo(lpbi)     if ((lpbi)->biSizeImage == 0)                 \
75                                                                                                 (lpbi)->biSizeImage = DibSizeImage(lpbi); \
76                                 if ((lpbi)->biClrUsed == 0)                   \
77                                     (lpbi)->biClrUsed = DibNumColors(lpbi);   \
78
79 #endif