[Scummvm-git-logs] scummvm master -> cd35dc6911864daa0ebc9d263322ddd353fe664e

sev- noreply at scummvm.org
Mon Jul 4 23:19:50 UTC 2022


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

Summary:
4e1afe31b3 DIRECTOR: Render 8bpp stretched images in 32bpp mode
cd35dc6911 DIRECTOR: Added support for remapping palettes


Commit: 4e1afe31b3105c23ad6a2ed6e54dcbd2b1558c11
    https://github.com/scummvm/scummvm/commit/4e1afe31b3105c23ad6a2ed6e54dcbd2b1558c11
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-07-05T00:26:28+02:00

Commit Message:
DIRECTOR: Render 8bpp stretched images in 32bpp mode

Changed paths:
    engines/director/castmember.cpp
    engines/director/castmember.h


diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index 06f1a702ef4..3d8ca63ade5 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -236,19 +236,27 @@ Graphics::MacWidget *BitmapCastMember::createWidget(Common::Rect &bbox, Channel
 		return nullptr;
 
 	// Check if we need to dither the image
-	if (g_director->_wm->_pixelformat.bytesPerPixel == 1 && _img->getSurface()->format.bytesPerPixel > 1) {
-		ditherFloydImage();
+	int dstBpp = g_director->_wm->_pixelformat.bytesPerPixel;
+	int srcBpp = _img->getSurface()->format.bytesPerPixel;
+	int palSize = g_director->_wm->getPaletteSize();
+
+	if (dstBpp == 1) {
+		if (srcBpp > 1 || (srcBpp == 1 &&
+			(palSize != _img->getPaletteColorCount()
+			|| memcmp(g_director->_wm->getPalette(), _img->getPalette(), palSize * 3)))) {
+			ditherFloydImage();
+		}
 	}
 
 	Graphics::MacWidget *widget = new Graphics::MacWidget(g_director->getCurrentWindow(), bbox.left, bbox.top, bbox.width(), bbox.height(), g_director->_wm, false);
 
 	// scale for drawing a different size sprite
-	copyStretchImg(widget->getSurface()->surfacePtr(), bbox);
+	copyStretchImg(widget->getSurface()->surfacePtr(), bbox, _img->getPalette());
 
 	return widget;
 }
 
-void BitmapCastMember::copyStretchImg(Graphics::Surface *surface, const Common::Rect &bbox) {
+void BitmapCastMember::copyStretchImg(Graphics::Surface *surface, const Common::Rect &bbox, const byte *pal) {
 	const Graphics::Surface *srcSurf;
 
 	if (_ditheredImg)
@@ -269,8 +277,24 @@ void BitmapCastMember::copyStretchImg(Graphics::Surface *surface, const Common::
 				}
 			} else {
 				for (int x = 0, scaleXCtr = 0; x < bbox.width(); x++, scaleXCtr += scaleX) {
-					const int *src = (const int *)srcSurf->getBasePtr(scaleXCtr / SCALE_THRESHOLD, scaleYCtr / SCALE_THRESHOLD);
-					*(int *)surface->getBasePtr(x, y) = *src;
+					const void *ptr = srcSurf->getBasePtr(scaleXCtr / SCALE_THRESHOLD, scaleYCtr / SCALE_THRESHOLD);
+					int32 color;
+
+					switch (srcSurf->format.bytesPerPixel) {
+					case 1:
+						{
+							color = *(const byte *)ptr * 3;
+							color = surface->format.RGBToColor(pal[color], pal[color + 1], pal[color + 2]);
+						}
+						break;
+					case 4:
+						color = *(const int32 *)ptr;
+						break;
+					default:
+						error("Unimplemented src bpp: %d", srcSurf->format.bytesPerPixel);
+					}
+
+					*(int32 *)surface->getBasePtr(x, y) = color;
 				}
 			}
 		}
diff --git a/engines/director/castmember.h b/engines/director/castmember.h
index 7ddc6a8ad91..7acf5567feb 100644
--- a/engines/director/castmember.h
+++ b/engines/director/castmember.h
@@ -125,7 +125,7 @@ public:
 
 	void createMatte(Common::Rect &bbox);
 	Graphics::Surface *getMatte(Common::Rect &bbox);
-	void copyStretchImg(Graphics::Surface *surface, const Common::Rect &bbox);
+	void copyStretchImg(Graphics::Surface *surface, const Common::Rect &bbox, const byte *pal = 0);
 
 	bool hasField(int field) override;
 	Datum getField(int field) override;


Commit: cd35dc6911864daa0ebc9d263322ddd353fe664e
    https://github.com/scummvm/scummvm/commit/cd35dc6911864daa0ebc9d263322ddd353fe664e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-07-05T00:26:28+02:00

Commit Message:
DIRECTOR: Added support for remapping palettes

Changed paths:
    engines/director/castmember.cpp


diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index 3d8ca63ade5..e6cab4cd12d 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -238,20 +238,24 @@ Graphics::MacWidget *BitmapCastMember::createWidget(Common::Rect &bbox, Channel
 	// Check if we need to dither the image
 	int dstBpp = g_director->_wm->_pixelformat.bytesPerPixel;
 	int srcBpp = _img->getSurface()->format.bytesPerPixel;
-	int palSize = g_director->_wm->getPaletteSize();
+	int palSize = _img->getPaletteColorCount();
+
+	const byte *pal = _img->getPalette();
 
 	if (dstBpp == 1) {
 		if (srcBpp > 1 || (srcBpp == 1 &&
-			(palSize != _img->getPaletteColorCount()
-			|| memcmp(g_director->_wm->getPalette(), _img->getPalette(), palSize * 3)))) {
+			memcmp(g_director->_wm->getPalette(), _img->getPalette(), palSize * 3))) {
+
 			ditherFloydImage();
+
+			pal = g_director->_wm->getPalette();
 		}
 	}
 
 	Graphics::MacWidget *widget = new Graphics::MacWidget(g_director->getCurrentWindow(), bbox.left, bbox.top, bbox.width(), bbox.height(), g_director->_wm, false);
 
 	// scale for drawing a different size sprite
-	copyStretchImg(widget->getSurface()->surfacePtr(), bbox, _img->getPalette());
+	copyStretchImg(widget->getSurface()->surfacePtr(), bbox, pal);
 
 	return widget;
 }
