]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dibutils.h
bb9845f2c601f9d1a86f80fd29830b4a5da6eb2f
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Utilities for DIBs
4 // Author: Julian Smart
8 // Copyright: (c) Microsoft, Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 /***************************************************************************
14 (C) Copyright 1994 Microsoft Corp. All rights reserved.
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.
22 **************************************************************************/
24 /***************************************************************************
25 Functions for handling Device Independent Bitmaps and clearing the
27 **************************************************************************/
29 #ifndef SAMPLES_UTILS_H
30 #define SAMPLES_UTILS_H
33 #pragma interface "dibutils.h"
36 typedef LPBITMAPINFOHEADER PDIB
;
39 /***************************************************************************
40 External function declarations
41 **************************************************************************/
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
);
51 /****************************************************************************
52 Internal function declarations
53 ***************************************************************************/
55 PDIB
wxDibReadBitmapInfo(HFILE fh
);
57 /****************************************************************************
59 ***************************************************************************/
62 #define wxHandleFromDib(lpbi) GlobalHandle(lpbi)
64 #define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
67 #define wxDibFromHandle(h) (PDIB)GlobalLock(h)
69 #define wxDibFree(pdib) GlobalFreePtr(pdib)
71 #define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
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)
78 #define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
79 #define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount)
81 #define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
82 ? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
83 : (lpbi)->biSizeImage)
85 #define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
86 #define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD))
88 #define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
90 //HACK for NT BI_BITFIELDS DIBs
92 #define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
93 ? (LPVOID)(wxDibColors(lpbi) + 3) \
94 : (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
96 #define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
99 #define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
101 #define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
102 ? (int)(1 << (int)(lpbi)->biBitCount) \
103 : (int)(lpbi)->biClrUsed)
105 #define wxDibXYN(lpbi,pb,x,y,n) (LPVOID)( \
106 (BYTE _huge *)(pb) + \
107 (UINT)((UINT)(x) * (UINT)(n) / 8u) + \
108 ((DWORD)wxDibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
110 #define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount)
112 #define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
113 (lpbi)->biSizeImage = wxDibSizeImage(lpbi); \
114 if ((lpbi)->biClrUsed == 0) \
115 (lpbi)->biClrUsed = wxDibNumColors(lpbi);
117 // if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0)
118 // ; // (lpbi)->biClrUsed = 3;
120 #define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
122 /***************************************************************************/
125 #define BI_BITFIELDS 3
129 #define HALFTONE COLORONCOLOR