]>
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 | ||
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 | ||
a61ddc47 UJ |
43 | void wxClearSystemPalette(void); |
44 | PDIB wxDibOpenFile(LPTSTR szFile); | |
45 | int wxDibWriteFile(LPTSTR szFile, LPBITMAPINFOHEADER lpbi); | |
46 | BOOL wxDibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage); | |
47 | PDIB wxDibCreate(int bits, int dx, int dy); | |
48 | BOOL wxDibMapToPalette(PDIB pdib, HPALETTE hpal); | |
49 | HPALETTE wxMakePalette(const BITMAPINFO FAR* Info, UINT flags); | |
2bda0e17 KB |
50 | |
51 | /**************************************************************************** | |
52 | Internal function declarations | |
53 | ***************************************************************************/ | |
54 | ||
a61ddc47 | 55 | PDIB wxDibReadBitmapInfo(HFILE fh); |
2bda0e17 KB |
56 | |
57 | /**************************************************************************** | |
58 | DIB macros. | |
59 | ***************************************************************************/ | |
60 | ||
61 | #ifdef WIN32 | |
a61ddc47 | 62 | #define wxHandleFromDib(lpbi) GlobalHandle(lpbi) |
2bda0e17 | 63 | #else |
a61ddc47 | 64 | #define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi)) |
2bda0e17 KB |
65 | #endif |
66 | ||
a61ddc47 | 67 | #define wxDibFromHandle(h) (PDIB)GlobalLock(h) |
2bda0e17 | 68 | |
a61ddc47 | 69 | #define wxDibFree(pdib) GlobalFreePtr(pdib) |
2bda0e17 | 70 | |
a61ddc47 | 71 | #define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */ |
2bda0e17 | 72 | |
a61ddc47 UJ |
73 | #define wxDibWidth(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth) |
74 | #define wxDibHeight(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biHeight) | |
75 | #define wxDibBitCount(lpbi) (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount) | |
76 | #define wxDibCompression(lpbi) (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression) | |
2bda0e17 | 77 | |
a61ddc47 UJ |
78 | #define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n)) |
79 | #define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount) | |
2bda0e17 | 80 | |
a61ddc47 UJ |
81 | #define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \ |
82 | ? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \ | |
2bda0e17 KB |
83 | : (lpbi)->biSizeImage) |
84 | ||
a61ddc47 UJ |
85 | #define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD)) |
86 | #define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD)) | |
2bda0e17 | 87 | |
a61ddc47 | 88 | #define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y)) |
2bda0e17 KB |
89 | |
90 | //HACK for NT BI_BITFIELDS DIBs | |
91 | #ifdef WIN32 | |
a61ddc47 UJ |
92 | #define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \ |
93 | ? (LPVOID)(wxDibColors(lpbi) + 3) \ | |
94 | : (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)) | |
2bda0e17 | 95 | #else |
a61ddc47 | 96 | #define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed) |
2bda0e17 KB |
97 | #endif |
98 | ||
a61ddc47 | 99 | #define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize)) |
2bda0e17 | 100 | |
a61ddc47 | 101 | #define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \ |
2bda0e17 KB |
102 | ? (int)(1 << (int)(lpbi)->biBitCount) \ |
103 | : (int)(lpbi)->biClrUsed) | |
104 | ||
a61ddc47 | 105 | #define wxDibXYN(lpbi,pb,x,y,n) (LPVOID)( \ |
2bda0e17 KB |
106 | (BYTE _huge *)(pb) + \ |
107 | (UINT)((UINT)(x) * (UINT)(n) / 8u) + \ | |
a61ddc47 | 108 | ((DWORD)wxDibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y))) |
2bda0e17 | 109 | |
a61ddc47 | 110 | #define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount) |
2bda0e17 | 111 | |
a61ddc47 UJ |
112 | #define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \ |
113 | (lpbi)->biSizeImage = wxDibSizeImage(lpbi); \ | |
2bda0e17 | 114 | if ((lpbi)->biClrUsed == 0) \ |
a61ddc47 | 115 | (lpbi)->biClrUsed = wxDibNumColors(lpbi); |
2917e920 BM |
116 | |
117 | // if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0) | |
118 | // ; // (lpbi)->biClrUsed = 3; | |
2bda0e17 | 119 | |
a61ddc47 | 120 | #define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB)) |
2bda0e17 KB |
121 | |
122 | /***************************************************************************/ | |
123 | ||
124 | #ifndef BI_BITFIELDS | |
125 | #define BI_BITFIELDS 3 | |
126 | #endif | |
127 | ||
128 | #ifndef HALFTONE | |
129 | #define HALFTONE COLORONCOLOR | |
130 | #endif | |
131 | ||
132 | #endif |