1
0
Fork 0

Codechange: Replace malloc/free with vector when padding sprites.

pull/12907/head
Peter Nelson 2024-08-18 18:54:53 +01:00 committed by Peter Nelson
parent 0f0f3d74ca
commit 9a037fe5ae
1 changed files with 2 additions and 4 deletions

View File

@ -290,12 +290,11 @@ static bool PadSingleSprite(SpriteLoader::Sprite *sprite, ZoomLevel zoom, uint p
/* Copy source data and reallocate sprite memory. */
size_t sprite_size = static_cast<size_t>(sprite->width) * sprite->height;
SpriteLoader::CommonPixel *src_data = MallocT<SpriteLoader::CommonPixel>(sprite_size);
MemCpyT(src_data, sprite->data, sprite_size);
std::vector<SpriteLoader::CommonPixel> src_data(sprite->data, sprite->data + sprite_size);
sprite->AllocateData(zoom, static_cast<size_t>(width) * height);
/* Copy with padding to destination. */
SpriteLoader::CommonPixel *src = src_data;
SpriteLoader::CommonPixel *src = src_data.data();
SpriteLoader::CommonPixel *data = sprite->data;
for (uint y = 0; y < height; y++) {
if (y < pad_top || pad_bottom + y >= height) {
@ -321,7 +320,6 @@ static bool PadSingleSprite(SpriteLoader::Sprite *sprite, ZoomLevel zoom, uint p
}
}
}
free(src_data);
/* Update sprite size. */
sprite->width = width;