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,22 +323,18 @@ 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. */
uint align = encoder->GetSpriteAlignment(); uint align = encoder->GetSpriteAlignment();
@ -348,8 +344,7 @@ 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. */
@ -362,7 +357,6 @@ static bool PadSprites(SpriteLoader::SpriteCollection &sprite, ZoomLevels sprite
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;
} }
} }
}
return true; return true;
} }

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;