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

Function ResizeSpriteOut

src/spritecache.cpp:236–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236static void ResizeSpriteOut(SpriteLoader::SpriteCollection &sprite, ZoomLevel zoom)
237{
238 const auto &root_sprite = sprite.Root();
239 const auto &src_sprite = sprite[zoom - 1];
240 auto &dest_sprite = sprite[zoom];
241
242 /* Algorithm based on 32bpp_Optimized::ResizeSprite() */
243 dest_sprite.width = UnScaleByZoom(root_sprite.width, zoom);
244 dest_sprite.height = UnScaleByZoom(root_sprite.height, zoom);
245 dest_sprite.x_offs = UnScaleByZoom(root_sprite.x_offs, zoom);
246 dest_sprite.y_offs = UnScaleByZoom(root_sprite.y_offs, zoom);
247 dest_sprite.colours = root_sprite.colours;
248
249 dest_sprite.AllocateData(zoom, static_cast<size_t>(dest_sprite.height) * dest_sprite.width);
250
251 SpriteLoader::CommonPixel *dst = dest_sprite.data;
252 const SpriteLoader::CommonPixel *src = src_sprite.data;
253 [[maybe_unused]] const SpriteLoader::CommonPixel *src_end = src + src_sprite.height * src_sprite.width;
254
255 for (uint y = 0; y < dest_sprite.height; y++) {
256 const SpriteLoader::CommonPixel *src_ln = src + src_sprite.width;
257 assert(src_ln <= src_end);
258 for (uint x = 0; x < dest_sprite.width; x++) {
259 assert(src < src_ln);
260 if (src + 1 != src_ln && (src + 1)->a != 0) {
261 *dst = *(src + 1);
262 } else {
263 *dst = *src;
264 }
265 dst++;
266 src += 2;
267 }
268 src = src_ln + src_sprite.width;
269 }
270}
271
272static bool PadSingleSprite(SpriteLoader::Sprite *sprite, ZoomLevel zoom, uint pad_left, uint pad_top, uint pad_right, uint pad_bottom)
273{

Callers 1

ResizeSpritesFunction · 0.85

Calls 2

UnScaleByZoomFunction · 0.85
AllocateDataMethod · 0.80

Tested by

no test coverage detected