const char *thresholds,ExceptionInfo *exception)
{
#define ThresholdImageTag "Threshold/Image"
+#define BlackThreshold(pixel,threshold_percentage) \
+ if (pixel < threshold_percentage) pixel=QuantumRange;
CacheView
*image_view;
MagickOffsetType
progress;
- MagickRealType
- threshold[5];
+ PixelInfo
+ threshold_percentage;
MagickStatusType
flags;
- register ssize_t
- i;
-
ssize_t
y;
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.
*/
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
+ PixelInfo
+ pixel;
+
register ssize_t
x;
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)
const char *thresholds,ExceptionInfo *exception)
{
#define ThresholdImageTag "Threshold/Image"
+#define WhiteThreshold(pixel,threshold_percentage) \
+ if (pixel > threshold_percentage) pixel=QuantumRange;
CacheView
*image_view;
MagickOffsetType
progress;
- MagickRealType
- threshold[5];
+ PixelInfo
+ threshold_percentage;
MagickStatusType
flags;
- register ssize_t
- i;
-
ssize_t
y;
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.
*/
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
+ PixelInfo
+ pixel;
+
register ssize_t
x;
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)