diff --git a/src/fontcache.cpp b/src/fontcache.cpp --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -351,6 +351,7 @@ const Sprite *TrueTypeFontCache::GetGlyp 0, // x_offs 0, // y_offs ST_FONT, + SCC_PAL, builtin_questionmark_data }; @@ -614,6 +615,7 @@ const Sprite *FreeTypeFontCache::Interna 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::InternalG length = len; return result; } - #endif /* WITH_FREETYPE */ diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -286,6 +286,7 @@ const Sprite *CoreTextFontCache::Interna 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 --- 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 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -199,6 +199,7 @@ static bool ResizeSpriteIn(SpriteLoader: 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[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 SpriteCach 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 --- 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[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 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 --- 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 /**