]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/dibutils.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Utilities for DIBs
4 // Author: Julian Smart
8 // Copyright: (c) Microsoft, Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dibutils.h"
19 typedef LPBITMAPINFOHEADER PDIB
;
22 /***************************************************************************
23 External function declarations
24 **************************************************************************/
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
);
33 /****************************************************************************
34 Internal function declarations
35 ***************************************************************************/
37 PDIB
wxDibReadBitmapInfo(HFILE fh
);
39 /****************************************************************************
41 ***************************************************************************/
44 #define wxHandleFromDib(lpbi) GlobalHandle(lpbi)
46 #define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
49 #define wxDibFromHandle(h) (PDIB)GlobalLock(h)
51 #define wxDibFree(pdib) GlobalFreePtr(pdib)
53 #define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
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)
60 #define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
61 #define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount)
63 #define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
64 ? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
65 : (lpbi)->biSizeImage)
67 #define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
68 #define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD))
70 #define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
72 //HACK for NT BI_BITFIELDS DIBs
74 #define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
75 ? (LPVOID)(wxDibColors(lpbi) + 3) \
76 : (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
78 #define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
81 #define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
83 #define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
84 ? (int)(1 << (int)(lpbi)->biBitCount) \
85 : (int)(lpbi)->biClrUsed)
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)))
92 #define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount)
94 #define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
95 (lpbi)->biSizeImage = wxDibSizeImage(lpbi); \
96 if ((lpbi)->biClrUsed == 0) \
97 (lpbi)->biClrUsed = wxDibNumColors(lpbi);
99 // if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0)
100 // ; // (lpbi)->biClrUsed = 3;
102 #define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
104 /***************************************************************************/
107 #define BI_BITFIELDS 3
111 #define HALFTONE COLORONCOLOR