% July 1992 %
% %
% %
-% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
Include declarations.
*/
#include "MagickCore/studio.h"
+#include "MagickCore/accelerate-private.h"
#include "MagickCore/artifact.h"
#include "MagickCore/attribute.h"
#include "MagickCore/cache.h"
gamma=log(mean*QuantumScale)/log_mean;
status&=LevelImage(image,0.0,(double) QuantumRange,gamma,exception);
(void) SetImageChannelMask(image,channel_mask);
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
break;
}
return(status != 0 ? MagickTrue : MagickFalse);
Compute slope and intercept.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
alpha=contrast;
slope=tan((double) (MagickPI*(alpha/100.0+1.0)/4.0));
y;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(clut_image != (Image *) NULL);
- assert(clut_image->signature == MagickSignature);
- if( IfMagickFalse(SetImageStorageClass(image,DirectClass,exception)) )
+ assert(clut_image->signature == MagickCoreSignature);
+ if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
return(MagickFalse);
- if( IfMagickTrue(IsGrayColorspace(image->colorspace)) &&
- IfMagickFalse(IsGrayColorspace(clut_image->colorspace)))
+ if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+ (IsGrayColorspace(clut_image->colorspace) == MagickFalse))
(void) SetImageColorspace(image,sRGBColorspace,exception);
clut_map=(PixelInfo *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*clut_map));
if (clut_map == (PixelInfo *) NULL)
{
GetPixelInfo(clut_image,clut_map+i);
(void) InterpolatePixelInfo(clut_image,clut_view,method,
- QuantumScale*i*(clut_image->columns-adjust),QuantumScale*i*
- (clut_image->rows-adjust),clut_map+i,exception);
+ (double) i*(clut_image->columns-adjust)/MaxMap,(double) i*
+ (clut_image->rows-adjust)/MaxMap,clut_map+i,exception);
}
clut_view=DestroyCacheView(clut_view);
image_view=AcquireAuthenticCacheView(image,exception);
pixel;
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
GetPixelInfo(image,&pixel);
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (GetPixelReadMask(image,q) == 0)
+ PixelTrait
+ traits;
+
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
GetPixelInfoPixel(image,q,&pixel);
- pixel.red=clut_map[ScaleQuantumToMap(
- ClampToQuantum(pixel.red))].red;
- pixel.green=clut_map[ScaleQuantumToMap(
- ClampToQuantum(pixel.green))].green;
- pixel.blue=clut_map[ScaleQuantumToMap(
- ClampToQuantum(pixel.blue))].blue;
- pixel.black=clut_map[ScaleQuantumToMap(
- ClampToQuantum(pixel.black))].black;
- pixel.alpha=clut_map[ScaleQuantumToMap(
- ClampToQuantum(pixel.alpha))].alpha;
- SetPixelInfoPixel(image,&pixel,q);
+ traits=GetPixelChannelTraits(image,RedPixelChannel);
+ if ((traits & UpdatePixelTrait) != 0)
+ pixel.red=clut_map[ScaleQuantumToMap(ClampToQuantum(
+ pixel.red))].red;
+ traits=GetPixelChannelTraits(image,GreenPixelChannel);
+ if ((traits & UpdatePixelTrait) != 0)
+ pixel.green=clut_map[ScaleQuantumToMap(ClampToQuantum(
+ pixel.green))].green;
+ traits=GetPixelChannelTraits(image,BluePixelChannel);
+ if ((traits & UpdatePixelTrait) != 0)
+ pixel.blue=clut_map[ScaleQuantumToMap(ClampToQuantum(
+ pixel.blue))].blue;
+ traits=GetPixelChannelTraits(image,BlackPixelChannel);
+ if ((traits & UpdatePixelTrait) != 0)
+ pixel.black=clut_map[ScaleQuantumToMap(ClampToQuantum(
+ pixel.black))].black;
+ traits=GetPixelChannelTraits(image,AlphaPixelChannel);
+ if ((traits & UpdatePixelTrait) != 0)
+ pixel.alpha=clut_map[ScaleQuantumToMap(ClampToQuantum(
+ pixel.alpha))].alpha;
+ SetPixelViaPixelInfo(image,&pixel,q);
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_ClutImage)
#endif
proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
image_view=DestroyCacheView(image_view);
clut_map=(PixelInfo *) RelinquishMagickMemory(clut_map);
- if ((clut_image->alpha_trait == BlendPixelTrait) &&
+ if ((clut_image->alpha_trait != UndefinedPixelTrait) &&
((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0))
(void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
return(status);
*image_view;
char
- token[MaxTextExtent];
+ token[MagickPathExtent];
ColorCorrection
color_correction;
Allocate and initialize cdl maps.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (color_correction_collection == (const char *) NULL)
return(MagickFalse);
p=(const char *) content;
for (i=0; (*p != '\0') && (i < 3); i++)
{
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
if (*token == ',')
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
switch (i)
{
case 0:
p=(const char *) content;
for (i=0; (*p != '\0') && (i < 3); i++)
{
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
if (*token == ',')
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
switch (i)
{
case 0:
p=(const char *) content;
for (i=0; (*p != '\0') && (i < 3); i++)
{
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
if (*token == ',')
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
switch (i)
{
case 0:
{
content=GetXMLTreeContent(saturation);
p=(const char *) content;
- GetMagickToken(p,&p,token);
+ GetNextToken(p,&p,MagickPathExtent,token);
color_correction.saturation=StringToDouble(token,(char **) NULL);
}
}
ccc=DestroyXMLTree(ccc);
- if( IfMagickTrue(image->debug) )
+ if (image->debug != MagickFalse)
{
(void) LogMagickEvent(TransformEvent,GetMagickModule(),
" Color Correction Collection:");
luma;
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
(cdl_map[ScaleQuantumToMap(GetPixelBlue(image,q))].blue-luma)),q);
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,ColorDecisionListCorrectImageTag,
progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
y;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+ if (AccelerateContrastImage(image,sharpen,exception) != MagickFalse)
+ return(MagickTrue);
+#endif
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- sign=IfMagickTrue(sharpen) ? 1 : -1;
+ sign=sharpen != MagickFalse ? 1 : -1;
if (image->storage_class == PseudoClass)
{
/*
green,
red;
+ red=(double) image->colormap[i].red;
+ green=(double) image->colormap[i].green;
+ blue=(double) image->colormap[i].blue;
Contrast(sign,&red,&green,&blue);
image->colormap[i].red=(MagickRealType) red;
image->colormap[i].green=(MagickRealType) green;
red;
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
SetPixelBlue(image,ClampToQuantum(blue),q);
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_ContrastImage)
#endif
proceed=SetImageProgress(image,ContrastImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
CacheView
*image_view;
- MagickBooleanType
- status;
-
- MagickOffsetType
- progress;
-
double
*black,
*histogram,
*stretch_map,
*white;
+ MagickBooleanType
+ status;
+
+ MagickOffsetType
+ progress;
+
register ssize_t
i;
- size_t
- number_channels;
-
ssize_t
y;
Allocate histogram and stretch map.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ if (SetImageGray(image,exception) != MagickFalse)
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
black=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*black));
white=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*white));
histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,GetPixelChannels(image)*
/*
Form histogram.
*/
- if( IfMagickTrue(IsImageGray(image,exception)) )
- (void) SetImageColorspace(image,GRAYColorspace,exception);
status=MagickTrue;
(void) ResetMagickMemory(histogram,0,(MaxMap+1)*GetPixelChannels(image)*
sizeof(*histogram));
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
- *restrict p;
+ *magick_restrict p;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
double
pixel;
- register ssize_t
- i;
-
pixel=GetPixelIntensity(image,p);
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
/*
Find the histogram boundaries by locating the black/white levels.
*/
- number_channels=GetPixelChannels(image);
- for (i=0; i < (ssize_t) number_channels; i++)
+ for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
double
intensity;
*/
(void) ResetMagickMemory(stretch_map,0,(MaxMap+1)*GetPixelChannels(image)*
sizeof(*stretch_map));
- number_channels=GetPixelChannels(image);
- for (i=0; i < (ssize_t) number_channels; i++)
+ for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
register ssize_t
j;
for (j=0; j <= (ssize_t) MaxMap; j++)
{
+ double
+ gamma;
+
+ gamma=PerceptibleReciprocal(white[i]-black[i]);
if (j < (ssize_t) black[i])
stretch_map[GetPixelChannels(image)*j+i]=0.0;
else
if (j > (ssize_t) white[i])
stretch_map[GetPixelChannels(image)*j+i]=(double) QuantumRange;
else
- if (black[i] != white[i])
- stretch_map[GetPixelChannels(image)*j+i]=(double) ScaleMapToQuantum(
- (double) (MaxMap*(j-black[i])/(white[i]-black[i])));
+ stretch_map[GetPixelChannels(image)*j+i]=(double) ScaleMapToQuantum(
+ (double) (MaxMap*gamma*(j-black[i])));
}
}
if (image->storage_class == PseudoClass)
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
{
- i=GetPixelChannelChannel(image,RedPixelChannel);
- if (black[i] != white[i])
- image->colormap[j].red=stretch_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))]+i;
+ i=GetPixelChannelOffset(image,RedPixelChannel);
+ image->colormap[j].red=stretch_map[GetPixelChannels(image)*
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))+i];
}
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
{
- i=GetPixelChannelChannel(image,GreenPixelChannel);
- if (black[i] != white[i])
- image->colormap[j].green=stretch_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))]+i;
+ i=GetPixelChannelOffset(image,GreenPixelChannel);
+ image->colormap[j].green=stretch_map[GetPixelChannels(image)*
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))+i];
}
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
{
- i=GetPixelChannelChannel(image,BluePixelChannel);
- if (black[i] != white[i])
- image->colormap[j].blue=stretch_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))]+i;
+ i=GetPixelChannelOffset(image,BluePixelChannel);
+ image->colormap[j].blue=stretch_map[GetPixelChannels(image)*
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))+i];
}
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
{
- i=GetPixelChannelChannel(image,AlphaPixelChannel);
- if (black[i] != white[i])
- image->colormap[j].alpha=stretch_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))]+i;
+ i=GetPixelChannelOffset(image,AlphaPixelChannel);
+ image->colormap[j].alpha=stretch_map[GetPixelChannels(image)*
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))+i];
}
}
}
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
- if (((traits & UpdatePixelTrait) == 0) || (black[i] == white[i]))
+ if ((traits & UpdatePixelTrait) == 0)
continue;
- q[i]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
- ScaleQuantumToMap(q[i])+i]);
+ q[j]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
+ ScaleQuantumToMap(q[j])+j]);
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,ContrastStretchImageTag,progress++,
image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
*/
MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
{
+#define EnhanceImageTag "Enhance/Image"
#define EnhancePixel(weight) \
- mean=((double) r[i]+GetPixelChannel(enhance_image,channel,q))/2.0; \
- distance=(double) r[i]-(double) GetPixelChannel(enhance_image,channel,q); \
- distance_squared=QuantumScale*(2.0*((double) QuantumRange+1.0)+mean)* \
- distance*distance; \
- if (distance_squared < ((double) QuantumRange*(double) QuantumRange/25.0f)) \
+ mean=QuantumScale*((double) GetPixelRed(image,r)+pixel.red)/2.0; \
+ distance=QuantumScale*((double) GetPixelRed(image,r)-pixel.red); \
+ distance_squared=(4.0+mean)*distance*distance; \
+ mean=QuantumScale*((double) GetPixelGreen(image,r)+pixel.green)/2.0; \
+ distance=QuantumScale*((double) GetPixelGreen(image,r)-pixel.green); \
+ distance_squared+=(7.0-mean)*distance*distance; \
+ mean=QuantumScale*((double) GetPixelBlue(image,r)+pixel.blue)/2.0; \
+ distance=QuantumScale*((double) GetPixelBlue(image,r)-pixel.blue); \
+ distance_squared+=(5.0-mean)*distance*distance; \
+ mean=QuantumScale*((double) GetPixelBlack(image,r)+pixel.black)/2.0; \
+ distance=QuantumScale*((double) GetPixelBlack(image,r)-pixel.black); \
+ distance_squared+=(5.0-mean)*distance*distance; \
+ mean=QuantumScale*((double) GetPixelAlpha(image,r)+pixel.alpha)/2.0; \
+ distance=QuantumScale*((double) GetPixelAlpha(image,r)-pixel.alpha); \
+ distance_squared+=(5.0-mean)*distance*distance; \
+ if (distance_squared < 0.069) \
{ \
- aggregate+=(weight)*r[i]; \
+ aggregate.red+=(weight)*GetPixelRed(image,r); \
+ aggregate.green+=(weight)*GetPixelGreen(image,r); \
+ aggregate.blue+=(weight)*GetPixelBlue(image,r); \
+ aggregate.black+=(weight)*GetPixelBlack(image,r); \
+ aggregate.alpha+=(weight)*GetPixelAlpha(image,r); \
total_weight+=(weight); \
} \
r+=GetPixelChannels(image);
-#define EnhanceImageTag "Enhance/Image"
CacheView
*enhance_view,
Initialize enhanced image attributes.
*/
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
enhance_image=CloneImage(image,image->columns,image->rows,MagickTrue,
exception);
if (enhance_image == (Image *) NULL)
return((Image *) NULL);
- if( IfMagickFalse(SetImageStorageClass(enhance_image,DirectClass,exception)) )
+ if (SetImageStorageClass(enhance_image,DirectClass,exception) == MagickFalse)
{
enhance_image=DestroyImage(enhance_image);
return((Image *) NULL);
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
+ PixelInfo
+ pixel;
+
register const Quantum
- *restrict p;
+ *magick_restrict p;
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
ssize_t
center;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
p=GetCacheViewVirtualPixels(image_view,-2,y-2,image->columns+4,5,exception);
q=QueueCacheViewAuthenticPixels(enhance_view,0,y,enhance_image->columns,1,
continue;
}
center=(ssize_t) GetPixelChannels(image)*(2*(image->columns+4)+2);
+ GetPixelInfo(image,&pixel);
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
+ double
+ distance,
+ distance_squared,
+ mean,
+ total_weight;
+
+ PixelInfo
+ aggregate;
+
+ register const Quantum
+ *magick_restrict r;
- if (GetPixelReadMask(image,p) == 0)
+ if (GetPixelWriteMask(image,p) == 0)
{
SetPixelBackgoundColor(enhance_image,q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(enhance_image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- double
- aggregate,
- distance,
- distance_squared,
- mean,
- total_weight;
-
- register const Quantum
- *restrict r;
-
- PixelChannel channel=GetPixelChannelChannel(image,i);
- PixelTrait traits=GetPixelChannelTraits(image,channel);
- PixelTrait enhance_traits=GetPixelChannelTraits(enhance_image,channel);
- if ((traits == UndefinedPixelTrait) ||
- (enhance_traits == UndefinedPixelTrait))
- continue;
- SetPixelChannel(enhance_image,channel,p[center+i],q);
- if ((enhance_traits & CopyPixelTrait) != 0)
- continue;
- /*
- Compute weighted average of target pixel color components.
- */
- aggregate=0.0;
- total_weight=0.0;
- r=p;
- EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
- EnhancePixel(8.0); EnhancePixel(5.0);
- r=p+1*GetPixelChannels(image)*(image->columns+4);
- EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
- EnhancePixel(20.0); EnhancePixel(8.0);
- r=p+2*GetPixelChannels(image)*(image->columns+4);
- EnhancePixel(10.0); EnhancePixel(40.0); EnhancePixel(80.0);
- EnhancePixel(40.0); EnhancePixel(10.0);
- r=p+3*GetPixelChannels(image)*(image->columns+4);
- EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
- EnhancePixel(20.0); EnhancePixel(8.0);
- r=p+4*GetPixelChannels(image)*(image->columns+4);
- EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
- EnhancePixel(8.0); EnhancePixel(5.0);
- SetPixelChannel(enhance_image,channel,ClampToQuantum(aggregate/
- total_weight),q);
- }
+ GetPixelInfo(image,&aggregate);
+ total_weight=0.0;
+ GetPixelInfoPixel(image,p+center,&pixel);
+ r=p;
+ EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
+ EnhancePixel(8.0); EnhancePixel(5.0);
+ r=p+GetPixelChannels(image)*(image->columns+4);
+ EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
+ EnhancePixel(20.0); EnhancePixel(8.0);
+ r=p+2*GetPixelChannels(image)*(image->columns+4);
+ EnhancePixel(10.0); EnhancePixel(40.0); EnhancePixel(80.0);
+ EnhancePixel(40.0); EnhancePixel(10.0);
+ r=p+3*GetPixelChannels(image)*(image->columns+4);
+ EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
+ EnhancePixel(20.0); EnhancePixel(8.0);
+ r=p+4*GetPixelChannels(image)*(image->columns+4);
+ EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
+ EnhancePixel(8.0); EnhancePixel(5.0);
+ pixel.red=((aggregate.red+total_weight/2.0)/total_weight);
+ pixel.green=((aggregate.green+total_weight/2.0)/total_weight);
+ pixel.blue=((aggregate.blue+total_weight/2.0)/total_weight);
+ pixel.black=((aggregate.black+total_weight/2.0)/total_weight);
+ pixel.alpha=((aggregate.alpha+total_weight/2.0)/total_weight);
+ SetPixelViaPixelInfo(image,&pixel,q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(enhance_image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(enhance_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(enhance_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_EnhanceImage)
#endif
proceed=SetImageProgress(image,EnhanceImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
enhance_view=DestroyCacheView(enhance_view);
image_view=DestroyCacheView(image_view);
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
enhance_image=DestroyImage(enhance_image);
return(enhance_image);
}
CacheView
*image_view;
- MagickBooleanType
- status;
-
- MagickOffsetType
- progress;
-
double
black[CompositePixelChannel+1],
*equalize_map,
*map,
white[CompositePixelChannel+1];
+ MagickBooleanType
+ status;
+
+ MagickOffsetType
+ progress;
+
register ssize_t
i;
- size_t
- number_channels;
-
ssize_t
y;
Allocate and initialize histogram arrays.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+ if (AccelerateEqualizeImage(image,exception) != MagickFalse)
+ return(MagickTrue);
+#endif
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
equalize_map=(double *) AcquireQuantumMemory(MaxMap+1UL,
GetPixelChannels(image)*sizeof(*equalize_map));
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
- *restrict p;
+ *magick_restrict p;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- register ssize_t
- i;
-
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- histogram[GetPixelChannels(image)*ScaleQuantumToMap(p[i])+i]++;
+ {
+ double
+ intensity;
+
+ intensity=p[i];
+ if ((image->channel_mask & SyncChannels) != 0)
+ intensity=GetPixelIntensity(image,p);
+ histogram[GetPixelChannels(image)*ScaleQuantumToMap(intensity)+i]++;
+ }
p+=GetPixelChannels(image);
}
}
/*
Integrate the histogram to get the equalization map.
*/
- number_channels=GetPixelChannels(image);
- for (i=0; i < (ssize_t) number_channels; i++)
+ for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
double
intensity;
sizeof(*equalize_map));
(void) ResetMagickMemory(black,0,sizeof(*black));
(void) ResetMagickMemory(white,0,sizeof(*white));
- number_channels=GetPixelChannels(image);
- for (i=0; i < (ssize_t) number_channels; i++)
+ for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
register ssize_t
j;
PixelChannel channel=GetPixelChannelChannel(image,RedPixelChannel);
if (black[channel] != white[channel])
image->colormap[j].red=equalize_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))]+
- channel;
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))+
+ channel];
}
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
{
GreenPixelChannel);
if (black[channel] != white[channel])
image->colormap[j].green=equalize_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))]+
- channel;
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))+
+ channel];
}
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
{
PixelChannel channel=GetPixelChannelChannel(image,BluePixelChannel);
if (black[channel] != white[channel])
image->colormap[j].blue=equalize_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))]+
- channel;
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))+
+ channel];
}
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
{
AlphaPixelChannel);
if (black[channel] != white[channel])
image->colormap[j].alpha=equalize_map[GetPixelChannels(image)*
- ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))]+
- channel;
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))+
+ channel];
}
}
}
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
- if (((traits & UpdatePixelTrait) == 0) || (black[i] == white[i]))
+ if (((traits & UpdatePixelTrait) == 0) || (black[j] == white[j]))
continue;
- q[i]=ClampToQuantum(equalize_map[GetPixelChannels(image)*
- ScaleQuantumToMap(q[i])+i]);
+ q[j]=ClampToQuantum(equalize_map[GetPixelChannels(image)*
+ ScaleQuantumToMap(q[j])+j]);
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_EqualizeImage)
#endif
proceed=SetImageProgress(image,EqualizeImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
Allocate and initialize gamma maps.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (gamma == 1.0)
return(MagickTrue);
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
#if !defined(MAGICKCORE_HDRI_SUPPORT)
- q[i]=gamma_map[ScaleQuantumToMap(q[i])];
+ q[j]=gamma_map[ScaleQuantumToMap(q[j])];
#else
- q[i]=QuantumRange*gamma_pow(QuantumScale*q[i],1.0/gamma);
+ q[j]=QuantumRange*gamma_pow(QuantumScale*q[j],1.0/gamma);
#endif
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,GammaCorrectImageTag,progress++,
image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
% o exception: return any errors or warnings in this structure.
%
*/
-
-static inline MagickRealType MagickMax(const MagickRealType x,
- const MagickRealType y)
-{
- if (x > y)
- return(x);
- return(y);
-}
-
-static inline MagickRealType MagickMin(const MagickRealType x,
- const MagickRealType y)
-{
- if (x < y)
- return(x);
- return(y);
-}
-
MagickExport MagickBooleanType GrayscaleImage(Image *image,
const PixelIntensityMethod method,ExceptionInfo *exception)
{
y;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
{
- if( IfMagickFalse(SyncImage(image,exception)) )
+ if (SyncImage(image,exception) == MagickFalse)
return(MagickFalse);
- if( IfMagickFalse(SetImageStorageClass(image,DirectClass,exception)) )
+ if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
return(MagickFalse);
}
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+ if (AccelerateGrayscaleImage(image,method,exception) != MagickFalse)
+ {
+ image->intensity=method;
+ image->type=GrayscaleType;
+ return(SetImageColorspace(image,GRAYColorspace,exception));
+ }
+#endif
/*
Grayscale image.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
red,
intensity;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
SetPixelGray(image,ClampToQuantum(intensity),q);
q+=GetPixelChannels(image);
}
- if (IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)))
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,GrayscaleImageTag,progress++,
image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
y;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(hald_image != (Image *) NULL);
- assert(hald_image->signature == MagickSignature);
- if( IfMagickFalse(SetImageStorageClass(image,DirectClass,exception)) )
+ assert(hald_image->signature == MagickCoreSignature);
+ if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
return(MagickFalse);
- if (image->alpha_trait != BlendPixelTrait)
+ if (image->alpha_trait == UndefinedPixelTrait)
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
/*
Hald clut image.
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
point.y-=floor(point.y);
point.z-=floor(point.z);
pixel1=zero;
- (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
+ (void) InterpolatePixelInfo(hald_image,hald_view,hald_image->interpolate,
fmod(offset,width),floor(offset/width),&pixel1,exception);
pixel2=zero;
- (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
+ (void) InterpolatePixelInfo(hald_image,hald_view,hald_image->interpolate,
fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
pixel3=zero;
CompositePixelInfoAreaBlend(&pixel1,pixel1.alpha,&pixel2,pixel2.alpha,
point.y,&pixel3);
offset+=cube_size;
- (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
+ (void) InterpolatePixelInfo(hald_image,hald_view,hald_image->interpolate,
fmod(offset,width),floor(offset/width),&pixel1,exception);
- (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
+ (void) InterpolatePixelInfo(hald_image,hald_view,hald_image->interpolate,
fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
pixel4=zero;
CompositePixelInfoAreaBlend(&pixel1,pixel1.alpha,&pixel2,pixel2.alpha,
(image->colorspace == CMYKColorspace))
SetPixelBlack(image,ClampToQuantum(pixel.black),q);
if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
- (image->alpha_trait == BlendPixelTrait))
+ (image->alpha_trait != UndefinedPixelTrait))
SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_HaldClutImage)
#endif
proceed=SetImageProgress(image,HaldClutImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
level_pixel,
scale;
- scale=(white_point != black_point) ? 1.0/(white_point-black_point) : 1.0;
+ if (fabs(white_point-black_point) < MagickEpsilon)
+ return(pixel);
+ scale=1.0/(white_point-black_point);
level_pixel=QuantumRange*gamma_pow(scale*((double) pixel-black_point),
1.0/gamma);
return(level_pixel);
Allocate and initialize levels map.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
for (i=0; i < (ssize_t) image->colors; i++)
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].alpha=(double) ClampToQuantum(LevelPixel(black_point,
white_point,gamma,image->colormap[i].alpha));
- }
+ }
/*
Level image.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
- q[i]=ClampToQuantum(LevelPixel(black_point,white_point,gamma,
- (double) q[i]));
+ q[j]=ClampToQuantum(LevelPixel(black_point,white_point,gamma,
+ (double) q[j]));
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_LevelImage)
#endif
proceed=SetImageProgress(image,LevelImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
Allocate and initialize levels map.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
for (i=0; i < (ssize_t) image->colors; i++)
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
- q[i]=LevelizeValue(q[i]);
+ q[j]=LevelizeValue(q[j]);
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_LevelizeImage)
#endif
proceed=SetImageProgress(image,LevelizeImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
Allocate and initialize levels map.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- if( IfMagickTrue(IsGrayColorspace(image->colorspace)) &&
- (IfMagickFalse(IsGrayColorspace(black_color->colorspace)) ||
- IfMagickFalse(IsGrayColorspace(white_color->colorspace))))
+ if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+ ((IsGrayColorspace(black_color->colorspace) == MagickFalse) ||
+ (IsGrayColorspace(white_color->colorspace) == MagickFalse)))
(void) SetImageColorspace(image,sRGBColorspace,exception);
- status=MagickFalse;
- if( IfMagickFalse(invert) )
+ status=MagickTrue;
+ if (invert == MagickFalse)
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
{
(void) SetImageChannelMask(image,channel_mask);
}
if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
- (image->alpha_trait == BlendPixelTrait))
+ (image->alpha_trait != UndefinedPixelTrait))
{
channel_mask=SetImageChannelMask(image,AlphaChannel);
status&=LevelImage(image,black_color->alpha,white_color->alpha,1.0,
(void) SetImageChannelMask(image,channel_mask);
}
if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
- (image->alpha_trait == BlendPixelTrait))
+ (image->alpha_trait != UndefinedPixelTrait))
{
channel_mask=SetImageChannelMask(image,AlphaChannel);
status&=LevelizeImage(image,black_color->alpha,white_color->alpha,1.0,
Allocate histogram and linear map.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*histogram));
if (histogram == (double *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
- *restrict p;
+ *magick_restrict p;
register ssize_t
x;
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- double
- intensity;
-
intensity=GetPixelIntensity(image,p);
histogram[ScaleQuantumToMap(ClampToQuantum(intensity))]++;
p+=GetPixelChannels(image);
break;
}
histogram=(double *) RelinquishMagickMemory(histogram);
- status=LevelImage(image,(double) black,(double) white,1.0,exception);
+ status=LevelImage(image,(double) ScaleMapToQuantum((MagickRealType) black),
+ (double) ScaleMapToQuantum((MagickRealType) white),1.0,exception);
return(status);
}
-\f
+
+
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
Increase or decrease color luma, chroma, or hue.
*/
ConvertRGBToHCL(*red,*green,*blue,&hue,&chroma,&luma);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue > 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
chroma*=0.01*percent_chroma;
luma*=0.01*percent_luma;
ConvertHCLToRGB(hue,chroma,luma,red,green,blue);
Increase or decrease color luma, chroma, or hue.
*/
ConvertRGBToHCLp(*red,*green,*blue,&hue,&chroma,&luma);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue > 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
chroma*=0.01*percent_chroma;
luma*=0.01*percent_luma;
ConvertHCLpToRGB(hue,chroma,luma,red,green,blue);
Increase or decrease color brightness, saturation, or hue.
*/
ConvertRGBToHSB(*red,*green,*blue,&hue,&saturation,&brightness);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue > 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
saturation*=0.01*percent_saturation;
brightness*=0.01*percent_brightness;
ConvertHSBToRGB(hue,saturation,brightness,red,green,blue);
Increase or decrease color intensity, saturation, or hue.
*/
ConvertRGBToHSI(*red,*green,*blue,&hue,&saturation,&intensity);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue > 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
saturation*=0.01*percent_saturation;
intensity*=0.01*percent_intensity;
ConvertHSIToRGB(hue,saturation,intensity,red,green,blue);
Increase or decrease color lightness, saturation, or hue.
*/
ConvertRGBToHSL(*red,*green,*blue,&hue,&saturation,&lightness);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue >= 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
saturation*=0.01*percent_saturation;
lightness*=0.01*percent_lightness;
ConvertHSLToRGB(hue,saturation,lightness,red,green,blue);
Increase or decrease color value, saturation, or hue.
*/
ConvertRGBToHSV(*red,*green,*blue,&hue,&saturation,&value);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue >= 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
saturation*=0.01*percent_saturation;
value*=0.01*percent_value;
ConvertHSVToRGB(hue,saturation,value,red,green,blue);
Increase or decrease color blackness, whiteness, or hue.
*/
ConvertRGBToHWB(*red,*green,*blue,&hue,&whiteness,&blackness);
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue >= 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
blackness*=0.01*percent_blackness;
whiteness*=0.01*percent_whiteness;
ConvertHWBToRGB(hue,whiteness,blackness,red,green,blue);
ConvertRGBToLCHab(*red,*green,*blue,&luma,&chroma,&hue);
luma*=0.01*percent_luma;
chroma*=0.01*percent_chroma;
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue >= 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
ConvertLCHabToRGB(luma,chroma,hue,red,green,blue);
}
ConvertRGBToLCHuv(*red,*green,*blue,&luma,&chroma,&hue);
luma*=0.01*percent_luma;
chroma*=0.01*percent_chroma;
- hue+=0.5*(0.01*percent_hue-1.0);
- while (hue < 0.0)
- hue+=1.0;
- while (hue >= 1.0)
- hue-=1.0;
+ hue+=fmod((percent_hue-100.0),200.0)/200.0;
ConvertLCHuvToRGB(luma,chroma,hue,red,green,blue);
}
Initialize modulate table.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (modulate == (char *) NULL)
return(MagickFalse);
- if( IfMagickFalse(IssRGBCompatibleColorspace(image->colorspace)) )
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) SetImageColorspace(image,sRGBColorspace,exception);
flags=ParseGeometry(modulate,&geometry_info);
percent_brightness=geometry_info.rho;
/*
Modulate image.
*/
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+ if (AccelerateModulateImage(image,percent_brightness,percent_hue,
+ percent_saturation,colorspace,exception) != MagickFalse)
+ return(MagickTrue);
+#endif
status=MagickTrue;
progress=0;
image_view=AcquireAuthenticCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
green,
red;
+ if (GetPixelWriteMask(image,q) == 0)
+ {
+ q+=GetPixelChannels(image);
+ continue;
+ }
red=(double) GetPixelRed(image,q);
green=(double) GetPixelGreen(image,q);
blue=(double) GetPixelBlue(image,q);
SetPixelBlue(image,ClampToQuantum(blue),q);
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_ModulateImage)
#endif
proceed=SetImageProgress(image,ModulateImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
y;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
for (i=0; i < (ssize_t) image->colors; i++)
/*
Negate colormap.
*/
- if( IfMagickTrue(grayscale) )
+ if( grayscale != MagickFalse )
if ((image->colormap[i].red != image->colormap[i].green) ||
(image->colormap[i].green != image->colormap[i].blue))
continue;
status=MagickTrue;
progress=0;
image_view=AcquireAuthenticCacheView(image,exception);
- if( IfMagickTrue(grayscale) )
+ if( grayscale != MagickFalse )
{
for (y=0; y < (ssize_t) image->rows; y++)
{
sync;
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
exception);
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if ((GetPixelReadMask(image,q) == 0) ||
- IfMagickTrue(IsPixelGray(image,q)))
+ if ((GetPixelWriteMask(image,q) == 0) ||
+ IsPixelGray(image,q) != MagickFalse)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
- q[i]=QuantumRange-q[i];
+ q[j]=QuantumRange-q[j];
}
q+=GetPixelChannels(image);
}
sync=SyncCacheViewAuthenticPixels(image_view,exception);
- if( IfMagickFalse(sync) )
+ if (sync == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,NegateImageTag,progress++,
image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
for (x=0; x < (ssize_t) image->columns; x++)
{
register ssize_t
- i;
+ j;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
{
- PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelChannel channel=GetPixelChannelChannel(image,j);
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
- q[i]=QuantumRange-q[i];
+ q[j]=QuantumRange-q[j];
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_NegateImage)
#endif
proceed=SetImageProgress(image,NegateImageTag,progress++,image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}
Convenience macros.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if( IfMagickTrue(image->debug) )
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
/*
Side effect: may clamp values unless contrast<MagickEpsilon, in which
register ssize_t
i;
- if( IfMagickTrue(sharpen) )
+ if( sharpen != MagickFalse )
for (i=0; i < (ssize_t) image->colors; i++)
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
for (y=0; y < (ssize_t) image->rows; y++)
{
register Quantum
- *restrict q;
+ *magick_restrict q;
register ssize_t
x;
- if( IfMagickFalse(status) )
+ if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelReadMask(image,q) == 0)
+ if (GetPixelWriteMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
- if( IfMagickTrue(sharpen) )
+ if( sharpen != MagickFalse )
q[i]=ScaledSig(q[i]);
else
q[i]=InverseScaledSig(q[i]);
}
q+=GetPixelChannels(image);
}
- if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,SigmoidalContrastImageTag,progress++,
image->rows);
- if( IfMagickFalse(proceed) )
+ if (proceed == MagickFalse)
status=MagickFalse;
}
}