source: trunk/src/gdi32/dibsect.h@ 22012

Last change on this file since 22012 was 10373, checked in by sandervl, 22 years ago

Update

File size: 6.3 KB
Line 
1/* $Id: dibsect.h,v 1.28 2004-01-11 11:42:11 sandervl Exp $ */
2
3/*
4 * GDI32 DIB sections
5 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Project Odin Software License can be found in LICENSE.TXT
7 */
8#ifndef __DIBSECT_H__
9#define __DIBSECT_H__
10
11#ifdef OS2_INCLUDED
12typedef struct
13{
14 BYTE rgbBlue;
15 BYTE rgbGreen;
16 BYTE rgbRed;
17 BYTE rgbReserved;
18} RGBQUAD, *LPRGBQUAD;
19
20typedef struct tagPALETTEENTRY
21{
22 BYTE peRed, peGreen, peBlue, peFlags;
23} PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
24
25#else
26#define BITMAPINFO2 DWORD
27#endif
28
29#define FLIP_VERT 1
30#define FLIP_HOR 2
31
32typedef struct {
33 DWORD biSize;
34 LONG biWidth;
35 LONG biHeight;
36 WORD biPlanes;
37 WORD biBitCount;
38 DWORD biCompression;
39 DWORD biSizeImage;
40 LONG biXPelsPerMeter;
41 LONG biYPelsPerMeter;
42 DWORD biClrUsed;
43 DWORD biClrImportant;
44} BITMAPINFOHEADER_W;
45
46typedef struct
47{
48 INT bmType;
49 INT bmWidth;
50 INT bmHeight;
51 INT bmWidthBytes;
52 WORD bmPlanes;
53 WORD bmBitsPixel;
54 LPVOID bmBits;
55} BITMAP_W, *LPBITMAP_W;
56
57typedef struct {
58 BITMAPINFOHEADER_W bmiHeader;
59 RGBQUAD bmiColors[1];
60} BITMAPINFO_W;
61typedef BITMAPINFO *LPBITMAPINFO;
62
63#ifdef OS2_INCLUDED
64#define DIB_RGB_COLORS 0
65#define DIB_PAL_COLORS 1
66
67typedef struct
68{
69 BITMAP_W dsBm;
70 BITMAPINFOHEADER_W dsBmih;
71 DWORD dsBitfields[3];
72 HANDLE dshSection;
73 DWORD dsOffset;
74} DIBSECTION,*LPDIBSECTION;
75#endif
76
77//
78//Mark DIB section as invalid (dib section memory is out of sync with
79//GDI bitmap).
80//
81//This must be done for any GDI function that modifies the bitmap
82//
83#define DIBSECTION_MARK_INVALID(hdc) \
84 if(DIBSection::getSection() != NULL) { \
85 DIBSection *dib = DIBSection::findHDC(hdc); \
86 if(dib) { \
87 dib->setInvalid(); \
88 } \
89 }
90
91#define DIBSECTION_MARK_INVALID_BMP(hBitmap) \
92 if(DIBSection::getSection() != NULL) { \
93 DIBSection *dib = DIBSection::findObj(hBitmap); \
94 if(dib) { \
95 dib->setInvalid(); \
96 } \
97 }
98
99//
100//Check if DIB section is marked dirty (bitmap data modified by application)
101//If true, then update the GDI bitmap
102//
103//This must be done for any GDI function that accesses the bitmap
104//
105#define DIBSECTION_CHECK_IF_DIRTY(hdc) \
106 if(DIBSection::getSection() != NULL) { \
107 DIBSection *dib = DIBSection::findHDC(hdc); \
108 if(dib && dib->isDirty()) { \
109 dib->flush(); \
110 } \
111 }
112
113#define DIBSECTION_CHECK_IF_DIRTY_BMP(hBitmap) \
114 if(DIBSection::getSection() != NULL) { \
115 DIBSection *dib = DIBSection::findObj(hBitmap); \
116 if(dib && dib->isDirty()) { \
117 dib->flush(); \
118 } \
119 }
120
121
122class DIBSection
123{
124public:
125 DIBSection(BITMAPINFOHEADER_W *pbmi, char *pColors, DWORD iUsage, DWORD hSection, DWORD dwOffset, HBITMAP hBitmap, int fFlip);
126 ~DIBSection();
127
128 char *GetDIBObject() { return bmpBits; };
129 void SelectDIBObject(HDC hdc);
130 int GetBitCount();
131 int GetHeight();
132 int GetWidth();
133 void UnSelectDIBObject() { this->hdc = 0; };
134
135 void setDirty() { fDirty = TRUE; };
136 BOOL isDirty() { return fDirty; }
137 void setInvalid();
138 BOOL isInvalid() { return fInvalid; };
139
140 DWORD GetBitmapHandle() { return hBitmap; };
141 void SetBitmapHandle(DWORD bmphandle) { hBitmap = bmphandle; };
142 DWORD GetRGBUsage() { return iUsage; };
143
144 BOOL BitBlt(HDC hdcDest, int nXdest, int nYDest,
145 int nDestWidth, int nDestHeight,
146 int nXsrc, int nYSrc,
147 int nSrcWidth, int nSrcHeight,
148 DWORD Rop);
149
150 void flush();
151 void sync();
152
153 void sync(HDC hdc, DWORD nYdest, DWORD nDestHeight, BOOL orgYInversion = TRUE);
154 void flush(HDC hdc, DWORD nYdest, DWORD nDestHeight, BOOL orgYInversion = TRUE);
155 void sync(DWORD xDst, DWORD yDst, DWORD widthDst, DWORD heightDst, PVOID bits);
156
157 int SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb);
158 int GetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb);
159 int SetDIBColorTable(int startIdx, int cEntries, PALETTEENTRY *rgb);
160
161 int GetDIBSection(int iSize , void *lpBuffer);
162
163 static DIBSection *getSection() { return section; } ;
164 static DIBSection *findObj(HBITMAP hBitmap);
165 static DIBSection *findHDC(HDC hdc);
166 static void deleteSection(HBITMAP hBitmap);
167
168 static void initDIBSection();
169
170 static void lock() { EnterCriticalSection(&dibcritsect); };
171 static void unlock() { LeaveCriticalSection(&dibcritsect); };
172
173 static void syncAll();
174
175protected:
176
177private:
178 HBITMAP hBitmap;
179
180 DWORD hSection, dwOffset, iUsage, dwSize;
181 HWND hwndParent;
182 HDC hdc;
183 char *bmpBits, *bmpBitsDblBuffer;
184 BOOL fFlip;
185 int bmpsize, os2bmphdrsize;
186 DIBSECTION dibinfo;
187
188 BOOL fDirty; //bitmap is out of sync with dib memory
189 BOOL fInvalid; //dib memory is out of sync with bitmap
190
191 BITMAPINFO2 *pOS2bmp;
192 // Linked list management
193 DIBSection* next; // Next DIB section
194 static DIBSection* section; // List of DIB sections
195
196 static CRITICAL_SECTION dibcritsect;
197};
198
199#endif
200
201
Note: See TracBrowser for help on using the repository browser.