| 1 | /* $Id: dibsect.cpp,v 1.25 2000-04-02 12:24:40 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * GDI32 DIB sections
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | * Copyright 1998 Patrick Haller
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | * NOTE:
|
|---|
| 12 | * This is not a complete solution for CreateDIBSection, but enough for Quake 2!
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | #define INCL_GPI
|
|---|
| 16 | #define INCL_WIN
|
|---|
| 17 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <win32type.h>
|
|---|
| 21 | #include <misc.h>
|
|---|
| 22 | #define OS2_ONLY
|
|---|
| 23 | #include "dibsect.h"
|
|---|
| 24 | #include <vmutex.h>
|
|---|
| 25 | #include <win32api.h>
|
|---|
| 26 | #include <winconst.h>
|
|---|
| 27 | #include <win32wnd.h>
|
|---|
| 28 | #include <cpuhlp.h>
|
|---|
| 29 | #include "oslibgpi.h"
|
|---|
| 30 | #include "rgbcvt.h"
|
|---|
| 31 |
|
|---|
| 32 | #define DBG_LOCALLOG DBG_dibsect
|
|---|
| 33 | #include "dbglocal.h"
|
|---|
| 34 |
|
|---|
| 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), bmpBitsRGB565(NULL)
|
|---|
| 41 | {
|
|---|
| 42 | bmpsize = pbmi->biWidth;
|
|---|
| 43 | /* @@@PH 98/06/07 -- high-color bitmaps don't have palette */
|
|---|
| 44 |
|
|---|
| 45 | this->fFlip = fFlip;
|
|---|
| 46 | os2bmphdrsize = sizeof(BITMAPINFO2);
|
|---|
| 47 |
|
|---|
| 48 | switch(pbmi->biBitCount)
|
|---|
| 49 | {
|
|---|
| 50 | case 1:
|
|---|
| 51 | bmpsize = ((bmpsize + 31) & ~31) / 8;
|
|---|
| 52 | os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
|
|---|
| 53 | break;
|
|---|
| 54 | case 4:
|
|---|
| 55 | bmpsize = ((bmpsize + 7) & ~7) / 2;
|
|---|
| 56 | os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
|
|---|
| 57 | break;
|
|---|
| 58 | case 8:
|
|---|
| 59 | os2bmphdrsize += ((1 << pbmi->biBitCount)-1)*sizeof(RGB2);
|
|---|
| 60 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 61 | break;
|
|---|
| 62 | case 16:
|
|---|
| 63 | bmpsize *= 2;
|
|---|
| 64 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 65 | break;
|
|---|
| 66 | case 24:
|
|---|
| 67 | bmpsize *= 3;
|
|---|
| 68 | bmpsize = (bmpsize + 3) & ~3;
|
|---|
| 69 | break;
|
|---|
| 70 | case 32:
|
|---|
| 71 | bmpsize *= 4;
|
|---|
| 72 | break;
|
|---|
| 73 | default:
|
|---|
| 74 | dprintf(("Unsupported nr of bits %d", pbmi->biBitCount));
|
|---|
| 75 | DebugInt3();
|
|---|
| 76 | break;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | this->hSection = hSection;
|
|---|
| 80 | if(hSection) {
|
|---|
| 81 | bmpBits = (char *)MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS_W, 0, dwOffset, bmpsize*pbmi->biHeight);
|
|---|
| 82 | if(!bmpBits) {
|
|---|
| 83 | dprintf(("Dibsection: mapViewOfFile %x failed!", hSection));
|
|---|
| 84 | DebugInt3();
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | if(!bmpBits) {
|
|---|
| 88 | DosAllocMem((PPVOID)&bmpBits, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
|
|---|
| 89 | }
|
|---|
| 90 | memset(bmpBits, 0, bmpsize*pbmi->biHeight);
|
|---|
| 91 |
|
|---|
| 92 | pOS2bmp = (BITMAPINFO2 *)malloc(os2bmphdrsize);
|
|---|
| 93 |
|
|---|
| 94 | memset(pOS2bmp, /* set header + palette entries to zero */
|
|---|
| 95 | 0,
|
|---|
| 96 | os2bmphdrsize);
|
|---|
| 97 |
|
|---|
| 98 | pOS2bmp->cbFix = sizeof(BITMAPINFO2) - sizeof(RGB2);
|
|---|
| 99 | pOS2bmp->cx = pbmi->biWidth;
|
|---|
| 100 | pOS2bmp->cy = pbmi->biHeight;
|
|---|
| 101 | pOS2bmp->cPlanes = pbmi->biPlanes;
|
|---|
| 102 | pOS2bmp->cBitCount = pbmi->biBitCount;
|
|---|
| 103 | pOS2bmp->ulCompression = pbmi->biCompression;
|
|---|
| 104 | //SvL: Ignore BI_BITFIELDS type (GpiDrawBits fails otherwise)
|
|---|
| 105 | if(pOS2bmp->ulCompression == BI_BITFIELDS) {
|
|---|
| 106 | pOS2bmp->ulCompression = 0;
|
|---|
| 107 | }
|
|---|
| 108 | pOS2bmp->cbImage = pbmi->biSizeImage;
|
|---|
| 109 | dprintf(("handle %x", handle));
|
|---|
| 110 | dprintf(("pOS2bmp->cx %d\n", pOS2bmp->cx));
|
|---|
| 111 | dprintf(("pOS2bmp->cy %d\n", pOS2bmp->cy));
|
|---|
| 112 | dprintf(("pOS2bmp->cPlanes %d\n", pOS2bmp->cPlanes));
|
|---|
| 113 | dprintf(("pOS2bmp->cBitCount %d\n", pOS2bmp->cBitCount));
|
|---|
| 114 | dprintf(("pOS2bmp->ulCompression %d\n", pOS2bmp->ulCompression));
|
|---|
| 115 | dprintf(("pOS2bmp->cbImage %d\n", pOS2bmp->cbImage));
|
|---|
| 116 | dprintf(("Bits at %x, size %d",bmpBits, bmpsize*pbmi->biHeight));
|
|---|
| 117 |
|
|---|
| 118 | // clear DIBSECTION structure
|
|---|
| 119 | memset(&dibinfo, 0, sizeof(dibinfo));
|
|---|
| 120 |
|
|---|
| 121 | // copy BITMAPINFOHEADER data into DIBSECTION structure
|
|---|
| 122 | memcpy(&dibinfo.dsBmih, pbmi, sizeof(*pbmi));
|
|---|
| 123 | dibinfo.dsBm.bmType = 0;
|
|---|
| 124 | dibinfo.dsBm.bmWidth = pbmi->biWidth;
|
|---|
| 125 | dibinfo.dsBm.bmHeight = pbmi->biHeight;
|
|---|
| 126 | dibinfo.dsBm.bmWidthBytes= bmpsize;
|
|---|
| 127 | dibinfo.dsBm.bmPlanes = pbmi->biPlanes;
|
|---|
| 128 | dibinfo.dsBm.bmBitsPixel = pbmi->biBitCount;
|
|---|
| 129 | dibinfo.dsBm.bmBits = bmpBits;
|
|---|
| 130 |
|
|---|
| 131 | dibinfo.dshSection = handle;
|
|---|
| 132 | dibinfo.dsOffset = 0; // TODO: put the correct value here (if createdibsection with file handle)
|
|---|
| 133 |
|
|---|
| 134 | if(iUsage == DIB_PAL_COLORS || pbmi->biBitCount <= 8)
|
|---|
| 135 | {
|
|---|
| 136 | dibinfo.dsBitfields[0] = dibinfo.dsBitfields[1] = dibinfo.dsBitfields[2] = 0;
|
|---|
| 137 | }
|
|---|
| 138 | else {
|
|---|
| 139 | switch(pbmi->biBitCount)
|
|---|
| 140 | {
|
|---|
| 141 | case 16:
|
|---|
| 142 | dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS) ? *(DWORD *)pColors : 0x7c00;
|
|---|
| 143 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
|
|---|
| 144 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0x001f;
|
|---|
| 145 |
|
|---|
| 146 | //double buffer for rgb 555 dib sections (for conversion)
|
|---|
| 147 | if(dibinfo.dsBitfields[1] == 0x03e0) {
|
|---|
| 148 | DosAllocMem((PPVOID)&bmpBitsRGB565, bmpsize*pbmi->biHeight, PAG_READ|PAG_WRITE|PAG_COMMIT);
|
|---|
| 149 | }
|
|---|
| 150 | break;
|
|---|
| 151 |
|
|---|
| 152 | case 24:
|
|---|
| 153 | dibinfo.dsBitfields[0] = 0xff;
|
|---|
| 154 | dibinfo.dsBitfields[1] = 0xff00;
|
|---|
| 155 | dibinfo.dsBitfields[2] = 0xff0000;
|
|---|
| 156 | break;
|
|---|
| 157 |
|
|---|
| 158 | case 32:
|
|---|
| 159 | dibinfo.dsBitfields[0] = (pbmi->biCompression == BI_BITFIELDS) ? *(DWORD *)pColors : 0xff;
|
|---|
| 160 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0xff00;
|
|---|
| 161 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 2) : 0xff0000;
|
|---|
| 162 | if(dibinfo.dsBitfields[0] != 0xff && dibinfo.dsBitfields[1] != 0xff00 && dibinfo.dsBitfields[2] != 0xff0000) {
|
|---|
| 163 | dprintf(("DIBSection: unsupported bitfields for 32 bits bitmap!!"));
|
|---|
| 164 | }
|
|---|
| 165 | break;
|
|---|
| 166 | }
|
|---|
| 167 | dprintf(("BI_BITFIELDS %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
|
|---|
| 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 | //******************************************************************************
|
|---|
| 197 | DIBSection::~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(bmpBitsRGB565)
|
|---|
| 209 | DosFreeMem(bmpBitsRGB565);
|
|---|
| 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 | //******************************************************************************
|
|---|
| 233 | int 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) ? *(DWORD *)pColors : 0x7c00;
|
|---|
| 320 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0x03e0;
|
|---|
| 321 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((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) ? *(DWORD *)pColors : 0xff;
|
|---|
| 332 | dibinfo.dsBitfields[1] = (pbmi->biCompression == BI_BITFIELDS) ? *((DWORD *)pColors + 1) : 0xff00;
|
|---|
| 333 | dibinfo.dsBitfields[2] = (pbmi->biCompression == BI_BITFIELDS) ? *((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 %x %x %x", dibinfo.dsBitfields[0], dibinfo.dsBitfields[1], dibinfo.dsBitfields[2]));
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | dprintf(("DIBSection::SetDIBits (%d,%d), %d %d", pbmi->biWidth, pbmi->biHeight, pbmi->biBitCount, pbmi->biCompression));
|
|---|
| 343 | if(palsize)
|
|---|
| 344 | memcpy(pOS2bmp->argbColor, (char *)pbmi + 1 , palsize);
|
|---|
| 345 |
|
|---|
| 346 | if(bits)
|
|---|
| 347 | {
|
|---|
| 348 | int size = bmpsize*lines;
|
|---|
| 349 | memcpy(bmpBits+bmpsize*startscan, bits, size);
|
|---|
| 350 | }
|
|---|
| 351 | return(lines);
|
|---|
| 352 | }
|
|---|
| 353 | //******************************************************************************
|
|---|
| 354 | //******************************************************************************
|
|---|
| 355 | int DIBSection::SetDIBColorTable(int startIdx, int cEntries, RGBQUAD *rgb)
|
|---|
| 356 | {
|
|---|
| 357 | int i;
|
|---|
| 358 |
|
|---|
| 359 | if(startIdx + cEntries > (1 << pOS2bmp->cBitCount))
|
|---|
| 360 | {
|
|---|
| 361 | dprintf(("DIBSection::SetDIBColorTable, invalid nr of entries %d %d\n", startIdx, cEntries));
|
|---|
| 362 | return(0);
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | memcpy(&pOS2bmp->argbColor[startIdx], rgb, cEntries*sizeof(RGB2));
|
|---|
| 366 |
|
|---|
| 367 | for(i=startIdx;i<cEntries;i++)
|
|---|
| 368 | {
|
|---|
| 369 | pOS2bmp->argbColor[i].fcOptions = 0;
|
|---|
| 370 | dprintf2(("Index %d : 0x%08X\n",i, *((ULONG*)(&pOS2bmp->argbColor[i])) ));
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | return(cEntries);
|
|---|
| 374 | }
|
|---|
| 375 | //******************************************************************************
|
|---|
| 376 | //******************************************************************************
|
|---|
| 377 | BOOL DIBSection::BitBlt(HDC hdcDest, int nXdest, int nYdest, int nDestWidth,
|
|---|
| 378 | int nDestHeight, int nXsrc, int nYsrc,
|
|---|
| 379 | int nSrcWidth, int nSrcHeight, DWORD Rop)
|
|---|
| 380 | {
|
|---|
| 381 | HPS hps = (HPS)hdcDest;
|
|---|
| 382 | POINTL point[4];
|
|---|
| 383 | LONG rc;
|
|---|
| 384 | PVOID bitmapBits = NULL;
|
|---|
| 385 | int oldyinversion = 0;
|
|---|
| 386 |
|
|---|
| 387 | HWND hwndDest = WindowFromDC(hdcDest);
|
|---|
| 388 | hwndDest = Win32ToOS2Handle(hwndDest);
|
|---|
| 389 | if(hwndDest != 0)
|
|---|
| 390 | {
|
|---|
| 391 | hps = WinGetPS(hwndDest);
|
|---|
| 392 | }
|
|---|
| 393 | if(hps == 0)
|
|---|
| 394 | {
|
|---|
| 395 | dprintf(("ERROR: DIBSection::BitBlt, hps == 0 hwndDest = %X", hwndDest));
|
|---|
| 396 | return(FALSE);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | dprintf(("DIBSection::BitBlt %x %X (hps %x) %x to(%d,%d)(%d,%d) from (%d,%d)(%d,%d) rop %x flip %x",
|
|---|
| 400 | handle, hdcDest, hps, hwndDest, nXdest, nYdest, nDestWidth, nDestHeight,
|
|---|
| 401 | nXsrc, nYsrc, nSrcWidth, nSrcHeight, Rop, fFlip));
|
|---|
| 402 |
|
|---|
| 403 | //win32 coordinates are of the left top, OS/2 expects left bottom
|
|---|
| 404 | point[0].x = nXdest;
|
|---|
| 405 | point[0].y = pOS2bmp->cy - nYdest - nDestHeight;
|
|---|
| 406 | point[1].x = nXdest + nDestWidth - 1;
|
|---|
| 407 | point[1].y = pOS2bmp->cy - nYdest - 1;
|
|---|
| 408 | point[2].x = nXsrc;
|
|---|
| 409 | point[2].y = pOS2bmp->cy - nYsrc - nSrcHeight;
|
|---|
| 410 | if(nXsrc + nSrcWidth > pOS2bmp->cx)
|
|---|
| 411 | {
|
|---|
| 412 | point[3].x = pOS2bmp->cx;
|
|---|
| 413 | nSrcWidth = pOS2bmp->cx - nXsrc;
|
|---|
| 414 | }
|
|---|
| 415 | else point[3].x = nXsrc + nSrcWidth;
|
|---|
| 416 |
|
|---|
| 417 | if(nYsrc + nSrcHeight > pOS2bmp->cy)
|
|---|
| 418 | {
|
|---|
| 419 | point[3].y = pOS2bmp->cy;
|
|---|
| 420 | nSrcHeight = pOS2bmp->cy - nYsrc;
|
|---|
| 421 | }
|
|---|
| 422 | else point[3].y = pOS2bmp->cy - nYsrc;
|
|---|
| 423 |
|
|---|
| 424 | oldyinversion = GpiQueryYInversion(hps);
|
|---|
| 425 | if(fFlip & FLIP_VERT)
|
|---|
| 426 | {
|
|---|
| 427 | GpiEnableYInversion(hps, nDestHeight-1);
|
|---|
| 428 | }
|
|---|
| 429 | else GpiEnableYInversion(hps, 0);
|
|---|
| 430 |
|
|---|
| 431 | if(fFlip & FLIP_HOR)
|
|---|
| 432 | {
|
|---|
| 433 | ULONG x;
|
|---|
| 434 | x = point[0].x;
|
|---|
| 435 | point[0].x = point[1].x;
|
|---|
| 436 | point[1].x = x;
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | //SvL: Optimize this.. (don't convert entire bitmap if only a part will be blitted to the dc)
|
|---|
| 440 | if(dibinfo.dsBitfields[1] == 0x3E0) {//RGB 555?
|
|---|
| 441 | dprintf(("DIBSection::BitBlt; convert rgb 555 to 565"));
|
|---|
| 442 |
|
|---|
| 443 | if(bmpBitsRGB565 == NULL)
|
|---|
| 444 | DebugInt3();
|
|---|
| 445 |
|
|---|
| 446 | if(CPUFeatures & CPUID_MMX) {
|
|---|
| 447 | RGB555to565MMX((WORD *)bmpBitsRGB565, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
|
|---|
| 448 | }
|
|---|
| 449 | else RGB555to565((WORD *)bmpBitsRGB565, (WORD *)bmpBits, pOS2bmp->cbImage/sizeof(WORD));
|
|---|
| 450 | rc = GpiDrawBits(hps, bmpBitsRGB565, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
|
|---|
| 451 | }
|
|---|
| 452 | else rc = GpiDrawBits(hps, bmpBits, pOS2bmp, 4, &point[0], ROP_SRCCOPY, BBO_OR);
|
|---|
| 453 |
|
|---|
| 454 | if(rc == GPI_OK) {
|
|---|
| 455 | DIBSection *destdib = DIBSection::findHDC(hdcDest);
|
|---|
| 456 | if(destdib) {
|
|---|
| 457 | dprintf(("Sync destination dibsection %x (%x) (%d)", destdib->handle, hdcDest, oldyinversion));
|
|---|
| 458 |
|
|---|
| 459 | //todo: rgb 565 to 555 conversion if bpp == 16
|
|---|
| 460 | BITMAPINFO2 *tmphdr = (BITMAPINFO2 *)malloc(destdib->os2bmphdrsize);
|
|---|
| 461 | memcpy(tmphdr, destdib->pOS2bmp, destdib->os2bmphdrsize);
|
|---|
| 462 | rc = GpiQueryBitmapBits(hps, nYdest, nDestHeight, destdib->GetDIBObject(),
|
|---|
| 463 | tmphdr);
|
|---|
| 464 | free(tmphdr);
|
|---|
| 465 | if(rc != nDestHeight) {
|
|---|
| 466 | DebugInt3();
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 | //restore old y inversion height
|
|---|
| 470 | GpiEnableYInversion(hps, oldyinversion);
|
|---|
| 471 | if(hwndDest != 0)
|
|---|
| 472 | {
|
|---|
| 473 | WinReleasePS(hps);
|
|---|
| 474 | }
|
|---|
| 475 | return(TRUE);
|
|---|
| 476 | }
|
|---|
| 477 | GpiEnableYInversion(hps, oldyinversion);
|
|---|
| 478 | if(hwndDest != 0)
|
|---|
| 479 | {
|
|---|
| 480 | WinReleasePS(hps);
|
|---|
| 481 | }
|
|---|
| 482 | 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));
|
|---|
| 483 | dprintf(("WinGetLastError returned %X\n", WinGetLastError(WinQueryAnchorBlock(hwndDest)) & 0xFFFF));
|
|---|
| 484 | return(FALSE);
|
|---|
| 485 | }
|
|---|
| 486 | //******************************************************************************
|
|---|
| 487 | //******************************************************************************
|
|---|
| 488 | void DIBSection::SelectDIBObject(HDC hdc)
|
|---|
| 489 | {
|
|---|
| 490 | this->hdc = hdc;
|
|---|
| 491 | hwndParent = WinWindowFromDC(hdc);
|
|---|
| 492 | dprintf(("SelectDIBObject %x into %x hwndParent = %x", handle, hdc, hwndParent));
|
|---|
| 493 | }
|
|---|
| 494 | //******************************************************************************
|
|---|
| 495 | //******************************************************************************
|
|---|
| 496 | DIBSection *DIBSection::find(DWORD handle)
|
|---|
| 497 | {
|
|---|
| 498 | DIBSection *dsect = section;
|
|---|
| 499 |
|
|---|
| 500 | dibMutex.enter();
|
|---|
| 501 | while(dsect)
|
|---|
| 502 | {
|
|---|
| 503 | if(dsect->handle == handle)
|
|---|
| 504 | {
|
|---|
| 505 | dibMutex.leave();
|
|---|
| 506 | return(dsect);
|
|---|
| 507 | }
|
|---|
| 508 | dsect = dsect->next;
|
|---|
| 509 | }
|
|---|
| 510 | dibMutex.leave();
|
|---|
| 511 | return(NULL);
|
|---|
| 512 | }
|
|---|
| 513 | //******************************************************************************
|
|---|
| 514 | //A bitmap can only be selected into one DC, so this works.
|
|---|
| 515 | //******************************************************************************
|
|---|
| 516 | DIBSection *DIBSection::findHDC(HDC hdc)
|
|---|
| 517 | {
|
|---|
| 518 | DIBSection *dsect = section;
|
|---|
| 519 |
|
|---|
| 520 | while(dsect)
|
|---|
| 521 | {
|
|---|
| 522 | if(dsect->hdc == hdc)
|
|---|
| 523 | {
|
|---|
| 524 | return(dsect);
|
|---|
| 525 | }
|
|---|
| 526 | dsect = dsect->next;
|
|---|
| 527 | }
|
|---|
| 528 | return(NULL);
|
|---|
| 529 | }
|
|---|
| 530 | //******************************************************************************
|
|---|
| 531 | //******************************************************************************
|
|---|
| 532 | void DIBSection::deleteSection(DWORD handle)
|
|---|
| 533 | {
|
|---|
| 534 | DIBSection *dsect = find(handle);
|
|---|
| 535 |
|
|---|
| 536 | if(dsect)
|
|---|
| 537 | delete dsect;
|
|---|
| 538 |
|
|---|
| 539 | }
|
|---|
| 540 | //******************************************************************************
|
|---|
| 541 | //******************************************************************************
|
|---|
| 542 | int DIBSection::GetDIBSection(int iSize, void *lpBuffer)
|
|---|
| 543 | {
|
|---|
| 544 | DIBSECTION *pDIBSection = (DIBSECTION *)lpBuffer;
|
|---|
| 545 | LPBITMAP_W dsBm = (LPBITMAP_W)lpBuffer;
|
|---|
| 546 |
|
|---|
| 547 | dprintf2(("GetDIBSection %x %d %x", handle, iSize, lpBuffer));
|
|---|
| 548 | if(iSize == sizeof(DIBSECTION))
|
|---|
| 549 | {
|
|---|
| 550 | memcpy(pDIBSection, &dibinfo, sizeof(dibinfo));
|
|---|
| 551 | return sizeof(DIBSECTION);
|
|---|
| 552 | }
|
|---|
| 553 | else
|
|---|
| 554 | if(iSize == sizeof(BITMAP_W))
|
|---|
| 555 | {
|
|---|
| 556 | memcpy(dsBm, &dibinfo.dsBm, sizeof(dibinfo.dsBm));
|
|---|
| 557 | return sizeof(BITMAP_W);
|
|---|
| 558 | }
|
|---|
| 559 | return 0;
|
|---|
| 560 |
|
|---|
| 561 | }
|
|---|
| 562 | //******************************************************************************
|
|---|
| 563 | //******************************************************************************
|
|---|
| 564 | char DIBSection::GetBitCount()
|
|---|
| 565 | {
|
|---|
| 566 | if(pOS2bmp == NULL)
|
|---|
| 567 | return 0;
|
|---|
| 568 | else
|
|---|
| 569 | return pOS2bmp->cBitCount;
|
|---|
| 570 | }
|
|---|
| 571 | //******************************************************************************
|
|---|
| 572 | //******************************************************************************
|
|---|
| 573 | DIBSection *DIBSection::section = NULL;
|
|---|