]>
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 /////////////////////////////////////////////////////////////////////////////
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 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
);
51 /****************************************************************************
52 Internal function declarations
53 ***************************************************************************/
55 PDIB
DibReadBitmapInfo(HFILE fh
);
57 /****************************************************************************
59 ***************************************************************************/
62 #define HandleFromDib(lpbi) GlobalHandle(lpbi)
64 #define HandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
67 #define DibFromHandle(h) (PDIB)GlobalLock(h)
69 #define DibFree(pdib) GlobalFreePtr(pdib)
71 #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
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)
78 #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
79 #define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount)
81 #define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
82 ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
83 : (lpbi)->biSizeImage)
85 #define DibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
86 #define DibPaletteSize(lpbi) (DibNumColors(lpbi) * sizeof(RGBQUAD))
88 #define DibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
90 //HACK for NT BI_BITFIELDS DIBs
92 #define DibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
93 ? (LPVOID)(DibColors(lpbi) + 3) \
94 : (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
96 #define DibPtr(lpbi) (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
99 #define DibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
101 #define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
102 ? (int)(1 << (int)(lpbi)->biBitCount) \
103 : (int)(lpbi)->biClrUsed)
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)))
110 #define DibXY(lpbi,x,y) DibXYN(lpbi,DibPtr(lpbi),x,y,(lpbi)->biBitCount)
112 #define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
113 (lpbi)->biSizeImage = DibSizeImage(lpbi); \
114 if ((lpbi)->biClrUsed == 0) \
115 (lpbi)->biClrUsed = DibNumColors(lpbi);
117 // if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0)
118 // ; // (lpbi)->biClrUsed = 3;
120 #define DibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
122 /***************************************************************************/
125 #define BI_BITFIELDS 3
129 #define HALFTONE COLORONCOLOR