]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/msw/dibutils.h
fixed ifdef
[wxWidgets.git] / include / wx / msw / dibutils.h
... / ...
CommitLineData
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
36typedef LPBITMAPINFOHEADER PDIB;
37typedef HANDLE HDIB;
38
39/***************************************************************************
40 External function declarations
41 **************************************************************************/
42
43void wxClearSystemPalette(void);
44PDIB wxDibOpenFile(LPTSTR szFile);
45int wxDibWriteFile(LPTSTR szFile, LPBITMAPINFOHEADER lpbi);
46BOOL wxDibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage);
47PDIB wxDibCreate(int bits, int dx, int dy);
48BOOL wxDibMapToPalette(PDIB pdib, HPALETTE hpal);
49HPALETTE wxMakePalette(const BITMAPINFO FAR* Info, UINT flags);
50
51/****************************************************************************
52 Internal function declarations
53 ***************************************************************************/
54
55PDIB wxDibReadBitmapInfo(HFILE fh);
56
57/****************************************************************************
58 DIB macros.
59 ***************************************************************************/
60
61#ifdef WIN32
62 #define wxHandleFromDib(lpbi) GlobalHandle(lpbi)
63#else
64 #define wxHandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
65#endif
66
67#define wxDibFromHandle(h) (PDIB)GlobalLock(h)
68
69#define wxDibFree(pdib) GlobalFreePtr(pdib)
70
71#define wxWIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
72
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)
77
78#define wxDibWidthBytesN(lpbi, n) (UINT)wxWIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
79#define wxDibWidthBytes(lpbi) wxDibWidthBytesN(lpbi, (lpbi)->biBitCount)
80
81#define wxDibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
82 ? ((DWORD)(UINT)wxDibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
83 : (lpbi)->biSizeImage)
84
85#define wxDibSize(lpbi) ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
86#define wxDibPaletteSize(lpbi) (wxDibNumColors(lpbi) * sizeof(RGBQUAD))
87
88#define wxDibFlipY(lpbi, y) ((int)(lpbi)->biHeight-1-(y))
89
90//HACK for NT BI_BITFIELDS DIBs
91#ifdef WIN32
92 #define wxDibPtr(lpbi) ((lpbi)->biCompression == BI_BITFIELDS \
93 ? (LPVOID)(wxDibColors(lpbi) + 3) \
94 : (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
95#else
96 #define wxDibPtr(lpbi) (LPVOID)(wxDibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
97#endif
98
99#define wxDibColors(lpbi) ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
100
101#define wxDibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
102 ? (int)(1 << (int)(lpbi)->biBitCount) \
103 : (int)(lpbi)->biClrUsed)
104
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)))
109
110#define wxDibXY(lpbi,x,y) wxDibXYN(lpbi,wxDibPtr(lpbi),x,y,(lpbi)->biBitCount)
111
112#define wxFixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
113 (lpbi)->biSizeImage = wxDibSizeImage(lpbi); \
114 if ((lpbi)->biClrUsed == 0) \
115 (lpbi)->biClrUsed = wxDibNumColors(lpbi);
116
117// if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0)
118// ; // (lpbi)->biClrUsed = 3;
119
120#define wxDibInfo(pDIB) ((BITMAPINFO FAR *)(pDIB))
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