[Scummvm-git-logs] scummvm master -> 26f0dbb1583742e1213e6843ec8c2c61c06e4844

sev- noreply at scummvm.org
Tue Jul 5 16:48:54 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:
3e2904b199 DIRECTOR: Made dithering code generic
26f0dbb158 DIRECTOR: Added different dithering algirithms


Commit: 3e2904b199049799d4ca335aa9f682d04b651f1a
    https://github.com/scummvm/scummvm/commit/3e2904b199049799d4ca335aa9f682d04b651f1a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-07-05T18:48:40+02:00

Commit Message:
DIRECTOR: Made dithering code generic

Changed paths:
    engines/director/castmember.cpp


diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index e6cab4cd12d..eba8ebe9fc6 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -352,15 +352,15 @@ void BitmapCastMember::ditherImage() {
 	}
 }
 
-static void updatePixel(byte *surf, int x, int y, int w, int h, int qr, int qg, int qb, int qq) {
+static void updatePixel(byte *surf, int x, int y, int w, int h, int qr, int qg, int qb, int qq, int qdiv) {
 	if (x >= w || y >= h)
 		return;
 
 	byte *ptr = &surf[x * 3 + y * w * 3];
 
-	ptr[0] = CLIP(ptr[0] + qr * qq / 16, 0, 255);
-	ptr[1] = CLIP(ptr[1] + qg * qq / 16, 0, 255);
-	ptr[2] = CLIP(ptr[2] + qb * qq / 16, 0, 255);
+	ptr[0] = CLIP(ptr[0] + qr * qq / qdiv, 0, 255);
+	ptr[1] = CLIP(ptr[1] + qg * qq / qdiv, 0, 255);
+	ptr[2] = CLIP(ptr[2] + qb * qq / qdiv, 0, 255);
 }
 
 void BitmapCastMember::ditherFloydImage() {
@@ -415,6 +415,36 @@ void BitmapCastMember::ditherFloydImage() {
 
 	pal = g_director->_wm->getPalette();
 
+	struct DitherParams {
+		int dx, dy, qq, qdiv;
+	};
+
+	DitherParams paramsNaive[] = {
+		{  0, 0, 0, 0 }
+	};
+
+	DitherParams paramsFloyd[] = {
+		{ +1,  0, 7, 16 },
+		{ -1, +1, 3, 16 },
+		{  0, +1, 5, 16 },
+		{ +1, +1, 1, 16 },
+		{  0,  0, 0,  0 }
+	};
+
+	struct DitherAlgos {
+		const char *name;
+		DitherParams *params;
+	} const algos[] = {
+		{ "Naive", paramsNaive },
+		{ "Floyd-Steinberg", paramsFloyd },
+		{ nullptr, nullptr }
+	};
+
+	enum {
+		kDitherNaive,
+		kDitherFloyd
+	};
+
 	for (int y = 0; y < h; y++) {
 		const byte *src = &tmpSurf[y * w * 3];
 		byte *dst = (byte *)_ditheredImg->getBasePtr(0, y);
@@ -429,10 +459,11 @@ void BitmapCastMember::ditherFloydImage() {
 			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);
-			updatePixel(tmpSurf, x,     y + 1, w, h, qr, qg, qb, 5);
-			updatePixel(tmpSurf, x + 1, y + 1, w, h, qr, qg, qb, 1);
+			int algo = kDitherFloyd;
+			DitherParams *params = algos[algo].params;
+
+			for (int i = 0; params[i].dx != 0 || params[i].dy != 0; i++)
+				updatePixel(tmpSurf, x + params[i].dx, y + params[i].dy, w, h, qr, qg, qb, params[i].qq, params[i].qdiv);
 
 			src += 3;
 			dst++;


Commit: 26f0dbb1583742e1213e6843ec8c2c61c06e4844
    https://github.com/scummvm/scummvm/commit/26f0dbb1583742e1213e6843ec8c2c61c06e4844
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-07-05T18:48:40+02:00

Commit Message:
DIRECTOR: Added different dithering algirithms

Changed paths:
    engines/director/castmember.cpp


diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index eba8ebe9fc6..e53a5490b9e 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -416,33 +416,142 @@ void BitmapCastMember::ditherFloydImage() {
 	pal = g_director->_wm->getPalette();
 
 	struct DitherParams {
-		int dx, dy, qq, qdiv;
+		int dy, dx, qq;
 	};
 
 	DitherParams paramsNaive[] = {
-		{  0, 0, 0, 0 }
+		{ 0, 0, 0 }
 	};
 
 	DitherParams paramsFloyd[] = {
-		{ +1,  0, 7, 16 },
-		{ -1, +1, 3, 16 },
-		{  0, +1, 5, 16 },
-		{ +1, +1, 1, 16 },
-		{  0,  0, 0,  0 }
+		{ 0, +1, 7 },
+		{ 1, -1, 3 },
+		{ 1,  0, 5 },
+		{ 1, +1, 1 },
+		{ 0,  0, 0 }
 	};
 
+	DitherParams paramsAtkinson[] = {
+		{ 0, +1, 1 },
+		{ 0, +2, 1 },
+		{ 1, -1, 1 },
+		{ 1,  0, 1 },
+		{ 1, +1, 1 },
+		{ 2,  0, 1 },
+		{ 0,  0, 0 }
+	};
+
+	DitherParams paramsBurkes[] = {
+		{ 0, +1, 8 },
+		{ 0, +2, 4 },
+		{ 1, -2, 2 },
+		{ 1, -1, 4 },
+		{ 1,  0, 8 },
+		{ 1, +1, 4 },
+		{ 1, +2, 2 },
+		{ 0,  0, 0 }
+	};
+
+	DitherParams paramsFalseFloyd[] = {
+		{ 0, +1, 3 },
+		{ 1,  0, 3 },
+		{ 1, +1, 2 },
+		{ 0,  0, 0 }
+	};
+
+    DitherParams paramsSierra[] = {
+		{ 0,  1, 5 },
+		{ 0,  2, 3 },
+		{ 1, -2, 2 },
+		{ 1, -1, 4 },
+		{ 1,  0, 5 },
+		{ 1,  1, 4 },
+		{ 1,  2, 2 },
+		{ 2, -1, 2 },
+		{ 2,  0, 3 },
+		{ 2,  1, 2 },
+		{ 0,  0, 0 }
+    };
+
+    DitherParams paramsSierraTwoRow[] = {
+		{ 0,  1, 4 },
+		{ 0,  2, 3 },
+		{ 1, -2, 1 },
+		{ 1, -1, 2 },
+		{ 1,  0, 3 },
+		{ 1,  1, 2 },
+		{ 1,  2, 1 },
+		{ 0,  0, 0 }
+    };
+
+    DitherParams paramsSierraLite[] = {
+		{ 0,  1, 2 },
+		{ 1, -1, 1 },
+		{ 1,  0, 1 },
+		{ 0,  0, 0 }
+    };
+
+    DitherParams paramsStucki[] = {
+		{ 0,  1, 8 },
+		{ 0,  2, 4 },
+		{ 1, -2, 2 },
+		{ 1, -1, 4 },
+		{ 1,  0, 8 },
+		{ 1,  1, 4 },
+		{ 1,  2, 2 },
+		{ 2, -2, 1 },
+		{ 2, -1, 2 },
+		{ 2,  0, 4 },
+		{ 2,  1, 2 },
+		{ 2,  2, 1 },
+		{ 0,  0, 0 }
+    };
+
+    DitherParams paramsJarvis[] = {
+		{ 0,  1, 7 },
+		{ 0,  2, 5 },
+		{ 1, -2, 3 },
+		{ 1, -1, 5 },
+		{ 1,  0, 7 },
+		{ 1,  1, 5 },
+		{ 1,  2, 3 },
+		{ 2, -2, 1 },
+		{ 2, -1, 3 },
+		{ 2,  0, 5 },
+		{ 2,  1, 3 },
+		{ 2,  2, 1 },
+		{ 0,  0, 0 }
+    };
+
 	struct DitherAlgos {
 		const char *name;
 		DitherParams *params;
+		int qdiv;
 	} const algos[] = {
-		{ "Naive", paramsNaive },
-		{ "Floyd-Steinberg", paramsFloyd },
-		{ nullptr, nullptr }
+		{ "Naive",                paramsNaive,         1 },
+		{ "Floyd-Steinberg",      paramsFloyd,        16 },
+		{ "Atkinson",             paramsAtkinson,      8 },
+		{ "Burkes",               paramsBurkes,       32 },
+		{ "False Floyd-Steinberg",paramsFalseFloyd,    8 },
+		{ "Sierra",               paramsSierra,       32 },
+		{ "Sierra 2",             paramsSierraTwoRow, 16 },
+		{ "Sierra Lite",          paramsSierraLite,    4 },
+		{ "Stucki",               paramsStucki,       42 },
+		{ "Jarvis-Judice-Ninke ", paramsJarvis,       48 },
+		{ nullptr, nullptr, 0 }
 	};
 
 	enum {
 		kDitherNaive,
-		kDitherFloyd
+		kDitherFloyd,
+		kDitherAtkinson,
+		kDitherBurkes,
+		kDitherFalseFloyd,
+		kDitherSierra,
+		kDitherSierraTwoRow,
+		kDitherSierraLite,
+		kDitherStucki,
+		kDitherJarvis,
 	};
 
 	for (int y = 0; y < h; y++) {
@@ -463,7 +572,7 @@ void BitmapCastMember::ditherFloydImage() {
 			DitherParams *params = algos[algo].params;
 
 			for (int i = 0; params[i].dx != 0 || params[i].dy != 0; i++)
-				updatePixel(tmpSurf, x + params[i].dx, y + params[i].dy, w, h, qr, qg, qb, params[i].qq, params[i].qdiv);
+				updatePixel(tmpSurf, x + params[i].dx, y + params[i].dy, w, h, qr, qg, qb, params[i].qq, algos[algo].qdiv);
 
 			src += 3;
 			dst++;




More information about the Scummvm-git-logs mailing list