aboutsummaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorColin Snover2017-09-24 12:15:22 -0500
committerColin Snover2017-09-24 16:22:40 -0500
commit56cc138e58b70695d83da890ce6a11ff8148043d (patch)
tree4b410cf6eeaeae0adb38b3ceeef09f4965b4a443 /image
parentf806b95eda4aafd936538cba591df4ee23dabc17 (diff)
downloadscummvm-rg350-56cc138e58b70695d83da890ce6a11ff8148043d.tar.gz
scummvm-rg350-56cc138e58b70695d83da890ce6a11ff8148043d.tar.bz2
scummvm-rg350-56cc138e58b70695d83da890ce6a11ff8148043d.zip
IMAGE: Remove unnecessary heap allocation in BitmapRawDecoder
Diffstat (limited to 'image')
-rw-r--r--image/codecs/bmp_raw.cpp26
-rw-r--r--image/codecs/bmp_raw.h2
2 files changed, 12 insertions, 16 deletions
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;
};