| 433 | |
| 434 | |
| 435 | ILboolean ILAPIENTRY ilutSetHBitmap(HBITMAP Bitmap) |
| 436 | { |
| 437 | #ifndef _WIN32_WCE |
| 438 | BITMAPINFO Info[2]; |
| 439 | HWND hWnd; |
| 440 | HDC hDC; |
| 441 | ILubyte *Buffer1 = NULL, *Buffer2 = NULL; |
| 442 | ILuint i, j, PadSize, Bps; |
| 443 | |
| 444 | ilutCurImage = ilGetCurImage(); |
| 445 | if (ilutCurImage == NULL) { |
| 446 | ilSetError(ILUT_ILLEGAL_OPERATION); |
| 447 | return IL_FALSE; |
| 448 | } |
| 449 | |
| 450 | hWnd = GetForegroundWindow(); |
| 451 | hDC = GetDC(hWnd); |
| 452 | |
| 453 | // Query the dimensions |
| 454 | memset(&Info, 0, sizeof(BITMAPINFO)); |
| 455 | Info[0].bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 456 | GetDIBits(hDC, Bitmap, 0, 0, NULL, Info, DIB_RGB_COLORS); |
| 457 | |
| 458 | // @TODO: Implement this shitz0rz! |
| 459 | if (Info[0].bmiHeader.biBitCount < 24) { |
| 460 | ReleaseDC(hWnd, hDC); //added 20040527 |
| 461 | return IL_FALSE; |
| 462 | } |
| 463 | |
| 464 | Buffer1 = (ILubyte*)ialloc(Info[0].bmiHeader.biSizeImage); |
| 465 | Buffer2 = (ILubyte*)ialloc(Info[0].bmiHeader.biSizeImage); |
| 466 | if (Buffer1 == NULL || Buffer2 == NULL) { |
| 467 | ReleaseDC(hWnd, hDC); //added 20040527 |
| 468 | ifree(Buffer1); |
| 469 | ifree(Buffer2); |
| 470 | return IL_FALSE; |
| 471 | } |
| 472 | |
| 473 | //GetBitmapBits |
| 474 | GetDIBits(hDC, Bitmap, 0, Info[0].bmiHeader.biHeight, Buffer1, Info, DIB_RGB_COLORS); |
| 475 | |
| 476 | Bps = Info[0].bmiHeader.biWidth * (Info[0].bmiHeader.biBitCount >> 3); |
| 477 | PadSize = (4 - (Bps % 4)) % 4; |
| 478 | |
| 479 | // Remove the padding. |
| 480 | for (i = 0, j = 0; i < Info[0].bmiHeader.biSizeImage; i += Bps + PadSize, j += Bps) { |
| 481 | memcpy(Buffer2 + j, Buffer1 + i, Bps); |
| 482 | } |
| 483 | |
| 484 | if (Info[0].bmiHeader.biBitCount == 24) { |
| 485 | ilTexImage(Info[0].bmiHeader.biWidth, Info[0].bmiHeader.biHeight, 1, |
| 486 | (ILubyte)(Info[0].bmiHeader.biBitCount >> 3), IL_BGR, IL_UNSIGNED_BYTE, Buffer2); |
| 487 | } |
| 488 | else if (Info[0].bmiHeader.biBitCount == 32) { |
| 489 | ilTexImage(Info[0].bmiHeader.biWidth, Info[0].bmiHeader.biHeight, 1, |
| 490 | (ILubyte)(Info[0].bmiHeader.biBitCount >> 3), IL_BGRA, IL_UNSIGNED_BYTE, Buffer2); |
| 491 | } |
| 492 | ilutCurImage->Origin = IL_ORIGIN_LOWER_LEFT; |
nothing calls this directly
no test coverage detected