diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index d118d75f7a..13a6560da4 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -20,11 +20,6 @@ /** Instantiation of the 32bpp with animation blitter factory. */ static FBlitter_32bppAnim iFBlitter_32bppAnim; -Blitter_32bppAnim::~Blitter_32bppAnim() -{ - free(this->anim_alloc); -} - template inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom) { @@ -545,13 +540,12 @@ void Blitter_32bppAnim::PostResize() if (_screen.width != this->anim_buf_width || _screen.height != this->anim_buf_height || _screen.pitch != this->anim_buf_pitch) { /* The size of the screen changed; we can assume we can wipe all data from our buffer */ - free(this->anim_alloc); this->anim_buf_width = _screen.width; this->anim_buf_height = _screen.height; this->anim_buf_pitch = (_screen.width + 7) & ~7; - this->anim_alloc = CallocT(this->anim_buf_pitch * this->anim_buf_height + 8); + this->anim_alloc = std::make_unique(this->anim_buf_pitch * this->anim_buf_height + 8); /* align buffer to next 16 byte boundary */ - this->anim_buf = reinterpret_cast((reinterpret_cast(this->anim_alloc) + 0xF) & (~0xF)); + this->anim_buf = reinterpret_cast((reinterpret_cast(this->anim_alloc.get()) + 0xF) & (~0xF)); } } diff --git a/src/blitter/32bpp_anim.hpp b/src/blitter/32bpp_anim.hpp index 975a9bfd62..3e4a63685f 100644 --- a/src/blitter/32bpp_anim.hpp +++ b/src/blitter/32bpp_anim.hpp @@ -16,7 +16,7 @@ class Blitter_32bppAnim : public Blitter_32bppOptimized { protected: uint16_t *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation - void *anim_alloc; ///< The raw allocated buffer, not necessarily aligned correctly + std::unique_ptr anim_alloc; ///< The raw allocated buffer, not necessarily aligned correctly int anim_buf_width; ///< The width of the animation buffer. int anim_buf_height; ///< The height of the animation buffer. int anim_buf_pitch; ///< The pitch of the animation buffer (width rounded up to 16 byte boundary). @@ -25,7 +25,6 @@ protected: public: Blitter_32bppAnim() : anim_buf(nullptr), - anim_alloc(nullptr), anim_buf_width(0), anim_buf_height(0), anim_buf_pitch(0) @@ -33,8 +32,6 @@ public: this->palette = _cur_palette; } - ~Blitter_32bppAnim(); - void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override; void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override; void SetPixel(void *video, int x, int y, uint8_t colour) override; diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index 848bb7e9c7..c2d4d25fa2 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -290,7 +290,7 @@ template Sprite *Blitter_32bppOptimized::EncodeInternal(const /* streams of pixels (a, r, g, b channels) * * stored in separated stream so data are always aligned on 4B boundary */ - Colour *dst_px_orig[ZOOM_LVL_END]; + std::array, ZOOM_LVL_END> dst_px_orig; /* interleaved stream of 'm' channel and 'n' channel * 'n' is number of following pixels with the same alpha channel class @@ -298,7 +298,7 @@ template Sprite *Blitter_32bppOptimized::EncodeInternal(const * * it has to be stored in one stream so fewer registers are used - * x86 has problems with register allocation even with this solution */ - uint16_t *dst_n_orig[ZOOM_LVL_END]; + std::array, ZOOM_LVL_END> dst_n_orig; /* lengths of streams */ uint32_t lengths[ZOOM_LVL_END][2]; @@ -320,11 +320,11 @@ template Sprite *Blitter_32bppOptimized::EncodeInternal(const uint size = src_orig->height * src_orig->width; - dst_px_orig[z] = CallocT(size + src_orig->height * 2); - dst_n_orig[z] = CallocT(size * 2 + src_orig->height * 4 * 2); + dst_px_orig[z] = std::make_unique(size + src_orig->height * 2); + dst_n_orig[z] = std::make_unique(size * 2 + src_orig->height * 4 * 2); - uint32_t *dst_px_ln = (uint32_t *)dst_px_orig[z]; - uint32_t *dst_n_ln = (uint32_t *)dst_n_orig[z]; + uint32_t *dst_px_ln = reinterpret_cast(dst_px_orig[z].get()); + uint32_t *dst_n_ln = reinterpret_cast(dst_n_orig[z].get()); const SpriteLoader::CommonPixel *src = (const SpriteLoader::CommonPixel *)src_orig->data; @@ -405,8 +405,8 @@ template Sprite *Blitter_32bppOptimized::EncodeInternal(const dst_n_ln = (uint32_t *)dst_n; } - lengths[z][0] = (uint8_t *)dst_px_ln - (uint8_t *)dst_px_orig[z]; // all are aligned to 4B boundary - lengths[z][1] = (uint8_t *)dst_n_ln - (uint8_t *)dst_n_orig[z]; + lengths[z][0] = reinterpret_cast(dst_px_ln) - reinterpret_cast(dst_px_orig[z].get()); // all are aligned to 4B boundary + lengths[z][1] = reinterpret_cast(dst_n_ln) - reinterpret_cast(dst_n_orig[z].get()); } uint len = 0; // total length of data @@ -428,11 +428,8 @@ template Sprite *Blitter_32bppOptimized::EncodeInternal(const dst->offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->offset[z - 1][1]; dst->offset[z][1] = lengths[z][0] + dst->offset[z][0]; - memcpy(dst->data + dst->offset[z][0], dst_px_orig[z], lengths[z][0]); - memcpy(dst->data + dst->offset[z][1], dst_n_orig[z], lengths[z][1]); - - free(dst_px_orig[z]); - free(dst_n_orig[z]); + memcpy(dst->data + dst->offset[z][0], dst_px_orig[z].get(), lengths[z][0]); + memcpy(dst->data + dst->offset[z][1], dst_n_orig[z].get(), lengths[z][1]); } return dest_sprite;