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

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

lots of small changes; CreateHalftonePalette + rgb 565 -> rgb 555 conversion

File size: 21.8 KB
Line 
1/* $Id: dibsect.cpp,v 1.37 2000-08-18 18:14:57 sandervl Exp $ */
2
3/*
4 * GDI32 DIB sections
5 *
6 * Copyright 1998-2000 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 = dwOffset;
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)hdcDest);
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 relative to left top, OS/2 expects left bottom
431 //source rectangle is non-inclusive (top, right not included)
432 //destination rectangle is incl.-inclusive (everything included)
433 if(nXdest + nDestWidth > hdcWidth) {
434 nDestWidth = hdcWidth - nXdest;
435 }
436 if(nYdest + nDestHeight > hdcHeight) {
437 nDestHeight = hdcHeight - nYdest;
438 }
439 point[0].x = nXdest;
440 point[0].y = hdcHeight - nYdest - nDestHeight;
441 point[1].x = nXdest + nDestWidth - 1;
442 point[1].y = hdcHeight - nYdest - 1;
443
444 //target rectangle is inclusive-inclusive
445 if(nXsrc + nSrcWidth > pOS2bmp->cx) {
446 nSrcWidth = pOS2bmp->cx - nXsrc;
447 }
448 if(nYsrc + nSrcHeight > pOS2bmp->cy) {
449 nSrcHeight = pOS2bmp->cy - nYsrc;
450 }
451 point[2].x = nXsrc;
452 point[2].y = pOS2bmp->cy - nYsrc - nSrcHeight;
453 point[3].x = nXsrc + nSrcWidth;
454 point[3].y = pOS2bmp->cy - nYsrc;
455
456 dprintf(("DIBSection::BitBlt (%d,%d)(%d,%d) from (%d,%d)(%d,%d) dim (%d,%d)(%d,%d)", point[0].x, point[0].y,
457 point[1].x, point[1].y, point[2].x, point[2].y, point[3].x, point[3].y,
458 nDestWidth, nDestHeight, nSrcWidth, nSrcHeight));
459
460/*
461 hwndDest = Win32ToOS2Handle(hwndDest);
462 if(hwndDest != 0)
463 {
464 hps = WinGetPS(hwndDest);
465 }
466*/
467 oldyinversion = GpiQueryYInversion(hps);
468 if(oldyinversion != 0) {
469 GpiEnableYInversion(hps, 0);
470 fRestoryYInversion = TRUE;
471 }
472
473 if(fFlip & FLIP_HOR)
474 {
475 ULONG x;
476 x = point[0].x;
477 point[0].x = point[1].x;
478 point[1].x = x;
479 }
480
481 ULONG os2mode, winmode;
482
483 os2mode = BBO_OR;
484 winmode = GetStretchBltMode(hdcDest);
485 switch(winmode) {
486 case BLACKONWHITE_W:
487 os2mode = BBO_AND;
488 break;
489 case WHITEONBLACK_W:
490 case HALFTONE_W: //TODO:
491 os2mode = BBO_OR;
492 break;
493 case COLORONCOLOR_W:
494 os2mode = BBO_IGNORE;
495 break;
496 }
497 if(fFlip & FLIP_VERT) {
498 //manually reverse bitmap data
499 char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
500 char *dst = bmpBitsDblBuffer;
501 for(int i=0;i<pOS2bmp->cy;i++) {
502 memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
503 dst += dibinfo.dsBm.bmWidthBytes;
504 src -= dibinfo.dsBm.bmWidthBytes;
505 }
506 bitmapBits = bmpBitsDblBuffer;
507 }
508 else bitmapBits = bmpBits;
509
510 //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
511 if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
512 dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
513
514 if(bmpBitsDblBuffer == NULL)
515 DebugInt3();
516
517 if(CPUFeatures & CPUID_MMX) {
518 RGB555to565MMX((WORD *)bmpBitsDblBuffer, (WORD *)bitmapBits, pOS2bmp->cbImage/sizeof(WORD));
519 }
520 else RGB555to565((WORD *)bmpBitsDblBuffer, (WORD *)bitmapBits, pOS2bmp->cbImage/sizeof(WORD));
521 rc = GpiDrawBits(hps, bmpBitsDblBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
522 }
523 else rc = GpiDrawBits(hps, bitmapBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
524
525/*
526 if(hwndDest != 0)
527 {
528 WinReleasePS(hps);
529 }
530*/
531 if(rc == GPI_OK) {
532 DIBSection *destdib = DIBSection::findHDC(hdcDest);
533 if(destdib) {
534 destdib->sync(hps, nYdest, nDestHeight);
535 }
536 //restore old y inversion height
537 if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
538 SetLastError(ERROR_SUCCESS_W);
539
540 return(TRUE);
541 }
542 if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
543
544 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));
545 dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndDest)) & 0xFFFF));
546 return(FALSE);
547}
548//******************************************************************************
549//******************************************************************************
550void DIBSection::sync(HDC hdc, DWORD nYdest, DWORD nDestHeight)
551{
552 APIRET rc;
553 char *destBuf;
554
555 dprintf(("Sync destination dibsection %x (%x)", handle, hdc));
556
557 BITMAPINFO2 *tmphdr = (BITMAPINFO2 *)malloc(os2bmphdrsize);
558 memcpy(tmphdr, pOS2bmp, os2bmphdrsize);
559
560 if(fFlip & FLIP_VERT) {
561 destBuf = bmpBitsDblBuffer + nYdest*dibinfo.dsBm.bmWidthBytes;
562
563 rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
564 tmphdr);
565 //manually reverse bitmap data
566 char *src = destBuf;
567 char *dst = GetDIBObject() + (nYdest+nDestHeight-1)*dibinfo.dsBm.bmWidthBytes;
568 for(int i=0;i<nDestHeight;i++) {
569 memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
570 dst -= dibinfo.dsBm.bmWidthBytes;
571 src += dibinfo.dsBm.bmWidthBytes;
572 }
573 }
574 else {
575 destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
576 rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
577 tmphdr);
578 }
579 if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
580 dprintf(("DIBSection::sync: convert RGB 565 to RGB 555"));
581
582 destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
583
584 if(CPUFeatures & CPUID_MMX) {
585 RGB565to555MMX((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
586 }
587 else RGB565to555((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
588 }
589 free(tmphdr);
590 if(rc != nDestHeight) {
591 DebugInt3();
592 }
593}
594//******************************************************************************
595//******************************************************************************
596void DIBSection::SelectDIBObject(HDC hdc)
597{
598 this->hdc = hdc;
599 hwndParent = WindowFromDC(hdc);
600 dprintf(("SelectDIBObject %x into %x hwndParent = %x", handle, hdc, hwndParent));
601}
602//******************************************************************************
603//******************************************************************************
604DIBSection *DIBSection::find(DWORD handle)
605{
606 DIBSection *dsect = section;
607
608 dibMutex.enter();
609 while(dsect)
610 {
611 if(dsect->handle == handle)
612 {
613 dibMutex.leave();
614 return(dsect);
615 }
616 dsect = dsect->next;
617 }
618 dibMutex.leave();
619 return(NULL);
620}
621//******************************************************************************
622//A bitmap can only be selected into one DC, so this works.
623//******************************************************************************
624DIBSection *DIBSection::findHDC(HDC hdc)
625{
626 DIBSection *dsect = section;
627
628 while(dsect)
629 {
630 if(dsect->hdc == hdc)
631 {
632 return(dsect);
633 }
634 dsect = dsect->next;
635 }
636 return(NULL);
637}
638//******************************************************************************
639//******************************************************************************
640void DIBSection::deleteSection(DWORD handle)
641{
642 DIBSection *dsect = find(handle);
643
644 if(dsect)
645 delete dsect;
646
647}
648//******************************************************************************
649//******************************************************************************
650int DIBSection::GetDIBSection(int iSize, void *lpBuffer)
651{
652 DIBSECTION *pDIBSection = (DIBSECTION *)lpBuffer;
653 LPBITMAP_W dsBm = (LPBITMAP_W)lpBuffer;
654
655 dprintf2(("GetDIBSection %x %d %x", handle, iSize, lpBuffer));
656 if(iSize == sizeof(DIBSECTION))
657 {
658 memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
659 return sizeof(DIBSECTION);
660 }
661 else
662 if(iSize == sizeof(BITMAP_W))
663 {
664 memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
665 return sizeof(BITMAP_W);
666 }
667 return 0;
668
669}
670//******************************************************************************
671//******************************************************************************
672int DIBSection::GetBitCount()
673{
674 if(pOS2bmp == NULL)
675 return 0;
676 else
677 return pOS2bmp->cBitCount;
678}
679//******************************************************************************
680//******************************************************************************
681int DIBSection::GetHeight()
682{
683 if(pOS2bmp == NULL)
684 return 0;
685 else
686 return pOS2bmp->cy;
687}
688//******************************************************************************
689//******************************************************************************
690DIBSection *DIBSection::section = NULL;
Note: See TracBrowser for help on using the repository browser.