[Scummvm-git-logs] scummvm master -> 18c88fabfef537ebcca1ecd1864302fbb7cd8be7

sev- noreply at scummvm.org
Wed Sep 28 21:02:25 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:
18c88fabfe GRAPHICS: Add possibility to specify dithering algorithm. Default is Floyd-Steinberg


Commit: 18c88fabfef537ebcca1ecd1864302fbb7cd8be7
    https://github.com/scummvm/scummvm/commit/18c88fabfef537ebcca1ecd1864302fbb7cd8be7
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-09-28T23:02:05+02:00

Commit Message:
GRAPHICS: Add possibility to specify dithering algorithm. Default is Floyd-Steinberg

Changed paths:
    graphics/surface.cpp
    graphics/surface.h


diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index be72069231b..2e86094ed3a 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -517,7 +517,7 @@ void Surface::convertToInPlace(const PixelFormat &dstFormat, const byte *palette
 	pitch = w * dstFormat.bytesPerPixel;
 }
 
-Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte *srcPalette, int srcPaletteCount, const byte *dstPalette, int dstPaletteCount) const {
+Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte *srcPalette, int srcPaletteCount, const byte *dstPalette, int dstPaletteCount, DitherMethod method) const {
 	assert(pixels);
 
 	Graphics::Surface *surface = new Graphics::Surface();
@@ -545,7 +545,7 @@ Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte *
 
 	// We are here when we are converting from a higher bpp or palettes are different
 	if (dstFormat.bytesPerPixel == 1) {
-		ditherFloyd(srcPalette, srcPaletteCount, surface, dstPalette, dstPaletteCount);
+		ditherFloyd(srcPalette, srcPaletteCount, surface, dstPalette, dstPaletteCount, method);
 		return surface;
 	}
 
@@ -719,7 +719,7 @@ static void updatePixel(byte *surf, int x, int y, int w, int h, int qr, int qg,
 	ptr[2] = CLIP(ptr[2] + qb * qq / qdiv, 0, 255);
 }
 
-void Surface::ditherFloyd(const byte *srcPalette, int srcPaletteCount, Surface *dstSurf, const byte *dstPalette, int dstPaletteCount) const {
+void Surface::ditherFloyd(const byte *srcPalette, int srcPaletteCount, Surface *dstSurf, const byte *dstPalette, int dstPaletteCount, DitherMethod method) const {
 	assert(dstPalette);
 
 	PaletteLookup _paletteLookup;
@@ -904,11 +904,10 @@ void Surface::ditherFloyd(const byte *srcPalette, int srcPaletteCount, Surface *
 			int qg = g - dstPalette[col * 3 + 1];
 			int qb = b - dstPalette[col * 3 + 2];
 
-			int algo = kDitherFloyd;
-			const DitherParams *params = algos[algo].params;
+			const DitherParams *params = algos[method].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);
+				updatePixel(tmpSurf, x + params[i].dx, y + params[i].dy, w, h, qr, qg, qb, params[i].qq, algos[method].qdiv);
 
 			src += 3;
 			dst++;
diff --git a/graphics/surface.h b/graphics/surface.h
index 7e25c7f8d41..d4d4661209a 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -46,7 +46,7 @@ namespace Graphics {
 
 struct TransformStruct;
 
-enum {
+enum DitherMethod {
 	kDitherNaive,
 	kDitherFloyd,
 	kDitherAtkinson,
@@ -351,13 +351,17 @@ public:
 	 * The client code must call @ref free on the returned surface and then delete
 	 * it.
 	 *
-	 * @param dstFormat  The desired format.
-	 * @param palette    The palette (in RGB888), if the source format has a bpp of 1.
+	 * @param dstFormat   The desired format.
+	 * @param srcPalette  The palette (in RGB888), if the source format has a bpp of 1.
+	 * @param srcPaletteCount The color count in the for the srcPalette.
+	 * @param dstPalette  The palette (in RGB888), If the destination format has a bpp of 1.
+	 * @param dstaletteCount The color count in the for the dstPalette.
+	 * @param method      The dithering method if destination format has a bpp of 1. Default is Floyd-Steinberg.
 	 */
-	Graphics::Surface *convertTo(const PixelFormat &dstFormat, const byte *srcPalette = 0, int srcPaletteCount = 0, const byte *dstPalette = 0, int dstPaletteCount = 0) const;
+	Graphics::Surface *convertTo(const PixelFormat &dstFormat, const byte *srcPalette = 0, int srcPaletteCount = 0, const byte *dstPalette = 0, int dstPaletteCount = 0, DitherMethod method = kDitherFloyd) const;
 
 private:
-	void ditherFloyd(const byte *srcPalette, int srcPaletteCount, Surface *dstSurf, const byte *dstPalette, int dstPaletteCount) const;
+	void ditherFloyd(const byte *srcPalette, int srcPaletteCount, Surface *dstSurf, const byte *dstPalette, int dstPaletteCount, DitherMethod method) const;
 
 public:
 




More information about the Scummvm-git-logs mailing list