From 405c523bbb199919ef172e4cb549625b319e6b2d Mon Sep 17 00:00:00 2001 From: Andrew Kurushin Date: Sat, 23 Oct 2010 21:56:16 +0000 Subject: SAGA: replace decodeBGImage malloc with ByteArray svn-id: r53748 --- engines/saga/animation.cpp | 8 +++---- engines/saga/events.cpp | 11 ++++------ engines/saga/gfx.cpp | 10 ++++----- engines/saga/image.cpp | 53 +++++++++++++++++++------------------------- engines/saga/interface.cpp | 55 +++++++++++++++++----------------------------- engines/saga/interface.h | 5 +---- engines/saga/saga.h | 9 ++++---- engines/saga/scene.cpp | 34 ++++++++++++---------------- engines/saga/scene.h | 14 +++++++----- engines/saga/sprite.cpp | 3 +-- 10 files changed, 81 insertions(+), 121 deletions(-) diff --git a/engines/saga/animation.cpp b/engines/saga/animation.cpp index 198a52c1f3..abefba92c6 100644 --- a/engines/saga/animation.cpp +++ b/engines/saga/animation.cpp @@ -331,20 +331,19 @@ void Anim::showCutawayBg(int bg) { byte *resourceData; size_t resourceDataLength; - byte *buf; - size_t buflen; + ByteArray image; int width; int height; Event event; static PalEntry pal[PAL_ENTRIES]; _vm->_resource->loadResource(context, bg, resourceData, resourceDataLength); - _vm->decodeBGImage(resourceData, resourceDataLength, &buf, &buflen, &width, &height); + _vm->decodeBGImage(resourceData, resourceDataLength, image, &width, &height); const byte *palPointer = _vm->getImagePal(resourceData, resourceDataLength); memcpy(pal, palPointer, sizeof(pal)); const Rect rect(width, height); - _vm->_render->getBackGroundSurface()->blit(rect, buf); + _vm->_render->getBackGroundSurface()->blit(rect, image.getBuffer()); _vm->_render->setFullRefresh(true); _vm->_frameCount++; @@ -361,7 +360,6 @@ void Anim::showCutawayBg(int bg) { _vm->_gfx->setPalette(pal); } - free(buf); free(resourceData); } diff --git a/engines/saga/events.cpp b/engines/saga/events.cpp index 1f4091d07c..057c602608 100644 --- a/engines/saga/events.cpp +++ b/engines/saga/events.cpp @@ -177,9 +177,8 @@ int Events::handleContinuous(Event *event) { // set flag of Dissolve to 1. It is a hack to simulate zero masking. int w, h; byte *maskBuffer; - size_t len; - _vm->_scene->getBGMaskInfo(w, h, maskBuffer, len); + _vm->_scene->getBGMaskInfo(w, h, maskBuffer); rect.left = (_vm->getDisplayInfo().width - w) / 2; rect.top = (_vm->getDisplayInfo().height - h) / 2; rect.setWidth(w); @@ -367,24 +366,22 @@ int Events::handleOneShot(Event *event) { _vm->_resource->loadResource(context, _vm->getResourceDescription()->psychicProfileResourceId, resourceData, resourceDataLength); - byte *buf; - size_t buflen; + ByteArray image; int width; int height; - _vm->decodeBGImage(resourceData, resourceDataLength, &buf, &buflen, &width, &height); + _vm->decodeBGImage(resourceData, resourceDataLength, image, &width, &height); const PalEntry *palette = (const PalEntry *)_vm->getImagePal(resourceData, resourceDataLength); const Rect profileRect(width, height); - _vm->_render->getBackGroundSurface()->blit(profileRect, buf); + _vm->_render->getBackGroundSurface()->blit(profileRect, image.getBuffer()); _vm->_render->addDirtyRect(profileRect); _vm->_frameCount++; _vm->_gfx->setPalette(palette); - free(buf); free(resourceData); // Draw the scene. It won't be drawn by Render::drawScene(), as a placard is up diff --git a/engines/saga/gfx.cpp b/engines/saga/gfx.cpp index e698a3b1bd..a06179634b 100644 --- a/engines/saga/gfx.cpp +++ b/engines/saga/gfx.cpp @@ -506,8 +506,7 @@ void Gfx::setCursor(CursorType cursorType) { byte *resource; size_t resourceLength; - byte *image; - size_t imageLength; + ByteArray image; int width, height; if (resourceId != (uint32)-1) { @@ -515,11 +514,11 @@ void Gfx::setCursor(CursorType cursorType) { _vm->_resource->loadResource(context, resourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &image, &imageLength, &width, &height); + _vm->decodeBGImage(resource, resourceLength, image, &width, &height); } else { resource = NULL; width = height = 31; - image = (byte *)calloc(width, height); + image.resize(width * height); for (int i = 0; i < 14; i++) { image[15 * 31 + i] = 1; @@ -530,9 +529,8 @@ void Gfx::setCursor(CursorType cursorType) { } // Note: Hard-coded hotspot - CursorMan.replaceCursor(image, width, height, 15, 15, 0); + CursorMan.replaceCursor(image.getBuffer(), width, height, 15, 15, 0); - free(image); free(resource); } } diff --git a/engines/saga/image.cpp b/engines/saga/image.cpp index 50aac48771..5383e6deca 100644 --- a/engines/saga/image.cpp +++ b/engines/saga/image.cpp @@ -47,8 +47,7 @@ static int granulate(int value, int granularity) { } } -int SagaEngine::decodeBGImage(const byte *image_data, size_t image_size, - byte **output_buf, size_t *output_buf_len, int *w, int *h, bool flip) { +bool SagaEngine::decodeBGImage(const byte *image_data, size_t image_size, ByteArray &outputBuffer, int *w, int *h, bool flip) { ImageHeader hdr; int modex_height; const byte *RLE_data_ptr; @@ -76,31 +75,26 @@ int SagaEngine::decodeBGImage(const byte *image_data, size_t image_size, decodeBuffer.resize(hdr.width * modex_height); - out_buf_len = hdr.width * hdr.height; - out_buf = (byte *)malloc(out_buf_len); + outputBuffer.resize(hdr.width * hdr.height); - if (decodeBGImageRLE(RLE_data_ptr, RLE_data_len, decodeBuffer) != SUCCESS) { - free(out_buf); - return FAILURE; + if (!decodeBGImageRLE(RLE_data_ptr, RLE_data_len, decodeBuffer)) { + return false; } - unbankBGImage(out_buf, decodeBuffer.getBuffer(), hdr.width, hdr.height); + unbankBGImage(outputBuffer.getBuffer(), decodeBuffer.getBuffer(), hdr.width, hdr.height); // For some reason bg images in IHNM are upside down if (getGameId() == GID_IHNM && !flip) { flipImage(out_buf, hdr.width, hdr.height); } - *output_buf_len = out_buf_len; - *output_buf = out_buf; - *w = hdr.width; *h = hdr.height; - return SUCCESS; + return true; } -int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray &outbuf) { +bool SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray &outbuf) { const byte *inbuf_ptr; byte *outbuf_ptr; byte *outbuf_start; @@ -140,7 +134,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray while ((inbuf_remain > 1) && (outbuf_remain > 0) && !decode_err) { if ((inbuf_ptr > inbuf_end) || (outbuf_ptr > outbuf_end)) { - return FAILURE; + return false; } mark_byte = *inbuf_ptr++; @@ -153,7 +147,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray // Uncompressed run follows: Max runlength 63 runcount = mark_byte & 0x3f; if ((inbuf_remain < runcount) || (outbuf_remain < runcount)) { - return FAILURE; + return false; } for (c = 0; c < runcount; c++) { @@ -168,7 +162,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray // Compressed run follows: Max runlength 63 runcount = (mark_byte & 0x3f) + 3; if (!inbuf_remain || (outbuf_remain < runcount)) { - return FAILURE; + return false; } for (c = 0; c < runcount; c++) { @@ -190,7 +184,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray backtrack_amount = *inbuf_ptr; if (!inbuf_remain || (backtrack_amount > (outbuf_ptr - outbuf_start)) || (runcount > outbuf_remain)) { - return FAILURE; + return false; } inbuf_ptr++; @@ -219,7 +213,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray runcount = (mark_byte & 0x0F) + 1; if ((inbuf_remain < (runcount + 2)) || (outbuf_remain < (runcount * 8))) { - return FAILURE; + return false; } bitfield_byte1 = *inbuf_ptr++; @@ -247,7 +241,7 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray // Uncompressed run follows runcount = ((mark_byte & 0x0F) << 8) + *inbuf_ptr; if ((inbuf_remain < (runcount + 1)) || (outbuf_remain < runcount)) { - return FAILURE; + return false; } inbuf_ptr++; @@ -266,14 +260,14 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray // Repeat decoded sequence from output stream backtrack_amount = ((mark_byte & 0x0F) << 8) + *inbuf_ptr; if (inbuf_remain < 2) { - return FAILURE; + return false; } inbuf_ptr++; runcount = *inbuf_ptr++; if ((backtrack_amount > (outbuf_ptr - outbuf_start)) || (outbuf_remain < runcount)) { - return FAILURE; + return false; } backtrack_ptr = outbuf_ptr - backtrack_amount; @@ -287,14 +281,14 @@ int SagaEngine::decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray continue; break; default: - return FAILURE; + return false; } } - return SUCCESS; + return true; } -int SagaEngine::flipImage(byte *img_buf, int columns, int scanlines) { +void SagaEngine::flipImage(byte *imageBuffer, int columns, int scanlines) { int line; ByteArray tmp_scan; @@ -307,11 +301,11 @@ int SagaEngine::flipImage(byte *img_buf, int columns, int scanlines) { tmp_scan.resize(columns); flip_tmp = tmp_scan.getBuffer(); if (flip_tmp == NULL) { - return FAILURE; + return; } - flip_p1 = img_buf; - flip_p2 = img_buf + (columns * (scanlines - 1)); + flip_p1 = imageBuffer; + flip_p2 = imageBuffer + (columns * (scanlines - 1)); for (line = 0; line < flipcount; line++) { memcpy(flip_tmp, flip_p1, columns); @@ -320,11 +314,9 @@ int SagaEngine::flipImage(byte *img_buf, int columns, int scanlines) { flip_p1 += columns; flip_p2 -= columns; } - - return SUCCESS; } -int SagaEngine::unbankBGImage(byte *dst_buf, const byte *src_buf, int columns, int scanlines) { +void SagaEngine::unbankBGImage(byte *dst_buf, const byte *src_buf, int columns, int scanlines) { int x, y; int temp; int quadruple_rows; @@ -419,7 +411,6 @@ int SagaEngine::unbankBGImage(byte *dst_buf, const byte *src_buf, int columns, i default: break; } - return SUCCESS; } const byte *SagaEngine::getImagePal(const byte *image_data, size_t image_size) { diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp index cb879f5ed2..7916693100 100644 --- a/engines/saga/interface.cpp +++ b/engines/saga/interface.cpp @@ -171,8 +171,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { } _vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->mainPanelResourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &_mainPanel.image, - &_mainPanel.imageLength, &_mainPanel.imageWidth, &_mainPanel.imageHeight); + _vm->decodeBGImage(resource, resourceLength, _mainPanel.image, &_mainPanel.imageWidth, &_mainPanel.imageHeight); free(resource); @@ -181,8 +180,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { _conversePanel.buttonsCount = _vm->getDisplayInfo().conversePanelButtonsCount; _vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->conversePanelResourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &_conversePanel.image, - &_conversePanel.imageLength, &_conversePanel.imageWidth, &_conversePanel.imageHeight); + _vm->decodeBGImage(resource, resourceLength, _conversePanel.image, &_conversePanel.imageWidth, &_conversePanel.imageHeight); free(resource); // Option panel @@ -191,8 +189,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { _optionPanel.buttonsCount = _vm->getDisplayInfo().optionPanelButtonsCount; _vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->optionPanelResourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &_optionPanel.image, - &_optionPanel.imageLength, &_optionPanel.imageWidth, &_optionPanel.imageHeight); + _vm->decodeBGImage(resource, resourceLength, _optionPanel.image, &_optionPanel.imageWidth, &_optionPanel.imageHeight); free(resource); } else { _optionPanel.buttons = NULL; @@ -207,8 +204,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { _quitPanel.buttonsCount = _vm->getDisplayInfo().quitPanelButtonsCount; _vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->warningPanelResourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &_quitPanel.image, - &_quitPanel.imageLength, &_quitPanel.imageWidth, &_quitPanel.imageHeight); + _vm->decodeBGImage(resource, resourceLength, _quitPanel.image, &_quitPanel.imageWidth, &_quitPanel.imageHeight); free(resource); } @@ -218,8 +214,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { _savePanel.buttonsCount = _vm->getDisplayInfo().savePanelButtonsCount; _vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->warningPanelResourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &_savePanel.image, - &_savePanel.imageLength, &_savePanel.imageWidth, &_savePanel.imageHeight); + _vm->decodeBGImage(resource, resourceLength, _savePanel.image, &_savePanel.imageWidth, &_savePanel.imageHeight); free(resource); } @@ -229,8 +224,7 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { _loadPanel.buttonsCount = _vm->getDisplayInfo().loadPanelButtonsCount; _vm->_resource->loadResource(_interfaceContext, _vm->getResourceDescription()->warningPanelResourceId, resource, resourceLength); - _vm->decodeBGImage(resource, resourceLength, &_loadPanel.image, - &_loadPanel.imageLength, &_loadPanel.imageWidth, &_loadPanel.imageHeight); + _vm->decodeBGImage(resource, resourceLength, _loadPanel.image, &_loadPanel.imageWidth, &_loadPanel.imageHeight); free(resource); } #endif @@ -346,13 +340,6 @@ Interface::Interface(SagaEngine *vm) : _vm(vm) { Interface::~Interface() { free(_inventory); - - free(_mainPanel.image); - free(_conversePanel.image); - free(_optionPanel.image); - free(_quitPanel.image); - free(_loadPanel.image); - free(_savePanel.image); } void Interface::saveReminderCallback(void *refCon) { @@ -806,7 +793,7 @@ void Interface::draw() { if (_panelMode == kPanelMain || _panelMode == kPanelMap || (_panelMode == kPanelNull && _vm->isIHNMDemo())) { _mainPanel.getRect(rect); - _vm->_gfx->drawRegion(rect, _mainPanel.image); + _vm->_gfx->drawRegion(rect, _mainPanel.image.getBuffer()); for (int i = 0; i < kVerbTypeIdsMax; i++) { if (_verbTypeToPanelButton[i] != NULL) { @@ -815,7 +802,7 @@ void Interface::draw() { } } else if (_panelMode == kPanelConverse) { _conversePanel.getRect(rect); - _vm->_gfx->drawRegion(rect, _conversePanel.image); + _vm->_gfx->drawRegion(rect, _conversePanel.image.getBuffer()); converseDisplayTextLines(); } @@ -949,7 +936,7 @@ void Interface::drawOption() { int spritenum = 0; _optionPanel.getRect(rect); - _vm->_gfx->drawRegion(rect, _optionPanel.image); + _vm->_gfx->drawRegion(rect, _optionPanel.image.getBuffer()); for (int i = 0; i < _optionPanel.buttonsCount; i++) { panelButton = &_optionPanel.buttons[i]; @@ -1026,7 +1013,7 @@ void Interface::drawQuit() { if (_vm->getGameId() == GID_ITE) drawButtonBox(rect, kButton, false); else - _vm->_gfx->drawRegion(rect, _quitPanel.image); + _vm->_gfx->drawRegion(rect, _quitPanel.image.getBuffer()); for (i = 0; i < _quitPanel.buttonsCount; i++) { panelButton = &_quitPanel.buttons[i]; @@ -1092,7 +1079,7 @@ void Interface::drawLoad() { if (_vm->getGameId() == GID_ITE) drawButtonBox(rect, kButton, false); else - _vm->_gfx->drawRegion(rect, _loadPanel.image); + _vm->_gfx->drawRegion(rect, _loadPanel.image.getBuffer()); for (i = 0; i < _loadPanel.buttonsCount; i++) { panelButton = &_loadPanel.buttons[i]; @@ -1312,7 +1299,7 @@ void Interface::drawSave() { if (_vm->getGameId() == GID_ITE) drawButtonBox(rect, kButton, false); else - _vm->_gfx->drawRegion(rect, _savePanel.image); + _vm->_gfx->drawRegion(rect, _savePanel.image.getBuffer()); for (i = 0; i < _savePanel.buttonsCount; i++) { panelButton = &_savePanel.buttons[i]; @@ -2714,9 +2701,9 @@ void Interface::loadState(Common::InSaveFile *in) { void Interface::mapPanelShow() { int i; byte *resource; - size_t resourceLength, imageLength; + size_t resourceLength; Rect rect; - byte *image; + ByteArray image; int imageWidth, imageHeight; const byte *pal; PalEntry cPal[PAL_ENTRIES]; @@ -2741,7 +2728,7 @@ void Interface::mapPanelShow() { _vm->_render->setFlag(RF_MAP); - _vm->decodeBGImage(resource, resourceLength, &image, &imageLength, &imageWidth, &imageHeight); + _vm->decodeBGImage(resource, resourceLength, image, &imageWidth, &imageHeight); pal = _vm->getImagePal(resource, resourceLength); for (i = 0; i < PAL_ENTRIES; i++) { @@ -2753,7 +2740,7 @@ void Interface::mapPanelShow() { rect.setWidth(imageWidth); rect.setHeight(imageHeight); - _vm->_gfx->drawRegion(rect, image); + _vm->_gfx->drawRegion(rect, image.getBuffer()); // Evil Evil for (i = 0; i < 6 ; i++) { @@ -2763,7 +2750,6 @@ void Interface::mapPanelShow() { } free(resource); - free(image); setSaveReminderState(false); @@ -2821,9 +2807,9 @@ void Interface::keyBoss() { int i; byte *resource; - size_t resourceLength, imageLength; + size_t resourceLength; Rect rect; - byte *image; + ByteArray image; int imageWidth, imageHeight; const byte *pal; PalEntry cPal[PAL_ENTRIES]; @@ -2840,7 +2826,7 @@ void Interface::keyBoss() { _bossMode = _panelMode; setMode(kPanelBoss); - _vm->decodeBGImage(resource, resourceLength, &image, &imageLength, &imageWidth, &imageHeight); + _vm->decodeBGImage(resource, resourceLength, image, &imageWidth, &imageHeight); rect.setWidth(imageWidth); rect.setHeight(imageHeight); @@ -2857,12 +2843,11 @@ void Interface::keyBoss() { cPal[i].blue = 128; } - _vm->_gfx->drawRegion(rect, image); + _vm->_gfx->drawRegion(rect, image.getBuffer()); _vm->_gfx->setPalette(cPal); free(resource); - free(image); } diff --git a/engines/saga/interface.h b/engines/saga/interface.h index f6e147bc3e..942c0f9849 100644 --- a/engines/saga/interface.h +++ b/engines/saga/interface.h @@ -94,8 +94,7 @@ enum FadeModes { struct InterfacePanel { int x; int y; - byte *image; - size_t imageLength; + ByteArray image; int imageWidth; int imageHeight; @@ -106,8 +105,6 @@ struct InterfacePanel { InterfacePanel() { x = y = 0; - image = NULL; - imageLength = 0; imageWidth = imageHeight = 0; currentButton = NULL; buttonsCount = 0; diff --git a/engines/saga/saga.h b/engines/saga/saga.h index 987c286560..74ebe1b23f 100644 --- a/engines/saga/saga.h +++ b/engines/saga/saga.h @@ -547,14 +547,13 @@ public: Common::RandomSource _rnd; private: - int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray &outbuf); - int flipImage(byte *img_buf, int columns, int scanlines); - int unbankBGImage(byte *dest_buf, const byte *src_buf, int columns, int scanlines); + bool decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, ByteArray &outbuf); + void flipImage(byte *imageBuffer, int columns, int scanlines); + void unbankBGImage(byte *dest_buf, const byte *src_buf, int columns, int scanlines); uint32 _previousTicks; public: - int decodeBGImage(const byte *image_data, size_t image_size, - byte **output_buf, size_t *output_buf_len, int *w, int *h, bool flip = false); + bool decodeBGImage(const byte *image_data, size_t image_size, ByteArray &outputBuffer, int *w, int *h, bool flip = false); const byte *getImagePal(const byte *image_data, size_t image_size); void loadStrings(StringsTable &stringsTable, const byte *stringsPointer, size_t stringsLength); diff --git a/engines/saga/scene.cpp b/engines/saga/scene.cpp index f745fbddcc..0438b5d6c0 100644 --- a/engines/saga/scene.cpp +++ b/engines/saga/scene.cpp @@ -220,8 +220,6 @@ Scene::Scene(SagaEngine *vm) : _vm(vm) { _sceneProc = NULL; _objectMap = new ObjectMap(_vm); _actionMap = new ObjectMap(_vm); - memset(&_bg, 0, sizeof(_bg)); - memset(&_bgMask, 0, sizeof(_bgMask)); } Scene::~Scene() { @@ -523,8 +521,7 @@ void Scene::getSlopes(int &beginSlope, int &endSlope) { } void Scene::getBGInfo(BGInfo &bgInfo) { - bgInfo.buffer = _bg.buf; - bgInfo.bufferLength = _bg.buf_len; + bgInfo.buffer = _bg.buffer.getBuffer(); bgInfo.bounds.left = 0; bgInfo.bounds.top = 0; @@ -576,15 +573,14 @@ bool Scene::offscreenPath(Point &testPoint) { } -void Scene::getBGMaskInfo(int &width, int &height, byte *&buffer, size_t &bufferLength) { +void Scene::getBGMaskInfo(int &width, int &height, byte *&buffer) { if (!_bgMask.loaded) { error("Scene::getBGMaskInfo _bgMask not loaded"); } width = _bgMask.w; height = _bgMask.h; - buffer = _bgMask.buf; - bufferLength = _bgMask.buf_len; + buffer = _bgMask.buffer.getBuffer(); } void Scene::initDoorsState() { @@ -1024,14 +1020,13 @@ void Scene::processSceneResources() { debug(3, "Loading background resource."); _bg.res_buf = resourceData; _bg.res_len = resourceDataLength; - _bg.loaded = 1; + _bg.loaded = true; - if (_vm->decodeBGImage(_bg.res_buf, + if (!_vm->decodeBGImage(_bg.res_buf, _bg.res_len, - &_bg.buf, - &_bg.buf_len, + _bg.buffer, &_bg.w, - &_bg.h) != SUCCESS) { + &_bg.h)) { error("Scene::processSceneResources() Error loading background resource %i", _resourceList[i].resourceId); } @@ -1045,16 +1040,15 @@ void Scene::processSceneResources() { debug(3, "Loading BACKGROUND MASK resource."); _bgMask.res_buf = resourceData; _bgMask.res_len = resourceDataLength; - _bgMask.loaded = 1; - _vm->decodeBGImage(_bgMask.res_buf, _bgMask.res_len, &_bgMask.buf, - &_bgMask.buf_len, &_bgMask.w, &_bgMask.h, true); + _bgMask.loaded = true; + _vm->decodeBGImage(_bgMask.res_buf, _bgMask.res_len, _bgMask.buffer, &_bgMask.w, &_bgMask.h, true); // At least in ITE the mask needs to be clipped. _bgMask.w = MIN(_bgMask.w, _vm->getDisplayInfo().width); _bgMask.h = MIN(_bgMask.h, getHeight()); - debug(4, "BACKGROUND MASK width=%d height=%d length=%d", _bgMask.w, _bgMask.h, (int)_bgMask.buf_len); + debug(4, "BACKGROUND MASK width=%d height=%d length=%d", _bgMask.w, _bgMask.h, _bgMask.buffer.size()); break; case SAGA_STRINGS: debug(3, "Loading scene strings resource..."); @@ -1217,14 +1211,14 @@ void Scene::endScene() { // Free scene background if (_bg.loaded) { - free(_bg.buf); - _bg.loaded = 0; + _bg.buffer.clear(); + _bg.loaded = false; } // Free scene background mask if (_bgMask.loaded) { - free(_bgMask.buf); - _bgMask.loaded = 0; + _bgMask.buffer.clear(); + _bgMask.loaded = false; } // Free scene resource list diff --git a/engines/saga/scene.h b/engines/saga/scene.h index f7c6c39ec5..fdb9919064 100644 --- a/engines/saga/scene.h +++ b/engines/saga/scene.h @@ -74,7 +74,6 @@ enum FTA2Endings { struct BGInfo { Rect bounds; byte *buffer; - size_t bufferLength; }; typedef int (SceneProc) (int, void *); @@ -141,15 +140,18 @@ class SceneEntryList : public Common::Array { }; struct SceneImage { - int loaded; + bool loaded; int w; int h; int p; - byte *buf; - size_t buf_len; + ByteArray buffer; byte *res_buf; size_t res_len; PalEntry pal[256]; + + SceneImage() : loaded(false), w(0), h(0), p(0) { + memset(pal, 0, sizeof(pal)); + } }; @@ -239,7 +241,7 @@ class Scene { bool isInIntro() { return !_inGame; } const Rect& getSceneClip() const { return _sceneClip; } - void getBGMaskInfo(int &width, int &height, byte *&buffer, size_t &bufferLength); + void getBGMaskInfo(int &width, int &height, byte *&buffer); int isBGMaskPresent() { return _bgMask.loaded; } int getBGMaskType(const Point &testPoint) { @@ -255,7 +257,7 @@ class Scene { } #endif - return (_bgMask.buf[offset] >> 4) & 0x0f; + return (_bgMask.buffer[offset] >> 4) & 0x0f; } bool validBGMaskPoint(const Point &testPoint) { diff --git a/engines/saga/sprite.cpp b/engines/saga/sprite.cpp index df387f4fff..4e0d9c6f75 100644 --- a/engines/saga/sprite.cpp +++ b/engines/saga/sprite.cpp @@ -372,7 +372,6 @@ void Sprite::drawOccluded(SpriteList &spriteList, uint spriteNumber, const Point int maskWidth; int maskHeight; byte *maskBuffer; - size_t maskBufferLength; byte *maskRowPointer; int maskZ; @@ -381,7 +380,7 @@ void Sprite::drawOccluded(SpriteList &spriteList, uint spriteNumber, const Point return; } - _vm->_scene->getBGMaskInfo(maskWidth, maskHeight, maskBuffer, maskBufferLength); + _vm->_scene->getBGMaskInfo(maskWidth, maskHeight, maskBuffer); getScaledSpriteBuffer(spriteList, spriteNumber, scale, width, height, xAlign, yAlign, spriteBuffer); -- cgit v1.2.3