| 1 | /* $Id: dibsect.cpp,v 1.44 2000-12-29 18:40:43 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 <cpuhlp.h>
|
|---|
| 28 | #include <dcdata.h>
|
|---|
| 29 | #include "oslibgpi.h"
|
|---|
| 30 | #include "rgbcvt.h"
|
|---|
| 31 |
|
|---|
| 32 | #define DBG_LOCALLOG DBG_dibsect
|
|---|
| 33 | #include "dbglocal.h"
|
|---|
| 34 |
|
|---|
| 35 | static VMutex dibMutex;
|
|---|
| 36 |
|
|---|
| 37 | //******************************************************************************
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | DIBSection::DIBSection(BITMAPINFOHEADER_W *pbmi, char *pColors, DWORD iUsage, DWORD hSection, DWORD dwOffset, DWORD handle, int fFlip)
|
|---|
| 40 | : bmpBits(NULL), pOS2bmp(NULL), next(NULL), bmpBitsDblBuffer(NULL)
|
|---|
| 41 | {
|
|---|
| 42 | int palsize=0;
|
|---|
| 43 |
|
|---|
| 44 | bmpsize = pbmi->biWidth;
|
|---|
| 45 | /* @@@PH 98/06/07 -- high-color bitmaps don't have palette */
|
|---|
| 46 |
|
|---|
| 47 | this->fFlip = fFlip;
|
|---|
| 48 | os2bmphdrsize = sizeof(BITMAPINFO2);
|
|---|
| 49 |
|
|---|
| 50 | switch(pbmi->biBitCount)
|
|---|
| 51 | {
|
|---|
| 52 | case 1:
|
|---|
| 53 | bmpsize = ((bmpsize + 31) & ~31) / 8;
|
|---|
| 54 | palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
|
|---|
| 55 | os2bmphdrsize += palsize;
|
|---|
| 56 | break;
|
|---|
| 57 | case 4:
|
|---|
| 58 | bmpsize = ((bmpsize + 7) & ~7) / 2;
|
|---|
| 59 | palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
|
|---|
| 60 | os2bmphdrsize += palsize;
|
|---|
| 61 | break;
|
|---|
| 62 | case 8:
|
|---|
| 63 | palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
|
|---|
| 64 | os2bmphdrsize += palsize;
|
|---|
| 65 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 66 | break;
|
|---|
| 67 | case 16:
|
|---|
| 68 | bmpsize *= 2;
|
|---|
| 69 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 70 | break;
|
|---|
| 71 | case 24:
|
|---|
| 72 | bmpsize *= 3;
|
|---|
| 73 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 74 | break;
|
|---|
| 75 | case 32:
|
|---|
| 76 | bmpsize *= 4;
|
|---|
| 77 | break;
|
|---|
| 78 | default:
|
|---|
| 79 | dprintf(("Unsupported nr of bits %d", pbmi->biBitCount));
|
|---|
| 80 | DebugInt3();
|
|---|
| 81 | break;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | this->hSection = hSection;
|
|---|
| 85 | this->dwOffset = dwOffset;
|
|---|
| 86 | if(hSection) {
|
|---|
| 87 | bmpBits = (char *)MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS_W, 0, dwOffset, bmpsize*pbmi->biHeight);
|
|---|
| 88 | if(!bmpBits) {
|
|---|
| 89 | dprintf(("Dibsection: mapViewOfFile %x failed!", hSection));
|
|---|
| 90 | DebugInt3();
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 | if(!bmpBits) {
|
|---|
| 94 | DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
|
|---|
| 95 | }
|
|---|
| 96 | memset(bmpBits, 0, bmpsize*pbmi->biHeight);
|
|---|
| 97 |
|
|---|
| 98 | pOS2bmp = (BITMAPINFO2 *)malloc(os2bmphdrsize);
|
|---|
| 99 |
|
|---|
| 100 | memset(pOS2bmp, /* set header + palette entries to zero */
|
|---|
| 101 | 0,
|
|---|
| 102 | os2bmphdrsize);
|
|---|
| 103 |
|
|---|
| 104 | pOS2bmp->cbFix = sizeof(BITMAPINFO2) - sizeof(RGB2);
|
|---|
| 105 | pOS2bmp->cx = pbmi->biWidth;
|
|---|
| 106 | pOS2bmp->cy = pbmi->biHeight;
|
|---|
| 107 | pOS2bmp->cPlanes = pbmi->biPlanes;
|
|---|
| 108 | pOS2bmp->cBitCount = pbmi->biBitCount;
|
|---|
| 109 | pOS2bmp->ulCompression = pbmi->biCompression; //same as OS/2 (uncompressed, rle8, rle4)
|
|---|
| 110 | //SvL: Ignore BI_BITFIELDS_W type (GpiDrawBits fails otherwise)
|
|---|
| 111 | if(pOS2bmp->ulCompression == BI_BITFIELDS_W) {
|
|---|
| 112 | pOS2bmp->ulCompression = 0;
|
|---|
| 113 | }
|
|---|
| 114 | pOS2bmp->cbImage = pbmi->biSizeImage;
|
|---|
| 115 | dprintf(("handle %x", handle));
|
|---|
| 116 | dprintf(("pOS2bmp->cx %d\n", pOS2bmp->cx));
|
|---|
| 117 | dprintf(("pOS2bmp->cy %d\n", pOS2bmp->cy));
|
|---|
| 118 | dprintf(("pOS2bmp->cPlanes %d\n", pOS2bmp->cPlanes));
|
|---|
| 119 | dprintf(("pOS2bmp->cBitCount %d\n", pOS2bmp->cBitCount));
|
|---|
| 120 | dprintf(("pOS2bmp->ulCompression %d\n", pOS2bmp->ulCompression));
|
|---|
| 121 | dprintf(("pOS2bmp->cbImage %d\n", pOS2bmp->cbImage));
|
|---|
| 122 | dprintf(("Bits at %x, size %d",bmpBits, bmpsize*pbmi->biHeight));
|
|---|
| 123 |
|
|---|
| 124 | // clear DIBSECTION structure
|
|---|
| 125 | memset(&dibinfo, 0, sizeof(dibinfo));
|
|---|
| 126 |
|
|---|
| 127 | // copy BITMAPINFOHEADER data into DIBSECTION structure
|
|---|
| 128 | memcpy(&dibinfo.dsBmih, pbmi, sizeof(*pbmi));
|
|---|
| 129 | dibinfo.dsBm.bmType = 0;
|
|---|
| 130 | dibinfo.dsBm.bmWidth = pbmi->biWidth;
|
|---|
| 131 | dibinfo.dsBm.bmHeight = pbmi->biHeight;
|
|---|
| 132 | dibinfo.dsBm.bmWidthBytes= bmpsize;
|
|---|
| 133 | dibinfo.dsBm.bmPlanes = pbmi->biPlanes;
|
|---|
| 134 | dibinfo.dsBm.bmBitsPixel = pbmi->biBitCount;
|
|---|
| 135 | dibinfo.dsBm.bmBits = bmpBits;
|
|---|
| 136 |
|
|---|
| 137 | dibinfo.dshSection = hSection;
|
|---|
| 138 | dibinfo.dsOffset = dwOffset;
|
|---|
| 139 |
|
|---|
| 140 | if(iUsage == DIB_PAL_COLORS || pbmi->biBitCount <= 8)
|
|---|
| 141 | {
|
|---|
| 142 | dibinfo.dsBitfields[0] = dibinfo.dsBitfields[1] = dibinfo.dsBitfields[2] = 0;
|
|---|
| 143 | if(palsize) {
|
|---|
| 144 | SetDIBColorTable(0, (1 << pbmi->biBitCount), (RGBQUAD *)(pbmi+1));
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 | else {
|
|---|
| 148 | switch(pbmi->biBitCount)
|
|---|
| 149 | {
|
|---|
| 150 | case 16:
|
|---|
| 151 | dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0x7c00;
|
|---|
| 152 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
|
|---|
| 153 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0x001f;
|
|---|
| 154 | break;
|
|---|
| 155 |
|
|---|
| 156 | case 24:
|
|---|
| 157 | dibinfo.dsBitfields[0] = 0xff;
|
|---|
| 158 | dibinfo.dsBitfields[1] = 0xff00;
|
|---|
| 159 | dibinfo.dsBitfields[2] = 0xff0000;
|
|---|
| 160 | break;
|
|---|
| 161 |
|
|---|
| 162 | case 32:
|
|---|
| 163 | dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0xff;
|
|---|
| 164 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
|
|---|
| 165 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0xff0000;
|
|---|
| 166 | if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
|
|---|
| 167 | dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
|
|---|
| 168 | }
|
|---|
| 169 | break;
|
|---|
| 170 | }
|
|---|
| 171 | dprintf(("BI_BITFIELDS_W %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
|
|---|
| 172 | }
|
|---|
| 173 | //double buffer for rgb 555 dib sections (for conversion) or flipped sections
|
|---|
| 174 | if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
|
|---|
| 175 | DosAllocMem((PPVOID)&bmpBitsDblBuffer, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | this->handle = handle;
|
|---|
| 179 | this->iUsage = iUsage;
|
|---|
| 180 |
|
|---|
| 181 | dibMutex.enter();
|
|---|
| 182 | if(section == NULL)
|
|---|
| 183 | {
|
|---|
| 184 | dprintf(("section was NULL\n"));
|
|---|
| 185 | section = this;
|
|---|
| 186 | }
|
|---|
| 187 | else
|
|---|
| 188 | {
|
|---|
| 189 | DIBSection *dsect = section;
|
|---|
| 190 | dprintf2(("Increment section starting at %08X\n",dsect));
|
|---|
| 191 |
|
|---|
| 192 | /* @@@PH 98/07/11 fix for dsect->next == NULL */
|
|---|
| 193 | while ( (dsect->next != this) &&
|
|---|
| 194 | (dsect->next != NULL) )
|
|---|
| 195 | {
|
|---|
| 196 | dprintf2(("Increment section to %08X\n",dsect->next));
|
|---|
| 197 | dsect = dsect->next;
|
|---|
| 198 | }
|
|---|
| 199 | dsect->next = this;
|
|---|
| 200 | }
|
|---|
| 201 | dibMutex.leave();
|
|---|
| 202 | }
|
|---|
| 203 | //******************************************************************************
|
|---|
| 204 | //******************************************************************************
|
|---|
| 205 | DIBSection::~DIBSection()
|
|---|
| 206 | {
|
|---|
| 207 | dprintf(("Delete DIBSection %x", handle));
|
|---|
| 208 |
|
|---|
| 209 | if(hSection) {
|
|---|
| 210 | UnmapViewOfFile(bmpBits);
|
|---|
| 211 | }
|
|---|
| 212 | else
|
|---|
| 213 | if(bmpBits)
|
|---|
| 214 | DosFreeMem(bmpBits);
|
|---|
| 215 |
|
|---|
| 216 | if(bmpBitsDblBuffer)
|
|---|
| 217 | DosFreeMem(bmpBitsDblBuffer);
|
|---|
| 218 |
|
|---|
| 219 | if(pOS2bmp)
|
|---|
| 220 | free(pOS2bmp);
|
|---|
| 221 |
|
|---|
| 222 | dibMutex.enter();
|
|---|
| 223 | if(section == this)
|
|---|
| 224 | {
|
|---|
| 225 | section = this->next;
|
|---|
| 226 | }
|
|---|
| 227 | else
|
|---|
| 228 | {
|
|---|
| 229 | DIBSection *dsect = section;
|
|---|
| 230 |
|
|---|
| 231 | while(dsect->next != this)
|
|---|
| 232 | {
|
|---|
| 233 | dsect = dsect->next;
|
|---|
| 234 | }
|
|---|
| 235 | dsect->next = this->next;
|
|---|
| 236 | }
|
|---|
| 237 | dibMutex.leave();
|
|---|
| 238 | }
|
|---|
| 239 | //******************************************************************************
|
|---|
| 240 | //******************************************************************************
|
|---|
| 241 | int DIBSection::SetDIBits(HDC hdc, HBITMAP hbitmap, UINT startscan, UINT
|
|---|
| 242 | lines, const VOID *bits, BITMAPINFOHEADER_W *pbmi,
|
|---|
| 243 | UINT coloruse)
|
|---|
| 244 | {
|
|---|
| 245 | lines = (int)lines >= 0 ? (int)lines : (int)-lines;
|
|---|
| 246 | int palsize=0;
|
|---|
| 247 |
|
|---|
| 248 | bmpsize = pbmi->biWidth;
|
|---|
| 249 | os2bmphdrsize = sizeof(BITMAPINFO2);
|
|---|
| 250 |
|
|---|
| 251 | switch(pbmi->biBitCount)
|
|---|
| 252 | {
|
|---|
| 253 | case 1:
|
|---|
| 254 | bmpsize = ((bmpsize + 31) & ~31) / 8;
|
|---|
| 255 | palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
|
|---|
| 256 | os2bmphdrsize += palsize;
|
|---|
| 257 | break;
|
|---|
| 258 | case 4:
|
|---|
| 259 | bmpsize = ((bmpsize + 7) & ~7) / 2;
|
|---|
| 260 | palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
|
|---|
| 261 | os2bmphdrsize += palsize;
|
|---|
| 262 | break;
|
|---|
| 263 | case 8:
|
|---|
| 264 | palsize = ((1 << pbmi->biBitCount))*sizeof(RGB2);
|
|---|
| 265 | os2bmphdrsize += palsize;
|
|---|
| 266 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 267 | break;
|
|---|
| 268 | case 16:
|
|---|
| 269 | bmpsize *= 2;
|
|---|
| 270 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 271 | break;
|
|---|
| 272 | case 24:
|
|---|
| 273 | bmpsize *= 3;
|
|---|
| 274 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 275 | break;
|
|---|
| 276 | case 32:
|
|---|
| 277 | bmpsize *= 4;
|
|---|
| 278 | break;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | //SvL: TODO: Correct??
|
|---|
| 282 | if(!hSection && pOS2bmp->cx != pbmi->biWidth && pOS2bmp->cy != pbmi->biHeight &&
|
|---|
| 283 | pOS2bmp->cBitCount != pbmi->biBitCount)
|
|---|
| 284 | {
|
|---|
| 285 | char *oldbits = bmpBits;
|
|---|
| 286 | int oldsize = dibinfo.dsBm.bmWidthBytes * dibinfo.dsBm.bmHeight;
|
|---|
| 287 |
|
|---|
| 288 | DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
|
|---|
| 289 | memcpy(bmpBits, oldbits, min(oldsize, bmpsize*pbmi->biHeight));
|
|---|
| 290 | DosFreeMem(oldbits);
|
|---|
| 291 | }
|
|---|
| 292 | pOS2bmp = (BITMAPINFO2 *)realloc(pOS2bmp, os2bmphdrsize);
|
|---|
| 293 | pOS2bmp->cbFix = sizeof(BITMAPINFO2) - sizeof(RGB2);
|
|---|
| 294 | pOS2bmp->cx = pbmi->biWidth;
|
|---|
| 295 | pOS2bmp->cy = pbmi->biHeight;
|
|---|
| 296 | pOS2bmp->cPlanes = pbmi->biPlanes;
|
|---|
| 297 | pOS2bmp->cBitCount = pbmi->biBitCount;
|
|---|
| 298 | pOS2bmp->ulCompression = pbmi->biCompression; //same as OS/2 (uncompressed, rle8, rle4)
|
|---|
| 299 | //SvL: Ignore BI_BITFIELDS_W type (GpiDrawBits fails otherwise)
|
|---|
| 300 | if(pOS2bmp->ulCompression == BI_BITFIELDS_W) {
|
|---|
| 301 | pOS2bmp->ulCompression = 0;
|
|---|
| 302 | }
|
|---|
| 303 | pOS2bmp->cbImage = pbmi->biSizeImage;
|
|---|
| 304 |
|
|---|
| 305 | // clear DIBSECTION structure
|
|---|
| 306 | memset(&dibinfo, 0, sizeof(dibinfo));
|
|---|
| 307 |
|
|---|
| 308 | // copy BITMAPINFOHEADER data into DIBSECTION structure
|
|---|
| 309 | memcpy(&dibinfo.dsBmih, pbmi, sizeof(*pbmi));
|
|---|
| 310 | dibinfo.dsBm.bmType = 0;
|
|---|
| 311 | dibinfo.dsBm.bmWidth = pbmi->biWidth;
|
|---|
| 312 | dibinfo.dsBm.bmHeight = pbmi->biHeight;
|
|---|
| 313 | dibinfo.dsBm.bmWidthBytes= bmpsize;
|
|---|
| 314 | dibinfo.dsBm.bmPlanes = pbmi->biPlanes;
|
|---|
| 315 | dibinfo.dsBm.bmBitsPixel = pbmi->biBitCount;
|
|---|
| 316 | dibinfo.dsBm.bmBits = bmpBits;
|
|---|
| 317 |
|
|---|
| 318 | dibinfo.dshSection = hSection;
|
|---|
| 319 | dibinfo.dsOffset = dwOffset;
|
|---|
| 320 |
|
|---|
| 321 | if(coloruse == DIB_PAL_COLORS || pbmi->biBitCount <= 8)
|
|---|
| 322 | {
|
|---|
| 323 | dibinfo.dsBitfields[0] = dibinfo.dsBitfields[1] = dibinfo.dsBitfields[2] = 0;
|
|---|
| 324 | }
|
|---|
| 325 | else {
|
|---|
| 326 | char *pColors = (char *)pbmi + 1;
|
|---|
| 327 |
|
|---|
| 328 | switch(pbmi->biBitCount)
|
|---|
| 329 | {
|
|---|
| 330 | case 16:
|
|---|
| 331 | dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0x7c00;
|
|---|
| 332 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0x03e0;
|
|---|
| 333 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0x001f;
|
|---|
| 334 | break;
|
|---|
| 335 |
|
|---|
| 336 | case 24:
|
|---|
| 337 | dibinfo.dsBitfields[0] = 0xff;
|
|---|
| 338 | dibinfo.dsBitfields[1] = 0xff00;
|
|---|
| 339 | dibinfo.dsBitfields[2] = 0xff0000;
|
|---|
| 340 | break;
|
|---|
| 341 |
|
|---|
| 342 | case 32:
|
|---|
| 343 | dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS_W) ? *(DWORD *)pColors : 0xff;
|
|---|
| 344 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 1) : 0xff00;
|
|---|
| 345 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS_W) ? *((DWORD *)pColors + 2) : 0xff0000;
|
|---|
| 346 | if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
|
|---|
| 347 | dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
|
|---|
| 348 | }
|
|---|
| 349 | break;
|
|---|
| 350 | }
|
|---|
| 351 | dprintf(("BI_BITFIELDS_W %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | //double buffer for rgb 555 dib sections (for conversion) or flipped sections
|
|---|
| 355 | if(dibinfo.dsBitfields[1] == 0x03e0 || (fFlip & FLIP_VERT)) {
|
|---|
| 356 | if(bmpBitsDblBuffer) {
|
|---|
| 357 | DosFreeMem(bmpBitsDblBuffer);
|
|---|
| 358 | }
|
|---|
| 359 | DosAllocMem((PPVOID)&bmpBitsDblBuffer, dibinfo.dsBm.bmWidthBytes*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
|
|---|
| 363 | if(palsize) {
|
|---|
| 364 | SetDIBColorTable(0, 1 << pbmi->biBitCount, (RGBQUAD *)(pbmi+1));
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | if(bits)
|
|---|
| 368 | {
|
|---|
| 369 | if(pOS2bmp->ulCompression == BCA_UNCOMP) {
|
|---|
| 370 | int size = bmpsize*lines;
|
|---|
| 371 | memcpy(bmpBits+bmpsize*startscan, bits, size);
|
|---|
| 372 | }
|
|---|
| 373 | else {
|
|---|
| 374 | dprintf(("Compressed image!!"));
|
|---|
| 375 | if(startscan != 0) {
|
|---|
| 376 | dprintf(("WARNING: Compressed image & startscan != 0!!!!"));
|
|---|
| 377 | }
|
|---|
| 378 | memcpy(bmpBits, bits, pbmi->biSizeImage);
|
|---|
| 379 | }
|
|---|
| 380 | }
|
|---|
| 381 | return(lines);
|
|---|
| 382 | }
|
|---|
| 383 | //******************************************************************************
|
|---|
| 384 | //******************************************************************************
|
|---|
| 385 | int DIBSection::SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb)
|
|---|
| 386 | {
|
|---|
| 387 | int i;
|
|---|
| 388 |
|
|---|
| 389 | if(startIdx + cEntries > (1 << pOS2bmp->cBitCount))
|
|---|
| 390 | {
|
|---|
| 391 | dprintf(("DIBSection::SetDIBColorTable, invalid nr of entries %d %d\n", startIdx, cEntries));
|
|---|
| 392 | return(0);
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | memcpy(&pOS2bmp->argbColor[startIdx], rgb, cEntries*sizeof(RGB2));
|
|---|
| 396 |
|
|---|
| 397 | for(i=startIdx;i<cEntries;i++)
|
|---|
| 398 | {
|
|---|
| 399 | pOS2bmp->argbColor[i].fcOptions = 0;
|
|---|
| 400 | #ifdef DEBUG_PALETTE
|
|---|
| 401 | dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&pOS2bmp->argbColor[i])) ));
|
|---|
| 402 | #endif
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | return(cEntries);
|
|---|
| 406 | }
|
|---|
| 407 | //******************************************************************************
|
|---|
| 408 | //******************************************************************************
|
|---|
| 409 | int DIBSection::SetDIBColorTable(int startIdx, int cEntries, PALETTEENTRY *palentry)
|
|---|
| 410 | {
|
|---|
| 411 | int i;
|
|---|
| 412 |
|
|---|
| 413 | if(startIdx + cEntries > (1 << pOS2bmp->cBitCount))
|
|---|
| 414 | {
|
|---|
| 415 | dprintf(("DIBSection::SetDIBColorTable, invalid nr of entries %d %d\n", startIdx, cEntries));
|
|---|
| 416 | return(0);
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 | for(i=startIdx;i<cEntries;i++)
|
|---|
| 420 | {
|
|---|
| 421 | pOS2bmp->argbColor[i].fcOptions = 0;
|
|---|
| 422 | pOS2bmp->argbColor[i].bBlue = palentry[i].peBlue;
|
|---|
| 423 | pOS2bmp->argbColor[i].bGreen = palentry[i].peGreen;
|
|---|
| 424 | pOS2bmp->argbColor[i].bRed = palentry[i].peRed;
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | return(cEntries);
|
|---|
| 428 | }
|
|---|
| 429 | //******************************************************************************
|
|---|
| 430 | //******************************************************************************
|
|---|
| 431 | BOOL DIBSection::BitBlt(HDC hdcDest, int nXdest, int nYdest, int nDestWidth,
|
|---|
| 432 | int nDestHeight, int nXsrc, int nYsrc,
|
|---|
| 433 | int nSrcWidth, int nSrcHeight, DWORD Rop)
|
|---|
| 434 | {
|
|---|
| 435 | HPS hps = (HPS)hdcDest;
|
|---|
| 436 | POINTL point[4];
|
|---|
| 437 | LONG rc, hdcHeight, hdcWidth;
|
|---|
| 438 | PVOID bitmapBits = NULL;
|
|---|
| 439 | int oldyinversion = 0;
|
|---|
| 440 | BOOL fRestoryYInversion = FALSE, fFrameWindowDC = FALSE;
|
|---|
| 441 | HWND hwndDest;
|
|---|
| 442 | pDCData pHps;
|
|---|
| 443 |
|
|---|
| 444 | pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdcDest);
|
|---|
| 445 | if(!pHps)
|
|---|
| 446 | {
|
|---|
| 447 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 448 | return FALSE;
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | hwndDest = WindowFromDC(hdcDest); //could return desktop window, so check that
|
|---|
| 452 | if(hwndDest && pHps->hwnd && !pHps->isClient) {
|
|---|
| 453 | fFrameWindowDC = TRUE;
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | dprintf(("DIBSection::BitBlt %x %X (hps %x) %x to(%d,%d)(%d,%d) from (%d,%d)(%d,%d) rop %x flip %x",
|
|---|
| 457 | handle, hdcDest, hps, hwndDest, nXdest, nYdest, nDestWidth, nDestHeight,
|
|---|
| 458 | nXsrc, nYsrc, nSrcWidth, nSrcHeight, Rop, fFlip));
|
|---|
| 459 |
|
|---|
| 460 | if(hwndDest) {
|
|---|
| 461 | RECT rect;
|
|---|
| 462 |
|
|---|
| 463 | if(fFrameWindowDC) {
|
|---|
| 464 | GetWindowRect(hwndDest, &rect);
|
|---|
| 465 | }
|
|---|
| 466 | else GetClientRect(hwndDest, &rect);
|
|---|
| 467 | hdcHeight = rect.bottom - rect.top;
|
|---|
| 468 | hdcWidth = rect.right - rect.left;
|
|---|
| 469 | }
|
|---|
| 470 | else {
|
|---|
| 471 | DIBSection *dsect = DIBSection::findHDC(hdcDest);
|
|---|
| 472 | if(dsect)
|
|---|
| 473 | {
|
|---|
| 474 | hdcHeight = dsect->GetHeight();
|
|---|
| 475 | hdcWidth = dsect->GetWidth();
|
|---|
| 476 | }
|
|---|
| 477 | else
|
|---|
| 478 | {
|
|---|
| 479 | hdcHeight = pOS2bmp->cy;
|
|---|
| 480 | hdcWidth = pOS2bmp->cx;
|
|---|
| 481 | }
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | //win32 coordinates are relative to left top, OS/2 expects left bottom
|
|---|
| 485 | //source rectangle is non-inclusive (top, right not included)
|
|---|
| 486 | //destination rectangle is incl.-inclusive (everything included)
|
|---|
| 487 |
|
|---|
| 488 | if(nXdest + nDestWidth > hdcWidth) {
|
|---|
| 489 | nDestWidth = hdcWidth - nXdest;
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | if(nYdest + nDestHeight > hdcHeight) {
|
|---|
| 493 | nDestHeight = hdcHeight - nYdest;
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | point[0].x = nXdest;
|
|---|
| 497 | point[0].y = hdcHeight - nYdest - nDestHeight;
|
|---|
| 498 | point[1].x = nXdest + nDestWidth - 1;
|
|---|
| 499 | point[1].y = hdcHeight - nYdest - 1;
|
|---|
| 500 |
|
|---|
| 501 | //target rectangle is inclusive-inclusive
|
|---|
| 502 | if(nXsrc + nSrcWidth > pOS2bmp->cx) {
|
|---|
| 503 | nSrcWidth = pOS2bmp->cx - nXsrc;
|
|---|
| 504 | }
|
|---|
| 505 | if(nYsrc + nSrcHeight > pOS2bmp->cy) {
|
|---|
| 506 | nSrcHeight = pOS2bmp->cy - nYsrc;
|
|---|
| 507 | }
|
|---|
| 508 | point[2].x = nXsrc;
|
|---|
| 509 | point[2].y = pOS2bmp->cy - nYsrc - nSrcHeight;
|
|---|
| 510 | point[3].x = nXsrc + nSrcWidth;
|
|---|
| 511 | point[3].y = pOS2bmp->cy - nYsrc;
|
|---|
| 512 |
|
|---|
| 513 | dprintf(("DIBSection::BitBlt (%d,%d)(%d,%d) from (%d,%d)(%d,%d) dim (%d,%d)(%d,%d)", point[0].x, point[0].y,
|
|---|
| 514 | point[1].x, point[1].y, point[2].x, point[2].y, point[3].x, point[3].y,
|
|---|
| 515 | nDestWidth, nDestHeight, nSrcWidth, nSrcHeight));
|
|---|
| 516 |
|
|---|
| 517 | /*
|
|---|
| 518 | hwndDest = Win32ToOS2Handle(hwndDest);
|
|---|
| 519 | if(hwndDest != 0)
|
|---|
| 520 | {
|
|---|
| 521 | hps = WinGetPS(hwndDest);
|
|---|
| 522 | }
|
|---|
| 523 | */
|
|---|
| 524 | #ifdef INVERT
|
|---|
| 525 | oldyinversion = GpiQueryYInversion(hps);
|
|---|
| 526 | if(oldyinversion != 0) {
|
|---|
| 527 | GpiEnableYInversion(hps, 0);
|
|---|
| 528 | fRestoryYInversion = TRUE;
|
|---|
| 529 | }
|
|---|
| 530 | #endif
|
|---|
| 531 |
|
|---|
| 532 | #ifdef DEBUG
|
|---|
| 533 | RECTL rcltemp;
|
|---|
| 534 | GreGetDCOrigin(hps, (PPOINTL)&rcltemp);
|
|---|
| 535 | dprintf(("origin (%d,%d) yinv %d", rcltemp.xLeft, rcltemp.yBottom, oldyinversion));
|
|---|
| 536 | #endif
|
|---|
| 537 |
|
|---|
| 538 | if(fFlip & FLIP_HOR)
|
|---|
| 539 | {
|
|---|
| 540 | ULONG x;
|
|---|
| 541 | x = point[0].x;
|
|---|
| 542 | point[0].x = point[1].x;
|
|---|
| 543 | point[1].x = x;
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | ULONG os2mode, winmode;
|
|---|
| 547 |
|
|---|
| 548 | os2mode = BBO_OR;
|
|---|
| 549 | winmode = GetStretchBltMode(hdcDest);
|
|---|
| 550 | switch(winmode) {
|
|---|
| 551 | case BLACKONWHITE_W:
|
|---|
| 552 | os2mode = BBO_AND;
|
|---|
| 553 | break;
|
|---|
| 554 | case WHITEONBLACK_W:
|
|---|
| 555 | case HALFTONE_W: //TODO:
|
|---|
| 556 | os2mode = BBO_OR;
|
|---|
| 557 | break;
|
|---|
| 558 | case COLORONCOLOR_W:
|
|---|
| 559 | os2mode = BBO_IGNORE;
|
|---|
| 560 | break;
|
|---|
| 561 | }
|
|---|
| 562 | if(fFlip & FLIP_VERT) {
|
|---|
| 563 | //manually reverse bitmap data
|
|---|
| 564 | char *src = bmpBits + (pOS2bmp->cy-1)*dibinfo.dsBm.bmWidthBytes;
|
|---|
| 565 | char *dst = bmpBitsDblBuffer;
|
|---|
| 566 | for(int i=0;i<pOS2bmp->cy;i++) {
|
|---|
| 567 | memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
|
|---|
| 568 | dst += dibinfo.dsBm.bmWidthBytes;
|
|---|
| 569 | src -= dibinfo.dsBm.bmWidthBytes;
|
|---|
| 570 | }
|
|---|
| 571 | bitmapBits = bmpBitsDblBuffer;
|
|---|
| 572 | }
|
|---|
| 573 | else bitmapBits = bmpBits;
|
|---|
| 574 |
|
|---|
| 575 | //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
|
|---|
| 576 | if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
|
|---|
| 577 | dprintf(("DIBSection::BitBlt; convert rgb 555 to 565 (old y inv. = %d)", oldyinversion));
|
|---|
| 578 |
|
|---|
| 579 | if(bmpBitsDblBuffer == NULL)
|
|---|
| 580 | DebugInt3();
|
|---|
| 581 |
|
|---|
| 582 | // PH 2000/10/01 - Fix for Beyond Compare 1.9d
|
|---|
| 583 | // Note: according to documentation, cmImage can be zero for
|
|---|
| 584 | // RGB- / non-compressed bitmaps.
|
|---|
| 585 | int iLength = pOS2bmp->cbImage;
|
|---|
| 586 | if (iLength == 0)
|
|---|
| 587 | iLength = pOS2bmp->cx * pOS2bmp->cy * (pOS2bmp->cBitCount >> 3);
|
|---|
| 588 |
|
|---|
| 589 | if (iLength > 0)
|
|---|
| 590 | {
|
|---|
| 591 | if(CPUFeatures & CPUID_MMX)
|
|---|
| 592 | RGB555to565MMX((WORD *)bmpBitsDblBuffer, (WORD *)bitmapBits, iLength/sizeof(WORD));
|
|---|
| 593 | else RGB555to565((WORD *)bmpBitsDblBuffer, (WORD *)bitmapBits, iLength/sizeof(WORD));
|
|---|
| 594 | }
|
|---|
| 595 | else
|
|---|
| 596 | {
|
|---|
| 597 | dprintf(("GDI32: DIBSect::BitBlt: WARNING! zero-length bitmap! %08xh", pOS2bmp));
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 | rc = GpiDrawBits(hps, bmpBitsDblBuffer, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
|
|---|
| 602 | }
|
|---|
| 603 | else rc = GpiDrawBits(hps, bitmapBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, os2mode);
|
|---|
| 604 |
|
|---|
| 605 | /*
|
|---|
| 606 | if(hwndDest != 0)
|
|---|
| 607 | {
|
|---|
| 608 | WinReleasePS(hps);
|
|---|
| 609 | }
|
|---|
| 610 | */
|
|---|
| 611 | if(rc == GPI_OK) {
|
|---|
| 612 | DIBSection *destdib = DIBSection::findHDC(hdcDest);
|
|---|
| 613 | if(destdib) {
|
|---|
| 614 | destdib->sync(hps, nYdest, nDestHeight);
|
|---|
| 615 | }
|
|---|
| 616 | #ifdef INVERT
|
|---|
| 617 | //restore old y inversion height
|
|---|
| 618 | if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
|
|---|
| 619 | #endif
|
|---|
| 620 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 621 |
|
|---|
| 622 | return(TRUE);
|
|---|
| 623 | }
|
|---|
| 624 | #ifdef INVERT
|
|---|
| 625 | if(fRestoryYInversion) GpiEnableYInversion(hps, oldyinversion);
|
|---|
| 626 | #endif
|
|---|
| 627 |
|
|---|
| 628 | 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));
|
|---|
| 629 | dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndDest)) & 0xFFFF));
|
|---|
| 630 | return(FALSE);
|
|---|
| 631 | }
|
|---|
| 632 | //******************************************************************************
|
|---|
| 633 | int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
|
|---|
| 634 | void *lpvBits, BITMAPINFO_W * lpbi, UINT uUsage);
|
|---|
| 635 |
|
|---|
| 636 | //******************************************************************************
|
|---|
| 637 | void DIBSection::sync(HDC hdc, DWORD nYdest, DWORD nDestHeight)
|
|---|
| 638 | {
|
|---|
| 639 | APIRET rc;
|
|---|
| 640 | char *destBuf;
|
|---|
| 641 |
|
|---|
| 642 | dprintf(("Sync destination dibsection %x (%x)", handle, hdc));
|
|---|
| 643 |
|
|---|
| 644 | #if 0
|
|---|
| 645 | BITMAPINFO_W *tmphdr = (BITMAPINFO_W *)malloc(os2bmphdrsize + sizeof(BITMAPINFO_W));
|
|---|
| 646 | tmphdr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER_W);
|
|---|
| 647 | GetDIBits(hdc, handle, nYdest, nDestHeight, NULL, tmphdr, 0);
|
|---|
| 648 | destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
|
|---|
| 649 | rc = GetDIBits(hdc, handle, nYdest, nDestHeight, destBuf, tmphdr, 0);
|
|---|
| 650 | #ifdef DEBUG_PALETTE
|
|---|
| 651 | if(rc && tmphdr->bmiHeader.biBitCount <= 8) {
|
|---|
| 652 | for(int i=0;i<(1<<tmphdr->bmiHeader.biBitCount);i++)
|
|---|
| 653 | {
|
|---|
| 654 | dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&tmphdr->bmiColors[i])) ));
|
|---|
| 655 | }
|
|---|
| 656 | }
|
|---|
| 657 | #endif
|
|---|
| 658 |
|
|---|
| 659 | #else
|
|---|
| 660 | BITMAPINFO2 *tmphdr = (BITMAPINFO2 *)malloc(os2bmphdrsize);
|
|---|
| 661 | memcpy(tmphdr, pOS2bmp, os2bmphdrsize);
|
|---|
| 662 |
|
|---|
| 663 | if(fFlip & FLIP_VERT) {
|
|---|
| 664 | destBuf = bmpBitsDblBuffer + nYdest*dibinfo.dsBm.bmWidthBytes;
|
|---|
| 665 |
|
|---|
| 666 | rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
|
|---|
| 667 | tmphdr);
|
|---|
| 668 | //manually reverse bitmap data
|
|---|
| 669 | char *src = destBuf;
|
|---|
| 670 | char *dst = GetDIBObject() + (nYdest+nDestHeight-1)*dibinfo.dsBm.bmWidthBytes;
|
|---|
| 671 | for(int i=0;i<nDestHeight;i++) {
|
|---|
| 672 | memcpy(dst, src, dibinfo.dsBm.bmWidthBytes);
|
|---|
| 673 | dst -= dibinfo.dsBm.bmWidthBytes;
|
|---|
| 674 | src += dibinfo.dsBm.bmWidthBytes;
|
|---|
| 675 | }
|
|---|
| 676 | }
|
|---|
| 677 | else {
|
|---|
| 678 | destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
|
|---|
| 679 | rc = GpiQueryBitmapBits(hdc, nYdest, nDestHeight, destBuf,
|
|---|
| 680 | tmphdr);
|
|---|
| 681 | #ifdef DEBUG_PALETTE
|
|---|
| 682 | if(rc != GPI_ALTERROR && tmphdr->cBitCount <= 8) {
|
|---|
| 683 | for(int i=0;i<(1<<tmphdr->cBitCount);i++)
|
|---|
| 684 | {
|
|---|
| 685 | dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&tmphdr->argbColor[i])) ));
|
|---|
| 686 | }
|
|---|
| 687 | }
|
|---|
| 688 | #endif
|
|---|
| 689 | }
|
|---|
| 690 | #endif
|
|---|
| 691 | #if 0
|
|---|
| 692 | if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
|
|---|
| 693 | dprintf(("DIBSection::sync: convert RGB 565 to RGB 555"));
|
|---|
| 694 |
|
|---|
| 695 | destBuf = GetDIBObject() + nYdest*dibinfo.dsBm.bmWidthBytes;
|
|---|
| 696 |
|
|---|
| 697 | if(CPUFeatures & CPUID_MMX) {
|
|---|
| 698 | RGB565to555MMX((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
|
|---|
| 699 | }
|
|---|
| 700 | else RGB565to555((WORD *)destBuf, (WORD *)destBuf, (nDestHeight*dibinfo.dsBm.bmWidthBytes)/sizeof(WORD));
|
|---|
| 701 | }
|
|---|
| 702 | #endif
|
|---|
| 703 | free(tmphdr);
|
|---|
| 704 | if(rc != nDestHeight) {
|
|---|
| 705 | DebugInt3();
|
|---|
| 706 | }
|
|---|
| 707 | }
|
|---|
| 708 | //******************************************************************************
|
|---|
| 709 | //manual sync if no stretching and bpp is the same
|
|---|
| 710 | //WARNING: this also assumes the colortables are the same
|
|---|
| 711 | //******************************************************************************
|
|---|
| 712 | void DIBSection::sync(DWORD xDst, DWORD yDst, DWORD widthDst, DWORD heightDst, PVOID bits)
|
|---|
| 713 | {
|
|---|
| 714 | char *srcbuf, *destbuf;
|
|---|
| 715 | int linesize;
|
|---|
| 716 |
|
|---|
| 717 | srcbuf = (char *)bits + dibinfo.dsBm.bmWidthBytes*yDst +
|
|---|
| 718 | (xDst*dibinfo.dsBm.bmWidthBytes)/pOS2bmp->cx;
|
|---|
| 719 | destbuf = (char *)GetDIBObject() + dibinfo.dsBm.bmWidthBytes*yDst +
|
|---|
| 720 | (xDst*dibinfo.dsBm.bmWidthBytes)/pOS2bmp->cx;
|
|---|
| 721 | linesize = (widthDst*dibinfo.dsBm.bmWidthBytes)/pOS2bmp->cx;
|
|---|
| 722 | for(int i=0;i<heightDst;i++) {
|
|---|
| 723 | memcpy(destbuf, srcbuf, linesize);
|
|---|
| 724 | destbuf += dibinfo.dsBm.bmWidthBytes;
|
|---|
| 725 | srcbuf += linesize;
|
|---|
| 726 | }
|
|---|
| 727 | }
|
|---|
| 728 | //******************************************************************************
|
|---|
| 729 | //******************************************************************************
|
|---|
| 730 | void DIBSection::SelectDIBObject(HDC hdc)
|
|---|
| 731 | {
|
|---|
| 732 | this->hdc = hdc;
|
|---|
| 733 | hwndParent = WindowFromDC(hdc);
|
|---|
| 734 | dprintf(("SelectDIBObject %x into %x hwndParent = %x", handle, hdc, hwndParent));
|
|---|
| 735 | }
|
|---|
| 736 | //******************************************************************************
|
|---|
| 737 | //******************************************************************************
|
|---|
| 738 | DIBSection *DIBSection::find(DWORD handle)
|
|---|
| 739 | {
|
|---|
| 740 | DIBSection *dsect = section;
|
|---|
| 741 |
|
|---|
| 742 | dibMutex.enter();
|
|---|
| 743 | while(dsect)
|
|---|
| 744 | {
|
|---|
| 745 | if(dsect->handle == handle)
|
|---|
| 746 | {
|
|---|
| 747 | dibMutex.leave();
|
|---|
| 748 | return(dsect);
|
|---|
| 749 | }
|
|---|
| 750 | dsect = dsect->next;
|
|---|
| 751 | }
|
|---|
| 752 | dibMutex.leave();
|
|---|
| 753 | return(NULL);
|
|---|
| 754 | }
|
|---|
| 755 | //******************************************************************************
|
|---|
| 756 | //A bitmap can only be selected into one DC, so this works.
|
|---|
| 757 | //******************************************************************************
|
|---|
| 758 | DIBSection *DIBSection::findHDC(HDC hdc)
|
|---|
| 759 | {
|
|---|
| 760 | DIBSection *dsect = section;
|
|---|
| 761 |
|
|---|
| 762 | while(dsect)
|
|---|
| 763 | {
|
|---|
| 764 | if(dsect->hdc == hdc)
|
|---|
| 765 | {
|
|---|
| 766 | return(dsect);
|
|---|
| 767 | }
|
|---|
| 768 | dsect = dsect->next;
|
|---|
| 769 | }
|
|---|
| 770 | return(NULL);
|
|---|
| 771 | }
|
|---|
| 772 | //******************************************************************************
|
|---|
| 773 | //******************************************************************************
|
|---|
| 774 | void DIBSection::deleteSection(DWORD handle)
|
|---|
| 775 | {
|
|---|
| 776 | DIBSection *dsect = find(handle);
|
|---|
| 777 |
|
|---|
| 778 | if(dsect)
|
|---|
| 779 | delete dsect;
|
|---|
| 780 | }
|
|---|
| 781 | //******************************************************************************
|
|---|
| 782 | //******************************************************************************
|
|---|
| 783 | int DIBSection::GetDIBSection(int iSize, void *lpBuffer)
|
|---|
| 784 | {
|
|---|
| 785 | DIBSECTION *pDIBSection = (DIBSECTION *)lpBuffer;
|
|---|
| 786 | LPBITMAP_W dsBm = (LPBITMAP_W)lpBuffer;
|
|---|
| 787 |
|
|---|
| 788 | dprintf2(("GetDIBSection %x %d %x", handle, iSize, lpBuffer));
|
|---|
| 789 | if(iSize == sizeof(DIBSECTION))
|
|---|
| 790 | {
|
|---|
| 791 | memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
|
|---|
| 792 | return sizeof(DIBSECTION);
|
|---|
| 793 | }
|
|---|
| 794 | else
|
|---|
| 795 | if(iSize == sizeof(BITMAP_W))
|
|---|
| 796 | {
|
|---|
| 797 | memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
|
|---|
| 798 | return sizeof(BITMAP_W);
|
|---|
| 799 | }
|
|---|
| 800 | return 0;
|
|---|
| 801 |
|
|---|
| 802 | }
|
|---|
| 803 | //******************************************************************************
|
|---|
| 804 | //******************************************************************************
|
|---|
| 805 | int DIBSection::GetBitCount()
|
|---|
| 806 | {
|
|---|
| 807 | if(pOS2bmp == NULL)
|
|---|
| 808 | return 0;
|
|---|
| 809 | else
|
|---|
| 810 | return pOS2bmp->cBitCount;
|
|---|
| 811 | }
|
|---|
| 812 | //******************************************************************************
|
|---|
| 813 | //******************************************************************************
|
|---|
| 814 | int DIBSection::GetHeight()
|
|---|
| 815 | {
|
|---|
| 816 | if(pOS2bmp == NULL)
|
|---|
| 817 | return 0;
|
|---|
| 818 | else
|
|---|
| 819 | return pOS2bmp->cy;
|
|---|
| 820 | }
|
|---|
| 821 | //******************************************************************************
|
|---|
| 822 | //******************************************************************************
|
|---|
| 823 | int DIBSection::GetWidth()
|
|---|
| 824 | {
|
|---|
| 825 | if(pOS2bmp == NULL)
|
|---|
| 826 | return 0;
|
|---|
| 827 | else
|
|---|
| 828 | return pOS2bmp->cx;
|
|---|
| 829 | }
|
|---|
| 830 | //******************************************************************************
|
|---|
| 831 | //******************************************************************************
|
|---|
| 832 | DIBSection *DIBSection::section = NULL;
|
|---|