Changeset 7043 for trunk/src/user32/oslibres.cpp
- Timestamp:
- Oct 14, 2001, 10:15:15 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/oslibres.cpp
r6928 r7043 1 /* $Id: oslibres.cpp,v 1.2 1 2001-10-02 17:14:09sandervl Exp $ */1 /* $Id: oslibres.cpp,v 1.22 2001-10-14 20:15:15 sandervl Exp $ */ 2 2 /* 3 3 * Window API wrappers for OS/2 … … 233 233 #endif 234 234 //****************************************************************************** 235 //****************************************************************************** 236 BOOL isMonoBitmap(BITMAP_W *pXorBmp, PBYTE os2rgb) 237 { 238 ULONG pixel, color[2]; 239 char *bmpdata; 240 int i, j, nrcolors = 0, increment; 241 242 increment = pXorBmp->bmBitsPixel/8; 243 244 for(i=0;i<pXorBmp->bmHeight;i++) { 245 bmpdata = (char *)os2rgb; 246 for(j=0;j<pXorBmp->bmWidth;j++) { 247 pixel = 0; 248 memcpy(&pixel, os2rgb, increment); 249 if(nrcolors == 0) { 250 color[0] = pixel; 251 nrcolors = 1; 252 } 253 else 254 if(nrcolors == 1 && color[0] != pixel) { 255 color[1] = pixel; 256 nrcolors = 2; 257 } 258 else { 259 if(color[0] != pixel && color[1] != pixel) 260 { 261 return FALSE; 262 } 263 } 264 os2rgb += increment; 265 } 266 os2rgb = bmpdata + pXorBmp->bmWidthBytes; 267 } 268 return TRUE; 269 } 270 //****************************************************************************** 271 //****************************************************************************** 272 char *colorToMonoBitmap(HBITMAP bmpsrc, BITMAPINFO2 *pBmpDest) 273 { 274 HDC hdcDest = 0; /* device context handle */ 275 HPS hpsDest = 0; 276 SIZEL sizl = { 0, 0 }; /* use same page size as device */ 277 DEVOPENSTRUC dop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; 278 LONG lHits; 279 char *bmpbuffer = 0; 280 BITMAPINFO2 *bmpinfo = NULL; 281 HAB hab; 282 283 hab = GetThreadHAB(); 284 285 /* create memory device context */ 286 hdcDest = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE); 287 288 /* Create the presentation and associate the memory device 289 context. */ 290 hpsDest = GpiCreatePS(hab, hdcDest, &sizl, PU_PELS | 291 GPIT_MICRO | GPIA_ASSOC); 292 if(!hpsDest) goto fail; 293 294 GpiSetBitmap(hpsDest, bmpsrc); 295 296 bmpinfo = (BITMAPINFO2 *)malloc(2*sizeof(BITMAPINFOHEADER2) + sizeof(RGB2)); 297 bmpbuffer = (char *)malloc(pBmpDest->cy*pBmpDest->cx); 298 memset(bmpinfo, 0, sizeof(BITMAPINFOHEADER2) + sizeof(RGB2)); 299 bmpinfo->cbFix = sizeof(BITMAPINFOHEADER2); 300 bmpinfo->cx = pBmpDest->cx; 301 bmpinfo->cy = pBmpDest->cy; 302 bmpinfo->cPlanes = 1; 303 bmpinfo->cBitCount = 1; 304 bmpinfo->ulCompression = BCA_UNCOMP; 305 bmpinfo->ulColorEncoding = BCE_RGB; 306 307 lHits = GpiQueryBitmapBits(hpsDest, 0, pBmpDest->cy, bmpbuffer, bmpinfo); 308 if(lHits == GPI_ERROR) goto fail; 309 310 { 311 dprintf(("colorToMonoBitmap %d %d (%x,%x,%x)(%x,%x,%x)", pBmpDest->cx, pBmpDest->cy, bmpinfo->argbColor[0].bRed, bmpinfo->argbColor[0].bGreen, bmpinfo->argbColor[0].bBlue, bmpinfo->argbColor[1].bRed, bmpinfo->argbColor[1].bGreen, bmpinfo->argbColor[1].bBlue)); 312 for(int i=pBmpDest->cy-1;i>=0;i--) { 313 for(int j=0;j<pBmpDest->cx;j++) { 314 if(j<8) { 315 if((*(bmpbuffer+i*4)) & (1<<(7-j))) { 316 WriteLogNoEOL("X"); 317 } 318 else WriteLogNoEOL("."); 319 } 320 else 321 if(j<16) { 322 if((*(bmpbuffer+1+i*4)) & (1<<(15-j))) { 323 WriteLogNoEOL("X"); 324 } 325 else WriteLogNoEOL("."); 326 } 327 else 328 if(j<24) { 329 if((*(bmpbuffer+2+i*4)) & (1<<(23-j))) { 330 WriteLogNoEOL("X"); 331 } 332 else WriteLogNoEOL("."); 333 } 334 else { 335 if((*(bmpbuffer+3+i*4)) & (1<<(31-j))) { 336 WriteLogNoEOL("X"); 337 } 338 else WriteLogNoEOL("."); 339 } 340 } 341 WriteLogNoEOL("\n"); 342 } 343 } 344 345 GpiSetBitmap(hpsDest, NULL); 346 347 GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */ 348 GpiDestroyPS(hpsDest); /* destroys presentation space */ 349 DevCloseDC(hdcDest); /* closes device context */ 350 free(bmpinfo); 351 352 return bmpbuffer; 353 354 fail: 355 if(bmpinfo) free(bmpinfo); 356 if(bmpbuffer) free(bmpbuffer); 357 358 if(hpsDest) { 359 GpiSetBitmap(hpsDest, NULL); 360 GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */ 361 GpiDestroyPS(hpsDest); /* destroys presentation space */ 362 } 363 if(hdcDest) DevCloseDC(hdcDest); /* closes device context */ 364 return 0; 365 } 366 //****************************************************************************** 367 //****************************************************************************** 235 368 //NOTE: Depends on origin of bitmap data!!! 236 369 // Assumes 1 bpp bitmaps have a top left origin and all others have a bottom left origin … … 242 375 HANDLE hPointer; 243 376 HBITMAP hbmColor = 0, hbmMask = 0; 244 BITMAPINFO2 *pBmpColor , *pBmpMask;377 BITMAPINFO2 *pBmpColor = 0, *pBmpMask = 0; 245 378 int masksize, colorsize, rgbsize, i; 246 379 HPS hps; 247 char *dest, *src ;380 char *dest, *src, *pOS2XorBits = 0; 248 381 249 382 hps = WinGetScreenPS(HWND_DESKTOP); 383 384 if(pXorBits) 385 {//color bitmap present 386 RGBQUAD *rgb; 387 RGB2 *os2rgb; 388 389 if(pXorBmp->bmBitsPixel <= 8) 390 rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2); 391 else rgbsize = 0; 392 393 colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize; 394 pBmpColor = (BITMAPINFO2 *)malloc(colorsize); 395 if(pBmpColor == NULL) { 396 DebugInt3(); 397 return 0; 398 } 399 memset(pBmpColor, 0, colorsize); 400 pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2); 401 pBmpColor->cx = (USHORT)pXorBmp->bmWidth; 402 pBmpColor->cy = (USHORT)pXorBmp->bmHeight; 403 pBmpColor->cPlanes = pXorBmp->bmPlanes; 404 pBmpColor->cBitCount = pXorBmp->bmBitsPixel; 405 pBmpColor->ulCompression = BCA_UNCOMP; 406 pBmpColor->ulColorEncoding = BCE_RGB; 407 408 os2rgb = &pBmpColor->argbColor[0]; 409 rgb = (RGBQUAD *)(pXorBits); 410 411 if(pXorBmp->bmBitsPixel <= 8) { 412 for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) { 413 os2rgb->bRed = rgb->rgbRed; 414 os2rgb->bBlue = rgb->rgbBlue; 415 os2rgb->bGreen = rgb->rgbGreen; 416 os2rgb++; 417 rgb++; 418 } 419 } 420 421 if(pXorBmp->bmBitsPixel == 1) { 422 //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left) 423 src = (char *)rgb; 424 dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes; 425 for(i=0;i<pXorBmp->bmHeight;i++) { 426 memcpy(dest, src, pXorBmp->bmWidthBytes); 427 dest -= pXorBmp->bmWidthBytes; 428 src += pXorBmp->bmWidthBytes; 429 } 430 } 431 else 432 if(pXorBmp->bmBitsPixel == 16) { 433 ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes); 434 } 435 else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes); 436 437 hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT, 438 (PBYTE)os2rgb, pBmpColor); 439 440 if(hbmColor == GPI_ERROR) { 441 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!")); 442 goto fail; 443 } 444 if(pXorBmp->bmBitsPixel >= 8) 445 { 446 if(isMonoBitmap(pXorBmp, (PBYTE)os2rgb) == TRUE) 447 { 448 pOS2XorBits = colorToMonoBitmap(hbmColor, pBmpColor); 449 if(pOS2XorBits) { 450 GpiDeleteBitmap(hbmColor); 451 hbmColor = 0; 452 } 453 } 454 } 455 //testestest 456 } 457 250 458 //SvL: 2*sizeof(RGB2) is enough, but GpiCreateBitmap seems to touch more 251 459 // memory. (Adobe Photoshop 6 running in the debugger) … … 266 474 memset(&pBmpMask->argbColor[0], 0, sizeof(RGB2)); 267 475 memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte 268 //Xor bits are already 0 476 if(pOS2XorBits) { 477 dest = ((char *)&pBmpMask->argbColor[2]); 478 memcpy(dest, pOS2XorBits, pAndBmp->bmWidthBytes*pAndBmp->bmHeight); 479 free(pOS2XorBits); 480 pOS2XorBits = NULL; 481 } 482 // else Xor bits are already 0 483 269 484 //copy And bits (must reverse scanlines because origin is top left instead of bottom left) 270 485 src = pAndBits; … … 280 495 if(hbmMask == GPI_ERROR) { 281 496 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!")); 282 WinReleasePS(hps); 283 free(pBmpMask); 284 return 0; 285 } 286 if(pXorBits) 287 {//color bitmap present 288 RGBQUAD *rgb; 289 RGB2 *os2rgb; 290 291 if(pXorBmp->bmBitsPixel <= 8) 292 rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2); 293 else rgbsize = 0; 294 295 colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize; 296 pBmpColor = (BITMAPINFO2 *)malloc(colorsize); 297 if(pBmpColor == NULL) { 298 DebugInt3(); 299 return 0; 300 } 301 memset(pBmpColor, 0, colorsize); 302 pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2); 303 pBmpColor->cx = (USHORT)pXorBmp->bmWidth; 304 pBmpColor->cy = (USHORT)pXorBmp->bmHeight; 305 pBmpColor->cPlanes = pXorBmp->bmPlanes; 306 pBmpColor->cBitCount = pXorBmp->bmBitsPixel; 307 pBmpColor->ulCompression = BCA_UNCOMP; 308 pBmpColor->ulColorEncoding = BCE_RGB; 309 310 os2rgb = &pBmpColor->argbColor[0]; 311 rgb = (RGBQUAD *)(pXorBits); 312 313 if(pXorBmp->bmBitsPixel <= 8) { 314 for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) { 315 os2rgb->bRed = rgb->rgbRed; 316 os2rgb->bBlue = rgb->rgbBlue; 317 os2rgb->bGreen = rgb->rgbGreen; 318 os2rgb++; 319 rgb++; 320 } 321 } 322 323 if(pXorBmp->bmBitsPixel == 1) { 324 //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left) 325 src = (char *)rgb; 326 dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes; 327 for(i=0;i<pXorBmp->bmHeight;i++) { 328 memcpy(dest, src, pXorBmp->bmWidthBytes); 329 dest -= pXorBmp->bmWidthBytes; 330 src += pXorBmp->bmWidthBytes; 331 } 332 } 333 else 334 if(pXorBmp->bmBitsPixel == 16) { 335 ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes); 336 } 337 else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes); 338 339 hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT, 340 (PBYTE)os2rgb, pBmpColor); 341 342 if(hbmColor == GPI_ERROR) { 343 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!")); 344 GpiDeleteBitmap(hbmMask); 345 WinReleasePS(hps); 346 free(pBmpMask); 347 return 0; 348 } 497 goto fail; 349 498 } 350 499 … … 366 515 free(pBmpColor); 367 516 return hPointer; 517 518 fail: 519 if(hbmMask) GpiDeleteBitmap(hbmMask); 520 if(hbmColor) GpiDeleteBitmap(hbmColor); 521 WinReleasePS(hps); 522 if(pBmpMask) free(pBmpMask); 523 if(pBmpColor) free(pBmpColor); 524 return 0; 368 525 } 369 526 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.