MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ResizeSprites

Function ResizeSprites

src/spritecache.cpp:364–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364static bool ResizeSprites(SpriteLoader::SpriteCollection &sprite, ZoomLevels sprite_avail, SpriteEncoder *encoder)
365{
366 /* Create a fully zoomed image if it does not exist */
367 ZoomLevel first_avail = ZoomLevel::End;
368 for (ZoomLevel zoom = ZoomLevel::Min; zoom <= ZoomLevel::Max; ++zoom) {
369 if (!sprite_avail.Test(zoom)) continue;
370 first_avail = zoom;
371 if (zoom != ZoomLevel::Min) {
372 if (!ResizeSpriteIn(sprite, zoom, ZoomLevel::Min)) return false;
373 sprite_avail.Set(ZoomLevel::Min);
374 }
375 break;
376 }
377
378 /* Pad sprites to make sizes match. */
379 if (!PadSprites(sprite, sprite_avail, encoder)) return false;
380
381 /* Create other missing zoom levels */
382 for (ZoomLevel zoom = ZoomLevel::Begin; zoom != ZoomLevel::End; zoom++) {
383 if (zoom == ZoomLevel::Min) continue;
384
385 if (sprite_avail.Test(zoom)) {
386 /* Check that size and offsets match the fully zoomed image. */
387 [[maybe_unused]] const auto &root_sprite = sprite[ZoomLevel::Min];
388 [[maybe_unused]] const auto &dest_sprite = sprite[zoom];
389 assert(dest_sprite.width == UnScaleByZoom(root_sprite.width, zoom));
390 assert(dest_sprite.height == UnScaleByZoom(root_sprite.height, zoom));
391 assert(dest_sprite.x_offs == UnScaleByZoom(root_sprite.x_offs, zoom));
392 assert(dest_sprite.y_offs == UnScaleByZoom(root_sprite.y_offs, zoom));
393 } else {
394 /* Zoom level is not available, or unusable, so create it */
395 ResizeSpriteOut(sprite, zoom);
396 }
397 }
398
399 /* Replace sprites with higher resolution than the desired maximum source resolution with scaled up sprites, if not already done. */
400 if (first_avail < _settings_client.gui.sprite_zoom_min) {
401 for (ZoomLevel zoom = std::min(ZoomLevel::Normal, _settings_client.gui.sprite_zoom_min); zoom > ZoomLevel::Min; --zoom) {
402 ResizeSpriteIn(sprite, zoom, zoom - 1);
403 }
404 }
405
406 return true;
407}
408
409/**
410 * Load a recolour sprite into memory.

Callers 1

ReadSpriteFunction · 0.85

Calls 6

ResizeSpriteInFunction · 0.85
PadSpritesFunction · 0.85
UnScaleByZoomFunction · 0.85
ResizeSpriteOutFunction · 0.85
TestMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected