From 56cc138e58b70695d83da890ce6a11ff8148043d Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 24 Sep 2017 12:15:22 -0500 Subject: IMAGE: Remove unnecessary heap allocation in BitmapRawDecoder --- image/codecs/bmp_raw.cpp | 26 +++++++++++--------------- image/codecs/bmp_raw.h | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) (limited to 'image') diff --git a/image/codecs/bmp_raw.cpp b/image/codecs/bmp_raw.cpp index 1a856f1306..149136c5b4 100644 --- a/image/codecs/bmp_raw.cpp +++ b/image/codecs/bmp_raw.cpp @@ -29,16 +29,12 @@ namespace Image { BitmapRawDecoder::BitmapRawDecoder(int width, int height, int bitsPerPixel) : Codec(), - _surface(0), _width(width), _height(height), _bitsPerPixel(bitsPerPixel) { - _surface = new Graphics::Surface(); - _surface->create(_width, _height, getPixelFormat()); + _width(width), _height(height), _bitsPerPixel(bitsPerPixel) { + _surface.create(_width, _height, getPixelFormat()); } BitmapRawDecoder::~BitmapRawDecoder() { - if (_surface) { - _surface->free(); - delete _surface; - } + _surface.free(); } const Graphics::Surface *BitmapRawDecoder::decodeFrame(Common::SeekableReadStream &stream) { @@ -54,7 +50,7 @@ const Graphics::Surface *BitmapRawDecoder::decodeFrame(Common::SeekableReadStrea if (_bitsPerPixel == 1) { for (int i = 0; i < _height; i++) { - byte *dst = (byte *)_surface->getBasePtr(0, i); + byte *dst = (byte *)_surface.getBasePtr(0, i); for (int j = 0; j != _width;) { byte color = stream.readByte(); for (int k = 0; k < 8; k++) { @@ -70,7 +66,7 @@ const Graphics::Surface *BitmapRawDecoder::decodeFrame(Common::SeekableReadStrea } } else if (_bitsPerPixel == 4) { for (int i = 0; i < _height; i++) { - byte *dst = (byte *)_surface->getBasePtr(0, _height - i - 1); + byte *dst = (byte *)_surface.getBasePtr(0, _height - i - 1); for (int j = 0; j < _width; j++) { byte color = stream.readByte(); @@ -86,14 +82,14 @@ const Graphics::Surface *BitmapRawDecoder::decodeFrame(Common::SeekableReadStrea stream.skip(extraDataLength); } } else if (_bitsPerPixel == 8) { - byte *dst = (byte *)_surface->getPixels(); + byte *dst = (byte *)_surface.getPixels(); for (int i = 0; i < _height; i++) { stream.read(dst + (_height - i - 1) * _width, _width); stream.skip(extraDataLength); } } else if (_bitsPerPixel == 24) { - byte *dst = (byte *)_surface->getBasePtr(0, _height - 1); + byte *dst = (byte *)_surface.getBasePtr(0, _height - 1); for (int i = 0; i < _height; i++) { for (int j = 0; j < _width; j++) { @@ -107,10 +103,10 @@ const Graphics::Surface *BitmapRawDecoder::decodeFrame(Common::SeekableReadStrea } stream.skip(extraDataLength); - dst -= _surface->pitch * 2; + dst -= _surface.pitch * 2; } } else { // 32 bpp - byte *dst = (byte *)_surface->getBasePtr(0, _height - 1); + byte *dst = (byte *)_surface.getBasePtr(0, _height - 1); for (int i = 0; i < _height; i++) { for (int j = 0; j < _width; j++) { @@ -128,11 +124,11 @@ const Graphics::Surface *BitmapRawDecoder::decodeFrame(Common::SeekableReadStrea } stream.skip(extraDataLength); - dst -= _surface->pitch * 2; + dst -= _surface.pitch * 2; } } - return _surface; + return &_surface; } Graphics::PixelFormat BitmapRawDecoder::getPixelFormat() const { diff --git a/image/codecs/bmp_raw.h b/image/codecs/bmp_raw.h index 99509a1708..8ec79e7230 100644 --- a/image/codecs/bmp_raw.h +++ b/image/codecs/bmp_raw.h @@ -41,7 +41,7 @@ public: Graphics::PixelFormat getPixelFormat() const; private: - Graphics::Surface *_surface; + Graphics::Surface _surface; int _width, _height; int _bitsPerPixel; }; -- cgit v1.2.3