| 505 | // composing the source one. This is done to produce an antialiasing effect. |
| 506 | |
| 507 | flag FBmpShrinkToWin(HDC hdc, HBITMAP hbmp, HDC hdcWin) |
| 508 | { |
| 509 | Bitmap *b = &wi.bmpSmooth, *b2 = &wi.bmpWin; |
| 510 | int x, y, cR, cG, cB, nR, nG, nB, x1, y1, x2, y2, sq, sq2; |
| 511 | flag fRet; |
| 512 | byte *pb, *pb2; |
| 513 | |
| 514 | if (us.fWriteOld) { |
| 515 | // Windows can quickly do the shrinking and blending, but not as well. |
| 516 | SetStretchBltMode(hdcWin, HALFTONE); |
| 517 | SetBrushOrgEx(hdcWin, 0, 0, NULL); |
| 518 | StretchBlt(hdcWin, 0, 0, wi.xClient, wi.yClient, |
| 519 | hdc, 0, 0, wi.xClient*wi.nScaleWin, wi.yClient*wi.nScaleWin, SRCCOPY); |
| 520 | return fTrue; |
| 521 | } |
| 522 | |
| 523 | // First copy to or allocate internal bitmap structures to make use of. |
| 524 | wi.xClient *= wi.nScaleWin; wi.yClient *= wi.nScaleWin; |
| 525 | fRet = FBmpCopyFromWin(b, hdc, wi.hbmp); |
| 526 | wi.xClient /= wi.nScaleWin; wi.yClient /= wi.nScaleWin; |
| 527 | if (!fRet) |
| 528 | return fFalse; |
| 529 | |
| 530 | if (!FAllocateBmp(b2, wi.xClient, wi.yClient)) |
| 531 | return fFalse; |
| 532 | sq = Sq(wi.nScaleWin); sq2 = sq >> 1; |
| 533 | |
| 534 | // Loop over each pixel in the destination bitmap. |
| 535 | for (y = 0; y < wi.yClient; y++) { |
| 536 | pb2 = _PbXY(b2, 0, y); |
| 537 | for (x = 0; x < wi.xClient; x++) { |
| 538 | // Loop over the current NxN square of pixels in the source bitmap. |
| 539 | cR = cG = cB = 0; |
| 540 | for (y1 = y * wi.nScaleWin, y2 = y1 + wi.nScaleWin; y1 < y2; y1++) { |
| 541 | pb = _PbXY(b, x * wi.nScaleWin, y1); |
| 542 | for (x1 = x * wi.nScaleWin, x2 = x1 + wi.nScaleWin; x1 < x2; x1++) { |
| 543 | _GetRGB(pb, &nR, &nG, &nB); |
| 544 | cR += nR; cG += nG; cB += nB; |
| 545 | pb += cbPixelK; |
| 546 | } |
| 547 | } |
| 548 | _SetRGB(pb2, (cR + sq2) / sq, (cG + sq2) / sq, (cB + sq2) / sq); |
| 549 | pb2 += cbPixelK; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | BmpCopyToWin(b2, hdcWin, 0, 0); |
| 554 | return fTrue; |
| 555 | } |
| 556 | #endif |
| 557 | #endif // WINANY |
| 558 |
no test coverage detected