1
0
Fork 0

Add: Allow sprite encoders (blitters) to specify an alignment for sprite width and height.

pull/8729/head
Michael Lutz 2021-01-16 16:43:29 +01:00
parent 02e8741457
commit e7e5316340
2 changed files with 20 additions and 4 deletions

View File

@ -295,7 +295,7 @@ static bool PadSingleSprite(SpriteLoader::Sprite *sprite, ZoomLevel zoom, uint p
return true; 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. */ /* Get minimum top left corner coordinates. */
int min_xoffs = INT32_MAX; int min_xoffs = INT32_MAX;
@ -317,6 +317,13 @@ static bool PadSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail)
} }
} }
/* 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. */ /* Pad sprites where needed. */
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) { for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) {
if (HasBit(sprite_avail, zoom)) { if (HasBit(sprite_avail, zoom)) {
@ -336,7 +343,7 @@ static bool PadSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail)
return true; 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 */ /* Create a fully zoomed image if it does not exist */
ZoomLevel first_avail = static_cast<ZoomLevel>(FIND_FIRST_BIT(sprite_avail)); ZoomLevel first_avail = static_cast<ZoomLevel>(FIND_FIRST_BIT(sprite_avail));
@ -346,7 +353,7 @@ static bool ResizeSprites(SpriteLoader::Sprite *sprite, uint8 sprite_avail, uint
} }
/* Pad sprites to make sizes match. */ /* 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 */ /* Create other missing zoom levels */
for (ZoomLevel zoom = ZOOM_LVL_OUT_2X; zoom != ZOOM_LVL_END; zoom++) { for (ZoomLevel zoom = ZOOM_LVL_OUT_2X; zoom != ZOOM_LVL_END; zoom++) {
@ -468,7 +475,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
return s; 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?"); 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); return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder);
} }

View File

@ -82,5 +82,14 @@ public:
* Convert a sprite from the loader to our own format. * Convert a sprite from the loader to our own format.
*/ */
virtual Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0; 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 */ #endif /* SPRITELOADER_HPP */