source: trunk/src/gdi32/dibsect.cpp@ 46

Last change on this file since 46 was 46, checked in by sandervl, 26 years ago

* empty log message *

File size: 8.5 KB
Line 
1/*
2 * GDI32 DIB sections
3 *
4 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
5 * Copyright 1998 Patrick Haller
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10#define INCL_GPI
11#define INCL_WIN
12#include <os2.h>
13#include <stdlib.h>
14#include <string.h>
15#include "win32type.h"
16#include "misc.h"
17#define OS2_ONLY
18#include "dibsect.h"
19
20//NOTE:
21//This is not a complete solution for CreateDIBSection, but enough for Quake 2!
22//******************************************************************************
23//******************************************************************************
24DIBSection::DIBSection(WINBITMAPINFOHEADER *pbmi, DWORD handle, int fFlip)
25 : bmpBits(NULL), pOS2bmp(NULL)
26{
27 int bmpsize = pbmi->biWidth, os2bmpsize;
28
29 /* @@@PH 98/06/07 -- high-color bitmaps don't have palette */
30
31
32 this->fFlip = fFlip;
33 os2bmpsize = sizeof(BITMAPINFO2);
34
35 switch(pbmi->biBitCount)
36 {
37 case 1:
38 bmpsize /= 8;
39 os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
40 break;
41 case 4:
42 bmpsize /= 2;
43 os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
44 break;
45 case 8:
46 os2bmpsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
47 break;
48 case 16:
49 bmpsize *= 2;
50 break;
51 case 24:
52 bmpsize *= 3;
53 break;
54 case 32:
55 bmpsize *= 4;
56 break;
57 }
58 if(bmpsize & 3) {
59 bmpsize = (bmpsize + 3) & ~3;
60 }
61 bmpBits = (char *)malloc(bmpsize*pbmi->biHeight);
62
63 pOS2bmp = (BITMAPINFO2 *)malloc(os2bmpsize);
64
65 memset(pOS2bmp, /* set header + palette entries to zero */
66 0,
67 os2bmpsize);
68
69 pOS2bmp->cbFix = sizeof(BITMAPINFO2) - sizeof(RGB2);
70 pOS2bmp->cx = pbmi->biWidth;
71 pOS2bmp->cy = pbmi->biHeight;
72 pOS2bmp->cPlanes = pbmi->biPlanes;
73 pOS2bmp->cBitCount = pbmi->biBitCount;
74 pOS2bmp->ulCompression = pbmi->biCompression;
75 pOS2bmp->cbImage = pbmi->biSizeImage;
76 dprintf(("pOS2bmp->cx %d\n", pOS2bmp->cx));
77 dprintf(("pOS2bmp->cy %d\n", pOS2bmp->cy));
78 dprintf(("pOS2bmp->cPlanes %d\n", pOS2bmp->cPlanes));
79 dprintf(("pOS2bmp->cBitCount %d\n", pOS2bmp->cBitCount));
80 dprintf(("pOS2bmp->ulCompression %d\n", pOS2bmp->ulCompression));
81 dprintf(("pOS2bmp->cbImage %d\n", pOS2bmp->cbImage));
82
83 this->handle = handle;
84
85 if(section == NULL) {
86 section = this;
87 }
88 else
89 {
90 DIBSection *dsect = section;
91
92 /* @@@PH 98/07/11 fix for dsect->next == NULL */
93 while ( (dsect->next != this) &&
94 (dsect->next != NULL) )
95 {
96 dsect = dsect->next;
97 }
98 dsect->next = this;
99 }
100}
101//******************************************************************************
102//******************************************************************************
103DIBSection::~DIBSection()
104{
105 if(bmpBits)
106 free(bmpBits);
107 if(pOS2bmp)
108 free(pOS2bmp);
109
110 if(section == this) {
111 section = this->next;
112 }
113 else {
114 DIBSection *dsect = section;
115
116 while(dsect->next != this) {
117 dsect = dsect->next;
118 }
119 dsect->next = this->next;
120 }
121}
122//******************************************************************************
123//******************************************************************************
124int DIBSection::SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb)
125{
126 int i;
127
128 if(startIdx + cEntries > (1 << pOS2bmp->cBitCount)) {
129 dprintf(("DIBSection::SetDIBColorTable, invalid nr of entries %d %d\n", startIdx, cEntries));
130 return(0);
131 }
132 memcpy(&pOS2bmp->argbColor[startIdx], rgb, cEntries*sizeof(RGB2));
133 for(i=startIdx;i<cEntries;i++) {
134 pOS2bmp->argbColor[i].fcOptions = 0;
135 }
136 return(cEntries);
137}
138//******************************************************************************
139//******************************************************************************
140#if 1
141BOOL DIBSection::BitBlt(HDC hdcDest, HWND hwndDest, int nXdest, int nYdest, int nWidth,
142 int nHeight, int nXsrc, int nYsrc, DWORD Rop)
143{
144 HPS hps = (HPS)hdcDest;
145 POINTL point[4];
146 LONG rc;
147
148 if(hwndDest != 0) {
149 hps = WinGetPS(hwndDest);
150 }
151 if(hps == 0) {
152 eprintf(("DIBSection::BitBlt, hps == 0 hwndDest = %X", hwndDest));
153 return(FALSE);
154 }
155
156 point[0].x = nXdest;
157 point[0].y = nYdest;
158 point[1].x = nXdest + nWidth - 1;
159 point[1].y = nYdest + nHeight - 1;
160 point[2].x = nXsrc;
161 point[2].y = nYsrc;
162 if(nXsrc + nWidth > pOS2bmp->cx) {
163 point[3].x = pOS2bmp->cx;
164 }
165 else point[3].x = nXsrc + nWidth;
166
167 if(nYsrc + nHeight > pOS2bmp->cy) {
168 point[3].y = pOS2bmp->cy;
169 }
170 else point[3].y = nYsrc + nHeight;
171
172 if(fFlip & FLIP_VERT) {
173 ULONG y;
174 y = point[0].y;
175 point[0].y = point[1].y;
176 point[1].y = y;
177 }
178
179 if(fFlip & FLIP_HOR) {
180 ULONG x;
181 x = point[0].x;
182 point[0].x = point[1].x;
183 point[1].x = x;
184 }
185
186 rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
187
188 if(hwndDest != 0) {
189 WinReleasePS(hps);
190 }
191 if(rc == GPI_OK)
192 return(TRUE);
193 dprintf(("DIBSection::BitBlt %X (%d,%d) (%d,%d) to (%d,%d) (%d,%d) returned %d\n", hps, point[0].x, point[0].y, point[1].x, point[1].y, point[2].x, point[2].y, point[3].x, point[3].y, rc));
194 dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndDest)) & 0xFFFF));
195 return(FALSE);
196}
197#else
198BOOL DIBSection::BitBlt(HDC hdcDest, int nXdest, int nYdest, int nWidth,
199 int nHeight, int nXsrc, int nYsrc, DWORD Rop)
200{
201 HPS hps = (HPS)hdcDest;
202 POINTL point[4];
203 LONG rc;
204
205 if(hps == 0) {
206 eprintf(("DIBSection::BitBlt, hps == 0"));
207 return(FALSE);
208 }
209
210// dprintf(("DIBSection::BitBlt (%d,%d) to (%d,%d) (%d,%d)\n", nXsrc, nYsrc, nXdest, nYdest, nXdest+ nWidth, nYdest + nHeight));
211 point[0].x = nXdest;
212 point[0].y = nYdest;
213 point[1].x = nXdest + nWidth - 1;
214 point[1].y = nYdest + nHeight - 1;
215 point[2].x = nXsrc;
216 point[2].y = nYsrc;
217 if(nXsrc + nWidth > pOS2bmp->cx) {
218 point[3].x = pOS2bmp->cx;
219 }
220 else point[3].x = nXsrc + nWidth;
221
222 if(nYsrc + nHeight > pOS2bmp->cy) {
223 point[3].y = pOS2bmp->cy;
224 }
225 else point[3].y = nYsrc + nHeight;
226
227 rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
228// dprintf(("DIBSection::BitBlt %X (%d,%d) (%d,%d) to (%d,%d) (%d,%d) returned %d\n", hps, point[0].x, point[0].y, point[1].x, point[1].y, point[2].x, point[2].y, point[3].x, point[3].y, rc));
229
230 if(rc == GPI_OK)
231 return(TRUE);
232 dprintf(("DIBSection::BitBlt %X (%d,%d) (%d,%d) to (%d,%d) (%d,%d) returned %d\n", hps, point[0].x, point[0].y, point[1].x, point[1].y, point[2].x, point[2].y, point[3].x, point[3].y, rc));
233 dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndParent)) & 0xFFFF));
234 return(FALSE);
235}
236#endif
237//******************************************************************************
238//******************************************************************************
239void DIBSection::SelectDIBObject(HDC hdc)
240{
241 this->hdc = hdc;
242 hwndParent = WinWindowFromDC(hdc);
243}
244//******************************************************************************
245//******************************************************************************
246DIBSection *DIBSection::find(DWORD handle)
247{
248 DIBSection *dsect = section;
249
250 while(dsect) {
251 if(dsect->handle == handle) {
252 return(dsect);
253 }
254 dsect = dsect->next;
255 }
256 return(NULL);
257}
258//******************************************************************************
259//A bitmap can only be selected into one DC, so this works.
260//******************************************************************************
261DIBSection *DIBSection::findHDC(HDC hdc)
262{
263 DIBSection *dsect = section;
264
265 while(dsect) {
266 if(dsect->hdc == hdc) {
267 return(dsect);
268 }
269 dsect = dsect->next;
270 }
271 return(NULL);
272}
273//******************************************************************************
274//******************************************************************************
275void DIBSection::deleteSection(DWORD handle)
276{
277 DIBSection *dsect = find(handle);
278
279 if(dsect)
280 delete dsect;
281
282}
283//******************************************************************************
284//******************************************************************************
285DIBSection *DIBSection::section = NULL;
Note: See TracBrowser for help on using the repository browser.