Ticket #5717: toon_magnify_clipping.txt

File toon_magnify_clipping.txt, 1.7 KB (added by fuzzie, 13 years ago)

hastily-written patch

Line 
1diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
2index 44c747c..30c4239 100644
3--- a/engines/toon/toon.cpp
4+++ b/engines/toon/toon.cpp
5@@ -464,24 +464,42 @@ void ToonEngine::doMagnifierEffect() {
6 11, 11, 11, 11, 12
7 };
8
9+ // clip the range so that it doesn't go outside the screen
10+ int32 minY = -12, maxY = 12, minX = -12, maxX = 12;
11+ if (minY + posY < 0)
12+ minY = -posY;
13+ if (maxY + posY >= surface.h)
14+ maxY = surface.h - posY - 1;
15+ if (minX + posX < 0)
16+ minX = -posX;
17+ if (maxX + posX >= surface.w)
18+ maxX = surface.w - posX - 1;
19+
20 byte tempBuffer[25 * 25];
21- for (int32 y = -12; y <= 12; y++) {
22- for (int32 x = -12; x <= 12; x++) {
23+ for (int32 y = minY; y <= maxY; y++) {
24+ for (int32 x = minX; x <= maxX; x++) {
25 int32 destPitch = surface.pitch;
26 uint8 *curRow = (uint8 *)surface.pixels + (posY + y) * destPitch + (posX + x);
27 tempBuffer[(y + 12) * 25 + x + 12] = *curRow;
28 }
29 }
30
31- for (int32 y = -12; y <= 12; y++) {
32- for (int32 x = -12; x <= 12; x++) {
33+ for (int32 y = minY; y <= maxY; y++) {
34+ for (int32 x = minX; x <= maxX; x++) {
35 int32 dist = y * y + x * x;
36 if (dist > 144)
37 continue;
38 int32 destPitch = surface.pitch;
39 uint8 *curRow = (uint8 *)surface.pixels + (posY + y) * destPitch + (posX + x);
40+
41+ // force the magnification source to only use pixels which are present
42 int32 lerp = (512 + intSqrt[dist] * 256 / 12);
43- *curRow = tempBuffer[(y * lerp / 1024 + 12) * 25 + x * lerp / 1024 + 12];
44+ int32 srcX = (x * lerp / 1024);
45+ srcX = MAX(MIN(srcX, maxX), minX);
46+ int32 srcY = (y * lerp / 1024);
47+ srcY = MAX(MIN(srcY, maxY), minY);
48+
49+ *curRow = tempBuffer[(srcY + 12) * 25 + srcX + 12];
50 }
51 }
52 }