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]))
1250 q[i]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
1251 ScaleQuantumToMap(q[i])+i]);
1253 q+=GetPixelChannels(image);
1255 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1257 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1262 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1263 #pragma omp critical (MagickCore_ContrastStretchImage)
1265 proceed=SetImageProgress(image,ContrastStretchImageTag,progress++,
1267 if (proceed == MagickFalse)
1271 image_view=DestroyCacheView(image_view);
1272 stretch_map=(double *) RelinquishMagickMemory(stretch_map);
1273 white=(double *) RelinquishMagickMemory(white);
1274 black=(double *) RelinquishMagickMemory(black);
1279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 % E n h a n c e I m a g e %
1287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 % EnhanceImage() applies a digital filter that improves the quality of a
1292 % The format of the EnhanceImage method is:
1294 % Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
1296 % A description of each parameter follows:
1298 % o image: the image.
1300 % o exception: return any errors or warnings in this structure.
1303 MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
1305 #define EnhancePixel(weight) \
1306 mean=((MagickRealType) r[i]+GetPixelChannel(enhance_image,channel,q))/2.0; \
1307 distance=(MagickRealType) r[i]-(MagickRealType) GetPixelChannel( \
1308 enhance_image,channel,q); \
1309 distance_squared=QuantumScale*(2.0*((MagickRealType) QuantumRange+1.0)+ \
1310 mean)*distance*distance; \
1311 if (distance_squared < ((MagickRealType) QuantumRange*(MagickRealType) \
1312 QuantumRange/25.0f)) \
1314 aggregate+=(weight)*r[i]; \
1315 total_weight+=(weight); \
1317 r+=GetPixelChannels(image);
1318 #define EnhanceImageTag "Enhance/Image"
1337 Initialize enhanced image attributes.
1339 assert(image != (const Image *) NULL);
1340 assert(image->signature == MagickSignature);
1341 if (image->debug != MagickFalse)
1342 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1343 assert(exception != (ExceptionInfo *) NULL);
1344 assert(exception->signature == MagickSignature);
1345 enhance_image=CloneImage(image,image->columns,image->rows,MagickTrue,
1347 if (enhance_image == (Image *) NULL)
1348 return((Image *) NULL);
1349 if (SetImageStorageClass(enhance_image,DirectClass,exception) == MagickFalse)
1351 enhance_image=DestroyImage(enhance_image);
1352 return((Image *) NULL);
1359 image_view=AcquireCacheView(image);
1360 enhance_view=AcquireCacheView(enhance_image);
1361 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1362 #pragma omp parallel for schedule(static,4) shared(progress,status)
1364 for (y=0; y < (ssize_t) image->rows; y++)
1366 register const Quantum
1378 if (status == MagickFalse)
1380 p=GetCacheViewVirtualPixels(image_view,-2,y-2,image->columns+4,5,exception);
1381 q=QueueCacheViewAuthenticPixels(enhance_view,0,y,enhance_image->columns,1,
1383 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1388 center=(ssize_t) GetPixelChannels(image)*(2*(image->columns+4)+2);
1389 for (x=0; x < (ssize_t) image->columns; x++)
1394 if (GetPixelMask(image,p) != 0)
1396 p+=GetPixelChannels(image);
1397 q+=GetPixelChannels(enhance_image);
1400 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1416 register const Quantum
1419 channel=GetPixelChannelMapChannel(image,i);
1420 traits=GetPixelChannelMapTraits(image,channel);
1421 enhance_traits=GetPixelChannelMapTraits(enhance_image,channel);
1422 if ((traits == UndefinedPixelTrait) ||
1423 (enhance_traits == UndefinedPixelTrait))
1425 SetPixelChannel(enhance_image,channel,p[center+i],q);
1426 if ((enhance_traits & CopyPixelTrait) != 0)
1429 Compute weighted average of target pixel color components.
1434 EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
1435 EnhancePixel(8.0); EnhancePixel(5.0);
1436 r=p+1*GetPixelChannels(image)*(image->columns+4);
1437 EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
1438 EnhancePixel(20.0); EnhancePixel(8.0);
1439 r=p+2*GetPixelChannels(image)*(image->columns+4);
1440 EnhancePixel(10.0); EnhancePixel(40.0); EnhancePixel(80.0);
1441 EnhancePixel(40.0); EnhancePixel(10.0);
1442 r=p+3*GetPixelChannels(image)*(image->columns+4);
1443 EnhancePixel(8.0); EnhancePixel(20.0); EnhancePixel(40.0);
1444 EnhancePixel(20.0); EnhancePixel(8.0);
1445 r=p+4*GetPixelChannels(image)*(image->columns+4);
1446 EnhancePixel(5.0); EnhancePixel(8.0); EnhancePixel(10.0);
1447 EnhancePixel(8.0); EnhancePixel(5.0);
1448 SetPixelChannel(enhance_image,channel,ClampToQuantum(aggregate/
1451 p+=GetPixelChannels(image);
1452 q+=GetPixelChannels(enhance_image);
1454 if (SyncCacheViewAuthenticPixels(enhance_view,exception) == MagickFalse)
1456 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1461 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1462 #pragma omp critical (MagickCore_EnhanceImage)
1464 proceed=SetImageProgress(image,EnhanceImageTag,progress++,image->rows);
1465 if (proceed == MagickFalse)
1469 enhance_view=DestroyCacheView(enhance_view);
1470 image_view=DestroyCacheView(image_view);
1471 return(enhance_image);
1475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1479 % E q u a l i z e I m a g e %
1483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1485 % EqualizeImage() applies a histogram equalization to the image.
1487 % The format of the EqualizeImage method is:
1489 % MagickBooleanType EqualizeImage(Image *image,ExceptionInfo *exception)
1491 % A description of each parameter follows:
1493 % o image: the image.
1495 % o exception: return any errors or warnings in this structure.
1498 MagickExport MagickBooleanType EqualizeImage(Image *image,
1499 ExceptionInfo *exception)
1501 #define EqualizeImageTag "Equalize/Image"
1513 black[CompositePixelChannel],
1517 white[CompositePixelChannel];
1529 Allocate and initialize histogram arrays.
1531 assert(image != (Image *) NULL);
1532 assert(image->signature == MagickSignature);
1533 if (image->debug != MagickFalse)
1534 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1535 equalize_map=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
1536 GetPixelChannels(image)*sizeof(*equalize_map));
1537 histogram=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
1538 GetPixelChannels(image)*sizeof(*histogram));
1539 map=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
1540 GetPixelChannels(image)*sizeof(*map));
1541 if ((equalize_map == (MagickRealType *) NULL) ||
1542 (histogram == (MagickRealType *) NULL) ||
1543 (map == (MagickRealType *) NULL))
1545 if (map != (MagickRealType *) NULL)
1546 map=(MagickRealType *) RelinquishMagickMemory(map);
1547 if (histogram != (MagickRealType *) NULL)
1548 histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
1549 if (equalize_map != (MagickRealType *) NULL)
1550 equalize_map=(MagickRealType *) RelinquishMagickMemory(equalize_map);
1551 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1558 (void) ResetMagickMemory(histogram,0,(MaxMap+1)*GetPixelChannels(image)*
1559 sizeof(*histogram));
1560 image_view=AcquireCacheView(image);
1561 for (y=0; y < (ssize_t) image->rows; y++)
1563 register const Quantum
1569 if (status == MagickFalse)
1571 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1572 if (p == (const Quantum *) NULL)
1577 for (x=0; x < (ssize_t) image->columns; x++)
1582 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1583 histogram[GetPixelChannels(image)*ScaleQuantumToMap(p[i])+i]++;
1584 p+=GetPixelChannels(image);
1588 Integrate the histogram to get the equalization map.
1590 number_channels=GetPixelChannels(image);
1591 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1592 #pragma omp parallel for schedule(static,4) shared(progress,status)
1594 for (i=0; i < (ssize_t) number_channels; i++)
1603 for (j=0; j <= (ssize_t) MaxMap; j++)
1605 intensity+=histogram[GetPixelChannels(image)*j+i];
1606 map[GetPixelChannels(image)*j+i]=intensity;
1609 (void) ResetMagickMemory(equalize_map,0,(MaxMap+1)*GetPixelChannels(image)*
1610 sizeof(*equalize_map));
1611 number_channels=GetPixelChannels(image);
1612 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1613 #pragma omp parallel for schedule(static,4) shared(progress,status)
1615 for (i=0; i < (ssize_t) number_channels; i++)
1621 white[i]=map[GetPixelChannels(image)*MaxMap+i];
1622 if (black[i] != white[i])
1623 for (j=0; j <= (ssize_t) MaxMap; j++)
1624 equalize_map[GetPixelChannels(image)*j+i]=(MagickRealType)
1625 ScaleMapToQuantum((MagickRealType) ((MaxMap*(map[
1626 GetPixelChannels(image)*j+i]-black[i]))/(white[i]-black[i])));
1628 histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
1629 map=(MagickRealType *) RelinquishMagickMemory(map);
1630 if (image->storage_class == PseudoClass)
1641 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1642 #pragma omp parallel for schedule(static,4) shared(progress,status)
1644 for (j=0; j < (ssize_t) image->colors; j++)
1646 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1648 channel=GetPixelChannelMapChannel(image,RedPixelChannel);
1649 if (black[channel] != white[channel])
1650 image->colormap[j].red=equalize_map[GetPixelChannels(image)*
1651 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].red))]+
1654 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1656 channel=GetPixelChannelMapChannel(image,GreenPixelChannel);
1657 if (black[channel] != white[channel])
1658 image->colormap[j].green=equalize_map[GetPixelChannels(image)*
1659 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].green))]+
1662 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1664 channel=GetPixelChannelMapChannel(image,BluePixelChannel);
1665 if (black[channel] != white[channel])
1666 image->colormap[j].blue=equalize_map[GetPixelChannels(image)*
1667 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].blue))]+
1670 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1672 channel=GetPixelChannelMapChannel(image,AlphaPixelChannel);
1673 if (black[channel] != white[channel])
1674 image->colormap[j].alpha=equalize_map[GetPixelChannels(image)*
1675 ScaleQuantumToMap(ClampToQuantum(image->colormap[j].alpha))]+
1684 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1685 #pragma omp parallel for schedule(static,4) shared(progress,status)
1687 for (y=0; y < (ssize_t) image->rows; y++)
1695 if (status == MagickFalse)
1697 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1698 if (q == (Quantum *) NULL)
1703 for (x=0; x < (ssize_t) image->columns; x++)
1708 if (GetPixelMask(image,q) != 0)
1710 q+=GetPixelChannels(image);
1713 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1721 channel=GetPixelChannelMapChannel(image,i);
1722 traits=GetPixelChannelMapTraits(image,channel);
1723 if (((traits & UpdatePixelTrait) == 0) || (black[i] == white[i]))
1725 q[i]=ClampToQuantum(equalize_map[GetPixelChannels(image)*
1726 ScaleQuantumToMap(q[i])+i]);
1728 q+=GetPixelChannels(image);
1730 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1732 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1737 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1738 #pragma omp critical (MagickCore_EqualizeImage)
1740 proceed=SetImageProgress(image,EqualizeImageTag,progress++,image->rows);
1741 if (proceed == MagickFalse)
1745 image_view=DestroyCacheView(image_view);
1746 equalize_map=(MagickRealType *) RelinquishMagickMemory(equalize_map);
1751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1755 % G a m m a I m a g e %
1759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1761 % GammaImage() gamma-corrects a particular image channel. The same
1762 % image viewed on different devices will have perceptual differences in the
1763 % way the image's intensities are represented on the screen. Specify
1764 % individual gamma levels for the red, green, and blue channels, or adjust
1765 % all three with the gamma parameter. Values typically range from 0.8 to 2.3.
1767 % You can also reduce the influence of a particular channel with a gamma
1770 % The format of the GammaImage method is:
1772 % MagickBooleanType GammaImage(Image *image,const double gamma,
1773 % ExceptionInfo *exception)
1775 % A description of each parameter follows:
1777 % o image: the image.
1779 % o level: the image gamma as a string (e.g. 1.6,1.2,1.0).
1781 % o gamma: the image gamma.
1784 MagickExport MagickBooleanType GammaImage(Image *image,const double gamma,
1785 ExceptionInfo *exception)
1787 #define GammaCorrectImageTag "GammaCorrect/Image"
1808 Allocate and initialize gamma maps.
1810 assert(image != (Image *) NULL);
1811 assert(image->signature == MagickSignature);
1812 if (image->debug != MagickFalse)
1813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1816 gamma_map=(Quantum *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*gamma_map));
1817 if (gamma_map == (Quantum *) NULL)
1818 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1820 (void) ResetMagickMemory(gamma_map,0,(MaxMap+1)*sizeof(*gamma_map));
1822 #if defined(MAGICKCORE_OPENMP_SUPPORT) && (MaxMap > 256)
1823 #pragma omp parallel for
1825 for (i=0; i <= (ssize_t) MaxMap; i++)
1826 gamma_map[i]=ScaleMapToQuantum((MagickRealType) (MaxMap*pow((double) i/
1827 MaxMap,1.0/gamma)));
1828 if (image->storage_class == PseudoClass)
1831 Gamma-correct colormap.
1833 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1834 #pragma omp parallel for schedule(static) shared(progress,status)
1836 for (i=0; i < (ssize_t) image->colors; i++)
1838 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
1839 image->colormap[i].red=(MagickRealType) gamma_map[
1840 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))];
1841 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
1842 image->colormap[i].green=(MagickRealType) gamma_map[
1843 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].green))];
1844 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
1845 image->colormap[i].blue=(MagickRealType) gamma_map[
1846 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].blue))];
1847 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1848 image->colormap[i].alpha=(MagickRealType) gamma_map[
1849 ScaleQuantumToMap(ClampToQuantum(image->colormap[i].alpha))];
1853 Gamma-correct image.
1857 image_view=AcquireCacheView(image);
1858 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1859 #pragma omp parallel for schedule(static,4) shared(progress,status)
1861 for (y=0; y < (ssize_t) image->rows; y++)
1869 if (status == MagickFalse)
1871 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1872 if (q == (Quantum *) NULL)
1877 for (x=0; x < (ssize_t) image->columns; x++)
1882 if (GetPixelMask(image,q) != 0)
1884 q+=GetPixelChannels(image);
1887 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1895 channel=GetPixelChannelMapChannel(image,i);
1896 traits=GetPixelChannelMapTraits(image,channel);
1897 if ((traits & UpdatePixelTrait) == 0)
1899 q[i]=gamma_map[ScaleQuantumToMap(q[i])];
1901 q+=GetPixelChannels(image);
1903 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1905 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1910 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1911 #pragma omp critical (MagickCore_GammaImage)
1913 proceed=SetImageProgress(image,GammaCorrectImageTag,progress++,
1915 if (proceed == MagickFalse)
1919 image_view=DestroyCacheView(image_view);
1920 gamma_map=(Quantum *) RelinquishMagickMemory(gamma_map);
1921 if (image->gamma != 0.0)
1922 image->gamma*=gamma;
1927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1931 % H a l d C l u t I m a g e %
1935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1937 % HaldClutImage() applies a Hald color lookup table to the image. A Hald
1938 % color lookup table is a 3-dimensional color cube mapped to 2 dimensions.
1939 % Create it with the HALD coder. You can apply any color transformation to
1940 % the Hald image and then use this method to apply the transform to the
1943 % The format of the HaldClutImage method is:
1945 % MagickBooleanType HaldClutImage(Image *image,Image *hald_image,
1946 % ExceptionInfo *exception)
1948 % A description of each parameter follows:
1950 % o image: the image, which is replaced by indexed CLUT values
1952 % o hald_image: the color lookup table image for replacement color values.
1954 % o exception: return any errors or warnings in this structure.
1958 static inline size_t MagickMin(const size_t x,const size_t y)
1965 MagickExport MagickBooleanType HaldClutImage(Image *image,
1966 const Image *hald_image,ExceptionInfo *exception)
1968 #define HaldClutImageTag "Clut/Image"
1970 typedef struct _HaldInfo
2002 assert(image != (Image *) NULL);
2003 assert(image->signature == MagickSignature);
2004 if (image->debug != MagickFalse)
2005 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2006 assert(hald_image != (Image *) NULL);
2007 assert(hald_image->signature == MagickSignature);
2008 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2009 return(MagickFalse);
2010 if (image->matte == MagickFalse)
2011 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2017 length=MagickMin(hald_image->columns,hald_image->rows);
2018 for (level=2; (level*level*level) < length; level++) ;
2020 cube_size=level*level;
2021 width=(double) hald_image->columns;
2022 GetPixelInfo(hald_image,&zero);
2023 image_view=AcquireCacheView(image);
2024 hald_view=AcquireCacheView(hald_image);
2025 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2026 #pragma omp parallel for schedule(static,4) shared(progress,status)
2028 for (y=0; y < (ssize_t) image->rows; y++)
2036 if (status == MagickFalse)
2038 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2039 if (q == (Quantum *) NULL)
2044 for (x=0; x < (ssize_t) image->columns; x++)
2059 point.x=QuantumScale*(level-1.0)*GetPixelRed(image,q);
2060 point.y=QuantumScale*(level-1.0)*GetPixelGreen(image,q);
2061 point.z=QuantumScale*(level-1.0)*GetPixelBlue(image,q);
2062 offset=point.x+level*floor(point.y)+cube_size*floor(point.z);
2063 point.x-=floor(point.x);
2064 point.y-=floor(point.y);
2065 point.z-=floor(point.z);
2067 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2068 fmod(offset,width),floor(offset/width),&pixel1,exception);
2070 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2071 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2073 CompositePixelInfoAreaBlend(&pixel1,pixel1.alpha,&pixel2,pixel2.alpha,
2076 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2077 fmod(offset,width),floor(offset/width),&pixel1,exception);
2078 (void) InterpolatePixelInfo(image,hald_view,image->interpolate,
2079 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2081 CompositePixelInfoAreaBlend(&pixel1,pixel1.alpha,&pixel2,pixel2.alpha,
2084 CompositePixelInfoAreaBlend(&pixel3,pixel3.alpha,&pixel4,pixel4.alpha,
2086 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2087 SetPixelRed(image,ClampToQuantum(pixel.red),q);
2088 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2089 SetPixelGreen(image,ClampToQuantum(pixel.green),q);
2090 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2091 SetPixelBlue(image,ClampToQuantum(pixel.blue),q);
2092 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2093 (image->colorspace == CMYKColorspace))
2094 SetPixelBlack(image,ClampToQuantum(pixel.black),q);
2095 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2096 (image->matte != MagickFalse))
2097 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
2098 q+=GetPixelChannels(image);
2100 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2102 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2107 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2108 #pragma omp critical (MagickCore_HaldClutImage)
2110 proceed=SetImageProgress(image,HaldClutImageTag,progress++,image->rows);
2111 if (proceed == MagickFalse)
2115 hald_view=DestroyCacheView(hald_view);
2116 image_view=DestroyCacheView(image_view);
2121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125 % L e v e l I m a g e %
2129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2131 % LevelImage() adjusts the levels of a particular image channel by
2132 % scaling the colors falling between specified white and black points to
2133 % the full available quantum range.
2135 % The parameters provided represent the black, and white points. The black
2136 % point specifies the darkest color in the image. Colors darker than the
2137 % black point are set to zero. White point specifies the lightest color in
2138 % the image. Colors brighter than the white point are set to the maximum
2141 % If a '!' flag is given, map black and white colors to the given levels
2142 % rather than mapping those levels to black and white. See
2143 % LevelizeImage() below.
2145 % Gamma specifies a gamma correction to apply to the image.
2147 % The format of the LevelImage method is:
2149 % MagickBooleanType LevelImage(Image *image,const double black_point,
2150 % const double white_point,const double gamma,ExceptionInfo *exception)
2152 % A description of each parameter follows:
2154 % o image: the image.
2156 % o black_point: The level to map zero (black) to.
2158 % o white_point: The level to map QuantumRange (white) to.
2160 % o exception: return any errors or warnings in this structure.
2164 static inline MagickRealType LevelPixel(const double black_point,
2165 const double white_point,const double gamma,const MagickRealType pixel)
2171 if (pixel < black_point)
2173 if (pixel > white_point)
2174 return((MagickRealType) QuantumRange);
2175 scale=(white_point != black_point) ? 1.0/(white_point-black_point) : 1.0;
2176 level_pixel=(MagickRealType) QuantumRange*pow(scale*((double) pixel-
2177 black_point),1.0/gamma);
2178 return(level_pixel);
2181 MagickExport MagickBooleanType LevelImage(Image *image,const double black_point,
2182 const double white_point,const double gamma,ExceptionInfo *exception)
2184 #define LevelImageTag "Level/Image"
2202 Allocate and initialize levels map.
2204 assert(image != (Image *) NULL);
2205 assert(image->signature == MagickSignature);
2206 if (image->debug != MagickFalse)
2207 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2208 if (image->storage_class == PseudoClass)
2209 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2210 #pragma omp parallel for schedule(static,4) shared(progress,status)
2212 for (i=0; i < (ssize_t) image->colors; i++)
2217 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2218 image->colormap[i].red=(double) ClampToQuantum(LevelPixel(black_point,
2219 white_point,gamma,image->colormap[i].red));
2220 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2221 image->colormap[i].green=(double) ClampToQuantum(LevelPixel(black_point,
2222 white_point,gamma,image->colormap[i].green));
2223 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2224 image->colormap[i].blue=(double) ClampToQuantum(LevelPixel(black_point,
2225 white_point,gamma,image->colormap[i].blue));
2226 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2227 image->colormap[i].alpha=(double) ClampToQuantum(LevelPixel(black_point,
2228 white_point,gamma,image->colormap[i].alpha));
2235 image_view=AcquireCacheView(image);
2236 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2237 #pragma omp parallel for schedule(static,4) shared(progress,status)
2239 for (y=0; y < (ssize_t) image->rows; y++)
2247 if (status == MagickFalse)
2249 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2250 if (q == (Quantum *) NULL)
2255 for (x=0; x < (ssize_t) image->columns; x++)
2260 if (GetPixelMask(image,q) != 0)
2262 q+=GetPixelChannels(image);
2265 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2273 channel=GetPixelChannelMapChannel(image,i);
2274 traits=GetPixelChannelMapTraits(image,channel);
2275 if ((traits & UpdatePixelTrait) == 0)
2277 q[i]=ClampToQuantum(LevelPixel(black_point,white_point,gamma,
2278 (MagickRealType) q[i]));
2280 q+=GetPixelChannels(image);
2282 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2284 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2289 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2290 #pragma omp critical (MagickCore_LevelImage)
2292 proceed=SetImageProgress(image,LevelImageTag,progress++,image->rows);
2293 if (proceed == MagickFalse)
2297 image_view=DestroyCacheView(image_view);
2302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2306 % L e v e l i z e I m a g e %
2310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2312 % LevelizeImage() applies the reversed LevelImage() operation to just
2313 % the specific channels specified. It compresses the full range of color
2314 % values, so that they lie between the given black and white points. Gamma is
2315 % applied before the values are mapped.
2317 % LevelizeImage() can be called with by using a +level command line
2318 % API option, or using a '!' on a -level or LevelImage() geometry string.
2320 % It can be used to de-contrast a greyscale image to the exact levels
2321 % specified. Or by using specific levels for each channel of an image you
2322 % can convert a gray-scale image to any linear color gradient, according to
2325 % The format of the LevelizeImage method is:
2327 % MagickBooleanType LevelizeImage(Image *image,const double black_point,
2328 % const double white_point,const double gamma,ExceptionInfo *exception)
2330 % A description of each parameter follows:
2332 % o image: the image.
2334 % o black_point: The level to map zero (black) to.
2336 % o white_point: The level to map QuantumRange (white) to.
2338 % o gamma: adjust gamma by this factor before mapping values.
2340 % o exception: return any errors or warnings in this structure.
2343 MagickExport MagickBooleanType LevelizeImage(Image *image,
2344 const double black_point,const double white_point,const double gamma,
2345 ExceptionInfo *exception)
2347 #define LevelizeImageTag "Levelize/Image"
2348 #define LevelizeValue(x) (ClampToQuantum(((MagickRealType) \
2349 pow((double) (QuantumScale*(x)),1.0/gamma))*(white_point-black_point)+ \
2368 Allocate and initialize levels map.
2370 assert(image != (Image *) NULL);
2371 assert(image->signature == MagickSignature);
2372 if (image->debug != MagickFalse)
2373 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2374 if (image->storage_class == PseudoClass)
2375 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2376 #pragma omp parallel for schedule(static,4) shared(progress,status)
2378 for (i=0; i < (ssize_t) image->colors; i++)
2383 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2384 image->colormap[i].red=(double) LevelizeValue(
2385 image->colormap[i].red);
2386 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2387 image->colormap[i].green=(double) LevelizeValue(
2388 image->colormap[i].green);
2389 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2390 image->colormap[i].blue=(double) LevelizeValue(
2391 image->colormap[i].blue);
2392 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2393 image->colormap[i].alpha=(double) LevelizeValue(
2394 image->colormap[i].alpha);
2401 image_view=AcquireCacheView(image);
2402 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2403 #pragma omp parallel for schedule(static,4) shared(progress,status)
2405 for (y=0; y < (ssize_t) image->rows; y++)
2413 if (status == MagickFalse)
2415 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2416 if (q == (Quantum *) NULL)
2421 for (x=0; x < (ssize_t) image->columns; x++)
2426 if (GetPixelMask(image,q) != 0)
2428 q+=GetPixelChannels(image);
2431 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2439 channel=GetPixelChannelMapChannel(image,i);
2440 traits=GetPixelChannelMapTraits(image,channel);
2441 if ((traits & UpdatePixelTrait) == 0)
2443 q[i]=LevelizeValue(q[i]);
2445 q+=GetPixelChannels(image);
2447 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2449 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2454 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2455 #pragma omp critical (MagickCore_LevelizeImage)
2457 proceed=SetImageProgress(image,LevelizeImageTag,progress++,image->rows);
2458 if (proceed == MagickFalse)
2462 image_view=DestroyCacheView(image_view);
2467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2471 % L e v e l I m a g e C o l o r s %
2475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2477 % LevelImageColors() maps the given color to "black" and "white" values,
2478 % linearly spreading out the colors, and level values on a channel by channel
2479 % bases, as per LevelImage(). The given colors allows you to specify
2480 % different level ranges for each of the color channels separately.
2482 % If the boolean 'invert' is set true the image values will modifyed in the
2483 % reverse direction. That is any existing "black" and "white" colors in the
2484 % image will become the color values given, with all other values compressed
2485 % appropriatally. This effectivally maps a greyscale gradient into the given
2488 % The format of the LevelImageColors method is:
2490 % MagickBooleanType LevelImageColors(Image *image,
2491 % const PixelInfo *black_color,const PixelInfo *white_color,
2492 % const MagickBooleanType invert,ExceptionInfo *exception)
2494 % A description of each parameter follows:
2496 % o image: the image.
2498 % o black_color: The color to map black to/from
2500 % o white_point: The color to map white to/from
2502 % o invert: if true map the colors (levelize), rather than from (level)
2504 % o exception: return any errors or warnings in this structure.
2507 MagickExport MagickBooleanType LevelImageColors(Image *image,
2508 const PixelInfo *black_color,const PixelInfo *white_color,
2509 const MagickBooleanType invert,ExceptionInfo *exception)
2518 Allocate and initialize levels map.
2520 assert(image != (Image *) NULL);
2521 assert(image->signature == MagickSignature);
2522 if (image->debug != MagickFalse)
2523 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2525 if (invert == MagickFalse)
2527 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2529 channel_mask=SetPixelChannelMask(image,RedChannel);
2530 status|=LevelImage(image,black_color->red,white_color->red,1.0,
2532 (void) SetPixelChannelMask(image,channel_mask);
2534 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2536 channel_mask=SetPixelChannelMask(image,GreenChannel);
2537 status|=LevelImage(image,black_color->green,white_color->green,1.0,
2539 (void) SetPixelChannelMask(image,channel_mask);
2541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2543 channel_mask=SetPixelChannelMask(image,BlueChannel);
2544 status|=LevelImage(image,black_color->blue,white_color->blue,1.0,
2546 (void) SetPixelChannelMask(image,channel_mask);
2548 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2549 (image->colorspace == CMYKColorspace))
2551 channel_mask=SetPixelChannelMask(image,BlackChannel);
2552 status|=LevelImage(image,black_color->black,white_color->black,1.0,
2554 (void) SetPixelChannelMask(image,channel_mask);
2556 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2557 (image->matte == MagickTrue))
2559 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2560 status|=LevelImage(image,black_color->alpha,white_color->alpha,1.0,
2562 (void) SetPixelChannelMask(image,channel_mask);
2567 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2569 channel_mask=SetPixelChannelMask(image,RedChannel);
2570 status|=LevelizeImage(image,black_color->red,white_color->red,1.0,
2572 (void) SetPixelChannelMask(image,channel_mask);
2574 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2576 channel_mask=SetPixelChannelMask(image,GreenChannel);
2577 status|=LevelizeImage(image,black_color->green,white_color->green,1.0,
2579 (void) SetPixelChannelMask(image,channel_mask);
2581 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2583 channel_mask=SetPixelChannelMask(image,BlueChannel);
2584 status|=LevelizeImage(image,black_color->blue,white_color->blue,1.0,
2586 (void) SetPixelChannelMask(image,channel_mask);
2588 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2589 (image->colorspace == CMYKColorspace))
2591 channel_mask=SetPixelChannelMask(image,BlackChannel);
2592 status|=LevelizeImage(image,black_color->black,white_color->black,1.0,
2594 (void) SetPixelChannelMask(image,channel_mask);
2596 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2597 (image->matte == MagickTrue))
2599 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2600 status|=LevelizeImage(image,black_color->alpha,white_color->alpha,1.0,
2602 (void) SetPixelChannelMask(image,channel_mask);
2605 return(status == 0 ? MagickFalse : MagickTrue);
2609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2613 % L i n e a r S t r e t c h I m a g e %
2617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2619 % LinearStretchImage() discards any pixels below the black point and above
2620 % the white point and levels the remaining pixels.
2622 % The format of the LinearStretchImage method is:
2624 % MagickBooleanType LinearStretchImage(Image *image,
2625 % const double black_point,const double white_point,
2626 % ExceptionInfo *exception)
2628 % A description of each parameter follows:
2630 % o image: the image.
2632 % o black_point: the black point.
2634 % o white_point: the white point.
2636 % o exception: return any errors or warnings in this structure.
2639 MagickExport MagickBooleanType LinearStretchImage(Image *image,
2640 const double black_point,const double white_point,ExceptionInfo *exception)
2642 #define LinearStretchImageTag "LinearStretch/Image"
2660 Allocate histogram and linear map.
2662 assert(image != (Image *) NULL);
2663 assert(image->signature == MagickSignature);
2664 histogram=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
2665 sizeof(*histogram));
2666 if (histogram == (MagickRealType *) NULL)
2667 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
2672 (void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram));
2673 image_view=AcquireCacheView(image);
2674 for (y=0; y < (ssize_t) image->rows; y++)
2676 register const Quantum
2682 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2683 if (p == (const Quantum *) NULL)
2685 for (x=0; x < (ssize_t) image->columns; x++)
2687 histogram[ScaleQuantumToMap(GetPixelIntensity(image,p))]++;
2688 p+=GetPixelChannels(image);
2691 image_view=DestroyCacheView(image_view);
2693 Find the histogram boundaries by locating the black and white point levels.
2696 for (black=0; black < (ssize_t) MaxMap; black++)
2698 intensity+=histogram[black];
2699 if (intensity >= black_point)
2703 for (white=(ssize_t) MaxMap; white != 0; white--)
2705 intensity+=histogram[white];
2706 if (intensity >= white_point)
2709 histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
2710 status=LevelImage(image,(double) black,(double) white,1.0,exception);
2715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2719 % M o d u l a t e I m a g e %
2723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2725 % ModulateImage() lets you control the brightness, saturation, and hue
2726 % of an image. Modulate represents the brightness, saturation, and hue
2727 % as one parameter (e.g. 90,150,100). If the image colorspace is HSL, the
2728 % modulation is lightness, saturation, and hue. And if the colorspace is
2729 % HWB, use blackness, whiteness, and hue.
2731 % The format of the ModulateImage method is:
2733 % MagickBooleanType ModulateImage(Image *image,const char *modulate,
2734 % ExceptionInfo *exception)
2736 % A description of each parameter follows:
2738 % o image: the image.
2740 % o modulate: Define the percent change in brightness, saturation, and hue.
2742 % o exception: return any errors or warnings in this structure.
2746 static void ModulateHSB(const double percent_hue,
2747 const double percent_saturation,const double percent_brightness,double *red,
2748 double *green,double *blue)
2756 Increase or decrease color brightness, saturation, or hue.
2758 assert(red != (double *) NULL);
2759 assert(green != (double *) NULL);
2760 assert(blue != (double *) NULL);
2761 ConvertRGBToHSB(*red,*green,*blue,&hue,&saturation,&brightness);
2762 hue+=0.5*(0.01*percent_hue-1.0);
2767 saturation*=0.01*percent_saturation;
2768 brightness*=0.01*percent_brightness;
2769 ConvertHSBToRGB(hue,saturation,brightness,red,green,blue);
2772 static void ModulateHSL(const double percent_hue,
2773 const double percent_saturation,const double percent_lightness,double *red,
2774 double *green,double *blue)
2782 Increase or decrease color lightness, saturation, or hue.
2784 assert(red != (double *) NULL);
2785 assert(green != (double *) NULL);
2786 assert(blue != (double *) NULL);
2787 ConvertRGBToHSL(*red,*green,*blue,&hue,&saturation,&lightness);
2788 hue+=0.5*(0.01*percent_hue-1.0);
2793 saturation*=0.01*percent_saturation;
2794 lightness*=0.01*percent_lightness;
2795 ConvertHSLToRGB(hue,saturation,lightness,red,green,blue);
2798 static void ModulateHWB(const double percent_hue,const double percent_whiteness, const double percent_blackness,double *red,double *green,double *blue)
2806 Increase or decrease color blackness, whiteness, or hue.
2808 assert(red != (double *) NULL);
2809 assert(green != (double *) NULL);
2810 assert(blue != (double *) NULL);
2811 ConvertRGBToHWB(*red,*green,*blue,&hue,&whiteness,&blackness);
2812 hue+=0.5*(0.01*percent_hue-1.0);
2817 blackness*=0.01*percent_blackness;
2818 whiteness*=0.01*percent_whiteness;
2819 ConvertHWBToRGB(hue,whiteness,blackness,red,green,blue);
2822 MagickExport MagickBooleanType ModulateImage(Image *image,const char *modulate,
2823 ExceptionInfo *exception)
2825 #define ModulateImageTag "Modulate/Image"
2860 Initialize modulate table.
2862 assert(image != (Image *) NULL);
2863 assert(image->signature == MagickSignature);
2864 if (image->debug != MagickFalse)
2865 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2866 if (modulate == (char *) NULL)
2867 return(MagickFalse);
2868 flags=ParseGeometry(modulate,&geometry_info);
2869 percent_brightness=geometry_info.rho;
2870 percent_saturation=geometry_info.sigma;
2871 if ((flags & SigmaValue) == 0)
2872 percent_saturation=100.0;
2873 percent_hue=geometry_info.xi;
2874 if ((flags & XiValue) == 0)
2876 colorspace=UndefinedColorspace;
2877 artifact=GetImageArtifact(image,"modulate:colorspace");
2878 if (artifact != (const char *) NULL)
2879 colorspace=(ColorspaceType) ParseCommandOption(MagickColorspaceOptions,
2880 MagickFalse,artifact);
2881 if (image->storage_class == PseudoClass)
2886 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2887 #pragma omp parallel for schedule(static,4) shared(progress,status)
2889 for (i=0; i < (ssize_t) image->colors; i++)
2894 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
2895 &image->colormap[i].red,&image->colormap[i].green,
2896 &image->colormap[i].blue);
2902 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
2903 &image->colormap[i].red,&image->colormap[i].green,
2904 &image->colormap[i].blue);
2909 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
2910 &image->colormap[i].red,&image->colormap[i].green,
2911 &image->colormap[i].blue);
2921 image_view=AcquireCacheView(image);
2922 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2923 #pragma omp parallel for schedule(static,4) shared(progress,status)
2925 for (y=0; y < (ssize_t) image->rows; y++)
2938 if (status == MagickFalse)
2940 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2941 if (q == (Quantum *) NULL)
2946 for (x=0; x < (ssize_t) image->columns; x++)
2948 red=(double) GetPixelRed(image,q);
2949 green=(double) GetPixelGreen(image,q);
2950 blue=(double) GetPixelBlue(image,q);
2955 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
2962 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
2968 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
2973 SetPixelRed(image,ClampToQuantum(red),q);
2974 SetPixelGreen(image,ClampToQuantum(green),q);
2975 SetPixelBlue(image,ClampToQuantum(blue),q);
2976 q+=GetPixelChannels(image);
2978 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2980 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2985 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2986 #pragma omp critical (MagickCore_ModulateImage)
2988 proceed=SetImageProgress(image,ModulateImageTag,progress++,image->rows);
2989 if (proceed == MagickFalse)
2993 image_view=DestroyCacheView(image_view);
2998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3002 % N e g a t e I m a g e %
3006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3008 % NegateImage() negates the colors in the reference image. The grayscale
3009 % option means that only grayscale values within the image are negated.
3011 % The format of the NegateImage method is:
3013 % MagickBooleanType NegateImage(Image *image,
3014 % const MagickBooleanType grayscale,ExceptionInfo *exception)
3016 % A description of each parameter follows:
3018 % o image: the image.
3020 % o grayscale: If MagickTrue, only negate grayscale pixels within the image.
3022 % o exception: return any errors or warnings in this structure.
3025 MagickExport MagickBooleanType NegateImage(Image *image,
3026 const MagickBooleanType grayscale,ExceptionInfo *exception)
3028 #define NegateImageTag "Negate/Image"
3045 assert(image != (Image *) NULL);
3046 assert(image->signature == MagickSignature);
3047 if (image->debug != MagickFalse)
3048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3049 if (image->storage_class == PseudoClass)
3054 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3055 #pragma omp parallel for schedule(static) shared(progress,status)
3057 for (i=0; i < (ssize_t) image->colors; i++)
3059 if (grayscale != MagickFalse)
3060 if ((image->colormap[i].red != image->colormap[i].green) ||
3061 (image->colormap[i].green != image->colormap[i].blue))
3063 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
3064 image->colormap[i].red=(Quantum) QuantumRange-
3065 image->colormap[i].red;
3066 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
3067 image->colormap[i].green=(Quantum) QuantumRange-
3068 image->colormap[i].green;
3069 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
3070 image->colormap[i].blue=(Quantum) QuantumRange-
3071 image->colormap[i].blue;
3079 image_view=AcquireCacheView(image);
3080 if (grayscale != MagickFalse)
3082 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3083 #pragma omp parallel for schedule(static) shared(progress,status)
3085 for (y=0; y < (ssize_t) image->rows; y++)
3096 if (status == MagickFalse)
3098 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
3100 if (q == (Quantum *) NULL)
3105 for (x=0; x < (ssize_t) image->columns; x++)
3110 if ((GetPixelMask(image,q) != 0) ||
3111 (IsPixelGray(image,q) != MagickFalse))
3113 q+=GetPixelChannels(image);
3116 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3124 channel=GetPixelChannelMapChannel(image,i);
3125 traits=GetPixelChannelMapTraits(image,channel);
3126 if ((traits & UpdatePixelTrait) == 0)
3128 q[i]=QuantumRange-q[i];
3130 q+=GetPixelChannels(image);
3132 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3133 if (sync == MagickFalse)
3135 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3140 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3141 #pragma omp critical (MagickCore_NegateImage)
3143 proceed=SetImageProgress(image,NegateImageTag,progress++,
3145 if (proceed == MagickFalse)
3149 image_view=DestroyCacheView(image_view);
3155 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3156 #pragma omp parallel for schedule(static) shared(progress,status)
3158 for (y=0; y < (ssize_t) image->rows; y++)
3166 if (status == MagickFalse)
3168 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3169 if (q == (Quantum *) NULL)
3174 for (x=0; x < (ssize_t) image->columns; x++)
3179 if (GetPixelMask(image,q) != 0)
3181 q+=GetPixelChannels(image);
3184 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3192 channel=GetPixelChannelMapChannel(image,i);
3193 traits=GetPixelChannelMapTraits(image,channel);
3194 if ((traits & UpdatePixelTrait) == 0)
3196 q[i]=QuantumRange-q[i];
3198 q+=GetPixelChannels(image);
3200 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3202 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3207 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3208 #pragma omp critical (MagickCore_NegateImage)
3210 proceed=SetImageProgress(image,NegateImageTag,progress++,image->rows);
3211 if (proceed == MagickFalse)
3215 image_view=DestroyCacheView(image_view);
3220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3224 % N o r m a l i z e I m a g e %
3228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3230 % NormalizeImage() enhances the contrast of a color image by mapping the
3231 % darkest 2 percent of all pixel to black and the brightest 1 percent to white.
3233 % The format of the NormalizeImage method is:
3235 % MagickBooleanType NormalizeImage(Image *image,ExceptionInfo *exception)
3237 % A description of each parameter follows:
3239 % o image: the image.
3241 % o exception: return any errors or warnings in this structure.
3244 MagickExport MagickBooleanType NormalizeImage(Image *image,
3245 ExceptionInfo *exception)
3251 black_point=(double) image->columns*image->rows*0.0015;
3252 white_point=(double) image->columns*image->rows*0.9995;
3253 return(ContrastStretchImage(image,black_point,white_point,exception));
3257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3261 % S i g m o i d a l C o n t r a s t I m a g e %
3265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3267 % SigmoidalContrastImage() adjusts the contrast of an image with a non-linear
3268 % sigmoidal contrast algorithm. Increase the contrast of the image using a
3269 % sigmoidal transfer function without saturating highlights or shadows.
3270 % Contrast indicates how much to increase the contrast (0 is none; 3 is
3271 % typical; 20 is pushing it); mid-point indicates where threshold 'knee' of
3272 % the curve falls (typical 50% for mid-gray). Set sharpen to MagickTrue to
3273 % increase the image contrast otherwise the contrast is reduced.
3275 % The format of the SigmoidalContrastImage method is:
3277 % MagickBooleanType SigmoidalContrastImage(Image *image,
3278 % const MagickBooleanType sharpen,const char *levels,
3279 % ExceptionInfo *exception)
3281 % A description of each parameter follows:
3283 % o image: the image.
3285 % o sharpen: Increase or decrease image contrast.
3287 % o alpha: strength of the contrast, the larger the number the more
3288 % 'threshold-like' it becomes.
3290 % o beta: midpoint of the function as a color value 0 to QuantumRange.
3292 % o exception: return any errors or warnings in this structure.
3295 MagickExport MagickBooleanType SigmoidalContrastImage(Image *image,
3296 const MagickBooleanType sharpen,const double contrast,const double midpoint,
3297 ExceptionInfo *exception)
3299 #define SigmoidalContrastImageTag "SigmoidalContrast/Image"
3320 Allocate and initialize sigmoidal maps.
3322 assert(image != (Image *) NULL);
3323 assert(image->signature == MagickSignature);
3324 if (image->debug != MagickFalse)
3325 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3326 sigmoidal_map=(MagickRealType *) AcquireQuantumMemory(MaxMap+1UL,
3327 sizeof(*sigmoidal_map));
3328 if (sigmoidal_map == (MagickRealType *) NULL)
3329 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3331 (void) ResetMagickMemory(sigmoidal_map,0,(MaxMap+1)*sizeof(*sigmoidal_map));
3332 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3333 #pragma omp parallel for schedule(static) shared(progress,status)
3335 for (i=0; i <= (ssize_t) MaxMap; i++)
3337 if (sharpen != MagickFalse)
3339 sigmoidal_map[i]=(MagickRealType) ScaleMapToQuantum((MagickRealType)
3340 (MaxMap*((1.0/(1.0+exp(contrast*(midpoint/(double) QuantumRange-
3341 (double) i/MaxMap))))-(1.0/(1.0+exp(contrast*(midpoint/(double)
3342 QuantumRange)))))/((1.0/(1.0+exp(contrast*(midpoint/(double)
3343 QuantumRange-1.0))))-(1.0/(1.0+exp(contrast*(midpoint/(double)
3344 QuantumRange)))))+0.5));
3347 sigmoidal_map[i]=(MagickRealType) ScaleMapToQuantum((MagickRealType)
3348 (MaxMap*(QuantumScale*midpoint-log((1.0-(1.0/(1.0+exp(midpoint/(double)
3349 QuantumRange*contrast))+((double) i/MaxMap)*((1.0/(1.0+exp(contrast*(
3350 midpoint/(double) QuantumRange-1.0))))-(1.0/(1.0+exp(midpoint/(double)
3351 QuantumRange*contrast))))))/(1.0/(1.0+exp(midpoint/(double) QuantumRange*
3352 contrast))+((double) i/MaxMap)*((1.0/(1.0+exp(contrast*(midpoint/(double)
3353 QuantumRange-1.0))))-(1.0/(1.0+exp(midpoint/(double) QuantumRange*
3354 contrast))))))/contrast)));
3356 if (image->storage_class == PseudoClass)
3359 Sigmoidal-contrast enhance colormap.
3361 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3362 #pragma omp parallel for schedule(static,4) shared(progress,status)
3364 for (i=0; i < (ssize_t) image->colors; i++)
3366 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
3367 image->colormap[i].red=sigmoidal_map[ScaleQuantumToMap(
3368 ClampToQuantum(image->colormap[i].red))];
3369 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
3370 image->colormap[i].green=sigmoidal_map[ScaleQuantumToMap(
3371 ClampToQuantum(image->colormap[i].green))];
3372 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
3373 image->colormap[i].blue=sigmoidal_map[ScaleQuantumToMap(
3374 ClampToQuantum(image->colormap[i].blue))];
3375 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
3376 image->colormap[i].alpha=sigmoidal_map[ScaleQuantumToMap(
3377 ClampToQuantum(image->colormap[i].alpha))];
3381 Sigmoidal-contrast enhance image.
3385 image_view=AcquireCacheView(image);
3386 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3387 #pragma omp parallel for schedule(static,4) shared(progress,status)
3389 for (y=0; y < (ssize_t) image->rows; y++)
3397 if (status == MagickFalse)
3399 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3400 if (q == (Quantum *) NULL)
3405 for (x=0; x < (ssize_t) image->columns; x++)
3410 if (GetPixelMask(image,q) != 0)
3412 q+=GetPixelChannels(image);
3415 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3423 channel=GetPixelChannelMapChannel(image,i);
3424 traits=GetPixelChannelMapTraits(image,channel);
3425 if ((traits & UpdatePixelTrait) == 0)
3427 q[i]=ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(q[i])]);
3429 q+=GetPixelChannels(image);
3431 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3433 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3438 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3439 #pragma omp critical (MagickCore_SigmoidalContrastImage)
3441 proceed=SetImageProgress(image,SigmoidalContrastImageTag,progress++,
3443 if (proceed == MagickFalse)
3447 image_view=DestroyCacheView(image_view);
3448 sigmoidal_map=(MagickRealType *) RelinquishMagickMemory(sigmoidal_map);