From b6d07d995f14e7559b1d92025e74f4ace166324e Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 2 Apr 2019 13:54:39 -0300 Subject: [PATCH] Fix error diffusion algorithm The error propagation must be limited to 0...255 values, and the new quantization error must be calculated to that limited value. Also the 1/16 part of the Floyd-Steinberg distribution must be the remaining of the other parts. --- src/render/error_diffusion.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/render/error_diffusion.cpp b/src/render/error_diffusion.cpp index 75f874114..49336e3f6 100644 --- a/src/render/error_diffusion.cpp +++ b/src/render/error_diffusion.cpp @@ -64,15 +64,14 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D( doc::rgba_getb(color), doc::rgba_geta(color) }; - int u[kChannels]; for (int i=0; imapColor(u[0], u[1], u[2], u[3]): - palette->findBestfit(u[0], u[1], u[2], u[3], m_transparentIndex)); + (rgbmap ? rgbmap->mapColor(v[0], v[1], v[2], v[3]): + palette->findBestfit(v[0], v[1], v[2], v[3], m_transparentIndex)); doc::color_t palColor = palette->getEntry(index); if (m_transparentIndex == index || doc::rgba_geta(palColor) == 0) { @@ -90,10 +89,17 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D( // TODO using Floyd-Steinberg matrix here but it should be configurable for (int i=0; i