From 5048d30ffd6670a4b4c9986bbcb46b228afdd884 Mon Sep 17 00:00:00 2001 From: cristy Date: Tue, 7 Aug 2012 01:05:16 +0000 Subject: [PATCH] --- MagickCore/fx.c | 33 ++++++++++++++++++++++----------- MagickCore/property.c | 4 ++-- MagickCore/statistic.c | 38 ++++++++++++++++---------------------- MagickCore/statistic.h | 1 + MagickWand/identify.c | 10 ++++++++++ utilities/identify.1.in | 1 + 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/MagickCore/fx.c b/MagickCore/fx.c index b845f0b2a..63a5edcf6 100644 --- a/MagickCore/fx.c +++ b/MagickCore/fx.c @@ -1128,9 +1128,12 @@ static inline double MagickMin(const double x,const double y) return(y); } -static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image, +static MagickRealType FxChannelStatistics(FxInfo *fx_info,Image *image, PixelChannel channel,const char *symbol,ExceptionInfo *exception) { + ChannelType + channel_mask; + char key[MaxTextExtent], statistic[MaxTextExtent]; @@ -1141,24 +1144,30 @@ static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image, register const char *p; + channel_mask=UndefinedChannel; for (p=symbol; (*p != '.') && (*p != '\0'); p++) ; if (*p == '.') - switch (*++p) /* e.g. depth.r */ { - case 'r': channel=RedPixelChannel; break; - case 'g': channel=GreenPixelChannel; break; - case 'b': channel=BluePixelChannel; break; - case 'c': channel=CyanPixelChannel; break; - case 'm': channel=MagentaPixelChannel; break; - case 'y': channel=YellowPixelChannel; break; - case 'k': channel=BlackPixelChannel; break; - default: break; + ssize_t + option; + + option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1); + if (option >= 0) + { + channel=(PixelChannel) option; + channel_mask=(ChannelType) (channel_mask | (1 << channel)); + SetPixelChannelMapMask(image,channel_mask); + } } (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image, (double) channel,symbol); value=(const char *) GetValueFromSplayTree(fx_info->symbols,key); if (value != (const char *) NULL) - return(QuantumScale*StringToDouble(value,(char **) NULL)); + { + if (channel_mask != UndefinedChannel) + SetPixelChannelMapMask(image,channel_mask); + return(QuantumScale*StringToDouble(value,(char **) NULL)); + } (void) DeleteNodeFromSplayTree(fx_info->symbols,key); if (LocaleNCompare(symbol,"depth",5) == 0) { @@ -1223,6 +1232,8 @@ static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image, (void) FormatLocaleString(statistic,MaxTextExtent,"%g", standard_deviation); } + if (channel_mask != UndefinedChannel) + SetPixelChannelMapMask(image,channel_mask); (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key), ConstantString(statistic)); return(QuantumScale*StringToDouble(statistic,(char **) NULL)); diff --git a/MagickCore/property.c b/MagickCore/property.c index cef97d07a..e02a1c855 100644 --- a/MagickCore/property.c +++ b/MagickCore/property.c @@ -3673,8 +3673,8 @@ MagickExport MagickBooleanType SetImageProperty(Image *image, (LocaleCompare("min",property) == 0) || (LocaleCompare("min",property) == 0) ) { - (void) ThrowMagickException(exception,GetMagickModule(), - OptionError,"SetReadOnlyProperty","'%s'",property); + (void) ThrowMagickException(exception,GetMagickModule(),OptionError, + "SetReadOnlyProperty","'%s'",property); status=MagickFalse; break; } diff --git a/MagickCore/statistic.c b/MagickCore/statistic.c index 71e16dfb0..14130fa8d 100644 --- a/MagickCore/statistic.c +++ b/MagickCore/statistic.c @@ -1180,8 +1180,8 @@ MagickExport MagickBooleanType GetImageExtrema(const Image *image, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% GetImageMean() returns the mean and standard deviation of one or more -% image channels. +% GetImageMean() returns the mean and standard deviation of one or more image +% channels. % % The format of the GetImageMean method is: % @@ -1202,15 +1202,15 @@ MagickExport MagickBooleanType GetImageExtrema(const Image *image, MagickExport MagickBooleanType GetImageMean(const Image *image,double *mean, double *standard_deviation,ExceptionInfo *exception) { + double + area; + ChannelStatistics *channel_statistics; register ssize_t i; - size_t - area; - assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) @@ -1218,7 +1218,7 @@ MagickExport MagickBooleanType GetImageMean(const Image *image,double *mean, channel_statistics=GetImageStatistics(image,exception); if (channel_statistics == (ChannelStatistics *) NULL) return(MagickFalse); - area=0; + area=0.0; channel_statistics[CompositePixelChannel].mean=0.0; channel_statistics[CompositePixelChannel].standard_deviation=0.0; for (i=0; i < (ssize_t) GetPixelChannels(image); i++) @@ -1528,10 +1528,10 @@ MagickExport MagickBooleanType GetImageRange(const Image *image,double *minima, % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% GetImageStatistics() returns statistics for each channel in the -% image. The statistics include the channel depth, its minima, maxima, mean, -% standard deviation, kurtosis and skewness. You can access the red channel -% mean, for example, like this: +% GetImageStatistics() returns statistics for each channel in the image. The +% statistics include the channel depth, its minima, maxima, mean, standard +% deviation, kurtosis and skewness. You can access the red channel mean, for +% example, like this: % % channel_statistics=GetImageStatistics(image,exception); % red_mean=channel_statistics[RedPixelChannel].mean; @@ -1582,9 +1582,6 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, ChannelStatistics *channel_statistics; - double - area; - MagickStatusType initialize, status; @@ -1613,11 +1610,7 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)* sizeof(*channel_statistics)); for (i=0; i <= (ssize_t) MaxPixelChannels; i++) - { channel_statistics[i].depth=1; - channel_statistics[i].maxima=0.0; - channel_statistics[i].minima=0.0; - } initialize=MagickTrue; for (y=0; y < (ssize_t) image->rows; y++) { @@ -1683,17 +1676,18 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, channel_statistics[channel].sum_cubed+=(double) p[i]*p[i]*p[i]; channel_statistics[channel].sum_fourth_power+=(double) p[i]*p[i]*p[i]* p[i]; + channel_statistics[channel].area++; } p+=GetPixelChannels(image); } } - area=(double) image->columns*image->rows; for (i=0; i < (ssize_t) MaxPixelChannels; i++) { - channel_statistics[i].sum/=area; - channel_statistics[i].sum_squared/=area; - channel_statistics[i].sum_cubed/=area; - channel_statistics[i].sum_fourth_power/=area; + if (channel_statistics[i].area != 0.0) + channel_statistics[i].sum/=channel_statistics[i].area; + channel_statistics[i].sum_squared/=channel_statistics[i].area; + channel_statistics[i].sum_cubed/=channel_statistics[i].area; + channel_statistics[i].sum_fourth_power/=channel_statistics[i].area; channel_statistics[i].mean=channel_statistics[i].sum; channel_statistics[i].variance=channel_statistics[i].sum_squared; channel_statistics[i].standard_deviation=sqrt( diff --git a/MagickCore/statistic.h b/MagickCore/statistic.h index 4fd9cd2e4..1a39b65ab 100644 --- a/MagickCore/statistic.h +++ b/MagickCore/statistic.h @@ -28,6 +28,7 @@ typedef struct _ChannelStatistics depth; double + area, minima, maxima, sum, diff --git a/MagickWand/identify.c b/MagickWand/identify.c index f294c9a93..95f5c4d12 100644 --- a/MagickWand/identify.c +++ b/MagickWand/identify.c @@ -132,6 +132,7 @@ static MagickBooleanType IdentifyUsage(void) "-interlace type type of image interlacing scheme", "-interpolate method pixel color interpolation method", "-limit type value pixel cache resource limit", + "-mask filename associate a mask with the image", "-monitor monitor progress", "-ping efficiently determine image attributes", "-quiet suppress all warning messages", @@ -678,6 +679,15 @@ WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info, } case 'm': { + if (LocaleCompare("mask",option+1) == 0) + { + if (*option == '+') + break; + i++; + if (i == (ssize_t) (argc-1)) + ThrowIdentifyException(OptionError,"MissingArgument",option); + break; + } if (LocaleCompare("matte",option+1) == 0) break; if (LocaleCompare("monitor",option+1) == 0) diff --git a/utilities/identify.1.in b/utilities/identify.1.in index 91fba829b..1f8d3c3e0 100644 --- a/utilities/identify.1.in +++ b/utilities/identify.1.in @@ -28,6 +28,7 @@ Image Settings: \-limit type value pixel cache resource limit \-list type Color, Configure, Delegate, Format, Magic, Module, Resource, or Type + \-mask filename associate a mask with the image \-matte store matte channel if the image has one \-monitor monitor progress \-ping efficiently determine image attributes -- 2.50.1