2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % EEEEE N N H H AAA N N CCCC EEEEE %
7 % E NN N H H A A NN N C E %
8 % EEE N N N HHHHH AAAAA N N N C EEE %
9 % E N NN H H A A N NN C E %
10 % EEEEE N N H H A A N N CCCC EEEEE %
13 % MagickCore Image Enhancement Methods %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/cache-view.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colorspace.h"
50 #include "MagickCore/composite-private.h"
51 #include "MagickCore/enhance.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/fx.h"
55 #include "MagickCore/gem.h"
56 #include "MagickCore/gem-private.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/histogram.h"
59 #include "MagickCore/image.h"
60 #include "MagickCore/image-private.h"
61 #include "MagickCore/memory_.h"
62 #include "MagickCore/monitor.h"
63 #include "MagickCore/monitor-private.h"
64 #include "MagickCore/option.h"
65 #include "MagickCore/pixel-accessor.h"
66 #include "MagickCore/quantum.h"
67 #include "MagickCore/quantum-private.h"
68 #include "MagickCore/resample.h"
69 #include "MagickCore/resample-private.h"
70 #include "MagickCore/statistic.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/string-private.h"
73 #include "MagickCore/thread-private.h"
74 #include "MagickCore/token.h"
75 #include "MagickCore/xml-tree.h"
76 #include "MagickCore/xml-tree-private.h"
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 % A u t o G a m m a I m a g e %
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 % AutoGammaImage() extract the 'mean' from the image and adjust the image
90 % to try make set its gamma appropriatally.
92 % The format of the AutoGammaImage method is:
94 % MagickBooleanType AutoGammaImage(Image *image,ExceptionInfo *exception)
96 % A description of each parameter follows:
98 % o image: The image to auto-level
100 % o exception: return any errors or warnings in this structure.
103 MagickExport MagickBooleanType AutoGammaImage(Image *image,
104 ExceptionInfo *exception)
119 if (image->channel_mask == DefaultChannels)
122 Apply gamma correction equally across all given channels.
124 (void) GetImageMean(image,&mean,&sans,exception);
125 gamma=log(mean*QuantumScale)/log_mean;
126 return(LevelImage(image,0.0,(double) QuantumRange,gamma,exception));
129 Auto-gamma each channel separately.
132 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
143 channel=GetPixelChannelMapChannel(image,i);
144 traits=GetPixelChannelMapTraits(image,channel);
145 if ((traits & UpdatePixelTrait) == 0)
147 channel_mask=SetPixelChannelMask(image,(ChannelType) (1 << i));
148 status=GetImageMean(image,&mean,&sans,exception);
149 gamma=log(mean*QuantumScale)/log_mean;
150 status&=LevelImage(image,0.0,(double) QuantumRange,gamma,exception);
151 (void) SetPixelChannelMask(image,channel_mask);
152 if (status == MagickFalse)
155 return(status != 0 ? MagickTrue : MagickFalse);
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 % A u t o L e v e l I m a g e %
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 % AutoLevelImage() adjusts the levels of a particular image channel by
170 % scaling the minimum and maximum values to the full quantum range.
172 % The format of the LevelImage method is:
174 % MagickBooleanType AutoLevelImage(Image *image,ExceptionInfo *exception)
176 % A description of each parameter follows:
178 % o image: The image to auto-level
180 % o exception: return any errors or warnings in this structure.
183 MagickExport MagickBooleanType AutoLevelImage(Image *image,
184 ExceptionInfo *exception)
186 return(MinMaxStretchImage(image,0.0,0.0,1.0,exception));
190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 % B r i g h t n e s s C o n t r a s t I m a g e %
198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 % BrightnessContrastImage() changes the brightness and/or contrast of an
201 % image. It converts the brightness and contrast parameters into slope and
202 % intercept and calls a polynomical function to apply to the image.
204 % The format of the BrightnessContrastImage method is:
206 % MagickBooleanType BrightnessContrastImage(Image *image,
207 % const double brightness,const double contrast,ExceptionInfo *exception)
209 % A description of each parameter follows:
211 % o image: the image.
213 % o brightness: the brightness percent (-100 .. 100).
215 % o contrast: the contrast percent (-100 .. 100).
217 % o exception: return any errors or warnings in this structure.
220 MagickExport MagickBooleanType BrightnessContrastImage(Image *image,
221 const double brightness,const double contrast,ExceptionInfo *exception)
223 #define BrightnessContastImageTag "BrightnessContast/Image"
235 Compute slope and intercept.
237 assert(image != (Image *) NULL);
238 assert(image->signature == MagickSignature);
239 if (image->debug != MagickFalse)
240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
242 slope=tan((double) (MagickPI*(alpha/100.0+1.0)/4.0));
245 intercept=brightness/100.0+((100-brightness)/200.0)*(1.0-slope);
246 coefficients[0]=slope;
247 coefficients[1]=intercept;
248 status=FunctionImage(image,PolynomialFunction,2,coefficients,exception);
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % C l u t I m a g e %
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 % ClutImage() replaces each color value in the given image, by using it as an
264 % index to lookup a replacement color value in a Color Look UP Table in the
265 % form of an image. The values are extracted along a diagonal of the CLUT
266 % image so either a horizontal or vertial gradient image can be used.
268 % Typically this is used to either re-color a gray-scale image according to a
269 % color gradient in the CLUT image, or to perform a freeform histogram
270 % (level) adjustment according to the (typically gray-scale) gradient in the
273 % When the 'channel' mask includes the matte/alpha transparency channel but
274 % one image has no such channel it is assumed that that image is a simple
275 % gray-scale image that will effect the alpha channel values, either for
276 % gray-scale coloring (with transparent or semi-transparent colors), or
277 % a histogram adjustment of existing alpha channel values. If both images
278 % have matte channels, direct and normal indexing is applied, which is rarely
281 % The format of the ClutImage method is:
283 % MagickBooleanType ClutImage(Image *image,Image *clut_image,
284 % const PixelInterpolateMethod method,ExceptionInfo *exception)
286 % A description of each parameter follows:
288 % o image: the image, which is replaced by indexed CLUT values
290 % o clut_image: the color lookup table image for replacement color values.
292 % o method: the pixel interpolation method.
294 % o exception: return any errors or warnings in this structure.
297 MagickExport MagickBooleanType ClutImage(Image *image,const Image *clut_image,
298 const PixelInterpolateMethod method,ExceptionInfo *exception)
300 #define ClutImageTag "Clut/Image"
322 assert(image != (Image *) NULL);
323 assert(image->signature == MagickSignature);
324 if (image->debug != MagickFalse)
325 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
326 assert(clut_image != (Image *) NULL);
327 assert(clut_image->signature == MagickSignature);
328 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
330 clut_map=(double *) AcquireQuantumMemory(MaxMap+1UL,GetPixelChannels(image)*
332 if (clut_map == (double *) NULL)
333 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
340 adjust=(ssize_t) (clut_image->interpolate == IntegerInterpolatePixel ? 0 : 1);
341 clut_view=AcquireCacheView(clut_image);
342 #if defined(MAGICKCORE_OPENMP_SUPPORT)
343 #pragma omp parallel for schedule(static,4)
345 for (x=0; x <= (ssize_t) MaxMap; x++)
350 for (i=0; i < (ssize_t) GetPixelChannels(clut_image); i++)
351 (void) InterpolatePixelChannel(clut_image,clut_view,(PixelChannel) i,
352 method,QuantumScale*x*(clut_image->columns-adjust),QuantumScale*x*
353 (clut_image->rows-adjust),clut_map+x*GetPixelChannels(clut_image)+i,
356 clut_view=DestroyCacheView(clut_view);
357 image_view=AcquireCacheView(image);
358 #if defined(MAGICKCORE_OPENMP_SUPPORT)
359 #pragma omp parallel for schedule(static,4) shared(progress,status)
361 for (y=0; y < (ssize_t) image->rows; y++)
369 if (status == MagickFalse)
371 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
372 if (q == (Quantum *) NULL)
377 for (x=0; x < (ssize_t) image->columns; x++)
382 if (GetPixelMask(image,q) != 0)
384 q+=GetPixelChannels(image);
387 for (i=0; i < (ssize_t) GetPixelChannels(clut_image); i++)
396 channel=GetPixelChannelMapChannel(clut_image,i);
397 clut_traits=GetPixelChannelMapTraits(clut_image,channel);
398 traits=GetPixelChannelMapTraits(clut_image,channel);
399 if ((traits == UndefinedPixelTrait) ||
400 (clut_traits == UndefinedPixelTrait) ||
401 ((traits & UpdatePixelTrait) == 0))
403 SetPixelChannel(clut_image,channel,ClampToQuantum(clut_map[
404 ScaleQuantumToMap(GetPixelChannel(clut_image,channel,q))*
405 GetPixelChannels(clut_image)+channel]),q);
407 q+=GetPixelChannels(image);
409 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
411 if (image->progress_monitor != (MagickProgressMonitor) NULL)
416 #if defined(MAGICKCORE_OPENMP_SUPPORT)
417 #pragma omp critical (MagickCore_ClutImage)
419 proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows);
420 if (proceed == MagickFalse)
424 image_view=DestroyCacheView(image_view);
425 clut_map=(double *) RelinquishMagickMemory(clut_map);
426 if ((clut_image->matte != MagickFalse) &&
427 ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0))
428 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 % C o l o r D e c i s i o n L i s t I m a g e %
441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 % ColorDecisionListImage() accepts a lightweight Color Correction Collection
444 % (CCC) file which solely contains one or more color corrections and applies
445 % the correction to the image. Here is a sample CCC file:
447 % <ColorCorrectionCollection xmlns="urn:ASC:CDL:v1.2">
448 % <ColorCorrection id="cc03345">
450 % <Slope> 0.9 1.2 0.5 </Slope>
451 % <Offset> 0.4 -0.5 0.6 </Offset>
452 % <Power> 1.0 0.8 1.5 </Power>
455 % <Saturation> 0.85 </Saturation>
458 % </ColorCorrectionCollection>
460 % which includes the slop, offset, and power for each of the RGB channels
461 % as well as the saturation.
463 % The format of the ColorDecisionListImage method is:
465 % MagickBooleanType ColorDecisionListImage(Image *image,
466 % const char *color_correction_collection,ExceptionInfo *exception)
468 % A description of each parameter follows:
470 % o image: the image.
472 % o color_correction_collection: the color correction collection in XML.
474 % o exception: return any errors or warnings in this structure.
477 MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
478 const char *color_correction_collection,ExceptionInfo *exception)
480 #define ColorDecisionListCorrectImageTag "ColorDecisionList/Image"
482 typedef struct _Correction
490 typedef struct _ColorCorrection
505 token[MaxTextExtent];
536 Allocate and initialize cdl maps.
538 assert(image != (Image *) NULL);
539 assert(image->signature == MagickSignature);
540 if (image->debug != MagickFalse)
541 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
542 if (color_correction_collection == (const char *) NULL)
544 ccc=NewXMLTree((const char *) color_correction_collection,exception);
545 if (ccc == (XMLTreeInfo *) NULL)
547 cc=GetXMLTreeChild(ccc,"ColorCorrection");
548 if (cc == (XMLTreeInfo *) NULL)
550 ccc=DestroyXMLTree(ccc);
553 color_correction.red.slope=1.0;
554 color_correction.red.offset=0.0;
555 color_correction.red.power=1.0;
556 color_correction.green.slope=1.0;
557 color_correction.green.offset=0.0;
558 color_correction.green.power=1.0;
559 color_correction.blue.slope=1.0;
560 color_correction.blue.offset=0.0;
561 color_correction.blue.power=1.0;
562 color_correction.saturation=0.0;
563 sop=GetXMLTreeChild(cc,"SOPNode");
564 if (sop != (XMLTreeInfo *) NULL)
571 slope=GetXMLTreeChild(sop,"Slope");
572 if (slope != (XMLTreeInfo *) NULL)
574 content=GetXMLTreeContent(slope);
575 p=(const char *) content;
576 for (i=0; (*p != '\0') && (i < 3); i++)
578 GetMagickToken(p,&p,token);
580 GetMagickToken(p,&p,token);
585 color_correction.red.slope=StringToDouble(token,(char **) NULL);
590 color_correction.green.slope=StringToDouble(token,
596 color_correction.blue.slope=StringToDouble(token,
603 offset=GetXMLTreeChild(sop,"Offset");
604 if (offset != (XMLTreeInfo *) NULL)
606 content=GetXMLTreeContent(offset);
607 p=(const char *) content;
608 for (i=0; (*p != '\0') && (i < 3); i++)
610 GetMagickToken(p,&p,token);
612 GetMagickToken(p,&p,token);
617 color_correction.red.offset=StringToDouble(token,
623 color_correction.green.offset=StringToDouble(token,
629 color_correction.blue.offset=StringToDouble(token,
636 power=GetXMLTreeChild(sop,"Power");
637 if (power != (XMLTreeInfo *) NULL)
639 content=GetXMLTreeContent(power);
640 p=(const char *) content;
641 for (i=0; (*p != '\0') && (i < 3); i++)
643 GetMagickToken(p,&p,token);
645 GetMagickToken(p,&p,token);
650 color_correction.red.power=StringToDouble(token,(char **) NULL);
655 color_correction.green.power=StringToDouble(token,
661 color_correction.blue.power=StringToDouble(token,
669 sat=GetXMLTreeChild(cc,"SATNode");
670 if (sat != (XMLTreeInfo *) NULL)
675 saturation=GetXMLTreeChild(sat,"Saturation");
676 if (saturation != (XMLTreeInfo *) NULL)
678 content=GetXMLTreeContent(saturation);
679 p=(const char *) content;
680 GetMagickToken(p,&p,token);
681 color_correction.saturation=StringToDouble(token,(char **) NULL);
684 ccc=DestroyXMLTree(ccc);
685 if (image->debug != MagickFalse)
687 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
688 " Color Correction Collection:");
689 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
690 " color_correction.red.slope: %g",color_correction.red.slope);
691 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
692 " color_correction.red.offset: %g",color_correction.red.offset);
693 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
694 " color_correction.red.power: %g",color_correction.red.power);
695 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
696 " color_correction.green.slope: %g",color_correction.green.slope);
697 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
698 " color_correction.green.offset: %g",color_correction.green.offset);
699 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
700 " color_correction.green.power: %g",color_correction.green.power);
701 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
702 " color_correction.blue.slope: %g",color_correction.blue.slope);
703 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
704 " color_correction.blue.offset: %g",color_correction.blue.offset);
705 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
706 " color_correction.blue.power: %g",color_correction.blue.power);
707 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
708 " color_correction.saturation: %g",color_correction.saturation);
710 cdl_map=(PixelInfo *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*cdl_map));
711 if (cdl_map == (PixelInfo *) NULL)
712 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
714 #if defined(MAGICKCORE_OPENMP_SUPPORT)
715 #pragma omp parallel for schedule(static,4)
717 for (i=0; i <= (ssize_t) MaxMap; i++)
719 cdl_map[i].red=(MagickRealType) ScaleMapToQuantum((MagickRealType)
720 (MaxMap*(pow(color_correction.red.slope*i/MaxMap+
721 color_correction.red.offset,color_correction.red.power))));
722 cdl_map[i].green=(MagickRealType) ScaleMapToQuantum((MagickRealType)
723 (MaxMap*(pow(color_correction.green.slope*i/MaxMap+
724 color_correction.green.offset,color_correction.green.power))));
725 cdl_map[i].blue=(MagickRealType) ScaleMapToQuantum((MagickRealType)
726 (MaxMap*(pow(color_correction.blue.slope*i/MaxMap+
727 color_correction.blue.offset,color_correction.blue.power))));
729 if (image->storage_class == PseudoClass)
732 Apply transfer function to colormap.
734 #if defined(MAGICKCORE_OPENMP_SUPPORT)
735 #pragma omp parallel for schedule(static,4) shared(progress,status)
737 for (i=0; i < (ssize_t) image->colors; i++)
742 luma=0.2126*image->colormap[i].red+0.7152*image->colormap[i].green+
743 0.0722*image->colormap[i].blue;
744 image->colormap[i].red=luma+color_correction.saturation*cdl_map[
745 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))].red-
747 image->colormap[i].green=luma+color_correction.saturation*cdl_map[
748 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].green))].green-
750 image->colormap[i].blue=luma+color_correction.saturation*cdl_map[
751 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].blue))].blue-
756 Apply transfer function to image.
760 image_view=AcquireCacheView(image);
761 #if defined(MAGICKCORE_OPENMP_SUPPORT)
762 #pragma omp parallel for schedule(static,4) shared(progress,status)
764 for (y=0; y < (ssize_t) image->rows; y++)
775 if (status == MagickFalse)
777 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
778 if (q == (Quantum *) NULL)
783 for (x=0; x < (ssize_t) image->columns; x++)
785 luma=0.2126*GetPixelRed(image,q)+0.7152*GetPixelGreen(image,q)+0.0722*
786 GetPixelBlue(image,q);
787 SetPixelRed(image,ClampToQuantum(luma+color_correction.saturation*
788 (cdl_map[ScaleQuantumToMap(GetPixelRed(image,q))].red-luma)),q);
789 SetPixelGreen(image,ClampToQuantum(luma+color_correction.saturation*
790 (cdl_map[ScaleQuantumToMap(GetPixelGreen(image,q))].green-luma)),q);
791 SetPixelBlue(image,ClampToQuantum(luma+color_correction.saturation*
792 (cdl_map[ScaleQuantumToMap(GetPixelBlue(image,q))].blue-luma)),q);
793 q+=GetPixelChannels(image);
795 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
797 if (image->progress_monitor != (MagickProgressMonitor) NULL)
802 #if defined(MAGICKCORE_OPENMP_SUPPORT)
803 #pragma omp critical (MagickCore_ColorDecisionListImageChannel)
805 proceed=SetImageProgress(image,ColorDecisionListCorrectImageTag,
806 progress++,image->rows);
807 if (proceed == MagickFalse)
811 image_view=DestroyCacheView(image_view);
812 cdl_map=(PixelInfo *) RelinquishMagickMemory(cdl_map);
817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 % C o n t r a s t I m a g e %
825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
827 % ContrastImage() enhances the intensity differences between the lighter and
828 % darker elements of the image. Set sharpen to a MagickTrue to increase the
829 % image contrast otherwise the contrast is reduced.
831 % The format of the ContrastImage method is:
833 % MagickBooleanType ContrastImage(Image *image,
834 % const MagickBooleanType sharpen,ExceptionInfo *exception)
836 % A description of each parameter follows:
838 % o image: the image.
840 % o sharpen: Increase or decrease image contrast.
842 % o exception: return any errors or warnings in this structure.
846 static void Contrast(const int sign,double *red,double *green,double *blue)
854 Enhance contrast: dark color become darker, light color become lighter.
856 assert(red != (double *) NULL);
857 assert(green != (double *) NULL);
858 assert(blue != (double *) NULL);
862 ConvertRGBToHSB(*red,*green,*blue,&hue,&saturation,&brightness);
863 brightness+=0.5*sign*(0.5*(sin((double) (MagickPI*(brightness-0.5)))+1.0)-
865 if (brightness > 1.0)
868 if (brightness < 0.0)
870 ConvertHSBToRGB(hue,saturation,brightness,red,green,blue);
873 MagickExport MagickBooleanType ContrastImage(Image *image,
874 const MagickBooleanType sharpen,ExceptionInfo *exception)
876 #define ContrastImageTag "Contrast/Image"
896 assert(image != (Image *) NULL);
897 assert(image->signature == MagickSignature);
898 if (image->debug != MagickFalse)
899 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
900 sign=sharpen != MagickFalse ? 1 : -1;
901 if (image->storage_class == PseudoClass)
904 Contrast enhance colormap.
906 for (i=0; i < (ssize_t) image->colors; i++)
907 Contrast(sign,&image->colormap[i].red,&image->colormap[i].green,
908 &image->colormap[i].blue);
911 Contrast enhance image.
915 image_view=AcquireCacheView(image);
916 #if defined(MAGICKCORE_OPENMP_SUPPORT)
917 #pragma omp parallel for schedule(static,4) shared(progress,status)
919 for (y=0; y < (ssize_t) image->rows; y++)
932 if (status == MagickFalse)
934 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
935 if (q == (Quantum *) NULL)
940 for (x=0; x < (ssize_t) image->columns; x++)
942 red=(double) GetPixelRed(image,q);
943 green=(double) GetPixelGreen(image,q);
944 blue=(double) GetPixelBlue(image,q);
945 Contrast(sign,&red,&green,&blue);
946 SetPixelRed(image,ClampToQuantum(red),q);
947 SetPixelGreen(image,ClampToQuantum(green),q);
948 SetPixelBlue(image,ClampToQuantum(blue),q);
949 q+=GetPixelChannels(image);
951 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
953 if (image->progress_monitor != (MagickProgressMonitor) NULL)
958 #if defined(MAGICKCORE_OPENMP_SUPPORT)
959 #pragma omp critical (MagickCore_ContrastImage)
961 proceed=SetImageProgress(image,ContrastImageTag,progress++,image->rows);
962 if (proceed == MagickFalse)
966 image_view=DestroyCacheView(image_view);
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975 % C o n t r a s t S t r e t c h I m a g e %
979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 % ContrastStretchImage() is a simple image enhancement technique that attempts
982 % to improve the contrast in an image by `stretching' the range of intensity
983 % values it contains to span a desired range of values. It differs from the
984 % more sophisticated histogram equalization in that it can only apply a
985 % linear scaling function to the image pixel values. As a result the
986 % `enhancement' is less harsh.
988 % The format of the ContrastStretchImage method is:
990 % MagickBooleanType ContrastStretchImage(Image *image,
991 % const char *levels,ExceptionInfo *exception)
993 % A description of each parameter follows:
995 % o image: the image.
997 % o black_point: the black point.
999 % o white_point: the white point.
1001 % o levels: Specify the levels where the black and white points have the
1002 % range of 0 to number-of-pixels (e.g. 1%, 10x90%, etc.).
1004 % o exception: return any errors or warnings in this structure.
1007 MagickExport MagickBooleanType ContrastStretchImage(Image *image,
1008 const double black_point,const double white_point,ExceptionInfo *exception)
1010 #define MaxRange(color) ((MagickRealType) ScaleQuantumToMap((Quantum) (color)))
1011 #define ContrastStretchImageTag "ContrastStretch/Image"
1038 Allocate histogram and stretch map.
1040 assert(image != (Image *) NULL);
1041 assert(image->signature == MagickSignature);
1042 if (image->debug != MagickFalse)
1043 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1044 black=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*black));
1045 white=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*white));
1046 histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,GetPixelChannels(image)*
1047 sizeof(*histogram));
1048 stretch_map=(double *) AcquireQuantumMemory(MaxMap+1UL,
1049 GetPixelChannels(image)*sizeof(*stretch_map));
1050 if ((black == (double *) NULL) || (white == (double *) NULL) ||
1051 (histogram == (double *) NULL) || (stretch_map == (double *) NULL))
1053 if (stretch_map != (double *) NULL)
1054 stretch_map=(double *) RelinquishMagickMemory(stretch_map);
1055 if (histogram != (double *) NULL)
1056 histogram=(double *) RelinquishMagickMemory(histogram);
1057 if (white != (double *) NULL)
1058 white=(double *) RelinquishMagickMemory(white);
1059 if (black != (double *) NULL)
1060 black=(double *) RelinquishMagickMemory(black);
1061 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1068 (void) ResetMagickMemory(histogram,0,(MaxMap+1)*GetPixelChannels(image)*
1069 sizeof(*histogram));
1070 image_view=AcquireCacheView(image);
1071 for (y=0; y < (ssize_t) image->rows; y++)
1073 register const Quantum
1079 if (status == MagickFalse)
1081 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1082 if (p == (const Quantum *) NULL)
1087 for (x=0; x < (ssize_t) image->columns; x++)
1092 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1093 histogram[GetPixelChannels(image)*ScaleQuantumToMap(p[i])+i]++;
1094 p+=GetPixelChannels(image);
1098 Find the histogram boundaries by locating the black/white levels.
1100 number_channels=GetPixelChannels(image);
1101 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1102 #pragma omp parallel for schedule(static,4) shared(progress,status)
1104 for (i=0; i < (ssize_t) number_channels; i++)
1113 white[i]=MaxRange(QuantumRange);
1115 for (j=0; j <= (ssize_t) MaxMap; j++)
1117 intensity+=histogram[GetPixelChannels(image)*j+i];
1118 if (intensity > black_point)
1121 black[i]=(MagickRealType) j;
1123 for (j=(ssize_t) MaxMap; j != 0; j--)
1125 intensity+=histogram[GetPixelChannels(image)*j+i];
1126 if (intensity > ((double) image->columns*image->rows-white_point))
1129 white[i]=(MagickRealType) j;
1131 histogram=(double *) RelinquishMagickMemory(histogram);
1133 Stretch the histogram to create the stretched image mapping.
1135 (void) ResetMagickMemory(stretch_map,0,(MaxMap+1)*GetPixelChannels(image)*
1136 sizeof(*stretch_map));
1137 number_channels=GetPixelChannels(image);
1138 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1139 #pragma omp parallel for schedule(static,4) shared(progress,status)
1141 for (i=0; i < (ssize_t) number_channels; i++)
1146 for (j=0; j <= (ssize_t) MaxMap; j++)
1148 if (j < (ssize_t) black[i])
1149 stretch_map[GetPixelChannels(image)*j+i]=0.0;
1151 if (j > (ssize_t) white[i])
1152 stretch_map[GetPixelChannels(image)*j+i]=(MagickRealType)
1155 if (black[i] != white[i])
1156 stretch_map[GetPixelChannels(image)*j+i]=(MagickRealType)
1157 ScaleMapToQuantum((MagickRealType) (MaxMap*(j-black[i])/
1158 (white[i]-black[i])));
1161 if (image->storage_class == PseudoClass)
1167 Stretch-contrast colormap.
1169 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1170 #pragma omp parallel for schedule(static,4) shared(progress,status)
1172 for (j=0; j < (ssize_t) image->colors; j++)
1174 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1176 i=GetPixelChannelMapChannel(image,RedPixelChannel);
1177 if (black[i] != white[i])
1178 image->colormap[j].red=stretch_map[GetPixelChannels(image)*
1179 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))]+i;
1181 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1183 i=GetPixelChannelMapChannel(image,GreenPixelChannel);
1184 if (black[i] != white[i])
1185 image->colormap[j].green=stretch_map[GetPixelChannels(image)*
1186 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))]+i;
1188 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1190 i=GetPixelChannelMapChannel(image,BluePixelChannel);
1191 if (black[i] != white[i])
1192 image->colormap[j].blue=stretch_map[GetPixelChannels(image)*
1193 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))]+i;
1195 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1197 i=GetPixelChannelMapChannel(image,AlphaPixelChannel);
1198 if (black[i] != white[i])
1199 image->colormap[j].alpha=stretch_map[GetPixelChannels(image)*
1200 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))]+i;
1205 Stretch-contrast image.
1209 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1210 #pragma omp parallel for schedule(static,4) shared(progress,status)
1212 for (y=0; y < (ssize_t) image->rows; y++)
1220 if (status == MagickFalse)
1222 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1223 if (q == (Quantum *) NULL)
1228 for (x=0; x < (ssize_t) image->columns; x++)
1233 if (GetPixelMask(image,q) != 0)
1235 q+=GetPixelChannels(image);
1238 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1246 channel=GetPixelChannelMapChannel(image,i);
1247 traits=GetPixelChannelMapTraits(image,channel);
1248 if (((traits & UpdatePixelTrait) != 0) && (black[i] != white[i]))
1249 q[i]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
1250 ScaleQuantumToMap(q[i])+i]);
1252 q+=GetPixelChannels(image);
1254 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1256 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1261 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1262 #pragma omp critical (MagickCore_ContrastStretchImage)
1264 proceed=SetImageProgress(image,ContrastStretchImageTag,progress++,
1266 if (proceed == MagickFalse)
1270 image_view=DestroyCacheView(image_view);
1271 stretch_map=(double *) RelinquishMagickMemory(stretch_map);
1272 white=(double *) RelinquishMagickMemory(white);
1273 black=(double *) RelinquishMagickMemory(black);
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1282 % E n h a n c e I m a g e %
1286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1288 % EnhanceImage() applies a digital filter that improves the quality of a
1291 % The format of the EnhanceImage method is:
1293 % Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
1295 % A description of each parameter follows:
1297 % o image: the image.
1299 % o exception: return any errors or warnings in this structure.
1302 MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
1304 #define EnhancePixel(weight) \
1305 mean=((MagickRealType) r[i]+GetPixelChannel(enhance_image,channel,q))/2.0; \
1306 distance=(MagickRealType) r[i]-(MagickRealType) GetPixelChannel( \
1307 enhance_image,channel,q); \
1308 distance_squared=QuantumScale*(2.0*((MagickRealType) QuantumRange+1.0)+ \
1309 mean)*distance*distance; \
1310 if (distance_squared < ((MagickRealType) QuantumRange*(MagickRealType) \
1311 QuantumRange/25.0f)) \
1313 aggregate+=(weight)*r[i]; \
1314 total_weight+=(weight); \
1316 r+=GetPixelChannels(image);
1317 #define EnhanceImageTag "Enhance/Image"
1336 Initialize enhanced image attributes.
1338 assert(image != (const Image *) NULL);
1339 assert(image->signature == MagickSignature);
1340 if (image->debug != MagickFalse)
1341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1342 assert(exception != (ExceptionInfo *) NULL);
1343 assert(exception->signature == MagickSignature);
1344 enhance_image=CloneImage(image,image->columns,image->rows,MagickTrue,
1346 if (enhance_image == (Image *) NULL)
1347 return((Image *) NULL);
1348 if (SetImageStorageClass(enhance_image,DirectClass,exception) == MagickFalse)
1350 enhance_image=DestroyImage(enhance_image);
1351 return((Image *) NULL);
1358 image_view=AcquireCacheView(image);
1359 enhance_view=AcquireCacheView(enhance_image);
1360 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1361 #pragma omp parallel for schedule(static,4) shared(progress,status)
1363 for (y=0; y < (ssize_t) image->rows; y++)
1365 register const Quantum
1377 if (status == MagickFalse)
1379 p=GetCacheViewVirtualPixels(image_view,-2,y-2,image->columns+4,5,exception);
1380 q=QueueCacheViewAuthenticPixels(enhance_view,0,y,enhance_image->columns,1,
1382 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1387 center=(ssize_t) GetPixelChannels(image)*(2*(image->columns+4)+2);
1388 for (x=0; x < (ssize_t) image->columns; x++)
1393 if (GetPixelMask(image,p) != 0)
1395 p+=GetPixelChannels(image);
1396 q+=GetPixelChannels(enhance_image);
1399 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1415 register const Quantum
1418 channel=GetPixelChannelMapChannel(image,i);
1419 traits=GetPixelChannelMapTraits(image,channel);
1420 enhance_traits=GetPixelChannelMapTraits(enhance_image,channel);
1421 if ((traits == UndefinedPixelTrait) ||
1422 (enhance_traits == UndefinedPixelTrait))
1424 SetPixelChannel(enhance_image,channel,p[center+i],q);
1425 if ((enhance_traits & CopyPixelTrait) != 0)
1428 Compute weighted average of target pixel color components.
1433 EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
1434 EnhancePixel(8.0); EnhancePixel(5.0);
1435 r=p+1*GetPixelChannels(image)*(image->columns+4);
1436 EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
1437 EnhancePixel(20.0); EnhancePixel(8.0);
1438 r=p+2*GetPixelChannels(image)*(image->columns+4);
1439 EnhancePixel(10.0); EnhancePixel(40.0); EnhancePixel(80.0);
1440 EnhancePixel(40.0); EnhancePixel(10.0);
1441 r=p+3*GetPixelChannels(image)*(image->columns+4);
1442 EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
1443 EnhancePixel(20.0); EnhancePixel(8.0);
1444 r=p+4*GetPixelChannels(image)*(image->columns+4);
1445 EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
1446 EnhancePixel(8.0); EnhancePixel(5.0);
1447 SetPixelChannel(enhance_image,channel,ClampToQuantum(aggregate/
1450 p+=GetPixelChannels(image);
1451 q+=GetPixelChannels(enhance_image);
1453 if (SyncCacheViewAuthenticPixels(enhance_view,exception) == MagickFalse)
1455 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1460 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1461 #pragma omp critical (MagickCore_EnhanceImage)
1463 proceed=SetImageProgress(image,EnhanceImageTag,progress++,image->rows);
1464 if (proceed == MagickFalse)
1468 enhance_view=DestroyCacheView(enhance_view);
1469 image_view=DestroyCacheView(image_view);
1470 return(enhance_image);
1474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1478 % E q u a l i z e I m a g e %
1482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % EqualizeImage() applies a histogram equalization to the image.
1486 % The format of the EqualizeImage method is:
1488 % MagickBooleanType EqualizeImage(Image *image,ExceptionInfo *exception)
1490 % A description of each parameter follows:
1492 % o image: the image.
1494 % o exception: return any errors or warnings in this structure.
1497 MagickExport MagickBooleanType EqualizeImage(Image *image,
1498 ExceptionInfo *exception)
1500 #define EqualizeImageTag "Equalize/Image"
1512 black[CompositePixelChannel],
1516 white[CompositePixelChannel];
1528 Allocate and initialize histogram arrays.
1530 assert(image != (Image *) NULL);
1531 assert(image->signature == MagickSignature);
1532 if (image->debug != MagickFalse)
1533 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1534 equalize_map=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
1535 GetPixelChannels(image)*sizeof(*equalize_map));
1536 histogram=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
1537 GetPixelChannels(image)*sizeof(*histogram));
1538 map=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
1539 GetPixelChannels(image)*sizeof(*map));
1540 if ((equalize_map == (MagickRealType *) NULL) ||
1541 (histogram == (MagickRealType *) NULL) ||
1542 (map == (MagickRealType *) NULL))
1544 if (map != (MagickRealType *) NULL)
1545 map=(MagickRealType *) RelinquishMagickMemory(map);
1546 if (histogram != (MagickRealType *) NULL)
1547 histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
1548 if (equalize_map != (MagickRealType *) NULL)
1549 equalize_map=(MagickRealType *) RelinquishMagickMemory(equalize_map);
1550 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1557 (void) ResetMagickMemory(histogram,0,(MaxMap+1)*GetPixelChannels(image)*
1558 sizeof(*histogram));
1559 image_view=AcquireCacheView(image);
1560 for (y=0; y < (ssize_t) image->rows; y++)
1562 register const Quantum
1568 if (status == MagickFalse)
1570 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1571 if (p == (const Quantum *) NULL)
1576 for (x=0; x < (ssize_t) image->columns; x++)
1581 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1582 histogram[GetPixelChannels(image)*ScaleQuantumToMap(p[i])+i]++;
1583 p+=GetPixelChannels(image);
1587 Integrate the histogram to get the equalization map.
1589 number_channels=GetPixelChannels(image);
1590 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1591 #pragma omp parallel for schedule(static,4) shared(progress,status)
1593 for (i=0; i < (ssize_t) number_channels; i++)
1602 for (j=0; j <= (ssize_t) MaxMap; j++)
1604 intensity+=histogram[GetPixelChannels(image)*j+i];
1605 map[GetPixelChannels(image)*j+i]=intensity;
1608 (void) ResetMagickMemory(equalize_map,0,(MaxMap+1)*GetPixelChannels(image)*
1609 sizeof(*equalize_map));
1610 number_channels=GetPixelChannels(image);
1611 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1612 #pragma omp parallel for schedule(static,4) shared(progress,status)
1614 for (i=0; i < (ssize_t) number_channels; i++)
1620 white[i]=map[GetPixelChannels(image)*MaxMap+i];
1621 if (black[i] != white[i])
1622 for (j=0; j <= (ssize_t) MaxMap; j++)
1623 equalize_map[GetPixelChannels(image)*j+i]=(MagickRealType)
1624 ScaleMapToQuantum((MagickRealType) ((MaxMap*(map[
1625 GetPixelChannels(image)*j+i]-black[i]))/(white[i]-black[i])));
1627 histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
1628 map=(MagickRealType *) RelinquishMagickMemory(map);
1629 if (image->storage_class == PseudoClass)
1640 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1641 #pragma omp parallel for schedule(static,4) shared(progress,status)
1643 for (j=0; j < (ssize_t) image->colors; j++)
1645 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1647 channel=GetPixelChannelMapChannel(image,RedPixelChannel);
1648 if (black[channel] != white[channel])
1649 image->colormap[j].red=equalize_map[GetPixelChannels(image)*
1650 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))]+
1653 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1655 channel=GetPixelChannelMapChannel(image,GreenPixelChannel);
1656 if (black[channel] != white[channel])
1657 image->colormap[j].green=equalize_map[GetPixelChannels(image)*
1658 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))]+
1661 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1663 channel=GetPixelChannelMapChannel(image,BluePixelChannel);
1664 if (black[channel] != white[channel])
1665 image->colormap[j].blue=equalize_map[GetPixelChannels(image)*
1666 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))]+
1669 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1671 channel=GetPixelChannelMapChannel(image,AlphaPixelChannel);
1672 if (black[channel] != white[channel])
1673 image->colormap[j].alpha=equalize_map[GetPixelChannels(image)*
1674 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))]+
1683 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1684 #pragma omp parallel for schedule(static,4) shared(progress,status)
1686 for (y=0; y < (ssize_t) image->rows; y++)
1694 if (status == MagickFalse)
1696 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1697 if (q == (Quantum *) NULL)
1702 for (x=0; x < (ssize_t) image->columns; x++)
1707 if (GetPixelMask(image,q) != 0)
1709 q+=GetPixelChannels(image);
1712 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1720 channel=GetPixelChannelMapChannel(image,i);
1721 traits=GetPixelChannelMapTraits(image,channel);
1722 if (((traits & UpdatePixelTrait) != 0) && (black[i] != white[i]))
1723 q[i]=ClampToQuantum(equalize_map[GetPixelChannels(image)*
1724 ScaleQuantumToMap(q[i])+i]);
1726 q+=GetPixelChannels(image);
1728 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1730 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1735 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1736 #pragma omp critical (MagickCore_EqualizeImage)
1738 proceed=SetImageProgress(image,EqualizeImageTag,progress++,image->rows);
1739 if (proceed == MagickFalse)
1743 image_view=DestroyCacheView(image_view);
1744 equalize_map=(MagickRealType *) RelinquishMagickMemory(equalize_map);
1749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1753 % G a m m a I m a g e %
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1759 % GammaImage() gamma-corrects a particular image channel. The same
1760 % image viewed on different devices will have perceptual differences in the
1761 % way the image's intensities are represented on the screen. Specify
1762 % individual gamma levels for the red, green, and blue channels, or adjust
1763 % all three with the gamma parameter. Values typically range from 0.8 to 2.3.
1765 % You can also reduce the influence of a particular channel with a gamma
1768 % The format of the GammaImage method is:
1770 % MagickBooleanType GammaImage(Image *image,const double gamma,
1771 % ExceptionInfo *exception)
1773 % A description of each parameter follows:
1775 % o image: the image.
1777 % o level: the image gamma as a string (e.g. 1.6,1.2,1.0).
1779 % o gamma: the image gamma.
1782 MagickExport MagickBooleanType GammaImage(Image *image,const double gamma,
1783 ExceptionInfo *exception)
1785 #define GammaCorrectImageTag "GammaCorrect/Image"
1806 Allocate and initialize gamma maps.
1808 assert(image != (Image *) NULL);
1809 assert(image->signature == MagickSignature);
1810 if (image->debug != MagickFalse)
1811 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1814 gamma_map=(Quantum *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*gamma_map));
1815 if (gamma_map == (Quantum *) NULL)
1816 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1818 (void) ResetMagickMemory(gamma_map,0,(MaxMap+1)*sizeof(*gamma_map));
1820 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (MaxMap > 256)
1821 #pragma omp parallel for
1823 for (i=0; i <= (ssize_t) MaxMap; i++)
1824 gamma_map[i]=ScaleMapToQuantum((MagickRealType) (MaxMap*pow((double) i/
1825 MaxMap,1.0/gamma)));
1826 if (image->storage_class == PseudoClass)
1829 Gamma-correct colormap.
1831 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1832 #pragma omp parallel for schedule(static) shared(progress,status)
1834 for (i=0; i < (ssize_t) image->colors; i++)
1836 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1837 image->colormap[i].red=(MagickRealType) gamma_map[
1838 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))];
1839 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1840 image->colormap[i].green=(MagickRealType) gamma_map[
1841 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].green))];
1842 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1843 image->colormap[i].blue=(MagickRealType) gamma_map[
1844 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].blue))];
1845 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1846 image->colormap[i].alpha=(MagickRealType) gamma_map[
1847 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].alpha))];
1851 Gamma-correct image.
1855 image_view=AcquireCacheView(image);
1856 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1857 #pragma omp parallel for schedule(static,4) shared(progress,status)
1859 for (y=0; y < (ssize_t) image->rows; y++)
1867 if (status == MagickFalse)
1869 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1870 if (q == (Quantum *) NULL)
1875 for (x=0; x < (ssize_t) image->columns; x++)
1880 if (GetPixelMask(image,q) != 0)
1882 q+=GetPixelChannels(image);
1885 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1893 channel=GetPixelChannelMapChannel(image,i);
1894 traits=GetPixelChannelMapTraits(image,channel);
1895 if ((traits & UpdatePixelTrait) != 0)
1896 q[i]=gamma_map[ScaleQuantumToMap(q[i])];
1898 q+=GetPixelChannels(image);
1900 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1902 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1907 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1908 #pragma omp critical (MagickCore_GammaImage)
1910 proceed=SetImageProgress(image,GammaCorrectImageTag,progress++,
1912 if (proceed == MagickFalse)
1916 image_view=DestroyCacheView(image_view);
1917 gamma_map=(Quantum *) RelinquishMagickMemory(gamma_map);
1918 if (image->gamma != 0.0)
1919 image->gamma*=gamma;
1924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1928 % H a l d C l u t I m a g e %
1932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1934 % HaldClutImage() applies a Hald color lookup table to the image. A Hald
1935 % color lookup table is a 3-dimensional color cube mapped to 2 dimensions.
1936 % Create it with the HALD coder. You can apply any color transformation to
1937 % the Hald image and then use this method to apply the transform to the
1940 % The format of the HaldClutImage method is:
1942 % MagickBooleanType HaldClutImage(Image *image,Image *hald_image,
1943 % ExceptionInfo *exception)
1945 % A description of each parameter follows:
1947 % o image: the image, which is replaced by indexed CLUT values
1949 % o hald_image: the color lookup table image for replacement color values.
1951 % o exception: return any errors or warnings in this structure.
1955 static inline size_t MagickMin(const size_t x,const size_t y)
1962 MagickExport MagickBooleanType HaldClutImage(Image *image,
1963 const Image *hald_image,ExceptionInfo *exception)
1965 #define HaldClutImageTag "Clut/Image"
1967 typedef struct _HaldInfo
1999 assert(image != (Image *) NULL);
2000 assert(image->signature == MagickSignature);
2001 if (image->debug != MagickFalse)
2002 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2003 assert(hald_image != (Image *) NULL);
2004 assert(hald_image->signature == MagickSignature);
2005 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2006 return(MagickFalse);
2007 if (image->matte == MagickFalse)
2008 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2014 length=MagickMin(hald_image->columns,hald_image->rows);
2015 for (level=2; (level*level*level) < length; level++) ;
2017 cube_size=level*level;
2018 width=(double) hald_image->columns;
2019 GetPixelInfo(hald_image,&zero);
2020 image_view=AcquireCacheView(image);
2021 hald_view=AcquireCacheView(hald_image);
2022 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2023 #pragma omp parallel for schedule(static,4) shared(progress,status)
2025 for (y=0; y < (ssize_t) image->rows; y++)
2033 if (status == MagickFalse)
2035 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2036 if (q == (Quantum *) NULL)
2041 for (x=0; x < (ssize_t) image->columns; x++)
2056 point.x=QuantumScale*(level-1.0)*GetPixelRed(image,q);
2057 point.y=QuantumScale*(level-1.0)*GetPixelGreen(image,q);
2058 point.z=QuantumScale*(level-1.0)*GetPixelBlue(image,q);
2059 offset=point.x+level*floor(point.y)+cube_size*floor(point.z);
2060 point.x-=floor(point.x);
2061 point.y-=floor(point.y);
2062 point.z-=floor(point.z);
2064 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2065 fmod(offset,width),floor(offset/width),&pixel1,exception);
2067 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2068 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2070 CompositePixelInfoAreaBlend(&pixel1,pixel1.alpha,&pixel2,pixel2.alpha,
2073 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2074 fmod(offset,width),floor(offset/width),&pixel1,exception);
2075 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2076 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2078 CompositePixelInfoAreaBlend(&pixel1,pixel1.alpha,&pixel2,pixel2.alpha,
2081 CompositePixelInfoAreaBlend(&pixel3,pixel3.alpha,&pixel4,pixel4.alpha,
2083 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2084 SetPixelRed(image,ClampToQuantum(pixel.red),q);
2085 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2086 SetPixelGreen(image,ClampToQuantum(pixel.green),q);
2087 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2088 SetPixelBlue(image,ClampToQuantum(pixel.blue),q);
2089 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2090 (image->colorspace == CMYKColorspace))
2091 SetPixelBlack(image,ClampToQuantum(pixel.black),q);
2092 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2093 (image->matte != MagickFalse))
2094 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
2095 q+=GetPixelChannels(image);
2097 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2099 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2104 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2105 #pragma omp critical (MagickCore_HaldClutImage)
2107 proceed=SetImageProgress(image,HaldClutImageTag,progress++,image->rows);
2108 if (proceed == MagickFalse)
2112 hald_view=DestroyCacheView(hald_view);
2113 image_view=DestroyCacheView(image_view);
2118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2122 % L e v e l I m a g e %
2126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2128 % LevelImage() adjusts the levels of a particular image channel by
2129 % scaling the colors falling between specified white and black points to
2130 % the full available quantum range.
2132 % The parameters provided represent the black, and white points. The black
2133 % point specifies the darkest color in the image. Colors darker than the
2134 % black point are set to zero. White point specifies the lightest color in
2135 % the image. Colors brighter than the white point are set to the maximum
2138 % If a '!' flag is given, map black and white colors to the given levels
2139 % rather than mapping those levels to black and white. See
2140 % LevelizeImage() below.
2142 % Gamma specifies a gamma correction to apply to the image.
2144 % The format of the LevelImage method is:
2146 % MagickBooleanType LevelImage(Image *image,const double black_point,
2147 % const double white_point,const double gamma,ExceptionInfo *exception)
2149 % A description of each parameter follows:
2151 % o image: the image.
2153 % o black_point: The level to map zero (black) to.
2155 % o white_point: The level to map QuantumRange (white) to.
2157 % o exception: return any errors or warnings in this structure.
2161 static inline MagickRealType LevelPixel(const double black_point,
2162 const double white_point,const double gamma,const MagickRealType pixel)
2168 if (pixel < black_point)
2170 if (pixel > white_point)
2171 return((MagickRealType) QuantumRange);
2172 scale=(white_point != black_point) ? 1.0/(white_point-black_point) : 1.0;
2173 level_pixel=(MagickRealType) QuantumRange*pow(scale*((double) pixel-
2174 black_point),1.0/gamma);
2175 return(level_pixel);
2178 MagickExport MagickBooleanType LevelImage(Image *image,const double black_point,
2179 const double white_point,const double gamma,ExceptionInfo *exception)
2181 #define LevelImageTag "Level/Image"
2199 Allocate and initialize levels map.
2201 assert(image != (Image *) NULL);
2202 assert(image->signature == MagickSignature);
2203 if (image->debug != MagickFalse)
2204 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2205 if (image->storage_class == PseudoClass)
2206 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2207 #pragma omp parallel for schedule(static,4) shared(progress,status)
2209 for (i=0; i < (ssize_t) image->colors; i++)
2214 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2215 image->colormap[i].red=(double) ClampToQuantum(LevelPixel(black_point,
2216 white_point,gamma,image->colormap[i].red));
2217 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2218 image->colormap[i].green=(double) ClampToQuantum(LevelPixel(black_point,
2219 white_point,gamma,image->colormap[i].green));
2220 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2221 image->colormap[i].blue=(double) ClampToQuantum(LevelPixel(black_point,
2222 white_point,gamma,image->colormap[i].blue));
2223 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2224 image->colormap[i].alpha=(double) ClampToQuantum(LevelPixel(black_point,
2225 white_point,gamma,image->colormap[i].alpha));
2232 image_view=AcquireCacheView(image);
2233 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2234 #pragma omp parallel for schedule(static,4) shared(progress,status)
2236 for (y=0; y < (ssize_t) image->rows; y++)
2244 if (status == MagickFalse)
2246 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2247 if (q == (Quantum *) NULL)
2252 for (x=0; x < (ssize_t) image->columns; x++)
2257 if (GetPixelMask(image,q) != 0)
2259 q+=GetPixelChannels(image);
2262 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2270 channel=GetPixelChannelMapChannel(image,i);
2271 traits=GetPixelChannelMapTraits(image,channel);
2272 if (traits == UndefinedPixelTrait)
2274 q[i]=ClampToQuantum(LevelPixel(black_point,white_point,gamma,
2275 (MagickRealType) q[i]));
2277 q+=GetPixelChannels(image);
2279 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2281 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2286 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2287 #pragma omp critical (MagickCore_LevelImage)
2289 proceed=SetImageProgress(image,LevelImageTag,progress++,image->rows);
2290 if (proceed == MagickFalse)
2294 image_view=DestroyCacheView(image_view);
2299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2303 % L e v e l i z e I m a g e %
2307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2309 % LevelizeImage() applies the reversed LevelImage() operation to just
2310 % the specific channels specified. It compresses the full range of color
2311 % values, so that they lie between the given black and white points. Gamma is
2312 % applied before the values are mapped.
2314 % LevelizeImage() can be called with by using a +level command line
2315 % API option, or using a '!' on a -level or LevelImage() geometry string.
2317 % It can be used to de-contrast a greyscale image to the exact levels
2318 % specified. Or by using specific levels for each channel of an image you
2319 % can convert a gray-scale image to any linear color gradient, according to
2322 % The format of the LevelizeImage method is:
2324 % MagickBooleanType LevelizeImage(Image *image,const double black_point,
2325 % const double white_point,const double gamma,ExceptionInfo *exception)
2327 % A description of each parameter follows:
2329 % o image: the image.
2331 % o black_point: The level to map zero (black) to.
2333 % o white_point: The level to map QuantumRange (white) to.
2335 % o gamma: adjust gamma by this factor before mapping values.
2337 % o exception: return any errors or warnings in this structure.
2340 MagickExport MagickBooleanType LevelizeImage(Image *image,
2341 const double black_point,const double white_point,const double gamma,
2342 ExceptionInfo *exception)
2344 #define LevelizeImageTag "Levelize/Image"
2345 #define LevelizeValue(x) (ClampToQuantum(((MagickRealType) \
2346 pow((double) (QuantumScale*(x)),1.0/gamma))*(white_point-black_point)+ \
2365 Allocate and initialize levels map.
2367 assert(image != (Image *) NULL);
2368 assert(image->signature == MagickSignature);
2369 if (image->debug != MagickFalse)
2370 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2371 if (image->storage_class == PseudoClass)
2372 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2373 #pragma omp parallel for schedule(static,4) shared(progress,status)
2375 for (i=0; i < (ssize_t) image->colors; i++)
2380 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2381 image->colormap[i].red=(double) LevelizeValue(
2382 image->colormap[i].red);
2383 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2384 image->colormap[i].green=(double) LevelizeValue(
2385 image->colormap[i].green);
2386 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2387 image->colormap[i].blue=(double) LevelizeValue(
2388 image->colormap[i].blue);
2389 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2390 image->colormap[i].alpha=(double) LevelizeValue(
2391 image->colormap[i].alpha);
2398 image_view=AcquireCacheView(image);
2399 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2400 #pragma omp parallel for schedule(static,4) shared(progress,status)
2402 for (y=0; y < (ssize_t) image->rows; y++)
2410 if (status == MagickFalse)
2412 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2413 if (q == (Quantum *) NULL)
2418 for (x=0; x < (ssize_t) image->columns; x++)
2423 if (GetPixelMask(image,q) != 0)
2425 q+=GetPixelChannels(image);
2428 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2436 channel=GetPixelChannelMapChannel(image,i);
2437 traits=GetPixelChannelMapTraits(image,channel);
2438 if (traits == UndefinedPixelTrait)
2440 q[i]=LevelizeValue(q[i]);
2442 q+=GetPixelChannels(image);
2444 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2446 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2451 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2452 #pragma omp critical (MagickCore_LevelizeImage)
2454 proceed=SetImageProgress(image,LevelizeImageTag,progress++,image->rows);
2455 if (proceed == MagickFalse)
2459 image_view=DestroyCacheView(image_view);
2464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2468 % L e v e l I m a g e C o l o r s %
2472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2474 % LevelImageColors() maps the given color to "black" and "white" values,
2475 % linearly spreading out the colors, and level values on a channel by channel
2476 % bases, as per LevelImage(). The given colors allows you to specify
2477 % different level ranges for each of the color channels separately.
2479 % If the boolean 'invert' is set true the image values will modifyed in the
2480 % reverse direction. That is any existing "black" and "white" colors in the
2481 % image will become the color values given, with all other values compressed
2482 % appropriatally. This effectivally maps a greyscale gradient into the given
2485 % The format of the LevelImageColors method is:
2487 % MagickBooleanType LevelImageColors(Image *image,
2488 % const PixelInfo *black_color,const PixelInfo *white_color,
2489 % const MagickBooleanType invert,ExceptionInfo *exception)
2491 % A description of each parameter follows:
2493 % o image: the image.
2495 % o black_color: The color to map black to/from
2497 % o white_point: The color to map white to/from
2499 % o invert: if true map the colors (levelize), rather than from (level)
2501 % o exception: return any errors or warnings in this structure.
2504 MagickExport MagickBooleanType LevelImageColors(Image *image,
2505 const PixelInfo *black_color,const PixelInfo *white_color,
2506 const MagickBooleanType invert,ExceptionInfo *exception)
2515 Allocate and initialize levels map.
2517 assert(image != (Image *) NULL);
2518 assert(image->signature == MagickSignature);
2519 if (image->debug != MagickFalse)
2520 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2522 if (invert == MagickFalse)
2524 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2526 channel_mask=SetPixelChannelMask(image,RedChannel);
2527 status|=LevelImage(image,black_color->red,white_color->red,1.0,
2529 (void) SetPixelChannelMask(image,channel_mask);
2531 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2533 channel_mask=SetPixelChannelMask(image,GreenChannel);
2534 status|=LevelImage(image,black_color->green,white_color->green,1.0,
2536 (void) SetPixelChannelMask(image,channel_mask);
2538 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2540 channel_mask=SetPixelChannelMask(image,BlueChannel);
2541 status|=LevelImage(image,black_color->blue,white_color->blue,1.0,
2543 (void) SetPixelChannelMask(image,channel_mask);
2545 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2546 (image->colorspace == CMYKColorspace))
2548 channel_mask=SetPixelChannelMask(image,BlackChannel);
2549 status|=LevelImage(image,black_color->black,white_color->black,1.0,
2551 (void) SetPixelChannelMask(image,channel_mask);
2553 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2554 (image->matte == MagickTrue))
2556 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2557 status|=LevelImage(image,black_color->alpha,white_color->alpha,1.0,
2559 (void) SetPixelChannelMask(image,channel_mask);
2564 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2566 channel_mask=SetPixelChannelMask(image,RedChannel);
2567 status|=LevelizeImage(image,black_color->red,white_color->red,1.0,
2569 (void) SetPixelChannelMask(image,channel_mask);
2571 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2573 channel_mask=SetPixelChannelMask(image,GreenChannel);
2574 status|=LevelizeImage(image,black_color->green,white_color->green,1.0,
2576 (void) SetPixelChannelMask(image,channel_mask);
2578 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2580 channel_mask=SetPixelChannelMask(image,BlueChannel);
2581 status|=LevelizeImage(image,black_color->blue,white_color->blue,1.0,
2583 (void) SetPixelChannelMask(image,channel_mask);
2585 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2586 (image->colorspace == CMYKColorspace))
2588 channel_mask=SetPixelChannelMask(image,BlackChannel);
2589 status|=LevelizeImage(image,black_color->black,white_color->black,1.0,
2591 (void) SetPixelChannelMask(image,channel_mask);
2593 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2594 (image->matte == MagickTrue))
2596 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2597 status|=LevelizeImage(image,black_color->alpha,white_color->alpha,1.0,
2599 (void) SetPixelChannelMask(image,channel_mask);
2602 return(status == 0 ? MagickFalse : MagickTrue);
2606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2610 % L i n e a r S t r e t c h I m a g e %
2614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2616 % LinearStretchImage() discards any pixels below the black point and above
2617 % the white point and levels the remaining pixels.
2619 % The format of the LinearStretchImage method is:
2621 % MagickBooleanType LinearStretchImage(Image *image,
2622 % const double black_point,const double white_point,
2623 % ExceptionInfo *exception)
2625 % A description of each parameter follows:
2627 % o image: the image.
2629 % o black_point: the black point.
2631 % o white_point: the white point.
2633 % o exception: return any errors or warnings in this structure.
2636 MagickExport MagickBooleanType LinearStretchImage(Image *image,
2637 const double black_point,const double white_point,ExceptionInfo *exception)
2639 #define LinearStretchImageTag "LinearStretch/Image"
2657 Allocate histogram and linear map.
2659 assert(image != (Image *) NULL);
2660 assert(image->signature == MagickSignature);
2661 histogram=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
2662 sizeof(*histogram));
2663 if (histogram == (MagickRealType *) NULL)
2664 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
2669 (void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram));
2670 image_view=AcquireCacheView(image);
2671 for (y=0; y < (ssize_t) image->rows; y++)
2673 register const Quantum
2679 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2680 if (p == (const Quantum *) NULL)
2682 for (x=0; x < (ssize_t) image->columns; x++)
2684 histogram[ScaleQuantumToMap(GetPixelIntensity(image,p))]++;
2685 p+=GetPixelChannels(image);
2688 image_view=DestroyCacheView(image_view);
2690 Find the histogram boundaries by locating the black and white point levels.
2693 for (black=0; black < (ssize_t) MaxMap; black++)
2695 intensity+=histogram[black];
2696 if (intensity >= black_point)
2700 for (white=(ssize_t) MaxMap; white != 0; white--)
2702 intensity+=histogram[white];
2703 if (intensity >= white_point)
2706 histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
2707 status=LevelImage(image,(double) black,(double) white,1.0,exception);
2712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2716 % M o d u l a t e I m a g e %
2720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2722 % ModulateImage() lets you control the brightness, saturation, and hue
2723 % of an image. Modulate represents the brightness, saturation, and hue
2724 % as one parameter (e.g. 90,150,100). If the image colorspace is HSL, the
2725 % modulation is lightness, saturation, and hue. And if the colorspace is
2726 % HWB, use blackness, whiteness, and hue.
2728 % The format of the ModulateImage method is:
2730 % MagickBooleanType ModulateImage(Image *image,const char *modulate,
2731 % ExceptionInfo *exception)
2733 % A description of each parameter follows:
2735 % o image: the image.
2737 % o modulate: Define the percent change in brightness, saturation, and hue.
2739 % o exception: return any errors or warnings in this structure.
2743 static void ModulateHSB(const double percent_hue,
2744 const double percent_saturation,const double percent_brightness,double *red,
2745 double *green,double *blue)
2753 Increase or decrease color brightness, saturation, or hue.
2755 assert(red != (double *) NULL);
2756 assert(green != (double *) NULL);
2757 assert(blue != (double *) NULL);
2758 ConvertRGBToHSB(*red,*green,*blue,&hue,&saturation,&brightness);
2759 hue+=0.5*(0.01*percent_hue-1.0);
2764 saturation*=0.01*percent_saturation;
2765 brightness*=0.01*percent_brightness;
2766 ConvertHSBToRGB(hue,saturation,brightness,red,green,blue);
2769 static void ModulateHSL(const double percent_hue,
2770 const double percent_saturation,const double percent_lightness,double *red,
2771 double *green,double *blue)
2779 Increase or decrease color lightness, saturation, or hue.
2781 assert(red != (double *) NULL);
2782 assert(green != (double *) NULL);
2783 assert(blue != (double *) NULL);
2784 ConvertRGBToHSL(*red,*green,*blue,&hue,&saturation,&lightness);
2785 hue+=0.5*(0.01*percent_hue-1.0);
2790 saturation*=0.01*percent_saturation;
2791 lightness*=0.01*percent_lightness;
2792 ConvertHSLToRGB(hue,saturation,lightness,red,green,blue);
2795 static void ModulateHWB(const double percent_hue,const double percent_whiteness, const double percent_blackness,double *red,double *green,double *blue)
2803 Increase or decrease color blackness, whiteness, or hue.
2805 assert(red != (double *) NULL);
2806 assert(green != (double *) NULL);
2807 assert(blue != (double *) NULL);
2808 ConvertRGBToHWB(*red,*green,*blue,&hue,&whiteness,&blackness);
2809 hue+=0.5*(0.01*percent_hue-1.0);
2814 blackness*=0.01*percent_blackness;
2815 whiteness*=0.01*percent_whiteness;
2816 ConvertHWBToRGB(hue,whiteness,blackness,red,green,blue);
2819 MagickExport MagickBooleanType ModulateImage(Image *image,const char *modulate,
2820 ExceptionInfo *exception)
2822 #define ModulateImageTag "Modulate/Image"
2857 Initialize modulate table.
2859 assert(image != (Image *) NULL);
2860 assert(image->signature == MagickSignature);
2861 if (image->debug != MagickFalse)
2862 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2863 if (modulate == (char *) NULL)
2864 return(MagickFalse);
2865 flags=ParseGeometry(modulate,&geometry_info);
2866 percent_brightness=geometry_info.rho;
2867 percent_saturation=geometry_info.sigma;
2868 if ((flags & SigmaValue) == 0)
2869 percent_saturation=100.0;
2870 percent_hue=geometry_info.xi;
2871 if ((flags & XiValue) == 0)
2873 colorspace=UndefinedColorspace;
2874 artifact=GetImageArtifact(image,"modulate:colorspace");
2875 if (artifact != (const char *) NULL)
2876 colorspace=(ColorspaceType) ParseCommandOption(MagickColorspaceOptions,
2877 MagickFalse,artifact);
2878 if (image->storage_class == PseudoClass)
2883 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2884 #pragma omp parallel for schedule(static,4) shared(progress,status)
2886 for (i=0; i < (ssize_t) image->colors; i++)
2891 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
2892 &image->colormap[i].red,&image->colormap[i].green,
2893 &image->colormap[i].blue);
2899 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
2900 &image->colormap[i].red,&image->colormap[i].green,
2901 &image->colormap[i].blue);
2906 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
2907 &image->colormap[i].red,&image->colormap[i].green,
2908 &image->colormap[i].blue);
2918 image_view=AcquireCacheView(image);
2919 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2920 #pragma omp parallel for schedule(static,4) shared(progress,status)
2922 for (y=0; y < (ssize_t) image->rows; y++)
2935 if (status == MagickFalse)
2937 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2938 if (q == (Quantum *) NULL)
2943 for (x=0; x < (ssize_t) image->columns; x++)
2945 red=(double) GetPixelRed(image,q);
2946 green=(double) GetPixelGreen(image,q);
2947 blue=(double) GetPixelBlue(image,q);
2952 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
2959 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
2965 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
2970 SetPixelRed(image,ClampToQuantum(red),q);
2971 SetPixelGreen(image,ClampToQuantum(green),q);
2972 SetPixelBlue(image,ClampToQuantum(blue),q);
2973 q+=GetPixelChannels(image);
2975 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2977 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2982 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2983 #pragma omp critical (MagickCore_ModulateImage)
2985 proceed=SetImageProgress(image,ModulateImageTag,progress++,image->rows);
2986 if (proceed == MagickFalse)
2990 image_view=DestroyCacheView(image_view);
2995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2999 % N e g a t e I m a g e %
3003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3005 % NegateImage() negates the colors in the reference image. The grayscale
3006 % option means that only grayscale values within the image are negated.
3008 % The format of the NegateImage method is:
3010 % MagickBooleanType NegateImage(Image *image,
3011 % const MagickBooleanType grayscale,ExceptionInfo *exception)
3013 % A description of each parameter follows:
3015 % o image: the image.
3017 % o grayscale: If MagickTrue, only negate grayscale pixels within the image.
3019 % o exception: return any errors or warnings in this structure.
3022 MagickExport MagickBooleanType NegateImage(Image *image,
3023 const MagickBooleanType grayscale,ExceptionInfo *exception)
3025 #define NegateImageTag "Negate/Image"
3042 assert(image != (Image *) NULL);
3043 assert(image->signature == MagickSignature);
3044 if (image->debug != MagickFalse)
3045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3046 if (image->storage_class == PseudoClass)
3051 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3052 #pragma omp parallel for schedule(static) shared(progress,status)
3054 for (i=0; i < (ssize_t) image->colors; i++)
3056 if (grayscale != MagickFalse)
3057 if ((image->colormap[i].red != image->colormap[i].green) ||
3058 (image->colormap[i].green != image->colormap[i].blue))
3060 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
3061 image->colormap[i].red=(Quantum) QuantumRange-
3062 image->colormap[i].red;
3063 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
3064 image->colormap[i].green=(Quantum) QuantumRange-
3065 image->colormap[i].green;
3066 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
3067 image->colormap[i].blue=(Quantum) QuantumRange-
3068 image->colormap[i].blue;
3076 image_view=AcquireCacheView(image);
3077 if (grayscale != MagickFalse)
3079 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3080 #pragma omp parallel for schedule(static) shared(progress,status)
3082 for (y=0; y < (ssize_t) image->rows; y++)
3093 if (status == MagickFalse)
3095 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
3097 if (q == (Quantum *) NULL)
3102 for (x=0; x < (ssize_t) image->columns; x++)
3107 if ((GetPixelMask(image,q) != 0) ||
3108 (IsPixelGray(image,q) != MagickFalse))
3110 q+=GetPixelChannels(image);
3113 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3121 channel=GetPixelChannelMapChannel(image,i);
3122 traits=GetPixelChannelMapTraits(image,channel);
3123 if ((traits & UpdatePixelTrait) != 0)
3124 q[i]=QuantumRange-q[i];
3126 q+=GetPixelChannels(image);
3128 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3129 if (sync == MagickFalse)
3131 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3136 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3137 #pragma omp critical (MagickCore_NegateImage)
3139 proceed=SetImageProgress(image,NegateImageTag,progress++,
3141 if (proceed == MagickFalse)
3145 image_view=DestroyCacheView(image_view);
3151 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3152 #pragma omp parallel for schedule(static) shared(progress,status)
3154 for (y=0; y < (ssize_t) image->rows; y++)
3162 if (status == MagickFalse)
3164 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3165 if (q == (Quantum *) NULL)
3170 for (x=0; x < (ssize_t) image->columns; x++)
3175 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3183 channel=GetPixelChannelMapChannel(image,i);
3184 traits=GetPixelChannelMapTraits(image,channel);
3185 if (((traits & CopyPixelTrait) != 0) ||
3186 (GetPixelMask(image,q) != 0))
3188 q[i]=QuantumRange-q[i];
3190 q+=GetPixelChannels(image);
3192 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3194 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3199 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3200 #pragma omp critical (MagickCore_NegateImage)
3202 proceed=SetImageProgress(image,NegateImageTag,progress++,image->rows);
3203 if (proceed == MagickFalse)
3207 image_view=DestroyCacheView(image_view);
3212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3216 % N o r m a l i z e I m a g e %
3220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3222 % NormalizeImage() enhances the contrast of a color image by mapping the
3223 % darkest 2 percent of all pixel to black and the brightest 1 percent to white.
3225 % The format of the NormalizeImage method is:
3227 % MagickBooleanType NormalizeImage(Image *image,ExceptionInfo *exception)
3229 % A description of each parameter follows:
3231 % o image: the image.
3233 % o exception: return any errors or warnings in this structure.
3236 MagickExport MagickBooleanType NormalizeImage(Image *image,
3237 ExceptionInfo *exception)
3243 black_point=(double) image->columns*image->rows*0.0015;
3244 white_point=(double) image->columns*image->rows*0.9995;
3245 return(ContrastStretchImage(image,black_point,white_point,exception));
3249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3253 % S i g m o i d a l C o n t r a s t I m a g e %
3257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3259 % SigmoidalContrastImage() adjusts the contrast of an image with a non-linear
3260 % sigmoidal contrast algorithm. Increase the contrast of the image using a
3261 % sigmoidal transfer function without saturating highlights or shadows.
3262 % Contrast indicates how much to increase the contrast (0 is none; 3 is
3263 % typical; 20 is pushing it); mid-point indicates where threshold 'knee' of
3264 % the curve falls (typical 50% for mid-gray). Set sharpen to MagickTrue to
3265 % increase the image contrast otherwise the contrast is reduced.
3267 % The format of the SigmoidalContrastImage method is:
3269 % MagickBooleanType SigmoidalContrastImage(Image *image,
3270 % const MagickBooleanType sharpen,const char *levels,
3271 % ExceptionInfo *exception)
3273 % A description of each parameter follows:
3275 % o image: the image.
3277 % o sharpen: Increase or decrease image contrast.
3279 % o alpha: strength of the contrast, the larger the number the more
3280 % 'threshold-like' it becomes.
3282 % o beta: midpoint of the function as a color value 0 to QuantumRange.
3284 % o exception: return any errors or warnings in this structure.
3287 MagickExport MagickBooleanType SigmoidalContrastImage(Image *image,
3288 const MagickBooleanType sharpen,const double contrast,const double midpoint,
3289 ExceptionInfo *exception)
3291 #define SigmoidalContrastImageTag "SigmoidalContrast/Image"
3312 Allocate and initialize sigmoidal maps.
3314 assert(image != (Image *) NULL);
3315 assert(image->signature == MagickSignature);
3316 if (image->debug != MagickFalse)
3317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3318 sigmoidal_map=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
3319 sizeof(*sigmoidal_map));
3320 if (sigmoidal_map == (MagickRealType *) NULL)
3321 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3323 (void) ResetMagickMemory(sigmoidal_map,0,(MaxMap+1)*sizeof(*sigmoidal_map));
3324 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3325 #pragma omp parallel for schedule(static) shared(progress,status)
3327 for (i=0; i <= (ssize_t) MaxMap; i++)
3329 if (sharpen != MagickFalse)
3331 sigmoidal_map[i]=(MagickRealType) ScaleMapToQuantum((MagickRealType)
3332 (MaxMap*((1.0/(1.0+exp(contrast*(midpoint/(double) QuantumRange-
3333 (double) i/MaxMap))))-(1.0/(1.0+exp(contrast*(midpoint/(double)
3334 QuantumRange)))))/((1.0/(1.0+exp(contrast*(midpoint/(double)
3335 QuantumRange-1.0))))-(1.0/(1.0+exp(contrast*(midpoint/(double)
3336 QuantumRange)))))+0.5));
3339 sigmoidal_map[i]=(MagickRealType) ScaleMapToQuantum((MagickRealType)
3340 (MaxMap*(QuantumScale*midpoint-log((1.0-(1.0/(1.0+exp(midpoint/(double)
3341 QuantumRange*contrast))+((double) i/MaxMap)*((1.0/(1.0+exp(contrast*(
3342 midpoint/(double) QuantumRange-1.0))))-(1.0/(1.0+exp(midpoint/(double)
3343 QuantumRange*contrast))))))/(1.0/(1.0+exp(midpoint/(double) QuantumRange*
3344 contrast))+((double) i/MaxMap)*((1.0/(1.0+exp(contrast*(midpoint/(double)
3345 QuantumRange-1.0))))-(1.0/(1.0+exp(midpoint/(double) QuantumRange*
3346 contrast))))))/contrast)));
3348 if (image->storage_class == PseudoClass)
3351 Sigmoidal-contrast enhance colormap.
3353 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3354 #pragma omp parallel for schedule(static,4) shared(progress,status)
3356 for (i=0; i < (ssize_t) image->colors; i++)
3358 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
3359 image->colormap[i].red=sigmoidal_map[ScaleQuantumToMap(
3360 ClampToQuantum(image->colormap[i].red))];
3361 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
3362 image->colormap[i].green=sigmoidal_map[ScaleQuantumToMap(
3363 ClampToQuantum(image->colormap[i].green))];
3364 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
3365 image->colormap[i].blue=sigmoidal_map[ScaleQuantumToMap(
3366 ClampToQuantum(image->colormap[i].blue))];
3367 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
3368 image->colormap[i].alpha=sigmoidal_map[ScaleQuantumToMap(
3369 ClampToQuantum(image->colormap[i].alpha))];
3373 Sigmoidal-contrast enhance image.
3377 image_view=AcquireCacheView(image);
3378 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3379 #pragma omp parallel for schedule(static,4) shared(progress,status)
3381 for (y=0; y < (ssize_t) image->rows; y++)
3389 if (status == MagickFalse)
3391 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3392 if (q == (Quantum *) NULL)
3397 for (x=0; x < (ssize_t) image->columns; x++)
3402 if (GetPixelMask(image,q) != 0)
3404 q+=GetPixelChannels(image);
3407 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3415 channel=GetPixelChannelMapChannel(image,i);
3416 traits=GetPixelChannelMapTraits(image,channel);
3417 if ((traits & UpdatePixelTrait) != 0)
3418 q[i]=ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(q[i])]);
3420 q+=GetPixelChannels(image);
3422 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3424 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3429 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3430 #pragma omp critical (MagickCore_SigmoidalContrastImage)
3432 proceed=SetImageProgress(image,SigmoidalContrastImageTag,progress++,
3434 if (proceed == MagickFalse)
3438 image_view=DestroyCacheView(image_view);
3439 sigmoidal_map=(MagickRealType *) RelinquishMagickMemory(sigmoidal_map);