Changeset - r24899:e3ddcc7e16c9
[Not reviewed]
master
0 6 0
Michael Lutz - 4 years ago 2021-01-16 15:43:30
michi@icosahedron.de
Codechange: Give sprite encoders a hint which colour components of a sprite are filled with useful information.
6 files changed with 21 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -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 */
 

	
 

	
src/os/macosx/font_osx.cpp
Show inline comments
 
@@ -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));
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -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;
src/spritecache.cpp
Show inline comments
 
@@ -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);
src/spriteloader/grf.cpp
Show inline comments
 
@@ -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;
src/spriteloader/spriteloader.hpp
Show inline comments
 
@@ -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
 

	
 
		/**
0 comments (0 inline, 0 general)