]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dibutils.h
- Modify #if to include wxCocoa as a platform using wxBitmapBase
[wxWidgets.git] / include / wx / msw / dibutils.h
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _DIBUTILS_H
13 #define _DIBUTILS_H
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
26 PDIB wxDibOpenFile(LPTSTR szFile);
27 int wxDibWriteFile(LPTSTR szFile, LPBITMAPINFOHEADER lpbi);
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);
31 HPALETTE wxMakePalette(const BITMAPINFO FAR* Info, UINT flags);
32
33 /****************************************************************************
34 Internal function declarations
35 ***************************************************************************/
36
37 PDIB wxDibReadBitmapInfo(HFILE fh);
38
39 /****************************************************************************
40 DIB macros.
41 ***************************************************************************/
42
43 #ifdef WIN32
44 #define wxHandleFromDib(lpbi) GlobalHandle(lpbi)
45 #else
46 #define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
47 #endif
48
49 #define wxDibFromHandle(h) (PDIB)GlobalLock(h)
50
51 #define wxDibFree(pdib) GlobalFreePtr(pdib)
52
53 #define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
54
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)
59
60 #define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
61 #define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount)
62
63 #define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
64 ? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
65 : (lpbi)->biSizeImage)
66
67 #define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
68 #define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD))
69
70 #define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
71
72 //HACK for NT BI_BITFIELDS DIBs
73 #ifdef __WIN32__
74 #define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
75 ? (LPVOID)(wxDibColors(lpbi) + 3) \
76 : (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
77 #else
78 #define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
79 #endif
80
81 #define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
82
83 #define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
84 ? (int)(1 << (int)(lpbi)->biBitCount) \
85 : (int)(lpbi)->biClrUsed)
86
87 #define wxDibXYN(lpbi,pb,x,y,n) (LPVOID)( \
88 (BYTE _huge *)(pb) + \
89 (UINT)((UINT)(x) * (UINT)(n) / 8u) + \
90 ((DWORD)wxDibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
91
92 #define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount)
93
94 #define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
95 (lpbi)->biSizeImage = wxDibSizeImage(lpbi); \
96 if ((lpbi)->biClrUsed == 0) \
97 (lpbi)->biClrUsed = wxDibNumColors(lpbi);
98
99 // if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0)
100 // ; // (lpbi)->biClrUsed = 3;
101
102 #define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
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
115 // _DIBUTILS_H