mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replace malloc/free with vector when padding sprites.
parent
0f0f3d74ca
commit
9a037fe5ae
|
@ -290,12 +290,11 @@ static bool PadSingleSprite(SpriteLoader::Sprite *sprite, ZoomLevel zoom, uint p
|
||||||
|
|
||||||
/* Copy source data and reallocate sprite memory. */
|
/* Copy source data and reallocate sprite memory. */
|
||||||
size_t sprite_size = static_cast<size_t>(sprite->width) * sprite->height;
|
size_t sprite_size = static_cast<size_t>(sprite->width) * sprite->height;
|
||||||
SpriteLoader::CommonPixel *src_data = MallocT<SpriteLoader::CommonPixel>(sprite_size);
|
std::vector<SpriteLoader::CommonPixel> src_data(sprite->data, sprite->data + sprite_size);
|
||||||
MemCpyT(src_data, sprite->data, sprite_size);
|
|
||||||
sprite->AllocateData(zoom, static_cast<size_t>(width) * height);
|
sprite->AllocateData(zoom, static_cast<size_t>(width) * height);
|
||||||
|
|
||||||
/* Copy with padding to destination. */
|
/* Copy with padding to destination. */
|
||||||
SpriteLoader::CommonPixel *src = src_data;
|
SpriteLoader::CommonPixel *src = src_data.data();
|
||||||
SpriteLoader::CommonPixel *data = sprite->data;
|
SpriteLoader::CommonPixel *data = sprite->data;
|
||||||
for (uint y = 0; y < height; y++) {
|
for (uint y = 0; y < height; y++) {
|
||||||
if (y < pad_top || pad_bottom + y >= height) {
|
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. */
|
/* Update sprite size. */
|
||||||
sprite->width = width;
|
sprite->width = width;
|
||||||
|
|
Loading…
Reference in New Issue