Skip to content

Commit 8352b50

Browse files
author
dirk
committed
Changed arguments of RandomThresholdImage.
1 parent 95aca41 commit 8352b50

File tree

7 files changed

+50
-52
lines changed

7 files changed

+50
-52
lines changed

Magick++/lib/Image.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -3939,22 +3939,20 @@ void Magick::Image::raise(const Geometry &geometry_,const bool raisedFlag_)
39393939
ThrowImageException;
39403940
}
39413941

3942-
void Magick::Image::randomThreshold(const Geometry &thresholds_)
3942+
void Magick::Image::randomThreshold(const double low_,const double high_)
39433943
{
39443944
GetPPException;
3945-
(void) RandomThresholdImage(image(),static_cast<std::string>(
3946-
thresholds_).c_str(),exceptionInfo);
3945+
(void) RandomThresholdImage(image(),low_,high_,exceptionInfo);
39473946
ThrowImageException;
39483947
}
39493948

39503949
void Magick::Image::randomThresholdChannel(const ChannelType channel_,
3951-
const Geometry &thresholds_)
3950+
const double low_,const double high_)
39523951
{
39533952
modifyImage();
39543953
GetPPException;
39553954
GetAndSetPPChannelMask(channel_);
3956-
(void) RandomThresholdImage(image(),static_cast<std::string>(
3957-
thresholds_).c_str(),exceptionInfo);
3955+
(void) RandomThresholdImage(image(),low_,high_,exceptionInfo);
39583956
RestorePPChannelMask;
39593957
ThrowImageException;
39603958
}

Magick++/lib/Magick++/Image.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -1184,15 +1184,10 @@ namespace Magick
11841184
//
11851185
// Changes the value of individual pixels based on the intensity
11861186
// of each pixel compared to a random threshold. The result is a
1187-
// low-contrast, two color image. The thresholds_ argument is a
1188-
// geometry containing LOWxHIGH thresholds. If the string
1189-
// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1190-
// 3, or 4 will be performed instead. If a channel_ argument is
1191-
// specified then only the specified channel is altered. This is
1192-
// a very fast alternative to 'quantize' based dithering.
1193-
void randomThreshold(const Geometry &thresholds_);
1194-
void randomThresholdChannel(const ChannelType channel_,
1195-
const Geometry &thresholds_);
1187+
// low-contrast, two color image.
1188+
void randomThreshold(const double low_,const double high_);
1189+
void randomThresholdChannel(const ChannelType channel_,const double low_,
1190+
const double high_);
11961191

11971192
// Read single image frame from in-memory BLOB
11981193
void read(const Blob &blob_);

MagickCore/threshold.c

