From 7201f34e2417f86365dfd2dfe41ea8deabebdb87 Mon Sep 17 00:00:00 2001 From: dirk Date: Mon, 10 Oct 2016 12:27:42 +0200 Subject: [PATCH] Corrected parsing of the threshold map and fixed incorrect increment. --- MagickCore/threshold.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/MagickCore/threshold.c b/MagickCore/threshold.c index 200b25f8d..a23b832f5 100644 --- a/MagickCore/threshold.c +++ b/MagickCore/threshold.c @@ -1348,12 +1348,17 @@ MagickExport MagickBooleanType OrderedDitherImage(Image *image, levels[i]=2.0; p=strchr((char *) threshold_map,','); if ((p != (char *) NULL) && (isdigit((int) ((unsigned char) *(++p))) != 0)) - for (i=0; (*p != '\0') && (i < MaxPixelChannels); i++) { GetNextToken(p,&p,MagickPathExtent,token); - if (*token == ',') + for (i=0; (i < MaxPixelChannels); i++) + levels[i]=StringToDouble(token,(char **) NULL); + for (i=0; (*p != '\0') && (i < MaxPixelChannels); i++) + { GetNextToken(p,&p,MagickPathExtent,token); - levels[i]=StringToDouble(token,(char **) NULL); + if (*token == ',') + GetNextToken(p,&p,MagickPathExtent,token); + levels[i]=StringToDouble(token,(char **) NULL); + } } for (i=0; i < MaxPixelChannels; i++) if (fabs(levels[i]) >= 1) @@ -1407,8 +1412,11 @@ MagickExport MagickBooleanType OrderedDitherImage(Image *image, PixelTrait traits=GetPixelChannelTraits(image,channel); if ((traits & UpdatePixelTrait) == 0) continue; - if (fabs(levels[n++]) < MagickEpsilon) - continue; + if (fabs(levels[n]) < MagickEpsilon) + { + n++; + continue; + } threshold=(ssize_t) (QuantumScale*q[i]*(levels[n]*(map->divisor-1)+1)); level=threshold/(map->divisor-1); threshold-=level*(map->divisor-1); -- 2.40.0