mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Give sprite encoders a hint which colour components of a sprite are filled with useful information.
parent
e7e5316340
commit
70aa3b4011
|
@ -351,6 +351,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
|
||||||
0, // x_offs
|
0, // x_offs
|
||||||
0, // y_offs
|
0, // y_offs
|
||||||
ST_FONT,
|
ST_FONT,
|
||||||
|
SCC_PAL,
|
||||||
builtin_questionmark_data
|
builtin_questionmark_data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -614,6 +615,7 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
|
||||||
SpriteLoader::Sprite sprite;
|
SpriteLoader::Sprite sprite;
|
||||||
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
||||||
sprite.type = ST_FONT;
|
sprite.type = ST_FONT;
|
||||||
|
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
||||||
sprite.width = width;
|
sprite.width = width;
|
||||||
sprite.height = height;
|
sprite.height = height;
|
||||||
sprite.x_offs = slot->bitmap_left;
|
sprite.x_offs = slot->bitmap_left;
|
||||||
|
@ -676,7 +678,6 @@ const void *FreeTypeFontCache::InternalGetFontTable(uint32 tag, size_t &length)
|
||||||
length = len;
|
length = len;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WITH_FREETYPE */
|
#endif /* WITH_FREETYPE */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
|
||||||
SpriteLoader::Sprite sprite;
|
SpriteLoader::Sprite sprite;
|
||||||
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
||||||
sprite.type = ST_FONT;
|
sprite.type = ST_FONT;
|
||||||
|
sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
||||||
sprite.width = width;
|
sprite.width = width;
|
||||||
sprite.height = height;
|
sprite.height = height;
|
||||||
sprite.x_offs = (int16)std::round(CGRectGetMinX(bounds));
|
sprite.x_offs = (int16)std::round(CGRectGetMinX(bounds));
|
||||||
|
|
|
@ -495,6 +495,7 @@ void Win32FontCache::ClearFontCache()
|
||||||
SpriteLoader::Sprite sprite;
|
SpriteLoader::Sprite sprite;
|
||||||
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
|
||||||
sprite.type = ST_FONT;
|
sprite.type = ST_FONT;
|
||||||
|
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
|
||||||
sprite.width = width;
|
sprite.width = width;
|
||||||
sprite.height = height;
|
sprite.height = height;
|
||||||
sprite.x_offs = gm.gmptGlyphOrigin.x;
|
sprite.x_offs = gm.gmptGlyphOrigin.x;
|
||||||
|
|
|
@ -199,6 +199,7 @@ static bool ResizeSpriteIn(SpriteLoader::Sprite *sprite, ZoomLevel src, ZoomLeve
|
||||||
sprite[tgt].height = sprite[src].height * scaled_1;
|
sprite[tgt].height = sprite[src].height * scaled_1;
|
||||||
sprite[tgt].x_offs = sprite[src].x_offs * scaled_1;
|
sprite[tgt].x_offs = sprite[src].x_offs * scaled_1;
|
||||||
sprite[tgt].y_offs = sprite[src].y_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);
|
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].height = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].height, zoom);
|
||||||
sprite[zoom].x_offs = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].x_offs, 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].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);
|
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].x_offs = sprite[ZOOM_LVL_FONT].x_offs;
|
||||||
sprite[ZOOM_LVL_NORMAL].y_offs = sprite[ZOOM_LVL_FONT].y_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].data = sprite[ZOOM_LVL_FONT].data;
|
||||||
|
sprite[ZOOM_LVL_NORMAL].colours = sprite[ZOOM_LVL_FONT].colours;
|
||||||
}
|
}
|
||||||
|
|
||||||
return encoder->Encode(sprite, allocator);
|
return encoder->Encode(sprite, allocator);
|
||||||
|
|
|
@ -23,15 +23,6 @@
|
||||||
|
|
||||||
extern const byte _palmap_w2d[];
|
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
|
* We found a corrupted sprite. This means that the sprite itself
|
||||||
* contains invalid data or is too small for the given dimensions.
|
* 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].width = FioReadWord();
|
||||||
sprite[zoom_lvl].x_offs = FioReadWord();
|
sprite[zoom_lvl].x_offs = FioReadWord();
|
||||||
sprite[zoom_lvl].y_offs = FioReadWord();
|
sprite[zoom_lvl].y_offs = FioReadWord();
|
||||||
|
sprite[zoom_lvl].colours = SCC_PAL;
|
||||||
|
|
||||||
if (sprite[zoom_lvl].width > INT16_MAX) {
|
if (sprite[zoom_lvl].width > INT16_MAX) {
|
||||||
WarnCorruptSprite(file_slot, file_pos, __LINE__);
|
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_ALPHA) bpp++; // Has alpha data.
|
||||||
if (colour & SCC_PAL) bpp++; // Has palette 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,
|
/* For chunked encoding we store the decompressed size in the file,
|
||||||
* otherwise we can calculate it from the image dimensions. */
|
* otherwise we can calculate it from the image dimensions. */
|
||||||
uint decomp_size = (type & 0x08) ? FioReadDword() : sprite[zoom_lvl].width * sprite[zoom_lvl].height * bpp;
|
uint decomp_size = (type & 0x08) ? FioReadDword() : sprite[zoom_lvl].width * sprite[zoom_lvl].height * bpp;
|
||||||
|
|
|
@ -11,11 +11,21 @@
|
||||||
#define SPRITELOADER_HPP
|
#define SPRITELOADER_HPP
|
||||||
|
|
||||||
#include "../core/alloc_type.hpp"
|
#include "../core/alloc_type.hpp"
|
||||||
|
#include "../core/enum_type.hpp"
|
||||||
#include "../gfx_type.h"
|
#include "../gfx_type.h"
|
||||||
|
|
||||||
struct Sprite;
|
struct Sprite;
|
||||||
typedef void *AllocatorProc(size_t size);
|
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. */
|
/** Interface for the loader of our sprites. */
|
||||||
class SpriteLoader {
|
class SpriteLoader {
|
||||||
public:
|
public:
|
||||||
|
@ -40,6 +50,7 @@ public:
|
||||||
int16 x_offs; ///< The x-offset of where the sprite will be drawn
|
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
|
int16 y_offs; ///< The y-offset of where the sprite will be drawn
|
||||||
SpriteType type; ///< The sprite type
|
SpriteType type; ///< The sprite type
|
||||||
|
SpriteColourComponent colours; ///< The colour components of the sprite with useful information.
|
||||||
SpriteLoader::CommonPixel *data; ///< The sprite itself
|
SpriteLoader::CommonPixel *data; ///< The sprite itself
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue