[Scummvm-git-logs] scummvm master -> 9dc04e29904b9566fc4beb741d59648f396041bb

dreammaster paulfgilbert at gmail.com
Sun Jun 7 20:22:14 UTC 2020


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f7a1f94f02 GLK: COMPREHEND: Remove _renderColor from DrawSurface
d044a1246c GLK: COMPREHEND: Reduce draw surface size to match original
9dc04e2990 GLK: COMPREHEND: Fixes for drawing out of bounds


Commit: f7a1f94f022e5b0fdb40e6b8db9fd749aa77490f
    https://github.com/scummvm/scummvm/commit/f7a1f94f022e5b0fdb40e6b8db9fd749aa77490f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-07T12:01:10-07:00

Commit Message:
GLK: COMPREHEND: Remove _renderColor from DrawSurface

Changed paths:
    engines/glk/comprehend/draw_surface.cpp
    engines/glk/comprehend/draw_surface.h
    engines/glk/comprehend/pics.cpp


diff --git a/engines/glk/comprehend/draw_surface.cpp b/engines/glk/comprehend/draw_surface.cpp
index fe1025b665..70f6119f6c 100644
--- a/engines/glk/comprehend/draw_surface.cpp
+++ b/engines/glk/comprehend/draw_surface.cpp
@@ -208,14 +208,9 @@ uint32 DrawSurface::getFillColor(uint8 index) {
 	return color;
 }
 
-void DrawSurface::setColor(uint32 color) {
-	_renderColor = color;
-}
-
 void DrawSurface::drawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color) {
-	setColor(color);
 #if 1
-	Graphics::ManagedSurface::drawLine(x1, y1, x2, y2, _renderColor);
+	Graphics::ManagedSurface::drawLine(x1, y1, x2, y2, color);
 #else
 	bool swapped = false;
 	int deltaX = -1, deltaY = -1;
@@ -265,18 +260,14 @@ void DrawSurface::drawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color)
 #endif
 }
 
-void DrawSurface::drawBox(int16 x1, int16 y1, int16 x2, int16 y2,
-                          uint32 color) {
-	setColor(color);
+void DrawSurface::drawBox(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color) {
 	Common::Rect r(x1, y1, x2 + 1, y2 + 1);
-	frameRect(r, _renderColor);
+	frameRect(r, color);
 }
 
-void DrawSurface::drawFilledBox(int16 x1, int16 y1,
-                                int16 x2, int16 y2, uint32 color) {
-	setColor(color);
+void DrawSurface::drawFilledBox(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color) {
 	Common::Rect r(x1, y1, x2 + 1, y2 + 1);
-	fillRect(r, _renderColor);
+	fillRect(r, color);
 }
 
 void DrawSurface::drawShape(int16 x, int16 y, int shape_type, uint32 fill_color) {
@@ -415,14 +406,9 @@ void DrawSurface::floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_colo
 }
 
 void DrawSurface::drawPixel(int16 x, int16 y, uint32 color) {
-	setColor(color);
-	drawPixel(x, y);
-}
-
-void DrawSurface::drawPixel(int16 x, int16 y) {
 	if (x >= 0 && y >= 0 && x < this->w && y < this->h) {
 		uint32 *ptr = (uint32 *)getBasePtr(x, y);
-		*ptr = _renderColor;
+		*ptr = color;
 	}
 }
 
@@ -432,24 +418,23 @@ uint32 DrawSurface::getPixelColor(int16 x, int16 y) {
 }
 
 void DrawSurface::clearScreen(uint32 color) {
-	setColor(color);
-	fillRect(Common::Rect(0, 0, this->w, this->h), _renderColor);
+	fillRect(Common::Rect(0, 0, this->w, this->h), color);
 }
 
-void DrawSurface::drawCircle(int16 x, int16 y, int16 diameter) {
+void DrawSurface::drawCircle(int16 x, int16 y, int16 diameter, uint32 color) {
 	int invert = -diameter;
 	int delta = 0;
 
 	do {
-		drawCirclePoint(x - delta, y - diameter);
-		drawCirclePoint(x + delta, y - diameter);
-		drawCirclePoint(x + delta, y + diameter);
-		drawCirclePoint(x - delta, y + diameter);
+		drawPixel(x - delta, y - diameter, color);
+		drawPixel(x + delta, y - diameter, color);
+		drawPixel(x + delta, y + diameter, color);
+		drawPixel(x - delta, y + diameter, color);
 
-		drawCirclePoint(x + diameter, y - delta);
-		drawCirclePoint(x - diameter, y - delta);
-		drawCirclePoint(x - diameter, y + delta);
-		drawCirclePoint(x + diameter, y + delta);
+		drawPixel(x + diameter, y - delta, color);
+		drawPixel(x - diameter, y - delta, color);
+		drawPixel(x - diameter, y + delta, color);
+		drawPixel(x + diameter, y + delta, color);
 
 		invert += (delta * 2) + 1;
 		++delta;
@@ -463,10 +448,5 @@ void DrawSurface::drawCircle(int16 x, int16 y, int16 diameter) {
 	} while (diameter >= delta);
 }
 
-void DrawSurface::drawCirclePoint(int16 x, int16 y) {
-	if (x < 280 && y < 160)
-		drawPixel(x, y);
-}
-
 } // namespace Comprehend
 } // namespace Glk
diff --git a/engines/glk/comprehend/draw_surface.h b/engines/glk/comprehend/draw_surface.h
index 5c0f78bd33..b7adb10c6e 100644
--- a/engines/glk/comprehend/draw_surface.h
+++ b/engines/glk/comprehend/draw_surface.h
@@ -71,10 +71,9 @@ private:
 	static const uint32 *COLOR_TABLES[2];
 
 public:
-	uint32 _renderColor;
 	const uint32 *_colorTable;
 public:
-	DrawSurface() : _renderColor(0), _colorTable(DEFAULT_COLOR_TABLE) {
+	DrawSurface() : _colorTable(DEFAULT_COLOR_TABLE) {
 		reset();
 	}
 
@@ -86,18 +85,16 @@ public:
 	void setColorTable(uint index);
 	uint getPenColor(uint8 param) const;
 	uint32 getFillColor(uint8 index);
-	void setColor(uint32 color);
 
 	void drawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color);
 	void drawBox(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color);
 	void drawFilledBox(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color);
 	void drawShape(int16 x, int16 y, int shape_type, uint32 fill_color);
 	void floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_color);
-	void drawPixel(int16 x, int16 y);
 	void drawPixel(int16 x, int16 y, uint32 color);
 	uint32 getPixelColor(int16 x, int16 y);
 	void clearScreen(uint32 color);
-	void drawCircle(int16 x, int16 y, int16 diameter);
+	void drawCircle(int16 x, int16 y, int16 diameter, uint32 color);
 	void drawCirclePoint(int16 x, int16 y);
 };
 
diff --git a/engines/glk/comprehend/pics.cpp b/engines/glk/comprehend/pics.cpp
index d77ff2cec3..f93ea5cf82 100644
--- a/engines/glk/comprehend/pics.cpp
+++ b/engines/glk/comprehend/pics.cpp
@@ -210,7 +210,7 @@ bool Pics::ImageFile::doImageOp(Pics::ImageContext *ctx) const {
 		debugC(kDebugGraphics, "draw_circle (%d, %d) diameter=%d",
 		       ctx->_x, ctx->_y, a);
 
-		ctx->_drawSurface->drawCircle(ctx->_x, ctx->_y, a);
+		ctx->_drawSurface->drawCircle(ctx->_x, ctx->_y, a, ctx->_penColor);
 		break;
 
 	case OPCODE_DRAW_SHAPE:


Commit: d044a1246c45cd3d105d5861f0898f47788e2d01
    https://github.com/scummvm/scummvm/commit/d044a1246c45cd3d105d5861f0898f47788e2d01
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-07T12:01:10-07:00

Commit Message:
GLK: COMPREHEND: Reduce draw surface size to match original

Changed paths:
    engines/glk/comprehend/draw_surface.cpp
    engines/glk/comprehend/draw_surface.h


diff --git a/engines/glk/comprehend/draw_surface.cpp b/engines/glk/comprehend/draw_surface.cpp
index 70f6119f6c..3d4ab9cadb 100644
--- a/engines/glk/comprehend/draw_surface.cpp
+++ b/engines/glk/comprehend/draw_surface.cpp
@@ -28,12 +28,6 @@
 namespace Glk {
 namespace Comprehend {
 
-#define RENDER_X_MAX 278
-#define RENDER_Y_MAX 162
-
-#define RENDERER_SCREEN 0
-#define RENDERER_PIXEL_DATA 1
-
 const uint32 DrawSurface::PEN_COLORS[8] = {
 	G_COLOR_BLACK,
 	RGB(0x00, 0x66, 0x00),
@@ -379,6 +373,11 @@ void DrawSurface::drawShape(int16 x, int16 y, int shape_type, uint32 fill_color)
 void DrawSurface::floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_color) {
 	int x1, x2, i;
 
+	if (y == this->h)
+		y = this->h - 1;
+	else if (y > this->h)
+		return;
+
 	if (getPixelColor(x, y) != old_color || fill_color == old_color)
 		return;
 
@@ -388,21 +387,25 @@ void DrawSurface::floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_colo
 			break;
 
 	/* Right end of scanline */
-	for (x2 = x; x2 < RENDER_X_MAX; x2++)
+	for (x2 = x; x2 < this->w; x2++)
 		if (getPixelColor(x2 + 1, y) != old_color)
 			break;
 
 	drawLine(x1, y, x2, y, fill_color);
 
 	/* Scanline above */
-	for (i = x1; i < x2; i++)
-		if (y > 0 && getPixelColor(i, y - 1) == old_color)
-			floodFill(i, y - 1, fill_color, old_color);
+	if (y > 0) {
+		for (i = x1; i < x2; i++)
+			if (getPixelColor(i, y - 1) == old_color)
+				floodFill(i, y - 1, fill_color, old_color);
+	}
 
 	/* Scanline below */
-	for (i = x1; i < x2; i++)
-		if (y < RENDER_Y_MAX && getPixelColor(i, y + 1) == old_color)
-			floodFill(i, y + 1, fill_color, old_color);
+	if (y < (this->h - 1)) {
+		for (i = x1; i < x2; i++)
+			if (getPixelColor(i, y + 1) == old_color)
+				floodFill(i, y + 1, fill_color, old_color);
+	}
 }
 
 void DrawSurface::drawPixel(int16 x, int16 y, uint32 color) {
diff --git a/engines/glk/comprehend/draw_surface.h b/engines/glk/comprehend/draw_surface.h
index b7adb10c6e..227ba9ca11 100644
--- a/engines/glk/comprehend/draw_surface.h
+++ b/engines/glk/comprehend/draw_surface.h
@@ -30,7 +30,7 @@ namespace Glk {
 namespace Comprehend {
 
 #define G_RENDER_WIDTH  280
-#define G_RENDER_HEIGHT 200
+#define G_RENDER_HEIGHT 160
 
 #define RGB(r, g, b)        (uint32)(((r) << 24) | ((g) << 16) | ((b) << 8) | 0xff)
 


Commit: 9dc04e29904b9566fc4beb741d59648f396041bb
    https://github.com/scummvm/scummvm/commit/9dc04e29904b9566fc4beb741d59648f396041bb
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-07T13:21:47-07:00

Commit Message:
GLK: COMPREHEND: Fixes for drawing out of bounds

Changed paths:
    engines/glk/comprehend/charset.cpp
    engines/glk/comprehend/draw_surface.cpp
    engines/glk/comprehend/draw_surface.h
    engines/glk/comprehend/pics.cpp


diff --git a/engines/glk/comprehend/charset.cpp b/engines/glk/comprehend/charset.cpp
index 0302973823..ba46485b27 100644
--- a/engines/glk/comprehend/charset.cpp
+++ b/engines/glk/comprehend/charset.cpp
@@ -48,11 +48,14 @@ void CharSet::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32
 	assert(chr >= 32 && chr < 128);
 
 	for (uint yp = 0; yp < 8; ++yp) {
+		if ((y + yp) < 0 || (y + yp) >= dst->h)
+			continue;
+
 		uint32 *lineP = (uint32 *)dst->getBasePtr(x, y + yp);
 		byte bits = _data[chr - 32][yp];
 
-		for (uint xp = 0; xp < 8; ++xp, ++lineP, bits >>= 1) {
-			if (bits & 1)
+		for (uint xp = 0; xp < 8; ++xp, ++lineP, ++x, bits >>= 1) {
+			if ((x >= 0) && (x < dst->w) && (bits & 1))
 				*lineP = color;
 		}
 	}
diff --git a/engines/glk/comprehend/draw_surface.cpp b/engines/glk/comprehend/draw_surface.cpp
index 3d4ab9cadb..d8daae135b 100644
--- a/engines/glk/comprehend/draw_surface.cpp
+++ b/engines/glk/comprehend/draw_surface.cpp
@@ -370,7 +370,7 @@ void DrawSurface::drawShape(int16 x, int16 y, int shape_type, uint32 fill_color)
 	}
 }
 
-void DrawSurface::floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_color) {
+void DrawSurface::floodFill(int16 x, int16 y, uint32 fillColor) {
 	int x1, x2, i;
 
 	if (y == this->h)
@@ -378,33 +378,33 @@ void DrawSurface::floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_colo
 	else if (y > this->h)
 		return;
 
-	if (getPixelColor(x, y) != old_color || fill_color == old_color)
+	if (!isPixelWhite(x, y))
 		return;
 
-	/* Left end of scanline */
+	// Left end of scanline
 	for (x1 = x; x1 > 0; x1--)
-		if (getPixelColor(x1 - 1, y) != old_color)
+		if (!isPixelWhite(x1 - 1, y))
 			break;
 
-	/* Right end of scanline */
+	// Right end of scanline
 	for (x2 = x; x2 < this->w; x2++)
-		if (getPixelColor(x2 + 1, y) != old_color)
+		if (!isPixelWhite(x2 + 1, y))
 			break;
 
-	drawLine(x1, y, x2, y, fill_color);
+	drawLine(x1, y, x2, y, fillColor);
 
-	/* Scanline above */
+	// Scanline above
 	if (y > 0) {
 		for (i = x1; i < x2; i++)
-			if (getPixelColor(i, y - 1) == old_color)
-				floodFill(i, y - 1, fill_color, old_color);
+			if (isPixelWhite(i, y - 1))
+				floodFill(i, y - 1, fillColor);
 	}
 
-	/* Scanline below */
+	// Scanline below
 	if (y < (this->h - 1)) {
 		for (i = x1; i < x2; i++)
-			if (getPixelColor(i, y + 1) == old_color)
-				floodFill(i, y + 1, fill_color, old_color);
+			if (isPixelWhite(i, y + 1))
+				floodFill(i, y + 1, fillColor);
 	}
 }
 
@@ -415,11 +415,22 @@ void DrawSurface::drawPixel(int16 x, int16 y, uint32 color) {
 	}
 }
 
-uint32 DrawSurface::getPixelColor(int16 x, int16 y) {
-	uint32 *ptr = (uint32 *)getBasePtr(x, y);
+uint32 DrawSurface::getPixelColor(int16 x, int16 y) const {
+	assert(x >= 0 && y >= 0 && x < this->w && y < this->h);
+	const uint32 *ptr = (uint32 *)getBasePtr(x, y);
 	return *ptr;
 }
 
+bool DrawSurface::isPixelWhite(int16 x, int16 y) const {
+	if (x < 0 || y < 0 || x >= this->w || y >= this->h) {
+		return false;
+	} else {
+		byte r, g, b;
+		format.colorToRGB(getPixelColor(x, y), r, g, b);
+		return r == 255 && g == 255 && b == 255;
+	}
+}
+
 void DrawSurface::clearScreen(uint32 color) {
 	fillRect(Common::Rect(0, 0, this->w, this->h), color);
 }
diff --git a/engines/glk/comprehend/draw_surface.h b/engines/glk/comprehend/draw_surface.h
index 227ba9ca11..a5568e1119 100644
--- a/engines/glk/comprehend/draw_surface.h
+++ b/engines/glk/comprehend/draw_surface.h
@@ -90,9 +90,10 @@ public:
 	void drawBox(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color);
 	void drawFilledBox(int16 x1, int16 y1, int16 x2, int16 y2, uint32 color);
 	void drawShape(int16 x, int16 y, int shape_type, uint32 fill_color);
-	void floodFill(int16 x, int16 y, uint32 fill_color, uint32 old_color);
+	void floodFill(int16 x, int16 y, uint32 fillColor);
 	void drawPixel(int16 x, int16 y, uint32 color);
-	uint32 getPixelColor(int16 x, int16 y);
+	uint32 getPixelColor(int16 x, int16 y) const;
+	bool isPixelWhite(int16 x, int16 y) const;
 	void clearScreen(uint32 color);
 	void drawCircle(int16 x, int16 y, int16 diameter, uint32 color);
 	void drawCirclePoint(int16 x, int16 y);
diff --git a/engines/glk/comprehend/pics.cpp b/engines/glk/comprehend/pics.cpp
index f93ea5cf82..e97e7ca678 100644
--- a/engines/glk/comprehend/pics.cpp
+++ b/engines/glk/comprehend/pics.cpp
@@ -238,8 +238,7 @@ bool Pics::ImageFile::doImageOp(Pics::ImageContext *ctx) const {
 
 		debugC(kDebugGraphics, "paint(%d, %d)", a, b);
 		if (!(ctx->_drawFlags & IMAGEF_NO_FLOODFILL))
-			ctx->_drawSurface->floodFill(a, b, ctx->_fillColor,
-			                             ctx->_drawSurface->getPixelColor(a, b));
+			ctx->_drawSurface->floodFill(a, b, ctx->_fillColor);
 		break;
 
 	case OPCODE_SPECIAL:
@@ -376,6 +375,7 @@ void Pics::drawPicture(int pictureNum) const {
 		ctx._drawSurface->clearScreen(G_COLOR_WHITE);
 
 	} else if (pictureNum == TITLE_IMAGE) {
+		ctx._drawSurface->clearScreen(G_COLOR_WHITE);
 		_title.draw(0, &ctx);
 
 	} else if (pictureNum >= ITEMS_OFFSET) {




More information about the Scummvm-git-logs mailing list