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>
This commit is contained in:
Eirik Aavitsland 2018-04-04 09:17:16 +02:00
parent 0ee5cbb1a4
commit cab5f37ef4

View File

@ -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++;
}