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,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.
573 % o exception: return any errors or warnings in this structure.
576 MagickExport Image *CharcoalImage(const Image *image,const double radius,
577 const double sigma,ExceptionInfo *exception)
584 assert(image != (Image *) NULL);
585 assert(image->signature == MagickSignature);
586 if (image->debug != MagickFalse)
587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
588 assert(exception != (ExceptionInfo *) NULL);
589 assert(exception->signature == MagickSignature);
590 clone_image=CloneImage(image,0,0,MagickTrue,exception);
591 if (clone_image == (Image *) NULL)
592 return((Image *) NULL);
593 (void) SetImageType(clone_image,GrayscaleType,exception);
594 edge_image=EdgeImage(clone_image,radius,sigma,exception);
595 clone_image=DestroyImage(clone_image);
596 if (edge_image == (Image *) NULL)
597 return((Image *) NULL);
598 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
599 edge_image=DestroyImage(edge_image);
600 if (charcoal_image == (Image *) NULL)
601 return((Image *) NULL);
602 (void) NormalizeImage(charcoal_image,exception);
603 (void) NegateImage(charcoal_image,MagickFalse,exception);
604 (void) SetImageType(charcoal_image,GrayscaleType,exception);
605 return(charcoal_image);
609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
613 % C o l o r i z e I m a g e %
617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 % ColorizeImage() blends the fill color with each pixel in the image.
620 % A percentage blend is specified with opacity. Control the application
621 % of different color components by specifying a different percentage for
622 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
624 % The format of the ColorizeImage method is:
626 % Image *ColorizeImage(const Image *image,const char *blend,
627 % const PixelInfo *colorize,ExceptionInfo *exception)
629 % A description of each parameter follows:
631 % o image: the image.
633 % o blend: A character string indicating the level of blending as a
636 % o colorize: A color value.
638 % o exception: return any errors or warnings in this structure.
641 MagickExport Image *ColorizeImage(const Image *image,const char *blend,
642 const PixelInfo *colorize,ExceptionInfo *exception)
644 #define ColorizeImageTag "Colorize/Image"
672 Allocate colorized image.
674 assert(image != (const Image *) NULL);
675 assert(image->signature == MagickSignature);
676 if (image->debug != MagickFalse)
677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
678 assert(exception != (ExceptionInfo *) NULL);
679 assert(exception->signature == MagickSignature);
680 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
682 if (colorize_image == (Image *) NULL)
683 return((Image *) NULL);
684 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
686 colorize_image=DestroyImage(colorize_image);
687 return((Image *) NULL);
689 if ((colorize->matte != MagickFalse) &&
690 (colorize_image->matte == MagickFalse))
691 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
692 if (blend == (const char *) NULL)
693 return(colorize_image);
695 Determine RGB values of the fill color for pixel
697 GetPixelInfo(image,&pixel);
698 flags=ParseGeometry(blend,&geometry_info);
699 pixel.red=geometry_info.rho;
700 pixel.green=geometry_info.rho;
701 pixel.blue=geometry_info.rho;
703 if ((flags & SigmaValue) != 0)
704 pixel.green=geometry_info.sigma;
705 if ((flags & XiValue) != 0)
706 pixel.blue=geometry_info.xi;
707 if ((flags & PsiValue) != 0)
708 pixel.alpha=geometry_info.psi;
709 if (pixel.colorspace == CMYKColorspace)
711 pixel.black=geometry_info.rho;
712 if ((flags & PsiValue) != 0)
713 pixel.black=geometry_info.psi;
714 if ((flags & ChiValue) != 0)
715 pixel.alpha=geometry_info.chi;
718 Colorize DirectClass image.
722 image_view=AcquireCacheView(image);
723 colorize_view=AcquireCacheView(colorize_image);
724 #if defined(MAGICKCORE_OPENMP_SUPPORT)
725 #pragma omp parallel for schedule(static,4) shared(progress,status)
727 for (y=0; y < (ssize_t) image->rows; y++)
732 register const Quantum
741 if (status == MagickFalse)
743 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
744 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
746 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
751 for (x=0; x < (ssize_t) image->columns; x++)
756 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
765 channel=GetPixelChannelMapChannel(image,i);
766 traits=GetPixelChannelMapTraits(image,channel);
767 colorize_traits=GetPixelChannelMapTraits(colorize_image,channel);
768 if ((traits == UndefinedPixelTrait) ||
769 (colorize_traits == UndefinedPixelTrait))
771 if (((colorize_traits & CopyPixelTrait) != 0) ||
772 (GetPixelMask(image,p) != 0))
774 SetPixelChannel(colorize_image,channel,p[i],q);
779 case RedPixelChannel:
781 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
782 (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q);
785 case GreenPixelChannel:
787 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
788 (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q);
791 case BluePixelChannel:
793 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
794 (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q);
797 case BlackPixelChannel:
799 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
800 (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q);
803 case AlphaPixelChannel:
805 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
806 (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q);
811 SetPixelChannel(colorize_image,channel,p[i],q);
816 p+=GetPixelChannels(image);
817 q+=GetPixelChannels(colorize_image);
819 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
820 if (sync == MagickFalse)
822 if (image->progress_monitor != (MagickProgressMonitor) NULL)
827 #if defined(MAGICKCORE_OPENMP_SUPPORT)
828 #pragma omp critical (MagickCore_ColorizeImage)
830 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
831 if (proceed == MagickFalse)
835 image_view=DestroyCacheView(image_view);
836 colorize_view=DestroyCacheView(colorize_view);
837 if (status == MagickFalse)
838 colorize_image=DestroyImage(colorize_image);
839 return(colorize_image);
843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
847 % C o l o r M a t r i x I m a g e %
851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
853 % ColorMatrixImage() applies color transformation to an image. This method
854 % permits saturation changes, hue rotation, luminance to alpha, and various
855 % other effects. Although variable-sized transformation matrices can be used,
856 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
857 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
858 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
859 % and offsets are normalized (divide Flash offset by 255).
861 % The format of the ColorMatrixImage method is:
863 % Image *ColorMatrixImage(const Image *image,
864 % const KernelInfo *color_matrix,ExceptionInfo *exception)
866 % A description of each parameter follows:
868 % o image: the image.
870 % o color_matrix: the color matrix.
872 % o exception: return any errors or warnings in this structure.
875 /* FUTURE: modify to make use of a MagickMatrix Mutliply function
876 That should be provided in "matrix.c"
877 (ASIDE: actually distorts should do this too but currently doesn't)
880 MagickExport Image *ColorMatrixImage(const Image *image,
881 const KernelInfo *color_matrix,ExceptionInfo *exception)
883 #define ColorMatrixImageTag "ColorMatrix/Image"
892 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
893 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
894 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
895 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
896 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
897 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
918 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
920 assert(image != (Image *) NULL);
921 assert(image->signature == MagickSignature);
922 if (image->debug != MagickFalse)
923 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
924 assert(exception != (ExceptionInfo *) NULL);
925 assert(exception->signature == MagickSignature);
927 for (v=0; v < (ssize_t) color_matrix->height; v++)
928 for (u=0; u < (ssize_t) color_matrix->width; u++)
930 if ((v < 6) && (u < 6))
931 ColorMatrix[v][u]=color_matrix->values[i];
935 Initialize color image.
937 color_image=CloneImage(image,0,0,MagickTrue,exception);
938 if (color_image == (Image *) NULL)
939 return((Image *) NULL);
940 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
942 color_image=DestroyImage(color_image);
943 return((Image *) NULL);
945 if (image->debug != MagickFalse)
948 format[MaxTextExtent],
951 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
952 " ColorMatrix image with color matrix:");
953 message=AcquireString("");
954 for (v=0; v < 6; v++)
957 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
958 (void) ConcatenateString(&message,format);
959 for (u=0; u < 6; u++)
961 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
963 (void) ConcatenateString(&message,format);
965 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
967 message=DestroyString(message);
970 Apply the ColorMatrix to image.
974 image_view=AcquireCacheView(image);
975 color_view=AcquireCacheView(color_image);
976 #if defined(MAGICKCORE_OPENMP_SUPPORT)
977 #pragma omp parallel for schedule(static,4) shared(progress,status)
979 for (y=0; y < (ssize_t) image->rows; y++)
984 register const Quantum
993 if (status == MagickFalse)
995 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
996 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
998 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1003 GetPixelInfo(image,&pixel);
1004 for (x=0; x < (ssize_t) image->columns; x++)
1012 GetPixelInfoPixel(image,p,&pixel);
1013 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
1014 for (v=0; v < (ssize_t) height; v++)
1019 sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
1020 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
1021 if (image->colorspace == CMYKColorspace)
1022 sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
1023 if (image->matte != MagickFalse)
1024 sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1025 sum+=QuantumRange*ColorMatrix[v][5];
1028 case 0: pixel.red=sum; break;
1029 case 1: pixel.green=sum; break;
1030 case 2: pixel.blue=sum; break;
1031 case 3: pixel.black=sum; break;
1032 case 4: pixel.alpha=sum; break;
1036 SetPixelInfoPixel(color_image,&pixel,q);
1037 p+=GetPixelChannels(image);
1038 q+=GetPixelChannels(color_image);
1040 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1042 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1047 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1048 #pragma omp critical (MagickCore_ColorMatrixImage)
1050 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1052 if (proceed == MagickFalse)
1056 color_view=DestroyCacheView(color_view);
1057 image_view=DestroyCacheView(image_view);
1058 if (status == MagickFalse)
1059 color_image=DestroyImage(color_image);
1060 return(color_image);
1064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1068 + D e s t r o y F x I n f o %
1072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1074 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1076 % The format of the DestroyFxInfo method is:
1078 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1080 % A description of each parameter follows:
1082 % o fx_info: the fx info.
1085 MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
1090 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1091 fx_info->expression=DestroyString(fx_info->expression);
1092 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1093 fx_info->colors=DestroySplayTree(fx_info->colors);
1094 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1095 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1096 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1097 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1098 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1107 + 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 %
1111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1113 % FxEvaluateChannelExpression() evaluates an expression and returns the
1116 % The format of the FxEvaluateExpression method is:
1118 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1119 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1120 % MagickRealType *alpha,Exceptioninfo *exception)
1121 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1122 % MagickRealType *alpha,Exceptioninfo *exception)
1124 % A description of each parameter follows:
1126 % o fx_info: the fx info.
1128 % o channel: the channel.
1130 % o x,y: the pixel position.
1132 % o alpha: the result.
1134 % o exception: return any errors or warnings in this structure.
1138 static inline double MagickMax(const double x,const double y)
1145 static inline double MagickMin(const double x,const double y)
1152 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1153 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1157 statistic[MaxTextExtent];
1165 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1167 switch (*++p) /* e.g. depth.r */
1169 case 'r': channel=RedPixelChannel; break;
1170 case 'g': channel=GreenPixelChannel; break;
1171 case 'b': channel=BluePixelChannel; break;
1172 case 'c': channel=CyanPixelChannel; break;
1173 case 'm': channel=MagentaPixelChannel; break;
1174 case 'y': channel=YellowPixelChannel; break;
1175 case 'k': channel=BlackPixelChannel; break;
1178 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1179 (double) channel,symbol);
1180 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1181 if (value != (const char *) NULL)
1182 return(QuantumScale*StringToDouble(value,(char **) NULL));
1183 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1184 if (LocaleNCompare(symbol,"depth",5) == 0)
1189 depth=GetImageDepth(image,exception);
1190 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1192 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1198 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1199 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1201 if (LocaleNCompare(symbol,"maxima",6) == 0)
1207 (void) GetImageRange(image,&minima,&maxima,exception);
1208 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1210 if (LocaleNCompare(symbol,"mean",4) == 0)
1216 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1217 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1219 if (LocaleNCompare(symbol,"minima",6) == 0)
1225 (void) GetImageRange(image,&minima,&maxima,exception);
1226 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1228 if (LocaleNCompare(symbol,"skewness",8) == 0)
1234 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1235 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1237 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1243 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1244 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1245 standard_deviation);
1247 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1248 ConstantString(statistic));
1249 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
1252 static MagickRealType
1253 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1254 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1256 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1259 return(FxGCD(beta,alpha % beta));
1263 static inline const char *FxSubexpression(const char *expression,
1264 ExceptionInfo *exception)
1273 subexpression=expression;
1274 while ((*subexpression != '\0') &&
1275 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1277 if (strchr("(",(int) *subexpression) != (char *) NULL)
1280 if (strchr(")",(int) *subexpression) != (char *) NULL)
1284 if (*subexpression == '\0')
1285 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1286 "UnbalancedParenthesis","`%s'",expression);
1287 return(subexpression);
1290 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1291 const ssize_t x,const ssize_t y,const char *expression,
1292 ExceptionInfo *exception)
1296 subexpression[MaxTextExtent],
1297 symbol[MaxTextExtent];
1324 i=GetImageIndexInList(fx_info->images);
1328 if (isalpha((int) *(p+1)) == 0)
1330 if (strchr("suv",(int) *p) != (char *) NULL)
1337 i=GetImageIndexInList(fx_info->images);
1340 case 'u': i=0; break;
1341 case 'v': i=1; break;
1348 for (p++; *p != '\0'; )
1362 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1364 i=(ssize_t) (alpha+0.5);
1370 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1377 for (p++; *p != '\0'; )
1391 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1402 for (p++; *p != '\0'; )
1416 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1426 length=GetImageListLength(fx_info->images);
1428 i+=(ssize_t) length;
1430 image=GetImageFromList(fx_info->images,i);
1431 if (image == (Image *) NULL)
1433 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1434 "NoSuchImage","`%s'",expression);
1437 GetPixelInfo(image,&pixel);
1438 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1439 point.x,point.y,&pixel,exception);
1440 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1441 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
1442 (LocaleCompare(p,"saturation") != 0) &&
1443 (LocaleCompare(p,"lightness") != 0))
1446 name[MaxTextExtent];
1448 (void) CopyMagickString(name,p,MaxTextExtent);
1449 for (q=name+(strlen(name)-1); q > name; q--)
1459 if ((strlen(name) > 2) &&
1460 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1465 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1466 if (color != (PixelInfo *) NULL)
1476 status=QueryColorCompliance(name,AllCompliance,&pixel,
1477 fx_info->exception);
1478 if (status != MagickFalse)
1480 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1481 name),ClonePixelInfo(&pixel));
1487 (void) CopyMagickString(symbol,p,MaxTextExtent);
1488 StripString(symbol);
1489 if (*symbol == '\0')
1493 case RedPixelChannel: return(QuantumScale*pixel.red);
1494 case GreenPixelChannel: return(QuantumScale*pixel.green);
1495 case BluePixelChannel: return(QuantumScale*pixel.blue);
1496 case BlackPixelChannel:
1498 if (image->colorspace != CMYKColorspace)
1500 (void) ThrowMagickException(exception,GetMagickModule(),
1501 ImageError,"ColorSeparatedImageRequired","`%s'",
1505 return(QuantumScale*pixel.black);
1507 case AlphaPixelChannel:
1512 if (pixel.matte == MagickFalse)
1514 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1517 case IndexPixelChannel:
1519 case IntensityPixelChannel:
1521 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1526 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1527 "UnableToParseExpression","`%s'",p);
1535 if (LocaleCompare(symbol,"a") == 0)
1536 return((MagickRealType) (QuantumScale*pixel.alpha));
1542 if (LocaleCompare(symbol,"b") == 0)
1543 return(QuantumScale*pixel.blue);
1549 if (LocaleNCompare(symbol,"channel",7) == 0)
1557 flags=ParseGeometry(symbol+7,&channel_info);
1558 if (image->colorspace == CMYKColorspace)
1561 case CyanPixelChannel:
1563 if ((flags & RhoValue) == 0)
1565 return(channel_info.rho);
1567 case MagentaPixelChannel:
1569 if ((flags & SigmaValue) == 0)
1571 return(channel_info.sigma);
1573 case YellowPixelChannel:
1575 if ((flags & XiValue) == 0)
1577 return(channel_info.xi);
1579 case BlackPixelChannel:
1581 if ((flags & PsiValue) == 0)
1583 return(channel_info.psi);
1585 case AlphaPixelChannel:
1587 if ((flags & ChiValue) == 0)
1589 return(channel_info.chi);
1596 case RedPixelChannel:
1598 if ((flags & RhoValue) == 0)
1600 return(channel_info.rho);
1602 case GreenPixelChannel:
1604 if ((flags & SigmaValue) == 0)
1606 return(channel_info.sigma);
1608 case BluePixelChannel:
1610 if ((flags & XiValue) == 0)
1612 return(channel_info.xi);
1614 case BlackPixelChannel:
1616 if ((flags & ChiValue) == 0)
1618 return(channel_info.chi);
1620 case AlphaPixelChannel:
1622 if ((flags & PsiValue) == 0)
1624 return(channel_info.psi);
1631 if (LocaleCompare(symbol,"c") == 0)
1632 return(QuantumScale*pixel.red);
1638 if (LocaleNCompare(symbol,"depth",5) == 0)
1639 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1645 if (LocaleCompare(symbol,"g") == 0)
1646 return(QuantumScale*pixel.green);
1652 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1653 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1654 if (LocaleCompare(symbol,"k") == 0)
1656 if (image->colorspace != CMYKColorspace)
1658 (void) ThrowMagickException(exception,GetMagickModule(),
1659 OptionError,"ColorSeparatedImageRequired","`%s'",
1663 return(QuantumScale*pixel.black);
1670 if (LocaleCompare(symbol,"h") == 0)
1671 return((MagickRealType) image->rows);
1672 if (LocaleCompare(symbol,"hue") == 0)
1679 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1688 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1689 (LocaleCompare(symbol,"image.minima") == 0) ||
1690 (LocaleCompare(symbol,"image.maxima") == 0) ||
1691 (LocaleCompare(symbol,"image.mean") == 0) ||
1692 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1693 (LocaleCompare(symbol,"image.skewness") == 0) ||
1694 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1695 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1696 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1697 return(image->resolution.x);
1698 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1699 return(image->resolution.y);
1700 if (LocaleCompare(symbol,"intensity") == 0)
1701 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1702 if (LocaleCompare(symbol,"i") == 0)
1703 return((MagickRealType) x);
1709 if (LocaleCompare(symbol,"j") == 0)
1710 return((MagickRealType) y);
1716 if (LocaleCompare(symbol,"lightness") == 0)
1723 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1727 if (LocaleCompare(symbol,"luminance") == 0)
1732 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1733 return(QuantumScale*luminence);
1740 if (LocaleNCompare(symbol,"maxima",6) == 0)
1741 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1742 if (LocaleNCompare(symbol,"mean",4) == 0)
1743 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1744 if (LocaleNCompare(symbol,"minima",6) == 0)
1745 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1746 if (LocaleCompare(symbol,"m") == 0)
1747 return(QuantumScale*pixel.blue);
1753 if (LocaleCompare(symbol,"n") == 0)
1754 return((MagickRealType) GetImageListLength(fx_info->images));
1760 if (LocaleCompare(symbol,"o") == 0)
1761 return(QuantumScale*pixel.alpha);
1767 if (LocaleCompare(symbol,"page.height") == 0)
1768 return((MagickRealType) image->page.height);
1769 if (LocaleCompare(symbol,"page.width") == 0)
1770 return((MagickRealType) image->page.width);
1771 if (LocaleCompare(symbol,"page.x") == 0)
1772 return((MagickRealType) image->page.x);
1773 if (LocaleCompare(symbol,"page.y") == 0)
1774 return((MagickRealType) image->page.y);
1780 if (LocaleCompare(symbol,"resolution.x") == 0)
1781 return(image->resolution.x);
1782 if (LocaleCompare(symbol,"resolution.y") == 0)
1783 return(image->resolution.y);
1784 if (LocaleCompare(symbol,"r") == 0)
1785 return(QuantumScale*pixel.red);
1791 if (LocaleCompare(symbol,"saturation") == 0)
1798 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1802 if (LocaleNCompare(symbol,"skewness",8) == 0)
1803 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1804 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1805 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1811 if (LocaleCompare(symbol,"t") == 0)
1812 return((MagickRealType) GetImageIndexInList(fx_info->images));
1818 if (LocaleCompare(symbol,"w") == 0)
1819 return((MagickRealType) image->columns);
1825 if (LocaleCompare(symbol,"y") == 0)
1826 return(QuantumScale*pixel.green);
1832 if (LocaleCompare(symbol,"z") == 0)
1837 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1845 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1846 if (value != (const char *) NULL)
1847 return((MagickRealType) StringToDouble(value,(char **) NULL));
1848 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1849 "UnableToParseExpression","`%s'",symbol);
1853 static const char *FxOperatorPrecedence(const char *expression,
1854 ExceptionInfo *exception)
1858 UndefinedPrecedence,
1860 BitwiseComplementPrecedence,
1862 ExponentialNotationPrecedence,
1866 RelationalPrecedence,
1867 EquivalencyPrecedence,
1868 BitwiseAndPrecedence,
1869 BitwiseOrPrecedence,
1870 LogicalAndPrecedence,
1871 LogicalOrPrecedence,
1873 AssignmentPrecedence,
1893 subexpression=(const char *) NULL;
1894 target=NullPrecedence;
1895 while (*expression != '\0')
1897 precedence=UndefinedPrecedence;
1898 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1903 switch (*expression)
1908 #if defined(MAGICKCORE_HAVE_ACOSH)
1909 if (LocaleNCompare(expression,"acosh",5) == 0)
1915 #if defined(MAGICKCORE_HAVE_ASINH)
1916 if (LocaleNCompare(expression,"asinh",5) == 0)
1922 #if defined(MAGICKCORE_HAVE_ATANH)
1923 if (LocaleNCompare(expression,"atanh",5) == 0)
1934 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1935 (LocaleNCompare(expression,"E-",2) == 0))
1937 expression+=2; /* scientific notation */
1944 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1945 (LocaleNCompare(expression,"j1",2) == 0))
1954 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1961 if ((c == (int) '{') || (c == (int) '['))
1964 if ((c == (int) '}') || (c == (int) ']'))
1967 switch ((unsigned char) *expression)
1972 precedence=BitwiseComplementPrecedence;
1978 precedence=ExponentPrecedence;
1983 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1984 (strchr(")",c) != (char *) NULL))) &&
1985 (((islower((int) ((char) *expression)) != 0) ||
1986 (strchr("(",(int) *expression) != (char *) NULL)) ||
1987 ((isdigit((int) ((char) c)) == 0) &&
1988 (isdigit((int) ((char) *expression)) != 0))) &&
1989 (strchr("xy",(int) *expression) == (char *) NULL))
1990 precedence=MultiplyPrecedence;
1997 precedence=MultiplyPrecedence;
2003 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2005 precedence=AdditionPrecedence;
2008 case LeftShiftOperator:
2009 case RightShiftOperator:
2011 precedence=ShiftPrecedence;
2015 case LessThanEqualOperator:
2016 case GreaterThanEqualOperator:
2019 precedence=RelationalPrecedence;
2023 case NotEqualOperator:
2025 precedence=EquivalencyPrecedence;
2030 precedence=BitwiseAndPrecedence;
2035 precedence=BitwiseOrPrecedence;
2038 case LogicalAndOperator:
2040 precedence=LogicalAndPrecedence;
2043 case LogicalOrOperator:
2045 precedence=LogicalOrPrecedence;
2048 case ExponentialNotation:
2050 precedence=ExponentialNotationPrecedence;
2056 precedence=TernaryPrecedence;
2061 precedence=AssignmentPrecedence;
2066 precedence=CommaPrecedence;
2071 precedence=SeparatorPrecedence;
2075 if ((precedence == BitwiseComplementPrecedence) ||
2076 (precedence == TernaryPrecedence) ||
2077 (precedence == AssignmentPrecedence))
2079 if (precedence > target)
2082 Right-to-left associativity.
2085 subexpression=expression;
2089 if (precedence >= target)
2092 Left-to-right associativity.
2095 subexpression=expression;
2097 if (strchr("(",(int) *expression) != (char *) NULL)
2098 expression=FxSubexpression(expression,exception);
2099 c=(int) (*expression++);
2101 return(subexpression);
2104 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2105 const PixelChannel channel,const ssize_t x,const ssize_t y,
2106 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2110 subexpression[MaxTextExtent];
2120 if (exception->severity != UndefinedException)
2122 while (isspace((int) *expression) != 0)
2124 if (*expression == '\0')
2126 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2127 "MissingExpression","`%s'",expression);
2130 *subexpression='\0';
2131 p=FxOperatorPrecedence(expression,exception);
2132 if (p != (const char *) NULL)
2134 (void) CopyMagickString(subexpression,expression,(size_t)
2136 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2138 switch ((unsigned char) *p)
2142 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2143 *beta=(MagickRealType) (~(size_t) *beta);
2148 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2149 return(*beta == 0.0 ? 1.0 : 0.0);
2153 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2154 channel,x,y,++p,beta,exception));
2158 case ExponentialNotation:
2160 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2161 return(alpha*(*beta));
2165 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2168 if (exception->severity == UndefinedException)
2169 (void) ThrowMagickException(exception,GetMagickModule(),
2170 OptionError,"DivideByZero","`%s'",expression);
2173 return(alpha/(*beta));
2177 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2178 *beta=fabs(floor(((double) *beta)+0.5));
2181 (void) ThrowMagickException(exception,GetMagickModule(),
2182 OptionError,"DivideByZero","`%s'",expression);
2185 return(fmod((double) alpha,(double) *beta));
2189 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2190 return(alpha+(*beta));
2194 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2195 return(alpha-(*beta));
2197 case LeftShiftOperator:
2199 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2200 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
2203 case RightShiftOperator:
2205 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2206 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
2211 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2212 return(alpha < *beta ? 1.0 : 0.0);
2214 case LessThanEqualOperator:
2216 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2217 return(alpha <= *beta ? 1.0 : 0.0);
2221 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2222 return(alpha > *beta ? 1.0 : 0.0);
2224 case GreaterThanEqualOperator:
2226 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2227 return(alpha >= *beta ? 1.0 : 0.0);
2231 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2232 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2234 case NotEqualOperator:
2236 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2237 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2241 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2242 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
2247 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2248 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
2251 case LogicalAndOperator:
2253 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2254 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2257 case LogicalOrOperator:
2259 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2260 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2268 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2270 p=StringToken(":",&q);
2271 if (q == (char *) NULL)
2273 (void) ThrowMagickException(exception,GetMagickModule(),
2274 OptionError,"UnableToParseExpression","`%s'",subexpression);
2277 if (fabs((double) alpha) > MagickEpsilon)
2278 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2280 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2286 numeric[MaxTextExtent];
2289 while (isalpha((int) ((unsigned char) *q)) != 0)
2293 (void) ThrowMagickException(exception,GetMagickModule(),
2294 OptionError,"UnableToParseExpression","`%s'",subexpression);
2297 ClearMagickException(exception);
2298 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2299 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2301 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2302 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2303 subexpression),ConstantString(numeric));
2308 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2313 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2318 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2324 if (strchr("(",(int) *expression) != (char *) NULL)
2326 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2327 subexpression[strlen(subexpression)-1]='\0';
2328 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2332 switch (*expression)
2336 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2342 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2348 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2350 return((MagickRealType) (~(size_t) (gamma+0.5)));
2355 if (LocaleNCompare(expression,"abs",3) == 0)
2357 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2359 return((MagickRealType) fabs((double) alpha));
2361 #if defined(MAGICKCORE_HAVE_ACOSH)
2362 if (LocaleNCompare(expression,"acosh",5) == 0)
2364 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2366 return((MagickRealType) acosh((double) alpha));
2369 if (LocaleNCompare(expression,"acos",4) == 0)
2371 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2373 return((MagickRealType) acos((double) alpha));
2375 #if defined(MAGICKCORE_HAVE_J1)
2376 if (LocaleNCompare(expression,"airy",4) == 0)
2378 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2382 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2383 return(gamma*gamma);
2386 #if defined(MAGICKCORE_HAVE_ASINH)
2387 if (LocaleNCompare(expression,"asinh",5) == 0)
2389 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2391 return((MagickRealType) asinh((double) alpha));
2394 if (LocaleNCompare(expression,"asin",4) == 0)
2396 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2398 return((MagickRealType) asin((double) alpha));
2400 if (LocaleNCompare(expression,"alt",3) == 0)
2402 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2404 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2406 if (LocaleNCompare(expression,"atan2",5) == 0)
2408 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2410 return((MagickRealType) atan2((double) alpha,(double) *beta));
2412 #if defined(MAGICKCORE_HAVE_ATANH)
2413 if (LocaleNCompare(expression,"atanh",5) == 0)
2415 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2417 return((MagickRealType) atanh((double) alpha));
2420 if (LocaleNCompare(expression,"atan",4) == 0)
2422 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2424 return((MagickRealType) atan((double) alpha));
2426 if (LocaleCompare(expression,"a") == 0)
2427 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2433 if (LocaleCompare(expression,"b") == 0)
2434 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2440 if (LocaleNCompare(expression,"ceil",4) == 0)
2442 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2444 return((MagickRealType) ceil((double) alpha));
2446 if (LocaleNCompare(expression,"cosh",4) == 0)
2448 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2450 return((MagickRealType) cosh((double) alpha));
2452 if (LocaleNCompare(expression,"cos",3) == 0)
2454 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2456 return((MagickRealType) cos((double) alpha));
2458 if (LocaleCompare(expression,"c") == 0)
2459 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2465 if (LocaleNCompare(expression,"debug",5) == 0)
2470 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2472 if (fx_info->images->colorspace == CMYKColorspace)
2475 case CyanPixelChannel: type="cyan"; break;
2476 case MagentaPixelChannel: type="magenta"; break;
2477 case YellowPixelChannel: type="yellow"; break;
2478 case AlphaPixelChannel: type="opacity"; break;
2479 case BlackPixelChannel: type="black"; break;
2480 default: type="unknown"; break;
2485 case RedPixelChannel: type="red"; break;
2486 case GreenPixelChannel: type="green"; break;
2487 case BluePixelChannel: type="blue"; break;
2488 case AlphaPixelChannel: type="opacity"; break;
2489 default: type="unknown"; break;
2491 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2492 if (strlen(subexpression) > 1)
2493 subexpression[strlen(subexpression)-1]='\0';
2494 if (fx_info->file != (FILE *) NULL)
2495 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2496 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2497 subexpression,GetMagickPrecision(),(double) alpha);
2500 if (LocaleNCompare(expression,"drc",3) == 0)
2502 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2504 return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0)));
2511 if (LocaleCompare(expression,"epsilon") == 0)
2512 return((MagickRealType) MagickEpsilon);
2513 if (LocaleNCompare(expression,"exp",3) == 0)
2515 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2517 return((MagickRealType) exp((double) alpha));
2519 if (LocaleCompare(expression,"e") == 0)
2520 return((MagickRealType) 2.7182818284590452354);
2526 if (LocaleNCompare(expression,"floor",5) == 0)
2528 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2530 return((MagickRealType) floor((double) alpha));
2537 if (LocaleNCompare(expression,"gauss",5) == 0)
2539 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2541 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2542 return((MagickRealType) gamma);
2544 if (LocaleNCompare(expression,"gcd",3) == 0)
2549 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2551 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2553 return((MagickRealType) gcd);
2555 if (LocaleCompare(expression,"g") == 0)
2556 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2562 if (LocaleCompare(expression,"h") == 0)
2563 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2564 if (LocaleCompare(expression,"hue") == 0)
2565 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2566 if (LocaleNCompare(expression,"hypot",5) == 0)
2568 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2570 return((MagickRealType) hypot((double) alpha,(double) *beta));
2577 if (LocaleCompare(expression,"k") == 0)
2578 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2584 if (LocaleCompare(expression,"intensity") == 0)
2585 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2586 if (LocaleNCompare(expression,"int",3) == 0)
2588 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2590 return((MagickRealType) floor(alpha));
2592 #if defined(MAGICKCORE_HAVE_ISNAN)
2593 if (LocaleNCompare(expression,"isnan",5) == 0)
2595 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2597 return((MagickRealType) !!isnan((double) alpha));
2600 if (LocaleCompare(expression,"i") == 0)
2601 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2607 if (LocaleCompare(expression,"j") == 0)
2608 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2609 #if defined(MAGICKCORE_HAVE_J0)
2610 if (LocaleNCompare(expression,"j0",2) == 0)
2612 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2614 return((MagickRealType) j0((double) alpha));
2617 #if defined(MAGICKCORE_HAVE_J1)
2618 if (LocaleNCompare(expression,"j1",2) == 0)
2620 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2622 return((MagickRealType) j1((double) alpha));
2625 #if defined(MAGICKCORE_HAVE_J1)
2626 if (LocaleNCompare(expression,"jinc",4) == 0)
2628 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2632 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
2642 if (LocaleNCompare(expression,"ln",2) == 0)
2644 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2646 return((MagickRealType) log((double) alpha));
2648 if (LocaleNCompare(expression,"logtwo",6) == 0)
2650 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2652 return((MagickRealType) log10((double) alpha))/log10(2.0);
2654 if (LocaleNCompare(expression,"log",3) == 0)
2656 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2658 return((MagickRealType) log10((double) alpha));
2660 if (LocaleCompare(expression,"lightness") == 0)
2661 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2667 if (LocaleCompare(expression,"MaxRGB") == 0)
2668 return((MagickRealType) QuantumRange);
2669 if (LocaleNCompare(expression,"maxima",6) == 0)
2671 if (LocaleNCompare(expression,"max",3) == 0)
2673 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2675 return(alpha > *beta ? alpha : *beta);
2677 if (LocaleNCompare(expression,"minima",6) == 0)
2679 if (LocaleNCompare(expression,"min",3) == 0)
2681 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2683 return(alpha < *beta ? alpha : *beta);
2685 if (LocaleNCompare(expression,"mod",3) == 0)
2687 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2689 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2692 if (LocaleCompare(expression,"m") == 0)
2693 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2699 if (LocaleNCompare(expression,"not",3) == 0)
2701 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2703 return((MagickRealType) (alpha < MagickEpsilon));
2705 if (LocaleCompare(expression,"n") == 0)
2706 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2712 if (LocaleCompare(expression,"Opaque") == 0)
2714 if (LocaleCompare(expression,"o") == 0)
2715 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2721 if (LocaleCompare(expression,"phi") == 0)
2722 return((MagickRealType) MagickPHI);
2723 if (LocaleCompare(expression,"pi") == 0)
2724 return((MagickRealType) MagickPI);
2725 if (LocaleNCompare(expression,"pow",3) == 0)
2727 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2729 return((MagickRealType) pow((double) alpha,(double) *beta));
2731 if (LocaleCompare(expression,"p") == 0)
2732 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2738 if (LocaleCompare(expression,"QuantumRange") == 0)
2739 return((MagickRealType) QuantumRange);
2740 if (LocaleCompare(expression,"QuantumScale") == 0)
2741 return((MagickRealType) QuantumScale);
2747 if (LocaleNCompare(expression,"rand",4) == 0)
2748 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2749 if (LocaleNCompare(expression,"round",5) == 0)
2751 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2753 return((MagickRealType) floor((double) alpha+0.5));
2755 if (LocaleCompare(expression,"r") == 0)
2756 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2762 if (LocaleCompare(expression,"saturation") == 0)
2763 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2764 if (LocaleNCompare(expression,"sign",4) == 0)
2766 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2768 return(alpha < 0.0 ? -1.0 : 1.0);
2770 if (LocaleNCompare(expression,"sinc",4) == 0)
2772 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2776 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2780 if (LocaleNCompare(expression,"sinh",4) == 0)
2782 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2784 return((MagickRealType) sinh((double) alpha));
2786 if (LocaleNCompare(expression,"sin",3) == 0)
2788 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2790 return((MagickRealType) sin((double) alpha));
2792 if (LocaleNCompare(expression,"sqrt",4) == 0)
2794 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2796 return((MagickRealType) sqrt((double) alpha));
2798 if (LocaleNCompare(expression,"squish",6) == 0)
2800 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2802 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2804 if (LocaleCompare(expression,"s") == 0)
2805 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2811 if (LocaleNCompare(expression,"tanh",4) == 0)
2813 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2815 return((MagickRealType) tanh((double) alpha));
2817 if (LocaleNCompare(expression,"tan",3) == 0)
2819 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2821 return((MagickRealType) tan((double) alpha));
2823 if (LocaleCompare(expression,"Transparent") == 0)
2825 if (LocaleNCompare(expression,"trunc",5) == 0)
2827 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2830 return((MagickRealType) floor((double) alpha));
2831 return((MagickRealType) ceil((double) alpha));
2833 if (LocaleCompare(expression,"t") == 0)
2834 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2840 if (LocaleCompare(expression,"u") == 0)
2841 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2847 if (LocaleCompare(expression,"v") == 0)
2848 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2854 if (LocaleNCompare(expression,"while",5) == 0)
2858 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2860 } while (fabs((double) alpha) >= MagickEpsilon);
2861 return((MagickRealType) *beta);
2863 if (LocaleCompare(expression,"w") == 0)
2864 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2870 if (LocaleCompare(expression,"y") == 0)
2871 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2877 if (LocaleCompare(expression,"z") == 0)
2878 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2884 q=(char *) expression;
2885 alpha=InterpretSiPrefixValue(expression,&q);
2886 if (q == expression)
2887 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2891 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2892 MagickRealType *alpha,ExceptionInfo *exception)
2897 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2902 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2903 MagickRealType *alpha,ExceptionInfo *exception)
2912 fx_info->file=(FILE *) NULL;
2913 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2919 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2920 const PixelChannel channel,const ssize_t x,const ssize_t y,
2921 MagickRealType *alpha,ExceptionInfo *exception)
2927 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2929 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2943 % FxImage() applies a mathematical expression to the specified image.
2945 % The format of the FxImage method is:
2947 % Image *FxImage(const Image *image,const char *expression,
2948 % ExceptionInfo *exception)
2950 % A description of each parameter follows:
2952 % o image: the image.
2954 % o expression: A mathematical expression.
2956 % o exception: return any errors or warnings in this structure.
2960 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2965 assert(fx_info != (FxInfo **) NULL);
2966 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2967 if (fx_info[i] != (FxInfo *) NULL)
2968 fx_info[i]=DestroyFxInfo(fx_info[i]);
2969 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2973 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2974 ExceptionInfo *exception)
2991 number_threads=GetOpenMPMaximumThreads();
2992 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2993 if (fx_info == (FxInfo **) NULL)
2994 return((FxInfo **) NULL);
2995 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2996 if (*expression != '@')
2997 fx_expression=ConstantString(expression);
2999 fx_expression=FileToString(expression+1,~0,exception);
3000 for (i=0; i < (ssize_t) number_threads; i++)
3002 fx_info[i]=AcquireFxInfo(image,fx_expression);
3003 if (fx_info[i] == (FxInfo *) NULL)
3004 return(DestroyFxThreadSet(fx_info));
3005 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
3007 fx_expression=DestroyString(fx_expression);
3011 MagickExport Image *FxImage(const Image *image,const char *expression,
3012 ExceptionInfo *exception)
3014 #define FxImageTag "Fx/Image"
3038 assert(image != (Image *) NULL);
3039 assert(image->signature == MagickSignature);
3040 if (image->debug != MagickFalse)
3041 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3042 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3043 if (fx_image == (Image *) NULL)
3044 return((Image *) NULL);
3045 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3047 fx_image=DestroyImage(fx_image);
3048 return((Image *) NULL);
3050 fx_info=AcquireFxThreadSet(image,expression,exception);
3051 if (fx_info == (FxInfo **) NULL)
3053 fx_image=DestroyImage(fx_image);
3054 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3056 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3057 if (status == MagickFalse)
3059 fx_image=DestroyImage(fx_image);
3060 fx_info=DestroyFxThreadSet(fx_info);
3061 return((Image *) NULL);
3068 image_view=AcquireCacheView(image);
3069 fx_view=AcquireCacheView(fx_image);
3070 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3071 #pragma omp parallel for schedule(static,4) shared(progress,status)
3073 for (y=0; y < (ssize_t) fx_image->rows; y++)
3076 id = GetOpenMPThreadId();
3078 register const Quantum
3087 if (status == MagickFalse)
3089 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3090 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3091 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3096 for (x=0; x < (ssize_t) fx_image->columns; x++)
3101 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3113 channel=GetPixelChannelMapChannel(image,i);
3114 traits=GetPixelChannelMapTraits(image,channel);
3115 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3116 if ((traits == UndefinedPixelTrait) ||
3117 (fx_traits == UndefinedPixelTrait))
3119 if (((fx_traits & CopyPixelTrait) != 0) ||
3120 (GetPixelMask(image,p) != 0))
3122 SetPixelChannel(fx_image,channel,p[i],q);
3126 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3128 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3130 p+=GetPixelChannels(image);
3131 q+=GetPixelChannels(fx_image);
3133 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3135 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3140 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3141 #pragma omp critical (MagickCore_FxImage)
3143 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3144 if (proceed == MagickFalse)
3148 fx_view=DestroyCacheView(fx_view);
3149 image_view=DestroyCacheView(image_view);
3150 fx_info=DestroyFxThreadSet(fx_info);
3151 if (status == MagickFalse)
3152 fx_image=DestroyImage(fx_image);
3157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3161 % I m p l o d e I m a g e %
3165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3167 % ImplodeImage() creates a new image that is a copy of an existing
3168 % one with the image pixels "implode" by the specified percentage. It
3169 % allocates the memory necessary for the new Image structure and returns a
3170 % pointer to the new image.
3172 % The format of the ImplodeImage method is:
3174 % Image *ImplodeImage(const Image *image,const double amount,
3175 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3177 % A description of each parameter follows:
3179 % o implode_image: Method ImplodeImage returns a pointer to the image
3180 % after it is implode. A null image is returned if there is a memory
3183 % o image: the image.
3185 % o amount: Define the extent of the implosion.
3187 % o method: the pixel interpolation method.
3189 % o exception: return any errors or warnings in this structure.
3192 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3193 const PixelInterpolateMethod method,ExceptionInfo *exception)
3195 #define ImplodeImageTag "Implode/Image"
3221 Initialize implode image attributes.
3223 assert(image != (Image *) NULL);
3224 assert(image->signature == MagickSignature);
3225 if (image->debug != MagickFalse)
3226 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3227 assert(exception != (ExceptionInfo *) NULL);
3228 assert(exception->signature == MagickSignature);
3229 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3231 if (implode_image == (Image *) NULL)
3232 return((Image *) NULL);
3233 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3235 implode_image=DestroyImage(implode_image);
3236 return((Image *) NULL);
3238 if (implode_image->background_color.alpha != OpaqueAlpha)
3239 implode_image->matte=MagickTrue;
3241 Compute scaling factor.
3245 center.x=0.5*image->columns;
3246 center.y=0.5*image->rows;
3248 if (image->columns > image->rows)
3249 scale.y=(double) image->columns/(double) image->rows;
3251 if (image->columns < image->rows)
3253 scale.x=(double) image->rows/(double) image->columns;
3261 image_view=AcquireCacheView(image);
3262 implode_view=AcquireCacheView(implode_image);
3263 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3264 #pragma omp parallel for schedule(static,4) shared(progress,status)
3266 for (y=0; y < (ssize_t) image->rows; y++)
3274 register const Quantum
3283 if (status == MagickFalse)
3285 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3286 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3288 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3293 delta.y=scale.y*(double) (y-center.y);
3294 for (x=0; x < (ssize_t) image->columns; x++)
3300 Determine if the pixel is within an ellipse.
3302 if (GetPixelMask(image,p) != 0)
3304 p+=GetPixelChannels(image);
3305 q+=GetPixelChannels(implode_image);
3308 delta.x=scale.x*(double) (x-center.x);
3309 distance=delta.x*delta.x+delta.y*delta.y;
3310 if (distance >= (radius*radius))
3311 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3320 channel=GetPixelChannelMapChannel(image,i);
3321 traits=GetPixelChannelMapTraits(image,channel);
3322 implode_traits=GetPixelChannelMapTraits(implode_image,channel);
3323 if ((traits == UndefinedPixelTrait) ||
3324 (implode_traits == UndefinedPixelTrait))
3326 SetPixelChannel(implode_image,channel,p[i],q);
3338 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3340 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3341 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3342 scale.y+center.y),q,exception);
3344 p+=GetPixelChannels(image);
3345 q+=GetPixelChannels(implode_image);
3347 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3349 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3354 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3355 #pragma omp critical (MagickCore_ImplodeImage)
3357 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3358 if (proceed == MagickFalse)
3362 implode_view=DestroyCacheView(implode_view);
3363 image_view=DestroyCacheView(image_view);
3364 if (status == MagickFalse)
3365 implode_image=DestroyImage(implode_image);
3366 return(implode_image);
3370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3374 % M o r p h I m a g e s %
3378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3380 % The MorphImages() method requires a minimum of two images. The first
3381 % image is transformed into the second by a number of intervening images
3382 % as specified by frames.
3384 % The format of the MorphImage method is:
3386 % Image *MorphImages(const Image *image,const size_t number_frames,
3387 % ExceptionInfo *exception)
3389 % A description of each parameter follows:
3391 % o image: the image.
3393 % o number_frames: Define the number of in-between image to generate.
3394 % The more in-between frames, the smoother the morph.
3396 % o exception: return any errors or warnings in this structure.
3399 MagickExport Image *MorphImages(const Image *image,
3400 const size_t number_frames,ExceptionInfo *exception)
3402 #define MorphImageTag "Morph/Image"
3418 register const Image
3428 Clone first frame in sequence.
3430 assert(image != (Image *) NULL);
3431 assert(image->signature == MagickSignature);
3432 if (image->debug != MagickFalse)
3433 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3434 assert(exception != (ExceptionInfo *) NULL);
3435 assert(exception->signature == MagickSignature);
3436 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3437 if (morph_images == (Image *) NULL)
3438 return((Image *) NULL);
3439 if (GetNextImageInList(image) == (Image *) NULL)
3444 for (i=1; i < (ssize_t) number_frames; i++)
3446 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3447 if (morph_image == (Image *) NULL)
3449 morph_images=DestroyImageList(morph_images);
3450 return((Image *) NULL);
3452 AppendImageToList(&morph_images,morph_image);
3453 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3458 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3460 if (proceed == MagickFalse)
3464 return(GetFirstImageInList(morph_images));
3467 Morph image sequence.
3472 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3474 for (i=0; i < (ssize_t) number_frames; i++)
3480 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3482 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3483 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
3484 GetNextImageInList(next)->rows+0.5),next->filter,exception);
3485 if (morph_image == (Image *) NULL)
3487 morph_images=DestroyImageList(morph_images);
3488 return((Image *) NULL);
3490 status=SetImageStorageClass(morph_image,DirectClass,exception);
3491 if (status == MagickFalse)
3493 morph_image=DestroyImage(morph_image);
3494 return((Image *) NULL);
3496 AppendImageToList(&morph_images,morph_image);
3497 morph_images=GetLastImageInList(morph_images);
3498 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3499 morph_images->rows,GetNextImageInList(next)->filter,exception);
3500 if (morph_image == (Image *) NULL)
3502 morph_images=DestroyImageList(morph_images);
3503 return((Image *) NULL);
3505 image_view=AcquireCacheView(morph_image);
3506 morph_view=AcquireCacheView(morph_images);
3507 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3508 #pragma omp parallel for schedule(static,4) shared(status)
3510 for (y=0; y < (ssize_t) morph_images->rows; y++)
3515 register const Quantum
3524 if (status == MagickFalse)
3526 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3528 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3530 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3535 for (x=0; x < (ssize_t) morph_images->columns; x++)
3540 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
3549 channel=GetPixelChannelMapChannel(image,i);
3550 traits=GetPixelChannelMapTraits(image,channel);
3551 morph_traits=GetPixelChannelMapTraits(morph_image,channel);
3552 if ((traits == UndefinedPixelTrait) ||
3553 (morph_traits == UndefinedPixelTrait))
3555 if (((morph_traits & CopyPixelTrait) != 0) ||
3556 (GetPixelMask(image,p) != 0))
3558 SetPixelChannel(morph_image,channel,p[i],q);
3561 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3562 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3564 p+=GetPixelChannels(morph_image);
3565 q+=GetPixelChannels(morph_images);
3567 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3568 if (sync == MagickFalse)
3571 morph_view=DestroyCacheView(morph_view);
3572 image_view=DestroyCacheView(image_view);
3573 morph_image=DestroyImage(morph_image);
3575 if (i < (ssize_t) number_frames)
3578 Clone last frame in sequence.
3580 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3581 if (morph_image == (Image *) NULL)
3583 morph_images=DestroyImageList(morph_images);
3584 return((Image *) NULL);
3586 AppendImageToList(&morph_images,morph_image);
3587 morph_images=GetLastImageInList(morph_images);
3588 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3593 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3594 #pragma omp critical (MagickCore_MorphImages)
3596 proceed=SetImageProgress(image,MorphImageTag,scene,
3597 GetImageListLength(image));
3598 if (proceed == MagickFalse)
3603 if (GetNextImageInList(next) != (Image *) NULL)
3605 morph_images=DestroyImageList(morph_images);
3606 return((Image *) NULL);
3608 return(GetFirstImageInList(morph_images));
3612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3616 % P l a s m a I m a g e %
3620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3622 % PlasmaImage() initializes an image with plasma fractal values. The image
3623 % must be initialized with a base color and the random number generator
3624 % seeded before this method is called.
3626 % The format of the PlasmaImage method is:
3628 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3629 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3631 % A description of each parameter follows:
3633 % o image: the image.
3635 % o segment: Define the region to apply plasma fractals values.
3637 % o attenuate: Define the plasma attenuation factor.
3639 % o depth: Limit the plasma recursion depth.
3641 % o exception: return any errors or warnings in this structure.
3645 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3646 const MagickRealType pixel,const MagickRealType noise)
3651 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3656 static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3657 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3658 const SegmentInfo *segment,size_t attenuate,size_t depth,
3659 ExceptionInfo *exception)
3670 register const Quantum
3686 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3694 Divide the area into quadrants and recurse.
3698 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3699 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3700 local_info=(*segment);
3701 local_info.x2=(double) x_mid;
3702 local_info.y2=(double) y_mid;
3703 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3704 &local_info,attenuate,depth,exception);
3705 local_info=(*segment);
3706 local_info.y1=(double) y_mid;
3707 local_info.x2=(double) x_mid;
3708 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3709 &local_info,attenuate,depth,exception);
3710 local_info=(*segment);
3711 local_info.x1=(double) x_mid;
3712 local_info.y2=(double) y_mid;
3713 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3714 &local_info,attenuate,depth,exception);
3715 local_info=(*segment);
3716 local_info.x1=(double) x_mid;
3717 local_info.y1=(double) y_mid;
3718 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3719 &local_info,attenuate,depth,exception));
3721 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3722 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3723 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3724 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3725 return(MagickFalse);
3727 Average pixels and apply plasma.
3729 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3730 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3735 x=(ssize_t) ceil(segment->x1-0.5);
3736 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3738 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3740 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3741 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3742 (q == (Quantum *) NULL))
3744 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3746 channel=GetPixelChannelMapChannel(image,i);
3747 traits=GetPixelChannelMapTraits(image,channel);
3748 if (traits == UndefinedPixelTrait)
3750 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3752 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3753 if (segment->x1 != segment->x2)
3758 x=(ssize_t) ceil(segment->x2-0.5);
3759 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3761 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3763 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3764 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3765 (q == (Quantum *) NULL))
3767 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3769 channel=GetPixelChannelMapChannel(image,i);
3770 traits=GetPixelChannelMapTraits(image,channel);
3771 if (traits == UndefinedPixelTrait)
3773 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3775 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3778 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3780 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3785 y=(ssize_t) ceil(segment->y2-0.5);
3786 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3788 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3790 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3791 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3792 (q == (Quantum *) NULL))
3794 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3796 channel=GetPixelChannelMapChannel(image,i);
3797 traits=GetPixelChannelMapTraits(image,channel);
3798 if (traits == UndefinedPixelTrait)
3800 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3802 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3804 if (segment->y1 != segment->y2)
3809 y=(ssize_t) ceil(segment->y1-0.5);
3810 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3812 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3814 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3815 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3816 (q == (Quantum *) NULL))
3818 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3820 channel=GetPixelChannelMapChannel(image,i);
3821 traits=GetPixelChannelMapTraits(image,channel);
3822 if (traits == UndefinedPixelTrait)
3824 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3826 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3829 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3834 x=(ssize_t) ceil(segment->x1-0.5);
3835 y=(ssize_t) ceil(segment->y1-0.5);
3836 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
3837 x=(ssize_t) ceil(segment->x2-0.5);
3838 y=(ssize_t) ceil(segment->y2-0.5);
3839 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
3840 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3841 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3842 (q == (Quantum *) NULL))
3844 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3846 channel=GetPixelChannelMapChannel(image,i);
3847 traits=GetPixelChannelMapTraits(image,channel);
3848 if (traits == UndefinedPixelTrait)
3850 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3852 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3854 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3856 return(MagickFalse);
3859 MagickExport MagickBooleanType PlasmaImage(Image *image,
3860 const SegmentInfo *segment,size_t attenuate,size_t depth,
3861 ExceptionInfo *exception)
3874 if (image->debug != MagickFalse)
3875 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3876 assert(image != (Image *) NULL);
3877 assert(image->signature == MagickSignature);
3878 if (image->debug != MagickFalse)
3879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3880 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3881 return(MagickFalse);
3882 image_view=AcquireCacheView(image);
3883 u_view=AcquireCacheView(image);
3884 v_view=AcquireCacheView(image);
3885 random_info=AcquireRandomInfo();
3886 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3887 attenuate,depth,exception);
3888 random_info=DestroyRandomInfo(random_info);
3889 v_view=DestroyCacheView(v_view);
3890 u_view=DestroyCacheView(u_view);
3891 image_view=DestroyCacheView(image_view);
3896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3900 % P o l a r o i d I m a g e %
3904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3906 % PolaroidImage() simulates a Polaroid picture.
3908 % The format of the AnnotateImage method is:
3910 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3911 % const char *caption,const double angle,
3912 % const PixelInterpolateMethod method,ExceptionInfo exception)
3914 % A description of each parameter follows:
3916 % o image: the image.
3918 % o draw_info: the draw info.
3920 % o caption: the Polaroid caption.
3922 % o angle: Apply the effect along this angle.
3924 % o method: the pixel interpolation method.
3926 % o exception: return any errors or warnings in this structure.
3929 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3930 const char *caption,const double angle,const PixelInterpolateMethod method,
3931 ExceptionInfo *exception)
3949 Simulate a Polaroid picture.
3951 assert(image != (Image *) NULL);
3952 assert(image->signature == MagickSignature);
3953 if (image->debug != MagickFalse)
3954 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3955 assert(exception != (ExceptionInfo *) NULL);
3956 assert(exception->signature == MagickSignature);
3957 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3958 image->rows)/25.0,10.0);
3959 height=image->rows+2*quantum;
3960 caption_image=(Image *) NULL;
3961 if (caption != (const char *) NULL)
3964 geometry[MaxTextExtent],
3980 Generate caption image.
3982 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3983 if (caption_image == (Image *) NULL)
3984 return((Image *) NULL);
3985 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3986 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3988 (void) CloneString(&annotate_info->text,text);
3989 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3991 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
3992 (metrics.ascent-metrics.descent)+0.5),exception);
3993 if (status == MagickFalse)
3994 caption_image=DestroyImage(caption_image);
3997 caption_image->background_color=image->border_color;
3998 (void) SetImageBackgroundColor(caption_image,exception);
3999 (void) CloneString(&annotate_info->text,text);
4000 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
4002 if (annotate_info->gravity == UndefinedGravity)
4003 (void) CloneString(&annotate_info->geometry,AcquireString(
4005 (void) AnnotateImage(caption_image,annotate_info,exception);
4006 height+=caption_image->rows;
4008 annotate_info=DestroyDrawInfo(annotate_info);
4009 text=DestroyString(text);
4011 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
4013 if (picture_image == (Image *) NULL)
4015 if (caption_image != (Image *) NULL)
4016 caption_image=DestroyImage(caption_image);
4017 return((Image *) NULL);
4019 picture_image->background_color=image->border_color;
4020 (void) SetImageBackgroundColor(picture_image,exception);
4021 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickFalse,quantum,
4023 if (caption_image != (Image *) NULL)
4025 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
4026 MagickFalse,quantum,(ssize_t) (image->rows+3*quantum/2),exception);
4027 caption_image=DestroyImage(caption_image);
4029 (void) QueryColorCompliance("none",AllCompliance,
4030 &picture_image->background_color,exception);
4031 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
4032 rotate_image=RotateImage(picture_image,90.0,exception);
4033 picture_image=DestroyImage(picture_image);
4034 if (rotate_image == (Image *) NULL)
4035 return((Image *) NULL);
4036 picture_image=rotate_image;
4037 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
4038 picture_image->columns,method,exception);
4039 picture_image=DestroyImage(picture_image);
4040 if (bend_image == (Image *) NULL)
4041 return((Image *) NULL);
4042 picture_image=bend_image;
4043 rotate_image=RotateImage(picture_image,-90.0,exception);
4044 picture_image=DestroyImage(picture_image);
4045 if (rotate_image == (Image *) NULL)
4046 return((Image *) NULL);
4047 picture_image=rotate_image;
4048 picture_image->background_color=image->background_color;
4049 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4051 if (polaroid_image == (Image *) NULL)
4053 picture_image=DestroyImage(picture_image);
4054 return(picture_image);
4056 flop_image=FlopImage(polaroid_image,exception);
4057 polaroid_image=DestroyImage(polaroid_image);
4058 if (flop_image == (Image *) NULL)
4060 picture_image=DestroyImage(picture_image);
4061 return(picture_image);
4063 polaroid_image=flop_image;
4064 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
4065 MagickFalse,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
4066 picture_image=DestroyImage(picture_image);
4067 (void) QueryColorCompliance("none",AllCompliance,
4068 &polaroid_image->background_color,exception);
4069 rotate_image=RotateImage(polaroid_image,angle,exception);
4070 polaroid_image=DestroyImage(polaroid_image);
4071 if (rotate_image == (Image *) NULL)
4072 return((Image *) NULL);
4073 polaroid_image=rotate_image;
4074 trim_image=TrimImage(polaroid_image,exception);
4075 polaroid_image=DestroyImage(polaroid_image);
4076 if (trim_image == (Image *) NULL)
4077 return((Image *) NULL);
4078 polaroid_image=trim_image;
4079 return(polaroid_image);
4083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4087 % S e p i a T o n e I m a g e %
4091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4093 % MagickSepiaToneImage() applies a special effect to the image, similar to the
4094 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4095 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4096 % threshold of 80% is a good starting point for a reasonable tone.
4098 % The format of the SepiaToneImage method is:
4100 % Image *SepiaToneImage(const Image *image,const double threshold,
4101 % ExceptionInfo *exception)
4103 % A description of each parameter follows:
4105 % o image: the image.
4107 % o threshold: the tone threshold.
4109 % o exception: return any errors or warnings in this structure.
4112 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4113 ExceptionInfo *exception)
4115 #define SepiaToneImageTag "SepiaTone/Image"
4134 Initialize sepia-toned image attributes.
4136 assert(image != (const Image *) NULL);
4137 assert(image->signature == MagickSignature);
4138 if (image->debug != MagickFalse)
4139 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4140 assert(exception != (ExceptionInfo *) NULL);
4141 assert(exception->signature == MagickSignature);
4142 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
4143 if (sepia_image == (Image *) NULL)
4144 return((Image *) NULL);
4145 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4147 sepia_image=DestroyImage(sepia_image);
4148 return((Image *) NULL);
4151 Tone each row of the image.
4155 image_view=AcquireCacheView(image);
4156 sepia_view=AcquireCacheView(sepia_image);
4157 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4158 #pragma omp parallel for schedule(static,4) shared(progress,status)
4160 for (y=0; y < (ssize_t) image->rows; y++)
4162 register const Quantum
4171 if (status == MagickFalse)
4173 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4174 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4176 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4181 for (x=0; x < (ssize_t) image->columns; x++)
4187 intensity=(MagickRealType) GetPixelIntensity(image,p);
4188 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4189 (MagickRealType) QuantumRange-threshold;
4190 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4191 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4192 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4193 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4194 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4195 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4197 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4198 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4199 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4200 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4201 p+=GetPixelChannels(image);
4202 q+=GetPixelChannels(sepia_image);
4204 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4206 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4211 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4212 #pragma omp critical (MagickCore_SepiaToneImage)
4214 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4216 if (proceed == MagickFalse)
4220 sepia_view=DestroyCacheView(sepia_view);
4221 image_view=DestroyCacheView(image_view);
4222 (void) NormalizeImage(sepia_image,exception);
4223 (void) ContrastImage(sepia_image,MagickTrue,exception);
4224 if (status == MagickFalse)
4225 sepia_image=DestroyImage(sepia_image);
4226 return(sepia_image);
4230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4234 % S h a d o w I m a g e %
4238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4240 % ShadowImage() simulates a shadow from the specified image and returns it.
4242 % The format of the ShadowImage method is:
4244 % Image *ShadowImage(const Image *image,const double alpha,
4245 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4246 % ExceptionInfo *exception)
4248 % A description of each parameter follows:
4250 % o image: the image.
4252 % o alpha: percentage transparency.
4254 % o sigma: the standard deviation of the Gaussian, in pixels.
4256 % o x_offset: the shadow x-offset.
4258 % o y_offset: the shadow y-offset.
4260 % o exception: return any errors or warnings in this structure.
4263 MagickExport Image *ShadowImage(const Image *image,const double alpha,
4264 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4265 ExceptionInfo *exception)
4267 #define ShadowImageTag "Shadow/Image"
4289 assert(image != (Image *) NULL);
4290 assert(image->signature == MagickSignature);
4291 if (image->debug != MagickFalse)
4292 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4293 assert(exception != (ExceptionInfo *) NULL);
4294 assert(exception->signature == MagickSignature);
4295 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4296 if (clone_image == (Image *) NULL)
4297 return((Image *) NULL);
4298 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod,
4300 border_info.width=(size_t) floor(2.0*sigma+0.5);
4301 border_info.height=(size_t) floor(2.0*sigma+0.5);
4304 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4306 clone_image->matte=MagickTrue;
4307 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
4308 clone_image=DestroyImage(clone_image);
4309 if (border_image == (Image *) NULL)
4310 return((Image *) NULL);
4311 if (border_image->matte == MagickFalse)
4312 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4317 image_view=AcquireCacheView(border_image);
4318 for (y=0; y < (ssize_t) border_image->rows; y++)
4329 if (status == MagickFalse)
4331 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4333 if (q == (Quantum *) NULL)
4338 background_color=border_image->background_color;
4339 background_color.matte=MagickTrue;
4340 for (x=0; x < (ssize_t) border_image->columns; x++)
4342 if (border_image->matte != MagickFalse)
4343 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4344 SetPixelInfoPixel(border_image,&background_color,q);
4345 q+=GetPixelChannels(border_image);
4347 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4350 image_view=DestroyCacheView(image_view);
4351 if (status == MagickFalse)
4353 border_image=DestroyImage(border_image);
4354 return((Image *) NULL);
4356 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4357 shadow_image=BlurImage(border_image,0.0,sigma,exception);
4358 border_image=DestroyImage(border_image);
4359 if (shadow_image == (Image *) NULL)
4360 return((Image *) NULL);
4361 (void) SetPixelChannelMapMask(shadow_image,channel_mask);
4362 if (shadow_image->page.width == 0)
4363 shadow_image->page.width=shadow_image->columns;
4364 if (shadow_image->page.height == 0)
4365 shadow_image->page.height=shadow_image->rows;
4366 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4367 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4368 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4369 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4370 return(shadow_image);
4374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4378 % S k e t c h I m a g e %
4382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4384 % SketchImage() simulates a pencil sketch. We convolve the image with a
4385 % Gaussian operator of the given radius and standard deviation (sigma). For
4386 % reasonable results, radius should be larger than sigma. Use a radius of 0
4387 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4390 % The format of the SketchImage method is:
4392 % Image *SketchImage(const Image *image,const double radius,
4393 % const double sigma,const double angle,ExceptionInfo *exception)
4395 % A description of each parameter follows:
4397 % o image: the image.
4399 % o radius: the radius of the Gaussian, in pixels, not counting the
4402 % o sigma: the standard deviation of the Gaussian, in pixels.
4404 % o angle: apply the effect along this angle.
4406 % o exception: return any errors or warnings in this structure.
4409 MagickExport Image *SketchImage(const Image *image,const double radius,
4410 const double sigma,const double angle,ExceptionInfo *exception)
4426 **restrict random_info;
4434 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4435 MagickTrue,exception);
4436 if (random_image == (Image *) NULL)
4437 return((Image *) NULL);
4439 random_info=AcquireRandomInfoThreadSet();
4440 random_view=AcquireCacheView(random_image);
4441 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4442 #pragma omp parallel for schedule(static,4) shared(status)
4444 for (y=0; y < (ssize_t) random_image->rows; y++)
4447 id = GetOpenMPThreadId();
4455 if (status == MagickFalse)
4457 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4459 if (q == (Quantum *) NULL)
4464 for (x=0; x < (ssize_t) random_image->columns; x++)
4472 if (GetPixelMask(random_image,q) != 0)
4474 q+=GetPixelChannels(random_image);
4477 value=GetPseudoRandomValue(random_info[id]);
4478 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4486 channel=GetPixelChannelMapChannel(image,i);
4487 traits=GetPixelChannelMapTraits(image,channel);
4488 if (traits == UndefinedPixelTrait)
4490 q[i]=ClampToQuantum(QuantumRange*value);
4492 q+=GetPixelChannels(random_image);
4494 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4497 random_view=DestroyCacheView(random_view);
4498 random_info=DestroyRandomInfoThreadSet(random_info);
4499 if (status == MagickFalse)
4501 random_image=DestroyImage(random_image);
4502 return(random_image);
4504 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4505 random_image=DestroyImage(random_image);
4506 if (blur_image == (Image *) NULL)
4507 return((Image *) NULL);
4508 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
4509 blur_image=DestroyImage(blur_image);
4510 if (dodge_image == (Image *) NULL)
4511 return((Image *) NULL);
4512 (void) NormalizeImage(dodge_image,exception);
4513 (void) NegateImage(dodge_image,MagickFalse,exception);
4514 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
4515 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4516 if (sketch_image == (Image *) NULL)
4518 dodge_image=DestroyImage(dodge_image);
4519 return((Image *) NULL);
4521 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
4522 MagickFalse,0,0,exception);
4523 dodge_image=DestroyImage(dodge_image);
4524 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4525 if (blend_image == (Image *) NULL)
4527 sketch_image=DestroyImage(sketch_image);
4528 return((Image *) NULL);
4530 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4531 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickFalse,
4533 blend_image=DestroyImage(blend_image);
4534 return(sketch_image);
4538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4542 % S o l a r i z e I m a g e %
4546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4548 % SolarizeImage() applies a special effect to the image, similar to the effect
4549 % achieved in a photo darkroom by selectively exposing areas of photo
4550 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4551 % measure of the extent of the solarization.
4553 % The format of the SolarizeImage method is:
4555 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4556 % ExceptionInfo *exception)
4558 % A description of each parameter follows:
4560 % o image: the image.
4562 % o threshold: Define the extent of the solarization.
4564 % o exception: return any errors or warnings in this structure.
4567 MagickExport MagickBooleanType SolarizeImage(Image *image,
4568 const double threshold,ExceptionInfo *exception)
4570 #define SolarizeImageTag "Solarize/Image"
4584 assert(image != (Image *) NULL);
4585 assert(image->signature == MagickSignature);
4586 if (image->debug != MagickFalse)
4587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4588 if (image->storage_class == PseudoClass)
4596 for (i=0; i < (ssize_t) image->colors; i++)
4598 if ((MagickRealType) image->colormap[i].red > threshold)
4599 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4600 if ((MagickRealType) image->colormap[i].green > threshold)
4601 image->colormap[i].green=(Quantum) QuantumRange-
4602 image->colormap[i].green;
4603 if ((MagickRealType) image->colormap[i].blue > threshold)
4604 image->colormap[i].blue=(Quantum) QuantumRange-
4605 image->colormap[i].blue;
4613 image_view=AcquireCacheView(image);
4614 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4615 #pragma omp parallel for schedule(static,4) shared(progress,status)
4617 for (y=0; y < (ssize_t) image->rows; y++)
4625 if (status == MagickFalse)
4627 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4628 if (q == (Quantum *) NULL)
4633 for (x=0; x < (ssize_t) image->columns; x++)
4638 if (GetPixelMask(image,q) != 0)
4640 q+=GetPixelChannels(image);
4643 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4651 channel=GetPixelChannelMapChannel(image,i);
4652 traits=GetPixelChannelMapTraits(image,channel);
4653 if ((traits == UndefinedPixelTrait) ||
4654 ((traits & CopyPixelTrait) != 0))
4656 if ((MagickRealType) q[i] > threshold)
4657 q[i]=QuantumRange-q[i];
4659 q+=GetPixelChannels(image);
4661 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4663 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4668 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4669 #pragma omp critical (MagickCore_SolarizeImage)
4671 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4672 if (proceed == MagickFalse)
4676 image_view=DestroyCacheView(image_view);
4681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4685 % S t e g a n o I m a g e %
4689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4691 % SteganoImage() hides a digital watermark within the image. Recover
4692 % the hidden watermark later to prove that the authenticity of an image.
4693 % Offset defines the start position within the image to hide the watermark.
4695 % The format of the SteganoImage method is:
4697 % Image *SteganoImage(const Image *image,Image *watermark,
4698 % ExceptionInfo *exception)
4700 % A description of each parameter follows:
4702 % o image: the image.
4704 % o watermark: the watermark image.
4706 % o exception: return any errors or warnings in this structure.
4709 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4710 ExceptionInfo *exception)
4712 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4713 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4714 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4715 #define SteganoImageTag "Stegano/Image"
4750 Initialize steganographic image attributes.
4752 assert(image != (const Image *) NULL);
4753 assert(image->signature == MagickSignature);
4754 if (image->debug != MagickFalse)
4755 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4756 assert(watermark != (const Image *) NULL);
4757 assert(watermark->signature == MagickSignature);
4758 assert(exception != (ExceptionInfo *) NULL);
4759 assert(exception->signature == MagickSignature);
4761 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4762 if (stegano_image == (Image *) NULL)
4763 return((Image *) NULL);
4764 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4766 stegano_image=DestroyImage(stegano_image);
4767 return((Image *) NULL);
4769 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4771 Hide watermark in low-order bits of image.
4776 depth=stegano_image->depth;
4779 watermark_view=AcquireCacheView(watermark);
4780 stegano_view=AcquireCacheView(stegano_image);
4781 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4783 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4785 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4790 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
4792 offset=k/(ssize_t) stegano_image->columns;
4793 if (offset >= (ssize_t) stegano_image->rows)
4795 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4796 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4798 if (q == (Quantum *) NULL)
4804 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
4805 GetPixelInfoIntensity(&pixel),i)),q);
4810 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
4811 GetPixelInfoIntensity(&pixel),i)),q);
4816 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
4817 GetPixelInfoIntensity(&pixel),i)),q);
4821 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4827 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4829 if (k == image->offset)
4833 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4838 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4840 if (proceed == MagickFalse)
4844 stegano_view=DestroyCacheView(stegano_view);
4845 watermark_view=DestroyCacheView(watermark_view);
4846 if (stegano_image->storage_class == PseudoClass)
4847 (void) SyncImage(stegano_image,exception);
4848 if (status == MagickFalse)
4850 stegano_image=DestroyImage(stegano_image);
4851 return((Image *) NULL);
4853 return(stegano_image);
4857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4861 % S t e r e o A n a g l y p h I m a g e %
4865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4867 % StereoAnaglyphImage() combines two images and produces a single image that
4868 % is the composite of a left and right image of a stereo pair. Special
4869 % red-green stereo glasses are required to view this effect.
4871 % The format of the StereoAnaglyphImage method is:
4873 % Image *StereoImage(const Image *left_image,const Image *right_image,
4874 % ExceptionInfo *exception)
4875 % Image *StereoAnaglyphImage(const Image *left_image,
4876 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4877 % ExceptionInfo *exception)
4879 % A description of each parameter follows:
4881 % o left_image: the left image.
4883 % o right_image: the right image.
4885 % o exception: return any errors or warnings in this structure.
4887 % o x_offset: amount, in pixels, by which the left image is offset to the
4888 % right of the right image.
4890 % o y_offset: amount, in pixels, by which the left image is offset to the
4891 % bottom of the right image.
4895 MagickExport Image *StereoImage(const Image *left_image,
4896 const Image *right_image,ExceptionInfo *exception)
4898 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4901 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4902 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4903 ExceptionInfo *exception)
4905 #define StereoImageTag "Stereo/Image"
4919 assert(left_image != (const Image *) NULL);
4920 assert(left_image->signature == MagickSignature);
4921 if (left_image->debug != MagickFalse)
4922 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4923 left_image->filename);
4924 assert(right_image != (const Image *) NULL);
4925 assert(right_image->signature == MagickSignature);
4926 assert(exception != (ExceptionInfo *) NULL);
4927 assert(exception->signature == MagickSignature);
4928 assert(right_image != (const Image *) NULL);
4930 if ((left_image->columns != right_image->columns) ||
4931 (left_image->rows != right_image->rows))
4932 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4934 Initialize stereo image attributes.
4936 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4937 MagickTrue,exception);
4938 if (stereo_image == (Image *) NULL)
4939 return((Image *) NULL);
4940 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4942 stereo_image=DestroyImage(stereo_image);
4943 return((Image *) NULL);
4946 Copy left image to red channel and right image to blue channel.
4949 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4951 register const Quantum
4961 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4963 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4964 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4965 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4966 (r == (Quantum *) NULL))
4968 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4970 SetPixelRed(image,GetPixelRed(left_image,p),r);
4971 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4972 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4973 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4974 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4975 GetPixelAlpha(right_image,q))/2,r);
4976 p+=GetPixelChannels(left_image);
4977 q+=GetPixelChannels(right_image);
4978 r+=GetPixelChannels(stereo_image);
4980 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4982 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4987 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4988 stereo_image->rows);
4989 if (proceed == MagickFalse)
4993 if (status == MagickFalse)
4995 stereo_image=DestroyImage(stereo_image);
4996 return((Image *) NULL);
4998 return(stereo_image);
5002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5006 % S w i r l I m a g e %
5010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5012 % SwirlImage() swirls the pixels about the center of the image, where
5013 % degrees indicates the sweep of the arc through which each pixel is moved.
5014 % You get a more dramatic effect as the degrees move from 1 to 360.
5016 % The format of the SwirlImage method is:
5018 % Image *SwirlImage(const Image *image,double degrees,
5019 % const PixelInterpolateMethod method,ExceptionInfo *exception)
5021 % A description of each parameter follows:
5023 % o image: the image.
5025 % o degrees: Define the tightness of the swirling effect.
5027 % o method: the pixel interpolation method.
5029 % o exception: return any errors or warnings in this structure.
5032 MagickExport Image *SwirlImage(const Image *image,double degrees,
5033 const PixelInterpolateMethod method,ExceptionInfo *exception)
5035 #define SwirlImageTag "Swirl/Image"
5061 Initialize swirl image attributes.
5063 assert(image != (const Image *) NULL);
5064 assert(image->signature == MagickSignature);
5065 if (image->debug != MagickFalse)
5066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5067 assert(exception != (ExceptionInfo *) NULL);
5068 assert(exception->signature == MagickSignature);
5069 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5070 if (swirl_image == (Image *) NULL)
5071 return((Image *) NULL);
5072 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
5074 swirl_image=DestroyImage(swirl_image);
5075 return((Image *) NULL);
5077 if (swirl_image->background_color.alpha != OpaqueAlpha)
5078 swirl_image->matte=MagickTrue;
5080 Compute scaling factor.
5082 center.x=(double) image->columns/2.0;
5083 center.y=(double) image->rows/2.0;
5084 radius=MagickMax(center.x,center.y);
5087 if (image->columns > image->rows)
5088 scale.y=(double) image->columns/(double) image->rows;
5090 if (image->columns < image->rows)
5091 scale.x=(double) image->rows/(double) image->columns;
5092 degrees=(double) DegreesToRadians(degrees);
5098 image_view=AcquireCacheView(image);
5099 swirl_view=AcquireCacheView(swirl_image);
5100 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5101 #pragma omp parallel for schedule(static,4) shared(progress,status)
5103 for (y=0; y < (ssize_t) image->rows; y++)
5111 register const Quantum
5120 if (status == MagickFalse)
5122 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
5123 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5125 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5130 delta.y=scale.y*(double) (y-center.y);
5131 for (x=0; x < (ssize_t) image->columns; x++)
5134 Determine if the pixel is within an ellipse.
5136 if (GetPixelMask(image,p) != 0)
5138 p+=GetPixelChannels(image);
5139 q+=GetPixelChannels(swirl_image);
5142 delta.x=scale.x*(double) (x-center.x);
5143 distance=delta.x*delta.x+delta.y*delta.y;
5144 if (distance >= (radius*radius))
5149 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5158 channel=GetPixelChannelMapChannel(image,i);
5159 traits=GetPixelChannelMapTraits(image,channel);
5160 swirl_traits=GetPixelChannelMapTraits(swirl_image,channel);
5161 if ((traits == UndefinedPixelTrait) ||
5162 (swirl_traits == UndefinedPixelTrait))
5164 SetPixelChannel(swirl_image,channel,p[i],q);
5177 factor=1.0-sqrt((double) distance)/radius;
5178 sine=sin((double) (degrees*factor*factor));
5179 cosine=cos((double) (degrees*factor*factor));
5180 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5181 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5182 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
5184 p+=GetPixelChannels(image);
5185 q+=GetPixelChannels(swirl_image);
5187 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5189 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5194 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5195 #pragma omp critical (MagickCore_SwirlImage)
5197 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5198 if (proceed == MagickFalse)
5202 swirl_view=DestroyCacheView(swirl_view);
5203 image_view=DestroyCacheView(image_view);
5204 if (status == MagickFalse)
5205 swirl_image=DestroyImage(swirl_image);
5206 return(swirl_image);
5210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5214 % T i n t I m a g e %
5218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5220 % TintImage() applies a color vector to each pixel in the image. The length
5221 % of the vector is 0 for black and white and at its maximum for the midtones.
5222 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5224 % The format of the TintImage method is:
5226 % Image *TintImage(const Image *image,const char *blend,
5227 % const PixelInfo *tint,ExceptionInfo *exception)
5229 % A description of each parameter follows:
5231 % o image: the image.
5233 % o blend: A color value used for tinting.
5235 % o tint: A color value used for tinting.
5237 % o exception: return any errors or warnings in this structure.
5240 MagickExport Image *TintImage(const Image *image,const char *blend,
5241 const PixelInfo *tint,ExceptionInfo *exception)
5243 #define TintImageTag "Tint/Image"
5274 Allocate tint image.
5276 assert(image != (const Image *) NULL);
5277 assert(image->signature == MagickSignature);
5278 if (image->debug != MagickFalse)
5279 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5280 assert(exception != (ExceptionInfo *) NULL);
5281 assert(exception->signature == MagickSignature);
5282 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5283 if (tint_image == (Image *) NULL)
5284 return((Image *) NULL);
5285 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5287 tint_image=DestroyImage(tint_image);
5288 return((Image *) NULL);
5290 if (blend == (const char *) NULL)
5293 Determine RGB values of the color.
5295 GetPixelInfo(image,&color_vector);
5296 flags=ParseGeometry(blend,&geometry_info);
5297 color_vector.red=geometry_info.rho;
5298 color_vector.green=geometry_info.rho;
5299 color_vector.blue=geometry_info.rho;
5300 color_vector.alpha=OpaqueAlpha;
5301 if ((flags & SigmaValue) != 0)
5302 color_vector.green=geometry_info.sigma;
5303 if ((flags & XiValue) != 0)
5304 color_vector.blue=geometry_info.xi;
5305 if ((flags & PsiValue) != 0)
5306 color_vector.alpha=geometry_info.psi;
5307 if (image->colorspace == CMYKColorspace)
5309 color_vector.black=geometry_info.rho;
5310 if ((flags & PsiValue) != 0)
5311 color_vector.black=geometry_info.psi;
5312 if ((flags & ChiValue) != 0)
5313 color_vector.alpha=geometry_info.chi;
5315 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5316 color_vector.red=(MagickRealType) (color_vector.red*tint->red/100.0-
5318 color_vector.green=(MagickRealType) (color_vector.green*tint->green/100.0-
5320 color_vector.blue=(MagickRealType) (color_vector.blue*tint->blue/100.0-
5322 color_vector.black=(MagickRealType) (color_vector.black*tint->black/100.0-
5324 color_vector.alpha=(MagickRealType) (color_vector.alpha*tint->alpha/100.0-
5331 image_view=AcquireCacheView(image);
5332 tint_view=AcquireCacheView(tint_image);
5333 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5334 #pragma omp parallel for schedule(static,4) shared(progress,status)
5336 for (y=0; y < (ssize_t) image->rows; y++)
5338 register const Quantum
5347 if (status == MagickFalse)
5349 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5350 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5352 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5357 for (x=0; x < (ssize_t) image->columns; x++)
5368 if (GetPixelMask(image,p) != 0)
5370 p+=GetPixelChannels(image);
5371 q+=GetPixelChannels(tint_image);
5374 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5383 channel=GetPixelChannelMapChannel(image,i);
5384 traits=GetPixelChannelMapTraits(image,channel);
5385 tint_traits=GetPixelChannelMapTraits(tint_image,channel);
5386 if ((traits == UndefinedPixelTrait) ||
5387 (tint_traits == UndefinedPixelTrait))
5389 if ((tint_traits & CopyPixelTrait) != 0)
5391 SetPixelChannel(tint_image,channel,p[i],q);
5395 GetPixelInfo(image,&pixel);
5396 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5397 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5398 (1.0-(4.0*(weight*weight)));
5399 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5400 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5401 (1.0-(4.0*(weight*weight)));
5402 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5403 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5404 (1.0-(4.0*(weight*weight)));
5405 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5406 pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black*
5407 (1.0-(4.0*(weight*weight)));
5408 SetPixelInfoPixel(tint_image,&pixel,q);
5409 p+=GetPixelChannels(image);
5410 q+=GetPixelChannels(tint_image);
5412 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5414 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5419 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5420 #pragma omp critical (MagickCore_TintImage)
5422 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5423 if (proceed == MagickFalse)
5427 tint_view=DestroyCacheView(tint_view);
5428 image_view=DestroyCacheView(image_view);
5429 if (status == MagickFalse)
5430 tint_image=DestroyImage(tint_image);
5435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5439 % V i g n e t t e I m a g e %
5443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5445 % VignetteImage() softens the edges of the image in vignette style.
5447 % The format of the VignetteImage method is:
5449 % Image *VignetteImage(const Image *image,const double radius,
5450 % const double sigma,const ssize_t x,const ssize_t y,
5451 % ExceptionInfo *exception)
5453 % A description of each parameter follows:
5455 % o image: the image.
5457 % o radius: the radius of the pixel neighborhood.
5459 % o sigma: the standard deviation of the Gaussian, in pixels.
5461 % o x, y: Define the x and y ellipse offset.
5463 % o exception: return any errors or warnings in this structure.
5466 MagickExport Image *VignetteImage(const Image *image,const double radius,
5467 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5470 ellipse[MaxTextExtent];
5481 assert(image != (Image *) NULL);
5482 assert(image->signature == MagickSignature);
5483 if (image->debug != MagickFalse)
5484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5485 assert(exception != (ExceptionInfo *) NULL);
5486 assert(exception->signature == MagickSignature);
5487 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5488 if (canvas_image == (Image *) NULL)
5489 return((Image *) NULL);
5490 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5492 canvas_image=DestroyImage(canvas_image);
5493 return((Image *) NULL);
5495 canvas_image->matte=MagickTrue;
5496 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5497 MagickTrue,exception);
5498 if (oval_image == (Image *) NULL)
5500 canvas_image=DestroyImage(canvas_image);
5501 return((Image *) NULL);
5503 (void) QueryColorCompliance("#000000",AllCompliance,
5504 &oval_image->background_color,exception);
5505 (void) SetImageBackgroundColor(oval_image,exception);
5506 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5507 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5509 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5511 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5512 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5514 draw_info->primitive=AcquireString(ellipse);
5515 (void) DrawImage(oval_image,draw_info,exception);
5516 draw_info=DestroyDrawInfo(draw_info);
5517 blur_image=BlurImage(oval_image,radius,sigma,exception);
5518 oval_image=DestroyImage(oval_image);
5519 if (blur_image == (Image *) NULL)
5521 canvas_image=DestroyImage(canvas_image);
5522 return((Image *) NULL);
5524 blur_image->matte=MagickFalse;
5525 (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,
5526 MagickFalse,0,0,exception);
5527 blur_image=DestroyImage(blur_image);
5528 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5529 canvas_image=DestroyImage(canvas_image);
5530 return(vignette_image);
5534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5538 % W a v e I m a g e %
5542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5544 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5545 % vertically along a sine wave whose amplitude and wavelength is specified
5546 % by the given parameters.
5548 % The format of the WaveImage method is:
5550 % Image *WaveImage(const Image *image,const double amplitude,
5551 % const double wave_length,const PixelInterpolateMethod method,
5552 % ExceptionInfo *exception)
5554 % A description of each parameter follows:
5556 % o image: the image.
5558 % o amplitude, wave_length: Define the amplitude and wave length of the
5561 % o interpolate: the pixel interpolation method.
5563 % o exception: return any errors or warnings in this structure.
5566 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5567 const double wave_length,const PixelInterpolateMethod method,
5568 ExceptionInfo *exception)
5570 #define WaveImageTag "Wave/Image"
5595 Initialize wave image attributes.
5597 assert(image != (Image *) NULL);
5598 assert(image->signature == MagickSignature);
5599 if (image->debug != MagickFalse)
5600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5601 assert(exception != (ExceptionInfo *) NULL);
5602 assert(exception->signature == MagickSignature);
5603 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5604 fabs(amplitude)),MagickTrue,exception);
5605 if (wave_image == (Image *) NULL)
5606 return((Image *) NULL);
5607 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5609 wave_image=DestroyImage(wave_image);
5610 return((Image *) NULL);
5612 if (wave_image->background_color.alpha != OpaqueAlpha)
5613 wave_image->matte=MagickTrue;
5617 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5619 if (sine_map == (MagickRealType *) NULL)
5621 wave_image=DestroyImage(wave_image);
5622 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5624 for (i=0; i < (ssize_t) wave_image->columns; i++)
5625 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5632 image_view=AcquireCacheView(image);
5633 wave_view=AcquireCacheView(wave_image);
5634 (void) SetCacheViewVirtualPixelMethod(image_view,
5635 BackgroundVirtualPixelMethod);
5636 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5637 #pragma omp parallel for schedule(static,4) shared(progress,status)
5639 for (y=0; y < (ssize_t) wave_image->rows; y++)
5647 if (status == MagickFalse)
5649 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5651 if (q == (Quantum *) NULL)
5656 for (x=0; x < (ssize_t) wave_image->columns; x++)
5658 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5659 (double) x,(double) (y-sine_map[x]),q,exception);
5660 q+=GetPixelChannels(wave_image);
5662 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5664 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5669 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5670 #pragma omp critical (MagickCore_WaveImage)
5672 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5673 if (proceed == MagickFalse)
5677 wave_view=DestroyCacheView(wave_view);
5678 image_view=DestroyCacheView(image_view);
5679 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5680 if (status == MagickFalse)
5681 wave_image=DestroyImage(wave_image);