From 49dd6a0c1bab5e1e6f99369c0f70a5e0184810d4 Mon Sep 17 00:00:00 2001 From: cristy Date: Sat, 24 Sep 2011 23:08:01 +0000 Subject: [PATCH] --- MagickCore/compare.c | 78 ++++++++--- MagickCore/statistic.c | 299 ++++++++++++++--------------------------- coders/dpx.c | 3 +- 3 files changed, 157 insertions(+), 223 deletions(-) diff --git a/MagickCore/compare.c b/MagickCore/compare.c index 2c55e8ec8..39910e251 100644 --- a/MagickCore/compare.c +++ b/MagickCore/compare.c @@ -115,9 +115,6 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image, *difference_image, *highlight_image; - ssize_t - y; - MagickBooleanType status; @@ -125,6 +122,9 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image, highlight, lowlight; + ssize_t + y; + assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) @@ -193,12 +193,12 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image, *restrict p, *restrict q; - register ssize_t - x; - register Quantum *restrict r; + register ssize_t + x; + if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); @@ -236,6 +236,8 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; if (fabs(p[i]-(double) q[channel]) >= MagickEpsilon) difference=MagickTrue; } @@ -365,6 +367,8 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; if (p[i] != q[channel]) difference=MagickTrue; } @@ -387,12 +391,12 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image, return(status); } -static size_t GetNumberChannels(const Image *image) +static size_t GetImageChannels(const Image *image) { register ssize_t i; - ssize_t + size_t channels; channels=0; @@ -477,6 +481,8 @@ static MagickBooleanType GetFuzzDistortion(const Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distance=QuantumScale*(p[i]-(MagickRealType) q[channel]); distance*=distance; channel_distortion[i]+=distance; @@ -495,7 +501,7 @@ static MagickBooleanType GetFuzzDistortion(const Image *image, image_view=DestroyCacheView(image_view); for (i=0; i <= MaxPixelChannels; i++) distortion[i]/=((double) image->columns*image->rows); - distortion[MaxPixelChannels]/=(double) GetNumberChannels(image); + distortion[MaxPixelChannels]/=(double) GetImageChannels(image); distortion[MaxPixelChannels]=sqrt(distortion[MaxPixelChannels]); return(status); } @@ -569,6 +575,8 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distance=QuantumScale*fabs(p[i]-(double) q[channel]); channel_distortion[i]+=distance; channel_distortion[MaxPixelChannels]+=distance; @@ -586,7 +594,7 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image, image_view=DestroyCacheView(image_view); for (i=0; i <= MaxPixelChannels; i++) distortion[i]/=((double) image->columns*image->rows); - distortion[MaxPixelChannels]/=(double) GetNumberChannels(image); + distortion[MaxPixelChannels]/=(double) GetImageChannels(image); return(status); } @@ -658,6 +666,8 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distance=fabs(alpha*p[i]-beta*q[channel]); distortion[i]+=distance; distortion[MaxPixelChannels]+=distance; @@ -747,6 +757,8 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distance=QuantumScale*(p[i]-(MagickRealType) q[channel]); distance*=distance; channel_distortion[i]+=distance; @@ -765,7 +777,7 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image, image_view=DestroyCacheView(image_view); for (i=0; i <= MaxPixelChannels; i++) distortion[i]/=((double) image->columns*image->rows); - distortion[MaxPixelChannels]/=GetNumberChannels(image); + distortion[MaxPixelChannels]/=GetImageChannels(image); return(status); } @@ -849,6 +861,8 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion( if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distortion[i]+=area*QuantumScale*(p[i]-image_statistics[i].mean)* (q[channel]-reconstruct_statistics[channel].mean); } @@ -888,7 +902,7 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion( distortion[MaxPixelChannels]+=distortion[i]*distortion[i]; } distortion[MaxPixelChannels]=sqrt(distortion[MaxPixelChannels]/ - GetNumberChannels(image)); + GetImageChannels(image)); /* Free resources. */ @@ -965,6 +979,8 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distance=QuantumScale*fabs(p[i]-(double) q[channel]); if (distance > channel_distortion[i]) channel_distortion[i]=distance; @@ -1370,6 +1386,8 @@ MagickExport MagickBooleanType IsImagesEqual(Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distance=fabs(p[i]-(double) q[channel]); mean_error_per_pixel+=distance; mean_error+=distance*distance; @@ -1500,6 +1518,8 @@ static double GetNCCDistortion(const Image *image, if ((traits == UndefinedPixelTrait) || (reconstruct_traits == UndefinedPixelTrait)) continue; + if ((reconstruct_traits & UpdatePixelTrait) == 0) + continue; distortion+=area*QuantumScale*(p[i]-image_statistics[i].mean)* (q[channel]-reconstruct_statistics[channel].mean); } @@ -1516,7 +1536,7 @@ static double GetNCCDistortion(const Image *image, reconstruct_statistics[MaxPixelChannels].standard_deviation; gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); distortion=QuantumRange*gamma*distortion; - distortion=sqrt(distortion/GetNumberChannels(image)); + distortion=sqrt(distortion/GetImageChannels(image)); /* Free resources. */ @@ -1609,12 +1629,12 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference, double similarity; - register ssize_t - x; - register Quantum *restrict q; + register ssize_t + x; + if (status == MagickFalse) continue; q=GetCacheViewAuthenticPixels(similarity_view,0,y,similarity_image->columns, @@ -1626,6 +1646,9 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference, } for (x=0; x < (ssize_t) (image->columns-reference->columns+1); x++) { + register ssize_t + i; + similarity=GetSimilarityMetric(image,reference,reference_statistics,x,y, exception); #if defined(MAGICKCORE_OPENMP_SUPPORT) @@ -1637,10 +1660,25 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference, offset->x=x; offset->y=y; } - SetPixelRed(similarity_image,ClampToQuantum(QuantumRange- - QuantumRange*similarity),q); - SetPixelGreen(similarity_image,GetPixelRed(image,q),q); - SetPixelBlue(similarity_image,GetPixelRed(image,q),q); + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelChannel + channel; + + PixelTrait + similarity_traits, + traits; + + traits=GetPixelChannelMapTraits(image,(PixelChannel) i); + channel=GetPixelChannelMapChannel(image,(PixelChannel) i); + similarity_traits=GetPixelChannelMapTraits(similarity_image,channel); + if ((traits == UndefinedPixelTrait) || + (similarity_traits == UndefinedPixelTrait)) + continue; + if ((similarity_traits & UpdatePixelTrait) == 0) + continue; + q[channel]=ClampToQuantum(QuantumRange-QuantumRange*similarity); + } q+=GetPixelChannels(similarity_image); } if (SyncCacheViewAuthenticPixels(similarity_view,exception) == MagickFalse) diff --git a/MagickCore/statistic.c b/MagickCore/statistic.c index 14c88740e..a8da9b1fe 100644 --- a/MagickCore/statistic.c +++ b/MagickCore/statistic.c @@ -166,8 +166,7 @@ static PixelInfo **AcquirePixelThreadSet(const Image *image, length=image->columns; if (length < number_images) length=number_images; - pixels[i]=(PixelInfo *) AcquireQuantumMemory(length, - sizeof(**pixels)); + pixels[i]=(PixelInfo *) AcquireQuantumMemory(length,sizeof(**pixels)); if (pixels[i] == (PixelInfo *) NULL) return(DestroyPixelThreadSet(pixels)); for (j=0; j < (ssize_t) length; j++) @@ -239,9 +238,9 @@ static MagickRealType ApplyEvaluateOperator(RandomInfo *random_info, { /* This returns a 'floored modulus' of the addition which is a - positive result. It differs from % or fmod() which returns a - 'truncated modulus' result, where floor() is replaced by trunc() - and could return a negative result (which is clipped). + positive result. It differs from % or fmod() that returns a + 'truncated modulus' result, where floor() is replaced by trunc() and + could return a negative result (which is clipped). */ result=pixel+value; result-=(QuantumRange+1.0)*floor((double) result/(QuantumRange+1.0)); @@ -756,28 +755,20 @@ MagickExport MagickBooleanType EvaluateImage(Image *image, } for (x=0; x < (ssize_t) image->columns; x++) { - if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) - SetPixelRed(image,ClampToQuantum(ApplyEvaluateOperator( - random_info[id],GetPixelRed(image,q),op,value)),q); - if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) - SetPixelGreen(image,ClampToQuantum(ApplyEvaluateOperator( - random_info[id],GetPixelGreen(image,q),op,value)),q); - if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) - SetPixelBlue(image,ClampToQuantum(ApplyEvaluateOperator( - random_info[id],GetPixelBlue(image,q),op,value)),q); - if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) && - (image->colorspace == CMYKColorspace)) - SetPixelBlack(image,ClampToQuantum(ApplyEvaluateOperator( - random_info[id],GetPixelBlack(image,q),op,value)),q); - if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) - { - if (image->matte == MagickFalse) - SetPixelAlpha(image,ClampToQuantum(ApplyEvaluateOperator( - random_info[id],GetPixelAlpha(image,q),op,value)),q); - else - SetPixelAlpha(image,ClampToQuantum(ApplyEvaluateOperator( - random_info[id],GetPixelAlpha(image,q),op,value)),q); - } + register ssize_t + i; + + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelTrait + traits; + + traits=GetPixelChannelMapTraits(image,(PixelChannel) i); + if (traits == UndefinedPixelTrait) + continue; + q[i]=ClampToQuantum(ApplyEvaluateOperator(random_info[id],q[i],op, + value)); + } q+=GetPixelChannels(image); } if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) @@ -1110,53 +1101,53 @@ MagickExport MagickBooleanType GetImageMean(const Image *image,double *mean, if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) { channel_statistics[MaxPixelChannels].mean+= - channel_statistics[RedChannel].mean; + channel_statistics[RedPixelChannel].mean; channel_statistics[MaxPixelChannels].standard_deviation+= - channel_statistics[RedChannel].variance- - channel_statistics[RedChannel].mean* - channel_statistics[RedChannel].mean; + channel_statistics[RedPixelChannel].variance- + channel_statistics[RedPixelChannel].mean* + channel_statistics[RedPixelChannel].mean; channels++; } if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) { channel_statistics[MaxPixelChannels].mean+= - channel_statistics[GreenChannel].mean; + channel_statistics[GreenPixelChannel].mean; channel_statistics[MaxPixelChannels].standard_deviation+= - channel_statistics[GreenChannel].variance- - channel_statistics[GreenChannel].mean* - channel_statistics[GreenChannel].mean; + channel_statistics[GreenPixelChannel].variance- + channel_statistics[GreenPixelChannel].mean* + channel_statistics[GreenPixelChannel].mean; channels++; } if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) { channel_statistics[MaxPixelChannels].mean+= - channel_statistics[BlueChannel].mean; + channel_statistics[BluePixelChannel].mean; channel_statistics[MaxPixelChannels].standard_deviation+= - channel_statistics[BlueChannel].variance- - channel_statistics[BlueChannel].mean* - channel_statistics[BlueChannel].mean; + channel_statistics[BluePixelChannel].variance- + channel_statistics[BluePixelChannel].mean* + channel_statistics[BluePixelChannel].mean; channels++; } if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) && (image->colorspace == CMYKColorspace)) { channel_statistics[MaxPixelChannels].mean+= - channel_statistics[BlackChannel].mean; + channel_statistics[BlackPixelChannel].mean; channel_statistics[MaxPixelChannels].standard_deviation+= - channel_statistics[BlackChannel].variance- - channel_statistics[BlackChannel].mean* - channel_statistics[BlackChannel].mean; + channel_statistics[BlackPixelChannel].variance- + channel_statistics[BlackPixelChannel].mean* + channel_statistics[BlackPixelChannel].mean; channels++; } if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) && (image->matte != MagickFalse)) { channel_statistics[MaxPixelChannels].mean+= - channel_statistics[AlphaChannel].mean; + channel_statistics[AlphaPixelChannel].mean; channel_statistics[MaxPixelChannels].standard_deviation+= - channel_statistics[AlphaChannel].variance- - channel_statistics[AlphaChannel].mean* - channel_statistics[AlphaChannel].mean; + channel_statistics[AlphaPixelChannel].variance- + channel_statistics[AlphaPixelChannel].mean* + channel_statistics[AlphaPixelChannel].mean; channels++; } channel_statistics[MaxPixelChannels].mean/=channels; @@ -1437,7 +1428,7 @@ MagickExport MagickBooleanType GetImageRange(const Image *image,double *minima, % mean, for example, like this: % % channel_statistics=GetImageStatistics(image,exception); -% red_mean=channel_statistics[RedChannel].mean; +% red_mean=channel_statistics[RedPixelChannel].mean; % % Use MagickRelinquishMemory() to free the statistics buffer. % @@ -1453,6 +1444,28 @@ MagickExport MagickBooleanType GetImageRange(const Image *image,double *minima, % o exception: return any errors or warnings in this structure. % */ + +static size_t GetImageChannels(const Image *image) +{ + register ssize_t + i; + + size_t + channels; + + channels=0; + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelTrait + traits; + + traits=GetPixelChannelMapTraits(image,(PixelChannel) i); + if ((traits & UpdatePixelTrait) != 0) + channels++; + } + return(channels); +} + MagickExport ChannelStatistics *GetImageStatistics(const Image *image, ExceptionInfo *exception) { @@ -1473,8 +1486,7 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, size_t channels, - depth, - length; + depth; ssize_t y; @@ -1483,12 +1495,11 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); - length=MaxPixelChannels+1UL; - channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(length, - sizeof(*channel_statistics)); + channel_statistics=(ChannelStatistics *) AcquireQuantumMemory( + MaxPixelChannels+1,sizeof(*channel_statistics)); if (channel_statistics == (ChannelStatistics *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - (void) ResetMagickMemory(channel_statistics,0,length* + (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)* sizeof(*channel_statistics)); for (i=0; i <= (ssize_t) MaxPixelChannels; i++) { @@ -1507,150 +1518,40 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, p=GetVirtualPixels(image,0,y,image->columns,1,exception); if (p == (const Quantum *) NULL) break; - for (x=0; x < (ssize_t) image->columns; ) + for (x=0; x < (ssize_t) image->columns; x++) { - if (channel_statistics[RedChannel].depth != MAGICKCORE_QUANTUM_DEPTH) - { - depth=channel_statistics[RedChannel].depth; - range=GetQuantumRange(depth); - status=GetPixelRed(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( - GetPixelRed(image,p),range),range) ? MagickTrue : MagickFalse; - if (status != MagickFalse) - { - channel_statistics[RedChannel].depth++; - continue; - } - } - if (channel_statistics[GreenChannel].depth != MAGICKCORE_QUANTUM_DEPTH) - { - depth=channel_statistics[GreenChannel].depth; - range=GetQuantumRange(depth); - status=GetPixelGreen(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( - GetPixelGreen(image,p),range),range) ? MagickTrue : MagickFalse; - if (status != MagickFalse) - { - channel_statistics[GreenChannel].depth++; - continue; - } - } - if (channel_statistics[BlueChannel].depth != MAGICKCORE_QUANTUM_DEPTH) - { - depth=channel_statistics[BlueChannel].depth; - range=GetQuantumRange(depth); - status=GetPixelBlue(image,p) != ScaleAnyToQuantum(ScaleQuantumToAny( - GetPixelBlue(image,p),range),range) ? MagickTrue : MagickFalse; - if (status != MagickFalse) - { - channel_statistics[BlueChannel].depth++; - continue; - } - } - if (image->matte != MagickFalse) - { - if (channel_statistics[AlphaChannel].depth != MAGICKCORE_QUANTUM_DEPTH) - { - depth=channel_statistics[AlphaChannel].depth; - range=GetQuantumRange(depth); - status=GetPixelAlpha(image,p) != ScaleAnyToQuantum( - ScaleQuantumToAny(GetPixelAlpha(image,p),range),range) ? - MagickTrue : MagickFalse; - if (status != MagickFalse) - { - channel_statistics[AlphaChannel].depth++; - continue; - } - } + register ssize_t + i; + + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelTrait + traits; + + traits=GetPixelChannelMapTraits(image,(PixelChannel) i); + if (traits == UndefinedPixelTrait) + continue; + if (channel_statistics[i].depth != MAGICKCORE_QUANTUM_DEPTH) + { + depth=channel_statistics[i].depth; + range=GetQuantumRange(depth); + status=p[i] != ScaleAnyToQuantum(ScaleQuantumToAny(p[i],range), + range) ? MagickTrue : MagickFalse; + if (status != MagickFalse) + { + channel_statistics[i].depth++; + continue; + } } - if (image->colorspace == CMYKColorspace) - { - if (channel_statistics[BlackChannel].depth != MAGICKCORE_QUANTUM_DEPTH) - { - depth=channel_statistics[BlackChannel].depth; - range=GetQuantumRange(depth); - status=GetPixelBlack(image,p) != ScaleAnyToQuantum( - ScaleQuantumToAny(GetPixelBlack(image,p),range),range) ? - MagickTrue : MagickFalse; - if (status != MagickFalse) - { - channel_statistics[BlackChannel].depth++; - continue; - } - } - } - if ((double) GetPixelRed(image,p) < channel_statistics[RedChannel].minima) - channel_statistics[RedChannel].minima=(double) GetPixelRed(image,p); - if ((double) GetPixelRed(image,p) > channel_statistics[RedChannel].maxima) - channel_statistics[RedChannel].maxima=(double) GetPixelRed(image,p); - channel_statistics[RedChannel].sum+=GetPixelRed(image,p); - channel_statistics[RedChannel].sum_squared+=(double) - GetPixelRed(image,p)*GetPixelRed(image,p); - channel_statistics[RedChannel].sum_cubed+=(double) - GetPixelRed(image,p)*GetPixelRed(image,p)*GetPixelRed(image,p); - channel_statistics[RedChannel].sum_fourth_power+=(double) - GetPixelRed(image,p)*GetPixelRed(image,p)*GetPixelRed(image,p)* - GetPixelRed(image,p); - if ((double) GetPixelGreen(image,p) < channel_statistics[GreenChannel].minima) - channel_statistics[GreenChannel].minima=(double) - GetPixelGreen(image,p); - if ((double) GetPixelGreen(image,p) > channel_statistics[GreenChannel].maxima) - channel_statistics[GreenChannel].maxima=(double) GetPixelGreen(image,p); - channel_statistics[GreenChannel].sum+=GetPixelGreen(image,p); - channel_statistics[GreenChannel].sum_squared+=(double) - GetPixelGreen(image,p)*GetPixelGreen(image,p); - channel_statistics[GreenChannel].sum_cubed+=(double) - GetPixelGreen(image,p)*GetPixelGreen(image,p)*GetPixelGreen(image,p); - channel_statistics[GreenChannel].sum_fourth_power+=(double) - GetPixelGreen(image,p)*GetPixelGreen(image,p)*GetPixelGreen(image,p)* - GetPixelGreen(image,p); - if ((double) GetPixelBlue(image,p) < channel_statistics[BlueChannel].minima) - channel_statistics[BlueChannel].minima=(double) GetPixelBlue(image,p); - if ((double) GetPixelBlue(image,p) > channel_statistics[BlueChannel].maxima) - channel_statistics[BlueChannel].maxima=(double) GetPixelBlue(image,p); - channel_statistics[BlueChannel].sum+=GetPixelBlue(image,p); - channel_statistics[BlueChannel].sum_squared+=(double) - GetPixelBlue(image,p)*GetPixelBlue(image,p); - channel_statistics[BlueChannel].sum_cubed+=(double) - GetPixelBlue(image,p)*GetPixelBlue(image,p)*GetPixelBlue(image,p); - channel_statistics[BlueChannel].sum_fourth_power+=(double) - GetPixelBlue(image,p)*GetPixelBlue(image,p)*GetPixelBlue(image,p)* - GetPixelBlue(image,p); - if (image->colorspace == CMYKColorspace) - { - if ((double) GetPixelBlack(image,p) < channel_statistics[BlackChannel].minima) - channel_statistics[BlackChannel].minima=(double) - GetPixelBlack(image,p); - if ((double) GetPixelBlack(image,p) > channel_statistics[BlackChannel].maxima) - channel_statistics[BlackChannel].maxima=(double) - GetPixelBlack(image,p); - channel_statistics[BlackChannel].sum+=GetPixelBlack(image,p); - channel_statistics[BlackChannel].sum_squared+=(double) - GetPixelBlack(image,p)*GetPixelBlack(image,p); - channel_statistics[BlackChannel].sum_cubed+=(double) - GetPixelBlack(image,p)*GetPixelBlack(image,p)* - GetPixelBlack(image,p); - channel_statistics[BlackChannel].sum_fourth_power+=(double) - GetPixelBlack(image,p)*GetPixelBlack(image,p)* - GetPixelBlack(image,p)*GetPixelBlack(image,p); - } - if (image->matte != MagickFalse) - { - if ((double) GetPixelAlpha(image,p) < channel_statistics[AlphaChannel].minima) - channel_statistics[AlphaChannel].minima=(double) - GetPixelAlpha(image,p); - if ((double) GetPixelAlpha(image,p) > channel_statistics[AlphaChannel].maxima) - channel_statistics[AlphaChannel].maxima=(double) - GetPixelAlpha(image,p); - channel_statistics[AlphaChannel].sum+=GetPixelAlpha(image,p); - channel_statistics[AlphaChannel].sum_squared+=(double) - GetPixelAlpha(image,p)*GetPixelAlpha(image,p); - channel_statistics[AlphaChannel].sum_cubed+=(double) - GetPixelAlpha(image,p)*GetPixelAlpha(image,p)* - GetPixelAlpha(image,p); - channel_statistics[AlphaChannel].sum_fourth_power+=(double) - GetPixelAlpha(image,p)*GetPixelAlpha(image,p)* - GetPixelAlpha(image,p)*GetPixelAlpha(image,p); - } - x++; + if ((double) p[i] < channel_statistics[i].minima) + channel_statistics[i].minima=(double) p[i]; + if ((double) p[i] > channel_statistics[i].maxima) + channel_statistics[i].maxima=(double) p[i]; + channel_statistics[i].sum+=p[i]; + channel_statistics[i].sum_squared+=(double) p[i]*p[i]; + channel_statistics[i].sum_cubed+=(double) p[i]*p[i]*p[i]; + channel_statistics[i].sum_fourth_power+=(double) p[i]*p[i]*p[i]*p[i]; + } p+=GetPixelChannels(image); } } @@ -1693,11 +1594,7 @@ MagickExport ChannelStatistics *GetImageStatistics(const Image *image, channel_statistics[i].variance-channel_statistics[i].mean* channel_statistics[i].mean; } - channels=3; - if (image->matte != MagickFalse) - channels++; - if (image->colorspace == CMYKColorspace) - channels++; + channels=GetImageChannels(image); channel_statistics[MaxPixelChannels].sum/=channels; channel_statistics[MaxPixelChannels].sum_squared/=channels; channel_statistics[MaxPixelChannels].sum_cubed/=channels; diff --git a/coders/dpx.c b/coders/dpx.c index 7cb751ae1..93ad8fccc 100644 --- a/coders/dpx.c +++ b/coders/dpx.c @@ -1426,8 +1426,7 @@ static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image, dpx.file.project); value=GetDPXProperty(image_info,image,"dpx:file.copyright"); if (value != (const char *) NULL) - (void) strncpy(dpx.file.copyright,value, - sizeof(dpx.file.copyright)); + (void) strncpy(dpx.file.copyright,value,sizeof(dpx.file.copyright)); offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *) dpx.file.copyright); dpx.file.encrypt_key=(~0U); -- 2.40.0