From d39a9272bf0334e5e98801ba06df89b4f59b79b8 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Thu, 24 Aug 2017 16:41:07 -0500 Subject: IMAGE: Remove unnecessary extra heap allocation of Indeo surface --- image/codecs/indeo/indeo.cpp | 12 +++++------- image/codecs/indeo/indeo.h | 2 +- image/codecs/indeo4.cpp | 24 ++++++++++++------------ image/codecs/indeo5.cpp | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) (limited to 'image/codecs') diff --git a/image/codecs/indeo/indeo.cpp b/image/codecs/indeo/indeo.cpp index f8cd8a1c64..27db365cf0 100644 --- a/image/codecs/indeo/indeo.cpp +++ b/image/codecs/indeo/indeo.cpp @@ -479,15 +479,13 @@ IndeoDecoderBase::IndeoDecoderBase(uint16 width, uint16 height, uint bitsPerPixe break; } - _surface = new Graphics::Surface(); - _surface->create(width, height, _pixelFormat); - _surface->fillRect(Common::Rect(0, 0, width, height), (bitsPerPixel == 32) ? 0xff : 0); + _surface.create(width, height, _pixelFormat); + _surface.fillRect(Common::Rect(0, 0, width, height), (bitsPerPixel == 32) ? 0xff : 0); _ctx._bRefBuf = 3; // buffer 2 is used for scalability mode } IndeoDecoderBase::~IndeoDecoderBase() { - _surface->free(); - delete _surface; + _surface.free(); IVIPlaneDesc::freeBuffers(_ctx._planes); if (_ctx._mbVlc._custTab._table) _ctx._mbVlc._custTab.freeVlc(); @@ -557,7 +555,7 @@ int IndeoDecoderBase::decodeIndeoFrame() { if (!isNonNullFrame()) return 0; - assert(_ctx._planes[0]._width <= _surface->w && _ctx._planes[0]._height <= _surface->h); + assert(_ctx._planes[0]._width <= _surface.w && _ctx._planes[0]._height <= _surface.h); result = frame->setDimensions(_ctx._planes[0]._width, _ctx._planes[0]._height); if (result < 0) return result; @@ -578,7 +576,7 @@ int IndeoDecoderBase::decodeIndeoFrame() { outputPlane(&_ctx._planes[1], frame->_data[2], frame->_linesize[2]); // Merge the planes into the final surface - YUVToRGBMan.convert410(_surface, Graphics::YUVToRGBManager::kScaleITU, + YUVToRGBMan.convert410(&_surface, Graphics::YUVToRGBManager::kScaleITU, frame->_data[0], frame->_data[1], frame->_data[2], frame->_width, frame->_height, frame->_width, frame->_width); diff --git a/image/codecs/indeo/indeo.h b/image/codecs/indeo/indeo.h index 962d06817d..6c2a6b17a2 100644 --- a/image/codecs/indeo/indeo.h +++ b/image/codecs/indeo/indeo.h @@ -519,7 +519,7 @@ private: protected: IVI45DecContext _ctx; Graphics::PixelFormat _pixelFormat; - Graphics::Surface *_surface; + Graphics::Surface _surface; /** * Scan patterns shared between indeo4 and indeo5 diff --git a/image/codecs/indeo4.cpp b/image/codecs/indeo4.cpp index 40f86f8fe2..65aed6a559 100644 --- a/image/codecs/indeo4.cpp +++ b/image/codecs/indeo4.cpp @@ -88,7 +88,7 @@ const Graphics::Surface *Indeo4Decoder::decodeFrame(Common::SeekableReadStream & _ctx._frameData = nullptr; _ctx._frameSize = 0; - return (err < 0) ? nullptr : _surface; + return (err < 0) ? nullptr : &_surface; } int Indeo4Decoder::decodePictureHeader() { @@ -607,16 +607,16 @@ int Indeo4Decoder::decodeRLETransparency(VLC_TYPE (*table)[2]) { const uint32 opacityMask = 0xFF << _pixelFormat.aShift; - uint32 *pixel = (uint32 *)_surface->getPixels(); - const int surfacePixelPitch = _surface->pitch / _surface->format.bytesPerPixel; - const int surfacePadding = surfacePixelPitch - _surface->w; - const uint32 *endOfVisibleRow = pixel + _surface->w; - const uint32 *endOfVisibleArea = pixel + surfacePixelPitch * _surface->h - surfacePadding; + uint32 *pixel = (uint32 *)_surface.getPixels(); + const int surfacePixelPitch = _surface.pitch / _surface.format.bytesPerPixel; + const int surfacePadding = surfacePixelPitch - _surface.w; + const uint32 *endOfVisibleRow = pixel + _surface.w; + const uint32 *endOfVisibleArea = pixel + surfacePixelPitch * _surface.h - surfacePadding; - const int codecAlignedWidth = (_surface->w + 31) & ~31; - const int codecPaddingSize = codecAlignedWidth - _surface->w; + const int codecAlignedWidth = (_surface.w + 31) & ~31; + const int codecPaddingSize = codecAlignedWidth - _surface.w; - int numPixelsToRead = codecAlignedWidth * _surface->h; + int numPixelsToRead = codecAlignedWidth * _surface.h; int numPixelsToSkip = 0; while (numPixelsToRead > 0) { int value = _ctx._gb->getVLC2<1>(table, IVI_VLC_BITS); @@ -774,8 +774,8 @@ int Indeo4Decoder::decodeTransparency() { _surface->convertToInPlace(_pixelFormat); } - assert(_surface->format.bytesPerPixel == 4); - assert((_surface->pitch % 4) == 0); + assert(_surface.format.bytesPerPixel == 4); + assert((_surface.pitch % 4) == 0); const uint32 startByte = _ctx._gb->pos() / 8; @@ -788,7 +788,7 @@ int Indeo4Decoder::decodeTransparency() { // It should only be necessary to draw transparency here since the // data from the YUV planes gets drawn to the output surface on each // frame, which resets the surface pixels to be fully opaque - _surface->fillRect(Common::Rect(_surface->w, _surface->h), 0); + _surface.fillRect(Common::Rect(_surface.w, _surface.h), 0); } // No alignment here diff --git a/image/codecs/indeo5.cpp b/image/codecs/indeo5.cpp index c4e98d4ac7..790bdec87a 100644 --- a/image/codecs/indeo5.cpp +++ b/image/codecs/indeo5.cpp @@ -97,7 +97,7 @@ const Graphics::Surface *Indeo5Decoder::decodeFrame(Common::SeekableReadStream & _ctx._frameData = nullptr; _ctx._frameSize = 0; - return (err < 0) ? nullptr : _surface; + return (err < 0) ? nullptr : &_surface; } int Indeo5Decoder::decodePictureHeader() { -- cgit v1.2.3