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