summaryrefslogtreecommitdiff
path: root/src/spriteloader
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-16 16:43:30 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-22 22:16:07 +0100
commit70aa3b401145ec6bb98073a2758206cf63e15da1 (patch)
tree167cef03688a11e5c4a6b44cb300c9fd33d1d0bb /src/spriteloader
parente7e53163404d4bb04b1213fccfb0772596b37f95 (diff)
downloadopenttd-70aa3b401145ec6bb98073a2758206cf63e15da1.tar.xz
Codechange: Give sprite encoders a hint which colour components of a sprite are filled with useful information.
Diffstat (limited to 'src/spriteloader')
-rw-r--r--src/spriteloader/grf.cpp12
-rw-r--r--src/spriteloader/spriteloader.hpp11
2 files changed, 14 insertions, 9 deletions
diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp
index 5e540450d..f3c3ed8ac 100644
--- a/src/spriteloader/grf.cpp
+++ b/src/spriteloader/grf.cpp
@@ -23,15 +23,6 @@
extern const byte _palmap_w2d[];
-/** The different colour components a sprite can have. */
-enum SpriteColourComponent {
- SCC_RGB = 1 << 0, ///< Sprite has RGB.
- SCC_ALPHA = 1 << 1, ///< Sprite has alpha.
- SCC_PAL = 1 << 2, ///< Sprite has palette data.
- SCC_MASK = SCC_RGB | SCC_ALPHA | SCC_PAL, ///< Mask of valid colour bits.
-};
-DECLARE_ENUM_AS_BIT_SET(SpriteColourComponent)
-
/**
* We found a corrupted sprite. This means that the sprite itself
* contains invalid data or is too small for the given dimensions.
@@ -234,6 +225,7 @@ uint8 LoadSpriteV1(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
sprite[zoom_lvl].width = FioReadWord();
sprite[zoom_lvl].x_offs = FioReadWord();
sprite[zoom_lvl].y_offs = FioReadWord();
+ sprite[zoom_lvl].colours = SCC_PAL;
if (sprite[zoom_lvl].width > INT16_MAX) {
WarnCorruptSprite(file_slot, file_pos, __LINE__);
@@ -302,6 +294,8 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
if (colour & SCC_ALPHA) bpp++; // Has alpha data.
if (colour & SCC_PAL) bpp++; // Has palette data.
+ sprite[zoom_lvl].colours = (SpriteColourComponent)colour;
+
/* For chunked encoding we store the decompressed size in the file,
* otherwise we can calculate it from the image dimensions. */
uint decomp_size = (type & 0x08) ? FioReadDword() : sprite[zoom_lvl].width * sprite[zoom_lvl].height * bpp;
diff --git a/src/spriteloader/spriteloader.hpp b/src/spriteloader/spriteloader.hpp
index c75f4685c..7b2474633 100644
--- a/src/spriteloader/spriteloader.hpp
+++ b/src/spriteloader/spriteloader.hpp
@@ -11,11 +11,21 @@
#define SPRITELOADER_HPP
#include "../core/alloc_type.hpp"
+#include "../core/enum_type.hpp"
#include "../gfx_type.h"
struct Sprite;
typedef void *AllocatorProc(size_t size);
+/** The different colour components a sprite can have. */
+enum SpriteColourComponent {
+ SCC_RGB = 1 << 0, ///< Sprite has RGB.
+ SCC_ALPHA = 1 << 1, ///< Sprite has alpha.
+ SCC_PAL = 1 << 2, ///< Sprite has palette data.
+ SCC_MASK = SCC_RGB | SCC_ALPHA | SCC_PAL, ///< Mask of valid colour bits.
+};
+DECLARE_ENUM_AS_BIT_SET(SpriteColourComponent)
+
/** Interface for the loader of our sprites. */
class SpriteLoader {
public:
@@ -40,6 +50,7 @@ public:
int16 x_offs; ///< The x-offset of where the sprite will be drawn
int16 y_offs; ///< The y-offset of where the sprite will be drawn
SpriteType type; ///< The sprite type
+ SpriteColourComponent colours; ///< The colour components of the sprite with useful information.
SpriteLoader::CommonPixel *data; ///< The sprite itself
/**