1
0
Fork 0

Codechange: Make use of ZoomLevels range iteration. (#14422)

pull/14423/head
Peter Nelson 2025-07-08 14:00:12 +01:00 committed by GitHub
parent b21c8a3450
commit 77b572619a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 24 deletions

View File

@ -323,21 +323,17 @@ static bool PadSprites(SpriteLoader::SpriteCollection &sprite, ZoomLevels sprite
/* Get minimum top left corner coordinates. */ /* Get minimum top left corner coordinates. */
int min_xoffs = INT32_MAX; int min_xoffs = INT32_MAX;
int min_yoffs = INT32_MAX; int min_yoffs = INT32_MAX;
for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { for (ZoomLevel zoom : sprite_avail) {
if (sprite_avail.Test(zoom)) { min_xoffs = std::min(min_xoffs, ScaleByZoom(sprite[zoom].x_offs, zoom));
min_xoffs = std::min(min_xoffs, ScaleByZoom(sprite[zoom].x_offs, zoom)); min_yoffs = std::min(min_yoffs, ScaleByZoom(sprite[zoom].y_offs, zoom));
min_yoffs = std::min(min_yoffs, ScaleByZoom(sprite[zoom].y_offs, zoom));
}
} }
/* Get maximum dimensions taking necessary padding at the top left into account. */ /* Get maximum dimensions taking necessary padding at the top left into account. */
int max_width = INT32_MIN; int max_width = INT32_MIN;
int max_height = INT32_MIN; int max_height = INT32_MIN;
for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { for (ZoomLevel zoom : sprite_avail) {
if (sprite_avail.Test(zoom)) { max_width = std::max(max_width, ScaleByZoom(sprite[zoom].width + sprite[zoom].x_offs - UnScaleByZoom(min_xoffs, zoom), zoom));
max_width = std::max(max_width, ScaleByZoom(sprite[zoom].width + sprite[zoom].x_offs - UnScaleByZoom(min_xoffs, zoom), zoom)); max_height = std::max(max_height, ScaleByZoom(sprite[zoom].height + sprite[zoom].y_offs - UnScaleByZoom(min_yoffs, zoom), zoom));
max_height = std::max(max_height, ScaleByZoom(sprite[zoom].height + sprite[zoom].y_offs - UnScaleByZoom(min_yoffs, zoom), zoom));
}
} }
/* Align height and width if required to match the needs of the sprite encoder. */ /* Align height and width if required to match the needs of the sprite encoder. */
@ -348,19 +344,17 @@ static bool PadSprites(SpriteLoader::SpriteCollection &sprite, ZoomLevels sprite
} }
/* Pad sprites where needed. */ /* Pad sprites where needed. */
for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { for (ZoomLevel zoom : sprite_avail) {
if (sprite_avail.Test(zoom)) { auto &cur_sprite = sprite[zoom];
auto &cur_sprite = sprite[zoom]; /* Scaling the sprite dimensions in the blitter is done with rounding up,
/* Scaling the sprite dimensions in the blitter is done with rounding up, * so a negative padding here is not an error. */
* so a negative padding here is not an error. */ int pad_left = std::max(0, cur_sprite.x_offs - UnScaleByZoom(min_xoffs, zoom));
int pad_left = std::max(0, cur_sprite.x_offs - UnScaleByZoom(min_xoffs, zoom)); int pad_top = std::max(0, cur_sprite.y_offs - UnScaleByZoom(min_yoffs, zoom));
int pad_top = std::max(0, cur_sprite.y_offs - UnScaleByZoom(min_yoffs, zoom)); int pad_right = std::max(0, UnScaleByZoom(max_width, zoom) - cur_sprite.width - pad_left);
int pad_right = std::max(0, UnScaleByZoom(max_width, zoom) - cur_sprite.width - pad_left); int pad_bottom = std::max(0, UnScaleByZoom(max_height, zoom) - cur_sprite.height - pad_top);
int pad_bottom = std::max(0, UnScaleByZoom(max_height, zoom) - cur_sprite.height - pad_top);
if (pad_left > 0 || pad_right > 0 || pad_top > 0 || pad_bottom > 0) { if (pad_left > 0 || pad_right > 0 || pad_top > 0 || pad_bottom > 0) {
if (!PadSingleSprite(&cur_sprite, zoom, pad_left, pad_top, pad_right, pad_bottom)) return false; if (!PadSingleSprite(&cur_sprite, zoom, pad_left, pad_top, pad_right, pad_bottom)) return false;
}
} }
} }

View File

@ -52,8 +52,8 @@ ZoomLevels SpriteLoaderMakeIndexed::LoadSprite(SpriteLoader::SpriteCollection &s
{ {
ZoomLevels avail = this->baseloader.LoadSprite(sprite, file, file_pos, sprite_type, true, control_flags, avail_8bpp, avail_32bpp); ZoomLevels avail = this->baseloader.LoadSprite(sprite, file, file_pos, sprite_type, true, control_flags, avail_8bpp, avail_32bpp);
for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { for (ZoomLevel zoom : avail) {
if (avail.Test(zoom)) Convert32bppTo8bpp(sprite[zoom]); Convert32bppTo8bpp(sprite[zoom]);
} }
return avail; return avail;