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

Function ResizeSpriteIn

src/spritecache.cpp:207–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207static bool ResizeSpriteIn(SpriteLoader::SpriteCollection &sprite, ZoomLevel src, ZoomLevel tgt)
208{
209 uint8_t scaled_1 = AdjustByZoom(1, src - tgt);
210 const auto &src_sprite = sprite[src];
211 auto &dest_sprite = sprite[tgt];
212
213 /* Check for possible memory overflow. */
214 if (src_sprite.width * scaled_1 > UINT16_MAX || src_sprite.height * scaled_1 > UINT16_MAX) return false;
215
216 dest_sprite.width = src_sprite.width * scaled_1;
217 dest_sprite.height = src_sprite.height * scaled_1;
218 dest_sprite.x_offs = src_sprite.x_offs * scaled_1;
219 dest_sprite.y_offs = src_sprite.y_offs * scaled_1;
220 dest_sprite.colours = src_sprite.colours;
221
222 dest_sprite.AllocateData(tgt, static_cast<size_t>(dest_sprite.width) * dest_sprite.height);
223
224 SpriteLoader::CommonPixel *dst = dest_sprite.data;
225 for (int y = 0; y < dest_sprite.height; y++) {
226 const SpriteLoader::CommonPixel *src_ln = &src_sprite.data[y / scaled_1 * src_sprite.width];
227 for (int x = 0; x < dest_sprite.width; x++) {
228 *dst = src_ln[x / scaled_1];
229 dst++;
230 }
231 }
232
233 return true;
234}
235
236static void ResizeSpriteOut(SpriteLoader::SpriteCollection &sprite, ZoomLevel zoom)
237{

Callers 1

ResizeSpritesFunction · 0.85

Calls 2

AdjustByZoomFunction · 0.85
AllocateDataMethod · 0.80

Tested by

no test coverage detected