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

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

dib blit fixes

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