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

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

compile fix

File size: 20.4 KB
Line 
1/* $Id: dibsect.cpp,v 1.33 2000-05-28 17:03:18 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_W type (GpiDrawBits fails otherwise)
105 if(pOS2bmp->ulCompression == BI_BITFIELDS_W) {
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_W) ? *(DWORD *)pColors : 0x7c00;
143 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
144 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((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_W) ? *(DWORD *)pColors : 0xff;
155 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
156 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((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_W %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_W) ? *(DWORD *)pColors : 0x7c00;
319 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
320 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((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_W) ? *(DWORD *)pColors : 0xff;
331 dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
332 dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((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_W %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 SetDIBColorTable(0, 1 << pbmi->biBitCount, (RGBQUAD *)(pbmi+1));
352 }
353
354 if(bits)
355 {
356 int size = bmpsize*lines;
357 memcpy(bmpBits+bmpsize*startscan, bits, size);
358 }
359 return(lines);
360}
361//******************************************************************************
362//******************************************************************************
363int DIBSection::SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb)
364{
365 int i;
366
367 if(startIdx + cEntries > (1 << pOS2bmp->cBitCount))
368 {
369 dprintf(("DIBSection::SetDIBColorTable, invalid nr of entries %d %d\n", startIdx, cEntries));
370 return(0);
371 }
372
373 memcpy(&pOS2bmp->argbColor[startIdx], rgb, cEntries*sizeof(RGB2));
374
375 for(i=startIdx;i<cEntries;i++)
376 {
377 pOS2bmp->argbColor[i].fcOptions = 0;
378 dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&pOS2bmp->argbColor[i])) ));
379 }
380
381 return(cEntries);
382}
383//******************************************************************************
384//******************************************************************************
385BOOL DIBSection::BitBlt(HDC hdcDest, int nXdest, int nYdest, int nDestWidth,
386 int nDestHeight, int nXsrc, int nYsrc,
387 int nSrcWidth, int nSrcHeight, DWORD Rop)
388{
389 HPS hps = (HPS)hdcDest;
390 POINTL point[4];
391 LONG rc, hdcHeight, hdcWidth;
392 PVOID bitmapBits = NULL;
393 int oldyinversion = 0;
394 BOOL fRestoryYInversion = FALSE, fFrameWindowDC = FALSE;
395 HWND hwndDest;
396
397 hwndDest = WindowFromDC(hdcDest);
398 //TODO: Test whether dc is for the client or frame window
399// if(hwndDest && IsOS2FrameWindowHandle(hwndDest)) {
400// fFrameWindowDC = TRUE;
401// }
402
403 dprintf(("DIBSection::BitBlt %x %X (hps %x) %x to(%d,%d)(%d,%d) from (%d,%d)(%d,%d) rop %x flip %x",
404 handle, hdcDest, hps, hwndDest, nXdest, nYdest, nDestWidth, nDestHeight,
405 nXsrc, nYsrc, nSrcWidth, nSrcHeight, Rop, fFlip));
406
407 if(hwndDest) {
408 RECT rect;
409
410 if(fFrameWindowDC) {
411 GetWindowRect(hwndDest, &rect);
412 }
413 else GetClientRect(hwndDest, &rect);
414 hdcHeight = rect.bottom - rect.top;
415 hdcWidth = rect.right - rect.left;
416 }
417 else {
418 hdcHeight = pOS2bmp->cy;
419 hdcWidth = pOS2bmp->cx;
420 }
421
422 //win32 coordinates are of the left top, OS/2 expects left bottom
423 //source rectangle is non-inclusive (top, right not included)
424 if(nXdest + nDestWidth > hdcWidth) {
425 nDestWidth = hdcWidth - nXdest;
426 }
427 if(nYdest + nDestHeight > hdcHeight) {
428 nDestHeight = hdcHeight - nYdest;
429 }
430 point[0].x = nXdest;
431 point[0].y = hdcHeight - nYdest - nDestHeight;
432 point[1].x = nXdest + nDestWidth;
433 point[1].y = hdcHeight - nYdest;
434
435 //target rectangle is inclusive-inclusive
436 if(nXsrc + nSrcWidth > pOS2bmp->cx) {
437 nSrcWidth = pOS2bmp->cx - nXsrc;
438 }
439 if(nYsrc + nSrcHeight > pOS2bmp->cy) {
440 nSrcHeight = pOS2bmp->cy - nYsrc;
441 }
442 point[2].x = nXsrc;
443 point[2].y = pOS2bmp->cy - nYsrc - nSrcHeight;
444 point[3].x = nXsrc + nSrcWidth;
445 point[3].y = pOS2bmp->cy - nYsrc;
446
447 oldyinversion = GpiQueryYInversion(hps);
448 if(oldyinversion != 0) {
449 GpiEnableYInversion(hps, 0);
450 fRestoryYInversion = TRUE;
451 }
452
453 if(fFlip & FLIP_HOR)
454 {
455 ULONG x;
456 x = point[0].x;
457 point[0].x = point[1].x;
458 point[1].x = x;
459 }
460
461 ULONG os2mode, winmode;
462
463 os2mode = BBO_OR;
464 winmode = GetStretchBltMode(hdcDest);
465 switch(winmode) {
466 case BLACKONWHITE_W:
467 os2mode = BBO_AND;
468 break;
469 case WHITEONBLACK_W:
470 case HALFTONE_W: //TODO:
471 os2mode = BBO_OR;
472 break;
473 case COLORONCOLOR_W:
474 os2mode = BBO_IGNORE;
475 break;
476 }
477 if(fFlip & FLIP_VERT) {
478 //manually reverse bitmap data
479 char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
480 char *dst = bmpBitsBuffer;
481 for(int i=0;i<pOS2bmp->cy;i++) {
482 memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
483 dst += dibinfo.dsBm.bmWidthBytes;
484 src -= dibinfo.dsBm.bmWidthBytes;
485 }
486 bmpBits = bmpBitsBuffer;
487 }
488
489 //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
490 if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
491 dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
492
493 if(bmpBitsBuffer == NULL)
494 DebugInt3();
495
496 if(CPUFeatures & CPUID_MMX) {
497 RGB555to565MMX((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
498 }
499 else RGB555to565((WORD *)bmpBitsBuffer, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
500 rc = GpiDrawBits(hps, bmpBitsBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
501 }
502 else rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
503
504 if(rc == GPI_OK) {
505 DIBSection *destdib = DIBSection::findHDC(hdcDest);
506 if(destdib) {
507 destdib->sync(hps, nYdest, nDestHeight);
508 }
509 //restore old y inversion height
510 if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
511 return(TRUE);
512 }
513 if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
514
515 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));
516 dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndDest)) & 0xFFFF));
517 return(FALSE);
518}
519//******************************************************************************
520//******************************************************************************
521void DIBSection::sync(HDC hdc, DWORD nYdest, DWORD nDestHeight)
522{
523 APIRET rc;
524 char *destBuf;
525
526 dprintf(("Sync destination dibsection %x (%x)", handle, hdc));
527
528 //todo: rgb 565 to 555 conversion if bpp == 16
529 if(GetBitCount() == 16) {
530 dprintf(("WARNING: need to convert RGB 565 to RGB 555!!"));
531 }
532
533 BITMAPINFO2 *tmphdr = (BITMAPINFO2 *)malloc(os2bmphdrsize);
534 memcpy(tmphdr, pOS2bmp, os2bmphdrsize);
535 destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
536 rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
537 tmphdr);
538 free(tmphdr);
539 if(rc != nDestHeight) {
540 DebugInt3();
541 }
542}
543//******************************************************************************
544//******************************************************************************
545void DIBSection::SelectDIBObject(HDC hdc)
546{
547 this->hdc = hdc;
548 hwndParent = WindowFromDC(hdc);
549 dprintf(("SelectDIBObject %x into %x hwndParent = %x", handle, hdc, hwndParent));
550}
551//******************************************************************************
552//******************************************************************************
553DIBSection *DIBSection::find(DWORD handle)
554{
555 DIBSection *dsect = section;
556
557 dibMutex.enter();
558 while(dsect)
559 {
560 if(dsect->handle == handle)
561 {
562 dibMutex.leave();
563 return(dsect);
564 }
565 dsect = dsect->next;
566 }
567 dibMutex.leave();
568 return(NULL);
569}
570//******************************************************************************
571//A bitmap can only be selected into one DC, so this works.
572//******************************************************************************
573DIBSection *DIBSection::findHDC(HDC hdc)
574{
575 DIBSection *dsect = section;
576
577 while(dsect)
578 {
579 if(dsect->hdc == hdc)
580 {
581 return(dsect);
582 }
583 dsect = dsect->next;
584 }
585 return(NULL);
586}
587//******************************************************************************
588//******************************************************************************
589void DIBSection::deleteSection(DWORD handle)
590{
591 DIBSection *dsect = find(handle);
592
593 if(dsect)
594 delete dsect;
595
596}
597//******************************************************************************
598//******************************************************************************
599int DIBSection::GetDIBSection(int iSize, void *lpBuffer)
600{
601 DIBSECTION *pDIBSection = (DIBSECTION *)lpBuffer;
602 LPBITMAP_W dsBm = (LPBITMAP_W)lpBuffer;
603
604 dprintf2(("GetDIBSection %x %d %x", handle, iSize, lpBuffer));
605 if(iSize == sizeof(DIBSECTION))
606 {
607 memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
608 return sizeof(DIBSECTION);
609 }
610 else
611 if(iSize == sizeof(BITMAP_W))
612 {
613 memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
614 return sizeof(BITMAP_W);
615 }
616 return 0;
617
618}
619//******************************************************************************
620//******************************************************************************
621int DIBSection::GetBitCount()
622{
623 if(pOS2bmp == NULL)
624 return 0;
625 else
626 return pOS2bmp->cBitCount;
627}
628//******************************************************************************
629//******************************************************************************
630int DIBSection::GetHeight()
631{
632 if(pOS2bmp == NULL)
633 return 0;
634 else
635 return pOS2bmp->cy;
636}
637//******************************************************************************
638//******************************************************************************
639DIBSection *DIBSection::section = NULL;
Note: See TracBrowser for help on using the repository browser.