diff options
author | Walter van Niftrik | 2017-02-02 09:47:35 +0100 |
---|---|---|
committer | Walter van Niftrik | 2017-02-02 09:49:45 +0100 |
commit | 1ae539d44de7af5e035161167e54f5a303356a7d (patch) | |
tree | 6af35ec3d81fe4385db896f4df6b71f97106f710 /engines/adl | |
parent | 255c76b3acce13a17a11a0022e10706e9c0045d3 (diff) | |
download | scummvm-rg350-1ae539d44de7af5e035161167e54f5a303356a7d.tar.gz scummvm-rg350-1ae539d44de7af5e035161167e54f5a303356a7d.tar.bz2 scummvm-rg350-1ae539d44de7af5e035161167e54f5a303356a7d.zip |
ADL: Increase robustness of graphics code
Diffstat (limited to 'engines/adl')
-rw-r--r-- | engines/adl/display.cpp | 5 | ||||
-rw-r--r-- | engines/adl/graphics.cpp | 38 | ||||
-rw-r--r-- | engines/adl/graphics.h | 4 |
3 files changed, 28 insertions, 19 deletions
diff --git a/engines/adl/display.cpp b/engines/adl/display.cpp index c630d034c9..7283777fe3 100644 --- a/engines/adl/display.cpp +++ b/engines/adl/display.cpp @@ -250,6 +250,8 @@ void Display::setPixelPalette(const Common::Point &p, byte color) { } bool Display::getPixelBit(const Common::Point &p) const { + assert(p.x >= 0 && p.x < DISPLAY_WIDTH && p.y >= 0 && p.y < DISPLAY_HEIGHT); + byte *b = _frameBuf + p.y * DISPLAY_PITCH + p.x / 7; return *b & (1 << (p.x % 7)); } @@ -334,8 +336,7 @@ void Display::showCursor(bool enable) { } void Display::writeFrameBuffer(const Common::Point &p, byte color, byte mask) { - if (p.x >= DISPLAY_WIDTH || p.y >= DISPLAY_HEIGHT) - return; + assert(p.x >= 0 && p.x < DISPLAY_WIDTH && p.y >= 0 && p.y < DISPLAY_HEIGHT); byte *b = _frameBuf + p.y * DISPLAY_PITCH + p.x / 7; color ^= *b; diff --git a/engines/adl/graphics.cpp b/engines/adl/graphics.cpp index 209f8a87a3..cf906657b5 100644 --- a/engines/adl/graphics.cpp +++ b/engines/adl/graphics.cpp @@ -57,7 +57,7 @@ void GraphicsMan::drawLine(const Common::Point &p1, const Common::Point &p2, byt int16 err = deltaX + deltaY; while (true) { - _display.putPixel(p, color); + putPixel(p, color); if (--steps == 0) return; @@ -72,6 +72,11 @@ void GraphicsMan::drawLine(const Common::Point &p1, const Common::Point &p2, byt } } +void GraphicsMan::putPixel(const Common::Point &p, byte color) const { + if (_bounds.contains(p)) + _display.putPixel(p, color); +} + void Graphics_v1::drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) { byte x, y; bool bNewLine = false; @@ -98,7 +103,7 @@ void Graphics_v1::drawPic(Common::SeekableReadStream &pic, const Common::Point & y = 160; if (bNewLine) { - _display.putPixel(Common::Point(x, y), 0x7f); + putPixel(Common::Point(x, y), 0x7f); bNewLine = false; } else { drawLine(Common::Point(oldX, oldY), Common::Point(x, y), 0x7f); @@ -111,7 +116,7 @@ void Graphics_v1::drawPic(Common::SeekableReadStream &pic, const Common::Point & void Graphics_v1::drawCornerPixel(Common::Point &p, byte color, byte bits, byte quadrant) const { if (bits & 4) - _display.putPixel(p, color); + putPixel(p, color); bits += quadrant; @@ -228,7 +233,7 @@ void Graphics_v2::drawCorners(Common::SeekableReadStream &pic, bool yFirst) { READ_BYTE(n); n += _offset.x; - _display.putPixel(p, _color); + putPixel(p, _color); n <<= 1; drawLine(p, Common::Point(n, p.y), _color); @@ -238,10 +243,10 @@ doYStep: READ_BYTE(n); n += _offset.y; - _display.putPixel(p, _color); + putPixel(p, _color); drawLine(p, Common::Point(p.x, n), _color); - _display.putPixel(Common::Point(p.x + 1, p.y), _color); + putPixel(Common::Point(p.x + 1, p.y), _color); drawLine(Common::Point(p.x + 1, p.y), Common::Point(p.x + 1, n), _color); p.y = n; @@ -252,7 +257,7 @@ void Graphics_v2::drawRelativeLines(Common::SeekableReadStream &pic) { Common::Point p1; READ_POINT(p1); - _display.putPixel(p1, _color); + putPixel(p1, _color); while (true) { Common::Point p2(p1); @@ -282,7 +287,7 @@ void Graphics_v2::drawAbsoluteLines(Common::SeekableReadStream &pic) { Common::Point p1; READ_POINT(p1); - _display.putPixel(p1, _color); + putPixel(p1, _color); while (true) { Common::Point p2; @@ -310,7 +315,7 @@ bool Graphics_v2::canFillAt(const Common::Point &p, const bool stopBit) { void Graphics_v2::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { byte color = getPatternColor(p, pattern); - while (--p.x >= 0) { + while (--p.x >= _bounds.left) { if ((p.x % 7) == 6) { color = getPatternColor(p, pattern); _display.setPixelPalette(p, color); @@ -331,7 +336,7 @@ void Graphics_v2::fillRow(Common::Point p, const byte pattern, const bool stopBi fillRowLeft(p, pattern, stopBit); // Fill right of p - while (++p.x < DISPLAY_WIDTH) { + while (++p.x < _bounds.right) { if ((p.x % 7) == 0) { color = getPatternColor(p, pattern); // Palette is set before the first bit is tested @@ -347,10 +352,10 @@ void Graphics_v2::fillAt(Common::Point p, const byte pattern) { const bool stopBit = !_display.getPixelBit(p); // Move up into the open space above p - while (--p.y >= 0 && canFillAt(p, stopBit)); + while (--p.y >= _bounds.top && canFillAt(p, stopBit)); // Then fill by moving down - while (++p.y < DISPLAY_HEIGHT && canFillAt(p, stopBit)) + while (++p.y < _bounds.bottom && canFillAt(p, stopBit)) fillRow(p, pattern, stopBit); } @@ -362,7 +367,8 @@ void Graphics_v2::fill(Common::SeekableReadStream &pic) { Common::Point p; READ_POINT(p); - fillAt(p, pattern); + if (_bounds.contains(p)) + fillAt(p, pattern); } } @@ -438,7 +444,7 @@ void Graphics_v2::drawPic(Common::SeekableReadStream &pic, const Common::Point & void Graphics_v3::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { byte color = getPatternColor(p, pattern); - while (--p.x >= 0) { + while (--p.x >= _bounds.left) { // In this version, when moving left, it no longer sets the palette first if (!_display.getPixelBit(p)) return; @@ -460,11 +466,11 @@ void Graphics_v3::fillAt(Common::Point p, const byte pattern) { Common::Point q(p); // Fill up from p - while (--q.y >= 0 && canFillAt(q)) + while (--q.y >= _bounds.top && canFillAt(q)) fillRow(q, pattern); // Fill down from p - while (++p.y < DISPLAY_HEIGHT && canFillAt(p)) + while (++p.y < _bounds.bottom && canFillAt(p)) fillRow(p, pattern); } diff --git a/engines/adl/graphics.h b/engines/adl/graphics.h index f05045a4dc..c0d1780a33 100644 --- a/engines/adl/graphics.h +++ b/engines/adl/graphics.h @@ -38,12 +38,14 @@ public: virtual ~GraphicsMan() { } virtual void drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) = 0; void clearScreen() const; + void putPixel(const Common::Point &p, byte color) const; protected: - GraphicsMan(Display &display) : _display(display) { } + GraphicsMan(Display &display) : _bounds(280, 160), _display(display) { } void drawLine(const Common::Point &p1, const Common::Point &p2, byte color) const; Display &_display; + Common::Rect _bounds; private: virtual byte getClearColor() const = 0; |