+3-28
Original file line numberDiff line numberDiff line change
@@ -1610,31 +1610,20 @@ MagickExport MagickBooleanType PerceptibleImage(Image *image,
16101610
%
16111611
% o image: the image.
16121612
%
1613-
% o thresholds: a geometry string containing low,high thresholds. If the
1614-
% string contains 2x2, 3x3, or 4x4, an ordered dither of order 2, 3, or 4
1615-
% is performed instead.
1613+
% o low,high: Specify the high and low thresholds. These values range from
1614+
% 0 to QuantumRange.
16161615
%
16171616
% o exception: return any errors or warnings in this structure.
16181617
%
16191618
*/
16201619
MagickExport MagickBooleanType RandomThresholdImage(Image *image,
1621-
const char *thresholds,ExceptionInfo *exception)
1620+
const double min_threshold, const double max_threshold,ExceptionInfo *exception)
16221621
{
16231622
#define ThresholdImageTag "Threshold/Image"
16241623

16251624
CacheView
16261625
*image_view;
16271626

1628-
double
1629-
min_threshold,
1630-
max_threshold;
1631-
1632-
GeometryInfo
1633-
geometry_info;
1634-
1635-
MagickStatusType
1636-
flags;
1637-
16381627
MagickBooleanType
16391628
status;
16401629

@@ -1661,23 +1650,9 @@ MagickExport MagickBooleanType RandomThresholdImage(Image *image,
16611650
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
16621651
assert(exception != (ExceptionInfo *) NULL);
16631652
assert(exception->signature == MagickCoreSignature);
1664-
if (thresholds == (const char *) NULL)
1665-
return(MagickTrue);
16661653
if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
16671654
return(MagickFalse);
16681655
GetPixelInfo(image,&threshold);
1669-
min_threshold=0.0;
1670-
max_threshold=(double) QuantumRange;
1671-
flags=ParseGeometry(thresholds,&geometry_info);
1672-
min_threshold=geometry_info.rho;
1673-
max_threshold=geometry_info.sigma;
1674-
if ((flags & SigmaValue) == 0)
1675-
max_threshold=min_threshold;
1676-
if (strchr(thresholds,'%') != (char *) NULL)
1677-
{
1678-
max_threshold*=(double) (0.01*QuantumRange);
1679-
min_threshold*=(double) (0.01*QuantumRange);
1680-
}
16811656
/*
16821657
Random threshold image.
16831658
*/

MagickCore/threshold.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern MagickExport MagickBooleanType
4040
ListThresholdMaps(FILE *,ExceptionInfo *),
4141
OrderedDitherImage(Image *,const char *,ExceptionInfo *),
4242
PerceptibleImage(Image *,const double,ExceptionInfo *),
43-
RandomThresholdImage(Image *,const char *,ExceptionInfo *),
43+
RandomThresholdImage(Image *,const double,const double,ExceptionInfo *),
4444
WhiteThresholdImage(Image *,const char *,ExceptionInfo *);
4545

4646
#if defined(__cplusplus) || defined(c_plusplus)

MagickWand/magick-image.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -8140,24 +8140,20 @@ WandExport MagickBooleanType MagickRaiseImage(MagickWand *wand,
81408140
%
81418141
% o wand: the magick wand.
81428142
%
8143-
% o low,high: Specify the high and low thresholds. These values range from
8143+
% o low,high: Specify the high and low thresholds. These values range from
81448144
% 0 to QuantumRange.
81458145
%
81468146
*/
81478147
WandExport MagickBooleanType MagickRandomThresholdImage(MagickWand *wand,
81488148
const double low,const double high)
81498149
{
8150-
char
8151-
threshold[MagickPathExtent];
8152-
81538150
assert(wand != (MagickWand *) NULL);
81548151
assert(wand->signature == MagickWandSignature);
81558152
if (wand->debug != MagickFalse)
81568153
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
81578154
if (wand->images == (Image *) NULL)
81588155
ThrowWandException(WandError,"ContainsNoImages",wand->name);
8159-
(void) FormatLocaleString(threshold,MagickPathExtent,"%gx%g",low,high);
8160-
return(RandomThresholdImage(wand->images,threshold,wand->exception));
8156+
return(RandomThresholdImage(wand->images,low,high,wand->exception));
81618157
}
81628158

81638159
/*

MagickWand/mogrify.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -2533,8 +2533,25 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
25332533
/*
25342534
Threshold image.
25352535
*/
2536+
double
2537+
min_threshold,
2538+
max_threshold;
2539+
25362540
(void) SyncImageSettings(mogrify_info,*image,exception);
2537-
(void) RandomThresholdImage(*image,argv[i+1],exception);
2541+
min_threshold=0.0;
2542+
max_threshold=(double) QuantumRange;
2543+
flags=ParseGeometry(argv[i+1],&geometry_info);
2544+
min_threshold=geometry_info.rho;
2545+
max_threshold=geometry_info.sigma;
2546+
if ((flags & SigmaValue) == 0)
2547+
max_threshold=min_threshold;
2548+
if (strchr(argv[i+1],'%') != (char *) NULL)
2549+
{
2550+
max_threshold*=(double) (0.01*QuantumRange);
2551+
min_threshold*=(double) (0.01*QuantumRange);
2552+
}
2553+
(void) RandomThresholdImage(*image,min_threshold,max_threshold,
2554+
exception);
25382555
break;
25392556
}
25402557
if (LocaleCompare("read-mask",option+1) == 0)

MagickWand/operation.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -3060,9 +3060,26 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
30603060
}
30613061
if (LocaleCompare("random-threshold",option+1) == 0)
30623062
{
3063+
double
3064+
min_threshold,
3065+
max_threshold;
3066+
30633067
if (IsGeometry(arg1) == MagickFalse)
30643068
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
3065-
(void) RandomThresholdImage(_image,arg1,_exception);
3069+
min_threshold=0.0;
3070+
max_threshold=(double) QuantumRange;
3071+
flags=ParseGeometry(arg1,&geometry_info);
3072+
min_threshold=geometry_info.rho;
3073+
max_threshold=geometry_info.sigma;
3074+
if ((flags & SigmaValue) == 0)
3075+
max_threshold=min_threshold;
3076+
if (strchr(arg1,'%') != (char *) NULL)
3077+
{
3078+
max_threshold*=(double) (0.01*QuantumRange);
3079+
min_threshold*=(double) (0.01*QuantumRange);
3080+
}
3081+
(void) RandomThresholdImage(_image,min_threshold,max_threshold,
3082+
_exception);
30663083
break;
30673084
}
30683085
if (LocaleCompare("read-mask",option+1) == 0)

0 commit comments

Comments
 (0)