@@ -313,7 +317,7 @@ void BitmapCastMember::ditherImage() {
 	int h = _initialRect.height();
 
 	_ditheredImg = new Graphics::Surface;
-	_ditheredImg->create(w, h, g_director->_pixelformat);
+	_ditheredImg->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
 
 	for (int y = 0; y < h; y++) {
 		const byte *src = (const byte *)_img->getSurface()->getBasePtr(0, y);
@@ -323,6 +327,10 @@ void BitmapCastMember::ditherImage() {
 			uint32 color;
 
 			switch (bpp) {
+			case 1:
+				color = *((const byte *)src);
+				src += 1;
+				break;
 			case 2:
 				color = *((const uint16 *)src);
 				src += 2;
@@ -366,39 +374,46 @@ void BitmapCastMember::ditherFloydImage() {
 	byte *tmpSurf = (byte *)malloc(w * h * 3);
 
 	int bpp = _img->getSurface()->format.bytesPerPixel;
+	const byte *pal = _img->getPalette();
 
 	for (int y = 0; y < h; y++) {
 		const byte *src = (const byte *)_img->getSurface()->getBasePtr(0, y);
 		byte *dst = &tmpSurf[y * w * 3];
 
+		byte r, g, b;
+
 		for (int x = 0; x < w; x++) {
 			uint32 color;
 
 			switch (bpp) {
+			case 1:
+				color = *src * 3;
+				src += 1;
+				r = pal[color + 0]; g = pal[color + 1]; b = pal[color + 2];
+				break;
 			case 2:
 				color = *((const uint16 *)src);
 				src += 2;
+				_img->getSurface()->format.colorToRGB(color, r, g, b);
 				break;
 			case 4:
 				color = *((const uint32 *)src);
 				src += 4;
+				_img->getSurface()->format.colorToRGB(color, r, g, b);
 				break;
 			default:
-				error("BitmapCastMember::ditherImage(): Unsupported bit depth: %d", bpp);
+				error("BitmapCastMember::ditherFloydImage(): Unsupported bit depth: %d", bpp);
 			}
 
-			byte r, g, b;
-			_img->getSurface()->format.colorToRGB(color, r, g, b);
-
 			dst[0] = r; dst[1] = g; dst[2] = b;
 			dst += 3;
 		}
 	}
 
 	_ditheredImg = new Graphics::Surface;
-	_ditheredImg->create(w, h, g_director->_pixelformat);
+	_ditheredImg->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
 
-	const byte *pal = g_director->_wm->getPalette();
+	pal = g_director->_wm->getPalette();
 
 	for (int y = 0; y < h; y++) {
 		const byte *src = &tmpSurf[y * w * 3];
@@ -411,8 +426,8 @@ void BitmapCastMember::ditherFloydImage() {
 			*dst = col;
 
 			int qr = r - pal[col * 3 + 0];
-			int qg = g = pal[col * 3 + 1];
-			int qb = b = pal[col * 3 + 2];
+			int qg = g - pal[col * 3 + 1];
+			int qb = b - pal[col * 3 + 2];
 
 			updatePixel(tmpSurf, x + 1, y,     w, h, qr, qg, qb, 7);
 			updatePixel(tmpSurf, x - 1, y + 1, w, h, qr, qg, qb, 3);




More information about the Scummvm-git-logs mailing list