2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects 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/annotate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/cache-view.h"
49 #include "MagickCore/color.h"
50 #include "MagickCore/color-private.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/decorate.h"
53 #include "MagickCore/distort.h"
54 #include "MagickCore/draw.h"
55 #include "MagickCore/effect.h"
56 #include "MagickCore/enhance.h"
57 #include "MagickCore/exception.h"
58 #include "MagickCore/exception-private.h"
59 #include "MagickCore/fx.h"
60 #include "MagickCore/fx-private.h"
61 #include "MagickCore/gem.h"
62 #include "MagickCore/gem-private.h"
63 #include "MagickCore/geometry.h"
64 #include "MagickCore/layer.h"
65 #include "MagickCore/list.h"
66 #include "MagickCore/log.h"
67 #include "MagickCore/image.h"
68 #include "MagickCore/image-private.h"
69 #include "MagickCore/magick.h"
70 #include "MagickCore/memory_.h"
71 #include "MagickCore/monitor.h"
72 #include "MagickCore/monitor-private.h"
73 #include "MagickCore/option.h"
74 #include "MagickCore/pixel.h"
75 #include "MagickCore/pixel-accessor.h"
76 #include "MagickCore/property.h"
77 #include "MagickCore/quantum.h"
78 #include "MagickCore/quantum-private.h"
79 #include "MagickCore/random_.h"
80 #include "MagickCore/random-private.h"
81 #include "MagickCore/resample.h"
82 #include "MagickCore/resample-private.h"
83 #include "MagickCore/resize.h"
84 #include "MagickCore/splay-tree.h"
85 #include "MagickCore/statistic.h"
86 #include "MagickCore/string_.h"
87 #include "MagickCore/string-private.h"
88 #include "MagickCore/thread-private.h"
89 #include "MagickCore/transform.h"
90 #include "MagickCore/utility.h"
95 #define LeftShiftOperator 0xf5
96 #define RightShiftOperator 0xf6
97 #define LessThanEqualOperator 0xf7
98 #define GreaterThanEqualOperator 0xf8
99 #define EqualOperator 0xf9
100 #define NotEqualOperator 0xfa
101 #define LogicalAndOperator 0xfb
102 #define LogicalOrOperator 0xfc
103 #define ExponentialNotation 0xfd
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 + A c q u i r e F x I n f o %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % AcquireFxInfo() allocates the FxInfo structure.
143 % The format of the AcquireFxInfo method is:
145 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
147 % A description of each parameter follows:
149 % o image: the image.
151 % o expression: the expression.
154 MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
168 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
169 if (fx_info == (FxInfo *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
172 fx_info->exception=AcquireExceptionInfo();
173 fx_info->images=image;
174 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
177 RelinquishMagickMemory);
178 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
179 fx_info->images),sizeof(*fx_info->view));
180 if (fx_info->view == (CacheView **) NULL)
181 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
183 next=GetFirstImageInList(fx_info->images);
184 for ( ; next != (Image *) NULL; next=next->next)
186 fx_info->view[i]=AcquireCacheView(next);
189 fx_info->random_info=AcquireRandomInfo();
190 fx_info->expression=ConstantString(expression);
191 fx_info->file=stderr;
192 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
194 Force right-to-left associativity for unary negation.
196 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
198 Convert complex to simple operators.
201 *fx_op=(char) LeftShiftOperator;
202 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
203 *fx_op=(char) RightShiftOperator;
204 (void) SubstituteString(&fx_info->expression,">>",fx_op);
205 *fx_op=(char) LessThanEqualOperator;
206 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
207 *fx_op=(char) GreaterThanEqualOperator;
208 (void) SubstituteString(&fx_info->expression,">=",fx_op);
209 *fx_op=(char) EqualOperator;
210 (void) SubstituteString(&fx_info->expression,"==",fx_op);
211 *fx_op=(char) NotEqualOperator;
212 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
213 *fx_op=(char) LogicalAndOperator;
214 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
215 *fx_op=(char) LogicalOrOperator;
216 (void) SubstituteString(&fx_info->expression,"||",fx_op);
217 *fx_op=(char) ExponentialNotation;
218 (void) SubstituteString(&fx_info->expression,"**",fx_op);
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 % A d d N o i s e I m a g e %
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 % AddNoiseImage() adds random noise to the image.
235 % The format of the AddNoiseImage method is:
237 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
238 % const double attenuate,ExceptionInfo *exception)
240 % A description of each parameter follows:
242 % o image: the image.
244 % o channel: the channel type.
246 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
247 % Impulse, Laplacian, or Poisson.
249 % o attenuate: attenuate the random distribution.
251 % o exception: return any errors or warnings in this structure.
254 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
255 const double attenuate,ExceptionInfo *exception)
257 #define AddNoiseImageTag "AddNoise/Image"
273 **restrict random_info;
279 Initialize noise image attributes.
281 assert(image != (const Image *) NULL);
282 assert(image->signature == MagickSignature);
283 if (image->debug != MagickFalse)
284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
285 assert(exception != (ExceptionInfo *) NULL);
286 assert(exception->signature == MagickSignature);
287 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
288 if (noise_image == (Image *) NULL)
289 return((Image *) NULL);
290 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
292 noise_image=DestroyImage(noise_image);
293 return((Image *) NULL);
296 Add noise in each row.
300 random_info=AcquireRandomInfoThreadSet();
301 image_view=AcquireCacheView(image);
302 noise_view=AcquireCacheView(noise_image);
303 #if defined(MAGICKCORE_OPENMP_SUPPORT)
304 #pragma omp parallel for schedule(static,4) shared(progress,status)
306 for (y=0; y < (ssize_t) image->rows; y++)
309 id = GetOpenMPThreadId();
314 register const Quantum
323 if (status == MagickFalse)
325 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
326 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
328 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
333 for (x=0; x < (ssize_t) image->columns; x++)
338 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
347 channel=GetPixelChannelMapChannel(image,i);
348 traits=GetPixelChannelMapTraits(image,channel);
349 noise_traits=GetPixelChannelMapTraits(noise_image,channel);
350 if ((traits == UndefinedPixelTrait) ||
351 (noise_traits == UndefinedPixelTrait))
353 if (((noise_traits & CopyPixelTrait) != 0) ||
354 (GetPixelMask(image,p) != 0))
356 SetPixelChannel(noise_image,channel,p[i],q);
359 SetPixelChannel(noise_image,channel,ClampToQuantum(
360 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
363 p+=GetPixelChannels(image);
364 q+=GetPixelChannels(noise_image);
366 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
367 if (sync == MagickFalse)
369 if (image->progress_monitor != (MagickProgressMonitor) NULL)
374 #if defined(MAGICKCORE_OPENMP_SUPPORT)
375 #pragma omp critical (MagickCore_AddNoiseImage)
377 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
379 if (proceed == MagickFalse)
383 noise_view=DestroyCacheView(noise_view);
384 image_view=DestroyCacheView(image_view);
385 random_info=DestroyRandomInfoThreadSet(random_info);
386 if (status == MagickFalse)
387 noise_image=DestroyImage(noise_image);
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 % B l u e S h i f t I m a g e %
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % BlueShiftImage() mutes the colors of the image to simulate a scene at
403 % nighttime in the moonlight.
405 % The format of the BlueShiftImage method is:
407 % Image *BlueShiftImage(const Image *image,const double factor,
408 % ExceptionInfo *exception)
410 % A description of each parameter follows:
412 % o image: the image.
414 % o factor: the shift factor.
416 % o exception: return any errors or warnings in this structure.
419 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
420 ExceptionInfo *exception)
422 #define BlueShiftImageTag "BlueShift/Image"
441 Allocate blue shift image.
443 assert(image != (const Image *) NULL);
444 assert(image->signature == MagickSignature);
445 if (image->debug != MagickFalse)
446 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
447 assert(exception != (ExceptionInfo *) NULL);
448 assert(exception->signature == MagickSignature);
449 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
450 if (shift_image == (Image *) NULL)
451 return((Image *) NULL);
452 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
454 shift_image=DestroyImage(shift_image);
455 return((Image *) NULL);
458 Blue-shift DirectClass image.
462 image_view=AcquireCacheView(image);
463 shift_view=AcquireCacheView(shift_image);
464 #if defined(MAGICKCORE_OPENMP_SUPPORT)
465 #pragma omp parallel for schedule(static,4) shared(progress,status)
467 for (y=0; y < (ssize_t) image->rows; y++)
478 register const Quantum
487 if (status == MagickFalse)
489 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
490 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
492 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
497 for (x=0; x < (ssize_t) image->columns; x++)
499 quantum=GetPixelRed(image,p);
500 if (GetPixelGreen(image,p) < quantum)
501 quantum=GetPixelGreen(image,p);
502 if (GetPixelBlue(image,p) < quantum)
503 quantum=GetPixelBlue(image,p);
504 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
505 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
506 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
507 quantum=GetPixelRed(image,p);
508 if (GetPixelGreen(image,p) > quantum)
509 quantum=GetPixelGreen(image,p);
510 if (GetPixelBlue(image,p) > quantum)
511 quantum=GetPixelBlue(image,p);
512 pixel.red=0.5*(pixel.red+factor*quantum);
513 pixel.green=0.5*(pixel.green+factor*quantum);
514 pixel.blue=0.5*(pixel.blue+factor*quantum);
515 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
516 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
517 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
518 p+=GetPixelChannels(image);
519 q+=GetPixelChannels(shift_image);
521 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
522 if (sync == MagickFalse)
524 if (image->progress_monitor != (MagickProgressMonitor) NULL)
529 #if defined(MAGICKCORE_OPENMP_SUPPORT)
530 #pragma omp critical (MagickCore_BlueShiftImage)
532 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
534 if (proceed == MagickFalse)
538 image_view=DestroyCacheView(image_view);
539 shift_view=DestroyCacheView(shift_view);
540 if (status == MagickFalse)
541 shift_image=DestroyImage(shift_image);
546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550 % C h a r c o a l I m a g e %
554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556 % CharcoalImage() creates a new image that is a copy of an existing one with
557 % the edge highlighted. It allocates the memory necessary for the new Image
558 % structure and returns a pointer to the new image.
560 % The format of the CharcoalImage method is:
562 % Image *CharcoalImage(const Image *image,const double radius,
563 % const double sigma,const double bias,ExceptionInfo *exception)
565 % A description of each parameter follows:
567 % o image: the image.
569 % o radius: the radius of the pixel neighborhood.
571 % o sigma: the standard deviation of the Gaussian, in pixels.
575 % o exception: return any errors or warnings in this structure.
578 MagickExport Image *CharcoalImage(const Image *image,const double radius,
579 const double sigma,const double bias,ExceptionInfo *exception)
586 assert(image != (Image *) NULL);
587 assert(image->signature == MagickSignature);
588 if (image->debug != MagickFalse)
589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
590 assert(exception != (ExceptionInfo *) NULL);
591 assert(exception->signature == MagickSignature);
592 clone_image=CloneImage(image,0,0,MagickTrue,exception);
593 if (clone_image == (Image *) NULL)
594 return((Image *) NULL);
595 (void) SetImageType(clone_image,GrayscaleType,exception);
596 edge_image=EdgeImage(clone_image,radius,sigma,exception);
597 clone_image=DestroyImage(clone_image);
598 if (edge_image == (Image *) NULL)
599 return((Image *) NULL);
600 charcoal_image=BlurImage(edge_image,radius,sigma,bias,exception);
601 edge_image=DestroyImage(edge_image);
602 if (charcoal_image == (Image *) NULL)
603 return((Image *) NULL);
604 (void) NormalizeImage(charcoal_image,exception);
605 (void) NegateImage(charcoal_image,MagickFalse,exception);
606 (void) SetImageType(charcoal_image,GrayscaleType,exception);
607 return(charcoal_image);
611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
615 % C o l o r i z e I m a g e %
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 % ColorizeImage() blends the fill color with each pixel in the image.
622 % A percentage blend is specified with opacity. Control the application
623 % of different color components by specifying a different percentage for
624 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
626 % The format of the ColorizeImage method is:
628 % Image *ColorizeImage(const Image *image,const char *blend,
629 % const PixelInfo *colorize,ExceptionInfo *exception)
631 % A description of each parameter follows:
633 % o image: the image.
635 % o blend: A character string indicating the level of blending as a
638 % o colorize: A color value.
640 % o exception: return any errors or warnings in this structure.
643 MagickExport Image *ColorizeImage(const Image *image,const char *blend,
644 const PixelInfo *colorize,ExceptionInfo *exception)
646 #define ColorizeImageTag "Colorize/Image"
674 Allocate colorized image.
676 assert(image != (const Image *) NULL);
677 assert(image->signature == MagickSignature);
678 if (image->debug != MagickFalse)
679 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
680 assert(exception != (ExceptionInfo *) NULL);
681 assert(exception->signature == MagickSignature);
682 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
684 if (colorize_image == (Image *) NULL)
685 return((Image *) NULL);
686 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
688 colorize_image=DestroyImage(colorize_image);
689 return((Image *) NULL);
691 if (blend == (const char *) NULL)
692 return(colorize_image);
694 Determine RGB values of the fill color for pixel
696 GetPixelInfo(image,&pixel);
697 flags=ParseGeometry(blend,&geometry_info);
698 pixel.red=geometry_info.rho;
699 pixel.green=geometry_info.rho;
700 pixel.blue=geometry_info.rho;
702 if ((flags & SigmaValue) != 0)
703 pixel.green=geometry_info.sigma;
704 if ((flags & XiValue) != 0)
705 pixel.blue=geometry_info.xi;
706 if ((flags & PsiValue) != 0)
707 pixel.alpha=geometry_info.psi;
708 if (pixel.colorspace == CMYKColorspace)
710 pixel.black=geometry_info.rho;
711 if ((flags & PsiValue) != 0)
712 pixel.black=geometry_info.psi;
713 if ((flags & ChiValue) != 0)
714 pixel.alpha=geometry_info.chi;
717 Colorize DirectClass image.
721 image_view=AcquireCacheView(image);
722 colorize_view=AcquireCacheView(colorize_image);
723 #if defined(MAGICKCORE_OPENMP_SUPPORT)
724 #pragma omp parallel for schedule(static,4) shared(progress,status)
726 for (y=0; y < (ssize_t) image->rows; y++)
731 register const Quantum
740 if (status == MagickFalse)
742 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
743 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
745 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
750 for (x=0; x < (ssize_t) image->columns; x++)
755 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
764 channel=GetPixelChannelMapChannel(image,i);
765 traits=GetPixelChannelMapTraits(image,channel);
766 colorize_traits=GetPixelChannelMapTraits(colorize_image,channel);
767 if ((traits == UndefinedPixelTrait) ||
768 (colorize_traits == UndefinedPixelTrait))
770 if (((colorize_traits & CopyPixelTrait) != 0) ||
771 (GetPixelMask(image,p) != 0))
773 SetPixelChannel(colorize_image,channel,p[i],q);
778 case RedPixelChannel:
780 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
781 (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q);
784 case GreenPixelChannel:
786 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
787 (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q);
790 case BluePixelChannel:
792 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
793 (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q);
796 case BlackPixelChannel:
798 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
799 (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q);
802 case AlphaPixelChannel:
804 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
805 (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q);
810 SetPixelChannel(colorize_image,channel,p[i],q);
815 p+=GetPixelChannels(image);
816 q+=GetPixelChannels(colorize_image);
818 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
819 if (sync == MagickFalse)
821 if (image->progress_monitor != (MagickProgressMonitor) NULL)
826 #if defined(MAGICKCORE_OPENMP_SUPPORT)
827 #pragma omp critical (MagickCore_ColorizeImage)
829 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
830 if (proceed == MagickFalse)
834 image_view=DestroyCacheView(image_view);
835 colorize_view=DestroyCacheView(colorize_view);
836 if (status == MagickFalse)
837 colorize_image=DestroyImage(colorize_image);
838 return(colorize_image);
842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 % C o l o r M a t r i x I m a g e %
850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
852 % ColorMatrixImage() applies color transformation to an image. This method
853 % permits saturation changes, hue rotation, luminance to alpha, and various
854 % other effects. Although variable-sized transformation matrices can be used,
855 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
856 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
857 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
858 % and offsets are normalized (divide Flash offset by 255).
860 % The format of the ColorMatrixImage method is:
862 % Image *ColorMatrixImage(const Image *image,
863 % const KernelInfo *color_matrix,ExceptionInfo *exception)
865 % A description of each parameter follows:
867 % o image: the image.
869 % o color_matrix: the color matrix.
871 % o exception: return any errors or warnings in this structure.
874 /* FUTURE: modify to make use of a MagickMatrix Mutliply function
875 That should be provided in "matrix.c"
876 (ASIDE: actually distorts should do this too but currently doesn't)
879 MagickExport Image *ColorMatrixImage(const Image *image,
880 const KernelInfo *color_matrix,ExceptionInfo *exception)
882 #define ColorMatrixImageTag "ColorMatrix/Image"
891 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
892 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
893 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
894 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
895 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
896 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
917 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
919 assert(image != (Image *) NULL);
920 assert(image->signature == MagickSignature);
921 if (image->debug != MagickFalse)
922 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
923 assert(exception != (ExceptionInfo *) NULL);
924 assert(exception->signature == MagickSignature);
926 for (v=0; v < (ssize_t) color_matrix->height; v++)
927 for (u=0; u < (ssize_t) color_matrix->width; u++)
929 if ((v < 6) && (u < 6))
930 ColorMatrix[v][u]=color_matrix->values[i];
934 Initialize color image.
936 color_image=CloneImage(image,0,0,MagickTrue,exception);
937 if (color_image == (Image *) NULL)
938 return((Image *) NULL);
939 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
941 color_image=DestroyImage(color_image);
942 return((Image *) NULL);
944 if (image->debug != MagickFalse)
947 format[MaxTextExtent],
950 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
951 " ColorMatrix image with color matrix:");
952 message=AcquireString("");
953 for (v=0; v < 6; v++)
956 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
957 (void) ConcatenateString(&message,format);
958 for (u=0; u < 6; u++)
960 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
962 (void) ConcatenateString(&message,format);
964 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
966 message=DestroyString(message);
969 Apply the ColorMatrix to image.
973 image_view=AcquireCacheView(image);
974 color_view=AcquireCacheView(color_image);
975 #if defined(MAGICKCORE_OPENMP_SUPPORT)
976 #pragma omp parallel for schedule(static,4) shared(progress,status)
978 for (y=0; y < (ssize_t) image->rows; y++)
983 register const Quantum
992 if (status == MagickFalse)
994 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
995 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
997 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1002 for (x=0; x < (ssize_t) image->columns; x++)
1010 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
1011 for (v=0; v < (ssize_t) height; v++)
1013 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
1014 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
1015 if (image->colorspace == CMYKColorspace)
1016 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
1017 if (image->matte != MagickFalse)
1018 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1019 pixel+=QuantumRange*ColorMatrix[v][5];
1022 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1023 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1024 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
1027 if (image->colorspace == CMYKColorspace)
1028 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
1033 if (image->matte != MagickFalse)
1034 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
1039 p+=GetPixelChannels(image);
1040 q+=GetPixelChannels(color_image);
1042 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1044 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1049 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1050 #pragma omp critical (MagickCore_ColorMatrixImage)
1052 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1054 if (proceed == MagickFalse)
1058 color_view=DestroyCacheView(color_view);
1059 image_view=DestroyCacheView(image_view);
1060 if (status == MagickFalse)
1061 color_image=DestroyImage(color_image);
1062 return(color_image);
1066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1070 + D e s t r o y F x I n f o %
1074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1076 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1078 % The format of the DestroyFxInfo method is:
1080 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1082 % A description of each parameter follows:
1084 % o fx_info: the fx info.
1087 MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
1092 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1093 fx_info->expression=DestroyString(fx_info->expression);
1094 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1095 fx_info->colors=DestroySplayTree(fx_info->colors);
1096 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1097 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1098 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1099 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1100 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1109 + F x E v a l u a t e C h a n n e l E x p r e s s i o n %
1113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115 % FxEvaluateChannelExpression() evaluates an expression and returns the
1118 % The format of the FxEvaluateExpression method is:
1120 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1121 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1122 % MagickRealType *alpha,Exceptioninfo *exception)
1123 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1124 % MagickRealType *alpha,Exceptioninfo *exception)
1126 % A description of each parameter follows:
1128 % o fx_info: the fx info.
1130 % o channel: the channel.
1132 % o x,y: the pixel position.
1134 % o alpha: the result.
1136 % o exception: return any errors or warnings in this structure.
1140 static inline double MagickMax(const double x,const double y)
1147 static inline double MagickMin(const double x,const double y)
1154 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1155 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1159 statistic[MaxTextExtent];
1167 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1169 switch (*++p) /* e.g. depth.r */
1171 case 'r': channel=RedPixelChannel; break;
1172 case 'g': channel=GreenPixelChannel; break;
1173 case 'b': channel=BluePixelChannel; break;
1174 case 'c': channel=CyanPixelChannel; break;
1175 case 'm': channel=MagentaPixelChannel; break;
1176 case 'y': channel=YellowPixelChannel; break;
1177 case 'k': channel=BlackPixelChannel; break;
1180 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1181 (double) channel,symbol);
1182 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1183 if (value != (const char *) NULL)
1184 return(QuantumScale*StringToDouble(value,(char **) NULL));
1185 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1186 if (LocaleNCompare(symbol,"depth",5) == 0)
1191 depth=GetImageDepth(image,exception);
1192 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1194 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1200 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1201 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1203 if (LocaleNCompare(symbol,"maxima",6) == 0)
1209 (void) GetImageRange(image,&minima,&maxima,exception);
1210 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1212 if (LocaleNCompare(symbol,"mean",4) == 0)
1218 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1219 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1221 if (LocaleNCompare(symbol,"minima",6) == 0)
1227 (void) GetImageRange(image,&minima,&maxima,exception);
1228 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1230 if (LocaleNCompare(symbol,"skewness",8) == 0)
1236 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1237 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1239 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1245 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1246 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1247 standard_deviation);
1249 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1250 ConstantString(statistic));
1251 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
1254 static MagickRealType
1255 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1256 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1258 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1261 return(FxGCD(beta,alpha % beta));
1265 static inline const char *FxSubexpression(const char *expression,
1266 ExceptionInfo *exception)
1275 subexpression=expression;
1276 while ((*subexpression != '\0') &&
1277 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1279 if (strchr("(",(int) *subexpression) != (char *) NULL)
1282 if (strchr(")",(int) *subexpression) != (char *) NULL)
1286 if (*subexpression == '\0')
1287 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1288 "UnbalancedParenthesis","`%s'",expression);
1289 return(subexpression);
1292 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1293 const ssize_t x,const ssize_t y,const char *expression,
1294 ExceptionInfo *exception)
1298 subexpression[MaxTextExtent],
1299 symbol[MaxTextExtent];
1326 i=GetImageIndexInList(fx_info->images);
1330 if (isalpha((int) *(p+1)) == 0)
1332 if (strchr("suv",(int) *p) != (char *) NULL)
1339 i=GetImageIndexInList(fx_info->images);
1342 case 'u': i=0; break;
1343 case 'v': i=1; break;
1350 for (p++; *p != '\0'; )
1364 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1366 i=(ssize_t) (alpha+0.5);
1372 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1379 for (p++; *p != '\0'; )
1393 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1404 for (p++; *p != '\0'; )
1418 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1428 length=GetImageListLength(fx_info->images);
1430 i+=(ssize_t) length;
1432 image=GetImageFromList(fx_info->images,i);
1433 if (image == (Image *) NULL)
1435 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1436 "NoSuchImage","`%s'",expression);
1439 GetPixelInfo(image,&pixel);
1440 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1441 point.x,point.y,&pixel,exception);
1442 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1443 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
1444 (LocaleCompare(p,"saturation") != 0) &&
1445 (LocaleCompare(p,"lightness") != 0))
1448 name[MaxTextExtent];
1450 (void) CopyMagickString(name,p,MaxTextExtent);
1451 for (q=name+(strlen(name)-1); q > name; q--)
1461 if ((strlen(name) > 2) &&
1462 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1467 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1468 if (color != (PixelInfo *) NULL)
1478 status=QueryColorCompliance(name,AllCompliance,&pixel,
1479 fx_info->exception);
1480 if (status != MagickFalse)
1482 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1483 name),ClonePixelInfo(&pixel));
1489 (void) CopyMagickString(symbol,p,MaxTextExtent);
1490 StripString(symbol);
1491 if (*symbol == '\0')
1495 case RedPixelChannel: return(QuantumScale*pixel.red);
1496 case GreenPixelChannel: return(QuantumScale*pixel.green);
1497 case BluePixelChannel: return(QuantumScale*pixel.blue);
1498 case BlackPixelChannel:
1500 if (image->colorspace != CMYKColorspace)
1502 (void) ThrowMagickException(exception,GetMagickModule(),
1503 ImageError,"ColorSeparatedImageRequired","`%s'",
1507 return(QuantumScale*pixel.black);
1509 case AlphaPixelChannel:
1514 if (pixel.matte == MagickFalse)
1516 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1519 case IndexPixelChannel:
1521 case IntensityPixelChannel:
1523 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1528 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1529 "UnableToParseExpression","`%s'",p);
1537 if (LocaleCompare(symbol,"a") == 0)
1538 return((MagickRealType) (QuantumScale*pixel.alpha));
1544 if (LocaleCompare(symbol,"b") == 0)
1545 return(QuantumScale*pixel.blue);
1551 if (LocaleNCompare(symbol,"channel",7) == 0)
1559 flags=ParseGeometry(symbol+7,&channel_info);
1560 if (image->colorspace == CMYKColorspace)
1563 case CyanPixelChannel:
1565 if ((flags & RhoValue) == 0)
1567 return(channel_info.rho);
1569 case MagentaPixelChannel:
1571 if ((flags & SigmaValue) == 0)
1573 return(channel_info.sigma);
1575 case YellowPixelChannel:
1577 if ((flags & XiValue) == 0)
1579 return(channel_info.xi);
1581 case BlackPixelChannel:
1583 if ((flags & PsiValue) == 0)
1585 return(channel_info.psi);
1587 case AlphaPixelChannel:
1589 if ((flags & ChiValue) == 0)
1591 return(channel_info.chi);
1598 case RedPixelChannel:
1600 if ((flags & RhoValue) == 0)
1602 return(channel_info.rho);
1604 case GreenPixelChannel:
1606 if ((flags & SigmaValue) == 0)
1608 return(channel_info.sigma);
1610 case BluePixelChannel:
1612 if ((flags & XiValue) == 0)
1614 return(channel_info.xi);
1616 case BlackPixelChannel:
1618 if ((flags & ChiValue) == 0)
1620 return(channel_info.chi);
1622 case AlphaPixelChannel:
1624 if ((flags & PsiValue) == 0)
1626 return(channel_info.psi);
1633 if (LocaleCompare(symbol,"c") == 0)
1634 return(QuantumScale*pixel.red);
1640 if (LocaleNCompare(symbol,"depth",5) == 0)
1641 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1647 if (LocaleCompare(symbol,"g") == 0)
1648 return(QuantumScale*pixel.green);
1654 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1655 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1656 if (LocaleCompare(symbol,"k") == 0)
1658 if (image->colorspace != CMYKColorspace)
1660 (void) ThrowMagickException(exception,GetMagickModule(),
1661 OptionError,"ColorSeparatedImageRequired","`%s'",
1665 return(QuantumScale*pixel.black);
1672 if (LocaleCompare(symbol,"h") == 0)
1673 return((MagickRealType) image->rows);
1674 if (LocaleCompare(symbol,"hue") == 0)
1681 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1690 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1691 (LocaleCompare(symbol,"image.minima") == 0) ||
1692 (LocaleCompare(symbol,"image.maxima") == 0) ||
1693 (LocaleCompare(symbol,"image.mean") == 0) ||
1694 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1695 (LocaleCompare(symbol,"image.skewness") == 0) ||
1696 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1697 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1698 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1699 return(image->resolution.x);
1700 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1701 return(image->resolution.y);
1702 if (LocaleCompare(symbol,"intensity") == 0)
1703 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1704 if (LocaleCompare(symbol,"i") == 0)
1705 return((MagickRealType) x);
1711 if (LocaleCompare(symbol,"j") == 0)
1712 return((MagickRealType) y);
1718 if (LocaleCompare(symbol,"lightness") == 0)
1725 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1729 if (LocaleCompare(symbol,"luminance") == 0)
1734 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1735 return(QuantumScale*luminence);
1742 if (LocaleNCompare(symbol,"maxima",6) == 0)
1743 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1744 if (LocaleNCompare(symbol,"mean",4) == 0)
1745 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1746 if (LocaleNCompare(symbol,"minima",6) == 0)
1747 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1748 if (LocaleCompare(symbol,"m") == 0)
1749 return(QuantumScale*pixel.blue);
1755 if (LocaleCompare(symbol,"n") == 0)
1756 return((MagickRealType) GetImageListLength(fx_info->images));
1762 if (LocaleCompare(symbol,"o") == 0)
1763 return(QuantumScale*pixel.alpha);
1769 if (LocaleCompare(symbol,"page.height") == 0)
1770 return((MagickRealType) image->page.height);
1771 if (LocaleCompare(symbol,"page.width") == 0)
1772 return((MagickRealType) image->page.width);
1773 if (LocaleCompare(symbol,"page.x") == 0)
1774 return((MagickRealType) image->page.x);
1775 if (LocaleCompare(symbol,"page.y") == 0)
1776 return((MagickRealType) image->page.y);
1782 if (LocaleCompare(symbol,"resolution.x") == 0)
1783 return(image->resolution.x);
1784 if (LocaleCompare(symbol,"resolution.y") == 0)
1785 return(image->resolution.y);
1786 if (LocaleCompare(symbol,"r") == 0)
1787 return(QuantumScale*pixel.red);
1793 if (LocaleCompare(symbol,"saturation") == 0)
1800 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1804 if (LocaleNCompare(symbol,"skewness",8) == 0)
1805 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1806 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1807 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1813 if (LocaleCompare(symbol,"t") == 0)
1814 return((MagickRealType) GetImageIndexInList(fx_info->images));
1820 if (LocaleCompare(symbol,"w") == 0)
1821 return((MagickRealType) image->columns);
1827 if (LocaleCompare(symbol,"y") == 0)
1828 return(QuantumScale*pixel.green);
1834 if (LocaleCompare(symbol,"z") == 0)
1839 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1847 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1848 if (value != (const char *) NULL)
1849 return((MagickRealType) StringToDouble(value,(char **) NULL));
1850 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1851 "UnableToParseExpression","`%s'",symbol);
1855 static const char *FxOperatorPrecedence(const char *expression,
1856 ExceptionInfo *exception)
1860 UndefinedPrecedence,
1862 BitwiseComplementPrecedence,
1864 ExponentialNotationPrecedence,
1868 RelationalPrecedence,
1869 EquivalencyPrecedence,
1870 BitwiseAndPrecedence,
1871 BitwiseOrPrecedence,
1872 LogicalAndPrecedence,
1873 LogicalOrPrecedence,
1875 AssignmentPrecedence,
1895 subexpression=(const char *) NULL;
1896 target=NullPrecedence;
1897 while (*expression != '\0')
1899 precedence=UndefinedPrecedence;
1900 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1905 switch (*expression)
1910 #if defined(MAGICKCORE_HAVE_ACOSH)
1911 if (LocaleNCompare(expression,"acosh",5) == 0)
1917 #if defined(MAGICKCORE_HAVE_ASINH)
1918 if (LocaleNCompare(expression,"asinh",5) == 0)
1924 #if defined(MAGICKCORE_HAVE_ATANH)
1925 if (LocaleNCompare(expression,"atanh",5) == 0)
1936 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1937 (LocaleNCompare(expression,"E-",2) == 0))
1939 expression+=2; /* scientific notation */
1946 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1947 (LocaleNCompare(expression,"j1",2) == 0))
1956 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1963 if ((c == (int) '{') || (c == (int) '['))
1966 if ((c == (int) '}') || (c == (int) ']'))
1969 switch ((unsigned char) *expression)
1974 precedence=BitwiseComplementPrecedence;
1980 precedence=ExponentPrecedence;
1985 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1986 (strchr(")",c) != (char *) NULL))) &&
1987 (((islower((int) ((char) *expression)) != 0) ||
1988 (strchr("(",(int) *expression) != (char *) NULL)) ||
1989 ((isdigit((int) ((char) c)) == 0) &&
1990 (isdigit((int) ((char) *expression)) != 0))) &&
1991 (strchr("xy",(int) *expression) == (char *) NULL))
1992 precedence=MultiplyPrecedence;
1999 precedence=MultiplyPrecedence;
2005 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2007 precedence=AdditionPrecedence;
2010 case LeftShiftOperator:
2011 case RightShiftOperator:
2013 precedence=ShiftPrecedence;
2017 case LessThanEqualOperator:
2018 case GreaterThanEqualOperator:
2021 precedence=RelationalPrecedence;
2025 case NotEqualOperator:
2027 precedence=EquivalencyPrecedence;
2032 precedence=BitwiseAndPrecedence;
2037 precedence=BitwiseOrPrecedence;
2040 case LogicalAndOperator:
2042 precedence=LogicalAndPrecedence;
2045 case LogicalOrOperator:
2047 precedence=LogicalOrPrecedence;
2050 case ExponentialNotation:
2052 precedence=ExponentialNotationPrecedence;
2058 precedence=TernaryPrecedence;
2063 precedence=AssignmentPrecedence;
2068 precedence=CommaPrecedence;
2073 precedence=SeparatorPrecedence;
2077 if ((precedence == BitwiseComplementPrecedence) ||
2078 (precedence == TernaryPrecedence) ||
2079 (precedence == AssignmentPrecedence))
2081 if (precedence > target)
2084 Right-to-left associativity.
2087 subexpression=expression;
2091 if (precedence >= target)
2094 Left-to-right associativity.
2097 subexpression=expression;
2099 if (strchr("(",(int) *expression) != (char *) NULL)
2100 expression=FxSubexpression(expression,exception);
2101 c=(int) (*expression++);
2103 return(subexpression);
2106 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2107 const PixelChannel channel,const ssize_t x,const ssize_t y,
2108 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2112 subexpression[MaxTextExtent];
2122 if (exception->severity != UndefinedException)
2124 while (isspace((int) *expression) != 0)
2126 if (*expression == '\0')
2128 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2129 "MissingExpression","`%s'",expression);
2132 *subexpression='\0';
2133 p=FxOperatorPrecedence(expression,exception);
2134 if (p != (const char *) NULL)
2136 (void) CopyMagickString(subexpression,expression,(size_t)
2138 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2140 switch ((unsigned char) *p)
2144 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2145 *beta=(MagickRealType) (~(size_t) *beta);
2150 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2151 return(*beta == 0.0 ? 1.0 : 0.0);
2155 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2156 channel,x,y,++p,beta,exception));
2160 case ExponentialNotation:
2162 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2163 return(alpha*(*beta));
2167 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2170 if (exception->severity == UndefinedException)
2171 (void) ThrowMagickException(exception,GetMagickModule(),
2172 OptionError,"DivideByZero","`%s'",expression);
2175 return(alpha/(*beta));
2179 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2180 *beta=fabs(floor(((double) *beta)+0.5));
2183 (void) ThrowMagickException(exception,GetMagickModule(),
2184 OptionError,"DivideByZero","`%s'",expression);
2187 return(fmod((double) alpha,(double) *beta));
2191 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2192 return(alpha+(*beta));
2196 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2197 return(alpha-(*beta));
2199 case LeftShiftOperator:
2201 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2202 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
2205 case RightShiftOperator:
2207 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2208 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
2213 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2214 return(alpha < *beta ? 1.0 : 0.0);
2216 case LessThanEqualOperator:
2218 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2219 return(alpha <= *beta ? 1.0 : 0.0);
2223 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2224 return(alpha > *beta ? 1.0 : 0.0);
2226 case GreaterThanEqualOperator:
2228 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2229 return(alpha >= *beta ? 1.0 : 0.0);
2233 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2234 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2236 case NotEqualOperator:
2238 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2239 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2243 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2244 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
2249 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2250 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
2253 case LogicalAndOperator:
2255 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2256 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2259 case LogicalOrOperator:
2261 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2262 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2270 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2272 p=StringToken(":",&q);
2273 if (q == (char *) NULL)
2275 (void) ThrowMagickException(exception,GetMagickModule(),
2276 OptionError,"UnableToParseExpression","`%s'",subexpression);
2279 if (fabs((double) alpha) > MagickEpsilon)
2280 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2282 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2288 numeric[MaxTextExtent];
2291 while (isalpha((int) ((unsigned char) *q)) != 0)
2295 (void) ThrowMagickException(exception,GetMagickModule(),
2296 OptionError,"UnableToParseExpression","`%s'",subexpression);
2299 ClearMagickException(exception);
2300 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2301 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2303 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2304 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2305 subexpression),ConstantString(numeric));
2310 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2315 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2320 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2326 if (strchr("(",(int) *expression) != (char *) NULL)
2328 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2329 subexpression[strlen(subexpression)-1]='\0';
2330 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2334 switch (*expression)
2338 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2344 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2350 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2352 return((MagickRealType) (~(size_t) (gamma+0.5)));
2357 if (LocaleNCompare(expression,"abs",3) == 0)
2359 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2361 return((MagickRealType) fabs((double) alpha));
2363 #if defined(MAGICKCORE_HAVE_ACOSH)
2364 if (LocaleNCompare(expression,"acosh",5) == 0)
2366 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2368 return((MagickRealType) acosh((double) alpha));
2371 if (LocaleNCompare(expression,"acos",4) == 0)
2373 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2375 return((MagickRealType) acos((double) alpha));
2377 #if defined(MAGICKCORE_HAVE_J1)
2378 if (LocaleNCompare(expression,"airy",4) == 0)
2380 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2384 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2385 return(gamma*gamma);
2388 #if defined(MAGICKCORE_HAVE_ASINH)
2389 if (LocaleNCompare(expression,"asinh",5) == 0)
2391 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2393 return((MagickRealType) asinh((double) alpha));
2396 if (LocaleNCompare(expression,"asin",4) == 0)
2398 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2400 return((MagickRealType) asin((double) alpha));
2402 if (LocaleNCompare(expression,"alt",3) == 0)
2404 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2406 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2408 if (LocaleNCompare(expression,"atan2",5) == 0)
2410 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2412 return((MagickRealType) atan2((double) alpha,(double) *beta));
2414 #if defined(MAGICKCORE_HAVE_ATANH)
2415 if (LocaleNCompare(expression,"atanh",5) == 0)
2417 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2419 return((MagickRealType) atanh((double) alpha));
2422 if (LocaleNCompare(expression,"atan",4) == 0)
2424 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2426 return((MagickRealType) atan((double) alpha));
2428 if (LocaleCompare(expression,"a") == 0)
2429 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2435 if (LocaleCompare(expression,"b") == 0)
2436 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2442 if (LocaleNCompare(expression,"ceil",4) == 0)
2444 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2446 return((MagickRealType) ceil((double) alpha));
2448 if (LocaleNCompare(expression,"cosh",4) == 0)
2450 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2452 return((MagickRealType) cosh((double) alpha));
2454 if (LocaleNCompare(expression,"cos",3) == 0)
2456 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2458 return((MagickRealType) cos((double) alpha));
2460 if (LocaleCompare(expression,"c") == 0)
2461 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2467 if (LocaleNCompare(expression,"debug",5) == 0)
2472 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2474 if (fx_info->images->colorspace == CMYKColorspace)
2477 case CyanPixelChannel: type="cyan"; break;
2478 case MagentaPixelChannel: type="magenta"; break;
2479 case YellowPixelChannel: type="yellow"; break;
2480 case AlphaPixelChannel: type="opacity"; break;
2481 case BlackPixelChannel: type="black"; break;
2482 default: type="unknown"; break;
2487 case RedPixelChannel: type="red"; break;
2488 case GreenPixelChannel: type="green"; break;
2489 case BluePixelChannel: type="blue"; break;
2490 case AlphaPixelChannel: type="opacity"; break;
2491 default: type="unknown"; break;
2493 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2494 if (strlen(subexpression) > 1)
2495 subexpression[strlen(subexpression)-1]='\0';
2496 if (fx_info->file != (FILE *) NULL)
2497 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2498 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2499 subexpression,GetMagickPrecision(),(double) alpha);
2502 if (LocaleNCompare(expression,"drc",3) == 0)
2504 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2506 return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0)));
2513 if (LocaleCompare(expression,"epsilon") == 0)
2514 return((MagickRealType) MagickEpsilon);
2515 if (LocaleNCompare(expression,"exp",3) == 0)
2517 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2519 return((MagickRealType) exp((double) alpha));
2521 if (LocaleCompare(expression,"e") == 0)
2522 return((MagickRealType) 2.7182818284590452354);
2528 if (LocaleNCompare(expression,"floor",5) == 0)
2530 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2532 return((MagickRealType) floor((double) alpha));
2539 if (LocaleNCompare(expression,"gauss",5) == 0)
2541 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2543 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2544 return((MagickRealType) gamma);
2546 if (LocaleNCompare(expression,"gcd",3) == 0)
2551 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2553 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2555 return((MagickRealType) gcd);
2557 if (LocaleCompare(expression,"g") == 0)
2558 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2564 if (LocaleCompare(expression,"h") == 0)
2565 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2566 if (LocaleCompare(expression,"hue") == 0)
2567 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2568 if (LocaleNCompare(expression,"hypot",5) == 0)
2570 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2572 return((MagickRealType) hypot((double) alpha,(double) *beta));
2579 if (LocaleCompare(expression,"k") == 0)
2580 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2586 if (LocaleCompare(expression,"intensity") == 0)
2587 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2588 if (LocaleNCompare(expression,"int",3) == 0)
2590 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2592 return((MagickRealType) floor(alpha));
2594 #if defined(MAGICKCORE_HAVE_ISNAN)
2595 if (LocaleNCompare(expression,"isnan",5) == 0)
2597 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2599 return((MagickRealType) !!isnan((double) alpha));
2602 if (LocaleCompare(expression,"i") == 0)
2603 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2609 if (LocaleCompare(expression,"j") == 0)
2610 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2611 #if defined(MAGICKCORE_HAVE_J0)
2612 if (LocaleNCompare(expression,"j0",2) == 0)
2614 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2616 return((MagickRealType) j0((double) alpha));
2619 #if defined(MAGICKCORE_HAVE_J1)
2620 if (LocaleNCompare(expression,"j1",2) == 0)
2622 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2624 return((MagickRealType) j1((double) alpha));
2627 #if defined(MAGICKCORE_HAVE_J1)
2628 if (LocaleNCompare(expression,"jinc",4) == 0)
2630 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2634 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
2644 if (LocaleNCompare(expression,"ln",2) == 0)
2646 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2648 return((MagickRealType) log((double) alpha));
2650 if (LocaleNCompare(expression,"logtwo",6) == 0)
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2654 return((MagickRealType) log10((double) alpha))/log10(2.0);
2656 if (LocaleNCompare(expression,"log",3) == 0)
2658 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2660 return((MagickRealType) log10((double) alpha));
2662 if (LocaleCompare(expression,"lightness") == 0)
2663 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2669 if (LocaleCompare(expression,"MaxRGB") == 0)
2670 return((MagickRealType) QuantumRange);
2671 if (LocaleNCompare(expression,"maxima",6) == 0)
2673 if (LocaleNCompare(expression,"max",3) == 0)
2675 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2677 return(alpha > *beta ? alpha : *beta);
2679 if (LocaleNCompare(expression,"minima",6) == 0)
2681 if (LocaleNCompare(expression,"min",3) == 0)
2683 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2685 return(alpha < *beta ? alpha : *beta);
2687 if (LocaleNCompare(expression,"mod",3) == 0)
2689 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2691 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2694 if (LocaleCompare(expression,"m") == 0)
2695 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2701 if (LocaleNCompare(expression,"not",3) == 0)
2703 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2705 return((MagickRealType) (alpha < MagickEpsilon));
2707 if (LocaleCompare(expression,"n") == 0)
2708 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2714 if (LocaleCompare(expression,"Opaque") == 0)
2716 if (LocaleCompare(expression,"o") == 0)
2717 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2723 if (LocaleCompare(expression,"phi") == 0)
2724 return((MagickRealType) MagickPHI);
2725 if (LocaleCompare(expression,"pi") == 0)
2726 return((MagickRealType) MagickPI);
2727 if (LocaleNCompare(expression,"pow",3) == 0)
2729 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2731 return((MagickRealType) pow((double) alpha,(double) *beta));
2733 if (LocaleCompare(expression,"p") == 0)
2734 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2740 if (LocaleCompare(expression,"QuantumRange") == 0)
2741 return((MagickRealType) QuantumRange);
2742 if (LocaleCompare(expression,"QuantumScale") == 0)
2743 return((MagickRealType) QuantumScale);
2749 if (LocaleNCompare(expression,"rand",4) == 0)
2750 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2751 if (LocaleNCompare(expression,"round",5) == 0)
2753 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2755 return((MagickRealType) floor((double) alpha+0.5));
2757 if (LocaleCompare(expression,"r") == 0)
2758 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2764 if (LocaleCompare(expression,"saturation") == 0)
2765 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2766 if (LocaleNCompare(expression,"sign",4) == 0)
2768 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2770 return(alpha < 0.0 ? -1.0 : 1.0);
2772 if (LocaleNCompare(expression,"sinc",4) == 0)
2774 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2778 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2782 if (LocaleNCompare(expression,"sinh",4) == 0)
2784 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2786 return((MagickRealType) sinh((double) alpha));
2788 if (LocaleNCompare(expression,"sin",3) == 0)
2790 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2792 return((MagickRealType) sin((double) alpha));
2794 if (LocaleNCompare(expression,"sqrt",4) == 0)
2796 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2798 return((MagickRealType) sqrt((double) alpha));
2800 if (LocaleNCompare(expression,"squish",6) == 0)
2802 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2804 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2806 if (LocaleCompare(expression,"s") == 0)
2807 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2813 if (LocaleNCompare(expression,"tanh",4) == 0)
2815 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2817 return((MagickRealType) tanh((double) alpha));
2819 if (LocaleNCompare(expression,"tan",3) == 0)
2821 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2823 return((MagickRealType) tan((double) alpha));
2825 if (LocaleCompare(expression,"Transparent") == 0)
2827 if (LocaleNCompare(expression,"trunc",5) == 0)
2829 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2832 return((MagickRealType) floor((double) alpha));
2833 return((MagickRealType) ceil((double) alpha));
2835 if (LocaleCompare(expression,"t") == 0)
2836 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2842 if (LocaleCompare(expression,"u") == 0)
2843 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2849 if (LocaleCompare(expression,"v") == 0)
2850 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2856 if (LocaleNCompare(expression,"while",5) == 0)
2860 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2862 } while (fabs((double) alpha) >= MagickEpsilon);
2863 return((MagickRealType) *beta);
2865 if (LocaleCompare(expression,"w") == 0)
2866 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2872 if (LocaleCompare(expression,"y") == 0)
2873 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2879 if (LocaleCompare(expression,"z") == 0)
2880 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2886 q=(char *) expression;
2887 alpha=InterpretSiPrefixValue(expression,&q);
2888 if (q == expression)
2889 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2893 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2894 MagickRealType *alpha,ExceptionInfo *exception)
2899 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2904 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2905 MagickRealType *alpha,ExceptionInfo *exception)
2914 fx_info->file=(FILE *) NULL;
2915 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2921 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2922 const PixelChannel channel,const ssize_t x,const ssize_t y,
2923 MagickRealType *alpha,ExceptionInfo *exception)
2929 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2931 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2945 % FxImage() applies a mathematical expression to the specified image.
2947 % The format of the FxImage method is:
2949 % Image *FxImage(const Image *image,const char *expression,
2950 % ExceptionInfo *exception)
2952 % A description of each parameter follows:
2954 % o image: the image.
2956 % o expression: A mathematical expression.
2958 % o exception: return any errors or warnings in this structure.
2962 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2967 assert(fx_info != (FxInfo **) NULL);
2968 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2969 if (fx_info[i] != (FxInfo *) NULL)
2970 fx_info[i]=DestroyFxInfo(fx_info[i]);
2971 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2975 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2976 ExceptionInfo *exception)
2993 number_threads=GetOpenMPMaximumThreads();
2994 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2995 if (fx_info == (FxInfo **) NULL)
2996 return((FxInfo **) NULL);
2997 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2998 if (*expression != '@')
2999 fx_expression=ConstantString(expression);
3001 fx_expression=FileToString(expression+1,~0,exception);
3002 for (i=0; i < (ssize_t) number_threads; i++)
3004 fx_info[i]=AcquireFxInfo(image,fx_expression);
3005 if (fx_info[i] == (FxInfo *) NULL)
3006 return(DestroyFxThreadSet(fx_info));
3007 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
3009 fx_expression=DestroyString(fx_expression);
3013 MagickExport Image *FxImage(const Image *image,const char *expression,
3014 ExceptionInfo *exception)
3016 #define FxImageTag "Fx/Image"
3040 assert(image != (Image *) NULL);
3041 assert(image->signature == MagickSignature);
3042 if (image->debug != MagickFalse)
3043 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3044 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3045 if (fx_image == (Image *) NULL)
3046 return((Image *) NULL);
3047 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3049 fx_image=DestroyImage(fx_image);
3050 return((Image *) NULL);
3052 fx_info=AcquireFxThreadSet(image,expression,exception);
3053 if (fx_info == (FxInfo **) NULL)
3055 fx_image=DestroyImage(fx_image);
3056 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3058 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3059 if (status == MagickFalse)
3061 fx_image=DestroyImage(fx_image);
3062 fx_info=DestroyFxThreadSet(fx_info);
3063 return((Image *) NULL);
3070 image_view=AcquireCacheView(image);
3071 fx_view=AcquireCacheView(fx_image);
3072 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3073 #pragma omp parallel for schedule(static,4) shared(progress,status)
3075 for (y=0; y < (ssize_t) fx_image->rows; y++)
3078 id = GetOpenMPThreadId();
3080 register const Quantum
3089 if (status == MagickFalse)
3091 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3092 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3093 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3098 for (x=0; x < (ssize_t) fx_image->columns; x++)
3103 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3115 channel=GetPixelChannelMapChannel(image,i);
3116 traits=GetPixelChannelMapTraits(image,channel);
3117 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3118 if ((traits == UndefinedPixelTrait) ||
3119 (fx_traits == UndefinedPixelTrait))
3121 if (((fx_traits & CopyPixelTrait) != 0) ||
3122 (GetPixelMask(image,p) != 0))
3124 SetPixelChannel(fx_image,channel,p[i],q);
3128 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3130 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3132 p+=GetPixelChannels(image);
3133 q+=GetPixelChannels(fx_image);
3135 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3137 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3142 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3143 #pragma omp critical (MagickCore_FxImage)
3145 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3146 if (proceed == MagickFalse)
3150 fx_view=DestroyCacheView(fx_view);
3151 image_view=DestroyCacheView(image_view);
3152 fx_info=DestroyFxThreadSet(fx_info);
3153 if (status == MagickFalse)
3154 fx_image=DestroyImage(fx_image);
3159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3163 % I m p l o d e I m a g e %
3167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3169 % ImplodeImage() creates a new image that is a copy of an existing
3170 % one with the image pixels "implode" by the specified percentage. It
3171 % allocates the memory necessary for the new Image structure and returns a
3172 % pointer to the new image.
3174 % The format of the ImplodeImage method is:
3176 % Image *ImplodeImage(const Image *image,const double amount,
3177 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3179 % A description of each parameter follows:
3181 % o implode_image: Method ImplodeImage returns a pointer to the image
3182 % after it is implode. A null image is returned if there is a memory
3185 % o image: the image.
3187 % o amount: Define the extent of the implosion.
3189 % o method: the pixel interpolation method.
3191 % o exception: return any errors or warnings in this structure.
3194 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3195 const PixelInterpolateMethod method,ExceptionInfo *exception)
3197 #define ImplodeImageTag "Implode/Image"
3223 Initialize implode image attributes.
3225 assert(image != (Image *) NULL);
3226 assert(image->signature == MagickSignature);
3227 if (image->debug != MagickFalse)
3228 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3229 assert(exception != (ExceptionInfo *) NULL);
3230 assert(exception->signature == MagickSignature);
3231 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3233 if (implode_image == (Image *) NULL)
3234 return((Image *) NULL);
3235 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3237 implode_image=DestroyImage(implode_image);
3238 return((Image *) NULL);
3240 if (implode_image->background_color.alpha != OpaqueAlpha)
3241 implode_image->matte=MagickTrue;
3243 Compute scaling factor.
3247 center.x=0.5*image->columns;
3248 center.y=0.5*image->rows;
3250 if (image->columns > image->rows)
3251 scale.y=(double) image->columns/(double) image->rows;
3253 if (image->columns < image->rows)
3255 scale.x=(double) image->rows/(double) image->columns;
3263 image_view=AcquireCacheView(image);
3264 implode_view=AcquireCacheView(implode_image);
3265 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3266 #pragma omp parallel for schedule(static,4) shared(progress,status)
3268 for (y=0; y < (ssize_t) image->rows; y++)
3276 register const Quantum
3285 if (status == MagickFalse)
3287 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3288 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3290 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3295 delta.y=scale.y*(double) (y-center.y);
3296 for (x=0; x < (ssize_t) image->columns; x++)
3302 Determine if the pixel is within an ellipse.
3304 if (GetPixelMask(image,p) != 0)
3306 p+=GetPixelChannels(image);
3307 q+=GetPixelChannels(implode_image);
3310 delta.x=scale.x*(double) (x-center.x);
3311 distance=delta.x*delta.x+delta.y*delta.y;
3312 if (distance >= (radius*radius))
3313 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3322 channel=GetPixelChannelMapChannel(image,i);
3323 traits=GetPixelChannelMapTraits(image,channel);
3324 implode_traits=GetPixelChannelMapTraits(implode_image,channel);
3325 if ((traits == UndefinedPixelTrait) ||
3326 (implode_traits == UndefinedPixelTrait))
3328 SetPixelChannel(implode_image,channel,p[i],q);
3340 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3342 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3343 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3344 scale.y+center.y),q,exception);
3346 p+=GetPixelChannels(image);
3347 q+=GetPixelChannels(implode_image);
3349 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3351 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3356 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3357 #pragma omp critical (MagickCore_ImplodeImage)
3359 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3360 if (proceed == MagickFalse)
3364 implode_view=DestroyCacheView(implode_view);
3365 image_view=DestroyCacheView(image_view);
3366 if (status == MagickFalse)
3367 implode_image=DestroyImage(implode_image);
3368 return(implode_image);
3372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3376 % M o r p h I m a g e s %
3380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3382 % The MorphImages() method requires a minimum of two images. The first
3383 % image is transformed into the second by a number of intervening images
3384 % as specified by frames.
3386 % The format of the MorphImage method is:
3388 % Image *MorphImages(const Image *image,const size_t number_frames,
3389 % ExceptionInfo *exception)
3391 % A description of each parameter follows:
3393 % o image: the image.
3395 % o number_frames: Define the number of in-between image to generate.
3396 % The more in-between frames, the smoother the morph.
3398 % o exception: return any errors or warnings in this structure.
3401 MagickExport Image *MorphImages(const Image *image,
3402 const size_t number_frames,ExceptionInfo *exception)
3404 #define MorphImageTag "Morph/Image"
3420 register const Image
3430 Clone first frame in sequence.
3432 assert(image != (Image *) NULL);
3433 assert(image->signature == MagickSignature);
3434 if (image->debug != MagickFalse)
3435 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3436 assert(exception != (ExceptionInfo *) NULL);
3437 assert(exception->signature == MagickSignature);
3438 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3439 if (morph_images == (Image *) NULL)
3440 return((Image *) NULL);
3441 if (GetNextImageInList(image) == (Image *) NULL)
3446 for (i=1; i < (ssize_t) number_frames; i++)
3448 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3449 if (morph_image == (Image *) NULL)
3451 morph_images=DestroyImageList(morph_images);
3452 return((Image *) NULL);
3454 AppendImageToList(&morph_images,morph_image);
3455 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3460 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3462 if (proceed == MagickFalse)
3466 return(GetFirstImageInList(morph_images));
3469 Morph image sequence.
3474 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3476 for (i=0; i < (ssize_t) number_frames; i++)
3482 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3484 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3485 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3486 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3487 next->filter,next->blur,exception);
3488 if (morph_image == (Image *) NULL)
3490 morph_images=DestroyImageList(morph_images);
3491 return((Image *) NULL);
3493 status=SetImageStorageClass(morph_image,DirectClass,exception);
3494 if (status == MagickFalse)
3496 morph_image=DestroyImage(morph_image);
3497 return((Image *) NULL);
3499 AppendImageToList(&morph_images,morph_image);
3500 morph_images=GetLastImageInList(morph_images);
3501 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3502 morph_images->rows,GetNextImageInList(next)->filter,
3503 GetNextImageInList(next)->blur,exception);
3504 if (morph_image == (Image *) NULL)
3506 morph_images=DestroyImageList(morph_images);
3507 return((Image *) NULL);
3509 image_view=AcquireCacheView(morph_image);
3510 morph_view=AcquireCacheView(morph_images);
3511 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3512 #pragma omp parallel for schedule(static,4) shared(status)
3514 for (y=0; y < (ssize_t) morph_images->rows; y++)
3519 register const Quantum
3528 if (status == MagickFalse)
3530 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3532 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3534 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3539 for (x=0; x < (ssize_t) morph_images->columns; x++)
3544 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
3553 channel=GetPixelChannelMapChannel(image,i);
3554 traits=GetPixelChannelMapTraits(image,channel);
3555 morph_traits=GetPixelChannelMapTraits(morph_image,channel);
3556 if ((traits == UndefinedPixelTrait) ||
3557 (morph_traits == UndefinedPixelTrait))
3559 if (((morph_traits & CopyPixelTrait) != 0) ||
3560 (GetPixelMask(image,p) != 0))
3562 SetPixelChannel(morph_image,channel,p[i],q);
3565 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3566 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3568 p+=GetPixelChannels(morph_image);
3569 q+=GetPixelChannels(morph_images);
3571 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3572 if (sync == MagickFalse)
3575 morph_view=DestroyCacheView(morph_view);
3576 image_view=DestroyCacheView(image_view);
3577 morph_image=DestroyImage(morph_image);
3579 if (i < (ssize_t) number_frames)
3582 Clone last frame in sequence.
3584 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3585 if (morph_image == (Image *) NULL)
3587 morph_images=DestroyImageList(morph_images);
3588 return((Image *) NULL);
3590 AppendImageToList(&morph_images,morph_image);
3591 morph_images=GetLastImageInList(morph_images);
3592 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3597 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3598 #pragma omp critical (MagickCore_MorphImages)
3600 proceed=SetImageProgress(image,MorphImageTag,scene,
3601 GetImageListLength(image));
3602 if (proceed == MagickFalse)
3607 if (GetNextImageInList(next) != (Image *) NULL)
3609 morph_images=DestroyImageList(morph_images);
3610 return((Image *) NULL);
3612 return(GetFirstImageInList(morph_images));
3616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3620 % P l a s m a I m a g e %
3624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3626 % PlasmaImage() initializes an image with plasma fractal values. The image
3627 % must be initialized with a base color and the random number generator
3628 % seeded before this method is called.
3630 % The format of the PlasmaImage method is:
3632 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3633 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3635 % A description of each parameter follows:
3637 % o image: the image.
3639 % o segment: Define the region to apply plasma fractals values.
3641 % o attenuate: Define the plasma attenuation factor.
3643 % o depth: Limit the plasma recursion depth.
3645 % o exception: return any errors or warnings in this structure.
3649 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3650 const MagickRealType pixel,const MagickRealType noise)
3655 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3660 static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3661 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3662 const SegmentInfo *segment,size_t attenuate,size_t depth,
3663 ExceptionInfo *exception)
3674 register const Quantum
3690 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3698 Divide the area into quadrants and recurse.
3702 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3703 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3704 local_info=(*segment);
3705 local_info.x2=(double) x_mid;
3706 local_info.y2=(double) y_mid;
3707 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3708 &local_info,attenuate,depth,exception);
3709 local_info=(*segment);
3710 local_info.y1=(double) y_mid;
3711 local_info.x2=(double) x_mid;
3712 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3713 &local_info,attenuate,depth,exception);
3714 local_info=(*segment);
3715 local_info.x1=(double) x_mid;
3716 local_info.y2=(double) y_mid;
3717 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3718 &local_info,attenuate,depth,exception);
3719 local_info=(*segment);
3720 local_info.x1=(double) x_mid;
3721 local_info.y1=(double) y_mid;
3722 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3723 &local_info,attenuate,depth,exception));
3725 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3726 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3727 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3728 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3729 return(MagickFalse);
3731 Average pixels and apply plasma.
3733 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3734 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3739 x=(ssize_t) ceil(segment->x1-0.5);
3740 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3742 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3744 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3745 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3746 (q == (Quantum *) NULL))
3748 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3750 channel=GetPixelChannelMapChannel(image,i);
3751 traits=GetPixelChannelMapTraits(image,channel);
3752 if (traits == UndefinedPixelTrait)
3754 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3756 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3757 if (segment->x1 != segment->x2)
3762 x=(ssize_t) ceil(segment->x2-0.5);
3763 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3765 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3767 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3768 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3769 (q == (Quantum *) NULL))
3771 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3773 channel=GetPixelChannelMapChannel(image,i);
3774 traits=GetPixelChannelMapTraits(image,channel);
3775 if (traits == UndefinedPixelTrait)
3777 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3779 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3782 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3784 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3789 y=(ssize_t) ceil(segment->y2-0.5);
3790 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3792 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3794 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3795 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3796 (q == (Quantum *) NULL))
3798 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3800 channel=GetPixelChannelMapChannel(image,i);
3801 traits=GetPixelChannelMapTraits(image,channel);
3802 if (traits == UndefinedPixelTrait)
3804 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3806 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3808 if (segment->y1 != segment->y2)
3813 y=(ssize_t) ceil(segment->y1-0.5);
3814 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3816 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3818 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3819 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3820 (q == (Quantum *) NULL))
3822 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3824 channel=GetPixelChannelMapChannel(image,i);
3825 traits=GetPixelChannelMapTraits(image,channel);
3826 if (traits == UndefinedPixelTrait)
3828 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3830 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3833 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3838 x=(ssize_t) ceil(segment->x1-0.5);
3839 y=(ssize_t) ceil(segment->y1-0.5);
3840 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
3841 x=(ssize_t) ceil(segment->x2-0.5);
3842 y=(ssize_t) ceil(segment->y2-0.5);
3843 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
3844 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3845 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3846 (q == (Quantum *) NULL))
3848 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3850 channel=GetPixelChannelMapChannel(image,i);
3851 traits=GetPixelChannelMapTraits(image,channel);
3852 if (traits == UndefinedPixelTrait)
3854 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3856 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3858 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3860 return(MagickFalse);
3863 MagickExport MagickBooleanType PlasmaImage(Image *image,
3864 const SegmentInfo *segment,size_t attenuate,size_t depth,
3865 ExceptionInfo *exception)
3878 if (image->debug != MagickFalse)
3879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3880 assert(image != (Image *) NULL);
3881 assert(image->signature == MagickSignature);
3882 if (image->debug != MagickFalse)
3883 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3884 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3885 return(MagickFalse);
3886 image_view=AcquireCacheView(image);
3887 u_view=AcquireCacheView(image);
3888 v_view=AcquireCacheView(image);
3889 random_info=AcquireRandomInfo();
3890 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3891 attenuate,depth,exception);
3892 random_info=DestroyRandomInfo(random_info);
3893 v_view=DestroyCacheView(v_view);
3894 u_view=DestroyCacheView(u_view);
3895 image_view=DestroyCacheView(image_view);
3900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3904 % P o l a r o i d I m a g e %
3908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3910 % PolaroidImage() simulates a Polaroid picture.
3912 % The format of the AnnotateImage method is:
3914 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3915 % const char *caption,const double angle,
3916 % const PixelInterpolateMethod method,ExceptionInfo exception)
3918 % A description of each parameter follows:
3920 % o image: the image.
3922 % o draw_info: the draw info.
3924 % o caption: the Polaroid caption.
3926 % o angle: Apply the effect along this angle.
3928 % o method: the pixel interpolation method.
3930 % o exception: return any errors or warnings in this structure.
3933 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3934 const char *caption,const double angle,const PixelInterpolateMethod method,
3935 ExceptionInfo *exception)
3953 Simulate a Polaroid picture.
3955 assert(image != (Image *) NULL);
3956 assert(image->signature == MagickSignature);
3957 if (image->debug != MagickFalse)
3958 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3959 assert(exception != (ExceptionInfo *) NULL);
3960 assert(exception->signature == MagickSignature);
3961 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3962 image->rows)/25.0,10.0);
3963 height=image->rows+2*quantum;
3964 caption_image=(Image *) NULL;
3965 if (caption != (const char *) NULL)
3968 geometry[MaxTextExtent],
3984 Generate caption image.
3986 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3987 if (caption_image == (Image *) NULL)
3988 return((Image *) NULL);
3989 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3990 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3992 (void) CloneString(&annotate_info->text,text);
3993 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3995 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
3996 (metrics.ascent-metrics.descent)+0.5),exception);
3997 if (status == MagickFalse)
3998 caption_image=DestroyImage(caption_image);
4001 caption_image->background_color=image->border_color;
4002 (void) SetImageBackgroundColor(caption_image,exception);
4003 (void) CloneString(&annotate_info->text,text);
4004 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
4006 if (annotate_info->gravity == UndefinedGravity)
4007 (void) CloneString(&annotate_info->geometry,AcquireString(
4009 (void) AnnotateImage(caption_image,annotate_info,exception);
4010 height+=caption_image->rows;
4012 annotate_info=DestroyDrawInfo(annotate_info);
4013 text=DestroyString(text);
4015 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
4017 if (picture_image == (Image *) NULL)
4019 if (caption_image != (Image *) NULL)
4020 caption_image=DestroyImage(caption_image);
4021 return((Image *) NULL);
4023 picture_image->background_color=image->border_color;
4024 (void) SetImageBackgroundColor(picture_image,exception);
4025 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum,
4027 if (caption_image != (Image *) NULL)
4029 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,quantum,
4030 (ssize_t) (image->rows+3*quantum/2),exception);
4031 caption_image=DestroyImage(caption_image);
4033 (void) QueryColorCompliance("none",AllCompliance,
4034 &picture_image->background_color,exception);
4035 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
4036 rotate_image=RotateImage(picture_image,90.0,exception);
4037 picture_image=DestroyImage(picture_image);
4038 if (rotate_image == (Image *) NULL)
4039 return((Image *) NULL);
4040 picture_image=rotate_image;
4041 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
4042 picture_image->columns,method,exception);
4043 picture_image=DestroyImage(picture_image);
4044 if (bend_image == (Image *) NULL)
4045 return((Image *) NULL);
4046 picture_image=bend_image;
4047 rotate_image=RotateImage(picture_image,-90.0,exception);
4048 picture_image=DestroyImage(picture_image);
4049 if (rotate_image == (Image *) NULL)
4050 return((Image *) NULL);
4051 picture_image=rotate_image;
4052 picture_image->background_color=image->background_color;
4053 polaroid_image=ShadowImage(picture_image,80.0,2.0,0.0,quantum/3,quantum/3,
4055 if (polaroid_image == (Image *) NULL)
4057 picture_image=DestroyImage(picture_image);
4058 return(picture_image);
4060 flop_image=FlopImage(polaroid_image,exception);
4061 polaroid_image=DestroyImage(polaroid_image);
4062 if (flop_image == (Image *) NULL)
4064 picture_image=DestroyImage(picture_image);
4065 return(picture_image);
4067 polaroid_image=flop_image;
4068 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,(ssize_t)
4069 (-0.01*picture_image->columns/2.0),0L,exception);
4070 picture_image=DestroyImage(picture_image);
4071 (void) QueryColorCompliance("none",AllCompliance,
4072 &polaroid_image->background_color,exception);
4073 rotate_image=RotateImage(polaroid_image,angle,exception);
4074 polaroid_image=DestroyImage(polaroid_image);
4075 if (rotate_image == (Image *) NULL)
4076 return((Image *) NULL);
4077 polaroid_image=rotate_image;
4078 trim_image=TrimImage(polaroid_image,exception);
4079 polaroid_image=DestroyImage(polaroid_image);
4080 if (trim_image == (Image *) NULL)
4081 return((Image *) NULL);
4082 polaroid_image=trim_image;
4083 return(polaroid_image);
4087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4091 % S e p i a T o n e I m a g e %
4095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4097 % MagickSepiaToneImage() applies a special effect to the image, similar to the
4098 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4099 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4100 % threshold of 80% is a good starting point for a reasonable tone.
4102 % The format of the SepiaToneImage method is:
4104 % Image *SepiaToneImage(const Image *image,const double threshold,
4105 % ExceptionInfo *exception)
4107 % A description of each parameter follows:
4109 % o image: the image.
4111 % o threshold: the tone threshold.
4113 % o exception: return any errors or warnings in this structure.
4116 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4117 ExceptionInfo *exception)
4119 #define SepiaToneImageTag "SepiaTone/Image"
4138 Initialize sepia-toned image attributes.
4140 assert(image != (const Image *) NULL);
4141 assert(image->signature == MagickSignature);
4142 if (image->debug != MagickFalse)
4143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4144 assert(exception != (ExceptionInfo *) NULL);
4145 assert(exception->signature == MagickSignature);
4146 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
4147 if (sepia_image == (Image *) NULL)
4148 return((Image *) NULL);
4149 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4151 sepia_image=DestroyImage(sepia_image);
4152 return((Image *) NULL);
4155 Tone each row of the image.
4159 image_view=AcquireCacheView(image);
4160 sepia_view=AcquireCacheView(sepia_image);
4161 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4162 #pragma omp parallel for schedule(static,4) shared(progress,status)
4164 for (y=0; y < (ssize_t) image->rows; y++)
4166 register const Quantum
4175 if (status == MagickFalse)
4177 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4178 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4180 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4185 for (x=0; x < (ssize_t) image->columns; x++)
4191 intensity=(MagickRealType) GetPixelIntensity(image,p);
4192 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4193 (MagickRealType) QuantumRange-threshold;
4194 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4195 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4196 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4197 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4198 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4199 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4201 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4202 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4203 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4204 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4205 p+=GetPixelChannels(image);
4206 q+=GetPixelChannels(sepia_image);
4208 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4210 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4215 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4216 #pragma omp critical (MagickCore_SepiaToneImage)
4218 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4220 if (proceed == MagickFalse)
4224 sepia_view=DestroyCacheView(sepia_view);
4225 image_view=DestroyCacheView(image_view);
4226 (void) NormalizeImage(sepia_image,exception);
4227 (void) ContrastImage(sepia_image,MagickTrue,exception);
4228 if (status == MagickFalse)
4229 sepia_image=DestroyImage(sepia_image);
4230 return(sepia_image);
4234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4238 % S h a d o w I m a g e %
4242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4244 % ShadowImage() simulates a shadow from the specified image and returns it.
4246 % The format of the ShadowImage method is:
4248 % Image *ShadowImage(const Image *image,const double alpha,
4249 % const double sigma,const double bias,const ssize_t x_offset,
4250 % const ssize_t y_offset,ExceptionInfo *exception)
4252 % A description of each parameter follows:
4254 % o image: the image.
4256 % o alpha: percentage transparency.
4258 % o sigma: the standard deviation of the Gaussian, in pixels.
4262 % o x_offset: the shadow x-offset.
4264 % o y_offset: the shadow y-offset.
4266 % o exception: return any errors or warnings in this structure.
4269 MagickExport Image *ShadowImage(const Image *image,const double alpha,
4270 const double sigma,const double bias,const ssize_t x_offset,
4271 const ssize_t y_offset,ExceptionInfo *exception)
4273 #define ShadowImageTag "Shadow/Image"
4295 assert(image != (Image *) NULL);
4296 assert(image->signature == MagickSignature);
4297 if (image->debug != MagickFalse)
4298 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4299 assert(exception != (ExceptionInfo *) NULL);
4300 assert(exception->signature == MagickSignature);
4301 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4302 if (clone_image == (Image *) NULL)
4303 return((Image *) NULL);
4304 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod,
4306 border_info.width=(size_t) floor(2.0*sigma+0.5);
4307 border_info.height=(size_t) floor(2.0*sigma+0.5);
4310 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4312 clone_image->matte=MagickTrue;
4313 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
4314 clone_image=DestroyImage(clone_image);
4315 if (border_image == (Image *) NULL)
4316 return((Image *) NULL);
4317 if (border_image->matte == MagickFalse)
4318 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4323 image_view=AcquireCacheView(border_image);
4324 for (y=0; y < (ssize_t) border_image->rows; y++)
4335 if (status == MagickFalse)
4337 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4339 if (q == (Quantum *) NULL)
4344 background_color=border_image->background_color;
4345 background_color.matte=MagickTrue;
4346 for (x=0; x < (ssize_t) border_image->columns; x++)
4348 if (border_image->matte != MagickFalse)
4349 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4350 SetPixelInfoPixel(border_image,&background_color,q);
4351 q+=GetPixelChannels(border_image);
4353 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4356 image_view=DestroyCacheView(image_view);
4357 if (status == MagickFalse)
4359 border_image=DestroyImage(border_image);
4360 return((Image *) NULL);
4362 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4363 shadow_image=BlurImage(border_image,0.0,sigma,bias,exception);
4364 border_image=DestroyImage(border_image);
4365 if (shadow_image == (Image *) NULL)
4366 return((Image *) NULL);
4367 (void) SetPixelChannelMapMask(shadow_image,channel_mask);
4368 if (shadow_image->page.width == 0)
4369 shadow_image->page.width=shadow_image->columns;
4370 if (shadow_image->page.height == 0)
4371 shadow_image->page.height=shadow_image->rows;
4372 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4373 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4374 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4375 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4376 return(shadow_image);
4380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4384 % S k e t c h I m a g e %
4388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4390 % SketchImage() simulates a pencil sketch. We convolve the image with a
4391 % Gaussian operator of the given radius and standard deviation (sigma). For
4392 % reasonable results, radius should be larger than sigma. Use a radius of 0
4393 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4396 % The format of the SketchImage method is:
4398 % Image *SketchImage(const Image *image,const double radius,
4399 % const double sigma,const double angle,const double bias,
4400 % ExceptionInfo *exception)
4402 % A description of each parameter follows:
4404 % o image: the image.
4406 % o radius: the radius of the Gaussian, in pixels, not counting the
4409 % o sigma: the standard deviation of the Gaussian, in pixels.
4411 % o angle: apply the effect along this angle.
4415 % o exception: return any errors or warnings in this structure.
4418 MagickExport Image *SketchImage(const Image *image,const double radius,
4419 const double sigma,const double angle,const double bias,
4420 ExceptionInfo *exception)
4436 **restrict random_info;
4444 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4445 MagickTrue,exception);
4446 if (random_image == (Image *) NULL)
4447 return((Image *) NULL);
4449 random_info=AcquireRandomInfoThreadSet();
4450 random_view=AcquireCacheView(random_image);
4451 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4452 #pragma omp parallel for schedule(static,4) shared(status)
4454 for (y=0; y < (ssize_t) random_image->rows; y++)
4457 id = GetOpenMPThreadId();
4465 if (status == MagickFalse)
4467 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4469 if (q == (Quantum *) NULL)
4474 for (x=0; x < (ssize_t) random_image->columns; x++)
4482 if (GetPixelMask(random_image,q) != 0)
4484 q+=GetPixelChannels(random_image);
4487 value=GetPseudoRandomValue(random_info[id]);
4488 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4496 channel=GetPixelChannelMapChannel(image,i);
4497 traits=GetPixelChannelMapTraits(image,channel);
4498 if (traits == UndefinedPixelTrait)
4500 q[i]=ClampToQuantum(QuantumRange*value);
4502 q+=GetPixelChannels(random_image);
4504 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4507 random_view=DestroyCacheView(random_view);
4508 random_info=DestroyRandomInfoThreadSet(random_info);
4509 if (status == MagickFalse)
4511 random_image=DestroyImage(random_image);
4512 return(random_image);
4514 blur_image=MotionBlurImage(random_image,radius,sigma,angle,bias,exception);
4515 random_image=DestroyImage(random_image);
4516 if (blur_image == (Image *) NULL)
4517 return((Image *) NULL);
4518 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
4519 blur_image=DestroyImage(blur_image);
4520 if (dodge_image == (Image *) NULL)
4521 return((Image *) NULL);
4522 (void) NormalizeImage(dodge_image,exception);
4523 (void) NegateImage(dodge_image,MagickFalse,exception);
4524 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
4525 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4526 if (sketch_image == (Image *) NULL)
4528 dodge_image=DestroyImage(dodge_image);
4529 return((Image *) NULL);
4531 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0,
4533 dodge_image=DestroyImage(dodge_image);
4534 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4535 if (blend_image == (Image *) NULL)
4537 sketch_image=DestroyImage(sketch_image);
4538 return((Image *) NULL);
4540 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4541 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0,
4543 blend_image=DestroyImage(blend_image);
4544 return(sketch_image);
4548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4552 % S o l a r i z e I m a g e %
4556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4558 % SolarizeImage() applies a special effect to the image, similar to the effect
4559 % achieved in a photo darkroom by selectively exposing areas of photo
4560 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4561 % measure of the extent of the solarization.
4563 % The format of the SolarizeImage method is:
4565 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4566 % ExceptionInfo *exception)
4568 % A description of each parameter follows:
4570 % o image: the image.
4572 % o threshold: Define the extent of the solarization.
4574 % o exception: return any errors or warnings in this structure.
4577 MagickExport MagickBooleanType SolarizeImage(Image *image,
4578 const double threshold,ExceptionInfo *exception)
4580 #define SolarizeImageTag "Solarize/Image"
4594 assert(image != (Image *) NULL);
4595 assert(image->signature == MagickSignature);
4596 if (image->debug != MagickFalse)
4597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4598 if (image->storage_class == PseudoClass)
4606 for (i=0; i < (ssize_t) image->colors; i++)
4608 if ((MagickRealType) image->colormap[i].red > threshold)
4609 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4610 if ((MagickRealType) image->colormap[i].green > threshold)
4611 image->colormap[i].green=(Quantum) QuantumRange-
4612 image->colormap[i].green;
4613 if ((MagickRealType) image->colormap[i].blue > threshold)
4614 image->colormap[i].blue=(Quantum) QuantumRange-
4615 image->colormap[i].blue;
4623 image_view=AcquireCacheView(image);
4624 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4625 #pragma omp parallel for schedule(static,4) shared(progress,status)
4627 for (y=0; y < (ssize_t) image->rows; y++)
4635 if (status == MagickFalse)
4637 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4638 if (q == (Quantum *) NULL)
4643 for (x=0; x < (ssize_t) image->columns; x++)
4648 if (GetPixelMask(image,q) != 0)
4650 q+=GetPixelChannels(image);
4653 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4661 channel=GetPixelChannelMapChannel(image,i);
4662 traits=GetPixelChannelMapTraits(image,channel);
4663 if ((traits == UndefinedPixelTrait) ||
4664 ((traits & CopyPixelTrait) != 0))
4666 if ((MagickRealType) q[i] > threshold)
4667 q[i]=QuantumRange-q[i];
4669 q+=GetPixelChannels(image);
4671 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4673 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4678 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4679 #pragma omp critical (MagickCore_SolarizeImage)
4681 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4682 if (proceed == MagickFalse)
4686 image_view=DestroyCacheView(image_view);
4691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4695 % S t e g a n o I m a g e %
4699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4701 % SteganoImage() hides a digital watermark within the image. Recover
4702 % the hidden watermark later to prove that the authenticity of an image.
4703 % Offset defines the start position within the image to hide the watermark.
4705 % The format of the SteganoImage method is:
4707 % Image *SteganoImage(const Image *image,Image *watermark,
4708 % ExceptionInfo *exception)
4710 % A description of each parameter follows:
4712 % o image: the image.
4714 % o watermark: the watermark image.
4716 % o exception: return any errors or warnings in this structure.
4719 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4720 ExceptionInfo *exception)
4722 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4723 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4724 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4725 #define SteganoImageTag "Stegano/Image"
4760 Initialize steganographic image attributes.
4762 assert(image != (const Image *) NULL);
4763 assert(image->signature == MagickSignature);
4764 if (image->debug != MagickFalse)
4765 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4766 assert(watermark != (const Image *) NULL);
4767 assert(watermark->signature == MagickSignature);
4768 assert(exception != (ExceptionInfo *) NULL);
4769 assert(exception->signature == MagickSignature);
4771 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4772 if (stegano_image == (Image *) NULL)
4773 return((Image *) NULL);
4774 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4776 stegano_image=DestroyImage(stegano_image);
4777 return((Image *) NULL);
4779 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4781 Hide watermark in low-order bits of image.
4786 depth=stegano_image->depth;
4789 watermark_view=AcquireCacheView(watermark);
4790 stegano_view=AcquireCacheView(stegano_image);
4791 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4793 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4795 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4798 virtual_pixel[CompositePixelChannel];
4803 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,virtual_pixel,
4805 pixel.red=(double) virtual_pixel[RedPixelChannel];
4806 pixel.green=(double) virtual_pixel[GreenPixelChannel];
4807 pixel.blue=(double) virtual_pixel[BluePixelChannel];
4808 pixel.alpha=(double) virtual_pixel[AlphaPixelChannel];
4809 offset=k/(ssize_t) stegano_image->columns;
4810 if (offset >= (ssize_t) stegano_image->rows)
4812 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4813 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4815 if (q == (Quantum *) NULL)
4821 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
4822 GetPixelInfoIntensity(&pixel),i)),q);
4827 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
4828 GetPixelInfoIntensity(&pixel),i)),q);
4833 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
4834 GetPixelInfoIntensity(&pixel),i)),q);
4838 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4844 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4846 if (k == image->offset)
4850 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4855 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4857 if (proceed == MagickFalse)
4861 stegano_view=DestroyCacheView(stegano_view);
4862 watermark_view=DestroyCacheView(watermark_view);
4863 if (stegano_image->storage_class == PseudoClass)
4864 (void) SyncImage(stegano_image,exception);
4865 if (status == MagickFalse)
4867 stegano_image=DestroyImage(stegano_image);
4868 return((Image *) NULL);
4870 return(stegano_image);
4874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4878 % S t e r e o A n a g l y p h I m a g e %
4882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4884 % StereoAnaglyphImage() combines two images and produces a single image that
4885 % is the composite of a left and right image of a stereo pair. Special
4886 % red-green stereo glasses are required to view this effect.
4888 % The format of the StereoAnaglyphImage method is:
4890 % Image *StereoImage(const Image *left_image,const Image *right_image,
4891 % ExceptionInfo *exception)
4892 % Image *StereoAnaglyphImage(const Image *left_image,
4893 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4894 % ExceptionInfo *exception)
4896 % A description of each parameter follows:
4898 % o left_image: the left image.
4900 % o right_image: the right image.
4902 % o exception: return any errors or warnings in this structure.
4904 % o x_offset: amount, in pixels, by which the left image is offset to the
4905 % right of the right image.
4907 % o y_offset: amount, in pixels, by which the left image is offset to the
4908 % bottom of the right image.
4912 MagickExport Image *StereoImage(const Image *left_image,
4913 const Image *right_image,ExceptionInfo *exception)
4915 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4918 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4919 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4920 ExceptionInfo *exception)
4922 #define StereoImageTag "Stereo/Image"
4936 assert(left_image != (const Image *) NULL);
4937 assert(left_image->signature == MagickSignature);
4938 if (left_image->debug != MagickFalse)
4939 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4940 left_image->filename);
4941 assert(right_image != (const Image *) NULL);
4942 assert(right_image->signature == MagickSignature);
4943 assert(exception != (ExceptionInfo *) NULL);
4944 assert(exception->signature == MagickSignature);
4945 assert(right_image != (const Image *) NULL);
4947 if ((left_image->columns != right_image->columns) ||
4948 (left_image->rows != right_image->rows))
4949 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4951 Initialize stereo image attributes.
4953 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4954 MagickTrue,exception);
4955 if (stereo_image == (Image *) NULL)
4956 return((Image *) NULL);
4957 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4959 stereo_image=DestroyImage(stereo_image);
4960 return((Image *) NULL);
4963 Copy left image to red channel and right image to blue channel.
4966 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4968 register const Quantum
4978 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4980 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4981 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4982 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4983 (r == (Quantum *) NULL))
4985 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4987 SetPixelRed(image,GetPixelRed(left_image,p),r);
4988 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4989 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4990 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4991 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4992 GetPixelAlpha(right_image,q))/2,r);
4993 p+=GetPixelChannels(left_image);
4994 q+=GetPixelChannels(right_image);
4995 r+=GetPixelChannels(stereo_image);
4997 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4999 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5004 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
5005 stereo_image->rows);
5006 if (proceed == MagickFalse)
5010 if (status == MagickFalse)
5012 stereo_image=DestroyImage(stereo_image);
5013 return((Image *) NULL);
5015 return(stereo_image);
5019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5023 % S w i r l I m a g e %
5027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5029 % SwirlImage() swirls the pixels about the center of the image, where
5030 % degrees indicates the sweep of the arc through which each pixel is moved.
5031 % You get a more dramatic effect as the degrees move from 1 to 360.
5033 % The format of the SwirlImage method is:
5035 % Image *SwirlImage(const Image *image,double degrees,
5036 % const PixelInterpolateMethod method,ExceptionInfo *exception)
5038 % A description of each parameter follows:
5040 % o image: the image.
5042 % o degrees: Define the tightness of the swirling effect.
5044 % o method: the pixel interpolation method.
5046 % o exception: return any errors or warnings in this structure.
5049 MagickExport Image *SwirlImage(const Image *image,double degrees,
5050 const PixelInterpolateMethod method,ExceptionInfo *exception)
5052 #define SwirlImageTag "Swirl/Image"
5078 Initialize swirl image attributes.
5080 assert(image != (const Image *) NULL);
5081 assert(image->signature == MagickSignature);
5082 if (image->debug != MagickFalse)
5083 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5084 assert(exception != (ExceptionInfo *) NULL);
5085 assert(exception->signature == MagickSignature);
5086 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5087 if (swirl_image == (Image *) NULL)
5088 return((Image *) NULL);
5089 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
5091 swirl_image=DestroyImage(swirl_image);
5092 return((Image *) NULL);
5094 if (swirl_image->background_color.alpha != OpaqueAlpha)
5095 swirl_image->matte=MagickTrue;
5097 Compute scaling factor.
5099 center.x=(double) image->columns/2.0;
5100 center.y=(double) image->rows/2.0;
5101 radius=MagickMax(center.x,center.y);
5104 if (image->columns > image->rows)
5105 scale.y=(double) image->columns/(double) image->rows;
5107 if (image->columns < image->rows)
5108 scale.x=(double) image->rows/(double) image->columns;
5109 degrees=(double) DegreesToRadians(degrees);
5115 image_view=AcquireCacheView(image);
5116 swirl_view=AcquireCacheView(swirl_image);
5117 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5118 #pragma omp parallel for schedule(static,4) shared(progress,status)
5120 for (y=0; y < (ssize_t) image->rows; y++)
5128 register const Quantum
5137 if (status == MagickFalse)
5139 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
5140 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5142 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5147 delta.y=scale.y*(double) (y-center.y);
5148 for (x=0; x < (ssize_t) image->columns; x++)
5151 Determine if the pixel is within an ellipse.
5153 if (GetPixelMask(image,p) != 0)
5155 p+=GetPixelChannels(image);
5156 q+=GetPixelChannels(swirl_image);
5159 delta.x=scale.x*(double) (x-center.x);
5160 distance=delta.x*delta.x+delta.y*delta.y;
5161 if (distance >= (radius*radius))
5166 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5175 channel=GetPixelChannelMapChannel(image,i);
5176 traits=GetPixelChannelMapTraits(image,channel);
5177 swirl_traits=GetPixelChannelMapTraits(swirl_image,channel);
5178 if ((traits == UndefinedPixelTrait) ||
5179 (swirl_traits == UndefinedPixelTrait))
5181 SetPixelChannel(swirl_image,channel,p[i],q);
5194 factor=1.0-sqrt((double) distance)/radius;
5195 sine=sin((double) (degrees*factor*factor));
5196 cosine=cos((double) (degrees*factor*factor));
5197 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5198 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5199 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
5201 p+=GetPixelChannels(image);
5202 q+=GetPixelChannels(swirl_image);
5204 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5206 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5211 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5212 #pragma omp critical (MagickCore_SwirlImage)
5214 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5215 if (proceed == MagickFalse)
5219 swirl_view=DestroyCacheView(swirl_view);
5220 image_view=DestroyCacheView(image_view);
5221 if (status == MagickFalse)
5222 swirl_image=DestroyImage(swirl_image);
5223 return(swirl_image);
5227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5231 % T i n t I m a g e %
5235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5237 % TintImage() applies a color vector to each pixel in the image. The length
5238 % of the vector is 0 for black and white and at its maximum for the midtones.
5239 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5241 % The format of the TintImage method is:
5243 % Image *TintImage(const Image *image,const char *blend,
5244 % const PixelInfo *tint,ExceptionInfo *exception)
5246 % A description of each parameter follows:
5248 % o image: the image.
5250 % o blend: A color value used for tinting.
5252 % o tint: A color value used for tinting.
5254 % o exception: return any errors or warnings in this structure.
5257 MagickExport Image *TintImage(const Image *image,const char *blend,
5258 const PixelInfo *tint,ExceptionInfo *exception)
5260 #define TintImageTag "Tint/Image"
5291 Allocate tint image.
5293 assert(image != (const Image *) NULL);
5294 assert(image->signature == MagickSignature);
5295 if (image->debug != MagickFalse)
5296 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5297 assert(exception != (ExceptionInfo *) NULL);
5298 assert(exception->signature == MagickSignature);
5299 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5300 if (tint_image == (Image *) NULL)
5301 return((Image *) NULL);
5302 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5304 tint_image=DestroyImage(tint_image);
5305 return((Image *) NULL);
5307 if (blend == (const char *) NULL)
5310 Determine RGB values of the color.
5312 GetPixelInfo(image,&color_vector);
5313 flags=ParseGeometry(blend,&geometry_info);
5314 color_vector.red=geometry_info.rho;
5315 color_vector.green=geometry_info.rho;
5316 color_vector.blue=geometry_info.rho;
5317 color_vector.alpha=OpaqueAlpha;
5318 if ((flags & SigmaValue) != 0)
5319 color_vector.green=geometry_info.sigma;
5320 if ((flags & XiValue) != 0)
5321 color_vector.blue=geometry_info.xi;
5322 if ((flags & PsiValue) != 0)
5323 color_vector.alpha=geometry_info.psi;
5324 if (image->colorspace == CMYKColorspace)
5326 color_vector.black=geometry_info.rho;
5327 if ((flags & PsiValue) != 0)
5328 color_vector.black=geometry_info.psi;
5329 if ((flags & ChiValue) != 0)
5330 color_vector.alpha=geometry_info.chi;
5332 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5333 color_vector.red=(MagickRealType) (color_vector.red*tint->red/100.0-
5335 color_vector.green=(MagickRealType) (color_vector.green*tint->green/100.0-
5337 color_vector.blue=(MagickRealType) (color_vector.blue*tint->blue/100.0-
5339 color_vector.black=(MagickRealType) (color_vector.black*tint->black/100.0-
5341 color_vector.alpha=(MagickRealType) (color_vector.alpha*tint->alpha/100.0-
5348 image_view=AcquireCacheView(image);
5349 tint_view=AcquireCacheView(tint_image);
5350 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5351 #pragma omp parallel for schedule(static,4) shared(progress,status)
5353 for (y=0; y < (ssize_t) image->rows; y++)
5355 register const Quantum
5364 if (status == MagickFalse)
5366 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5367 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5369 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5374 for (x=0; x < (ssize_t) image->columns; x++)
5385 if (GetPixelMask(image,p) != 0)
5387 p+=GetPixelChannels(image);
5388 q+=GetPixelChannels(tint_image);
5391 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5400 channel=GetPixelChannelMapChannel(image,i);
5401 traits=GetPixelChannelMapTraits(image,channel);
5402 tint_traits=GetPixelChannelMapTraits(tint_image,channel);
5403 if ((traits == UndefinedPixelTrait) ||
5404 (tint_traits == UndefinedPixelTrait))
5406 if ((tint_traits & CopyPixelTrait) != 0)
5408 SetPixelChannel(tint_image,channel,p[i],q);
5412 GetPixelInfo(image,&pixel);
5413 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5414 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5415 (1.0-(4.0*(weight*weight)));
5416 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5417 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5418 (1.0-(4.0*(weight*weight)));
5419 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5420 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5421 (1.0-(4.0*(weight*weight)));
5422 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5423 pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black*
5424 (1.0-(4.0*(weight*weight)));
5425 SetPixelInfoPixel(tint_image,&pixel,q);
5426 p+=GetPixelChannels(image);
5427 q+=GetPixelChannels(tint_image);
5429 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5431 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5436 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5437 #pragma omp critical (MagickCore_TintImage)
5439 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5440 if (proceed == MagickFalse)
5444 tint_view=DestroyCacheView(tint_view);
5445 image_view=DestroyCacheView(image_view);
5446 if (status == MagickFalse)
5447 tint_image=DestroyImage(tint_image);
5452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5456 % V i g n e t t e I m a g e %
5460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5462 % VignetteImage() softens the edges of the image in vignette style.
5464 % The format of the VignetteImage method is:
5466 % Image *VignetteImage(const Image *image,const double radius,
5467 % const double sigma,const double bias,const ssize_t x,const ssize_t y,
5468 % ExceptionInfo *exception)
5470 % A description of each parameter follows:
5472 % o image: the image.
5474 % o radius: the radius of the pixel neighborhood.
5476 % o sigma: the standard deviation of the Gaussian, in pixels.
5480 % o x, y: Define the x and y ellipse offset.
5482 % o exception: return any errors or warnings in this structure.
5485 MagickExport Image *VignetteImage(const Image *image,const double radius,
5486 const double sigma,const double bias,const ssize_t x,const ssize_t y,
5487 ExceptionInfo *exception)
5490 ellipse[MaxTextExtent];
5501 assert(image != (Image *) NULL);
5502 assert(image->signature == MagickSignature);
5503 if (image->debug != MagickFalse)
5504 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5505 assert(exception != (ExceptionInfo *) NULL);
5506 assert(exception->signature == MagickSignature);
5507 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5508 if (canvas_image == (Image *) NULL)
5509 return((Image *) NULL);
5510 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5512 canvas_image=DestroyImage(canvas_image);
5513 return((Image *) NULL);
5515 canvas_image->matte=MagickTrue;
5516 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5517 MagickTrue,exception);
5518 if (oval_image == (Image *) NULL)
5520 canvas_image=DestroyImage(canvas_image);
5521 return((Image *) NULL);
5523 (void) QueryColorCompliance("#000000",AllCompliance,
5524 &oval_image->background_color,exception);
5525 (void) SetImageBackgroundColor(oval_image,exception);
5526 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5527 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5529 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5531 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5532 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5534 draw_info->primitive=AcquireString(ellipse);
5535 (void) DrawImage(oval_image,draw_info,exception);
5536 draw_info=DestroyDrawInfo(draw_info);
5537 blur_image=BlurImage(oval_image,radius,sigma,bias,exception);
5538 oval_image=DestroyImage(oval_image);
5539 if (blur_image == (Image *) NULL)
5541 canvas_image=DestroyImage(canvas_image);
5542 return((Image *) NULL);
5544 blur_image->matte=MagickFalse;
5545 (void) CompositeImage(canvas_image,IntensityCompositeOp,blur_image,0,0,
5547 blur_image=DestroyImage(blur_image);
5548 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5549 canvas_image=DestroyImage(canvas_image);
5550 return(vignette_image);
5554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5558 % W a v e I m a g e %
5562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5564 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5565 % vertically along a sine wave whose amplitude and wavelength is specified
5566 % by the given parameters.
5568 % The format of the WaveImage method is:
5570 % Image *WaveImage(const Image *image,const double amplitude,
5571 % const double wave_length,const PixelInterpolateMethod method,
5572 % ExceptionInfo *exception)
5574 % A description of each parameter follows:
5576 % o image: the image.
5578 % o amplitude, wave_length: Define the amplitude and wave length of the
5581 % o interpolate: the pixel interpolation method.
5583 % o exception: return any errors or warnings in this structure.
5586 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5587 const double wave_length,const PixelInterpolateMethod method,
5588 ExceptionInfo *exception)
5590 #define WaveImageTag "Wave/Image"
5615 Initialize wave image attributes.
5617 assert(image != (Image *) NULL);
5618 assert(image->signature == MagickSignature);
5619 if (image->debug != MagickFalse)
5620 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5621 assert(exception != (ExceptionInfo *) NULL);
5622 assert(exception->signature == MagickSignature);
5623 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5624 fabs(amplitude)),MagickTrue,exception);
5625 if (wave_image == (Image *) NULL)
5626 return((Image *) NULL);
5627 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5629 wave_image=DestroyImage(wave_image);
5630 return((Image *) NULL);
5632 if (wave_image->background_color.alpha != OpaqueAlpha)
5633 wave_image->matte=MagickTrue;
5637 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5639 if (sine_map == (MagickRealType *) NULL)
5641 wave_image=DestroyImage(wave_image);
5642 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5644 for (i=0; i < (ssize_t) wave_image->columns; i++)
5645 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5652 image_view=AcquireCacheView(image);
5653 wave_view=AcquireCacheView(wave_image);
5654 (void) SetCacheViewVirtualPixelMethod(image_view,
5655 BackgroundVirtualPixelMethod);
5656 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5657 #pragma omp parallel for schedule(static,4) shared(progress,status)
5659 for (y=0; y < (ssize_t) wave_image->rows; y++)
5667 if (status == MagickFalse)
5669 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5671 if (q == (Quantum *) NULL)
5676 for (x=0; x < (ssize_t) wave_image->columns; x++)
5678 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5679 (double) x,(double) (y-sine_map[x]),q,exception);
5680 q+=GetPixelChannels(wave_image);
5682 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5684 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5689 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5690 #pragma omp critical (MagickCore_WaveImage)
5692 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5693 if (proceed == MagickFalse)
5697 wave_view=DestroyCacheView(wave_view);
5698 image_view=DestroyCacheView(image_view);
5699 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5700 if (status == MagickFalse)
5701 wave_image=DestroyImage(wave_image);