summaryrefslogtreecommitdiff
path: root/src/blitter
diff options
context:
space:
mode:
Diffstat (limited to 'src/blitter')
-rw-r--r--src/blitter/32bpp_optimized.cpp54
-rw-r--r--src/blitter/8bpp_optimized.cpp19
2 files changed, 6 insertions, 67 deletions
diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp
index fbbf7f055..90a310075 100644
--- a/src/blitter/32bpp_optimized.cpp
+++ b/src/blitter/32bpp_optimized.cpp
@@ -207,55 +207,6 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
}
}
-/**
- * Resizes the sprite in a very simple way, takes every n-th pixel and every n-th row
- *
- * @param sprite_src sprite to resize
- * @param zoom resizing scale
- * @return resized sprite
- */
-static const SpriteLoader::Sprite *ResizeSprite(const SpriteLoader::Sprite *sprite_src, ZoomLevel zoom)
-{
- SpriteLoader::Sprite *sprite = MallocT<SpriteLoader::Sprite>(1);
-
- if (zoom == ZOOM_LVL_NORMAL) {
- memcpy(sprite, sprite_src, sizeof(*sprite));
- uint size = sprite_src->height * sprite_src->width;
- sprite->data = MallocT<SpriteLoader::CommonPixel>(size);
- memcpy(sprite->data, sprite_src->data, size * sizeof(SpriteLoader::CommonPixel));
- return sprite;
- }
-
- sprite->height = UnScaleByZoom(sprite_src->height, zoom);
- sprite->width = UnScaleByZoom(sprite_src->width, zoom);
- sprite->x_offs = UnScaleByZoom(sprite_src->x_offs, zoom);
- sprite->y_offs = UnScaleByZoom(sprite_src->y_offs, zoom);
-
- uint size = sprite->height * sprite->width;
- SpriteLoader::CommonPixel *dst = sprite->data = CallocT<SpriteLoader::CommonPixel>(size);
-
- const SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite_src->data;
- const SpriteLoader::CommonPixel *src_end = src + sprite_src->height * sprite_src->width;
-
- uint scaled_1 = ScaleByZoom(1, zoom);
-
- for (uint y = 0; y < sprite->height; y++) {
- if (src >= src_end) src = src_end - sprite_src->width;
-
- const SpriteLoader::CommonPixel *src_ln = src + sprite_src->width * scaled_1;
- for (uint x = 0; x < sprite->width; x++) {
- if (src >= src_ln) src = src_ln - 1;
- *dst = *src;
- dst++;
- src += scaled_1;
- }
-
- src = src_ln;
- }
-
- return sprite;
-}
-
Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
{
/* streams of pixels (a, r, g, b channels)
@@ -287,7 +238,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr
}
for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
- const SpriteLoader::Sprite *src_orig = ResizeSprite(sprite, z);
+ const SpriteLoader::Sprite *src_orig = &sprite[z];
uint size = src_orig->height * src_orig->width;
@@ -371,9 +322,6 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr
lengths[z][0] = (byte *)dst_px_ln - (byte *)dst_px_orig[z]; // all are aligned to 4B boundary
lengths[z][1] = (byte *)dst_n_ln - (byte *)dst_n_orig[z];
-
- free(src_orig->data);
- free(src_orig);
}
uint len = 0; // total length of data
diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp
index 300c79b52..acef6949e 100644
--- a/src/blitter/8bpp_optimized.cpp
+++ b/src/blitter/8bpp_optimized.cpp
@@ -130,7 +130,7 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPro
}
for (ZoomLevel i = zoom_min; i <= zoom_max; i++) {
- memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
+ memory += sprite[i].width * sprite[i].height;
}
/* We have no idea how much memory we really need, so just guess something */
@@ -150,9 +150,8 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPro
temp_dst->offset[i] = offset;
/* cache values, because compiler can't cache it */
- int scaled_height = UnScaleByZoom(sprite->height, i);
- int scaled_width = UnScaleByZoom(sprite->width, i);
- int scaled_1 = ScaleByZoom(1, i);
+ int scaled_height = sprite[i].height;
+ int scaled_width = sprite[i].width;
for (int y = 0; y < scaled_height; y++) {
uint trans = 0;
@@ -161,18 +160,10 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPro
byte *count_dst = NULL;
/* Store the scaled image */
- const SpriteLoader::CommonPixel *src = &sprite->data[ScaleByZoom(y, i) * sprite->width];
- const SpriteLoader::CommonPixel *src_end = &src[sprite->width];
+ const SpriteLoader::CommonPixel *src = &sprite[i].data[y * sprite[i].width];
for (int x = 0; x < scaled_width; x++) {
- uint colour = 0;
-
- /* Get the colour keeping in mind the zoom-level */
- for (int j = 0; j < scaled_1; j++) {
- if (src->m != 0) colour = src->m;
- /* Because of the scaling it might happen we read outside the buffer. Avoid that. */
- if (++src == src_end) break;
- }
+ uint colour = src++->m;
if (last_colour == 0 || colour == 0 || pixels == 255) {
if (count_dst != NULL) {