diff options
author | Colin Snover | 2017-11-12 13:47:51 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2017-11-18 22:35:12 +0100 |
commit | 0cc0b1932e7feb97b15810ed9748a55a20947763 (patch) | |
tree | 6ad3de78cc2ff5621911d37f679d74206bca0665 /engines/fullpipe | |
parent | 8e0c53de180d2e0de613934f1dedbfd4aa5fdf7c (diff) | |
download | scummvm-rg350-0cc0b1932e7feb97b15810ed9748a55a20947763.tar.gz scummvm-rg350-0cc0b1932e7feb97b15810ed9748a55a20947763.tar.bz2 scummvm-rg350-0cc0b1932e7feb97b15810ed9748a55a20947763.zip |
FULLPIPE: Fix memory leaks, ownership issues, and endianness issues in graphics code
Diffstat (limited to 'engines/fullpipe')
-rw-r--r-- | engines/fullpipe/fullpipe.cpp | 3 | ||||
-rw-r--r-- | engines/fullpipe/fullpipe.h | 4 | ||||
-rw-r--r-- | engines/fullpipe/gfx.cpp | 163 | ||||
-rw-r--r-- | engines/fullpipe/gfx.h | 82 | ||||
-rw-r--r-- | engines/fullpipe/scene.cpp | 17 | ||||
-rw-r--r-- | engines/fullpipe/statics.cpp | 42 |
6 files changed, 148 insertions, 163 deletions
diff --git a/engines/fullpipe/fullpipe.cpp b/engines/fullpipe/fullpipe.cpp index ad9b6a42f6..122b68511c 100644 --- a/engines/fullpipe/fullpipe.cpp +++ b/engines/fullpipe/fullpipe.cpp @@ -76,7 +76,6 @@ FullpipeEngine::FullpipeEngine(OSystem *syst, const ADGameDescription *gameDesc) _pictureScale = 8; _scrollSpeed = 0; _currSoundListCount = 0; - _globalPalette = 0; _updateTicks = 0; _lastInputTicks = 0; @@ -290,6 +289,7 @@ Common::Error FullpipeEngine::run() { _console = new Console(this); initialize(); + _globalPalette = &_defaultPalette; _isSaveAllowed = false; @@ -338,6 +338,7 @@ Common::Error FullpipeEngine::run() { freeGameLoader(); _currentScene = 0; _updateTicks = 0; + _globalPalette = &_defaultPalette; loadGam("fullpipe.gam"); _needRestart = false; diff --git a/engines/fullpipe/fullpipe.h b/engines/fullpipe/fullpipe.h index 0a763816fd..d5aa730e07 100644 --- a/engines/fullpipe/fullpipe.h +++ b/engines/fullpipe/fullpipe.h @@ -83,6 +83,7 @@ class Scene; class SoundList; class StaticANIObject; class Vars; +typedef Common::Array<int32> Palette; int global_messageHandler1(ExCommand *cmd); int global_messageHandler2(ExCommand *cmd); @@ -151,7 +152,8 @@ public: Scene *_scene3; StaticANIObject *_aniMan; StaticANIObject *_aniMan2; - byte *_globalPalette; + Palette _defaultPalette; + const Palette *_globalPalette; InputController *_inputController; bool _inputDisabled; diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp index f227e134d1..75366f5834 100644 --- a/engines/fullpipe/gfx.cpp +++ b/engines/fullpipe/gfx.cpp @@ -41,7 +41,6 @@ Background::Background() { _bigPictureArray1Count = 0; _bigPictureArray2Count = 0; _bigPictureArray = 0; - _palette = 0; } Background::~Background() { @@ -432,35 +431,17 @@ bool GameObject::setPicAniInfo(PicAniInfo *picAniInfo) { return false; } -Picture::Picture() { - _x = 0; - _y = 0; - _field_44 = 0; - _field_54 = 0; - _bitmap = 0; - _alpha = -1; - _paletteData = 0; - _convertedBitmap = 0; - _memoryObject2 = 0; - _width = 0; - _height = 0; -} +Picture::Picture() : + _x(0), + _y(0), + _field_44(0), + _field_54(0), + _alpha(-1), + _width(0), + _height(0) {} Picture::~Picture() { freePicture(); - - _bitmap = 0; - - if (_memoryObject2) - delete _memoryObject2; - - if (_paletteData) - free(_paletteData); - - if (_convertedBitmap) { - delete _convertedBitmap; - _convertedBitmap = 0; - } } void Picture::freePicture() { @@ -469,20 +450,12 @@ void Picture::freePicture() { if (_bitmap) { if (testFlags() && !_field_54) { freeData(); - delete _bitmap; - _bitmap = 0; } + _bitmap.reset(); + _data = nullptr; } - if (_bitmap) { - _bitmap = 0; - _data = 0; - } - - if (_convertedBitmap) { - delete _convertedBitmap; - _convertedBitmap = 0; - } + _convertedBitmap.reset(); } void Picture::freePixelData() { @@ -505,7 +478,7 @@ bool Picture::load(MfcArchive &file) { _mflags |= 1; - _memoryObject2 = new MemoryObject2; + _memoryObject2.reset(new MemoryObject2); _memoryObject2->load(file); if (_memoryObject2->_data) { @@ -519,8 +492,10 @@ bool Picture::load(MfcArchive &file) { int havePal = file.readUint32LE(); if (havePal > 0) { - _paletteData = (byte *)calloc(1024, 1); - file.read(_paletteData, 1024); + _paletteData.reserve(256); + for (int i = 0; i < 256; ++i) { + _paletteData.push_back(file.readUint32LE()); + } } getData(); @@ -549,7 +524,7 @@ void Picture::init() { MemoryObject::getData(); - _bitmap = new Bitmap(); + _bitmap = BitmapPtr(new Bitmap()); getDibInfo(); @@ -583,14 +558,14 @@ void Picture::getDibInfo() { _bitmap->load(s); delete s; - _bitmap->decode(_data, (int32 *)(_paletteData ? _paletteData : g_fp->_globalPalette)); + _bitmap->decode(_data, _paletteData.size() ? _paletteData : *g_fp->_globalPalette); } -Bitmap *Picture::getPixelData() { +const Bitmap *Picture::getPixelData() { if (!_bitmap) init(); - return _bitmap; + return _bitmap.get(); } void Picture::draw(int x, int y, int style, int angle) { @@ -615,9 +590,10 @@ void Picture::draw(int x, int y, int style, int angle) { debugC(7, kDebugDrawing, "Picture:draw: alpha = %0x", _alpha); } - byte *pal = _paletteData; - - if (!pal) { + const Palette *pal; + if (_paletteData.size()) { + pal = &_paletteData; + } else { //warning("Picture:draw: using global palette"); pal = g_fp->_globalPalette; } @@ -626,13 +602,13 @@ void Picture::draw(int x, int y, int style, int angle) { case 1: { //flip const Dims dims = getDimensions(); - _bitmap->flipVertical()->drawShaded(1, x1, y1 + 30 + dims.y, pal, _alpha); + _bitmap->flipVertical()->drawShaded(1, x1, y1 + 30 + dims.y, *pal, _alpha); break; } case 2: //vrtSetFadeRatio(g_vrtDrawHandle, 0.34999999); //vrtSetFadeTable(g_vrtDrawHandle, &unk_477F88, 1.0, 1000.0, 0, 0); - _bitmap->drawShaded(2, x1, y1, pal, _alpha); + _bitmap->drawShaded(2, x1, y1, *pal, _alpha); //vrtSetFadeRatio(g_vrtDrawHandle, 0.0); //vrtSetFadeTable(g_vrtDrawHandle, &unk_477F90, 1.0, 1000.0, 0, 0); break; @@ -640,7 +616,7 @@ void Picture::draw(int x, int y, int style, int angle) { if (angle) drawRotated(x1, y1, angle); else { - _bitmap->putDib(x1, y1, (int32 *)pal, _alpha); + _bitmap->putDib(x1, y1, *pal, _alpha); } } } @@ -680,13 +656,11 @@ void Picture::displayPicture() { } } -void Picture::setPaletteData(byte *pal) { - if (_paletteData) - free(_paletteData); - - if (pal) { - _paletteData = (byte *)malloc(1024); - memcpy(_paletteData, pal, 1024); +void Picture::setPaletteData(const Palette &pal) { + if (pal.size()) { + _paletteData = pal; + } else { + _paletteData.clear(); } } @@ -750,29 +724,26 @@ Bitmap::Bitmap() { _type = 0; _dataSize = 0; _flags = 0; - _surface = 0; _flipping = Graphics::FLIP_NONE; - _copied_surface = false; } -Bitmap::Bitmap(Bitmap *src) { - _x = src->_x; - _y = src->_y; - _flags = src->_flags; - _dataSize = src->_dataSize; - _type = src->_type; - _width = src->_width; - _height = src->_height; - _surface = new Graphics::TransparentSurface(*src->_surface); - _copied_surface = true; - _flipping = src->_flipping; +Bitmap::Bitmap(const Bitmap &src) { + _x = src._x; + _y = src._y; + _flags = src._flags; + _dataSize = src._dataSize; + _type = src._type; + _width = src._width; + _height = src._height; + _surface = TransSurfacePtr(src._surface); + _flipping = src._flipping; } Bitmap::~Bitmap() { - if (!_copied_surface) + // TODO: This is a hack because Graphics::Surface has terrible resource + // management + if (_surface.unique()) _surface->free(); - delete _surface; - _surface = 0; } void Bitmap::load(Common::ReadStream *s) { @@ -801,8 +772,8 @@ bool Bitmap::isPixelHitAtPos(int x, int y) { return ((*((int32 *)_surface->getBasePtr(x - _x, y - _y)) & 0xff) != 0); } -void Bitmap::decode(byte *pixels, int32 *palette) { - _surface = new Graphics::TransparentSurface; +void Bitmap::decode(byte *pixels, const Palette &palette) { + _surface = TransSurfacePtr(new Graphics::TransparentSurface); _surface->create(_width, _height, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)); @@ -812,7 +783,7 @@ void Bitmap::decode(byte *pixels, int32 *palette) { putDibCB(pixels, palette); } -void Bitmap::putDib(int x, int y, int32 *palette, byte alpha) { +void Bitmap::putDib(int x, int y, const Palette &palette, byte alpha) { debugC(7, kDebugDrawing, "Bitmap::putDib(%d, %d)", x, y); int x1 = x - g_fp->_sceneRect.left; @@ -841,7 +812,7 @@ void Bitmap::putDib(int x, int y, int32 *palette, byte alpha) { g_fp->_system->copyRectToScreen(g_fp->_backgroundSurface->getBasePtr(x1, y1), g_fp->_backgroundSurface->pitch, x1, y1, sub.width(), sub.height()); } -bool Bitmap::putDibRB(byte *pixels, int32 *palette) { +bool Bitmap::putDibRB(byte *pixels, const Palette &palette) { uint32 *curDestPtr; int endy; int x; @@ -852,7 +823,7 @@ bool Bitmap::putDibRB(byte *pixels, int32 *palette) { uint16 *srcPtr2; uint16 *srcPtr; - if (!palette) { + if (!palette.size()) { debugC(2, kDebugDrawing, "Bitmap::putDibRB(): Both global and local palettes are empty"); return false; } @@ -934,7 +905,7 @@ bool Bitmap::putDibRB(byte *pixels, int32 *palette) { if (y <= endy) { curDestPtr = (uint32 *)_surface->getBasePtr(start1, y); - paletteFill(curDestPtr, (byte *)srcPtr2, fillLen, (int32 *)palette); + paletteFill(curDestPtr, (byte *)srcPtr2, fillLen, palette); } } } @@ -943,7 +914,7 @@ bool Bitmap::putDibRB(byte *pixels, int32 *palette) { return false; } -void Bitmap::putDibCB(byte *pixels, int32 *palette) { +void Bitmap::putDibCB(byte *pixels, const Palette &palette) { uint32 *curDestPtr; int endx; int endy; @@ -956,7 +927,7 @@ void Bitmap::putDibCB(byte *pixels, int32 *palette) { cb05_format = (_type == MKTAG('C', 'B', '\05', 'e')); - if (!palette && !cb05_format) + if (!palette.size() && !cb05_format) error("Bitmap::putDibCB(): Both global and local palettes are empty"); bpp = cb05_format ? 2 : 1; @@ -973,12 +944,12 @@ void Bitmap::putDibCB(byte *pixels, int32 *palette) { if (_flags & 0x1000000) { for (int y = starty; y <= endy; srcPtr -= pitch, y++) { curDestPtr = (uint32 *)_surface->getBasePtr(startx, y); - copierKeyColor(curDestPtr, srcPtr, endx - startx + 1, _flags & 0xff, (int32 *)palette, cb05_format); + copierKeyColor(curDestPtr, srcPtr, endx - startx + 1, _flags & 0xff, palette, cb05_format); } } else { for (int y = starty; y <= endy; srcPtr -= pitch, y++) { curDestPtr = (uint32 *)_surface->getBasePtr(startx, y); - copier(curDestPtr, srcPtr, endx - startx + 1, (int32 *)palette, cb05_format); + copier(curDestPtr, srcPtr, endx - startx + 1, palette, cb05_format); } } } @@ -1004,7 +975,7 @@ void Bitmap::colorFill(uint32 *dest, int len, int32 color) { *dest++ = c; } -void Bitmap::paletteFill(uint32 *dest, byte *src, int len, int32 *palette) { +void Bitmap::paletteFill(uint32 *dest, byte *src, int len, const Palette &palette) { #if 0 if (blendMode) { if (blendMode != 1) @@ -1025,7 +996,7 @@ void Bitmap::paletteFill(uint32 *dest, byte *src, int len, int32 *palette) { } } -void Bitmap::copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, int32 *palette, bool cb05_format) { +void Bitmap::copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, const Palette &palette, bool cb05_format) { #if 0 if (blendMode) { if (blendMode == 1) { @@ -1070,7 +1041,7 @@ void Bitmap::copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, int3 } } -void Bitmap::copier(uint32 *dest, byte *src, int len, int32 *palette, bool cb05_format) { +void Bitmap::copier(uint32 *dest, byte *src, int len, const Palette &palette, bool cb05_format) { #if 0 if (blendMode) { if (blendMode == 1) { @@ -1106,8 +1077,8 @@ void Bitmap::copier(uint32 *dest, byte *src, int len, int32 *palette, bool cb05_ } } -Bitmap *Bitmap::reverseImage(bool flip) { - Bitmap *b = new Bitmap(this); +Bitmap *Bitmap::reverseImage(bool flip) const { + Bitmap *b = new Bitmap(*this); if (flip) b->_flipping ^= Graphics::FLIP_H; @@ -1115,25 +1086,25 @@ Bitmap *Bitmap::reverseImage(bool flip) { return b; } -Bitmap *Bitmap::flipVertical() { - Bitmap *b = new Bitmap(this); +Bitmap *Bitmap::flipVertical() const { + Bitmap *b = new Bitmap(*this); b->_flipping ^= Graphics::FLIP_V; return b; } -void Bitmap::drawShaded(int type, int x, int y, byte *palette, int alpha) { +void Bitmap::drawShaded(int type, int x, int y, const Palette &palette, int alpha) { if (alpha != 255) warning("STUB: Bitmap::drawShaded(%d, %d, %d, %d)", type, x, y, alpha); - putDib(x, y, (int32 *)palette, alpha); + putDib(x, y, palette, alpha); } -void Bitmap::drawRotated(int x, int y, int angle, byte *palette, int alpha) { +void Bitmap::drawRotated(int x, int y, int angle, const Palette &palette, int alpha) { warning("STUB: Bitmap::drawRotated(%d, %d, %d, %d)", x, y, angle, alpha); - putDib(x, y, (int32 *)palette, alpha); + putDib(x, y, palette, alpha); } bool BigPicture::load(MfcArchive &file) { @@ -1159,7 +1130,7 @@ void BigPicture::draw(int x, int y, int style, int angle) { if (y != -1) ny = y; - _bitmap->putDib(nx, ny, 0, _alpha); + _bitmap->putDib(nx, ny, Palette(), _alpha); } } diff --git a/engines/fullpipe/gfx.h b/engines/fullpipe/gfx.h index 41214eef1b..b92e94b79d 100644 --- a/engines/fullpipe/gfx.h +++ b/engines/fullpipe/gfx.h @@ -23,6 +23,8 @@ #ifndef FULLPIPE_GFX_H #define FULLPIPE_GFX_H +#include "common/ptr.h" + namespace Graphics { struct Surface; struct TransparentSurface; @@ -34,8 +36,11 @@ class DynamicPhase; class Movement; struct PicAniInfo; +typedef Common::Array<int32> Palette; typedef Common::Point Dims; +typedef Common::SharedPtr<Graphics::TransparentSurface> TransSurfacePtr; + struct Bitmap { int _x; int _y; @@ -44,52 +49,42 @@ struct Bitmap { int _type; int _dataSize; int _flags; - Graphics::TransparentSurface *_surface; int _flipping; - bool _copied_surface; + TransSurfacePtr _surface; Bitmap(); - Bitmap(Bitmap *src); + Bitmap(const Bitmap &src); ~Bitmap(); void load(Common::ReadStream *s); - void decode(byte *pixels, int32 *palette); - void putDib(int x, int y, int32 *palette, byte alpha); - bool putDibRB(byte *pixels, int32 *palette); - void putDibCB(byte *pixels, int32 *palette); + void decode(byte *pixels, const Palette &palette); + void putDib(int x, int y, const Palette &palette, byte alpha); + bool putDibRB(byte *pixels, const Palette &palette); + void putDibCB(byte *pixels, const Palette &palette); void colorFill(uint32 *dest, int len, int32 color); - void paletteFill(uint32 *dest, byte *src, int len, int32 *palette); - void copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, int32 *palette, bool cb05_format); - void copier(uint32 *dest, byte *src, int len, int32 *palette, bool cb05_format); + void paletteFill(uint32 *dest, byte *src, int len, const Palette &palette); + void copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, const Palette &palette, bool cb05_format); + void copier(uint32 *dest, byte *src, int len, const Palette &palette, bool cb05_format); - Bitmap *reverseImage(bool flip = true); - Bitmap *flipVertical(); + /** ownership of returned object is transferred to caller */ + Bitmap *reverseImage(bool flip = true) const; + /** ownership of returned object is transferred to caller */ + Bitmap *flipVertical() const; - void drawShaded(int type, int x, int y, byte *palette, int alpha); - void drawRotated(int x, int y, int angle, byte *palette, int alpha); + void drawShaded(int type, int x, int y, const Palette &palette, int alpha); + void drawRotated(int x, int y, int angle, const Palette &palette, int alpha); bool isPixelHitAtPos(int x, int y); -}; -class Picture : public MemoryObject { - public: - Common::Rect _rect; - Bitmap *_convertedBitmap; - int _x; - int _y; - int _field_44; - int _width; - int _height; - Bitmap *_bitmap; - int _field_54; - MemoryObject2 *_memoryObject2; - int _alpha; - byte *_paletteData; +private: + Bitmap operator=(const Bitmap &); +}; - void displayPicture(); +typedef Common::SharedPtr<Bitmap> BitmapPtr; - public: +class Picture : public MemoryObject { +public: Picture(); virtual ~Picture(); @@ -100,7 +95,7 @@ class Picture : public MemoryObject { void setAOIDs(); virtual void init(); void getDibInfo(); - Bitmap *getPixelData(); + const Bitmap *getPixelData(); virtual void draw(int x, int y, int style, int angle); void drawRotated(int x, int y, int angle); @@ -113,10 +108,27 @@ class Picture : public MemoryObject { int getPixelAtPos(int x, int y); int getPixelAtPosEx(int x, int y); - byte *getPaletteData() { return _paletteData; } - void setPaletteData(byte *pal); + const Bitmap *getConvertedBitmap() const { return _convertedBitmap.get(); } + const Palette &getPaletteData() const { return _paletteData; } + void setPaletteData(const Palette &pal); void copyMemoryObject2(Picture *src); + + int _x, _y; + +protected: + Common::Rect _rect; + Common::ScopedPtr<Bitmap> _convertedBitmap; + int _field_44; + int _width; + int _height; + BitmapPtr _bitmap; + int _field_54; + Common::ScopedPtr<MemoryObject2> _memoryObject2; + int _alpha; + Palette _paletteData; + + void displayPicture(); }; class BigPicture : public Picture { @@ -191,7 +203,7 @@ class Background : public CObject { int _x; int _y; int16 _messageQueueId; - MemoryObject *_palette; + Palette _palette; int _bigPictureArray1Count; int _bigPictureArray2Count; BigPicture ***_bigPictureArray; diff --git a/engines/fullpipe/scene.cpp b/engines/fullpipe/scene.cpp index 5e92c5f1eb..ee0e5e5c1f 100644 --- a/engines/fullpipe/scene.cpp +++ b/engines/fullpipe/scene.cpp @@ -129,7 +129,6 @@ Scene::Scene() { Scene::~Scene() { delete _soundList; delete _shadows; - delete _palette; // _faObjlist is not used @@ -216,10 +215,16 @@ bool Scene::load(MfcArchive &file) { Common::strlcpy(fname, _bgname.c_str(), 260); Common::strlcpy(strrchr(fname, '.') + 1, "col", 260); - MemoryObject *col = new MemoryObject(); + Common::ScopedPtr<MemoryObject> col(new MemoryObject()); col->loadFile(fname); - - _palette = col; + if (col->getDataSize()) { + assert(col->getDataSize() == 256 * sizeof(uint32)); + const byte *data = col->getData(); + for (int i = 0; i < 256; ++i) { + _palette.push_back(READ_LE_UINT32(data)); + data += sizeof(uint32); + } + } } Common::String shdname = genFileName(0, _sceneId, "shd"); @@ -670,8 +675,8 @@ void Scene::drawContent(int minPri, int maxPri, bool drawBg) { if (!_picObjList.size() && !_bigPictureArray1Count) return; - if (_palette) { - g_fp->_globalPalette = _palette->_data; + if (_palette.size()) { + g_fp->_globalPalette = &_palette; } debugC(1, kDebugDrawing, "Scene::drawContent(>%d, <%d, %d)", minPri, maxPri, drawBg); diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp index a78131d29d..6b7dbbb913 100644 --- a/engines/fullpipe/statics.cpp +++ b/engines/fullpipe/statics.cpp @@ -528,41 +528,41 @@ void Movement::draw(bool flipFlag, int angle) { int x = _ox - point.x; int y = _oy - point.y; - if (_currDynamicPhase->getPaletteData()) - g_fp->_globalPalette = _currDynamicPhase->getPaletteData(); + if (_currDynamicPhase->getPaletteData().size()) + g_fp->_globalPalette = &_currDynamicPhase->getPaletteData(); - Bitmap *bmp; + Common::ScopedPtr<Bitmap> bmp; if (_currMovement) { - bmp = _currDynamicPhase->getPixelData()->reverseImage(); + bmp.reset(_currDynamicPhase->getPixelData()->reverseImage()); } else { - bmp = _currDynamicPhase->getPixelData()->reverseImage(false); + bmp.reset(_currDynamicPhase->getPixelData()->reverseImage(false)); } if (flipFlag) { - bmp->flipVertical()->drawShaded(1, x, y + 30 + _currDynamicPhase->_rect->bottom, _currDynamicPhase->_paletteData, _currDynamicPhase->_alpha); + bmp->flipVertical()->drawShaded(1, x, y + 30 + _currDynamicPhase->_rect->bottom, _currDynamicPhase->getPaletteData(), _currDynamicPhase->getAlpha()); } else if (angle) { - bmp->drawRotated(x, y, angle, _currDynamicPhase->_paletteData, _currDynamicPhase->_alpha); + bmp->drawRotated(x, y, angle, _currDynamicPhase->getPaletteData(), _currDynamicPhase->getAlpha()); } else { - bmp->putDib(x, y, (int32 *)_currDynamicPhase->_paletteData, _currDynamicPhase->_alpha); + bmp->putDib(x, y, _currDynamicPhase->getPaletteData(), _currDynamicPhase->getAlpha()); } - //Prevent memory leak after new was used to create bmp in reverseImage() - delete bmp; if (_currDynamicPhase->_rect->top) { - if (!_currDynamicPhase->_convertedBitmap) { + if (!_currDynamicPhase->getConvertedBitmap()) { //v12 = Picture_getPixelData(v5); //v13 = Bitmap_convertTo16Bit565(v12, (unsigned int *)&_currDynamicPhase->rect); //_currDynamicPhase->convertedBitmap = v13; } - if (_currDynamicPhase->_convertedBitmap) { + if (_currDynamicPhase->getConvertedBitmap()) { if (_currMovement) { //vrtSetAlphaBlendMode(g_vrtDrawHandle, 1, LOBYTE(_currDynamicPhase->rect.top)); - _currDynamicPhase->_convertedBitmap->reverseImage()->putDib(x, y, (int32 *)_currDynamicPhase->_paletteData, _currDynamicPhase->_alpha); + bmp.reset(_currDynamicPhase->getConvertedBitmap()->reverseImage()); + bmp->putDib(x, y, _currDynamicPhase->getPaletteData(), _currDynamicPhase->getAlpha()); //vrtSetAlphaBlendMode(g_vrtDrawHandle, 0, 255); } else { //vrtSetAlphaBlendMode(g_vrtDrawHandle, 1, LOBYTE(_currDynamicPhase->rect.top)); - _currDynamicPhase->_convertedBitmap->reverseImage(false)->putDib(x, y, (int32 *)_currDynamicPhase->_paletteData, _currDynamicPhase->_alpha); + bmp.reset(_currDynamicPhase->getConvertedBitmap()->reverseImage(false)); + bmp->putDib(x, y, _currDynamicPhase->getPaletteData(), _currDynamicPhase->getAlpha()); //vrtSetAlphaBlendMode(g_vrtDrawHandle, 0, 255); } } @@ -1441,11 +1441,7 @@ void Statics::init() { Picture::init(); if (_staticsId & 0x4000) { - Bitmap *reversed = _bitmap->reverseImage(); - // TODO: properly dispose old _bitmap - // Enabling the call below causes corruption in flipped bitmaps - //freePixelData(); - _bitmap = reversed; + _bitmap = BitmapPtr(_bitmap->reverseImage()); } } @@ -2166,7 +2162,7 @@ DynamicPhase::DynamicPhase(DynamicPhase *src, bool reverse) { if (!src->_bitmap) src->init(); - _bitmap = src->_bitmap->reverseImage(); + _bitmap = BitmapPtr(src->_bitmap->reverseImage()); _dataSize = src->_dataSize; if (g_fp->_currArchive) { @@ -2188,11 +2184,9 @@ DynamicPhase::DynamicPhase(DynamicPhase *src, bool reverse) { _mfield_10 = src->_mfield_10; _libHandle = src->_libHandle; - _bitmap = src->_bitmap; - if (_bitmap) { + if (src->_bitmap) { _field_54 = 1; - - _bitmap = src->_bitmap->reverseImage(false); + _bitmap = BitmapPtr(src->_bitmap->reverseImage(false)); } _someX = src->_someX; |