]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dibutils.h
Simplified BC++ makefiles; C++Builder 1.0 compilation seems to work;
[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 /***************************************************************************
13
14 (C) Copyright 1994 Microsoft Corp. All rights reserved.
15
16 You have a royalty-free right to use, modify, reproduce and
17 distribute the Sample Files (and/or any modified version) in
18 any way you find useful, provided that you agree that
19 Microsoft has no warranty obligations or liability for any
20 Sample Application Files which are modified.
21
22 **************************************************************************/
23
24 /***************************************************************************
25 Functions for handling Device Independent Bitmaps and clearing the
26 System Palette.
27 **************************************************************************/
28
29 #ifndef SAMPLES_UTILS_H
30 #define SAMPLES_UTILS_H
31
32 #ifdef __GNUG__
33 #pragma interface "dibutils.h"
34 #endif
35
36 typedef LPBITMAPINFOHEADER PDIB;
37 typedef HANDLE HDIB;
38
39 /***************************************************************************
40 External function declarations
41 **************************************************************************/
42
43 void ClearSystemPalette(void);
44 PDIB DibOpenFile(LPSTR szFile);
45 int DibWriteFile(LPSTR szFile, LPBITMAPINFOHEADER lpbi);
46 BOOL DibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage);
47 PDIB DibCreate(int bits, int dx, int dy);
48 BOOL DibMapToPalette(PDIB pdib, HPALETTE hpal);
49 HPALETTE MakePalette(const BITMAPINFO FAR* Info, UINT flags);
50
51 /****************************************************************************
52 Internal function declarations
53 ***************************************************************************/
54
55 PDIB DibReadBitmapInfo(HFILE fh);
56
57 /****************************************************************************
58 DIB macros.
59 ***************************************************************************/
60
61 #ifdef WIN32
62 #define HandleFromDib(lpbi) GlobalHandle(lpbi)
63 #else
64 #define HandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
65 #endif
66
67 #define DibFromHandle(h) (PDIB)GlobalLock(h)
68
69 #define DibFree(pdib) GlobalFreePtr(pdib)
70
71 #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
72
73 #define DibWidth(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth)
74 #define DibHeight(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biHeight)
75 #define DibBitCount(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount)
76 #define DibCompression(lpbi) (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression)
77
78 #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
79 #define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount)
80
81 #define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
82 ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
83 : (lpbi)->biSizeImage)
84
85 #define DibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
86 #define DibPaletteSize(lpbi) (DibNumColors(lpbi) * sizeof(RGBQUAD))
87
88 #define DibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
89
90 //HACK for NT BI_BITFIELDS DIBs
91 #ifdef WIN32
92 #define DibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
93 ? (LPVOID)(DibColors(lpbi) + 3) \
94 : (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
95 #else
96 #define DibPtr(lpbi) (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
97 #endif
98
99 #define DibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
100
101 #define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
102 ? (int)(1 << (int)(lpbi)->biBitCount) \
103 : (int)(lpbi)->biClrUsed)
104
105 #define DibXYN(lpbi,pb,x,y,n) (LPVOID)( \
106 (BYTE _huge *)(pb) + \
107 (UINT)((UINT)(x) * (UINT)(n) / 8u) + \
108 ((DWORD)DibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
109
110 #define DibXY(lpbi,x,y) DibXYN(lpbi,DibPtr(lpbi),x,y,(lpbi)->biBitCount)
111
112 #define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
113 (lpbi)->biSizeImage = DibSizeImage(lpbi); \
114 if ((lpbi)->biClrUsed == 0) \
115 (lpbi)->biClrUsed = DibNumColors(lpbi); \
116 if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0) \
117 ; // (lpbi)->biClrUsed = 3;
118
119 #define DibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
120
121 /***************************************************************************/
122
123 #ifndef BI_BITFIELDS
124 #define BI_BITFIELDS 3
125 #endif
126
127 #ifndef HALFTONE
128 #define HALFTONE COLORONCOLOR
129 #endif
130
131 #endif