[Scummvm-git-logs] scummvm master -> 8fe6e28c72e02f541de615e31cc5c62ad1462f9c
sev-
noreply at scummvm.org
Thu Nov 3 18:06:15 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
8fe6e28c72 DIRECTOR: Use common dithering implementation
Commit: 8fe6e28c72e02f541de615e31cc5c62ad1462f9c
https://github.com/scummvm/scummvm/commit/8fe6e28c72e02f541de615e31cc5c62ad1462f9c
Author: Fedor Antokhin (uroboros5144 at gmail.com)
Date: 2022-11-03T19:06:11+01:00
Commit Message:
DIRECTOR: Use common dithering implementation
Changed paths:
engines/director/castmember.cpp
diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index 2f60c2523d2..3feb6075b30 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -252,7 +252,7 @@ Graphics::MacWidget *BitmapCastMember::createWidget(Common::Rect &bbox, Channel
#endif
) {
- ditherFloydImage();
+ _img->getSurface()->convertTo(g_director->_wm->_pixelformat, _img->getPalette(), srcBpp, g_director->_wm->getPalette(), dstBpp);
pal = g_director->_wm->getPalette();
}
@@ -358,236 +358,6 @@ void BitmapCastMember::ditherImage() {
}
}
-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 / 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() {
- // If palette did not change, do not re-dither
- if (!_paletteLookup.setPalette(g_director->_wm->getPalette(), g_director->_wm->getPaletteSize()))
- return;
-
- int w = _initialRect.width();
- int h = _initialRect.height();
-
- 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::ditherFloydImage(): Unsupported bit depth: %d", bpp);
- }
-
- dst[0] = r; dst[1] = g; dst[2] = b;
- dst += 3;
- }
- }
-
- _ditheredImg = new Graphics::Surface;
- _ditheredImg->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
-
- pal = g_director->_wm->getPalette();
-
- struct DitherParams {
- int dy, dx, qq;
- };
-
- DitherParams paramsNaive[] = {
- { 0, 0, 0 }
- };
-
- DitherParams paramsFloyd[] = {
- { 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, 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,
- kDitherAtkinson,
- kDitherBurkes,
- kDitherFalseFloyd,
- kDitherSierra,
- kDitherSierraTwoRow,
- kDitherSierraLite,
- kDitherStucki,
- kDitherJarvis,
- };
-
- for (int y = 0; y < h; y++) {
- const byte *src = &tmpSurf[y * w * 3];
- byte *dst = (byte *)_ditheredImg->getBasePtr(0, y);
-
- for (int x = 0; x < w; x++) {
- byte r = src[0], g = src[1], b = src[2];
- byte col = _paletteLookup.findBestColor(r, g, b);
-
- *dst = col;
-
- int qr = r - pal[col * 3 + 0];
- int qg = g - pal[col * 3 + 1];
- int qb = b - pal[col * 3 + 2];
-
- 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, algos[algo].qdiv);
-
- src += 3;
- dst++;
- }
- }
-
- free(tmpSurf);
-}
-
void BitmapCastMember::createMatte(Common::Rect &bbox) {
// Like background trans, but all white pixels NOT ENCLOSED by coloured pixels
// are transparent
More information about the Scummvm-git-logs
mailing list