% July 1992 %
% %
% %
-% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2011 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 "magick/enhance.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
+#include "magick/fx.h"
#include "magick/gem.h"
#include "magick/geometry.h"
#include "magick/histogram.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
+#include "magick/pixel-private.h"
#include "magick/quantum.h"
#include "magick/quantum-private.h"
#include "magick/resample.h"
#include "magick/resample-private.h"
#include "magick/statistic.h"
#include "magick/string_.h"
+#include "magick/string-private.h"
#include "magick/thread-private.h"
#include "magick/token.h"
#include "magick/xml-tree.h"
status;
double
- mean,junk,gamma,logmean;
+ mean,sans,gamma,logmean;
logmean=log(0.5);
/*
Apply gamma correction equally accross all given channels
*/
- GetImageChannelMean(image, channel, &mean, &junk, &image->exception);
- gamma = log(mean*QuantumScale)/logmean;
- //return GammaImageChannel(image, channel, gamma);
+ (void) GetImageChannelMean(image,channel,&mean,&sans,&image->exception);
+ gamma=log(mean*QuantumScale)/logmean;
return LevelImageChannel(image, channel,
0.0, (double)QuantumRange, gamma);
}
status = MagickTrue;
if ((channel & RedChannel) != 0)
{
- GetImageChannelMean(image, RedChannel, &mean, &junk, &image->exception);
- gamma = log(mean*QuantumScale)/logmean;
- //status = status && GammaImageChannel(image, RedChannel, gamma);
+ (void) GetImageChannelMean(image,RedChannel,&mean,&sans,
+ &image->exception);
+ gamma=log(mean*QuantumScale)/logmean;
status = status && LevelImageChannel(image, RedChannel,
0.0, (double)QuantumRange, gamma);
}
if ((channel & GreenChannel) != 0)
{
- GetImageChannelMean(image, GreenChannel, &mean, &junk, &image->exception);
- gamma = log(mean*QuantumScale)/logmean;
- //status = status && GammaImageChannel(image, GreenChannel, gamma);
+ (void) GetImageChannelMean(image,GreenChannel,&mean,&sans,
+ &image->exception);
+ gamma=log(mean*QuantumScale)/logmean;
status = status && LevelImageChannel(image, GreenChannel,
0.0, (double)QuantumRange, gamma);
}
if ((channel & BlueChannel) != 0)
{
- GetImageChannelMean(image, BlueChannel, &mean, &junk, &image->exception);
- gamma = log(mean*QuantumScale)/logmean;
- //status = status && GammaImageChannel(image, BlueChannel, gamma);
+ (void) GetImageChannelMean(image,BlueChannel,&mean,&sans,
+ &image->exception);
+ gamma=log(mean*QuantumScale)/logmean;
status = status && LevelImageChannel(image, BlueChannel,
0.0, (double)QuantumRange, gamma);
}
if (((channel & OpacityChannel) != 0) &&
(image->matte == MagickTrue))
{
- GetImageChannelMean(image, OpacityChannel, &mean, &junk, &image->exception);
- gamma = log(mean*QuantumScale)/logmean;
- //status = status && GammaImageChannel(image, OpacityChannel, gamma);
+ (void) GetImageChannelMean(image,OpacityChannel,&mean,&sans,
+ &image->exception);
+ gamma=log(mean*QuantumScale)/logmean;
status = status && LevelImageChannel(image, OpacityChannel,
0.0, (double)QuantumRange, gamma);
}
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
{
- GetImageChannelMean(image, IndexChannel, &mean, &junk, &image->exception);
- gamma = log(mean*QuantumScale)/logmean;
- //status = status && GammaImageChannel(image, IndexChannel, gamma);
+ (void) GetImageChannelMean(image,IndexChannel,&mean,&sans,
+ &image->exception);
+ gamma=log(mean*QuantumScale)/logmean;
status = status && LevelImageChannel(image, IndexChannel,
0.0, (double)QuantumRange, gamma);
}
% %
% %
% %
+% B r i g h t n e s s C o n t r a s t I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% Use BrightnessContrastImage() to change the brightness and/or contrast of
+% an image. It converts the brightness and contrast parameters into slope
+% and intercept and calls a polynomical function to apply to the image.
+%
+% The format of the BrightnessContrastImage method is:
+%
+% MagickBooleanType BrightnessContrastImage(Image *image,
+% const double brightness,const double contrast)
+% MagickBooleanType BrightnessContrastImageChannel(Image *image,
+% const ChannelType channel,const double brightness,
+% const double contrast)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o channel: the channel.
+%
+% o brightness: the brightness percent (-100 .. 100).
+%
+% o contrast: the contrast percent (-100 .. 100).
+%
+*/
+
+MagickExport MagickBooleanType BrightnessContrastImage(Image *image,
+ const double brightness,const double contrast)
+{
+ MagickBooleanType
+ status;
+
+ status=BrightnessContrastImageChannel(image,DefaultChannels,brightness,
+ contrast);
+ return(status);
+}
+
+MagickExport MagickBooleanType BrightnessContrastImageChannel(Image *image,
+ const ChannelType channel,const double brightness,const double contrast)
+{
+#define BrightnessContastImageTag "BrightnessContast/Image"
+
+ double
+ alpha,
+ intercept,
+ coefficients[2],
+ slope;
+
+ MagickBooleanType
+ status;
+
+ /*
+ Compute slope and intercept.
+ */
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickSignature);
+ if (image->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ alpha=contrast;
+ slope=tan((double) (MagickPI*(alpha/100.0+1.0)/4.0));
+ if (slope < 0.0)
+ slope=0.0;
+ intercept=brightness/100.0+((100-brightness)/200.0)*(1.0-slope);
+ coefficients[0]=slope;
+ coefficients[1]=intercept;
+ status=FunctionImageChannel(image,channel,PolynomialFunction,2,coefficients,
+ &image->exception);
+ return(status);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% C o l o r D e c i s i o n L i s t I m a g e %
% %
% %
saturation;
} ColorCorrection;
+ CacheView
+ *image_view;
+
char
token[MaxTextExtent];
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
PixelPacket
*cdl_map;
- register long
+ register ssize_t
i;
+ ssize_t
+ y;
+
XMLTreeInfo
*cc,
*ccc,
*sat,
*sop;
- CacheView
- *image_view;
-
/*
Allocate and initialize cdl maps.
*/
GetMagickToken(p,&p,token);
switch (i)
{
- case 0: color_correction.red.slope=atof(token); break;
- case 1: color_correction.green.slope=atof(token); break;
- case 2: color_correction.blue.slope=atof(token); break;
+ case 0: color_correction.red.slope=LocaleToDouble(token,(char **) NULL); break;
+ case 1: color_correction.green.slope=LocaleToDouble(token,(char **) NULL); break;
+ case 2: color_correction.blue.slope=LocaleToDouble(token,(char **) NULL); break;
}
}
}
GetMagickToken(p,&p,token);
switch (i)
{
- case 0: color_correction.red.offset=atof(token); break;
- case 1: color_correction.green.offset=atof(token); break;
- case 2: color_correction.blue.offset=atof(token); break;
+ case 0: color_correction.red.offset=LocaleToDouble(token,(char **) NULL); break;
+ case 1: color_correction.green.offset=LocaleToDouble(token,(char **) NULL); break;
+ case 2: color_correction.blue.offset=LocaleToDouble(token,(char **) NULL); break;
}
}
}
GetMagickToken(p,&p,token);
switch (i)
{
- case 0: color_correction.red.power=atof(token); break;
- case 1: color_correction.green.power=atof(token); break;
- case 2: color_correction.blue.power=atof(token); break;
+ case 0: color_correction.red.power=LocaleToDouble(token,(char **) NULL); break;
+ case 1: color_correction.green.power=LocaleToDouble(token,(char **) NULL); break;
+ case 2: color_correction.blue.power=LocaleToDouble(token,(char **) NULL); break;
}
}
}
content=GetXMLTreeContent(saturation);
p=(const char *) content;
GetMagickToken(p,&p,token);
- color_correction.saturation=atof(token);
+ color_correction.saturation=LocaleToDouble(token,(char **) NULL);
}
}
ccc=DestroyXMLTree(ccc);
if (cdl_map == (PixelPacket *) NULL)
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4)
#endif
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
- cdl_map[i].red=RoundToQuantum((MagickRealType) ScaleMapToQuantum((
+ cdl_map[i].red=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
MagickRealType) (MaxMap*(pow(color_correction.red.slope*i/MaxMap+
color_correction.red.offset,color_correction.red.power)))));
- cdl_map[i].green=RoundToQuantum((MagickRealType) ScaleMapToQuantum((
+ cdl_map[i].green=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
MagickRealType) (MaxMap*(pow(color_correction.green.slope*i/MaxMap+
color_correction.green.offset,color_correction.green.power)))));
- cdl_map[i].blue=RoundToQuantum((MagickRealType) ScaleMapToQuantum((
+ cdl_map[i].blue=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
MagickRealType) (MaxMap*(pow(color_correction.blue.slope*i/MaxMap+
color_correction.blue.offset,color_correction.blue.power)))));
}
/*
Apply transfer function to colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
double
luma;
luma=0.2126*image->colormap[i].red+0.7152*image->colormap[i].green+
0.0722*image->colormap[i].blue;
- image->colormap[i].red=RoundToQuantum(luma+color_correction.saturation*
+ image->colormap[i].red=ClampToQuantum(luma+color_correction.saturation*
cdl_map[ScaleQuantumToMap(image->colormap[i].red)].red-luma);
- image->colormap[i].green=RoundToQuantum(luma+
+ image->colormap[i].green=ClampToQuantum(luma+
color_correction.saturation*cdl_map[ScaleQuantumToMap(
image->colormap[i].green)].green-luma);
- image->colormap[i].blue=RoundToQuantum(luma+color_correction.saturation*
+ image->colormap[i].blue=ClampToQuantum(luma+color_correction.saturation*
cdl_map[ScaleQuantumToMap(image->colormap[i].blue)].blue-luma);
}
}
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
double
luma;
- register long
- x;
-
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
status=MagickFalse;
continue;
}
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- luma=0.2126*q->red+0.7152*q->green+0.0722*q->blue;
- q->red=RoundToQuantum(luma+color_correction.saturation*
- (cdl_map[ScaleQuantumToMap(q->red)].red-luma));
- q->green=RoundToQuantum(luma+color_correction.saturation*
- (cdl_map[ScaleQuantumToMap(q->green)].green-luma));
- q->blue=RoundToQuantum(luma+color_correction.saturation*
- (cdl_map[ScaleQuantumToMap(q->blue)].blue-luma));
+ luma=0.2126*GetRedPixelComponent(q)+0.7152*GetGreenPixelComponent(q)+
+ 0.0722*GetBluePixelComponent(q);
+ SetRedPixelComponent(q,ClampToQuantum(luma+color_correction.saturation*
+ (cdl_map[ScaleQuantumToMap(GetRedPixelComponent(q))].red-luma)));
+ SetGreenPixelComponent(q,ClampToQuantum(luma+color_correction.saturation*
+ (cdl_map[ScaleQuantumToMap(GetGreenPixelComponent(q))].green-luma)));
+ SetBluePixelComponent(q,ClampToQuantum(luma+color_correction.saturation*
+ (cdl_map[ScaleQuantumToMap(GetBluePixelComponent(q))].blue-luma)));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_ColorDecisionListImageChannel)
#endif
proceed=SetImageProgress(image,ColorDecisionListCorrectImageTag,
{
#define ClutImageTag "Clut/Image"
+ CacheView
+ *clut_view,
+ *image_view;
+
ExceptionInfo
*exception;
- long
- adjust,
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickPixelPacket
- zero;
+ *clut_map;
- ResampleFilter
- **resample_filter;
+ register ssize_t
+ i;
- CacheView
- *image_view;
+ ssize_t
+ adjust,
+ y;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
assert(clut_image->signature == MagickSignature);
if (SetImageStorageClass(image,DirectClass) == MagickFalse)
return(MagickFalse);
+ clut_map=(MagickPixelPacket *) AcquireQuantumMemory(MaxMap+1UL,
+ sizeof(*clut_map));
+ if (clut_map == (MagickPixelPacket *) NULL)
+ ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
+ image->filename);
/*
Clut image.
*/
status=MagickTrue;
progress=0;
- GetMagickPixelPacket(clut_image,&zero);
- adjust=clut_image->interpolate == IntegerInterpolatePixel ? 0 : 1;
+ adjust=(ssize_t) (clut_image->interpolate == IntegerInterpolatePixel ? 0 : 1);
exception=(&image->exception);
- resample_filter=AcquireResampleFilterThreadSet(clut_image,MagickTrue,
- exception);
+ clut_view=AcquireCacheView(clut_image);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4)
+#endif
+ for (i=0; i <= (ssize_t) MaxMap; i++)
+ {
+ GetMagickPixelPacket(clut_image,clut_map+i);
+ (void) InterpolateMagickPixelPacket(clut_image,clut_view,
+ UndefinedInterpolatePixel,QuantumScale*i*(clut_image->columns-adjust),
+ QuantumScale*i*(clut_image->rows-adjust),clut_map+i,exception);
+ }
+ clut_view=DestroyCacheView(clut_view);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
MagickPixelPacket
pixel;
register IndexPacket
- *__restrict indexes;
-
- register long
- id,
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- pixel=zero;
- id=GetOpenMPThreadId();
- for (x=0; x < (long) image->columns; x++)
+ GetMagickPixelPacket(image,&pixel);
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- /*
- PROGRAMMERS WARNING:
-
- Apply OpacityChannel BEFORE the color channels. Do not re-order.
-
- The handling special case 2 (coloring gray-scale), requires access to
- the unmodified colors of the original image to determine the index
- value. As such alpha/matte channel handling must be performed BEFORE,
- any of the color channels are modified.
-
- */
+ SetMagickPixelPacket(image,q,indexes+x,&pixel);
+ if ((channel & RedChannel) != 0)
+ SetRedPixelComponent(q,ClampRedPixelComponent(clut_map+
+ ScaleQuantumToMap(GetRedPixelComponent(q))));
+ if ((channel & GreenChannel) != 0)
+ SetGreenPixelComponent(q,ClampGreenPixelComponent(clut_map+
+ ScaleQuantumToMap(GetGreenPixelComponent(q))));
+ if ((channel & BlueChannel) != 0)
+ SetBluePixelComponent(q,ClampBluePixelComponent(clut_map+
+ ScaleQuantumToMap(GetBluePixelComponent(q))));
if ((channel & OpacityChannel) != 0)
{
if (clut_image->matte == MagickFalse)
- {
- /*
- A gray-scale LUT replacement for an image alpha channel.
- */
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*
- (QuantumRange-q->opacity)*(clut_image->columns+adjust),
- QuantumScale*(QuantumRange-q->opacity)*(clut_image->rows+
- adjust),&pixel);
- q->opacity=(Quantum) (QuantumRange-MagickPixelIntensityToQuantum(
- &pixel));
- }
+ SetOpacityPixelComponent(q,(QuantumRange-
+ MagickPixelIntensityToQuantum(clut_map+ScaleQuantumToMap(
+ (Quantum) GetAlphaPixelComponent(q)))));
else
if (image->matte == MagickFalse)
- {
- /*
- A greyscale image being colored by a LUT with transparency.
- */
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*
- PixelIntensity(q)*(clut_image->columns-adjust),QuantumScale*
- PixelIntensity(q)*(clut_image->rows-adjust),&pixel);
- q->opacity=RoundToQuantum(pixel.opacity);
- }
+ SetOpacityPixelComponent(q,ClampOpacityPixelComponent(clut_map+
+ ScaleQuantumToMap((Quantum) MagickPixelIntensity(&pixel))));
else
- {
- /*
- Direct alpha channel lookup.
- */
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*
- q->opacity*(clut_image->columns-adjust),QuantumScale*
- q->opacity* (clut_image->rows-adjust),&pixel);
- q->opacity=RoundToQuantum(pixel.opacity);
- }
- }
- if ((channel & RedChannel) != 0)
- {
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*q->red*
- (clut_image->columns-adjust),QuantumScale*q->red*
- (clut_image->rows-adjust),&pixel);
- q->red=RoundToQuantum(pixel.red);
- }
- if ((channel & GreenChannel) != 0)
- {
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*q->green*
- (clut_image->columns-adjust),QuantumScale*q->green*
- (clut_image->rows-adjust),&pixel);
- q->green=RoundToQuantum(pixel.green);
- }
- if ((channel & BlueChannel) != 0)
- {
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*q->blue*
- (clut_image->columns-adjust),QuantumScale*q->blue*
- (clut_image->rows-adjust),&pixel);
- q->blue=RoundToQuantum(pixel.blue);
+ SetOpacityPixelComponent(q,ClampOpacityPixelComponent(
+ clut_map+ScaleQuantumToMap(GetOpacityPixelComponent(q))));
}
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- {
- (void) ResamplePixelColor(resample_filter[id],QuantumScale*indexes[x]*
- (clut_image->columns-adjust),QuantumScale*indexes[x]*
- (clut_image->rows-adjust),&pixel);
- indexes[x]=RoundToQuantum(pixel.index);
- }
+ SetIndexPixelComponent(indexes+x,ClampToQuantum((clut_map+(ssize_t)
+ GetIndexPixelComponent(indexes+x))->index));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_ClutImageChannel)
#endif
proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows);
}
}
image_view=DestroyCacheView(image_view);
- resample_filter=DestroyResampleFilterThreadSet(resample_filter);
- /*
- Enable alpha channel if CLUT image could enable it.
- */
+ clut_map=(MagickPixelPacket *) RelinquishMagickMemory(clut_map);
if ((clut_image->matte != MagickFalse) && ((channel & OpacityChannel) != 0))
(void) SetImageAlphaChannel(image,ActivateAlphaChannel);
return(status);
saturation=0.0;
brightness=0.0;
ConvertRGBToHSB(*red,*green,*blue,&hue,&saturation,&brightness);
- brightness+=0.5*sign*(0.5*(sin(MagickPI*(brightness-0.5))+1.0)-brightness);
+ brightness+=0.5*sign*(0.5*(sin((double) (MagickPI*(brightness-0.5)))+1.0)-
+ brightness);
if (brightness > 1.0)
brightness=1.0;
else
{
#define ContrastImageTag "Contrast/Image"
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
int
sign;
- long
- progress,
- y;
-
MagickBooleanType
status;
- register long
+ MagickOffsetType
+ progress;
+
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
/*
Contrast enhance colormap.
*/
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
Contrast(sign,&image->colormap[i].red,&image->colormap[i].green,
&image->colormap[i].blue);
}
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- register long
- x;
+ Quantum
+ blue,
+ green,
+ red;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
status=MagickFalse;
continue;
}
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- Contrast(sign,&q->red,&q->green,&q->blue);
+ red=GetRedPixelComponent(q);
+ green=GetGreenPixelComponent(q);
+ blue=GetBluePixelComponent(q);
+ Contrast(sign,&red,&green,&blue);
+ SetRedPixelComponent(q,red);
+ SetGreenPixelComponent(q,green);
+ SetBluePixelComponent(q,blue);
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_ContrastImage)
#endif
proceed=SetImageProgress(image,ContrastImageTag,progress++,image->rows);
% MagickBooleanType ContrastStretchImage(Image *image,
% const char *levels)
% MagickBooleanType ContrastStretchImageChannel(Image *image,
-% const unsigned long channel,const double black_point,
+% const size_t channel,const double black_point,
% const double white_point)
%
% A description of each parameter follows:
#define MaxRange(color) ((MagickRealType) ScaleQuantumToMap((Quantum) (color)))
#define ContrastStretchImageTag "ContrastStretch/Image"
+ CacheView
+ *image_view;
+
double
intensity;
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickPixelPacket
black,
*histogram,
*stretch_map,
white;
- register long
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
Allocate histogram and stretch map.
exception=(&image->exception);
(void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram));
image_view=AcquireCacheView(image);
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register const PixelPacket
- *__restrict p;
+ *restrict p;
register IndexPacket
- *__restrict indexes;
+ *restrict indexes;
- register long
+ register ssize_t
x;
if (status == MagickFalse)
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
if (channel == DefaultChannels)
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
Quantum
intensity;
p++;
}
else
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- histogram[ScaleQuantumToMap(p->red)].red++;
+ histogram[ScaleQuantumToMap(GetRedPixelComponent(p))].red++;
if ((channel & GreenChannel) != 0)
- histogram[ScaleQuantumToMap(p->green)].green++;
+ histogram[ScaleQuantumToMap(GetGreenPixelComponent(p))].green++;
if ((channel & BlueChannel) != 0)
- histogram[ScaleQuantumToMap(p->blue)].blue++;
+ histogram[ScaleQuantumToMap(GetBluePixelComponent(p))].blue++;
if ((channel & OpacityChannel) != 0)
- histogram[ScaleQuantumToMap(p->opacity)].opacity++;
+ histogram[ScaleQuantumToMap(GetOpacityPixelComponent(p))].opacity++;
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- histogram[ScaleQuantumToMap(indexes[x])].index++;
+ histogram[ScaleQuantumToMap(GetIndexPixelComponent(
+ indexes+x))].index++;
p++;
}
}
if ((channel & RedChannel) != 0)
{
intensity=0.0;
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
intensity+=histogram[i].red;
if (intensity > black_point)
}
black.red=(MagickRealType) i;
intensity=0.0;
- for (i=(long) MaxMap; i != 0; i--)
+ for (i=(ssize_t) MaxMap; i != 0; i--)
{
intensity+=histogram[i].red;
if (intensity > ((double) image->columns*image->rows-white_point))
if ((channel & GreenChannel) != 0)
{
intensity=0.0;
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
intensity+=histogram[i].green;
if (intensity > black_point)
}
black.green=(MagickRealType) i;
intensity=0.0;
- for (i=(long) MaxMap; i != 0; i--)
+ for (i=(ssize_t) MaxMap; i != 0; i--)
{
intensity+=histogram[i].green;
if (intensity > ((double) image->columns*image->rows-white_point))
if ((channel & BlueChannel) != 0)
{
intensity=0.0;
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
intensity+=histogram[i].blue;
if (intensity > black_point)
}
black.blue=(MagickRealType) i;
intensity=0.0;
- for (i=(long) MaxMap; i != 0; i--)
+ for (i=(ssize_t) MaxMap; i != 0; i--)
{
intensity+=histogram[i].blue;
if (intensity > ((double) image->columns*image->rows-white_point))
if ((channel & OpacityChannel) != 0)
{
intensity=0.0;
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
intensity+=histogram[i].opacity;
if (intensity > black_point)
}
black.opacity=(MagickRealType) i;
intensity=0.0;
- for (i=(long) MaxMap; i != 0; i--)
+ for (i=(ssize_t) MaxMap; i != 0; i--)
{
intensity+=histogram[i].opacity;
if (intensity > ((double) image->columns*image->rows-white_point))
if (((channel & IndexChannel) != 0) && (image->colorspace == CMYKColorspace))
{
intensity=0.0;
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
intensity+=histogram[i].index;
if (intensity > black_point)
}
black.index=(MagickRealType) i;
intensity=0.0;
- for (i=(long) MaxMap; i != 0; i--)
+ for (i=(ssize_t) MaxMap; i != 0; i--)
{
intensity+=histogram[i].index;
if (intensity > ((double) image->columns*image->rows-white_point))
Stretch the histogram to create the stretched image mapping.
*/
(void) ResetMagickMemory(stretch_map,0,(MaxMap+1)*sizeof(*stretch_map));
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
if ((channel & RedChannel) != 0)
{
- if (i < (long) black.red)
+ if (i < (ssize_t) black.red)
stretch_map[i].red=0.0;
else
- if (i > (long) white.red)
+ if (i > (ssize_t) white.red)
stretch_map[i].red=(MagickRealType) QuantumRange;
else
if (black.red != white.red)
}
if ((channel & GreenChannel) != 0)
{
- if (i < (long) black.green)
+ if (i < (ssize_t) black.green)
stretch_map[i].green=0.0;
else
- if (i > (long) white.green)
+ if (i > (ssize_t) white.green)
stretch_map[i].green=(MagickRealType) QuantumRange;
else
if (black.green != white.green)
}
if ((channel & BlueChannel) != 0)
{
- if (i < (long) black.blue)
+ if (i < (ssize_t) black.blue)
stretch_map[i].blue=0.0;
else
- if (i > (long) white.blue)
+ if (i > (ssize_t) white.blue)
stretch_map[i].blue=(MagickRealType) QuantumRange;
else
if (black.blue != white.blue)
}
if ((channel & OpacityChannel) != 0)
{
- if (i < (long) black.opacity)
+ if (i < (ssize_t) black.opacity)
stretch_map[i].opacity=0.0;
else
- if (i > (long) white.opacity)
+ if (i > (ssize_t) white.opacity)
stretch_map[i].opacity=(MagickRealType) QuantumRange;
else
if (black.opacity != white.opacity)
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
{
- if (i < (long) black.index)
+ if (i < (ssize_t) black.index)
stretch_map[i].index=0.0;
else
- if (i > (long) white.index)
+ if (i > (ssize_t) white.index)
stretch_map[i].index=(MagickRealType) QuantumRange;
else
if (black.index != white.index)
/*
Stretch colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
if ((channel & RedChannel) != 0)
{
if (black.red != white.red)
- image->colormap[i].red=RoundToQuantum(stretch_map[
+ image->colormap[i].red=ClampToQuantum(stretch_map[
ScaleQuantumToMap(image->colormap[i].red)].red);
}
if ((channel & GreenChannel) != 0)
{
if (black.green != white.green)
- image->colormap[i].green=RoundToQuantum(stretch_map[
+ image->colormap[i].green=ClampToQuantum(stretch_map[
ScaleQuantumToMap(image->colormap[i].green)].green);
}
if ((channel & BlueChannel) != 0)
{
if (black.blue != white.blue)
- image->colormap[i].blue=RoundToQuantum(stretch_map[
+ image->colormap[i].blue=ClampToQuantum(stretch_map[
ScaleQuantumToMap(image->colormap[i].blue)].blue);
}
if ((channel & OpacityChannel) != 0)
{
if (black.opacity != white.opacity)
- image->colormap[i].opacity=RoundToQuantum(stretch_map[
+ image->colormap[i].opacity=ClampToQuantum(stretch_map[
ScaleQuantumToMap(image->colormap[i].opacity)].opacity);
}
}
*/
status=MagickTrue;
progress=0;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
{
if (black.red != white.red)
- q->red=RoundToQuantum(stretch_map[ScaleQuantumToMap(q->red)].red);
+ SetRedPixelComponent(q,ClampToQuantum(stretch_map[
+ ScaleQuantumToMap(GetRedPixelComponent(q))].red));
}
if ((channel & GreenChannel) != 0)
{
if (black.green != white.green)
- q->green=RoundToQuantum(stretch_map[ScaleQuantumToMap(
- q->green)].green);
+ SetGreenPixelComponent(q,ClampToQuantum(stretch_map[
+ ScaleQuantumToMap(GetGreenPixelComponent(q))].green));
}
if ((channel & BlueChannel) != 0)
{
if (black.blue != white.blue)
- q->blue=RoundToQuantum(stretch_map[ScaleQuantumToMap(
- q->blue)].blue);
+ SetBluePixelComponent(q,ClampToQuantum(stretch_map[
+ ScaleQuantumToMap(GetBluePixelComponent(q))].blue));
}
if ((channel & OpacityChannel) != 0)
{
if (black.opacity != white.opacity)
- q->opacity=RoundToQuantum(stretch_map[ScaleQuantumToMap(
- q->opacity)].opacity);
+ SetOpacityPixelComponent(q,ClampToQuantum(stretch_map[
+ ScaleQuantumToMap(GetOpacityPixelComponent(q))].opacity));
}
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
{
if (black.index != white.index)
- indexes[x]=(IndexPacket) RoundToQuantum(stretch_map[
- ScaleQuantumToMap(indexes[x])].index);
+ SetIndexPixelComponent(indexes+x,ClampToQuantum(stretch_map[
+ ScaleQuantumToMap(GetIndexPixelComponent(indexes+x))].index));
}
q++;
}
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_ContrastStretchImageChannel)
#endif
proceed=SetImageProgress(image,ContrastStretchImageTag,progress++,
MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
{
#define Enhance(weight) \
- mean=((MagickRealType) r->red+pixel.red)/2; \
- distance=(MagickRealType) r->red-(MagickRealType) pixel.red; \
+ mean=((MagickRealType) GetRedPixelComponent(r)+pixel.red)/2; \
+ distance=(MagickRealType) GetRedPixelComponent(r)-(MagickRealType) pixel.red; \
distance_squared=QuantumScale*(2.0*((MagickRealType) QuantumRange+1.0)+ \
mean)*distance*distance; \
- mean=((MagickRealType) r->green+pixel.green)/2; \
- distance=(MagickRealType) r->green-(MagickRealType) pixel.green; \
+ mean=((MagickRealType) GetGreenPixelComponent(r)+pixel.green)/2; \
+ distance=(MagickRealType) GetGreenPixelComponent(r)-(MagickRealType) \
+ pixel.green; \
distance_squared+=4.0*distance*distance; \
- mean=((MagickRealType) r->blue+pixel.blue)/2; \
- distance=(MagickRealType) r->blue-(MagickRealType) pixel.blue; \
+ mean=((MagickRealType) GetBluePixelComponent(r)+pixel.blue)/2; \
+ distance=(MagickRealType) GetBluePixelComponent(r)-(MagickRealType) \
+ pixel.blue; \
distance_squared+=QuantumScale*(3.0*((MagickRealType) \
QuantumRange+1.0)-1.0-mean)*distance*distance; \
mean=((MagickRealType) r->opacity+pixel.opacity)/2; \
if (distance_squared < ((MagickRealType) QuantumRange*(MagickRealType) \
QuantumRange/25.0f)) \
{ \
- aggregate.red+=(weight)*r->red; \
- aggregate.green+=(weight)*r->green; \
- aggregate.blue+=(weight)*r->blue; \
- aggregate.opacity+=(weight)*r->opacity; \
+ aggregate.red+=(weight)*GetRedPixelComponent(r); \
+ aggregate.green+=(weight)*GetGreenPixelComponent(r); \
+ aggregate.blue+=(weight)*GetBluePixelComponent(r); \
+ aggregate.opacity+=(weight)*GetOpacityPixelComponent(r); \
total_weight+=(weight); \
} \
r++;
#define EnhanceImageTag "Enhance/Image"
+ CacheView
+ *enhance_view,
+ *image_view;
+
Image
*enhance_image;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickPixelPacket
zero;
- CacheView
- *enhance_view,
- *image_view;
+ ssize_t
+ y;
/*
Initialize enhanced image attributes.
(void) ResetMagickMemory(&zero,0,sizeof(zero));
image_view=AcquireCacheView(image);
enhance_view=AcquireCacheView(enhance_image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register const PixelPacket
- *__restrict p;
-
- register long
- x;
+ *restrict p;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
/*
Read another scan line.
status=MagickFalse;
continue;
}
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
MagickPixelPacket
aggregate;
pixel;
register const PixelPacket
- *__restrict r;
+ *restrict r;
/*
Compute weighted average of target pixel color components.
Enhance(8.0); Enhance(20.0); Enhance(40.0); Enhance(20.0); Enhance(8.0);
r=p+4*(image->columns+4);
Enhance(5.0); Enhance(8.0); Enhance(10.0); Enhance(8.0); Enhance(5.0);
- q->red=(Quantum) ((aggregate.red+(total_weight/2)-1)/total_weight);
- q->green=(Quantum) ((aggregate.green+(total_weight/2)-1)/total_weight);
- q->blue=(Quantum) ((aggregate.blue+(total_weight/2)-1)/total_weight);
- q->opacity=(Quantum) ((aggregate.opacity+(total_weight/2)-1)/
+ SetRedPixelComponent(q,(aggregate.red+(total_weight/2)-1)/total_weight);
+ SetGreenPixelComponent(q,(aggregate.green+(total_weight/2)-1)/
+ total_weight);
+ SetBluePixelComponent(q,(aggregate.blue+(total_weight/2)-1)/total_weight);
+ SetOpacityPixelComponent(q,(aggregate.opacity+(total_weight/2)-1)/
total_weight);
p++;
q++;
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_EnhanceImage)
#endif
proceed=SetImageProgress(image,EnhanceImageTag,progress++,image->rows);
{
#define EqualizeImageTag "Equalize/Image"
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickPixelPacket
black,
*equalize_map,
*map,
white;
- register long
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
Allocate and initialize histogram arrays.
*/
(void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram));
exception=(&image->exception);
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register const IndexPacket
- *__restrict indexes;
+ *restrict indexes;
register const PixelPacket
- *__restrict p;
+ *restrict p;
- register long
+ register ssize_t
x;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetVirtualIndexQueue(image);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- histogram[ScaleQuantumToMap(p->red)].red++;
+ histogram[ScaleQuantumToMap(GetRedPixelComponent(p))].red++;
if ((channel & GreenChannel) != 0)
- histogram[ScaleQuantumToMap(p->green)].green++;
+ histogram[ScaleQuantumToMap(GetGreenPixelComponent(p))].green++;
if ((channel & BlueChannel) != 0)
- histogram[ScaleQuantumToMap(p->blue)].blue++;
+ histogram[ScaleQuantumToMap(GetBluePixelComponent(p))].blue++;
if ((channel & OpacityChannel) != 0)
- histogram[ScaleQuantumToMap(p->opacity)].opacity++;
+ histogram[ScaleQuantumToMap(GetOpacityPixelComponent(p))].opacity++;
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- histogram[ScaleQuantumToMap(indexes[x])].index++;
+ histogram[ScaleQuantumToMap(GetIndexPixelComponent(indexes+x))].index++;
p++;
}
}
Integrate the histogram to get the equalization map.
*/
(void) ResetMagickMemory(&intensity,0,sizeof(intensity));
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
if ((channel & RedChannel) != 0)
intensity.red+=histogram[i].red;
black=map[0];
white=map[(int) MaxMap];
(void) ResetMagickMemory(equalize_map,0,(MaxMap+1)*sizeof(*equalize_map));
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
if (((channel & RedChannel) != 0) && (white.red != black.red))
equalize_map[i].red=(MagickRealType) ScaleMapToQuantum((MagickRealType)
/*
Equalize colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
if (((channel & RedChannel) != 0) && (white.red != black.red))
- image->colormap[i].red=RoundToQuantum(equalize_map[
+ image->colormap[i].red=ClampToQuantum(equalize_map[
ScaleQuantumToMap(image->colormap[i].red)].red);
if (((channel & GreenChannel) != 0) && (white.green != black.green))
- image->colormap[i].green=RoundToQuantum(equalize_map[
+ image->colormap[i].green=ClampToQuantum(equalize_map[
ScaleQuantumToMap(image->colormap[i].green)].green);
if (((channel & BlueChannel) != 0) && (white.blue != black.blue))
- image->colormap[i].blue=RoundToQuantum(equalize_map[
+ image->colormap[i].blue=ClampToQuantum(equalize_map[
ScaleQuantumToMap(image->colormap[i].blue)].blue);
if (((channel & OpacityChannel) != 0) &&
(white.opacity != black.opacity))
- image->colormap[i].opacity=RoundToQuantum(equalize_map[
+ image->colormap[i].opacity=ClampToQuantum(equalize_map[
ScaleQuantumToMap(image->colormap[i].opacity)].opacity);
}
}
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if (((channel & RedChannel) != 0) && (white.red != black.red))
- q->red=RoundToQuantum(equalize_map[ScaleQuantumToMap(q->red)].red);
+ SetRedPixelComponent(q,ClampToQuantum(equalize_map[
+ ScaleQuantumToMap(GetRedPixelComponent(q))].red));
if (((channel & GreenChannel) != 0) && (white.green != black.green))
- q->green=RoundToQuantum(equalize_map[ScaleQuantumToMap(
- q->green)].green);
+ SetGreenPixelComponent(q,ClampToQuantum(equalize_map[
+ ScaleQuantumToMap(GetGreenPixelComponent(q))].green));
if (((channel & BlueChannel) != 0) && (white.blue != black.blue))
- q->blue=RoundToQuantum(equalize_map[ScaleQuantumToMap(q->blue)].blue);
+ SetBluePixelComponent(q,ClampToQuantum(equalize_map[
+ ScaleQuantumToMap(GetBluePixelComponent(q))].blue));
if (((channel & OpacityChannel) != 0) && (white.opacity != black.opacity))
- q->opacity=RoundToQuantum(equalize_map[ScaleQuantumToMap(
- q->opacity)].opacity);
+ SetOpacityPixelComponent(q,ClampToQuantum(equalize_map[
+ ScaleQuantumToMap(GetOpacityPixelComponent(q))].opacity));
if ((((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace)) &&
(white.index != black.index))
- indexes[x]=RoundToQuantum(equalize_map[ScaleQuantumToMap(
- indexes[x])].index);
+ SetIndexPixelComponent(indexes+x,ClampToQuantum(equalize_map[
+ ScaleQuantumToMap(GetIndexPixelComponent(indexes+x))].index));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_EqualizeImageChannel)
#endif
proceed=SetImageProgress(image,EqualizeImageTag,progress++,image->rows);
%
% The format of the GammaImage method is:
%
-% MagickBooleanType GammaImage(Image *image,const double gamma)
+% MagickBooleanType GammaImage(Image *image,const char *level)
% MagickBooleanType GammaImageChannel(Image *image,
% const ChannelType channel,const double gamma)
%
%
% o channel: the channel.
%
+% o level: the image gamma as a string (e.g. 1.6,1.2,1.0).
+%
% o gamma: the image gamma.
%
*/
{
#define GammaCorrectImageTag "GammaCorrect/Image"
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
Quantum
*gamma_map;
- register long
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
Allocate and initialize gamma maps.
image->filename);
(void) ResetMagickMemory(gamma_map,0,(MaxMap+1)*sizeof(*gamma_map));
if (gamma != 0.0)
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4)
#endif
- for (i=0; i <= (long) MaxMap; i++)
- gamma_map[i]=RoundToQuantum((MagickRealType) ScaleMapToQuantum((
+ for (i=0; i <= (ssize_t) MaxMap; i++)
+ gamma_map[i]=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
MagickRealType) (MaxMap*pow((double) i/MaxMap,1.0/gamma))));
if (image->storage_class == PseudoClass)
{
/*
Gamma-correct colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
if ((channel & RedChannel) != 0)
image->colormap[i].red=gamma_map[
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if (channel == DefaultChannels)
{
- q->red=gamma_map[ScaleQuantumToMap(q->red)];
- q->green=gamma_map[ScaleQuantumToMap(q->green)];
- q->blue=gamma_map[ScaleQuantumToMap(q->blue)];
+ SetRedPixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetRedPixelComponent(q))]);
+ SetGreenPixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetGreenPixelComponent(q))]);
+ SetBluePixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetBluePixelComponent(q))]);
}
else
{
if ((channel & RedChannel) != 0)
- q->red=gamma_map[ScaleQuantumToMap(q->red)];
+ SetRedPixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetRedPixelComponent(q))]);
if ((channel & GreenChannel) != 0)
- q->green=gamma_map[ScaleQuantumToMap(q->green)];
+ SetGreenPixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetGreenPixelComponent(q))]);
if ((channel & BlueChannel) != 0)
- q->blue=gamma_map[ScaleQuantumToMap(q->blue)];
+ SetBluePixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetBluePixelComponent(q))]);
if ((channel & OpacityChannel) != 0)
{
if (image->matte == MagickFalse)
- q->opacity=gamma_map[ScaleQuantumToMap(q->opacity)];
+ SetOpacityPixelComponent(q,gamma_map[ScaleQuantumToMap(
+ GetOpacityPixelComponent(q))]);
else
- q->opacity=(Quantum) QuantumRange-gamma_map[
- ScaleQuantumToMap((Quantum) (QuantumRange-q->opacity))];
+ SetOpacityPixelComponent(q,(Quantum) QuantumRange-gamma_map[
+ ScaleQuantumToMap((Quantum) GetAlphaPixelComponent(q))]);
}
}
q++;
}
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- for (x=0; x < (long) image->columns; x++)
- indexes[x]=gamma_map[ScaleQuantumToMap(indexes[x])];
+ for (x=0; x < (ssize_t) image->columns; x++)
+ SetIndexPixelComponent(indexes+x,gamma_map[ScaleQuantumToMap(
+ GetIndexPixelComponent(indexes+x))]);
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
if (image->progress_monitor != (MagickProgressMonitor) NULL)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_GammaImageChannel)
#endif
proceed=SetImageProgress(image,GammaCorrectImageTag,progress++,
z;
} HaldInfo;
+ CacheView
+ *hald_view,
+ *image_view;
+
double
width;
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickPixelPacket
zero;
- ResampleFilter
- **resample_filter;
-
size_t
cube_size,
length,
level;
- CacheView
- *image_view;
+ ssize_t
+ y;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
width=(double) hald_image->columns;
GetMagickPixelPacket(hald_image,&zero);
exception=(&image->exception);
- resample_filter=AcquireResampleFilterThreadSet(hald_image,MagickTrue,
- exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+ hald_view=AcquireCacheView(hald_image);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
double
offset;
pixel4;
register IndexPacket
- *__restrict indexes;
-
- register long
- id,
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
status=MagickFalse;
continue;
}
- indexes=GetCacheViewAuthenticIndexQueue(image_view);
+ indexes=GetCacheViewAuthenticIndexQueue(hald_view);
pixel=zero;
pixel1=zero;
pixel2=zero;
pixel3=zero;
pixel4=zero;
- id=GetOpenMPThreadId();
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- point.x=QuantumScale*(level-1.0)*q->red;
- point.y=QuantumScale*(level-1.0)*q->green;
- point.z=QuantumScale*(level-1.0)*q->blue;
+ point.x=QuantumScale*(level-1.0)*GetRedPixelComponent(q);
+ point.y=QuantumScale*(level-1.0)*GetGreenPixelComponent(q);
+ point.z=QuantumScale*(level-1.0)*GetBluePixelComponent(q);
offset=point.x+level*floor(point.y)+cube_size*floor(point.z);
point.x-=floor(point.x);
point.y-=floor(point.y);
point.z-=floor(point.z);
- (void) ResamplePixelColor(resample_filter[id],fmod(offset,width),
- floor(offset/width),&pixel1);
- (void) ResamplePixelColor(resample_filter[id],fmod(offset+level,width),
- floor((offset+level)/width),&pixel2);
+ (void) InterpolateMagickPixelPacket(image,hald_view,
+ UndefinedInterpolatePixel,fmod(offset,width),floor(offset/width),
+ &pixel1,exception);
+ (void) InterpolateMagickPixelPacket(image,hald_view,
+ UndefinedInterpolatePixel,fmod(offset+level,width),floor((offset+level)/
+ width),&pixel2,exception);
MagickPixelCompositeAreaBlend(&pixel1,pixel1.opacity,&pixel2,
pixel2.opacity,point.y,&pixel3);
offset+=cube_size;
- (void) ResamplePixelColor(resample_filter[id],fmod(offset,width),
- floor(offset/width),&pixel1);
- (void) ResamplePixelColor(resample_filter[id],fmod(offset+level,width),
- floor((offset+level)/width),&pixel2);
+ (void) InterpolateMagickPixelPacket(image,hald_view,
+ UndefinedInterpolatePixel,fmod(offset,width),floor(offset/width),
+ &pixel1,exception);
+ (void) InterpolateMagickPixelPacket(image,hald_view,
+ UndefinedInterpolatePixel,fmod(offset+level,width),floor((offset+level)/
+ width),&pixel2,exception);
MagickPixelCompositeAreaBlend(&pixel1,pixel1.opacity,&pixel2,
pixel2.opacity,point.y,&pixel4);
MagickPixelCompositeAreaBlend(&pixel3,pixel3.opacity,&pixel4,
pixel4.opacity,point.z,&pixel);
if ((channel & RedChannel) != 0)
- q->red=RoundToQuantum(pixel.red);
+ SetRedPixelComponent(q,ClampToQuantum(pixel.red));
if ((channel & GreenChannel) != 0)
- q->green=RoundToQuantum(pixel.green);
+ SetGreenPixelComponent(q,ClampToQuantum(pixel.green));
if ((channel & BlueChannel) != 0)
- q->blue=RoundToQuantum(pixel.blue);
+ SetBluePixelComponent(q,ClampToQuantum(pixel.blue));
if (((channel & OpacityChannel) != 0) && (image->matte != MagickFalse))
- q->opacity=RoundToQuantum(pixel.opacity);
+ SetOpacityPixelComponent(q,ClampToQuantum(pixel.opacity));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=RoundToQuantum(pixel.index);
+ SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel.index));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_HaldClutImageChannel)
#endif
proceed=SetImageProgress(image,HaldClutImageTag,progress++,image->rows);
status=MagickFalse;
}
}
+ hald_view=DestroyCacheView(hald_view);
image_view=DestroyCacheView(image_view);
- resample_filter=DestroyResampleFilterThreadSet(resample_filter);
return(status);
}
\f
% use 1.0 for purely linear stretching of image color values
%
*/
-
-MagickExport MagickBooleanType LevelizeImage(Image *image,
- const double black_point,const double white_point,const double gamma)
-{
- MagickBooleanType
- status;
-
- status=LevelizeImageChannel(image,DefaultChannels,black_point,white_point,
- gamma);
- return(status);
-}
-
MagickExport MagickBooleanType LevelImageChannel(Image *image,
const ChannelType channel,const double black_point,const double white_point,
const double gamma)
{
#define LevelImageTag "Level/Image"
-#define LevelValue(x) (RoundToQuantum((MagickRealType) QuantumRange* \
- pow(((double) (x)-black_point)/(white_point-black_point),1.0/gamma)))
+#define LevelQuantum(x) (ClampToQuantum((MagickRealType) QuantumRange* \
+ pow(scale*((double) (x)-black_point),1.0/gamma)))
+
+ CacheView
+ *image_view;
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
- register long
+ MagickOffsetType
+ progress;
+
+ register double
+ scale;
+
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
Allocate and initialize levels map.
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ scale=(white_point != black_point) ? 1.0/(white_point-black_point) : 1.0;
if (image->storage_class == PseudoClass)
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
/*
Level colormap.
*/
if ((channel & RedChannel) != 0)
- image->colormap[i].red=LevelValue(image->colormap[i].red);
+ image->colormap[i].red=LevelQuantum(image->colormap[i].red);
if ((channel & GreenChannel) != 0)
- image->colormap[i].green=LevelValue(image->colormap[i].green);
+ image->colormap[i].green=LevelQuantum(image->colormap[i].green);
if ((channel & BlueChannel) != 0)
- image->colormap[i].blue=LevelValue(image->colormap[i].blue);
+ image->colormap[i].blue=LevelQuantum(image->colormap[i].blue);
if ((channel & OpacityChannel) != 0)
- image->colormap[i].opacity=LevelValue(image->colormap[i].opacity);
+ image->colormap[i].opacity=LevelQuantum(image->colormap[i].opacity);
}
/*
Level image.
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- q->red=LevelValue(q->red);
+ SetRedPixelComponent(q,LevelQuantum(GetRedPixelComponent(q)));
if ((channel & GreenChannel) != 0)
- q->green=LevelValue(q->green);
+ SetGreenPixelComponent(q,LevelQuantum(GetGreenPixelComponent(q)));
if ((channel & BlueChannel) != 0)
- q->blue=LevelValue(q->blue);
+ SetBluePixelComponent(q,LevelQuantum(GetBluePixelComponent(q)));
if (((channel & OpacityChannel) != 0) &&
(image->matte == MagickTrue))
- q->opacity=LevelValue(q->opacity);
+ SetOpacityPixelComponent(q,QuantumRange-LevelQuantum(QuantumRange-
+ q->opacity));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=LevelValue(indexes[x]);
+ SetIndexPixelComponent(indexes+x,LevelQuantum(
+ GetIndexPixelComponent(indexes+x)));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_LevelImageChannel)
#endif
proceed=SetImageProgress(image,LevelImageTag,progress++,image->rows);
% o gamma: adjust gamma by this factor before mapping values.
%
*/
+
+MagickExport MagickBooleanType LevelizeImage(Image *image,
+ const double black_point,const double white_point,const double gamma)
+{
+ MagickBooleanType
+ status;
+
+ status=LevelizeImageChannel(image,DefaultChannels,black_point,white_point,
+ gamma);
+ return(status);
+}
+
MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
const ChannelType channel,const double black_point,const double white_point,
const double gamma)
{
#define LevelizeImageTag "Levelize/Image"
-#define LevelizeValue(x) (RoundToQuantum(((MagickRealType) \
+#define LevelizeValue(x) (ClampToQuantum(((MagickRealType) \
pow((double)(QuantumScale*(x)),1.0/gamma))*(white_point-black_point)+ \
black_point))
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
- register long
+ MagickOffsetType
+ progress;
+
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
Allocate and initialize levels map.
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
/*
Level colormap.
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- q->red=LevelizeValue(q->red);
+ SetRedPixelComponent(q,LevelizeValue(GetRedPixelComponent(q)));
if ((channel & GreenChannel) != 0)
- q->green=LevelizeValue(q->green);
+ SetGreenPixelComponent(q,LevelizeValue(GetGreenPixelComponent(q)));
if ((channel & BlueChannel) != 0)
- q->blue=LevelizeValue(q->blue);
+ SetBluePixelComponent(q,LevelizeValue(GetBluePixelComponent(q)));
if (((channel & OpacityChannel) != 0) &&
(image->matte == MagickTrue))
- q->opacity=LevelizeValue(q->opacity);
+ SetOpacityPixelComponent(q,LevelizeValue(GetOpacityPixelComponent(q)));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=LevelizeValue(indexes[x]);
+ SetIndexPixelComponent(indexes+x,LevelizeValue(
+ GetIndexPixelComponent(indexes+x)));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_LevelizeImageChannel)
#endif
proceed=SetImageProgress(image,LevelizeImageTag,progress++,image->rows);
status=MagickFalse;
}
}
+ image_view=DestroyCacheView(image_view);
return(status);
}
\f
% LevelImageColor() maps the given color to "black" and "white" values,
% linearly spreading out the colors, and level values on a channel by channel
% bases, as per LevelImage(). The given colors allows you to specify
-% different level ranges for each of the color channels seperatally.
+% different level ranges for each of the color channels separately.
%
% If the boolean 'invert' is set true the image values will modifyed in the
% reverse direction. That is any existing "black" and "white" colors in the
ExceptionInfo
*exception;
- long
- black,
- white,
- y;
-
MagickBooleanType
status;
*histogram,
intensity;
- MagickSizeType
- number_pixels;
+ ssize_t
+ black,
+ white,
+ y;
/*
Allocate histogram and linear map.
*/
(void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram));
exception=(&image->exception);
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register const PixelPacket
- *__restrict p;
+ *restrict p;
- register long
+ register ssize_t
x;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
- for (x=(long) image->columns-1; x >= 0; x--)
+ for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
histogram[ScaleQuantumToMap(PixelIntensityToQuantum(p))]++;
p++;
/*
Find the histogram boundaries by locating the black and white point levels.
*/
- number_pixels=(MagickSizeType) image->columns*image->rows;
intensity=0.0;
- for (black=0; black < (long) MaxMap; black++)
+ for (black=0; black < (ssize_t) MaxMap; black++)
{
intensity+=histogram[black];
if (intensity >= black_point)
break;
}
intensity=0.0;
- for (white=(long) MaxMap; white != 0; white--)
+ for (white=(ssize_t) MaxMap; white != 0; white--)
{
intensity+=histogram[white];
if (intensity >= white_point)
{
#define ModulateImageTag "Modulate/Image"
+ CacheView
+ *image_view;
+
ColorspaceType
colorspace;
GeometryInfo
geometry_info;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickStatusType
flags;
- register long
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
- Initialize gamma table.
+ Initialize modulate table.
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
colorspace=UndefinedColorspace;
artifact=GetImageArtifact(image,"modulate:colorspace");
if (artifact != (const char *) NULL)
- colorspace=(ColorspaceType) ParseMagickOption(MagickColorspaceOptions,
+ colorspace=(ColorspaceType) ParseCommandOption(MagickColorspaceOptions,
MagickFalse,artifact);
if (image->storage_class == PseudoClass)
{
/*
Modulate colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
switch (colorspace)
{
case HSBColorspace:
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- register long
- x;
+ Quantum
+ blue,
+ green,
+ red;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
status=MagickFalse;
continue;
}
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
+ red=GetRedPixelComponent(q);
+ green=GetGreenPixelComponent(q);
+ blue=GetBluePixelComponent(q);
switch (colorspace)
{
case HSBColorspace:
{
ModulateHSB(percent_hue,percent_saturation,percent_brightness,
- &q->red,&q->green,&q->blue);
+ &red,&green,&blue);
break;
}
case HSLColorspace:
default:
{
ModulateHSL(percent_hue,percent_saturation,percent_brightness,
- &q->red,&q->green,&q->blue);
+ &red,&green,&blue);
break;
}
case HWBColorspace:
{
ModulateHWB(percent_hue,percent_saturation,percent_brightness,
- &q->red,&q->green,&q->blue);
+ &red,&green,&blue);
break;
}
}
+ SetRedPixelComponent(q,red);
+ SetGreenPixelComponent(q,green);
+ SetBluePixelComponent(q,blue);
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_ModulateImage)
#endif
proceed=SetImageProgress(image,ModulateImageTag,progress++,image->rows);
{
#define NegateImageTag "Negate/Image"
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
- register long
+ MagickOffsetType
+ progress;
+
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
/*
Negate colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
if (grayscale != MagickFalse)
if ((image->colormap[i].red != image->colormap[i].green) ||
image_view=AcquireCacheView(image);
if (grayscale != MagickFalse)
{
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
MagickBooleanType
sync;
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- if ((q->red != q->green) || (q->green != q->blue))
+ if ((GetRedPixelComponent(q) != GetGreenPixelComponent(q)) ||
+ (GetGreenPixelComponent(q) != GetBluePixelComponent(q)))
{
q++;
continue;
}
if ((channel & RedChannel) != 0)
- q->red=(Quantum) QuantumRange-q->red;
+ SetRedPixelComponent(q,QuantumRange-GetRedPixelComponent(q));
if ((channel & GreenChannel) != 0)
- q->green=(Quantum) QuantumRange-q->green;
+ SetGreenPixelComponent(q,QuantumRange-GetGreenPixelComponent(q));
if ((channel & BlueChannel) != 0)
- q->blue=(Quantum) QuantumRange-q->blue;
+ SetBluePixelComponent(q,QuantumRange-GetBluePixelComponent(q));
if ((channel & OpacityChannel) != 0)
- q->opacity=(Quantum) QuantumRange-q->opacity;
+ SetOpacityPixelComponent(q,QuantumRange-
+ GetOpacityPixelComponent(q));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=(IndexPacket) QuantumRange-indexes[x];
+ SetIndexPixelComponent(indexes+x,QuantumRange-
+ GetIndexPixelComponent(indexes+x));
q++;
}
sync=SyncCacheViewAuthenticPixels(image_view,exception);
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_NegateImageChannel)
#endif
proceed=SetImageProgress(image,NegateImageTag,progress++,
/*
Negate image.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- q->red=(Quantum) QuantumRange-q->red;
+ SetRedPixelComponent(q,QuantumRange-GetRedPixelComponent(q));
if ((channel & GreenChannel) != 0)
- q->green=(Quantum) QuantumRange-q->green;
+ SetGreenPixelComponent(q,QuantumRange-GetGreenPixelComponent(q));
if ((channel & BlueChannel) != 0)
- q->blue=(Quantum) QuantumRange-q->blue;
+ SetBluePixelComponent(q,QuantumRange-GetBluePixelComponent(q));
if ((channel & OpacityChannel) != 0)
- q->opacity=(Quantum) QuantumRange-q->opacity;
+ SetOpacityPixelComponent(q,QuantumRange-GetOpacityPixelComponent(q));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=(IndexPacket) QuantumRange-indexes[x];
+ SetIndexPixelComponent(indexes+x,QuantumRange-
+ GetIndexPixelComponent(indexes+x));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_NegateImageChannel)
#endif
proceed=SetImageProgress(image,NegateImageTag,progress++,image->rows);
black_point,
white_point;
- black_point=(double) image->columns*image->rows*0.02;
- white_point=(double) image->columns*image->rows*0.99;
+ black_point=(double) image->columns*image->rows*0.0015;
+ white_point=(double) image->columns*image->rows*0.9995;
return(ContrastStretchImageChannel(image,channel,black_point,white_point));
}
\f
%
% o sharpen: Increase or decrease image contrast.
%
-% o contrast: control the "shoulder" of the contast curve.
+% o alpha: strength of the contrast, the larger the number the more
+% 'threshold-like' it becomes.
%
-% o midpoint: control the "toe" of the contast curve.
+% o beta: midpoint of the function as a color value 0 to QuantumRange.
%
*/
{
#define SigmoidalContrastImageTag "SigmoidalContrast/Image"
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
- long
- progress,
- y;
-
MagickBooleanType
status;
+ MagickOffsetType
+ progress;
+
MagickRealType
*sigmoidal_map;
- register long
+ register ssize_t
i;
- CacheView
- *image_view;
+ ssize_t
+ y;
/*
Allocate and initialize sigmoidal maps.
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
(void) ResetMagickMemory(sigmoidal_map,0,(MaxMap+1)*sizeof(*sigmoidal_map));
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i <= (long) MaxMap; i++)
+ for (i=0; i <= (ssize_t) MaxMap; i++)
{
if (sharpen != MagickFalse)
{
/*
Sigmoidal-contrast enhance colormap.
*/
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
if ((channel & RedChannel) != 0)
- image->colormap[i].red=RoundToQuantum(sigmoidal_map[
+ image->colormap[i].red=ClampToQuantum(sigmoidal_map[
ScaleQuantumToMap(image->colormap[i].red)]);
if ((channel & GreenChannel) != 0)
- image->colormap[i].green=RoundToQuantum(sigmoidal_map[
+ image->colormap[i].green=ClampToQuantum(sigmoidal_map[
ScaleQuantumToMap(image->colormap[i].green)]);
if ((channel & BlueChannel) != 0)
- image->colormap[i].blue=RoundToQuantum(sigmoidal_map[
+ image->colormap[i].blue=ClampToQuantum(sigmoidal_map[
ScaleQuantumToMap(image->colormap[i].blue)]);
if ((channel & OpacityChannel) != 0)
- image->colormap[i].opacity=RoundToQuantum(sigmoidal_map[
+ image->colormap[i].opacity=ClampToQuantum(sigmoidal_map[
ScaleQuantumToMap(image->colormap[i].opacity)]);
}
}
progress=0;
exception=(&image->exception);
image_view=AcquireCacheView(image);
-#if defined(_OPENMP) && (_OPENMP >= 200203)
- #pragma omp parallel for shared(progress,status)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
register IndexPacket
- *__restrict indexes;
-
- register long
- x;
+ *restrict indexes;
register PixelPacket
- *__restrict q;
+ *restrict q;
+
+ register ssize_t
+ x;
if (status == MagickFalse)
continue;
continue;
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- q->red=RoundToQuantum(sigmoidal_map[ScaleQuantumToMap(q->red)]);
+ SetRedPixelComponent(q,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
+ GetRedPixelComponent(q))]));
if ((channel & GreenChannel) != 0)
- q->green=RoundToQuantum(sigmoidal_map[ScaleQuantumToMap(q->green)]);
+ SetGreenPixelComponent(q,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
+ GetGreenPixelComponent(q))]));
if ((channel & BlueChannel) != 0)
- q->blue=RoundToQuantum(sigmoidal_map[ScaleQuantumToMap(q->blue)]);
+ SetBluePixelComponent(q,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
+ GetBluePixelComponent(q))]));
if ((channel & OpacityChannel) != 0)
- q->opacity=RoundToQuantum(sigmoidal_map[ScaleQuantumToMap(q->opacity)]);
+ SetOpacityPixelComponent(q,ClampToQuantum(sigmoidal_map[
+ ScaleQuantumToMap(GetOpacityPixelComponent(q))]));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=(IndexPacket) RoundToQuantum(sigmoidal_map[
- ScaleQuantumToMap(indexes[x])]);
+ SetIndexPixelComponent(indexes+x,ClampToQuantum(sigmoidal_map[
+ ScaleQuantumToMap(GetIndexPixelComponent(indexes+x))]));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
MagickBooleanType
proceed;
-#if defined(_OPENMP) && (_OPENMP >= 200203)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp critical (MagickCore_SigmoidalContrastImageChannel)
#endif
proceed=SetImageProgress(image,SigmoidalContrastImageTag,progress++,