From 54fb85855d49335513cc1f2766aeebcf7efcdae4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 May 2016 09:04:49 +0530 Subject: [PATCH] Off by one Also forgot to sum errors during propagation --- src/calibre/utils/imageops/quantize.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/utils/imageops/quantize.cpp b/src/calibre/utils/imageops/quantize.cpp index 14b013e461..664f7e5fd9 100644 --- a/src/calibre/utils/imageops/quantize.cpp +++ b/src/calibre/utils/imageops/quantize.cpp @@ -213,9 +213,9 @@ public: }; static inline void propagate_error(QVector &error_line, int c, unsigned char mult, DoublePixel &error) { - error_line[c].red = error.red * mult; - error_line[c].green = error.green * mult; - error_line[c].blue = error.blue * mult; + error_line[c].red += error.red * mult; + error_line[c].green += error.green * mult; + error_line[c].blue += error.blue * mult; } static inline QRgb apply_error(QRgb pixel, DoublePixel &error) { @@ -250,7 +250,7 @@ static void dither_image(const QImage &img, QImage &ans, QVector &color_ta line1 = is_odd ? &err2 : &err1; line2 = is_odd ? &err1 : &err2; line2->fill(zero); - for (c = start; 0 < (is_odd ? c : iwidth - c); c += delta) { + for (c = start; 0 < (is_odd ? c + 1 : iwidth - c); c += delta) { pixel = *(line + c); new_pixel = apply_error(pixel, (*line1)[c]); index = root.index_for_nearest_color(qRed(new_pixel), qGreen(new_pixel), qBlue(new_pixel), 0);