]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dibutils.h | |
3 | // Purpose: Utilities for DIBs | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Microsoft, Julian Smart | |
bbcdf8bc | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1cfa5d8e JS |
12 | #ifndef _DIBUTILS_H |
13 | #define _DIBUTILS_H | |
2bda0e17 KB |
14 | |
15 | #ifdef __GNUG__ | |
16 | #pragma interface "dibutils.h" | |
17 | #endif | |
18 | ||
19 | typedef LPBITMAPINFOHEADER PDIB; | |
20 | typedef HANDLE HDIB; | |
21 | ||
22 | /*************************************************************************** | |
23 | External function declarations | |
24 | **************************************************************************/ | |
25 | ||
1cfa5d8e JS |
26 | PDIB wxDibOpenFile(LPTSTR szFile); |
27 | int wxDibWriteFile(LPTSTR szFile, LPBITMAPINFOHEADER lpbi); | |
a61ddc47 UJ |
28 | BOOL wxDibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage); |
29 | PDIB wxDibCreate(int bits, int dx, int dy); | |
30 | BOOL wxDibMapToPalette(PDIB pdib, HPALETTE hpal); | |
1cfa5d8e | 31 | HPALETTE wxMakePalette(const BITMAPINFO FAR* Info, UINT flags); |
2bda0e17 KB |
32 | |
33 | /**************************************************************************** | |
34 | Internal function declarations | |
35 | ***************************************************************************/ | |
36 | ||
a61ddc47 | 37 | PDIB wxDibReadBitmapInfo(HFILE fh); |
2bda0e17 KB |
38 | |
39 | /**************************************************************************** | |
40 | DIB macros. | |
41 | ***************************************************************************/ | |
42 | ||
43 | #ifdef WIN32 | |
a61ddc47 | 44 | #define wxHandleFromDib(lpbi) GlobalHandle(lpbi) |
2bda0e17 | 45 | #else |
a61ddc47 | 46 | #define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi)) |
2bda0e17 KB |
47 | #endif |
48 | ||
a61ddc47 | 49 | #define wxDibFromHandle(h) (PDIB)GlobalLock(h) |
2bda0e17 | 50 | |
a61ddc47 | 51 | #define wxDibFree(pdib) GlobalFreePtr(pdib) |
2bda0e17 | 52 | |
a61ddc47 | 53 | #define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */ |
2bda0e17 | 54 | |
a61ddc47 UJ |
55 | #define wxDibWidth(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth) |
56 | #define wxDibHeight(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biHeight) | |
57 | #define wxDibBitCount(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount) | |
58 | #define wxDibCompression(lpbi) (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression) | |
2bda0e17 | 59 | |
a61ddc47 UJ |
60 | #define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n)) |
61 | #define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount) | |
2bda0e17 | 62 | |
a61ddc47 UJ |
63 | #define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \ |
64 | ? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \ | |
2bda0e17 KB |
65 | : (lpbi)->biSizeImage) |
66 | ||
a61ddc47 UJ |
67 | #define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD)) |
68 | #define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD)) | |
2bda0e17 | 69 | |
a61ddc47 | 70 | #define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y)) |
2bda0e17 KB |
71 | |
72 | //HACK for NT BI_BITFIELDS DIBs | |
d66dcb60 | 73 | #ifdef __WIN32__ |
a61ddc47 UJ |
74 | #define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \ |
75 | ? (LPVOID)(wxDibColors(lpbi) + 3) \ | |
76 | : (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)) | |
2bda0e17 | 77 | #else |
a61ddc47 | 78 | #define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed) |
2bda0e17 KB |
79 | #endif |
80 | ||
a61ddc47 | 81 | #define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize)) |
2bda0e17 | 82 | |
a61ddc47 | 83 | #define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \ |
2bda0e17 KB |
84 | ? (int)(1 << (int)(lpbi)->biBitCount) \ |
85 | : (int)(lpbi)->biClrUsed) | |
86 | ||
a61ddc47 | 87 | #define wxDibXYN(lpbi,pb,x,y,n) (LPVOID)( \ |
2bda0e17 KB |
88 | (BYTE _huge *)(pb) + \ |
89 | (UINT)((UINT)(x) * (UINT)(n) / 8u) + \ | |
a61ddc47 | 90 | ((DWORD)wxDibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y))) |
2bda0e17 | 91 | |
a61ddc47 | 92 | #define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount) |
2bda0e17 | 93 | |
a61ddc47 UJ |
94 | #define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \ |
95 | (lpbi)->biSizeImage = wxDibSizeImage(lpbi); \ | |
2bda0e17 | 96 | if ((lpbi)->biClrUsed == 0) \ |
a61ddc47 | 97 | (lpbi)->biClrUsed = wxDibNumColors(lpbi); |
2917e920 BM |
98 | |
99 | // if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0) | |
100 | // ; // (lpbi)->biClrUsed = 3; | |
2bda0e17 | 101 | |
a61ddc47 | 102 | #define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB)) |
2bda0e17 KB |
103 | |
104 | /***************************************************************************/ | |
105 | ||
106 | #ifndef BI_BITFIELDS | |
107 | #define BI_BITFIELDS 3 | |
108 | #endif | |
109 | ||
110 | #ifndef HALFTONE | |
111 | #define HALFTONE COLORONCOLOR | |
112 | #endif | |
113 | ||
114 | #endif | |
1cfa5d8e | 115 | // _DIBUTILS_H |