From d680338de12af5ad866696d865f491a5a1962f5b Mon Sep 17 00:00:00 2001 From: cristy Date: Tue, 10 Apr 2012 01:41:25 +0000 Subject: [PATCH] --- MagickCore/fx.c | 6 ++ MagickCore/threshold.c | 136 +++++++++++++++++++---------------------- 2 files changed, 68 insertions(+), 74 deletions(-) diff --git a/MagickCore/fx.c b/MagickCore/fx.c index 9e542abbd..46875b6be 100644 --- a/MagickCore/fx.c +++ b/MagickCore/fx.c @@ -757,6 +757,12 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend, GetPixelInfo(image,&pixel); for (x=0; x < (ssize_t) image->columns; x++) { + if (GetPixelMask(colorize_image,q) != 0) + { + p+=GetPixelChannels(image); + q+=GetPixelChannels(colorize_image); + continue; + } GetPixelInfoPixel(image,p,&pixel); Colorize(pixel.red,blend_percentage.red,colorize->red); Colorize(pixel.green,blend_percentage.green,colorize->green); diff --git a/MagickCore/threshold.c b/MagickCore/threshold.c index 8a3204499..286cde85f 100644 --- a/MagickCore/threshold.c +++ b/MagickCore/threshold.c @@ -483,6 +483,8 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image, const char *thresholds,ExceptionInfo *exception) { #define ThresholdImageTag "Threshold/Image" +#define BlackThreshold(pixel,threshold_percentage) \ + if (pixel < threshold_percentage) pixel=QuantumRange; CacheView *image_view; @@ -496,15 +498,12 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image, MagickOffsetType progress; - MagickRealType - threshold[5]; + PixelInfo + threshold_percentage; MagickStatusType flags; - register ssize_t - i; - ssize_t y; @@ -518,20 +517,26 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image, return(MagickFalse); if (IsGrayColorspace(image->colorspace) != MagickFalse) (void) TransformImageColorspace(image,sRGBColorspace,exception); + GetPixelInfo(image,&threshold_percentage); flags=ParseGeometry(thresholds,&geometry_info); - for (i=0; i < 5; i++) - threshold[i]=geometry_info.rho; + threshold_percentage.red=geometry_info.rho; + threshold_percentage.green=geometry_info.rho; + threshold_percentage.blue=geometry_info.rho; + threshold_percentage.black=geometry_info.rho; + threshold_percentage.alpha=100.0; if ((flags & SigmaValue) != 0) - threshold[1]=geometry_info.sigma; + threshold_percentage.green=geometry_info.sigma; if ((flags & XiValue) != 0) - threshold[2]=geometry_info.xi; + threshold_percentage.blue=geometry_info.xi; if ((flags & PsiValue) != 0) - threshold[3]=geometry_info.psi; - if ((flags & ChiValue) != 0) - threshold[4]=geometry_info.chi; - if ((flags & PercentValue) != 0) - for (i=0; i < 5; i++) - threshold[i]*=(QuantumRange/100.0); + threshold_percentage.alpha=geometry_info.psi; + if (threshold_percentage.colorspace == CMYKColorspace) + { + if ((flags & PsiValue) != 0) + threshold_percentage.black=geometry_info.psi; + if ((flags & ChiValue) != 0) + threshold_percentage.alpha=geometry_info.chi; + } /* White threshold image. */ @@ -543,6 +548,9 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image, #endif for (y=0; y < (ssize_t) image->rows; y++) { + PixelInfo + pixel; + register ssize_t x; @@ -557,35 +565,21 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image, status=MagickFalse; continue; } + GetPixelInfo(image,&pixel); for (x=0; x < (ssize_t) image->columns; x++) { - register ssize_t - i; - - ssize_t - n; - if (GetPixelMask(image,q) != 0) { q+=GetPixelChannels(image); continue; } - n=0; - for (i=0; i < (ssize_t) GetPixelChannels(image); i++) - { - PixelChannel - channel; - - PixelTrait - traits; - - channel=GetPixelChannelMapChannel(image,i); - traits=GetPixelChannelMapTraits(image,channel); - if ((traits & UpdatePixelTrait) == 0) - continue; - if ((MagickRealType) q[i] < threshold[n++ % 5]) - q[i]=QuantumRange; - } + GetPixelInfoPixel(image,q,&pixel); + BlackThreshold(pixel.red,threshold_percentage.red); + BlackThreshold(pixel.green,threshold_percentage.green); + BlackThreshold(pixel.blue,threshold_percentage.blue); + BlackThreshold(pixel.black,threshold_percentage.black); + BlackThreshold(pixel.alpha,threshold_percentage.alpha); + SetPixelInfoPixel(image,&pixel,q); q+=GetPixelChannels(image); } if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) @@ -1603,6 +1597,8 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image, const char *thresholds,ExceptionInfo *exception) { #define ThresholdImageTag "Threshold/Image" +#define WhiteThreshold(pixel,threshold_percentage) \ + if (pixel > threshold_percentage) pixel=QuantumRange; CacheView *image_view; @@ -1616,15 +1612,12 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image, MagickOffsetType progress; - MagickRealType - threshold[5]; + PixelInfo + threshold_percentage; MagickStatusType flags; - register ssize_t - i; - ssize_t y; @@ -1638,20 +1631,26 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image, return(MagickFalse); if (IsGrayColorspace(image->colorspace) != MagickFalse) (void) TransformImageColorspace(image,sRGBColorspace,exception); + GetPixelInfo(image,&threshold_percentage); flags=ParseGeometry(thresholds,&geometry_info); - for (i=0; i < 5; i++) - threshold[i]=geometry_info.rho; + threshold_percentage.red=geometry_info.rho; + threshold_percentage.green=geometry_info.rho; + threshold_percentage.blue=geometry_info.rho; + threshold_percentage.black=geometry_info.rho; + threshold_percentage.alpha=100.0; if ((flags & SigmaValue) != 0) - threshold[1]=geometry_info.sigma; + threshold_percentage.green=geometry_info.sigma; if ((flags & XiValue) != 0) - threshold[2]=geometry_info.xi; + threshold_percentage.blue=geometry_info.xi; if ((flags & PsiValue) != 0) - threshold[3]=geometry_info.psi; - if ((flags & ChiValue) != 0) - threshold[4]=geometry_info.chi; - if ((flags & PercentValue) != 0) - for (i=0; i < 5; i++) - threshold[i]*=(QuantumRange/100.0); + threshold_percentage.alpha=geometry_info.psi; + if (threshold_percentage.colorspace == CMYKColorspace) + { + if ((flags & PsiValue) != 0) + threshold_percentage.black=geometry_info.psi; + if ((flags & ChiValue) != 0) + threshold_percentage.alpha=geometry_info.chi; + } /* White threshold image. */ @@ -1663,6 +1662,9 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image, #endif for (y=0; y < (ssize_t) image->rows; y++) { + PixelInfo + pixel; + register ssize_t x; @@ -1677,35 +1679,21 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image, status=MagickFalse; continue; } + GetPixelInfo(image,&pixel); for (x=0; x < (ssize_t) image->columns; x++) { - register ssize_t - i; - - ssize_t - n; - if (GetPixelMask(image,q) != 0) { q+=GetPixelChannels(image); continue; } - n=0; - for (i=0; i < (ssize_t) GetPixelChannels(image); i++) - { - PixelChannel - channel; - - PixelTrait - traits; - - channel=GetPixelChannelMapChannel(image,i); - traits=GetPixelChannelMapTraits(image,channel); - if ((traits & UpdatePixelTrait) == 0) - continue; - if ((MagickRealType) q[i] > threshold[n++ % 5]) - q[i]=QuantumRange; - } + GetPixelInfoPixel(image,q,&pixel); + WhiteThreshold(pixel.red,threshold_percentage.red); + WhiteThreshold(pixel.green,threshold_percentage.green); + WhiteThreshold(pixel.blue,threshold_percentage.blue); + WhiteThreshold(pixel.black,threshold_percentage.black); + WhiteThreshold(pixel.alpha,threshold_percentage.alpha); + SetPixelInfoPixel(image,&pixel,q); q+=GetPixelChannels(image); } if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) -- 2.40.0