From 7fe39fcbe2b2af639aa166c123ae45f53d8de6a0 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 6 Apr 2010 03:19:20 +0000 Subject: [PATCH] Fixed bug in -auto-level for one value in channel situation. --- ChangeLog | 8 +++++++- magick/enhance.c | 8 ++++++-- magick/histogram.c | 27 +++++++++++++++++++-------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index ddb5aaa2b..914cd6593 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ +2010-04-06 6.6.1-1 Anthony Thyssen + * Fixed bug in -auto-level for special case when only one value is present + in some channel of the image. In this case no 'stretch is performed, just + as -normalize does. + 2010-04-05 6.6.1-1 Cristy - * WMF support under Windows does not produce the same results as under Linux. + * WMF support under Windows does not produce the same results as under + Linux. 2010-03-31 6.6.1-0 Anthony Thyssen * Fixed bug in equal-size tile cropping, when image has a page offset. diff --git a/magick/enhance.c b/magick/enhance.c index 629286a49..0b3d3ba0f 100644 --- a/magick/enhance.c +++ b/magick/enhance.c @@ -2545,7 +2545,7 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image, { #define LevelImageTag "Level/Image" #define LevelValue(x) (ClampToQuantum((MagickRealType) QuantumRange* \ - pow(((double) (x)-black_point)/(white_point-black_point),1.0/gamma))) + pow(scale*((double)(x)-black_point),1.0/gamma))) CacheView *image_view; @@ -2563,6 +2563,9 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image, register long i; + register double + scale; + /* Allocate and initialize levels map. */ @@ -2570,6 +2573,7 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image, assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); + scale = (white_point != black_point) ? 1.0/(white_point-black_point) : 1.0; if (image->storage_class == PseudoClass) #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(dynamic,4) shared(progress,status) @@ -2628,7 +2632,7 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image, q->blue=LevelValue(q->blue); if (((channel & OpacityChannel) != 0) && (image->matte == MagickTrue)) - q->opacity=LevelValue(q->opacity); + q->opacity=QuantumRange-LevelValue(QuantumRange-q->opacity); if (((channel & IndexChannel) != 0) && (image->colorspace == CMYKColorspace)) indexes[x]=LevelValue(indexes[x]); diff --git a/magick/histogram.c b/magick/histogram.c index 99bae916e..4de601760 100644 --- a/magick/histogram.c +++ b/magick/histogram.c @@ -959,6 +959,9 @@ MagickExport MagickBooleanType IsPaletteImage(const Image *image, % will be extracted from all the given channels, and those channels will be % stretched by exactly the same amount (preventing color distortion). % +% In the special case that only ONE value is found in a channel of the image +% that value is not stretched, that value is left as is. +% % The 'SyncChannels' is turned on in the 'DefaultChannels' setting by % default. % @@ -979,6 +982,7 @@ MagickExport MagickBooleanType IsPaletteImage(const Image *image, % from the minimum and maximum points by this color value. % */ + MagickExport MagickBooleanType MinMaxStretchImage(Image *image, const ChannelType channel,const double black_value,const double white_value) { @@ -988,6 +992,7 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image, MagickStatusType status; + status=MagickTrue; if ((channel & SyncChannels) != 0) { /* @@ -996,18 +1001,20 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image, (void) GetImageChannelRange(image,channel,&min,&max,&image->exception); min+=black_value; max-=white_value; - return(LevelImageChannel(image,channel,min,max,1.0)); + if ( fabs(min-max) >= MagickEpsilon ) + status = LevelImageChannel(image,channel,min,max,1.0); + return(status); } /* Auto-level each channel separately. */ - status=MagickTrue; if ((channel & RedChannel) != 0) { (void) GetImageChannelRange(image,RedChannel,&min,&max,&image->exception); min+=black_value; max-=white_value; - status&=LevelImageChannel(image,RedChannel,min,max,1.0); + if ( fabs(min-max) >= MagickEpsilon ) + status&=LevelImageChannel(image,RedChannel,min,max,1.0); } if ((channel & GreenChannel) != 0) { @@ -1015,7 +1022,8 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image, &image->exception); min+=black_value; max-=white_value; - status&=LevelImageChannel(image,GreenChannel,min,max,1.0); + if ( fabs(min-max) >= MagickEpsilon ) + status&=LevelImageChannel(image,GreenChannel,min,max,1.0); } if ((channel & BlueChannel) != 0) { @@ -1023,7 +1031,8 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image, &image->exception); min+=black_value; max-=white_value; - status&=LevelImageChannel(image,BlueChannel,min,max,1.0); + if ( fabs(min-max) >= MagickEpsilon ) + status&=LevelImageChannel(image,BlueChannel,min,max,1.0); } if (((channel & OpacityChannel) != 0) && (image->matte == MagickTrue)) @@ -1032,7 +1041,8 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image, &image->exception); min+=black_value; max-=white_value; - status&=LevelImageChannel(image,OpacityChannel,min,max,1.0); + if ( fabs(min-max) >= MagickEpsilon ) + status&=LevelImageChannel(image,OpacityChannel,min,max,1.0); } if (((channel & IndexChannel) != 0) && (image->colorspace == CMYKColorspace)) @@ -1041,9 +1051,10 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image, &image->exception); min+=black_value; max-=white_value; - status&=LevelImageChannel(image,IndexChannel,min,max,1.0); + if ( fabs(min-max) >= MagickEpsilon ) + status&=LevelImageChannel(image,IndexChannel,min,max,1.0); } - return(status != 0 ? MagickTrue : MagickFalse); + return(status); } /* -- 2.40.0