summaryrefslogtreecommitdiff
path: root/src/spriteloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/spriteloader')
-rw-r--r--src/spriteloader/grf.cpp18
-rw-r--r--src/spriteloader/png.cpp19
2 files changed, 35 insertions, 2 deletions
diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp
index a0f5c8632..2876f2f35 100644
--- a/src/spriteloader/grf.cpp
+++ b/src/spriteloader/grf.cpp
@@ -95,7 +95,7 @@ bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot,
if (num != 0) return WarnCorruptSprite(file_slot, file_pos, __LINE__);
- sprite->AllocateData(sprite->width * sprite->height);
+ sprite->AllocateData(sprite->width * sprite->height * ZOOM_LVL_BASE * ZOOM_LVL_BASE);
/* When there are transparency pixels, this format has another trick.. decode it */
if (type & 0x08) {
@@ -163,6 +163,22 @@ bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot,
}
}
+ if (ZOOM_LVL_BASE != 1 && sprite_type == ST_NORMAL) {
+ /* Simple scaling, back-to-front so that no intermediate buffers are needed. */
+ int width = sprite->width * ZOOM_LVL_BASE;
+ int height = sprite->height * ZOOM_LVL_BASE;
+ for (int y = height - 1; y >= 0; y--) {
+ for (int x = width - 1; x >= 0; x--) {
+ sprite->data[y * width + x] = sprite->data[y / ZOOM_LVL_BASE * sprite->width + x / ZOOM_LVL_BASE];
+ }
+ }
+
+ sprite->width *= ZOOM_LVL_BASE;
+ sprite->height *= ZOOM_LVL_BASE;
+ sprite->x_offs *= ZOOM_LVL_BASE;
+ sprite->y_offs *= ZOOM_LVL_BASE;
+ }
+
/* Make sure to mark all transparent pixels transparent on the alpha channel too */
for (int i = 0; i < sprite->width * sprite->height; i++) {
if (sprite->data[i].m != 0) sprite->data[i].a = 0xFF;
diff --git a/src/spriteloader/png.cpp b/src/spriteloader/png.cpp
index 790b2a2c9..abc9592e0 100644
--- a/src/spriteloader/png.cpp
+++ b/src/spriteloader/png.cpp
@@ -115,7 +115,7 @@ static bool LoadPNG(SpriteLoader::Sprite *sprite, const char *filename, uint32 i
}
sprite->height = height;
sprite->width = width;
- sprite->AllocateData(sprite->width * sprite->height);
+ sprite->AllocateData(sprite->width * sprite->height * ZOOM_LVL_BASE * ZOOM_LVL_BASE);
} else if (sprite->height != png_get_image_height(png_ptr, info_ptr) || sprite->width != png_get_image_width(png_ptr, info_ptr)) {
/* Make sure the mask image isn't larger than the sprite image. */
DEBUG(misc, 0, "Ignoring mask for SpriteID %d as it isn't the same dimension as the masked sprite", id);
@@ -214,6 +214,23 @@ bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot,
const char *filename = FioGetFilename(file_slot);
if (!LoadPNG(sprite, filename, (uint32)file_pos, false)) return false;
if (!LoadPNG(sprite, filename, (uint32)file_pos, true)) return false;
+
+ if (ZOOM_LVL_BASE != 1 && sprite_type == ST_NORMAL) {
+ /* Simple scaling, back-to-front so that no intermediate buffers are needed. */
+ int width = sprite->width * ZOOM_LVL_BASE;
+ int height = sprite->height * ZOOM_LVL_BASE;
+ for (int y = height - 1; y >= 0; y--) {
+ for (int x = width - 1; x >= 0; x--) {
+ sprite->data[y * width + x] = sprite->data[y / ZOOM_LVL_BASE * sprite->width + x / ZOOM_LVL_BASE];
+ }
+ }
+
+ sprite->width *= ZOOM_LVL_BASE;
+ sprite->height *= ZOOM_LVL_BASE;
+ sprite->x_offs *= ZOOM_LVL_BASE;
+ sprite->y_offs *= ZOOM_LVL_BASE;
+ }
+
return true;
}