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

Last change on this file since 3562 was 3527, checked in by sandervl, 25 years ago

manual flipping of dibsection images

File size: 20.2 KB
Line 
1/* $Id: dibsect.cpp,v 1.30 2000-05-12 19:14:55 sandervl Exp $ */
2
3/*
4 * GDI32 DIB sections
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1998 Patrick Haller
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 * NOTE:
12 * This is not a complete solution for CreateDIBSection, but enough for Quake 2!
13 *
14 */
15#define INCL_GPI
16#define INCL_WIN
17#include <os2wrap.h> //Odin32 OS/2 api wrappers
18#include <stdlib.h>
19#include <string.h>
20#include <win32type.h>
21#include <misc.h>
22#define OS2_ONLY
23#include "dibsect.h"
24#include <vmutex.h>
25#include <win32api.h>
26#include <winconst.h>
27#include <win32wnd.h>
28#include <cpuhlp.h>
29#include "oslibgpi.h"
30#include "rgbcvt.h"
31
32#define DBG_LOCALLOG DBG_dibsect
33#include "dbglocal.h"
34
35static VMutex dibMutex;
36
37//******************************************************************************
38//******************************************************************************
39DIBSection::DIBSection(BITMAPINFOHEADER_W *pbmi, char *pColors, DWORD iUsage, DWORD hSection, DWORD dwOffset, DWORD handle, int fFlip)
40 : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsBuffer(NULL)
41{
42 bmpsize = pbmi->biWidth;
43 /* @@@PH 98/06/07 -- high-color bitmaps don't have palette */
44
45 this->fFlip = fFlip;
46 os2bmphdrsize = sizeof(BITMAPINFO2);
47
48 switch(pbmi->biBitCount)
49 {
50 case 1:
51 bmpsize = ((bmpsize + 31) & ~31) / 8;
52 os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
53 break;
54 case 4:
55 bmpsize = ((bmpsize + 7) & ~7) / 2;
56 os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
57 break;
58 case 8:
59 os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
60 bmpsize = (bmpsize + 3) & ~3;
61 break;
62 case 16:
63 bmpsize *= 2;
64 bmpsize = (bmpsize + 3) & ~3;
65 break;
66 case 24:
67 bmpsize *= 3;
68 bmpsize = (bmpsize + 3) & ~3;
69 break;
70 case 32:
71 bmpsize *= 4;
72 break;
73 default:
74 dprintf(("Unsupported nr of bits %d", pbmi->biBitCount));
75 DebugInt3();
76 break;
77 }
78
79 this->hSection = hSection;
80 if(hSection) {
81 bmpBits = (char *)MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS_W, 0, dwOffset, bmpsize*pbmi->biHeight);
82 if(!bmpBits) {
83 dprintf(("Dibsection: mapViewOfFile %x failed!", hSection));
84 DebugInt3();
85 }
86 }
87 if(!bmpBits) {
88 DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
89 }
90 memset(bmpBits, 0, bmpsize*pbmi->biHeight);
91
92 pOS2bmp = (BITMAPINFO2 *)malloc(os2bmphdrsize);
93
94 memset(pOS2bmp, /* set header + palette entries to zero */
95 0,
96 os2bmphdrsize);
97
98 pOS2bmp->cbFix = sizeof(BITMAPINFO2) - sizeof(RGB2);
99 pOS2bmp->cx = pbmi->biWidth;
100 pOS2bmp->cy = pbmi->biHeight;
101 pOS2bmp->cPlanes = pbmi->biPlanes;
102 pOS2bmp->cBitCount = pbmi->biBitCount;
103 pOS2bmp->ulCompression = pbmi->biCompression;
104 //SvL: Ignore BI_BITFIELDS type (GpiDrawBits fails otherwise)
105 if(pOS2bmp->ulCompression == BI_BITFIELDS) {
106 pOS2bmp->ulCompression = 0;
107 }
108 pOS2bmp->cbImage = pbmi->biSizeImage;
109 dprintf(("handle %x", handle));
110 dprintf(("pOS2bmp->cx %d\n", pOS2bmp->cx));
111 dprintf(("pOS2bmp->cy %d\n", pOS2bmp->cy));
112 dprintf(("pOS2bmp->cPlanes %d\n", pOS2bmp->cPlanes));
113 dprintf(("pOS2bmp->cBitCount %d\n", pOS2bmp->cBitCount));
114 dprintf(("pOS2bmp->ulCompression %d\n", pOS2bmp->ulCompression));
115 dprintf(("pOS2bmp->cbImage %d\n", pOS2bmp->cbImage));
116 dprintf(("Bits at %x, size %d",bmpBits, bmpsize*pbmi->biHeight));
117
118 // clear DIBSECTION structure
119 memset(&dibinfo, 0, sizeof(dibinfo));
120
121 // copy BITMAPINFOHEADER data into DIBSECTION structure
122 memcpy(&dibinfo.dsBmih, pbmi, sizeof(*pbmi));
123 dibinfo.dsBm.bmType = 0;
124 dibinfo.dsBm.bmWidth = pbmi->biWidth;
125 dibinfo.dsBm.bmHeight = pbmi->biHeight;
126 dibinfo.dsBm.bmWidthBytes= bmpsize;
127 dibinfo.dsBm.bmPlanes = pbmi->biPlanes;
128 dibinfo.dsBm.bmBitsPixel = pbmi->biBitCount;
129 dibinfo.dsBm.bmBits = bmpBits;
130
131 dibinfo.dshSection = handle;
132 dibinfo.dsOffset = 0; // TODO: put the correct value here (if createdibsection with file handle)
133
134 if(iUsage == DIB_PAL_COLORS || pbmi->biBitCount <= 8)
135 {
136 dibinfo.dsBitfields[0] = dibinfo.dsBitfields[1] = dibinfo.dsBitfields[2] = 0;
137 }
138 else {
139 switch(pbmi->biBitCount)
140 {
141 case 16:
142 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS) ? *(DWORD *)pColors : 0x7c00;
143 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
144 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
145 break;
146
147 case 24:
148 dibinfo.dsBitfields[0] = 0xff;
149 dibinfo.dsBitfields[1] = 0xff00;
150 dibinfo.dsBitfields[2] = 0xff0000;
151 break;
152
153 case 32:
154 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS) ? *(DWORD *)pColors : 0xff;
155 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0xff00;
156 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0xff0000;
157 if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
158 dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
159 }
160 break;
161 }
162 dprintf(("BI_BITFIELDS %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
163 }
164 //double buffer for rgb 555 dib sections (for conversion) or flipped sections
165 if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
166 DosAllocMem((PPVOID)&bmpBitsBuffer, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
167 }
168
169 this->handle = handle;
170 this->iUsage = iUsage;
171
172 dibMutex.enter();
173 if(section == NULL)
174 {
175 dprintf(("section was NULL\n"));
176 section = this;
177 }
178 else
179 {
180 DIBSection *dsect = section;
181 dprintf2(("Increment section starting at %08X\n",dsect));
182
183 /* @@@PH 98/07/11 fix for dsect->next == NULL */
184 while ( (dsect->next != this) &&
185 (dsect->next != NULL) )
186 {
187 dprintf2(("Increment section to %08X\n",dsect->next));
188 dsect = dsect->next;
189 }
190 dsect->next = this;
191 }
192 dibMutex.leave();
193}
194//******************************************************************************
195//******************************************************************************
196DIBSection::~DIBSection()
197{
198 dprintf(("Delete DIBSection %x", handle));
199
200 if(hSection) {
201 UnmapViewOfFile(bmpBits);
202 }
203 else
204 if(bmpBits)
205 DosFreeMem(bmpBits);
206
207 if(bmpBitsBuffer)
208 DosFreeMem(bmpBitsBuffer);
209
210 if(pOS2bmp)
211 free(pOS2bmp);
212
213 dibMutex.enter();
214 if(section == this)
215 {
216 section = this->next;
217 }
218 else
219 {
220 DIBSection *dsect = section;
221
222 while(dsect->next != this)
223 {
224 dsect = dsect->next;
225 }
226 dsect->next = this->next;
227 }
228 dibMutex.leave();
229}
230//******************************************************************************
231//******************************************************************************
232int DIBSection::SetDIBits(HDC hdc, HBITMAP hbitmap, UINT startscan, UINT
233 lines, const VOID *bits, BITMAPINFOHEADER_W *pbmi,
234 UINT coloruse)
235{
236 lines = (int)lines >= 0 ? (int)lines : (int)-lines;
237 int palsize=0;
238
239 bmpsize = pbmi->biWidth;
240 os2bmphdrsize = sizeof(BITMAPINFO2);
241
242 switch(pbmi->biBitCount)
243 {
244 case 1:
245 bmpsize = ((bmpsize + 31) & ~31) / 8;
246 palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
247 os2bmphdrsize += palsize;
248 break;
249 case 4:
250 bmpsize = ((bmpsize + 7) & ~7) / 2;
251 palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
252 os2bmphdrsize += palsize;
253 break;
254 case 8:
255 palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
256 os2bmphdrsize += palsize;
257 bmpsize = (bmpsize + 3) & ~3;
258 break;
259 case 16:
260 bmpsize *= 2;
261 bmpsize = (bmpsize + 3) & ~3;
262 break;
263 case 24:
264 bmpsize *= 3;
265 bmpsize = (bmpsize + 3) & ~3;
266 break;
267 case 32:
268 bmpsize *= 4;
269 break;
270 }
271
272 //SvL: TODO: Correct??
273 if(!hSection && pOS2bmp->cx != pbmi->biWidth && pOS2bmp->cy != pbmi->biHeight &&
274 pOS2bmp->cBitCount != pbmi->biBitCount)
275 {
276 char *oldbits = bmpBits;
277 int oldsize = dibinfo.dsBm.bmWidthBytes * dibinfo.dsBm.bmHeight;
278
279 DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
280 memcpy(bmpBits, oldbits, min(oldsize, bmpsize*pbmi->biHeight));
281 DosFreeMem(oldbits);
282 }
283 pOS2bmp = (BITMAPINFO2 *)realloc(pOS2bmp, os2bmphdrsize);
284 pOS2bmp->cbFix = sizeof(BITMAPINFO2) - sizeof(RGB2);
285 pOS2bmp->cx = pbmi->biWidth;
286 pOS2bmp->cy = pbmi->biHeight;
287 pOS2bmp->cPlanes = pbmi->biPlanes;
288 pOS2bmp->cBitCount = pbmi->biBitCount;
289 pOS2bmp->ulCompression = pbmi->biCompression;
290 pOS2bmp->cbImage = pbmi->biSizeImage;
291
292 // clear DIBSECTION structure
293 memset(&dibinfo, 0, sizeof(dibinfo));
294
295 // copy BITMAPINFOHEADER data into DIBSECTION structure
296 memcpy(&dibinfo.dsBmih, pbmi, sizeof(*pbmi));
297 dibinfo.dsBm.bmType = 0;
298 dibinfo.dsBm.bmWidth = pbmi->biWidth;
299 dibinfo.dsBm.bmHeight = pbmi->biHeight;
300 dibinfo.dsBm.bmWidthBytes= bmpsize;
301 dibinfo.dsBm.bmPlanes = pbmi->biPlanes;
302 dibinfo.dsBm.bmBitsPixel = pbmi->biBitCount;
303 dibinfo.dsBm.bmBits = bmpBits;
304
305 dibinfo.dshSection = hSection;
306 dibinfo.dsOffset = 0; // TODO: put the correct value here (if createdibsection with file handle)
307
308 if(coloruse == DIB_PAL_COLORS || pbmi->biBitCount <= 8)
309 {
310 dibinfo.dsBitfields[0] = dibinfo.dsBitfields[1] = dibinfo.dsBitfields[2] = 0;
311 }
312 else {
313 char *pColors = (char *)pbmi + 1;
314
315 switch(pbmi->biBitCount)
316 {
317 case 16:
318 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS) ? *(DWORD *)pColors : 0x7c00;
319 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
320 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
321 break;
322
323 case 24:
324 dibinfo.dsBitfields[0] = 0xff;
325 dibinfo.dsBitfields[1] = 0xff00;
326 dibinfo.dsBitfields[2] = 0xff0000;
327 break;
328
329 case 32:
330 dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS) ? *(DWORD *)pColors : 0xff;
331 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0xff00;
332 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0xff0000;
333 if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
334 dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
335 }
336 break;
337 }
338 dprintf(("BI_BITFIELDS %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
339 }
340
341 //double buffer for rgb 555 dib sections (for conversion) or flipped sections
342 if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
343 if(bmpBitsBuffer) {
344 DosFreeMem(bmpBitsBuffer);
345 }
346 DosAllocMem((PPVOID)&bmpBitsBuffer, dibinfo.dsBm.bmWidthBytes*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
347 }
348
349 dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
350 if(palsize)
351 memcpy(pOS2bmp->argbColor, (char *)pbmi + 1 , palsize);
352
353 if(bits)
354 {
355 int size = bmpsize*lines;
356 memcpy(bmpBits+bmpsize*startscan, bits, size);
357 }
358 return(lines);
359}
360//******************************************************************************
361//******************************************************************************
362int DIBSection::SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb)
363{
364 int i;
365
366 if(startIdx + cEntries > (1 << pOS2bmp->cBitCount))
367 {
368 dprintf(("DIBSection::SetDIBColorTable, invalid nr of entries %d %d\n", startIdx, cEntries));
369 return(0);
370 }
371
372 memcpy(&pOS2bmp->argbColor[startIdx], rgb, cEntries*sizeof(RGB2));
373
374 for(i=startIdx;i<cEntries;i++)
375 {
376 pOS2bmp->argbColor[i].fcOptions = 0;
377 dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&pOS2bmp->argbColor[i])) ));
378 }
379
380 return(cEntries);
381}
382//******************************************************************************
383//******************************************************************************
384BOOL DIBSection::BitBlt(HDC hdcDest, int nXdest, int nYdest, int nDestWidth,
385 int nDestHeight, int nXsrc, int nYsrc,
386 int nSrcWidth, int nSrcHeight, DWORD Rop)
387{
388 HPS hps = (HPS)hdcDest;
389 POINTL point[4];
390 LONG rc, hdcHeight, hdcWidth;
391 PVOID bitmapBits = NULL;
392 int oldyinversion = 0;
393 BOOL fRestoryYInversion = FALSE, fFrameWindowDC = FALSE;
394 HWND hwndDest;
395
396 hwndDest = WindowFromDC(hdcDest);
397 //TODO: Test whether dc is for the client or frame window
398// if(hwndDest && IsOS2FrameWindowHandle(hwndDest)) {
399// fFrameWindowDC = TRUE;
400// }
401
402 dprintf(("DIBSection::BitBlt %x %X (hps %x) %x to(%d,%d)(%d,%d) from (%d,%d)(%d,%d) rop %x flip %x",
403 handle, hdcDest, hps, hwndDest, nXdest, nYdest, nDestWidth, nDestHeight,
404 nXsrc, nYsrc, nSrcWidth, nSrcHeight, Rop, fFlip));
405
406 if(hwndDest) {
407 RECT rect;
408
409 if(fFrameWindowDC) {
410 GetWindowRect(hwndDest, &rect);
411 }
412 else GetClientRect(hwndDest, &rect);
413 hdcHeight = rect.bottom - rect.top;
414 hdcWidth = rect.right - rect.left;
415 }
416 else {
417 hdcHeight = pOS2bmp->cy;
418 hdcWidth = pOS2bmp->cx;
419 }
420
421#if 0
422 nXdest = 0;
423 nYdest = 0;
424 nXsrc = 0;
425 nXsrc = 0;
426 nDestWidth = pOS2bmp->cx;
427 nDestHeight = pOS2bmp->cy;
428 nSrcWidth = pOS2bmp->cx;
429 nSrcHeight = pOS2bmp->cy;
430#endif
431
432 //win32 coordinates are of the left top, OS/2 expects left bottom
433 //source rectangle is non-inclusive (top, right not included)
434 if(nXdest + nDestWidth > hdcWidth) {
435 nDestWidth = hdcWidth - nXdest;
436 }
437 if(nYdest + nDestHeight > hdcHeight) {
438 nDestHeight = hdcHeight - nYdest;
439 }
440 point[0].x = nXdest;
441 point[0].y = hdcHeight - nYdest - nDestHeight;
442 point[1].x = nXdest + nDestWidth;
443 point[1].y = hdcHeight - nYdest;
444
445 //target rectangle is inclusive-inclusive
446 if(nXsrc + nSrcWidth > pOS2bmp->cx) {
447 nSrcWidth = pOS2bmp->cx - nXsrc;
448 }
449 if(nYsrc + nSrcHeight > pOS2bmp->cy) {
450 nSrcHeight = pOS2bmp->cy - nYsrc;
451 }
452 point[2].x = nXsrc;
453 point[2].y = pOS2bmp->cy - nYsrc - nSrcHeight;
454 point[3].x = nXsrc + nSrcWidth;
455 point[3].y = pOS2bmp->cy - nYsrc;
456
457 oldyinversion = GpiQueryYInversion(hps);
458 if(oldyinversion != 0) {
459 GpiEnableYInversion(hps, 0);
460 fRestoryYInversion = TRUE;
461 }
462
463 if(fFlip & FLIP_HOR)
464 {
465 ULONG x;
466 x = point[0].x;
467 point[0].x = point[1].x;
468 point[1].x = x;
469 }
470
471 ULONG os2mode, winmode;
472
473 os2mode = BBO_OR;
474 winmode = GetStretchBltMode(hdcDest);
475 switch(winmode) {
476 case BLACKONWHITE_W:
477 os2mode = BBO_AND;
478 break;
479 case WHITEONBLACK_W:
480 case HALFTONE_W: //TODO:
481 os2mode = BBO_OR;
482 break;
483 case COLORONCOLOR_W:
484 os2mode = BBO_IGNORE;
485 break;
486 }
487 if(fFlip & FLIP_VERT) {
488 //manually reverse bitmap data
489 char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
490 char *dst = bmpBitsBuffer;
491 for(int i=0;i<pOS2bmp->cy;i++) {
492 memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
493 dst += dibinfo.dsBm.bmWidthBytes;
494 src -= dibinfo.dsBm.bmWidthBytes;
495 }
496 bmpBits = bmpBitsBuffer;
497 }
498
499 //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
500 if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
501 dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
502
503 if(bmpBitsBuffer == NULL)
504 DebugInt3();
505
506 if(CPUFeatures & CPUID_MMX) {
507 RGB555to565MMX((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
508 }
509 else RGB555to565((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
510 rc = GpiDrawBits(hps, bmpBitsBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
511 }
512 else rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
513
514 if(rc == GPI_OK) {
515 DIBSection *destdib = DIBSection::findHDC(hdcDest);
516 if(destdib) {
517 destdib->sync(hps, nYdest, nDestHeight);
518 }
519 //restore old y inversion height
520 if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
521 return(TRUE);
522 }
523 if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
524
525 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));
526 dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndDest)) & 0xFFFF));
527 return(FALSE);
528}
529//******************************************************************************
530//******************************************************************************
531void DIBSection::sync(HDC hdc, DWORD nYdest, DWORD nDestHeight)
532{
533 APIRET rc;
534 char *destBuf;
535
536 dprintf(("Sync destination dibsection %x (%x)", handle, hdc));
537
538 //todo: rgb 565 to 555 conversion if bpp == 16
539 if(GetBitCount() == 16) {
540 dprintf(("WARNING: need to convert RGB 565 to RGB 555!!"));
541 }
542
543 BITMAPINFO2 *tmphdr = (BITMAPINFO2 *)malloc(os2bmphdrsize);
544 memcpy(tmphdr, pOS2bmp, os2bmphdrsize);
545 destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
546 rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
547 tmphdr);
548 free(tmphdr);
549 if(rc != nDestHeight) {
550 DebugInt3();
551 }
552}
553//******************************************************************************
554//******************************************************************************
555void DIBSection::SelectDIBObject(HDC hdc)
556{
557 this->hdc = hdc;
558 hwndParent = WindowFromDC(hdc);
559 dprintf(("SelectDIBObject %x into %x hwndParent = %x", handle, hdc, hwndParent));
560}
561//******************************************************************************
562//******************************************************************************
563DIBSection *DIBSection::find(DWORD handle)
564{
565 DIBSection *dsect = section;
566
567 dibMutex.enter();
568 while(dsect)
569 {
570 if(dsect->handle == handle)
571 {
572 dibMutex.leave();
573 return(dsect);
574 }
575 dsect = dsect->next;
576 }
577 dibMutex.leave();
578 return(NULL);
579}
580//******************************************************************************
581//A bitmap can only be selected into one DC, so this works.
582//******************************************************************************
583DIBSection *DIBSection::findHDC(HDC hdc)
584{
585 DIBSection *dsect = section;
586
587 while(dsect)
588 {
589 if(dsect->hdc == hdc)
590 {
591 return(dsect);
592 }
593 dsect = dsect->next;
594 }
595 return(NULL);
596}
597//******************************************************************************
598//******************************************************************************
599void DIBSection::deleteSection(DWORD handle)
600{
601 DIBSection *dsect = find(handle);
602
603 if(dsect)
604 delete dsect;
605
606}
607//******************************************************************************
608//******************************************************************************
609int DIBSection::GetDIBSection(int iSize, void *lpBuffer)
610{
611 DIBSECTION *pDIBSection = (DIBSECTION *)lpBuffer;
612 LPBITMAP_W dsBm = (LPBITMAP_W)lpBuffer;
613
614 dprintf2(("GetDIBSection %x %d %x", handle, iSize, lpBuffer));
615 if(iSize == sizeof(DIBSECTION))
616 {
617 memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
618 return sizeof(DIBSECTION);
619 }
620 else
621 if(iSize == sizeof(BITMAP_W))
622 {
623 memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
624 return sizeof(BITMAP_W);
625 }
626 return 0;
627
628}
629//******************************************************************************
630//******************************************************************************
631char DIBSection::GetBitCount()
632{
633 if(pOS2bmp == NULL)
634 return 0;
635 else
636 return pOS2bmp->cBitCount;
637}
638//******************************************************************************
639//******************************************************************************
640DIBSection *DIBSection::section = NULL;
Note: See TracBrowser for help on using the repository browser.