From cab5f37ef48d996529416913d912e8e8a2b061f5 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 4 Apr 2018 09:17:16 +0200 Subject: [PATCH] Fix visual artifacts in diffuse image dithering (the default) The distributed error fractions in the Floyd-Steinberg dithering algorithm were not computed precisely. In particular, rounding errors could be accumulated, leading to visual artifacts. Task-number: QTBUG-67425 Change-Id: I77b48c3cab3e66ca161721d14b58fcc4188e74a8 Reviewed-by: Allan Sandfeld Jensen --- src/gui/image/qimage_conversions.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 4eef6173364..1b4d3e63ddd 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -1333,14 +1333,18 @@ void dither_to_Mono(QImageData *dst, const QImageData *src, } else { bit--; } + const int e7 = ((err * 7) + 8) >> 4; + const int e5 = ((err * 5) + 8) >> 4; + const int e3 = ((err * 3) + 8) >> 4; + const int e1 = err - (e7 + e5 + e3); if (x < w) - *b1 += (err*7)>>4; // spread error to right pixel + *b1 += e7; // spread error to right pixel if (not_last_line) { - b2[0] += (err*5)>>4; // pixel below + b2[0] += e5; // pixel below if (x > 1) - b2[-1] += (err*3)>>4; // pixel below left + b2[-1] += e3; // pixel below left if (x < w) - b2[1] += err>>4; // pixel below right + b2[1] += e1; // pixel below right } b2++; }