summaryrefslogtreecommitdiff
path: root/src/blitter
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-06-11 12:51:27 +0000
committertruelight <truelight@openttd.org>2007-06-11 12:51:27 +0000
commit9d570fa018a7c449853c113c9d2190e5246a8f09 (patch)
tree9c3c30c4652118fa38812c429adf42bbceccf1d8 /src/blitter
parentf98b175cf5d0e454ea11fbd72fa1d4c2c2a579a2 (diff)
downloadopenttd-9d570fa018a7c449853c113c9d2190e5246a8f09.tar.xz
(svn r10095) -Fix: avoid reading outside the buffer because of scaling problems
Diffstat (limited to 'src/blitter')
-rw-r--r--src/blitter/8bpp_optimized.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp
index 00c427441..62397a045 100644
--- a/src/blitter/8bpp_optimized.cpp
+++ b/src/blitter/8bpp_optimized.cpp
@@ -134,6 +134,7 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite)
uint pixels = 0;
uint last_color = 0;
uint count_index = 0;
+ uint rx = 0;
src = &sprite->data[ScaleByZoom(y, (ZoomLevel)i) * sprite->width];
for (int x = 0; x < UnScaleByZoom(sprite->width, (ZoomLevel)i); x++) {
@@ -144,6 +145,9 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite)
for (int j = 0; j < ScaleByZoom(1, (ZoomLevel)i); j++) {
if (src->m != 0) { color = src->m; count++; }
src++;
+ rx++;
+ /* Because of the scaling it might happen we read outside the buffer. Avoid that. */
+ if (rx == sprite->width) break;
}
/* If more than 12.5% of the pixels are non-transparent, make thisone non-transparent too */
if (count < ScaleByZoom(1, (ZoomLevel)i) / 8) color = 0;