summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fontcache.cpp3
-rw-r--r--src/os/macosx/font_osx.cpp1
-rw-r--r--src/os/windows/font_win32.cpp1
-rw-r--r--src/spritecache.cpp3
-rw-r--r--src/spriteloader/grf.cpp12
-rw-r--r--src/spriteloader/spriteloader.hpp11
6 files changed, 21 insertions, 10 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index be36ac107..8ed8708aa 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -351,6 +351,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
0, // x_offs
0, // y_offs
ST_FONT,
+ SCC_PAL,
builtin_questionmark_data
};
@@ -614,6 +615,7 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
SpriteLoader::Sprite sprite;
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
sprite.type = ST_FONT;
+ sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
sprite.width = width;
sprite.height = height;
sprite.x_offs = slot->bitmap_left;
@@ -676,7 +678,6 @@ const void *FreeTypeFontCache::InternalGetFontTable(uint32 tag, size_t &length)
length = len;
return result;
}
-
#endif /* WITH_FREETYPE */
diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp
index 0a1b9e99a..04e5db9ab 100644
--- a/src/os/macosx/font_osx.cpp
+++ b/src/os/macosx/font_osx.cpp
@@ -286,6 +286,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
SpriteLoader::Sprite sprite;
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
sprite.type = ST_FONT;
+ sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
sprite.width = width;
sprite.height = height;
sprite.x_offs = (int16)std::round(CGRectGetMinX(bounds));
diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp
index 7df24828b..a3b60933c 100644
--- a/src/os/windows/font_win32.cpp
+++ b/src/os/windows/font_win32.cpp
@@ -495,6 +495,7 @@ void Win32FontCache::ClearFontCache()
SpriteLoader::Sprite sprite;
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
sprite.type = ST_FONT;
+ sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
sprite.width = width;
sprite.height = height;
sprite.x_offs = gm.gmptGlyphOrigin.x;
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index c045605d6..f86be1b97 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -199,6 +199,7 @@ static bool ResizeSpriteIn(SpriteLoader::Sprite *sprite, ZoomLevel src, ZoomLeve
sprite[tgt].height = sprite[src].height * scaled_1;
sprite[tgt].x_offs = sprite[src].x_offs * scaled_1;
sprite[tgt].y_offs = sprite[src].y_offs * scaled_1;
+ sprite[tgt].colours = sprite[src].colours;
sprite[tgt].AllocateData(tgt, sprite[tgt].width * sprite[tgt].height);
@@ -221,6 +222,7 @@ static void ResizeSpriteOut(SpriteLoader::Sprite *sprite, ZoomLevel zoom)
sprite[zoom].height = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].height, zoom);
sprite[zoom].x_offs = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].x_offs, zoom);
sprite[zoom].y_offs = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].y_offs, zoom);
+ sprite[zoom].colours = sprite[ZOOM_LVL_NORMAL].colours;
sprite[zoom].AllocateData(zoom, sprite[zoom].height * sprite[zoom].width);
@@ -487,6 +489,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
sprite[ZOOM_LVL_NORMAL].x_offs = sprite[ZOOM_LVL_FONT].x_offs;
sprite[ZOOM_LVL_NORMAL].y_offs = sprite[ZOOM_LVL_FONT].y_offs;
sprite[ZOOM_LVL_NORMAL].data = sprite[ZOOM_LVL_FONT].data;
+ sprite[ZOOM_LVL_NORMAL].colours = sprite[ZOOM_LVL_FONT].colours;
}
return encoder->Encode(sprite, allocator);
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
/**