summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2018-04-04 09:17:16 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2018-04-06 06:40:37 +0000
commitcab5f37ef48d996529416913d912e8e8a2b061f5 (patch)
tree58e46da53097015053a3eee5ccfe6bf5262c119d /src
parent0ee5cbb1a449e05270454dfb6151438b04a5cb84 (diff)
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 <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qimage_conversions.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index 4eef617336..1b4d3e63dd 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++;
}