diff options
author | Thierry Crozat | 2017-11-05 02:59:22 +0000 |
---|---|---|
committer | Thierry Crozat | 2018-01-23 02:15:37 +0000 |
commit | 841e7182f28471ffda0ecd0c692649f58fd3aea8 (patch) | |
tree | 74ef3b95878b69b82fb1aa90eab3f018c1906c87 | |
parent | 73278c3f9f0157e1adf19134eceeb65eec3e37eb (diff) | |
download | scummvm-rg350-841e7182f28471ffda0ecd0c692649f58fd3aea8.tar.gz scummvm-rg350-841e7182f28471ffda0ecd0c692649f58fd3aea8.tar.bz2 scummvm-rg350-841e7182f28471ffda0ecd0c692649f58fd3aea8.zip |
SUPERNOVA: Reduce memory usage to store sections and simplify code
Each section was store dusing the full image size. Now it only uses the
section size, which should reduce considerably the amout of memory used
for each image.
Also when a section has one or more next section, they were all drawn on
the surface for this section, but then they were drawn again on their own
surface. And while this should not cause any issue, this was really
unnecessary (and prevented optimizing the surface size for each section).
So now this is no longer the case and the surface for a section only
contains this section.
-rw-r--r-- | engines/supernova/graphics.cpp | 33 | ||||
-rw-r--r-- | engines/supernova/supernova.cpp | 8 |
2 files changed, 16 insertions, 25 deletions
diff --git a/engines/supernova/graphics.cpp b/engines/supernova/graphics.cpp index 87485e0edc..ee2bfe8e3a 100644 --- a/engines/supernova/graphics.cpp +++ b/engines/supernova/graphics.cpp @@ -203,12 +203,10 @@ bool MSNImageDecoder::loadSections() { for (int section = 0; section < _numSections; ++section) { Graphics::Surface *surface = new Graphics::Surface; _sectionSurfaces.push_back(surface); - surface->create(imageWidth, - imageHeight, - g_system->getScreenFormat()); - byte *surfacePixels = static_cast<byte *>(surface->getPixels()); if (isNewspaper) { + surface->create(imageWidth, imageHeight, g_system->getScreenFormat()); + byte *surfacePixels = static_cast<byte *>(surface->getPixels()); for (int i = 0; i < imageWidth * imageHeight / 8; ++i) { *surfacePixels++ = (_encodedImage[i] & 0x80) ? kColorWhite63 : kColorBlack; *surfacePixels++ = (_encodedImage[i] & 0x40) ? kColorWhite63 : kColorBlack; @@ -220,24 +218,15 @@ bool MSNImageDecoder::loadSections() { *surfacePixels++ = (_encodedImage[i] & 0x01) ? kColorWhite63 : kColorBlack; } } else { - uint image = section; - do { - uint32 offset = (_section[image].addressHigh << 16) + _section[image].addressLow; - if (offset == kInvalidAddress || _section[image].x2 == 0) { - return false; - } - int width = _section[image].x2 - _section[image].x1 + 1; - int height = _section[image].y2 - _section[image].y1 + 1; - uint32 destAddress = imageWidth * _section[image].y1 + _section[image].x1; - while (height) { - Common::copy(_encodedImage + offset, _encodedImage + offset + width, surfacePixels + destAddress); - offset += width; - destAddress += imageWidth; - --height; - } - - image = _section[image].next; - } while (image != 0); + uint32 offset = (_section[section].addressHigh << 16) + _section[section].addressLow; + if (offset == kInvalidAddress || _section[section].x2 == 0) { + return false; + } + int width = _section[section].x2 - _section[section].x1 + 1; + int height = _section[section].y2 - _section[section].y1 + 1; + surface->create(width, height, g_system->getScreenFormat()); + byte *surfacePixels = static_cast<byte *>(surface->getPixels()); + Common::copy(_encodedImage + offset, _encodedImage + offset + width * height, surfacePixels); } } diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index 6dda5657ff..291e18d964 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -425,12 +425,14 @@ void SupernovaEngine::renderImage(MSNImageDecoder &image, int section) { } } - uint offset = image._section[section].y1 * image._pitch + image._section[section].x1; - if (invert) + uint offset = 0; + if (invert) { + offset = image._section[section].y1 * image._pitch + image._section[section].x1; section = 0; + } _system->copyRectToScreen(static_cast<const byte *>(image._sectionSurfaces[section]->getPixels()) + offset, - image._pitch, + sectionRect.width(), sectionRect.left, sectionRect.top, sectionRect.width(), sectionRect.height()); } |