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