diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 5cf38cfb13..df20385b86 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -323,21 +323,17 @@ static bool PadSprites(SpriteLoader::SpriteCollection &sprite, ZoomLevels sprite /* Get minimum top left corner coordinates. */ int min_xoffs = INT32_MAX; int min_yoffs = INT32_MAX; - for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { - if (sprite_avail.Test(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)); - } + for (ZoomLevel zoom : sprite_avail) { + min_xoffs = std::min(min_xoffs, ScaleByZoom(sprite[zoom].x_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. */ int max_width = INT32_MIN; int max_height = INT32_MIN; - for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { - 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_height = std::max(max_height, ScaleByZoom(sprite[zoom].height + sprite[zoom].y_offs - UnScaleByZoom(min_yoffs, zoom), zoom)); - } + for (ZoomLevel zoom : sprite_avail) { + 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)); } /* 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. */ - for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { - if (sprite_avail.Test(zoom)) { - auto &cur_sprite = sprite[zoom]; - /* Scaling the sprite dimensions in the blitter is done with rounding up, - * 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_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_bottom = std::max(0, UnScaleByZoom(max_height, zoom) - cur_sprite.height - pad_top); + for (ZoomLevel zoom : sprite_avail) { + auto &cur_sprite = sprite[zoom]; + /* Scaling the sprite dimensions in the blitter is done with rounding up, + * 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_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_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 (!PadSingleSprite(&cur_sprite, zoom, pad_left, pad_top, pad_right, pad_bottom)) return false; - } + 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; } } diff --git a/src/spriteloader/makeindexed.cpp b/src/spriteloader/makeindexed.cpp index fd5cb2c631..c54afaa251 100644 --- a/src/spriteloader/makeindexed.cpp +++ b/src/spriteloader/makeindexed.cpp @@ -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); - for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) { - if (avail.Test(zoom)) Convert32bppTo8bpp(sprite[zoom]); + for (ZoomLevel zoom : avail) { + Convert32bppTo8bpp(sprite[zoom]); } return avail;