aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJoseph-Eugene Winzer2017-06-28 14:09:13 +0200
committerThierry Crozat2018-01-22 23:42:08 +0000
commitef1bbce68eb2c45d36de0147df14c27dd8b622b6 (patch)
tree3bf57d0c724dfd642513cb2e4a747b48e9c0e90b /engines
parent1ae113470645dc356ec05662f1144f2ab658a516 (diff)
downloadscummvm-rg350-ef1bbce68eb2c45d36de0147df14c27dd8b622b6.tar.gz
scummvm-rg350-ef1bbce68eb2c45d36de0147df14c27dd8b622b6.tar.bz2
scummvm-rg350-ef1bbce68eb2c45d36de0147df14c27dd8b622b6.zip
SUPERNOVA: Buffers sections of image on init
Diffstat (limited to 'engines')
-rw-r--r--engines/supernova/graphics.cpp141
-rw-r--r--engines/supernova/graphics.h9
-rw-r--r--engines/supernova/supernova.cpp15
3 files changed, 84 insertions, 81 deletions
diff --git a/engines/supernova/graphics.cpp b/engines/supernova/graphics.cpp
index 5acc2adc83..ba2f06e39e 100644
--- a/engines/supernova/graphics.cpp
+++ b/engines/supernova/graphics.cpp
@@ -33,8 +33,7 @@
namespace Supernova {
MSNImageDecoder::MSNImageDecoder()
- : _surface(NULL)
- , _palette(NULL)
+ : _palette(NULL)
, _encodedImage(NULL) {
}
@@ -133,77 +132,73 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) {
}
}
+ loadSections();
+
return true;
}
-bool MSNImageDecoder::loadSection(int section) {
- int imageWidth = 320;
- int imageHeight = 200;
-
- if (_surface)
- _surface->free();
-
- _surface = new Graphics::Surface;
-
- if (_filenumber == 1 || _filenumber == 2) {
- imageWidth = 640;
- imageHeight = 480;
- _pitch = 640;
-
- _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;
- *surfacePixels++ = (_encodedImage[i] & 0x20) ? kColorWhite63 : kColorBlack;
- *surfacePixels++ = (_encodedImage[i] & 0x10) ? kColorWhite63 : kColorBlack;
- *surfacePixels++ = (_encodedImage[i] & 0x08) ? kColorWhite63 : kColorBlack;
- *surfacePixels++ = (_encodedImage[i] & 0x04) ? kColorWhite63 : kColorBlack;
- *surfacePixels++ = (_encodedImage[i] & 0x02) ? kColorWhite63 : kColorBlack;
- *surfacePixels++ = (_encodedImage[i] & 0x01) ? kColorWhite63 : kColorBlack;
- }
- } else {
- _pitch = 320;
- _surface->create(imageWidth, imageHeight, g_system->getScreenFormat());
- byte *surfacePixels = static_cast<byte *>(_surface->getPixels());
-
- const uint32 kInvalidAddress = 0x00FFFFFF;
-
- uint image = section;
- if (image < 128) {
- 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);
+bool MSNImageDecoder::loadSections() {
+ bool isNewspaper = _filenumber == 1 || _filenumber == 2;
+ int imageWidth = isNewspaper ? 640 : 320;
+ int imageHeight = isNewspaper ? 480 : 200;
+ _pitch = imageWidth;
+
+ 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) {
+ for (int i = 0; i < imageWidth * imageHeight / 8; ++i) {
+ *surfacePixels++ = (_encodedImage[i] & 0x80) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x40) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x20) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x10) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x08) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x04) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x02) ? kColorWhite63 : kColorBlack;
+ *surfacePixels++ = (_encodedImage[i] & 0x01) ? kColorWhite63 : kColorBlack;
+ }
} else {
- image -= 128;
- do {
- 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;
- uint32 offset = (_section[image].addressHigh << 16) + _section[image].addressLow + destAddress;
- while (height) {
- Common::copy(_encodedImage + offset, _encodedImage + offset + width, surfacePixels + destAddress);
- offset += imageWidth;
- destAddress += imageWidth;
- --height;
- }
-
- image = _section[image].next;
- } while (image != 0);
+ uint image = section;
+ if (image < 128) {
+ 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);
+ } else {
+ image -= 128;
+ do {
+ 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;
+ uint32 offset = (_section[image].addressHigh << 16) + _section[image].addressLow + destAddress;
+ while (height) {
+ Common::copy(_encodedImage + offset, _encodedImage + offset + width, surfacePixels + destAddress);
+ offset += imageWidth;
+ destAddress += imageWidth;
+ --height;
+ }
+
+ image = _section[image].next;
+ } while (image != 0);
+ }
}
}
@@ -215,14 +210,14 @@ void MSNImageDecoder::destroy() {
delete[] _palette;
_palette = NULL;
}
- if (_surface) {
- _surface->free();
- _surface = NULL;
- }
if (_encodedImage) {
delete[] _encodedImage;
_encodedImage = NULL;
}
+ for (Common::Array<Graphics::Surface *>::iterator it = _sectionSurfaces.begin();
+ it != _sectionSurfaces.end(); ++it) {
+ (*it)->free();
+ }
}
}
diff --git a/engines/supernova/graphics.h b/engines/supernova/graphics.h
index 3bd2bfdd29..c04afbadf9 100644
--- a/engines/supernova/graphics.h
+++ b/engines/supernova/graphics.h
@@ -43,20 +43,20 @@ public:
virtual void destroy();
virtual bool loadStream(Common::SeekableReadStream &stream);
- virtual const Graphics::Surface *getSurface() const { return _surface; }
+ virtual const Graphics::Surface *getSurface() const { return _sectionSurfaces[0]; }
virtual const byte *getPalette() const { return _palette; }
- bool loadSection(int section);
bool init(int filenumber);
static const int kMaxSections = 50;
static const int kMaxClickFields = 80;
+ static const uint32 kInvalidAddress = 0x00FFFFFF;
int _filenumber;
int _pitch;
int _numSections;
int _numClickFields;
- Graphics::Surface *_surface;
+ Common::Array<Graphics::Surface *> _sectionSurfaces;
byte *_palette;
byte *_encodedImage;
@@ -77,6 +77,9 @@ public:
byte y2;
byte next;
} _clickField[kMaxClickFields];
+
+private:
+ bool loadSections();
};
}
diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp
index 4d5da92819..5fc88f6d06 100644
--- a/engines/supernova/supernova.cpp
+++ b/engines/supernova/supernova.cpp
@@ -267,18 +267,20 @@ void SupernovaEngine::playSoundMod(int filenumber)
}
void SupernovaEngine::renderImage(MSNImageDecoder &image, int section, bool fullscreen) {
+ if (section > image._numSections - 1)
+ return;
+
_currentImage = &image;
_imageIndex = image._filenumber;
_sectionIndex = section;
- image.loadSection(section);
_system->getPaletteManager()->setPalette(image.getPalette(), 16, 239);
paletteBrightness();
Common::Rect sectionRect(image._section[section].x1,
image._section[section].y1,
- image._section[section].x2 - image._section[section].x1,
- image._section[section].y2 - image._section[section].y1);
+ image._section[section].x2,
+ image._section[section].y2);
if (image._filenumber == 1 || image._filenumber == 2) {
sectionRect.setWidth(640);
sectionRect.setHeight(480);
@@ -297,11 +299,11 @@ void SupernovaEngine::renderImage(MSNImageDecoder &image, int section, bool full
}
if (fullscreen) {
- _system->copyRectToScreen(image.getSurface()->getPixels(),
+ _system->copyRectToScreen(image._sectionSurfaces[section]->getPixels(),
image._pitch, 0, 0, _screenWidth, _screenHeight);
} else {
uint offset = image._section[section].y1 * image._pitch + image._section[section].x1;
- _system->copyRectToScreen(static_cast<const byte *>(image.getSurface()->getPixels()) + offset,
+ _system->copyRectToScreen(static_cast<const byte *>(image._sectionSurfaces[section]->getPixels()) + offset,
image._pitch,
sectionRect.top, sectionRect.left,
sectionRect.width(), sectionRect.height());
@@ -309,6 +311,9 @@ void SupernovaEngine::renderImage(MSNImageDecoder &image, int section, bool full
}
void SupernovaEngine::renderImage(int filenumber, int section, bool fullscreen) {
+ if (filenumber > ARRAYSIZE(_images) - 1)
+ return;
+
renderImage(_images[filenumber], section, fullscreen);
}