% MagickCore Image Enhancement Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 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 %
*/
#include "MagickCore/studio.h"
#include "MagickCore/artifact.h"
+#include "MagickCore/attribute.h"
#include "MagickCore/cache.h"
#include "MagickCore/cache-view.h"
+#include "MagickCore/channel.h"
#include "MagickCore/color.h"
#include "MagickCore/color-private.h"
#include "MagickCore/colorspace.h"
ChannelType
channel_mask;
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
channel_mask=SetImageChannelMask(image,(ChannelType) (1 << i));
gamma=log(mean*QuantumScale)/log_mean;
status&=LevelImage(image,0.0,(double) QuantumRange,gamma,exception);
(void) SetImageChannelMask(image,channel_mask);
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
break;
}
return(status != 0 ? MagickTrue : MagickFalse);
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
alpha=contrast;
slope=tan((double) (MagickPI*(alpha/100.0+1.0)/4.0));
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(clut_image != (Image *) NULL);
assert(clut_image->signature == MagickSignature);
- if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+ if( IfMagickFalse(SetImageStorageClass(image,DirectClass,exception)) )
return(MagickFalse);
- if (IsGrayColorspace(image->colorspace) != MagickFalse)
- (void) TransformImageColorspace(image,RGBColorspace,exception);
+ if( IfMagickTrue(IsGrayColorspace(image->colorspace)) &&
+ IfMagickFalse(IsGrayColorspace(clut_image->colorspace)))
+ (void) SetImageColorspace(image,sRGBColorspace,exception);
clut_map=(PixelInfo *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*clut_map));
if (clut_map == (PixelInfo *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
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 (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
SetPixelInfoPixel(image,&pixel,q);
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_ClutImage)
#endif
proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (color_correction_collection == (const char *) NULL)
return(MagickFalse);
}
}
ccc=DestroyXMLTree(ccc);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
{
(void) LogMagickEvent(TransformEvent,GetMagickModule(),
" Color Correction Collection:");
for (i=0; i < (ssize_t) image->colors; i++)
{
/*
- Apply transfer function to colormap.
+ Apply transfer function to colormap.
*/
double
- luma;
+ luma;
- luma=0.21267*image->colormap[i].red+0.71526*image->colormap[i].green+
- 0.07217*image->colormap[i].blue;
+ luma=0.21267f*image->colormap[i].red+0.71526*image->colormap[i].green+
+ 0.07217f*image->colormap[i].blue;
image->colormap[i].red=luma+color_correction.saturation*cdl_map[
- ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))].red-luma;
+ ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))].red-luma;
image->colormap[i].green=luma+color_correction.saturation*cdl_map[
ScaleQuantumToMap(ClampToQuantum(image->colormap[i].green))].green-luma;
image->colormap[i].blue=luma+color_correction.saturation*cdl_map[
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- luma=0.21267*GetPixelRed(image,q)+0.71526*GetPixelGreen(image,q)+0.07217*
- GetPixelBlue(image,q);
+ luma=0.21267f*GetPixelRed(image,q)+0.71526*GetPixelGreen(image,q)+
+ 0.07217f*GetPixelBlue(image,q);
SetPixelRed(image,ClampToQuantum(luma+color_correction.saturation*
(cdl_map[ScaleQuantumToMap(GetPixelRed(image,q))].red-luma)),q);
SetPixelGreen(image,ClampToQuantum(luma+color_correction.saturation*
(cdl_map[ScaleQuantumToMap(GetPixelBlue(image,q))].blue-luma)),q);
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,ColorDecisionListCorrectImageTag,
progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- sign=sharpen != MagickFalse ? 1 : -1;
+ sign=IfMagickTrue(sharpen) ? 1 : -1;
if (image->storage_class == PseudoClass)
{
/*
Contrast enhance colormap.
*/
for (i=0; i < (ssize_t) image->colors; i++)
- Contrast(sign,&image->colormap[i].red,&image->colormap[i].green,
- &image->colormap[i].blue);
+ {
+ double
+ blue,
+ green,
+ red;
+
+ red=0.0;
+ green=0.0;
+ blue=0.0;
+ Contrast(sign,&red,&green,&blue);
+ image->colormap[i].red=(MagickRealType) red;
+ image->colormap[i].green=(MagickRealType) green;
+ image->colormap[i].blue=(MagickRealType) blue;
+ }
}
/*
Contrast enhance image.
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
SetPixelBlue(image,ClampToQuantum(blue),q);
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_ContrastImage)
#endif
proceed=SetImageProgress(image,ContrastImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
black=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*black));
white=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*white));
/*
Form histogram.
*/
+ if( IfMagickTrue(IsImageGray(image,exception)) )
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
status=MagickTrue;
(void) ResetMagickMemory(histogram,0,(MaxMap+1)*GetPixelChannels(image)*
sizeof(*histogram));
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
stretch_map[GetPixelChannels(image)*j+i]=0.0;
else
if (j > (ssize_t) white[i])
- stretch_map[GetPixelChannels(image)*j+i]=(double)
- QuantumRange;
+ 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*(j-black[i])/(white[i]-black[i])));
}
}
if (image->storage_class == PseudoClass)
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if (((traits & UpdatePixelTrait) == 0) || (black[i] == white[i]))
continue;
q[i]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,ContrastStretchImageTag,progress++,
image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
{
#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)) \
+ 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)) \
{ \
aggregate+=(weight)*r[i]; \
total_weight+=(weight); \
*/
assert(image != (const Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
exception);
if (enhance_image == (Image *) NULL)
return((Image *) NULL);
- if (SetImageStorageClass(enhance_image,DirectClass,exception) == MagickFalse)
+ if( IfMagickFalse(SetImageStorageClass(enhance_image,DirectClass,exception)) )
{
enhance_image=DestroyImage(enhance_image);
return((Image *) NULL);
enhance_view=AcquireAuthenticCacheView(enhance_image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,enhance_image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
ssize_t
center;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
p=GetCacheViewVirtualPixels(image_view,-2,y-2,image->columns+4,5,exception);
q=QueueCacheViewAuthenticPixels(enhance_view,0,y,enhance_image->columns,1,
register ssize_t
i;
- if (GetPixelMask(image,p) != 0)
+ if (GetPixelReadMask(image,p) == 0)
{
+ SetPixelBackgoundColor(enhance_image,q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(enhance_image);
continue;
mean,
total_weight;
- PixelChannel
- channel;
-
- PixelTrait
- enhance_traits,
- traits;
-
register const Quantum
*restrict r;
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
- enhance_traits=GetPixelChannelTraits(enhance_image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
+ PixelTrait enhance_traits=GetPixelChannelTraits(enhance_image,channel);
if ((traits == UndefinedPixelTrait) ||
(enhance_traits == UndefinedPixelTrait))
continue;
p+=GetPixelChannels(image);
q+=GetPixelChannels(enhance_image);
}
- if (SyncCacheViewAuthenticPixels(enhance_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(enhance_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_EnhanceImage)
#endif
proceed=SetImageProgress(image,EnhanceImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
enhance_view=DestroyCacheView(enhance_view);
image_view=DestroyCacheView(image_view);
+ if( IfMagickFalse(status) )
+ enhance_image=DestroyImage(enhance_image);
return(enhance_image);
}
\f
progress;
double
- black[CompositePixelChannel],
+ black[CompositePixelChannel+1],
*equalize_map,
*histogram,
*map,
- white[CompositePixelChannel];
+ white[CompositePixelChannel+1];
register ssize_t
i;
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
equalize_map=(double *) AcquireQuantumMemory(MaxMap+1UL,
GetPixelChannels(image)*sizeof(*equalize_map));
- histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,
- GetPixelChannels(image)*sizeof(*histogram));
- map=(double *) AcquireQuantumMemory(MaxMap+1UL,
- GetPixelChannels(image)*sizeof(*map));
- if ((equalize_map == (double *) NULL) ||
- (histogram == (double *) NULL) ||
+ histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,GetPixelChannels(image)*
+ sizeof(*histogram));
+ map=(double *) AcquireQuantumMemory(MaxMap+1UL,GetPixelChannels(image)*
+ sizeof(*map));
+ if ((equalize_map == (double *) NULL) || (histogram == (double *) NULL) ||
(map == (double *) NULL))
{
if (map != (double *) NULL)
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
}
(void) ResetMagickMemory(equalize_map,0,(MaxMap+1)*GetPixelChannels(image)*
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++)
{
map=(double *) RelinquishMagickMemory(map);
if (image->storage_class == PseudoClass)
{
- PixelChannel
- channel;
-
register ssize_t
j;
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
{
- channel=GetPixelChannelChannel(image,RedPixelChannel);
+ PixelChannel channel=GetPixelChannelChannel(image,RedPixelChannel);
if (black[channel] != white[channel])
image->colormap[j].red=equalize_map[GetPixelChannels(image)*
ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))]+
}
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
{
- channel=GetPixelChannelChannel(image,GreenPixelChannel);
+ PixelChannel channel=GetPixelChannelChannel(image,
+ GreenPixelChannel);
if (black[channel] != white[channel])
image->colormap[j].green=equalize_map[GetPixelChannels(image)*
ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))]+
}
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
{
- channel=GetPixelChannelChannel(image,BluePixelChannel);
+ PixelChannel channel=GetPixelChannelChannel(image,BluePixelChannel);
if (black[channel] != white[channel])
image->colormap[j].blue=equalize_map[GetPixelChannels(image)*
ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))]+
}
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
{
- channel=GetPixelChannelChannel(image,AlphaPixelChannel);
+ PixelChannel channel=GetPixelChannelChannel(image,
+ AlphaPixelChannel);
if (black[channel] != white[channel])
image->colormap[j].alpha=equalize_map[GetPixelChannels(image)*
ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))]+
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if (((traits & UpdatePixelTrait) == 0) || (black[i] == white[i]))
continue;
q[i]=ClampToQuantum(equalize_map[GetPixelChannels(image)*
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_EqualizeImage)
#endif
proceed=SetImageProgress(image,EqualizeImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
% o gamma: the image gamma.
%
*/
+
+static inline double gamma_pow(const double value,const double gamma)
+{
+ return(value < 0.0 ? value : pow(value,gamma));
+}
+
MagickExport MagickBooleanType GammaImage(Image *image,const double gamma,
ExceptionInfo *exception)
{
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (gamma == 1.0)
return(MagickTrue);
for (i=0; i < (ssize_t) image->colors; i++)
{
/*
- Gamma-correct colormap.
+ Gamma-correct colormap.
*/
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
+ if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].red=(double) gamma_map[ScaleQuantumToMap(
+ ClampToQuantum(image->colormap[i].red))];
+ if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].green=(double) gamma_map[ScaleQuantumToMap(
+ ClampToQuantum(image->colormap[i].green))];
+ if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].blue=(double) gamma_map[ScaleQuantumToMap(
+ ClampToQuantum(image->colormap[i].blue))];
+ if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].alpha=(double) gamma_map[ScaleQuantumToMap(
+ ClampToQuantum(image->colormap[i].alpha))];
+#else
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].red=(double) gamma_map[
- ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))];
+ image->colormap[i].red=QuantumRange*gamma_pow(QuantumScale*
+ image->colormap[i].red,1.0/gamma);
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].green=(double) gamma_map[
- ScaleQuantumToMap(ClampToQuantum(image->colormap[i].green))];
+ image->colormap[i].green=QuantumRange*gamma_pow(QuantumScale*
+ image->colormap[i].green,1.0/gamma);
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].blue=(double) gamma_map[
- ScaleQuantumToMap(ClampToQuantum(image->colormap[i].blue))];
+ image->colormap[i].blue=QuantumRange*gamma_pow(QuantumScale*
+ image->colormap[i].blue,1.0/gamma);
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].alpha=(double) gamma_map[
- ScaleQuantumToMap(ClampToQuantum(image->colormap[i].alpha))];
+ image->colormap[i].alpha=QuantumRange*gamma_pow(QuantumScale*
+ image->colormap[i].alpha,1.0/gamma);
+#endif
}
/*
Gamma-correct image.
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
q[i]=gamma_map[ScaleQuantumToMap(q[i])];
+#else
+ q[i]=QuantumRange*gamma_pow(QuantumScale*q[i],1.0/gamma);
+#endif
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,GammaCorrectImageTag,progress++,
image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
% %
% %
% %
+% G r a y s c a l e I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% GrayscaleImage() converts the image to grayscale.
+%
+% The format of the GrayscaleImage method is:
+%
+% MagickBooleanType GrayscaleImage(Image *image,
+% const PixelIntensityMethod method ,ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o method: the pixel intensity method.
+%
+% 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)
+{
+#define GrayscaleImageTag "Grayscale/Image"
+
+ CacheView
+ *image_view;
+
+ MagickBooleanType
+ status;
+
+ MagickOffsetType
+ progress;
+
+ ssize_t
+ y;
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickSignature);
+ if( IfMagickTrue(image->debug) )
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ if (image->storage_class == PseudoClass)
+ {
+ if( IfMagickFalse(SyncImage(image,exception)) )
+ return(MagickFalse);
+ if( IfMagickFalse(SetImageStorageClass(image,DirectClass,exception)) )
+ return(MagickFalse);
+ }
+ /*
+ Grayscale image.
+ */
+ status=MagickTrue;
+ progress=0;
+ image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(static,4) shared(progress,status) \
+ magick_threads(image,image,image->rows,1)
+#endif
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ register Quantum
+ *restrict q;
+
+ register ssize_t
+ x;
+
+ if( IfMagickFalse(status) )
+ continue;
+ q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+ if (q == (Quantum *) NULL)
+ {
+ status=MagickFalse;
+ continue;
+ }
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ MagickRealType
+ blue,
+ green,
+ red,
+ intensity;
+
+ if (GetPixelReadMask(image,q) == 0)
+ {
+ q+=GetPixelChannels(image);
+ continue;
+ }
+ red=(MagickRealType) GetPixelRed(image,q);
+ green=(MagickRealType) GetPixelGreen(image,q);
+ blue=(MagickRealType) GetPixelBlue(image,q);
+ intensity=0.0;
+ switch (method)
+ {
+ case AveragePixelIntensityMethod:
+ {
+ intensity=(red+green+blue)/3.0;
+ break;
+ }
+ case BrightnessPixelIntensityMethod:
+ {
+ intensity=MagickMax(MagickMax(red,green),blue);
+ break;
+ }
+ case LightnessPixelIntensityMethod:
+ {
+ intensity=(MagickMin(MagickMin(red,green),blue)+
+ MagickMax(MagickMax(red,green),blue))/2.0;
+ break;
+ }
+ case MSPixelIntensityMethod:
+ {
+ intensity=(MagickRealType) (((double) red*red+green*green+
+ blue*blue)/3.0);
+ break;
+ }
+ case Rec601LumaPixelIntensityMethod:
+ {
+ if (image->colorspace == RGBColorspace)
+ {
+ red=EncodePixelGamma(red);
+ green=EncodePixelGamma(green);
+ blue=EncodePixelGamma(blue);
+ }
+ intensity=0.298839*red+0.586811*green+0.114350*blue;
+ break;
+ }
+ case Rec601LuminancePixelIntensityMethod:
+ {
+ if (image->colorspace == sRGBColorspace)
+ {
+ red=DecodePixelGamma(red);
+ green=DecodePixelGamma(green);
+ blue=DecodePixelGamma(blue);
+ }
+ intensity=0.298839*red+0.586811*green+0.114350*blue;
+ break;
+ }
+ case Rec709LumaPixelIntensityMethod:
+ default:
+ {
+ if (image->colorspace == RGBColorspace)
+ {
+ red=EncodePixelGamma(red);
+ green=EncodePixelGamma(green);
+ blue=EncodePixelGamma(blue);
+ }
+ intensity=0.212656*red+0.715158*green+0.072186*blue;
+ break;
+ }
+ case Rec709LuminancePixelIntensityMethod:
+ {
+ if (image->colorspace == sRGBColorspace)
+ {
+ red=DecodePixelGamma(red);
+ green=DecodePixelGamma(green);
+ blue=DecodePixelGamma(blue);
+ }
+ intensity=0.212656*red+0.715158*green+0.072186*blue;
+ break;
+ }
+ case RMSPixelIntensityMethod:
+ {
+ intensity=(MagickRealType) (sqrt((double) red*red+green*green+
+ blue*blue)/sqrt(3.0));
+ break;
+ }
+ }
+ SetPixelGray(image,ClampToQuantum(intensity),q);
+ q+=GetPixelChannels(image);
+ }
+ if (IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)))
+ status=MagickFalse;
+ if (image->progress_monitor != (MagickProgressMonitor) NULL)
+ {
+ MagickBooleanType
+ proceed;
+
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp critical (MagickCore_GrayscaleImage)
+#endif
+ proceed=SetImageProgress(image,GrayscaleImageTag,progress++,
+ image->rows);
+ if( IfMagickFalse(proceed) )
+ status=MagickFalse;
+ }
+ }
+ image_view=DestroyCacheView(image_view);
+ image->intensity=method;
+ image->type=GrayscaleType;
+ return(SetImageColorspace(image,GRAYColorspace,exception));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% H a l d C l u t I m a g e %
% %
% %
% o exception: return any errors or warnings in this structure.
%
*/
-
-static inline size_t MagickMin(const size_t x,const size_t y)
-{
- if (x < y)
- return(x);
- return(y);
-}
-
MagickExport MagickBooleanType HaldClutImage(Image *image,
const Image *hald_image,ExceptionInfo *exception)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(hald_image != (Image *) NULL);
assert(hald_image->signature == MagickSignature);
- if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+ if( IfMagickFalse(SetImageStorageClass(image,DirectClass,exception)) )
return(MagickFalse);
- if (IsGrayColorspace(image->colorspace) != MagickFalse)
- (void) TransformImageColorspace(image,RGBColorspace,exception);
if (image->alpha_trait != BlendPixelTrait)
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
/*
*/
status=MagickTrue;
progress=0;
- length=MagickMin(hald_image->columns,hald_image->rows);
+ length=(size_t) MagickMin((MagickRealType) hald_image->columns,
+ (MagickRealType) hald_image->rows);
for (level=2; (level*level*level) < length; level++) ;
level*=level;
cube_size=level*level;
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_HaldClutImage)
#endif
proceed=SetImageProgress(image,HaldClutImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
scale;
scale=(white_point != black_point) ? 1.0/(white_point-black_point) : 1.0;
- level_pixel=(double) QuantumRange*pow(scale*((double) pixel-
- black_point),1.0/gamma);
+ level_pixel=QuantumRange*gamma_pow(scale*((double) pixel-black_point),
+ 1.0/gamma);
return(level_pixel);
}
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
for (i=0; i < (ssize_t) image->colors; i++)
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
q[i]=ClampToQuantum(LevelPixel(black_point,white_point,gamma,
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_LevelImage)
#endif
proceed=SetImageProgress(image,LevelImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
image_view=DestroyCacheView(image_view);
- if (status != MagickFalse)
- (void) ClampImage(image,exception);
+ (void) ClampImage(image,exception);
return(status);
}
\f
ExceptionInfo *exception)
{
#define LevelizeImageTag "Levelize/Image"
-#define LevelizeValue(x) (ClampToQuantum((pow((double) (QuantumScale*(x)), \
- 1.0/gamma))*(white_point-black_point)+black_point))
+#define LevelizeValue(x) ClampToQuantum(((MagickRealType) gamma_pow((double) \
+ (QuantumScale*(x)),gamma))*(white_point-black_point)+black_point)
CacheView
*image_view;
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- if (IsGrayColorspace(image->colorspace) != MagickFalse)
- (void) SetImageColorspace(image,RGBColorspace,exception);
if (image->storage_class == PseudoClass)
for (i=0; i < (ssize_t) image->colors; i++)
{
Level colormap.
*/
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].red=(double) LevelizeValue(
- image->colormap[i].red);
+ image->colormap[i].red=(double) LevelizeValue(image->colormap[i].red);
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].green=(double) LevelizeValue(
image->colormap[i].green);
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].blue=(double) LevelizeValue(
- image->colormap[i].blue);
+ image->colormap[i].blue=(double) LevelizeValue(image->colormap[i].blue);
if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
image->colormap[i].alpha=(double) LevelizeValue(
image->colormap[i].alpha);
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
q[i]=LevelizeValue(q[i]);
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_LevelizeImage)
#endif
proceed=SetImageProgress(image,LevelizeImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ if( IfMagickTrue(IsGrayColorspace(image->colorspace)) &&
+ (IfMagickFalse(IsGrayColorspace(black_color->colorspace)) ||
+ IfMagickFalse(IsGrayColorspace(white_color->colorspace))))
+ (void) SetImageColorspace(image,sRGBColorspace,exception);
status=MagickFalse;
- if (invert == MagickFalse)
+ if( IfMagickFalse(invert) )
{
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
{
channel_mask=SetImageChannelMask(image,RedChannel);
- status|=LevelImage(image,black_color->red,white_color->red,1.0,
+ status&=LevelImage(image,black_color->red,white_color->red,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
{
channel_mask=SetImageChannelMask(image,GreenChannel);
- status|=LevelImage(image,black_color->green,white_color->green,1.0,
+ status&=LevelImage(image,black_color->green,white_color->green,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
{
channel_mask=SetImageChannelMask(image,BlueChannel);
- status|=LevelImage(image,black_color->blue,white_color->blue,1.0,
+ status&=LevelImage(image,black_color->blue,white_color->blue,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
(image->colorspace == CMYKColorspace))
{
channel_mask=SetImageChannelMask(image,BlackChannel);
- status|=LevelImage(image,black_color->black,white_color->black,1.0,
+ status&=LevelImage(image,black_color->black,white_color->black,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
(image->alpha_trait == BlendPixelTrait))
{
channel_mask=SetImageChannelMask(image,AlphaChannel);
- status|=LevelImage(image,black_color->alpha,white_color->alpha,1.0,
+ status&=LevelImage(image,black_color->alpha,white_color->alpha,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
{
channel_mask=SetImageChannelMask(image,RedChannel);
- status|=LevelizeImage(image,black_color->red,white_color->red,1.0,
+ status&=LevelizeImage(image,black_color->red,white_color->red,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
{
channel_mask=SetImageChannelMask(image,GreenChannel);
- status|=LevelizeImage(image,black_color->green,white_color->green,1.0,
+ status&=LevelizeImage(image,black_color->green,white_color->green,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
{
channel_mask=SetImageChannelMask(image,BlueChannel);
- status|=LevelizeImage(image,black_color->blue,white_color->blue,1.0,
+ status&=LevelizeImage(image,black_color->blue,white_color->blue,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
(image->colorspace == CMYKColorspace))
{
channel_mask=SetImageChannelMask(image,BlackChannel);
- status|=LevelizeImage(image,black_color->black,white_color->black,1.0,
+ status&=LevelizeImage(image,black_color->black,white_color->black,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
(image->alpha_trait == BlendPixelTrait))
{
channel_mask=SetImageChannelMask(image,AlphaChannel);
- status|=LevelizeImage(image,black_color->alpha,white_color->alpha,1.0,
+ status&=LevelizeImage(image,black_color->alpha,white_color->alpha,1.0,
exception);
(void) SetImageChannelMask(image,channel_mask);
}
}
- return(status == 0 ? MagickFalse : MagickTrue);
+ return(status != 0 ? MagickTrue : MagickFalse);
}
\f
/*
CacheView
*image_view;
- MagickBooleanType
- status;
-
double
*histogram,
intensity;
+ MagickBooleanType
+ status;
+
ssize_t
black,
white,
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,
- sizeof(*histogram));
+ histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*histogram));
if (histogram == (double *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
ConvertHCLToRGB(hue,chroma,luma,red,green,blue);
}
+static inline void ModulateHCLp(const double percent_hue,
+ const double percent_chroma,const double percent_luma,double *red,
+ double *green,double *blue)
+{
+ double
+ hue,
+ luma,
+ chroma;
+
+ /*
+ 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;
+ chroma*=0.01*percent_chroma;
+ luma*=0.01*percent_luma;
+ ConvertHCLpToRGB(hue,chroma,luma,red,green,blue);
+}
+
static inline void ModulateHSB(const double percent_hue,
const double percent_saturation,const double percent_brightness,double *red,
double *green,double *blue)
ConvertHSBToRGB(hue,saturation,brightness,red,green,blue);
}
+static inline void ModulateHSI(const double percent_hue,
+ const double percent_saturation,const double percent_intensity,double *red,
+ double *green,double *blue)
+{
+ double
+ intensity,
+ hue,
+ saturation;
+
+ /*
+ 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;
+ saturation*=0.01*percent_saturation;
+ intensity*=0.01*percent_intensity;
+ ConvertHSIToRGB(hue,saturation,intensity,red,green,blue);
+}
+
static inline void ModulateHSL(const double percent_hue,
const double percent_saturation,const double percent_lightness,double *red,
double *green,double *blue)
hue+=0.5*(0.01*percent_hue-1.0);
while (hue < 0.0)
hue+=1.0;
- while (hue > 1.0)
+ while (hue >= 1.0)
hue-=1.0;
saturation*=0.01*percent_saturation;
lightness*=0.01*percent_lightness;
ConvertHSLToRGB(hue,saturation,lightness,red,green,blue);
}
+static inline void ModulateHSV(const double percent_hue,
+ const double percent_saturation,const double percent_value,double *red,
+ double *green,double *blue)
+{
+ double
+ hue,
+ saturation,
+ value;
+
+ /*
+ 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;
+ saturation*=0.01*percent_saturation;
+ value*=0.01*percent_value;
+ ConvertHSVToRGB(hue,saturation,value,red,green,blue);
+}
+
static inline void ModulateHWB(const double percent_hue,
const double percent_whiteness,const double percent_blackness,double *red,
double *green,double *blue)
hue+=0.5*(0.01*percent_hue-1.0);
while (hue < 0.0)
hue+=1.0;
- while (hue > 1.0)
+ while (hue >= 1.0)
hue-=1.0;
blackness*=0.01*percent_blackness;
whiteness*=0.01*percent_whiteness;
ConvertHWBToRGB(hue,whiteness,blackness,red,green,blue);
}
+static inline void ModulateLCHab(const double percent_luma,
+ const double percent_chroma,const double percent_hue,double *red,
+ double *green,double *blue)
+{
+ double
+ hue,
+ luma,
+ chroma;
+
+ /*
+ Increase or decrease color luma, chroma, or hue.
+ */
+ 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;
+ ConvertLCHabToRGB(luma,chroma,hue,red,green,blue);
+}
+
+static inline void ModulateLCHuv(const double percent_luma,
+ const double percent_chroma,const double percent_hue,double *red,
+ double *green,double *blue)
+{
+ double
+ hue,
+ luma,
+ chroma;
+
+ /*
+ Increase or decrease color luma, chroma, or hue.
+ */
+ 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;
+ ConvertLCHuvToRGB(luma,chroma,hue,red,green,blue);
+}
+
MagickExport MagickBooleanType ModulateImage(Image *image,const char *modulate,
ExceptionInfo *exception)
{
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (modulate == (char *) NULL)
return(MagickFalse);
- if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,sRGBColorspace,exception);
+ if( IfMagickFalse(IssRGBCompatibleColorspace(image->colorspace)) )
+ (void) SetImageColorspace(image,sRGBColorspace,exception);
flags=ParseGeometry(modulate,&geometry_info);
percent_brightness=geometry_info.rho;
percent_saturation=geometry_info.sigma;
red;
/*
- Modulate colormap.
+ Modulate image colormap.
*/
- red=image->colormap[i].red;
- green=image->colormap[i].green;
- blue=image->colormap[i].blue;
+ red=(double) image->colormap[i].red;
+ green=(double) image->colormap[i].green;
+ blue=(double) image->colormap[i].blue;
switch (colorspace)
{
case HCLColorspace:
&red,&green,&blue);
break;
}
+ case HCLpColorspace:
+ {
+ ModulateHCLp(percent_hue,percent_saturation,percent_brightness,
+ &red,&green,&blue);
+ break;
+ }
case HSBColorspace:
{
ModulateHSB(percent_hue,percent_saturation,percent_brightness,
&red,&green,&blue);
break;
}
+ case HSIColorspace:
+ {
+ ModulateHSI(percent_hue,percent_saturation,percent_brightness,
+ &red,&green,&blue);
+ break;
+ }
case HSLColorspace:
default:
{
&red,&green,&blue);
break;
}
+ case HSVColorspace:
+ {
+ ModulateHSV(percent_hue,percent_saturation,percent_brightness,
+ &red,&green,&blue);
+ break;
+ }
case HWBColorspace:
{
ModulateHWB(percent_hue,percent_saturation,percent_brightness,
&red,&green,&blue);
break;
}
+ case LCHColorspace:
+ case LCHabColorspace:
+ {
+ ModulateLCHab(percent_brightness,percent_saturation,percent_hue,
+ &red,&green,&blue);
+ break;
+ }
+ case LCHuvColorspace:
+ {
+ ModulateLCHuv(percent_brightness,percent_saturation,percent_hue,
+ &red,&green,&blue);
+ break;
+ }
}
+ image->colormap[i].red=red;
+ image->colormap[i].green=green;
+ image->colormap[i].blue=blue;
}
/*
Modulate image.
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
&red,&green,&blue);
break;
}
+ case HCLpColorspace:
+ {
+ ModulateHCLp(percent_hue,percent_saturation,percent_brightness,
+ &red,&green,&blue);
+ break;
+ }
case HSBColorspace:
{
ModulateHSB(percent_hue,percent_saturation,percent_brightness,
&red,&green,&blue);
break;
}
+ case HSVColorspace:
+ {
+ ModulateHSV(percent_hue,percent_saturation,percent_brightness,
+ &red,&green,&blue);
+ break;
+ }
case HWBColorspace:
{
ModulateHWB(percent_hue,percent_saturation,percent_brightness,
&red,&green,&blue);
break;
}
+ case LCHabColorspace:
+ {
+ ModulateLCHab(percent_brightness,percent_saturation,percent_hue,
+ &red,&green,&blue);
+ break;
+ }
+ case LCHColorspace:
+ case LCHuvColorspace:
+ {
+ ModulateLCHuv(percent_brightness,percent_saturation,percent_hue,
+ &red,&green,&blue);
+ break;
+ }
}
SetPixelRed(image,ClampToQuantum(red),q);
SetPixelGreen(image,ClampToQuantum(green),q);
SetPixelBlue(image,ClampToQuantum(blue),q);
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_ModulateImage)
#endif
proceed=SetImageProgress(image,ModulateImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
for (i=0; i < (ssize_t) image->colors; i++)
{
/*
- Negate colormap.
+ Negate colormap.
*/
- if (grayscale != MagickFalse)
- if ((image->colormap[i].red != image->colormap[i].green) ||
- (image->colormap[i].green != image->colormap[i].blue))
- continue;
+ if( IfMagickTrue(grayscale) )
+ if ((image->colormap[i].red != image->colormap[i].green) ||
+ (image->colormap[i].green != image->colormap[i].blue))
+ continue;
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].red=QuantumRange-image->colormap[i].red;
+ image->colormap[i].red=QuantumRange-image->colormap[i].red;
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].green=QuantumRange-image->colormap[i].green;
+ image->colormap[i].green=QuantumRange-image->colormap[i].green;
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].blue=QuantumRange-image->colormap[i].blue;
+ image->colormap[i].blue=QuantumRange-image->colormap[i].blue;
}
/*
Negate image.
status=MagickTrue;
progress=0;
image_view=AcquireAuthenticCacheView(image,exception);
- if (grayscale != MagickFalse)
+ if( IfMagickTrue(grayscale) )
{
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
exception);
register ssize_t
i;
- if ((GetPixelMask(image,q) != 0) ||
- (IsPixelGray(image,q) != MagickFalse))
+ if ((GetPixelReadMask(image,q) == 0) ||
+ IfMagickTrue(IsPixelGray(image,q)))
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
q[i]=QuantumRange-q[i];
q+=GetPixelChannels(image);
}
sync=SyncCacheViewAuthenticPixels(image_view,exception);
- if (sync == MagickFalse)
+ if( IfMagickFalse(sync) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,NegateImageTag,progress++,
image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
Negate image.
*/
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ #pragma omp parallel for schedule(static,4) shared(progress,status) \
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
register ssize_t
i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
q[i]=QuantumRange-q[i];
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#pragma omp critical (MagickCore_NegateImage)
#endif
proceed=SetImageProgress(image,NegateImageTag,progress++,image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}
% o exception: return any errors or warnings in this structure.
%
*/
+
+/*
+ ImageMagick 6 has a version of this function which uses LUTs.
+*/
+
+/*
+ Sigmoidal function Sigmoidal with inflexion point moved to b and "slope
+ constant" set to a.
+
+ The first version, based on the hyperbolic tangent tanh, when combined with
+ the scaling step, is an exact arithmetic clone of the the sigmoid function
+ based on the logistic curve. The equivalence is based on the identity
+
+ 1/(1+exp(-t)) = (1+tanh(t/2))/2
+
+ (http://de.wikipedia.org/wiki/Sigmoidfunktion) and the fact that the
+ scaled sigmoidal derivation is invariant under affine transformations of
+ the ordinate.
+
+ The tanh version is almost certainly more accurate and cheaper. The 0.5
+ factor in the argument is to clone the legacy ImageMagick behavior. The
+ reason for making the define depend on atanh even though it only uses tanh
+ has to do with the construction of the inverse of the scaled sigmoidal.
+*/
+#if defined(MAGICKCORE_HAVE_ATANH)
+#define Sigmoidal(a,b,x) ( tanh((0.5*(a))*((x)-(b))) )
+#else
+#define Sigmoidal(a,b,x) ( 1.0/(1.0+exp((a)*((b)-(x)))) )
+#endif
+/*
+ Scaled sigmoidal function:
+
+ ( Sigmoidal(a,b,x) - Sigmoidal(a,b,0) ) /
+ ( Sigmoidal(a,b,1) - Sigmoidal(a,b,0) )
+
+ See http://osdir.com/ml/video.image-magick.devel/2005-04/msg00006.html and
+ http://www.cs.dartmouth.edu/farid/downloads/tutorials/fip.pdf. The limit
+ of ScaledSigmoidal as a->0 is the identity, but a=0 gives a division by
+ zero. This is fixed below by exiting immediately when contrast is small,
+ leaving the image (or colormap) unmodified. This appears to be safe because
+ the series expansion of the logistic sigmoidal function around x=b is
+
+ 1/2-a*(b-x)/4+...
+
+ so that the key denominator s(1)-s(0) is about a/4 (a/2 with tanh).
+*/
+#define ScaledSigmoidal(a,b,x) ( \
+ (Sigmoidal((a),(b),(x))-Sigmoidal((a),(b),0.0)) / \
+ (Sigmoidal((a),(b),1.0)-Sigmoidal((a),(b),0.0)) )
+/*
+ Inverse of ScaledSigmoidal, used for +sigmoidal-contrast. Because b
+ may be 0 or 1, the argument of the hyperbolic tangent (resp. logistic
+ sigmoidal) may be outside of the interval (-1,1) (resp. (0,1)), even
+ when creating a LUT from in gamut values, hence the branching. In
+ addition, HDRI may have out of gamut values.
+ InverseScaledSigmoidal is not a two-sided inverse of ScaledSigmoidal:
+ It is only a right inverse. This is unavoidable.
+*/
+static inline double InverseScaledSigmoidal(const double a,const double b,
+ const double x)
+{
+ const double sig0=Sigmoidal(a,b,0.0);
+ const double sig1=Sigmoidal(a,b,1.0);
+ const double argument=(sig1-sig0)*x+sig0;
+ const double clamped=
+ (
+#if defined(MAGICKCORE_HAVE_ATANH)
+ argument < -1+MagickEpsilon
+ ?
+ -1+MagickEpsilon
+ :
+ ( argument > 1-MagickEpsilon ? 1-MagickEpsilon : argument )
+ );
+ return(b+(2.0/a)*atanh(clamped));
+#else
+ argument < MagickEpsilon
+ ?
+ MagickEpsilon
+ :
+ ( argument > 1-MagickEpsilon ? 1-MagickEpsilon : argument )
+ );
+ return(b-log(1.0/clamped-1.0)/a);
+#endif
+}
+
MagickExport MagickBooleanType SigmoidalContrastImage(Image *image,
const MagickBooleanType sharpen,const double contrast,const double midpoint,
ExceptionInfo *exception)
{
#define SigmoidalContrastImageTag "SigmoidalContrast/Image"
+#define ScaledSig(x) ( ClampToQuantum(QuantumRange* \
+ ScaledSigmoidal(contrast,QuantumScale*midpoint,QuantumScale*(x))) )
+#define InverseScaledSig(x) ( ClampToQuantum(QuantumRange* \
+ InverseScaledSigmoidal(contrast,QuantumScale*midpoint,QuantumScale*(x))) )
CacheView
*image_view;
y;
/*
- Side effect: clamps values unless contrast<MagickEpsilon, in which
- case values are left alone.
- */
- /*
- Sigmoidal function Sigmoidal with inflexion point moved to b and "slope
- constant" set to a.
- The first version, based on the hyperbolic tangent tanh, when
- combined with the scaling step, is an exact arithmetic clone of the
- the sigmoid function based on the logistic curve. The equivalence is
- based on the identity
- 1/(1+exp(-t)) = (1+tanh(t/2))/2
- (http://de.wikipedia.org/wiki/Sigmoidfunktion) and the fact that the
- scaled sigmoidal derivation is invariant under affine transformations
- of the ordinate.
- The tanh version is almost certainly more accurate and cheaper.
- The 0.5 factor in the argument is to clone the legacy ImageMagick
- behavior.
- The reason for making the define depend on atanh even though it only
- uses tanh has to do with the construction of the inverse of the scaled
- sigmoidal.
- */
-#if defined(MAGICKCORE_HAVE_ATANH)
-#define Sigmoidal(a,b,x) ( tanh((0.5*(a))*((x)-(b))) )
-#else
-#define Sigmoidal(a,b,x) ( 1.0/(1.0+exp((a)*((b)-(x)))) )
-#endif
- /*
- Scaled sigmoidal formula:
- ( Sigmoidal(a,b,x) - Sigmoidal(a,b,0) ) /
- ( Sigmoidal(a,b,1) - Sigmoidal(a,b,0) )
- See http://osdir.com/ml/video.image-magick.devel/2005-04/msg00006.html
- and http://www.cs.dartmouth.edu/farid/downloads/tutorials/fip.pdf.
- The limit of ScaledSigmoidal as a->0 is the identity, but a=0 gives a
- division by zero. This is fixed below by hardwiring the identity when a
- is small. This would appear to be safe because the series expansion of
- the logistic sigmoidal function around x=b is 1/2-a*(b-x)/4+... so that
- s(1)-s(0) is about a/4. (With tanh, it's a/2.)
- */
-#define ScaledSigmoidal(a,b,x) ( \
- (Sigmoidal((a),(b),(x))-Sigmoidal((a),(b),0.0)) \
- / \
- (Sigmoidal((a),(b),1.0)-Sigmoidal((a),(b),0.0)) )
- /*
- Inverse of ScaledSigmoidal, used for +sigmoidal-contrast:
- */
-#if defined(MAGICKCORE_HAVE_ATANH)
-#define InverseScaledSigmoidal(a,b,x) ( (b) + (2.0/(a)) * atanh( \
- (Sigmoidal((a),(b),1.0)-Sigmoidal((a),(b),0.0))*(x)+Sigmoidal((a),(b),0.0) ) )
-#else
-#define InverseScaledSigmoidal(a,b,x) ( (b) + (-1.0/(a)) * log( 1.0 / \
- ((Sigmoidal((a),(b),1.0)-Sigmoidal((a),(b),0.0))*(x)+Sigmoidal((a),(b),0.0)) \
- -1.0 ) )
-#endif
- /*
- Convenience macros. No clamping needed at the end because of monotonicity.
+ Convenience macros.
*/
-#define ScaledSig(x) ( (Quantum) (QuantumRange*ScaledSigmoidal(contrast, \
- QuantumScale*midpoint,QuantumScale*ClampToQuantum((x)))) )
-#define InverseScaledSig(x) ( (Quantum) (QuantumRange*InverseScaledSigmoidal( \
- contrast,QuantumScale*midpoint,QuantumScale*ClampToQuantum((x)))) )
-
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-
/*
- Sigmoidal-contrast enhance colormap:
+ Side effect: may clamp values unless contrast<MagickEpsilon, in which
+ case nothing is done.
+ */
+ if (contrast < MagickEpsilon)
+ return(MagickTrue);
+ /*
+ Sigmoidal-contrast enhance colormap.
*/
if (image->storage_class == PseudoClass)
{
- if (contrast>=MagickEpsilon)
- {
- register ssize_t
- i;
-
- if (sharpen != MagickFalse)
- {
- for (i=0; i < (ssize_t) image->colors; i++)
- {
- if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].red=ScaledSig(image->colormap[i].red);
- if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].green=ScaledSig(image->colormap[i].green);
- if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].blue=ScaledSig(image->colormap[i].blue);
- if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].alpha=ScaledSig(image->colormap[i].alpha);
- }
- }
- else
- {
- for (i=0; i < (ssize_t) image->colors; i++)
- {
- if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].red=
- InverseScaledSig(image->colormap[i].red);
- if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].green=
- InverseScaledSig(image->colormap[i].green);
- if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].blue=
- InverseScaledSig(image->colormap[i].blue);
- if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
- image->colormap[i].alpha=
- InverseScaledSig(image->colormap[i].alpha);
- }
- }
- }
+ register ssize_t
+ i;
+
+ if( IfMagickTrue(sharpen) )
+ for (i=0; i < (ssize_t) image->colors; i++)
+ {
+ if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].red=(MagickRealType) ScaledSig(
+ image->colormap[i].red);
+ if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].green=(MagickRealType) ScaledSig(
+ image->colormap[i].green);
+ if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].blue=(MagickRealType) ScaledSig(
+ image->colormap[i].blue);
+ if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].alpha=(MagickRealType) ScaledSig(
+ image->colormap[i].alpha);
+ }
+ else
+ for (i=0; i < (ssize_t) image->colors; i++)
+ {
+ if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].red=(MagickRealType) InverseScaledSig(
+ image->colormap[i].red);
+ if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].green=(MagickRealType) InverseScaledSig(
+ image->colormap[i].green);
+ if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].blue=(MagickRealType) InverseScaledSig(
+ image->colormap[i].blue);
+ if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
+ image->colormap[i].alpha=(MagickRealType) InverseScaledSig(
+ image->colormap[i].alpha);
+ }
}
/*
- Sigmoidal-contrast enhance image:
+ Sigmoidal-contrast enhance image.
*/
status=MagickTrue;
progress=0;
image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status) \
- dynamic_number_threads(image,image->columns,image->rows,1)
+ magick_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register ssize_t
x;
- if (status == MagickFalse)
+ if( IfMagickFalse(status) )
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;
+ i;
- if (GetPixelMask(image,q) != 0)
+ if (GetPixelReadMask(image,q) == 0)
{
q+=GetPixelChannels(image);
continue;
}
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- PixelChannel
- channel;
-
- PixelTrait
- traits;
-
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) == 0)
continue;
- if (contrast>=MagickEpsilon)
- {
- if (sharpen != MagickFalse)
- q[i]=ScaledSig(q[i]);
- else
- q[i]=InverseScaledSig(q[i]);
- }
+ if( IfMagickTrue(sharpen) )
+ q[i]=ScaledSig(q[i]);
+ else
+ q[i]=InverseScaledSig(q[i]);
}
q+=GetPixelChannels(image);
}
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ if( IfMagickFalse(SyncCacheViewAuthenticPixels(image_view,exception)) )
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
#endif
proceed=SetImageProgress(image,SigmoidalContrastImageTag,progress++,
image->rows);
- if (proceed == MagickFalse)
+ if( IfMagickFalse(proceed) )
status=MagickFalse;
}
}