Changeset - r24898:4f4f325b2cf2
[Not reviewed]
master
0 2 0
Michael Lutz - 3 years ago 2021-01-16 15:43:29
michi@icosahedron.de
Add: Allow sprite encoders (blitters) to specify an alignment for sprite width and height.
2 files changed with 20 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/spritecache.cpp
Show inline comments
 
@@ -295,7 +295,7 @@ static bool PadSingleSprite(SpriteLoader
 
	return true;
 
}
 

	
 
static bool PadSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail)
 
static bool PadSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail, SpriteEncoder *encoder)
 
{
 
	/* Get minimum top left corner coordinates. */
 
	int min_xoffs = INT32_MAX;
 
@@ -317,6 +317,13 @@ static bool PadSprites(SpriteLoader::Spr
 
		}
 
	}
 

	
 
	/* Align height and width if required to match the needs of the sprite encoder. */
 
	uint align = encoder->GetSpriteAlignment();
 
	if (align != 0) {
 
		max_width  = Align(max_width,  align);
 
		max_height = Align(max_height, align);
 
	}
 

	
 
	/* Pad sprites where needed. */
 
	for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) {
 
		if (HasBit(sprite_avail, zoom)) {
 
@@ -336,7 +343,7 @@ static bool PadSprites(SpriteLoader::Spr
 
	return true;
 
}
 

	
 
static bool ResizeSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail, uint32 file_slot, uint32 file_pos)
 
static bool ResizeSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail, uint32 file_slot, uint32 file_pos, SpriteEncoder *encoder)
 
{
 
	/* Create a fully zoomed image if it does not exist */
 
	ZoomLevel first_avail = static_cast<ZoomLevel>(FIND_FIRST_BIT(sprite_avail));
 
@@ -346,7 +353,7 @@ static bool ResizeSprites(SpriteLoader::
 
	}
 

	
 
	/* Pad sprites to make sizes match. */
 
	if (!PadSprites(sprite, sprite_avail)) return false;
 
	if (!PadSprites(sprite, sprite_avail, encoder)) return false;
 

	
 
	/* Create other missing zoom levels */
 
	for (ZoomLevel zoom = ZOOM_LVL_OUT_2X; zoom != ZOOM_LVL_END; zoom++) {
 
@@ -468,7 +475,7 @@ static void *ReadSprite(const SpriteCach
 
		return s;
 
	}
 

	
 
	if (!ResizeSprites(sprite, sprite_avail, file_slot, sc->id)) {
 
	if (!ResizeSprites(sprite, sprite_avail, file_slot, sc->id, encoder)) {
 
		if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't resize the fallback sprite. What should I do?");
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder);
 
	}
src/spriteloader/spriteloader.hpp
Show inline comments
 
@@ -82,5 +82,14 @@ public:
 
	 * Convert a sprite from the loader to our own format.
 
	 */
 
	virtual Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0;
 

	
 
	/**
 
	 * Get the value which the height and width on a sprite have to be aligned by.
 
	 * @return The needed alignment or 0 if any alignment is accepted.
 
	 */
 
	virtual uint GetSpriteAlignment()
 
	{
 
		return 0;
 
	}
 
};
 
#endif /* SPRITELOADER_HPP */
0 comments (0 inline, 0 general)