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/colorspace-private.h"
52 #include "MagickCore/composite.h"
53 #include "MagickCore/decorate.h"
54 #include "MagickCore/distort.h"
55 #include "MagickCore/draw.h"
56 #include "MagickCore/effect.h"
57 #include "MagickCore/enhance.h"
58 #include "MagickCore/exception.h"
59 #include "MagickCore/exception-private.h"
60 #include "MagickCore/fx.h"
61 #include "MagickCore/fx-private.h"
62 #include "MagickCore/gem.h"
63 #include "MagickCore/gem-private.h"
64 #include "MagickCore/geometry.h"
65 #include "MagickCore/layer.h"
66 #include "MagickCore/list.h"
67 #include "MagickCore/log.h"
68 #include "MagickCore/image.h"
69 #include "MagickCore/image-private.h"
70 #include "MagickCore/magick.h"
71 #include "MagickCore/memory_.h"
72 #include "MagickCore/monitor.h"
73 #include "MagickCore/monitor-private.h"
74 #include "MagickCore/option.h"
75 #include "MagickCore/pixel.h"
76 #include "MagickCore/pixel-accessor.h"
77 #include "MagickCore/property.h"
78 #include "MagickCore/quantum.h"
79 #include "MagickCore/quantum-private.h"
80 #include "MagickCore/random_.h"
81 #include "MagickCore/random-private.h"
82 #include "MagickCore/resample.h"
83 #include "MagickCore/resample-private.h"
84 #include "MagickCore/resize.h"
85 #include "MagickCore/splay-tree.h"
86 #include "MagickCore/statistic.h"
87 #include "MagickCore/string_.h"
88 #include "MagickCore/string-private.h"
89 #include "MagickCore/thread-private.h"
90 #include "MagickCore/transform.h"
91 #include "MagickCore/utility.h"
96 #define LeftShiftOperator 0xf5
97 #define RightShiftOperator 0xf6
98 #define LessThanEqualOperator 0xf7
99 #define GreaterThanEqualOperator 0xf8
100 #define EqualOperator 0xf9
101 #define NotEqualOperator 0xfa
102 #define LogicalAndOperator 0xfb
103 #define LogicalOrOperator 0xfc
104 #define ExponentialNotation 0xfd
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 + A c q u i r e F x I n f o %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % AcquireFxInfo() allocates the FxInfo structure.
144 % The format of the AcquireFxInfo method is:
146 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
148 % A description of each parameter follows:
150 % o image: the image.
152 % o expression: the expression.
155 MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
169 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
170 if (fx_info == (FxInfo *) NULL)
171 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
172 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
173 fx_info->exception=AcquireExceptionInfo();
174 fx_info->images=image;
175 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
176 RelinquishMagickMemory);
177 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
178 RelinquishMagickMemory);
179 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
180 fx_info->images),sizeof(*fx_info->view));
181 if (fx_info->view == (CacheView **) NULL)
182 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
184 next=GetFirstImageInList(fx_info->images);
185 for ( ; next != (Image *) NULL; next=next->next)
187 fx_info->view[i]=AcquireCacheView(next);
190 fx_info->random_info=AcquireRandomInfo();
191 fx_info->expression=ConstantString(expression);
192 fx_info->file=stderr;
193 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
195 Force right-to-left associativity for unary negation.
197 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
199 Convert complex to simple operators.
202 *fx_op=(char) LeftShiftOperator;
203 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
204 *fx_op=(char) RightShiftOperator;
205 (void) SubstituteString(&fx_info->expression,">>",fx_op);
206 *fx_op=(char) LessThanEqualOperator;
207 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
208 *fx_op=(char) GreaterThanEqualOperator;
209 (void) SubstituteString(&fx_info->expression,">=",fx_op);
210 *fx_op=(char) EqualOperator;
211 (void) SubstituteString(&fx_info->expression,"==",fx_op);
212 *fx_op=(char) NotEqualOperator;
213 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
214 *fx_op=(char) LogicalAndOperator;
215 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
216 *fx_op=(char) LogicalOrOperator;
217 (void) SubstituteString(&fx_info->expression,"||",fx_op);
218 *fx_op=(char) ExponentialNotation;
219 (void) SubstituteString(&fx_info->expression,"**",fx_op);
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % A d d N o i s e I m a g e %
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % AddNoiseImage() adds random noise to the image.
236 % The format of the AddNoiseImage method is:
238 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
239 % const double attenuate,ExceptionInfo *exception)
241 % A description of each parameter follows:
243 % o image: the image.
245 % o channel: the channel type.
247 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
248 % Impulse, Laplacian, or Poisson.
250 % o attenuate: attenuate the random distribution.
252 % o exception: return any errors or warnings in this structure.
255 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
256 const double attenuate,ExceptionInfo *exception)
258 #define AddNoiseImageTag "AddNoise/Image"
274 **restrict random_info;
280 Initialize noise image attributes.
282 assert(image != (const Image *) NULL);
283 assert(image->signature == MagickSignature);
284 if (image->debug != MagickFalse)
285 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
286 assert(exception != (ExceptionInfo *) NULL);
287 assert(exception->signature == MagickSignature);
288 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
289 if (noise_image == (Image *) NULL)
290 return((Image *) NULL);
291 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
293 noise_image=DestroyImage(noise_image);
294 return((Image *) NULL);
297 Add noise in each row.
301 random_info=AcquireRandomInfoThreadSet();
302 image_view=AcquireCacheView(image);
303 noise_view=AcquireCacheView(noise_image);
304 #if defined(MAGICKCORE_OPENMP_SUPPORT)
305 #pragma omp parallel for schedule(static,4) shared(progress,status)
307 for (y=0; y < (ssize_t) image->rows; y++)
310 id = GetOpenMPThreadId();
315 register const Quantum
324 if (status == MagickFalse)
326 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
327 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
329 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
334 for (x=0; x < (ssize_t) image->columns; x++)
339 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
348 channel=GetPixelChannelMapChannel(image,i);
349 traits=GetPixelChannelMapTraits(image,channel);
350 noise_traits=GetPixelChannelMapTraits(noise_image,channel);
351 if ((traits == UndefinedPixelTrait) ||
352 (noise_traits == UndefinedPixelTrait))
354 if (((noise_traits & CopyPixelTrait) != 0) ||
355 (GetPixelMask(image,p) != 0))
357 SetPixelChannel(noise_image,channel,p[i],q);
360 SetPixelChannel(noise_image,channel,ClampToQuantum(
361 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
364 p+=GetPixelChannels(image);
365 q+=GetPixelChannels(noise_image);
367 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
368 if (sync == MagickFalse)
370 if (image->progress_monitor != (MagickProgressMonitor) NULL)
375 #if defined(MAGICKCORE_OPENMP_SUPPORT)
376 #pragma omp critical (MagickCore_AddNoiseImage)
378 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
380 if (proceed == MagickFalse)
384 noise_view=DestroyCacheView(noise_view);
385 image_view=DestroyCacheView(image_view);
386 random_info=DestroyRandomInfoThreadSet(random_info);
387 if (status == MagickFalse)
388 noise_image=DestroyImage(noise_image);
393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 % B l u e S h i f t I m a g e %
401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 % BlueShiftImage() mutes the colors of the image to simulate a scene at
404 % nighttime in the moonlight.
406 % The format of the BlueShiftImage method is:
408 % Image *BlueShiftImage(const Image *image,const double factor,
409 % ExceptionInfo *exception)
411 % A description of each parameter follows:
413 % o image: the image.
415 % o factor: the shift factor.
417 % o exception: return any errors or warnings in this structure.
420 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
421 ExceptionInfo *exception)
423 #define BlueShiftImageTag "BlueShift/Image"
442 Allocate blue shift image.
444 assert(image != (const Image *) NULL);
445 assert(image->signature == MagickSignature);
446 if (image->debug != MagickFalse)
447 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
448 assert(exception != (ExceptionInfo *) NULL);
449 assert(exception->signature == MagickSignature);
450 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
451 if (shift_image == (Image *) NULL)
452 return((Image *) NULL);
453 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
455 shift_image=DestroyImage(shift_image);
456 return((Image *) NULL);
459 Blue-shift DirectClass image.
463 image_view=AcquireCacheView(image);
464 shift_view=AcquireCacheView(shift_image);
465 #if defined(MAGICKCORE_OPENMP_SUPPORT)
466 #pragma omp parallel for schedule(static,4) shared(progress,status)
468 for (y=0; y < (ssize_t) image->rows; y++)
479 register const Quantum
488 if (status == MagickFalse)
490 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
491 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
493 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
498 for (x=0; x < (ssize_t) image->columns; x++)
500 quantum=GetPixelRed(image,p);
501 if (GetPixelGreen(image,p) < quantum)
502 quantum=GetPixelGreen(image,p);
503 if (GetPixelBlue(image,p) < quantum)
504 quantum=GetPixelBlue(image,p);
505 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
506 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
507 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
508 quantum=GetPixelRed(image,p);
509 if (GetPixelGreen(image,p) > quantum)
510 quantum=GetPixelGreen(image,p);
511 if (GetPixelBlue(image,p) > quantum)
512 quantum=GetPixelBlue(image,p);
513 pixel.red=0.5*(pixel.red+factor*quantum);
514 pixel.green=0.5*(pixel.green+factor*quantum);
515 pixel.blue=0.5*(pixel.blue+factor*quantum);
516 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
517 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
518 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
519 p+=GetPixelChannels(image);
520 q+=GetPixelChannels(shift_image);
522 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
523 if (sync == MagickFalse)
525 if (image->progress_monitor != (MagickProgressMonitor) NULL)
530 #if defined(MAGICKCORE_OPENMP_SUPPORT)
531 #pragma omp critical (MagickCore_BlueShiftImage)
533 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
535 if (proceed == MagickFalse)
539 image_view=DestroyCacheView(image_view);
540 shift_view=DestroyCacheView(shift_view);
541 if (status == MagickFalse)
542 shift_image=DestroyImage(shift_image);
547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551 % C h a r c o a l I m a g e %
555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557 % CharcoalImage() creates a new image that is a copy of an existing one with
558 % the edge highlighted. It allocates the memory necessary for the new Image
559 % structure and returns a pointer to the new image.
561 % The format of the CharcoalImage method is:
563 % Image *CharcoalImage(const Image *image,const double radius,
564 % const double sigma,ExceptionInfo *exception)
566 % A description of each parameter follows:
568 % o image: the image.
570 % o radius: the radius of the pixel neighborhood.
572 % o sigma: the standard deviation of the Gaussian, in pixels.
574 % o exception: return any errors or warnings in this structure.
577 MagickExport Image *CharcoalImage(const Image *image,const double radius,
578 const double sigma,ExceptionInfo *exception)
585 assert(image != (Image *) NULL);
586 assert(image->signature == MagickSignature);
587 if (image->debug != MagickFalse)
588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
589 assert(exception != (ExceptionInfo *) NULL);
590 assert(exception->signature == MagickSignature);
591 clone_image=CloneImage(image,0,0,MagickTrue,exception);
592 if (clone_image == (Image *) NULL)
593 return((Image *) NULL);
594 (void) SetImageType(clone_image,GrayscaleType,exception);
595 edge_image=EdgeImage(clone_image,radius,sigma,exception);
596 clone_image=DestroyImage(clone_image);
597 if (edge_image == (Image *) NULL)
598 return((Image *) NULL);
599 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
600 edge_image=DestroyImage(edge_image);
601 if (charcoal_image == (Image *) NULL)
602 return((Image *) NULL);
603 (void) NormalizeImage(charcoal_image,exception);
604 (void) NegateImage(charcoal_image,MagickFalse,exception);
605 (void) SetImageType(charcoal_image,GrayscaleType,exception);
606 return(charcoal_image);
610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614 % C o l o r i z e I m a g e %
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620 % ColorizeImage() blends the fill color with each pixel in the image.
621 % A percentage blend is specified with opacity. Control the application
622 % of different color components by specifying a different percentage for
623 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
625 % The format of the ColorizeImage method is:
627 % Image *ColorizeImage(const Image *image,const char *blend,
628 % const PixelInfo *colorize,ExceptionInfo *exception)
630 % A description of each parameter follows:
632 % o image: the image.
634 % o blend: A character string indicating the level of blending as a
637 % o colorize: A color value.
639 % o exception: return any errors or warnings in this structure.
642 MagickExport Image *ColorizeImage(const Image *image,const char *blend,
643 const PixelInfo *colorize,ExceptionInfo *exception)
645 #define ColorizeImageTag "Colorize/Image"
646 #define Colorize(pixel,fill_color,colorize) \
647 (pixel)=((pixel)*(100.0-(fill_color))+(colorize)*(fill_color))/100.0;
675 Allocate colorized image.
677 assert(image != (const Image *) NULL);
678 assert(image->signature == MagickSignature);
679 if (image->debug != MagickFalse)
680 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
681 assert(exception != (ExceptionInfo *) NULL);
682 assert(exception->signature == MagickSignature);
683 GetPixelInfo(image,&fill_color);
684 flags=ParseGeometry(blend,&geometry_info);
685 fill_color.red=geometry_info.rho;
686 fill_color.green=geometry_info.rho;
687 fill_color.blue=geometry_info.rho;
688 fill_color.black=geometry_info.rho;
689 fill_color.alpha=100.0;
690 if ((flags & SigmaValue) != 0)
691 fill_color.green=geometry_info.sigma;
692 if ((flags & XiValue) != 0)
693 fill_color.blue=geometry_info.xi;
694 if ((flags & PsiValue) != 0)
695 fill_color.alpha=geometry_info.psi;
696 if (fill_color.colorspace == CMYKColorspace)
698 if ((flags & PsiValue) != 0)
699 fill_color.black=geometry_info.psi;
700 if ((flags & ChiValue) != 0)
701 fill_color.alpha=geometry_info.chi;
703 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
705 if (colorize_image == (Image *) NULL)
706 return((Image *) NULL);
707 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
709 colorize_image=DestroyImage(colorize_image);
710 return((Image *) NULL);
712 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
713 (IsPixelInfoGray(&fill_color) != MagickFalse))
714 SetImageColorspace(colorize_image,sRGBColorspace,exception);
715 if ((colorize->matte != MagickFalse) &&
716 (colorize_image->matte == MagickFalse))
717 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
718 if (blend == (const char *) NULL)
719 return(colorize_image);
721 Colorize DirectClass image.
725 image_view=AcquireCacheView(image);
726 colorize_view=AcquireCacheView(colorize_image);
727 #if defined(MAGICKCORE_OPENMP_SUPPORT)
728 #pragma omp parallel for schedule(static,4) shared(progress,status)
730 for (y=0; y < (ssize_t) image->rows; y++)
738 register const Quantum
747 if (status == MagickFalse)
749 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
750 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
752 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
757 GetPixelInfo(image,&pixel);
758 for (x=0; x < (ssize_t) image->columns; x++)
760 GetPixelInfoPixel(image,p,&pixel);
761 Colorize(pixel.red,fill_color.red,colorize->red);
762 Colorize(pixel.green,fill_color.green,colorize->green);
763 Colorize(pixel.blue,fill_color.blue,colorize->blue);
764 Colorize(pixel.black,fill_color.black,colorize->black);
765 Colorize(pixel.alpha,fill_color.alpha,colorize->alpha);
766 SetPixelInfoPixel(colorize_image,&pixel,q);
767 p+=GetPixelChannels(image);
768 q+=GetPixelChannels(colorize_image);
770 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
771 if (sync == MagickFalse)
773 if (image->progress_monitor != (MagickProgressMonitor) NULL)
778 #if defined(MAGICKCORE_OPENMP_SUPPORT)
779 #pragma omp critical (MagickCore_ColorizeImage)
781 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
782 if (proceed == MagickFalse)
786 image_view=DestroyCacheView(image_view);
787 colorize_view=DestroyCacheView(colorize_view);
788 if (status == MagickFalse)
789 colorize_image=DestroyImage(colorize_image);
790 return(colorize_image);
794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798 % C o l o r M a t r i x I m a g e %
802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804 % ColorMatrixImage() applies color transformation to an image. This method
805 % permits saturation changes, hue rotation, luminance to alpha, and various
806 % other effects. Although variable-sized transformation matrices can be used,
807 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
808 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
809 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
810 % and offsets are normalized (divide Flash offset by 255).
812 % The format of the ColorMatrixImage method is:
814 % Image *ColorMatrixImage(const Image *image,
815 % const KernelInfo *color_matrix,ExceptionInfo *exception)
817 % A description of each parameter follows:
819 % o image: the image.
821 % o color_matrix: the color matrix.
823 % o exception: return any errors or warnings in this structure.
826 /* FUTURE: modify to make use of a MagickMatrix Mutliply function
827 That should be provided in "matrix.c"
828 (ASIDE: actually distorts should do this too but currently doesn't)
831 MagickExport Image *ColorMatrixImage(const Image *image,
832 const KernelInfo *color_matrix,ExceptionInfo *exception)
834 #define ColorMatrixImageTag "ColorMatrix/Image"
843 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
844 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
845 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
846 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
847 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
848 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
869 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
871 assert(image != (Image *) NULL);
872 assert(image->signature == MagickSignature);
873 if (image->debug != MagickFalse)
874 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
875 assert(exception != (ExceptionInfo *) NULL);
876 assert(exception->signature == MagickSignature);
878 for (v=0; v < (ssize_t) color_matrix->height; v++)
879 for (u=0; u < (ssize_t) color_matrix->width; u++)
881 if ((v < 6) && (u < 6))
882 ColorMatrix[v][u]=color_matrix->values[i];
886 Initialize color image.
888 color_image=CloneImage(image,0,0,MagickTrue,exception);
889 if (color_image == (Image *) NULL)
890 return((Image *) NULL);
891 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
893 color_image=DestroyImage(color_image);
894 return((Image *) NULL);
896 if (image->debug != MagickFalse)
899 format[MaxTextExtent],
902 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
903 " ColorMatrix image with color matrix:");
904 message=AcquireString("");
905 for (v=0; v < 6; v++)
908 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
909 (void) ConcatenateString(&message,format);
910 for (u=0; u < 6; u++)
912 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
914 (void) ConcatenateString(&message,format);
916 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
918 message=DestroyString(message);
921 Apply the ColorMatrix to image.
925 image_view=AcquireCacheView(image);
926 color_view=AcquireCacheView(color_image);
927 #if defined(MAGICKCORE_OPENMP_SUPPORT)
928 #pragma omp parallel for schedule(static,4) shared(progress,status)
930 for (y=0; y < (ssize_t) image->rows; y++)
935 register const Quantum
944 if (status == MagickFalse)
946 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
947 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
949 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
954 GetPixelInfo(image,&pixel);
955 for (x=0; x < (ssize_t) image->columns; x++)
963 GetPixelInfoPixel(image,p,&pixel);
964 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
965 for (v=0; v < (ssize_t) height; v++)
970 sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
971 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
972 if (image->colorspace == CMYKColorspace)
973 sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
974 if (image->matte != MagickFalse)
975 sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
976 sum+=QuantumRange*ColorMatrix[v][5];
979 case 0: pixel.red=sum; break;
980 case 1: pixel.green=sum; break;
981 case 2: pixel.blue=sum; break;
982 case 3: pixel.black=sum; break;
983 case 4: pixel.alpha=sum; break;
987 SetPixelInfoPixel(color_image,&pixel,q);
988 p+=GetPixelChannels(image);
989 q+=GetPixelChannels(color_image);
991 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
993 if (image->progress_monitor != (MagickProgressMonitor) NULL)
998 #if defined(MAGICKCORE_OPENMP_SUPPORT)
999 #pragma omp critical (MagickCore_ColorMatrixImage)
1001 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1003 if (proceed == MagickFalse)
1007 color_view=DestroyCacheView(color_view);
1008 image_view=DestroyCacheView(image_view);
1009 if (status == MagickFalse)
1010 color_image=DestroyImage(color_image);
1011 return(color_image);
1015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1019 + D e s t r o y F x I n f o %
1023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1025 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1027 % The format of the DestroyFxInfo method is:
1029 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1031 % A description of each parameter follows:
1033 % o fx_info: the fx info.
1036 MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
1041 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1042 fx_info->expression=DestroyString(fx_info->expression);
1043 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1044 fx_info->colors=DestroySplayTree(fx_info->colors);
1045 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1046 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1047 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1048 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1049 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 + 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 %
1062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 % FxEvaluateChannelExpression() evaluates an expression and returns the
1067 % The format of the FxEvaluateExpression method is:
1069 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1070 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1071 % MagickRealType *alpha,Exceptioninfo *exception)
1072 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1073 % MagickRealType *alpha,Exceptioninfo *exception)
1075 % A description of each parameter follows:
1077 % o fx_info: the fx info.
1079 % o channel: the channel.
1081 % o x,y: the pixel position.
1083 % o alpha: the result.
1085 % o exception: return any errors or warnings in this structure.
1089 static inline double MagickMax(const double x,const double y)
1096 static inline double MagickMin(const double x,const double y)
1103 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1104 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1108 statistic[MaxTextExtent];
1116 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1118 switch (*++p) /* e.g. depth.r */
1120 case 'r': channel=RedPixelChannel; break;
1121 case 'g': channel=GreenPixelChannel; break;
1122 case 'b': channel=BluePixelChannel; break;
1123 case 'c': channel=CyanPixelChannel; break;
1124 case 'm': channel=MagentaPixelChannel; break;
1125 case 'y': channel=YellowPixelChannel; break;
1126 case 'k': channel=BlackPixelChannel; break;
1129 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1130 (double) channel,symbol);
1131 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1132 if (value != (const char *) NULL)
1133 return(QuantumScale*StringToDouble(value,(char **) NULL));
1134 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1135 if (LocaleNCompare(symbol,"depth",5) == 0)
1140 depth=GetImageDepth(image,exception);
1141 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1143 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1149 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1150 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1152 if (LocaleNCompare(symbol,"maxima",6) == 0)
1158 (void) GetImageRange(image,&minima,&maxima,exception);
1159 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1161 if (LocaleNCompare(symbol,"mean",4) == 0)
1167 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1168 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1170 if (LocaleNCompare(symbol,"minima",6) == 0)
1176 (void) GetImageRange(image,&minima,&maxima,exception);
1177 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1179 if (LocaleNCompare(symbol,"skewness",8) == 0)
1185 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1186 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1188 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1194 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1195 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1196 standard_deviation);
1198 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1199 ConstantString(statistic));
1200 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
1203 static MagickRealType
1204 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1205 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1207 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1210 return(FxGCD(beta,alpha % beta));
1214 static inline const char *FxSubexpression(const char *expression,
1215 ExceptionInfo *exception)
1224 subexpression=expression;
1225 while ((*subexpression != '\0') &&
1226 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1228 if (strchr("(",(int) *subexpression) != (char *) NULL)
1231 if (strchr(")",(int) *subexpression) != (char *) NULL)
1235 if (*subexpression == '\0')
1236 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1237 "UnbalancedParenthesis","`%s'",expression);
1238 return(subexpression);
1241 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1242 const ssize_t x,const ssize_t y,const char *expression,
1243 ExceptionInfo *exception)
1247 subexpression[MaxTextExtent],
1248 symbol[MaxTextExtent];
1275 i=GetImageIndexInList(fx_info->images);
1279 if (isalpha((int) *(p+1)) == 0)
1281 if (strchr("suv",(int) *p) != (char *) NULL)
1288 i=GetImageIndexInList(fx_info->images);
1291 case 'u': i=0; break;
1292 case 'v': i=1; break;
1299 for (p++; *p != '\0'; )
1313 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1315 i=(ssize_t) (alpha+0.5);
1321 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1328 for (p++; *p != '\0'; )
1342 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1353 for (p++; *p != '\0'; )
1367 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1377 length=GetImageListLength(fx_info->images);
1379 i+=(ssize_t) length;
1381 image=GetImageFromList(fx_info->images,i);
1382 if (image == (Image *) NULL)
1384 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1385 "NoSuchImage","`%s'",expression);
1388 GetPixelInfo(image,&pixel);
1389 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1390 point.x,point.y,&pixel,exception);
1391 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1392 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
1393 (LocaleCompare(p,"saturation") != 0) &&
1394 (LocaleCompare(p,"lightness") != 0))
1397 name[MaxTextExtent];
1399 (void) CopyMagickString(name,p,MaxTextExtent);
1400 for (q=name+(strlen(name)-1); q > name; q--)
1410 if ((strlen(name) > 2) &&
1411 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1416 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1417 if (color != (PixelInfo *) NULL)
1427 status=QueryColorCompliance(name,AllCompliance,&pixel,
1428 fx_info->exception);
1429 if (status != MagickFalse)
1431 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1432 name),ClonePixelInfo(&pixel));
1438 (void) CopyMagickString(symbol,p,MaxTextExtent);
1439 StripString(symbol);
1440 if (*symbol == '\0')
1444 case RedPixelChannel: return(QuantumScale*pixel.red);
1445 case GreenPixelChannel: return(QuantumScale*pixel.green);
1446 case BluePixelChannel: return(QuantumScale*pixel.blue);
1447 case BlackPixelChannel:
1449 if (image->colorspace != CMYKColorspace)
1451 (void) ThrowMagickException(exception,GetMagickModule(),
1452 ImageError,"ColorSeparatedImageRequired","`%s'",
1456 return(QuantumScale*pixel.black);
1458 case AlphaPixelChannel:
1463 if (pixel.matte == MagickFalse)
1465 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1468 case IndexPixelChannel:
1470 case IntensityPixelChannel:
1472 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1477 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1478 "UnableToParseExpression","`%s'",p);
1486 if (LocaleCompare(symbol,"a") == 0)
1487 return((MagickRealType) (QuantumScale*pixel.alpha));
1493 if (LocaleCompare(symbol,"b") == 0)
1494 return(QuantumScale*pixel.blue);
1500 if (LocaleNCompare(symbol,"channel",7) == 0)
1508 flags=ParseGeometry(symbol+7,&channel_info);
1509 if (image->colorspace == CMYKColorspace)
1512 case CyanPixelChannel:
1514 if ((flags & RhoValue) == 0)
1516 return(channel_info.rho);
1518 case MagentaPixelChannel:
1520 if ((flags & SigmaValue) == 0)
1522 return(channel_info.sigma);
1524 case YellowPixelChannel:
1526 if ((flags & XiValue) == 0)
1528 return(channel_info.xi);
1530 case BlackPixelChannel:
1532 if ((flags & PsiValue) == 0)
1534 return(channel_info.psi);
1536 case AlphaPixelChannel:
1538 if ((flags & ChiValue) == 0)
1540 return(channel_info.chi);
1547 case RedPixelChannel:
1549 if ((flags & RhoValue) == 0)
1551 return(channel_info.rho);
1553 case GreenPixelChannel:
1555 if ((flags & SigmaValue) == 0)
1557 return(channel_info.sigma);
1559 case BluePixelChannel:
1561 if ((flags & XiValue) == 0)
1563 return(channel_info.xi);
1565 case BlackPixelChannel:
1567 if ((flags & ChiValue) == 0)
1569 return(channel_info.chi);
1571 case AlphaPixelChannel:
1573 if ((flags & PsiValue) == 0)
1575 return(channel_info.psi);
1582 if (LocaleCompare(symbol,"c") == 0)
1583 return(QuantumScale*pixel.red);
1589 if (LocaleNCompare(symbol,"depth",5) == 0)
1590 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1596 if (LocaleCompare(symbol,"g") == 0)
1597 return(QuantumScale*pixel.green);
1603 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1604 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1605 if (LocaleCompare(symbol,"k") == 0)
1607 if (image->colorspace != CMYKColorspace)
1609 (void) ThrowMagickException(exception,GetMagickModule(),
1610 OptionError,"ColorSeparatedImageRequired","`%s'",
1614 return(QuantumScale*pixel.black);
1621 if (LocaleCompare(symbol,"h") == 0)
1622 return((MagickRealType) image->rows);
1623 if (LocaleCompare(symbol,"hue") == 0)
1630 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1639 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1640 (LocaleCompare(symbol,"image.minima") == 0) ||
1641 (LocaleCompare(symbol,"image.maxima") == 0) ||
1642 (LocaleCompare(symbol,"image.mean") == 0) ||
1643 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1644 (LocaleCompare(symbol,"image.skewness") == 0) ||
1645 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1646 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1647 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1648 return(image->resolution.x);
1649 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1650 return(image->resolution.y);
1651 if (LocaleCompare(symbol,"intensity") == 0)
1652 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1653 if (LocaleCompare(symbol,"i") == 0)
1654 return((MagickRealType) x);
1660 if (LocaleCompare(symbol,"j") == 0)
1661 return((MagickRealType) y);
1667 if (LocaleCompare(symbol,"lightness") == 0)
1674 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1678 if (LocaleCompare(symbol,"luminance") == 0)
1683 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1684 return(QuantumScale*luminence);
1691 if (LocaleNCompare(symbol,"maxima",6) == 0)
1692 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1693 if (LocaleNCompare(symbol,"mean",4) == 0)
1694 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1695 if (LocaleNCompare(symbol,"minima",6) == 0)
1696 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1697 if (LocaleCompare(symbol,"m") == 0)
1698 return(QuantumScale*pixel.blue);
1704 if (LocaleCompare(symbol,"n") == 0)
1705 return((MagickRealType) GetImageListLength(fx_info->images));
1711 if (LocaleCompare(symbol,"o") == 0)
1712 return(QuantumScale*pixel.alpha);
1718 if (LocaleCompare(symbol,"page.height") == 0)
1719 return((MagickRealType) image->page.height);
1720 if (LocaleCompare(symbol,"page.width") == 0)
1721 return((MagickRealType) image->page.width);
1722 if (LocaleCompare(symbol,"page.x") == 0)
1723 return((MagickRealType) image->page.x);
1724 if (LocaleCompare(symbol,"page.y") == 0)
1725 return((MagickRealType) image->page.y);
1731 if (LocaleCompare(symbol,"resolution.x") == 0)
1732 return(image->resolution.x);
1733 if (LocaleCompare(symbol,"resolution.y") == 0)
1734 return(image->resolution.y);
1735 if (LocaleCompare(symbol,"r") == 0)
1736 return(QuantumScale*pixel.red);
1742 if (LocaleCompare(symbol,"saturation") == 0)
1749 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1753 if (LocaleNCompare(symbol,"skewness",8) == 0)
1754 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1755 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1756 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1762 if (LocaleCompare(symbol,"t") == 0)
1763 return((MagickRealType) GetImageIndexInList(fx_info->images));
1769 if (LocaleCompare(symbol,"w") == 0)
1770 return((MagickRealType) image->columns);
1776 if (LocaleCompare(symbol,"y") == 0)
1777 return(QuantumScale*pixel.green);
1783 if (LocaleCompare(symbol,"z") == 0)
1788 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1796 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1797 if (value != (const char *) NULL)
1798 return((MagickRealType) StringToDouble(value,(char **) NULL));
1799 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1800 "UnableToParseExpression","`%s'",symbol);
1804 static const char *FxOperatorPrecedence(const char *expression,
1805 ExceptionInfo *exception)
1809 UndefinedPrecedence,
1811 BitwiseComplementPrecedence,
1813 ExponentialNotationPrecedence,
1817 RelationalPrecedence,
1818 EquivalencyPrecedence,
1819 BitwiseAndPrecedence,
1820 BitwiseOrPrecedence,
1821 LogicalAndPrecedence,
1822 LogicalOrPrecedence,
1824 AssignmentPrecedence,
1844 subexpression=(const char *) NULL;
1845 target=NullPrecedence;
1846 while (*expression != '\0')
1848 precedence=UndefinedPrecedence;
1849 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1854 switch (*expression)
1859 #if defined(MAGICKCORE_HAVE_ACOSH)
1860 if (LocaleNCompare(expression,"acosh",5) == 0)
1866 #if defined(MAGICKCORE_HAVE_ASINH)
1867 if (LocaleNCompare(expression,"asinh",5) == 0)
1873 #if defined(MAGICKCORE_HAVE_ATANH)
1874 if (LocaleNCompare(expression,"atanh",5) == 0)
1885 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1886 (LocaleNCompare(expression,"E-",2) == 0))
1888 expression+=2; /* scientific notation */
1895 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1896 (LocaleNCompare(expression,"j1",2) == 0))
1905 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1912 if ((c == (int) '{') || (c == (int) '['))
1915 if ((c == (int) '}') || (c == (int) ']'))
1918 switch ((unsigned char) *expression)
1923 precedence=BitwiseComplementPrecedence;
1929 precedence=ExponentPrecedence;
1934 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1935 (strchr(")",c) != (char *) NULL))) &&
1936 (((islower((int) ((char) *expression)) != 0) ||
1937 (strchr("(",(int) *expression) != (char *) NULL)) ||
1938 ((isdigit((int) ((char) c)) == 0) &&
1939 (isdigit((int) ((char) *expression)) != 0))) &&
1940 (strchr("xy",(int) *expression) == (char *) NULL))
1941 precedence=MultiplyPrecedence;
1948 precedence=MultiplyPrecedence;
1954 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1956 precedence=AdditionPrecedence;
1959 case LeftShiftOperator:
1960 case RightShiftOperator:
1962 precedence=ShiftPrecedence;
1966 case LessThanEqualOperator:
1967 case GreaterThanEqualOperator:
1970 precedence=RelationalPrecedence;
1974 case NotEqualOperator:
1976 precedence=EquivalencyPrecedence;
1981 precedence=BitwiseAndPrecedence;
1986 precedence=BitwiseOrPrecedence;
1989 case LogicalAndOperator:
1991 precedence=LogicalAndPrecedence;
1994 case LogicalOrOperator:
1996 precedence=LogicalOrPrecedence;
1999 case ExponentialNotation:
2001 precedence=ExponentialNotationPrecedence;
2007 precedence=TernaryPrecedence;
2012 precedence=AssignmentPrecedence;
2017 precedence=CommaPrecedence;
2022 precedence=SeparatorPrecedence;
2026 if ((precedence == BitwiseComplementPrecedence) ||
2027 (precedence == TernaryPrecedence) ||
2028 (precedence == AssignmentPrecedence))
2030 if (precedence > target)
2033 Right-to-left associativity.
2036 subexpression=expression;
2040 if (precedence >= target)
2043 Left-to-right associativity.
2046 subexpression=expression;
2048 if (strchr("(",(int) *expression) != (char *) NULL)
2049 expression=FxSubexpression(expression,exception);
2050 c=(int) (*expression++);
2052 return(subexpression);
2055 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2056 const PixelChannel channel,const ssize_t x,const ssize_t y,
2057 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2061 subexpression[MaxTextExtent];
2071 if (exception->severity != UndefinedException)
2073 while (isspace((int) *expression) != 0)
2075 if (*expression == '\0')
2077 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2078 "MissingExpression","`%s'",expression);
2081 *subexpression='\0';
2082 p=FxOperatorPrecedence(expression,exception);
2083 if (p != (const char *) NULL)
2085 (void) CopyMagickString(subexpression,expression,(size_t)
2087 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2089 switch ((unsigned char) *p)
2093 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2094 *beta=(MagickRealType) (~(size_t) *beta);
2099 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2100 return(*beta == 0.0 ? 1.0 : 0.0);
2104 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2105 channel,x,y,++p,beta,exception));
2109 case ExponentialNotation:
2111 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2112 return(alpha*(*beta));
2116 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2119 if (exception->severity == UndefinedException)
2120 (void) ThrowMagickException(exception,GetMagickModule(),
2121 OptionError,"DivideByZero","`%s'",expression);
2124 return(alpha/(*beta));
2128 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2129 *beta=fabs(floor(((double) *beta)+0.5));
2132 (void) ThrowMagickException(exception,GetMagickModule(),
2133 OptionError,"DivideByZero","`%s'",expression);
2136 return(fmod((double) alpha,(double) *beta));
2140 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2141 return(alpha+(*beta));
2145 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2146 return(alpha-(*beta));
2148 case LeftShiftOperator:
2150 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2151 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
2154 case RightShiftOperator:
2156 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2157 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
2162 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2163 return(alpha < *beta ? 1.0 : 0.0);
2165 case LessThanEqualOperator:
2167 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2168 return(alpha <= *beta ? 1.0 : 0.0);
2172 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2173 return(alpha > *beta ? 1.0 : 0.0);
2175 case GreaterThanEqualOperator:
2177 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2178 return(alpha >= *beta ? 1.0 : 0.0);
2182 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2183 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2185 case NotEqualOperator:
2187 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2188 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2192 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2193 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
2198 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2199 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
2202 case LogicalAndOperator:
2204 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2205 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2208 case LogicalOrOperator:
2210 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2211 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2219 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2221 p=StringToken(":",&q);
2222 if (q == (char *) NULL)
2224 (void) ThrowMagickException(exception,GetMagickModule(),
2225 OptionError,"UnableToParseExpression","`%s'",subexpression);
2228 if (fabs((double) alpha) > MagickEpsilon)
2229 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2231 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2237 numeric[MaxTextExtent];
2240 while (isalpha((int) ((unsigned char) *q)) != 0)
2244 (void) ThrowMagickException(exception,GetMagickModule(),
2245 OptionError,"UnableToParseExpression","`%s'",subexpression);
2248 ClearMagickException(exception);
2249 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2250 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2252 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2253 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2254 subexpression),ConstantString(numeric));
2259 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2264 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2269 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2275 if (strchr("(",(int) *expression) != (char *) NULL)
2277 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2278 subexpression[strlen(subexpression)-1]='\0';
2279 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2283 switch (*expression)
2287 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2293 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2299 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2301 return((MagickRealType) (~(size_t) (gamma+0.5)));
2306 if (LocaleNCompare(expression,"abs",3) == 0)
2308 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2310 return((MagickRealType) fabs((double) alpha));
2312 #if defined(MAGICKCORE_HAVE_ACOSH)
2313 if (LocaleNCompare(expression,"acosh",5) == 0)
2315 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2317 return((MagickRealType) acosh((double) alpha));
2320 if (LocaleNCompare(expression,"acos",4) == 0)
2322 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2324 return((MagickRealType) acos((double) alpha));
2326 #if defined(MAGICKCORE_HAVE_J1)
2327 if (LocaleNCompare(expression,"airy",4) == 0)
2329 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2333 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2334 return(gamma*gamma);
2337 #if defined(MAGICKCORE_HAVE_ASINH)
2338 if (LocaleNCompare(expression,"asinh",5) == 0)
2340 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2342 return((MagickRealType) asinh((double) alpha));
2345 if (LocaleNCompare(expression,"asin",4) == 0)
2347 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2349 return((MagickRealType) asin((double) alpha));
2351 if (LocaleNCompare(expression,"alt",3) == 0)
2353 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2355 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2357 if (LocaleNCompare(expression,"atan2",5) == 0)
2359 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2361 return((MagickRealType) atan2((double) alpha,(double) *beta));
2363 #if defined(MAGICKCORE_HAVE_ATANH)
2364 if (LocaleNCompare(expression,"atanh",5) == 0)
2366 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2368 return((MagickRealType) atanh((double) alpha));
2371 if (LocaleNCompare(expression,"atan",4) == 0)
2373 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2375 return((MagickRealType) atan((double) alpha));
2377 if (LocaleCompare(expression,"a") == 0)
2378 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2384 if (LocaleCompare(expression,"b") == 0)
2385 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2391 if (LocaleNCompare(expression,"ceil",4) == 0)
2393 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2395 return((MagickRealType) ceil((double) alpha));
2397 if (LocaleNCompare(expression,"cosh",4) == 0)
2399 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2401 return((MagickRealType) cosh((double) alpha));
2403 if (LocaleNCompare(expression,"cos",3) == 0)
2405 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2407 return((MagickRealType) cos((double) alpha));
2409 if (LocaleCompare(expression,"c") == 0)
2410 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2416 if (LocaleNCompare(expression,"debug",5) == 0)
2421 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2423 if (fx_info->images->colorspace == CMYKColorspace)
2426 case CyanPixelChannel: type="cyan"; break;
2427 case MagentaPixelChannel: type="magenta"; break;
2428 case YellowPixelChannel: type="yellow"; break;
2429 case AlphaPixelChannel: type="opacity"; break;
2430 case BlackPixelChannel: type="black"; break;
2431 default: type="unknown"; break;
2436 case RedPixelChannel: type="red"; break;
2437 case GreenPixelChannel: type="green"; break;
2438 case BluePixelChannel: type="blue"; break;
2439 case AlphaPixelChannel: type="opacity"; break;
2440 default: type="unknown"; break;
2442 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2443 if (strlen(subexpression) > 1)
2444 subexpression[strlen(subexpression)-1]='\0';
2445 if (fx_info->file != (FILE *) NULL)
2446 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2447 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2448 subexpression,GetMagickPrecision(),(double) alpha);
2451 if (LocaleNCompare(expression,"drc",3) == 0)
2453 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2455 return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0)));
2462 if (LocaleCompare(expression,"epsilon") == 0)
2463 return((MagickRealType) MagickEpsilon);
2464 if (LocaleNCompare(expression,"exp",3) == 0)
2466 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2468 return((MagickRealType) exp((double) alpha));
2470 if (LocaleCompare(expression,"e") == 0)
2471 return((MagickRealType) 2.7182818284590452354);
2477 if (LocaleNCompare(expression,"floor",5) == 0)
2479 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2481 return((MagickRealType) floor((double) alpha));
2488 if (LocaleNCompare(expression,"gauss",5) == 0)
2490 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2492 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2493 return((MagickRealType) gamma);
2495 if (LocaleNCompare(expression,"gcd",3) == 0)
2500 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2502 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2504 return((MagickRealType) gcd);
2506 if (LocaleCompare(expression,"g") == 0)
2507 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2513 if (LocaleCompare(expression,"h") == 0)
2514 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2515 if (LocaleCompare(expression,"hue") == 0)
2516 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2517 if (LocaleNCompare(expression,"hypot",5) == 0)
2519 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2521 return((MagickRealType) hypot((double) alpha,(double) *beta));
2528 if (LocaleCompare(expression,"k") == 0)
2529 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2535 if (LocaleCompare(expression,"intensity") == 0)
2536 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2537 if (LocaleNCompare(expression,"int",3) == 0)
2539 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2541 return((MagickRealType) floor(alpha));
2543 #if defined(MAGICKCORE_HAVE_ISNAN)
2544 if (LocaleNCompare(expression,"isnan",5) == 0)
2546 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2548 return((MagickRealType) !!isnan((double) alpha));
2551 if (LocaleCompare(expression,"i") == 0)
2552 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2558 if (LocaleCompare(expression,"j") == 0)
2559 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2560 #if defined(MAGICKCORE_HAVE_J0)
2561 if (LocaleNCompare(expression,"j0",2) == 0)
2563 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2565 return((MagickRealType) j0((double) alpha));
2568 #if defined(MAGICKCORE_HAVE_J1)
2569 if (LocaleNCompare(expression,"j1",2) == 0)
2571 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2573 return((MagickRealType) j1((double) alpha));
2576 #if defined(MAGICKCORE_HAVE_J1)
2577 if (LocaleNCompare(expression,"jinc",4) == 0)
2579 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2583 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
2593 if (LocaleNCompare(expression,"ln",2) == 0)
2595 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2597 return((MagickRealType) log((double) alpha));
2599 if (LocaleNCompare(expression,"logtwo",6) == 0)
2601 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2603 return((MagickRealType) log10((double) alpha))/log10(2.0);
2605 if (LocaleNCompare(expression,"log",3) == 0)
2607 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2609 return((MagickRealType) log10((double) alpha));
2611 if (LocaleCompare(expression,"lightness") == 0)
2612 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2618 if (LocaleCompare(expression,"MaxRGB") == 0)
2619 return((MagickRealType) QuantumRange);
2620 if (LocaleNCompare(expression,"maxima",6) == 0)
2622 if (LocaleNCompare(expression,"max",3) == 0)
2624 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2626 return(alpha > *beta ? alpha : *beta);
2628 if (LocaleNCompare(expression,"minima",6) == 0)
2630 if (LocaleNCompare(expression,"min",3) == 0)
2632 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2634 return(alpha < *beta ? alpha : *beta);
2636 if (LocaleNCompare(expression,"mod",3) == 0)
2638 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2640 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2643 if (LocaleCompare(expression,"m") == 0)
2644 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2650 if (LocaleNCompare(expression,"not",3) == 0)
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2654 return((MagickRealType) (alpha < MagickEpsilon));
2656 if (LocaleCompare(expression,"n") == 0)
2657 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2663 if (LocaleCompare(expression,"Opaque") == 0)
2665 if (LocaleCompare(expression,"o") == 0)
2666 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2672 if (LocaleCompare(expression,"phi") == 0)
2673 return((MagickRealType) MagickPHI);
2674 if (LocaleCompare(expression,"pi") == 0)
2675 return((MagickRealType) MagickPI);
2676 if (LocaleNCompare(expression,"pow",3) == 0)
2678 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2680 return((MagickRealType) pow((double) alpha,(double) *beta));
2682 if (LocaleCompare(expression,"p") == 0)
2683 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2689 if (LocaleCompare(expression,"QuantumRange") == 0)
2690 return((MagickRealType) QuantumRange);
2691 if (LocaleCompare(expression,"QuantumScale") == 0)
2692 return((MagickRealType) QuantumScale);
2698 if (LocaleNCompare(expression,"rand",4) == 0)
2699 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2700 if (LocaleNCompare(expression,"round",5) == 0)
2702 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2704 return((MagickRealType) floor((double) alpha+0.5));
2706 if (LocaleCompare(expression,"r") == 0)
2707 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2713 if (LocaleCompare(expression,"saturation") == 0)
2714 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2715 if (LocaleNCompare(expression,"sign",4) == 0)
2717 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2719 return(alpha < 0.0 ? -1.0 : 1.0);
2721 if (LocaleNCompare(expression,"sinc",4) == 0)
2723 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2727 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2731 if (LocaleNCompare(expression,"sinh",4) == 0)
2733 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2735 return((MagickRealType) sinh((double) alpha));
2737 if (LocaleNCompare(expression,"sin",3) == 0)
2739 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2741 return((MagickRealType) sin((double) alpha));
2743 if (LocaleNCompare(expression,"sqrt",4) == 0)
2745 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2747 return((MagickRealType) sqrt((double) alpha));
2749 if (LocaleNCompare(expression,"squish",6) == 0)
2751 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2753 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2755 if (LocaleCompare(expression,"s") == 0)
2756 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2762 if (LocaleNCompare(expression,"tanh",4) == 0)
2764 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2766 return((MagickRealType) tanh((double) alpha));
2768 if (LocaleNCompare(expression,"tan",3) == 0)
2770 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2772 return((MagickRealType) tan((double) alpha));
2774 if (LocaleCompare(expression,"Transparent") == 0)
2776 if (LocaleNCompare(expression,"trunc",5) == 0)
2778 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2781 return((MagickRealType) floor((double) alpha));
2782 return((MagickRealType) ceil((double) alpha));
2784 if (LocaleCompare(expression,"t") == 0)
2785 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2791 if (LocaleCompare(expression,"u") == 0)
2792 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2798 if (LocaleCompare(expression,"v") == 0)
2799 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2805 if (LocaleNCompare(expression,"while",5) == 0)
2809 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2811 } while (fabs((double) alpha) >= MagickEpsilon);
2812 return((MagickRealType) *beta);
2814 if (LocaleCompare(expression,"w") == 0)
2815 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2821 if (LocaleCompare(expression,"y") == 0)
2822 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2828 if (LocaleCompare(expression,"z") == 0)
2829 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2835 q=(char *) expression;
2836 alpha=InterpretSiPrefixValue(expression,&q);
2837 if (q == expression)
2838 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2842 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2843 MagickRealType *alpha,ExceptionInfo *exception)
2848 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2853 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2854 MagickRealType *alpha,ExceptionInfo *exception)
2863 fx_info->file=(FILE *) NULL;
2864 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2870 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2871 const PixelChannel channel,const ssize_t x,const ssize_t y,
2872 MagickRealType *alpha,ExceptionInfo *exception)
2878 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2880 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2894 % FxImage() applies a mathematical expression to the specified image.
2896 % The format of the FxImage method is:
2898 % Image *FxImage(const Image *image,const char *expression,
2899 % ExceptionInfo *exception)
2901 % A description of each parameter follows:
2903 % o image: the image.
2905 % o expression: A mathematical expression.
2907 % o exception: return any errors or warnings in this structure.
2911 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2916 assert(fx_info != (FxInfo **) NULL);
2917 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2918 if (fx_info[i] != (FxInfo *) NULL)
2919 fx_info[i]=DestroyFxInfo(fx_info[i]);
2920 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2924 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2925 ExceptionInfo *exception)
2942 number_threads=GetOpenMPMaximumThreads();
2943 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2944 if (fx_info == (FxInfo **) NULL)
2945 return((FxInfo **) NULL);
2946 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2947 if (*expression != '@')
2948 fx_expression=ConstantString(expression);
2950 fx_expression=FileToString(expression+1,~0,exception);
2951 for (i=0; i < (ssize_t) number_threads; i++)
2953 fx_info[i]=AcquireFxInfo(image,fx_expression);
2954 if (fx_info[i] == (FxInfo *) NULL)
2955 return(DestroyFxThreadSet(fx_info));
2956 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2958 fx_expression=DestroyString(fx_expression);
2962 MagickExport Image *FxImage(const Image *image,const char *expression,
2963 ExceptionInfo *exception)
2965 #define FxImageTag "Fx/Image"
2989 assert(image != (Image *) NULL);
2990 assert(image->signature == MagickSignature);
2991 if (image->debug != MagickFalse)
2992 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2993 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2994 if (fx_image == (Image *) NULL)
2995 return((Image *) NULL);
2996 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
2998 fx_image=DestroyImage(fx_image);
2999 return((Image *) NULL);
3001 fx_info=AcquireFxThreadSet(image,expression,exception);
3002 if (fx_info == (FxInfo **) NULL)
3004 fx_image=DestroyImage(fx_image);
3005 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3007 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3008 if (status == MagickFalse)
3010 fx_image=DestroyImage(fx_image);
3011 fx_info=DestroyFxThreadSet(fx_info);
3012 return((Image *) NULL);
3019 image_view=AcquireCacheView(image);
3020 fx_view=AcquireCacheView(fx_image);
3021 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3022 #pragma omp parallel for schedule(static,4) shared(progress,status)
3024 for (y=0; y < (ssize_t) fx_image->rows; y++)
3027 id = GetOpenMPThreadId();
3029 register const Quantum
3038 if (status == MagickFalse)
3040 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3041 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3042 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3047 for (x=0; x < (ssize_t) fx_image->columns; x++)
3052 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3064 channel=GetPixelChannelMapChannel(image,i);
3065 traits=GetPixelChannelMapTraits(image,channel);
3066 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3067 if ((traits == UndefinedPixelTrait) ||
3068 (fx_traits == UndefinedPixelTrait))
3070 if (((fx_traits & CopyPixelTrait) != 0) ||
3071 (GetPixelMask(image,p) != 0))
3073 SetPixelChannel(fx_image,channel,p[i],q);
3077 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3079 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3081 p+=GetPixelChannels(image);
3082 q+=GetPixelChannels(fx_image);
3084 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3086 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3091 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3092 #pragma omp critical (MagickCore_FxImage)
3094 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3095 if (proceed == MagickFalse)
3099 fx_view=DestroyCacheView(fx_view);
3100 image_view=DestroyCacheView(image_view);
3101 fx_info=DestroyFxThreadSet(fx_info);
3102 if (status == MagickFalse)
3103 fx_image=DestroyImage(fx_image);
3108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3112 % I m p l o d e I m a g e %
3116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3118 % ImplodeImage() creates a new image that is a copy of an existing
3119 % one with the image pixels "implode" by the specified percentage. It
3120 % allocates the memory necessary for the new Image structure and returns a
3121 % pointer to the new image.
3123 % The format of the ImplodeImage method is:
3125 % Image *ImplodeImage(const Image *image,const double amount,
3126 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3128 % A description of each parameter follows:
3130 % o implode_image: Method ImplodeImage returns a pointer to the image
3131 % after it is implode. A null image is returned if there is a memory
3134 % o image: the image.
3136 % o amount: Define the extent of the implosion.
3138 % o method: the pixel interpolation method.
3140 % o exception: return any errors or warnings in this structure.
3143 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3144 const PixelInterpolateMethod method,ExceptionInfo *exception)
3146 #define ImplodeImageTag "Implode/Image"
3172 Initialize implode image attributes.
3174 assert(image != (Image *) NULL);
3175 assert(image->signature == MagickSignature);
3176 if (image->debug != MagickFalse)
3177 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3178 assert(exception != (ExceptionInfo *) NULL);
3179 assert(exception->signature == MagickSignature);
3180 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3182 if (implode_image == (Image *) NULL)
3183 return((Image *) NULL);
3184 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3186 implode_image=DestroyImage(implode_image);
3187 return((Image *) NULL);
3189 if (implode_image->background_color.alpha != OpaqueAlpha)
3190 implode_image->matte=MagickTrue;
3192 Compute scaling factor.
3196 center.x=0.5*image->columns;
3197 center.y=0.5*image->rows;
3199 if (image->columns > image->rows)
3200 scale.y=(double) image->columns/(double) image->rows;
3202 if (image->columns < image->rows)
3204 scale.x=(double) image->rows/(double) image->columns;
3212 image_view=AcquireCacheView(image);
3213 implode_view=AcquireCacheView(implode_image);
3214 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3215 #pragma omp parallel for schedule(static,4) shared(progress,status)
3217 for (y=0; y < (ssize_t) image->rows; y++)
3225 register const Quantum
3234 if (status == MagickFalse)
3236 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3237 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3239 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3244 delta.y=scale.y*(double) (y-center.y);
3245 for (x=0; x < (ssize_t) image->columns; x++)
3251 Determine if the pixel is within an ellipse.
3253 if (GetPixelMask(image,p) != 0)
3255 p+=GetPixelChannels(image);
3256 q+=GetPixelChannels(implode_image);
3259 delta.x=scale.x*(double) (x-center.x);
3260 distance=delta.x*delta.x+delta.y*delta.y;
3261 if (distance >= (radius*radius))
3262 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3271 channel=GetPixelChannelMapChannel(image,i);
3272 traits=GetPixelChannelMapTraits(image,channel);
3273 implode_traits=GetPixelChannelMapTraits(implode_image,channel);
3274 if ((traits == UndefinedPixelTrait) ||
3275 (implode_traits == UndefinedPixelTrait))
3277 SetPixelChannel(implode_image,channel,p[i],q);
3289 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3291 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3292 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3293 scale.y+center.y),q,exception);
3295 p+=GetPixelChannels(image);
3296 q+=GetPixelChannels(implode_image);
3298 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3300 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3305 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3306 #pragma omp critical (MagickCore_ImplodeImage)
3308 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3309 if (proceed == MagickFalse)
3313 implode_view=DestroyCacheView(implode_view);
3314 image_view=DestroyCacheView(image_view);
3315 if (status == MagickFalse)
3316 implode_image=DestroyImage(implode_image);
3317 return(implode_image);
3321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3325 % M o r p h I m a g e s %
3329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3331 % The MorphImages() method requires a minimum of two images. The first
3332 % image is transformed into the second by a number of intervening images
3333 % as specified by frames.
3335 % The format of the MorphImage method is:
3337 % Image *MorphImages(const Image *image,const size_t number_frames,
3338 % ExceptionInfo *exception)
3340 % A description of each parameter follows:
3342 % o image: the image.
3344 % o number_frames: Define the number of in-between image to generate.
3345 % The more in-between frames, the smoother the morph.
3347 % o exception: return any errors or warnings in this structure.
3350 MagickExport Image *MorphImages(const Image *image,
3351 const size_t number_frames,ExceptionInfo *exception)
3353 #define MorphImageTag "Morph/Image"
3369 register const Image
3379 Clone first frame in sequence.
3381 assert(image != (Image *) NULL);
3382 assert(image->signature == MagickSignature);
3383 if (image->debug != MagickFalse)
3384 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3385 assert(exception != (ExceptionInfo *) NULL);
3386 assert(exception->signature == MagickSignature);
3387 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3388 if (morph_images == (Image *) NULL)
3389 return((Image *) NULL);
3390 if (GetNextImageInList(image) == (Image *) NULL)
3395 for (i=1; i < (ssize_t) number_frames; i++)
3397 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3398 if (morph_image == (Image *) NULL)
3400 morph_images=DestroyImageList(morph_images);
3401 return((Image *) NULL);
3403 AppendImageToList(&morph_images,morph_image);
3404 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3409 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3411 if (proceed == MagickFalse)
3415 return(GetFirstImageInList(morph_images));
3418 Morph image sequence.
3423 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3425 for (i=0; i < (ssize_t) number_frames; i++)
3431 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3433 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3434 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
3435 GetNextImageInList(next)->rows+0.5),next->filter,exception);
3436 if (morph_image == (Image *) NULL)
3438 morph_images=DestroyImageList(morph_images);
3439 return((Image *) NULL);
3441 status=SetImageStorageClass(morph_image,DirectClass,exception);
3442 if (status == MagickFalse)
3444 morph_image=DestroyImage(morph_image);
3445 return((Image *) NULL);
3447 AppendImageToList(&morph_images,morph_image);
3448 morph_images=GetLastImageInList(morph_images);
3449 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3450 morph_images->rows,GetNextImageInList(next)->filter,exception);
3451 if (morph_image == (Image *) NULL)
3453 morph_images=DestroyImageList(morph_images);
3454 return((Image *) NULL);
3456 image_view=AcquireCacheView(morph_image);
3457 morph_view=AcquireCacheView(morph_images);
3458 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3459 #pragma omp parallel for schedule(static,4) shared(status)
3461 for (y=0; y < (ssize_t) morph_images->rows; y++)
3466 register const Quantum
3475 if (status == MagickFalse)
3477 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3479 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3481 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3486 for (x=0; x < (ssize_t) morph_images->columns; x++)
3491 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
3500 channel=GetPixelChannelMapChannel(image,i);
3501 traits=GetPixelChannelMapTraits(image,channel);
3502 morph_traits=GetPixelChannelMapTraits(morph_image,channel);
3503 if ((traits == UndefinedPixelTrait) ||
3504 (morph_traits == UndefinedPixelTrait))
3506 if (((morph_traits & CopyPixelTrait) != 0) ||
3507 (GetPixelMask(image,p) != 0))
3509 SetPixelChannel(morph_image,channel,p[i],q);
3512 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3513 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3515 p+=GetPixelChannels(morph_image);
3516 q+=GetPixelChannels(morph_images);
3518 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3519 if (sync == MagickFalse)
3522 morph_view=DestroyCacheView(morph_view);
3523 image_view=DestroyCacheView(image_view);
3524 morph_image=DestroyImage(morph_image);
3526 if (i < (ssize_t) number_frames)
3529 Clone last frame in sequence.
3531 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3532 if (morph_image == (Image *) NULL)
3534 morph_images=DestroyImageList(morph_images);
3535 return((Image *) NULL);
3537 AppendImageToList(&morph_images,morph_image);
3538 morph_images=GetLastImageInList(morph_images);
3539 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3544 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3545 #pragma omp critical (MagickCore_MorphImages)
3547 proceed=SetImageProgress(image,MorphImageTag,scene,
3548 GetImageListLength(image));
3549 if (proceed == MagickFalse)
3554 if (GetNextImageInList(next) != (Image *) NULL)
3556 morph_images=DestroyImageList(morph_images);
3557 return((Image *) NULL);
3559 return(GetFirstImageInList(morph_images));
3563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3567 % P l a s m a I m a g e %
3571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3573 % PlasmaImage() initializes an image with plasma fractal values. The image
3574 % must be initialized with a base color and the random number generator
3575 % seeded before this method is called.
3577 % The format of the PlasmaImage method is:
3579 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3580 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3582 % A description of each parameter follows:
3584 % o image: the image.
3586 % o segment: Define the region to apply plasma fractals values.
3588 % o attenuate: Define the plasma attenuation factor.
3590 % o depth: Limit the plasma recursion depth.
3592 % o exception: return any errors or warnings in this structure.
3596 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3597 const MagickRealType pixel,const MagickRealType noise)
3602 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3607 static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3608 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3609 const SegmentInfo *segment,size_t attenuate,size_t depth,
3610 ExceptionInfo *exception)
3621 register const Quantum
3637 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3645 Divide the area into quadrants and recurse.
3649 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3650 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3651 local_info=(*segment);
3652 local_info.x2=(double) x_mid;
3653 local_info.y2=(double) y_mid;
3654 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3655 &local_info,attenuate,depth,exception);
3656 local_info=(*segment);
3657 local_info.y1=(double) y_mid;
3658 local_info.x2=(double) x_mid;
3659 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3660 &local_info,attenuate,depth,exception);
3661 local_info=(*segment);
3662 local_info.x1=(double) x_mid;
3663 local_info.y2=(double) y_mid;
3664 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3665 &local_info,attenuate,depth,exception);
3666 local_info=(*segment);
3667 local_info.x1=(double) x_mid;
3668 local_info.y1=(double) y_mid;
3669 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3670 &local_info,attenuate,depth,exception));
3672 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3673 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3674 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3675 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3676 return(MagickFalse);
3678 Average pixels and apply plasma.
3680 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3681 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3686 x=(ssize_t) ceil(segment->x1-0.5);
3687 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3689 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3691 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3692 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3693 (q == (Quantum *) NULL))
3695 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3697 channel=GetPixelChannelMapChannel(image,i);
3698 traits=GetPixelChannelMapTraits(image,channel);
3699 if (traits == UndefinedPixelTrait)
3701 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3703 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3704 if (segment->x1 != segment->x2)
3709 x=(ssize_t) ceil(segment->x2-0.5);
3710 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3712 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3714 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3715 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3716 (q == (Quantum *) NULL))
3718 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3720 channel=GetPixelChannelMapChannel(image,i);
3721 traits=GetPixelChannelMapTraits(image,channel);
3722 if (traits == UndefinedPixelTrait)
3724 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3726 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3729 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3731 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3736 y=(ssize_t) ceil(segment->y2-0.5);
3737 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3739 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3741 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3742 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3743 (q == (Quantum *) NULL))
3745 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3747 channel=GetPixelChannelMapChannel(image,i);
3748 traits=GetPixelChannelMapTraits(image,channel);
3749 if (traits == UndefinedPixelTrait)
3751 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3753 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3755 if (segment->y1 != segment->y2)
3760 y=(ssize_t) ceil(segment->y1-0.5);
3761 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3763 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3765 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3766 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3767 (q == (Quantum *) NULL))
3769 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3771 channel=GetPixelChannelMapChannel(image,i);
3772 traits=GetPixelChannelMapTraits(image,channel);
3773 if (traits == UndefinedPixelTrait)
3775 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3777 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3780 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3785 x=(ssize_t) ceil(segment->x1-0.5);
3786 y=(ssize_t) ceil(segment->y1-0.5);
3787 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
3788 x=(ssize_t) ceil(segment->x2-0.5);
3789 y=(ssize_t) ceil(segment->y2-0.5);
3790 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
3791 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3792 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3793 (q == (Quantum *) NULL))
3795 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3797 channel=GetPixelChannelMapChannel(image,i);
3798 traits=GetPixelChannelMapTraits(image,channel);
3799 if (traits == UndefinedPixelTrait)
3801 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3803 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3805 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3807 return(MagickFalse);
3810 MagickExport MagickBooleanType PlasmaImage(Image *image,
3811 const SegmentInfo *segment,size_t attenuate,size_t depth,
3812 ExceptionInfo *exception)
3825 if (image->debug != MagickFalse)
3826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3827 assert(image != (Image *) NULL);
3828 assert(image->signature == MagickSignature);
3829 if (image->debug != MagickFalse)
3830 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3831 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3832 return(MagickFalse);
3833 image_view=AcquireCacheView(image);
3834 u_view=AcquireCacheView(image);
3835 v_view=AcquireCacheView(image);
3836 random_info=AcquireRandomInfo();
3837 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3838 attenuate,depth,exception);
3839 random_info=DestroyRandomInfo(random_info);
3840 v_view=DestroyCacheView(v_view);
3841 u_view=DestroyCacheView(u_view);
3842 image_view=DestroyCacheView(image_view);
3847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3851 % P o l a r o i d I m a g e %
3855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3857 % PolaroidImage() simulates a Polaroid picture.
3859 % The format of the AnnotateImage method is:
3861 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3862 % const char *caption,const double angle,
3863 % const PixelInterpolateMethod method,ExceptionInfo exception)
3865 % A description of each parameter follows:
3867 % o image: the image.
3869 % o draw_info: the draw info.
3871 % o caption: the Polaroid caption.
3873 % o angle: Apply the effect along this angle.
3875 % o method: the pixel interpolation method.
3877 % o exception: return any errors or warnings in this structure.
3880 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3881 const char *caption,const double angle,const PixelInterpolateMethod method,
3882 ExceptionInfo *exception)
3900 Simulate a Polaroid picture.
3902 assert(image != (Image *) NULL);
3903 assert(image->signature == MagickSignature);
3904 if (image->debug != MagickFalse)
3905 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3906 assert(exception != (ExceptionInfo *) NULL);
3907 assert(exception->signature == MagickSignature);
3908 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3909 image->rows)/25.0,10.0);
3910 height=image->rows+2*quantum;
3911 caption_image=(Image *) NULL;
3912 if (caption != (const char *) NULL)
3915 geometry[MaxTextExtent],
3931 Generate caption image.
3933 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3934 if (caption_image == (Image *) NULL)
3935 return((Image *) NULL);
3936 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3937 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3939 (void) CloneString(&annotate_info->text,text);
3940 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3942 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
3943 (metrics.ascent-metrics.descent)+0.5),exception);
3944 if (status == MagickFalse)
3945 caption_image=DestroyImage(caption_image);
3948 caption_image->background_color=image->border_color;
3949 (void) SetImageBackgroundColor(caption_image,exception);
3950 (void) CloneString(&annotate_info->text,text);
3951 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
3953 if (annotate_info->gravity == UndefinedGravity)
3954 (void) CloneString(&annotate_info->geometry,AcquireString(
3956 (void) AnnotateImage(caption_image,annotate_info,exception);
3957 height+=caption_image->rows;
3959 annotate_info=DestroyDrawInfo(annotate_info);
3960 text=DestroyString(text);
3962 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3964 if (picture_image == (Image *) NULL)
3966 if (caption_image != (Image *) NULL)
3967 caption_image=DestroyImage(caption_image);
3968 return((Image *) NULL);
3970 picture_image->background_color=image->border_color;
3971 (void) SetImageBackgroundColor(picture_image,exception);
3972 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum,
3974 if (caption_image != (Image *) NULL)
3976 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
3977 MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception);
3978 caption_image=DestroyImage(caption_image);
3980 (void) QueryColorCompliance("none",AllCompliance,
3981 &picture_image->background_color,exception);
3982 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
3983 rotate_image=RotateImage(picture_image,90.0,exception);
3984 picture_image=DestroyImage(picture_image);
3985 if (rotate_image == (Image *) NULL)
3986 return((Image *) NULL);
3987 picture_image=rotate_image;
3988 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3989 picture_image->columns,method,exception);
3990 picture_image=DestroyImage(picture_image);
3991 if (bend_image == (Image *) NULL)
3992 return((Image *) NULL);
3993 picture_image=bend_image;
3994 rotate_image=RotateImage(picture_image,-90.0,exception);
3995 picture_image=DestroyImage(picture_image);
3996 if (rotate_image == (Image *) NULL)
3997 return((Image *) NULL);
3998 picture_image=rotate_image;
3999 picture_image->background_color=image->background_color;
4000 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4002 if (polaroid_image == (Image *) NULL)
4004 picture_image=DestroyImage(picture_image);
4005 return(picture_image);
4007 flop_image=FlopImage(polaroid_image,exception);
4008 polaroid_image=DestroyImage(polaroid_image);
4009 if (flop_image == (Image *) NULL)
4011 picture_image=DestroyImage(picture_image);
4012 return(picture_image);
4014 polaroid_image=flop_image;
4015 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
4016 MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
4017 picture_image=DestroyImage(picture_image);
4018 (void) QueryColorCompliance("none",AllCompliance,
4019 &polaroid_image->background_color,exception);
4020 rotate_image=RotateImage(polaroid_image,angle,exception);
4021 polaroid_image=DestroyImage(polaroid_image);
4022 if (rotate_image == (Image *) NULL)
4023 return((Image *) NULL);
4024 polaroid_image=rotate_image;
4025 trim_image=TrimImage(polaroid_image,exception);
4026 polaroid_image=DestroyImage(polaroid_image);
4027 if (trim_image == (Image *) NULL)
4028 return((Image *) NULL);
4029 polaroid_image=trim_image;
4030 return(polaroid_image);
4034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4038 % S e p i a T o n e I m a g e %
4042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4044 % MagickSepiaToneImage() applies a special effect to the image, similar to the
4045 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4046 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4047 % threshold of 80% is a good starting point for a reasonable tone.
4049 % The format of the SepiaToneImage method is:
4051 % Image *SepiaToneImage(const Image *image,const double threshold,
4052 % ExceptionInfo *exception)
4054 % A description of each parameter follows:
4056 % o image: the image.
4058 % o threshold: the tone threshold.
4060 % o exception: return any errors or warnings in this structure.
4063 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4064 ExceptionInfo *exception)
4066 #define SepiaToneImageTag "SepiaTone/Image"
4085 Initialize sepia-toned image attributes.
4087 assert(image != (const Image *) NULL);
4088 assert(image->signature == MagickSignature);
4089 if (image->debug != MagickFalse)
4090 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4091 assert(exception != (ExceptionInfo *) NULL);
4092 assert(exception->signature == MagickSignature);
4093 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
4094 if (sepia_image == (Image *) NULL)
4095 return((Image *) NULL);
4096 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4098 sepia_image=DestroyImage(sepia_image);
4099 return((Image *) NULL);
4102 Tone each row of the image.
4106 image_view=AcquireCacheView(image);
4107 sepia_view=AcquireCacheView(sepia_image);
4108 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4109 #pragma omp parallel for schedule(static,4) shared(progress,status)
4111 for (y=0; y < (ssize_t) image->rows; y++)
4113 register const Quantum
4122 if (status == MagickFalse)
4124 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4125 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4127 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4132 for (x=0; x < (ssize_t) image->columns; x++)
4138 intensity=(MagickRealType) GetPixelIntensity(image,p);
4139 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4140 (MagickRealType) QuantumRange-threshold;
4141 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4142 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4143 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4144 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4145 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4146 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4148 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4149 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4150 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4151 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4152 p+=GetPixelChannels(image);
4153 q+=GetPixelChannels(sepia_image);
4155 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4157 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4162 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4163 #pragma omp critical (MagickCore_SepiaToneImage)
4165 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4167 if (proceed == MagickFalse)
4171 sepia_view=DestroyCacheView(sepia_view);
4172 image_view=DestroyCacheView(image_view);
4173 (void) NormalizeImage(sepia_image,exception);
4174 (void) ContrastImage(sepia_image,MagickTrue,exception);
4175 if (status == MagickFalse)
4176 sepia_image=DestroyImage(sepia_image);
4177 return(sepia_image);
4181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4185 % S h a d o w I m a g e %
4189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4191 % ShadowImage() simulates a shadow from the specified image and returns it.
4193 % The format of the ShadowImage method is:
4195 % Image *ShadowImage(const Image *image,const double alpha,
4196 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4197 % ExceptionInfo *exception)
4199 % A description of each parameter follows:
4201 % o image: the image.
4203 % o alpha: percentage transparency.
4205 % o sigma: the standard deviation of the Gaussian, in pixels.
4207 % o x_offset: the shadow x-offset.
4209 % o y_offset: the shadow y-offset.
4211 % o exception: return any errors or warnings in this structure.
4214 MagickExport Image *ShadowImage(const Image *image,const double alpha,
4215 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4216 ExceptionInfo *exception)
4218 #define ShadowImageTag "Shadow/Image"
4240 assert(image != (Image *) NULL);
4241 assert(image->signature == MagickSignature);
4242 if (image->debug != MagickFalse)
4243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4244 assert(exception != (ExceptionInfo *) NULL);
4245 assert(exception->signature == MagickSignature);
4246 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4247 if (clone_image == (Image *) NULL)
4248 return((Image *) NULL);
4249 if (IsGrayColorspace(image->colorspace) != MagickFalse)
4250 (void) TransformImageColorspace(clone_image,sRGBColorspace,exception);
4251 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod,
4253 border_info.width=(size_t) floor(2.0*sigma+0.5);
4254 border_info.height=(size_t) floor(2.0*sigma+0.5);
4257 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4259 clone_image->matte=MagickTrue;
4260 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
4261 clone_image=DestroyImage(clone_image);
4262 if (border_image == (Image *) NULL)
4263 return((Image *) NULL);
4264 if (border_image->matte == MagickFalse)
4265 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4270 image_view=AcquireCacheView(border_image);
4271 for (y=0; y < (ssize_t) border_image->rows; y++)
4282 if (status == MagickFalse)
4284 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4286 if (q == (Quantum *) NULL)
4291 background_color=border_image->background_color;
4292 background_color.matte=MagickTrue;
4293 for (x=0; x < (ssize_t) border_image->columns; x++)
4295 if (border_image->matte != MagickFalse)
4296 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4297 SetPixelInfoPixel(border_image,&background_color,q);
4298 q+=GetPixelChannels(border_image);
4300 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4303 image_view=DestroyCacheView(image_view);
4304 if (status == MagickFalse)
4306 border_image=DestroyImage(border_image);
4307 return((Image *) NULL);
4309 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4310 shadow_image=BlurImage(border_image,0.0,sigma,exception);
4311 border_image=DestroyImage(border_image);
4312 if (shadow_image == (Image *) NULL)
4313 return((Image *) NULL);
4314 (void) SetPixelChannelMapMask(shadow_image,channel_mask);
4315 if (shadow_image->page.width == 0)
4316 shadow_image->page.width=shadow_image->columns;
4317 if (shadow_image->page.height == 0)
4318 shadow_image->page.height=shadow_image->rows;
4319 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4320 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4321 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4322 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4323 return(shadow_image);
4327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4331 % S k e t c h I m a g e %
4335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4337 % SketchImage() simulates a pencil sketch. We convolve the image with a
4338 % Gaussian operator of the given radius and standard deviation (sigma). For
4339 % reasonable results, radius should be larger than sigma. Use a radius of 0
4340 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4343 % The format of the SketchImage method is:
4345 % Image *SketchImage(const Image *image,const double radius,
4346 % const double sigma,const double angle,ExceptionInfo *exception)
4348 % A description of each parameter follows:
4350 % o image: the image.
4352 % o radius: the radius of the Gaussian, in pixels, not counting the
4355 % o sigma: the standard deviation of the Gaussian, in pixels.
4357 % o angle: apply the effect along this angle.
4359 % o exception: return any errors or warnings in this structure.
4362 MagickExport Image *SketchImage(const Image *image,const double radius,
4363 const double sigma,const double angle,ExceptionInfo *exception)
4379 **restrict random_info;
4387 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4388 MagickTrue,exception);
4389 if (random_image == (Image *) NULL)
4390 return((Image *) NULL);
4392 random_info=AcquireRandomInfoThreadSet();
4393 random_view=AcquireCacheView(random_image);
4394 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4395 #pragma omp parallel for schedule(static,4) shared(status)
4397 for (y=0; y < (ssize_t) random_image->rows; y++)
4400 id = GetOpenMPThreadId();
4408 if (status == MagickFalse)
4410 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4412 if (q == (Quantum *) NULL)
4417 for (x=0; x < (ssize_t) random_image->columns; x++)
4425 if (GetPixelMask(random_image,q) != 0)
4427 q+=GetPixelChannels(random_image);
4430 value=GetPseudoRandomValue(random_info[id]);
4431 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4439 channel=GetPixelChannelMapChannel(image,i);
4440 traits=GetPixelChannelMapTraits(image,channel);
4441 if (traits == UndefinedPixelTrait)
4443 q[i]=ClampToQuantum(QuantumRange*value);
4445 q+=GetPixelChannels(random_image);
4447 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4450 random_view=DestroyCacheView(random_view);
4451 random_info=DestroyRandomInfoThreadSet(random_info);
4452 if (status == MagickFalse)
4454 random_image=DestroyImage(random_image);
4455 return(random_image);
4457 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4458 random_image=DestroyImage(random_image);
4459 if (blur_image == (Image *) NULL)
4460 return((Image *) NULL);
4461 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
4462 blur_image=DestroyImage(blur_image);
4463 if (dodge_image == (Image *) NULL)
4464 return((Image *) NULL);
4465 (void) NormalizeImage(dodge_image,exception);
4466 (void) NegateImage(dodge_image,MagickFalse,exception);
4467 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
4468 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4469 if (sketch_image == (Image *) NULL)
4471 dodge_image=DestroyImage(dodge_image);
4472 return((Image *) NULL);
4474 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
4475 MagickTrue,0,0,exception);
4476 dodge_image=DestroyImage(dodge_image);
4477 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4478 if (blend_image == (Image *) NULL)
4480 sketch_image=DestroyImage(sketch_image);
4481 return((Image *) NULL);
4483 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4484 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue,
4486 blend_image=DestroyImage(blend_image);
4487 return(sketch_image);
4491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4495 % S o l a r i z e I m a g e %
4499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4501 % SolarizeImage() applies a special effect to the image, similar to the effect
4502 % achieved in a photo darkroom by selectively exposing areas of photo
4503 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4504 % measure of the extent of the solarization.
4506 % The format of the SolarizeImage method is:
4508 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4509 % ExceptionInfo *exception)
4511 % A description of each parameter follows:
4513 % o image: the image.
4515 % o threshold: Define the extent of the solarization.
4517 % o exception: return any errors or warnings in this structure.
4520 MagickExport MagickBooleanType SolarizeImage(Image *image,
4521 const double threshold,ExceptionInfo *exception)
4523 #define SolarizeImageTag "Solarize/Image"
4537 assert(image != (Image *) NULL);
4538 assert(image->signature == MagickSignature);
4539 if (image->debug != MagickFalse)
4540 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4541 if (image->storage_class == PseudoClass)
4549 for (i=0; i < (ssize_t) image->colors; i++)
4551 if ((MagickRealType) image->colormap[i].red > threshold)
4552 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4553 if ((MagickRealType) image->colormap[i].green > threshold)
4554 image->colormap[i].green=(Quantum) QuantumRange-
4555 image->colormap[i].green;
4556 if ((MagickRealType) image->colormap[i].blue > threshold)
4557 image->colormap[i].blue=(Quantum) QuantumRange-
4558 image->colormap[i].blue;
4566 image_view=AcquireCacheView(image);
4567 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4568 #pragma omp parallel for schedule(static,4) shared(progress,status)
4570 for (y=0; y < (ssize_t) image->rows; y++)
4578 if (status == MagickFalse)
4580 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4581 if (q == (Quantum *) NULL)
4586 for (x=0; x < (ssize_t) image->columns; x++)
4591 if (GetPixelMask(image,q) != 0)
4593 q+=GetPixelChannels(image);
4596 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4604 channel=GetPixelChannelMapChannel(image,i);
4605 traits=GetPixelChannelMapTraits(image,channel);
4606 if ((traits == UndefinedPixelTrait) ||
4607 ((traits & CopyPixelTrait) != 0))
4609 if ((MagickRealType) q[i] > threshold)
4610 q[i]=QuantumRange-q[i];
4612 q+=GetPixelChannels(image);
4614 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4616 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4621 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4622 #pragma omp critical (MagickCore_SolarizeImage)
4624 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4625 if (proceed == MagickFalse)
4629 image_view=DestroyCacheView(image_view);
4634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4638 % S t e g a n o I m a g e %
4642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4644 % SteganoImage() hides a digital watermark within the image. Recover
4645 % the hidden watermark later to prove that the authenticity of an image.
4646 % Offset defines the start position within the image to hide the watermark.
4648 % The format of the SteganoImage method is:
4650 % Image *SteganoImage(const Image *image,Image *watermark,
4651 % ExceptionInfo *exception)
4653 % A description of each parameter follows:
4655 % o image: the image.
4657 % o watermark: the watermark image.
4659 % o exception: return any errors or warnings in this structure.
4662 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4663 ExceptionInfo *exception)
4665 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4666 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4667 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4668 #define SteganoImageTag "Stegano/Image"
4703 Initialize steganographic image attributes.
4705 assert(image != (const Image *) NULL);
4706 assert(image->signature == MagickSignature);
4707 if (image->debug != MagickFalse)
4708 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4709 assert(watermark != (const Image *) NULL);
4710 assert(watermark->signature == MagickSignature);
4711 assert(exception != (ExceptionInfo *) NULL);
4712 assert(exception->signature == MagickSignature);
4714 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4715 if (stegano_image == (Image *) NULL)
4716 return((Image *) NULL);
4717 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4718 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4720 stegano_image=DestroyImage(stegano_image);
4721 return((Image *) NULL);
4724 Hide watermark in low-order bits of image.
4729 depth=stegano_image->depth;
4730 k=stegano_image->offset;
4732 watermark_view=AcquireCacheView(watermark);
4733 stegano_view=AcquireCacheView(stegano_image);
4734 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4736 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4738 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4743 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
4745 offset=k/(ssize_t) stegano_image->columns;
4746 if (offset >= (ssize_t) stegano_image->rows)
4748 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4749 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4751 if (q == (Quantum *) NULL)
4757 SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
4758 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
4763 SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
4764 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
4769 SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
4770 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
4774 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4780 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4782 if (k == stegano_image->offset)
4786 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4791 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4793 if (proceed == MagickFalse)
4797 stegano_view=DestroyCacheView(stegano_view);
4798 watermark_view=DestroyCacheView(watermark_view);
4799 if (status == MagickFalse)
4801 stegano_image=DestroyImage(stegano_image);
4802 return((Image *) NULL);
4804 return(stegano_image);
4808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4812 % S t e r e o A n a g l y p h I m a g e %
4816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4818 % StereoAnaglyphImage() combines two images and produces a single image that
4819 % is the composite of a left and right image of a stereo pair. Special
4820 % red-green stereo glasses are required to view this effect.
4822 % The format of the StereoAnaglyphImage method is:
4824 % Image *StereoImage(const Image *left_image,const Image *right_image,
4825 % ExceptionInfo *exception)
4826 % Image *StereoAnaglyphImage(const Image *left_image,
4827 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4828 % ExceptionInfo *exception)
4830 % A description of each parameter follows:
4832 % o left_image: the left image.
4834 % o right_image: the right image.
4836 % o exception: return any errors or warnings in this structure.
4838 % o x_offset: amount, in pixels, by which the left image is offset to the
4839 % right of the right image.
4841 % o y_offset: amount, in pixels, by which the left image is offset to the
4842 % bottom of the right image.
4846 MagickExport Image *StereoImage(const Image *left_image,
4847 const Image *right_image,ExceptionInfo *exception)
4849 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4852 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4853 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4854 ExceptionInfo *exception)
4856 #define StereoImageTag "Stereo/Image"
4870 assert(left_image != (const Image *) NULL);
4871 assert(left_image->signature == MagickSignature);
4872 if (left_image->debug != MagickFalse)
4873 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4874 left_image->filename);
4875 assert(right_image != (const Image *) NULL);
4876 assert(right_image->signature == MagickSignature);
4877 assert(exception != (ExceptionInfo *) NULL);
4878 assert(exception->signature == MagickSignature);
4879 assert(right_image != (const Image *) NULL);
4881 if ((left_image->columns != right_image->columns) ||
4882 (left_image->rows != right_image->rows))
4883 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4885 Initialize stereo image attributes.
4887 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4888 MagickTrue,exception);
4889 if (stereo_image == (Image *) NULL)
4890 return((Image *) NULL);
4891 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4893 stereo_image=DestroyImage(stereo_image);
4894 return((Image *) NULL);
4897 Copy left image to red channel and right image to blue channel.
4900 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4902 register const Quantum
4912 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4914 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4915 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4916 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4917 (r == (Quantum *) NULL))
4919 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4921 SetPixelRed(image,GetPixelRed(left_image,p),r);
4922 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4923 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4924 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4925 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4926 GetPixelAlpha(right_image,q))/2,r);
4927 p+=GetPixelChannels(left_image);
4928 q+=GetPixelChannels(right_image);
4929 r+=GetPixelChannels(stereo_image);
4931 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4933 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4938 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4939 stereo_image->rows);
4940 if (proceed == MagickFalse)
4944 if (status == MagickFalse)
4946 stereo_image=DestroyImage(stereo_image);
4947 return((Image *) NULL);
4949 return(stereo_image);
4953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4957 % S w i r l I m a g e %
4961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4963 % SwirlImage() swirls the pixels about the center of the image, where
4964 % degrees indicates the sweep of the arc through which each pixel is moved.
4965 % You get a more dramatic effect as the degrees move from 1 to 360.
4967 % The format of the SwirlImage method is:
4969 % Image *SwirlImage(const Image *image,double degrees,
4970 % const PixelInterpolateMethod method,ExceptionInfo *exception)
4972 % A description of each parameter follows:
4974 % o image: the image.
4976 % o degrees: Define the tightness of the swirling effect.
4978 % o method: the pixel interpolation method.
4980 % o exception: return any errors or warnings in this structure.
4983 MagickExport Image *SwirlImage(const Image *image,double degrees,
4984 const PixelInterpolateMethod method,ExceptionInfo *exception)
4986 #define SwirlImageTag "Swirl/Image"
5012 Initialize swirl image attributes.
5014 assert(image != (const Image *) NULL);
5015 assert(image->signature == MagickSignature);
5016 if (image->debug != MagickFalse)
5017 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5018 assert(exception != (ExceptionInfo *) NULL);
5019 assert(exception->signature == MagickSignature);
5020 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5021 if (swirl_image == (Image *) NULL)
5022 return((Image *) NULL);
5023 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
5025 swirl_image=DestroyImage(swirl_image);
5026 return((Image *) NULL);
5028 if (swirl_image->background_color.alpha != OpaqueAlpha)
5029 swirl_image->matte=MagickTrue;
5031 Compute scaling factor.
5033 center.x=(double) image->columns/2.0;
5034 center.y=(double) image->rows/2.0;
5035 radius=MagickMax(center.x,center.y);
5038 if (image->columns > image->rows)
5039 scale.y=(double) image->columns/(double) image->rows;
5041 if (image->columns < image->rows)
5042 scale.x=(double) image->rows/(double) image->columns;
5043 degrees=(double) DegreesToRadians(degrees);
5049 image_view=AcquireCacheView(image);
5050 swirl_view=AcquireCacheView(swirl_image);
5051 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5052 #pragma omp parallel for schedule(static,4) shared(progress,status)
5054 for (y=0; y < (ssize_t) image->rows; y++)
5062 register const Quantum
5071 if (status == MagickFalse)
5073 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
5074 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5076 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5081 delta.y=scale.y*(double) (y-center.y);
5082 for (x=0; x < (ssize_t) image->columns; x++)
5085 Determine if the pixel is within an ellipse.
5087 if (GetPixelMask(image,p) != 0)
5089 p+=GetPixelChannels(image);
5090 q+=GetPixelChannels(swirl_image);
5093 delta.x=scale.x*(double) (x-center.x);
5094 distance=delta.x*delta.x+delta.y*delta.y;
5095 if (distance >= (radius*radius))
5100 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5109 channel=GetPixelChannelMapChannel(image,i);
5110 traits=GetPixelChannelMapTraits(image,channel);
5111 swirl_traits=GetPixelChannelMapTraits(swirl_image,channel);
5112 if ((traits == UndefinedPixelTrait) ||
5113 (swirl_traits == UndefinedPixelTrait))
5115 SetPixelChannel(swirl_image,channel,p[i],q);
5128 factor=1.0-sqrt((double) distance)/radius;
5129 sine=sin((double) (degrees*factor*factor));
5130 cosine=cos((double) (degrees*factor*factor));
5131 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5132 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5133 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
5135 p+=GetPixelChannels(image);
5136 q+=GetPixelChannels(swirl_image);
5138 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5140 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5145 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5146 #pragma omp critical (MagickCore_SwirlImage)
5148 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5149 if (proceed == MagickFalse)
5153 swirl_view=DestroyCacheView(swirl_view);
5154 image_view=DestroyCacheView(image_view);
5155 if (status == MagickFalse)
5156 swirl_image=DestroyImage(swirl_image);
5157 return(swirl_image);
5161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5165 % T i n t I m a g e %
5169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5171 % TintImage() applies a color vector to each pixel in the image. The length
5172 % of the vector is 0 for black and white and at its maximum for the midtones.
5173 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5175 % The format of the TintImage method is:
5177 % Image *TintImage(const Image *image,const char *blend,
5178 % const PixelInfo *tint,ExceptionInfo *exception)
5180 % A description of each parameter follows:
5182 % o image: the image.
5184 % o blend: A color value used for tinting.
5186 % o tint: A color value used for tinting.
5188 % o exception: return any errors or warnings in this structure.
5191 MagickExport Image *TintImage(const Image *image,const char *blend,
5192 const PixelInfo *tint,ExceptionInfo *exception)
5194 #define TintImageTag "Tint/Image"
5225 Allocate tint image.
5227 assert(image != (const Image *) NULL);
5228 assert(image->signature == MagickSignature);
5229 if (image->debug != MagickFalse)
5230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5231 assert(exception != (ExceptionInfo *) NULL);
5232 assert(exception->signature == MagickSignature);
5233 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5234 if (tint_image == (Image *) NULL)
5235 return((Image *) NULL);
5236 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5238 tint_image=DestroyImage(tint_image);
5239 return((Image *) NULL);
5241 if (blend == (const char *) NULL)
5244 Determine RGB values of the color.
5246 GetPixelInfo(image,&color_vector);
5247 flags=ParseGeometry(blend,&geometry_info);
5248 color_vector.red=geometry_info.rho;
5249 color_vector.green=geometry_info.rho;
5250 color_vector.blue=geometry_info.rho;
5251 color_vector.alpha=OpaqueAlpha;
5252 if ((flags & SigmaValue) != 0)
5253 color_vector.green=geometry_info.sigma;
5254 if ((flags & XiValue) != 0)
5255 color_vector.blue=geometry_info.xi;
5256 if ((flags & PsiValue) != 0)
5257 color_vector.alpha=geometry_info.psi;
5258 if (image->colorspace == CMYKColorspace)
5260 color_vector.black=geometry_info.rho;
5261 if ((flags & PsiValue) != 0)
5262 color_vector.black=geometry_info.psi;
5263 if ((flags & ChiValue) != 0)
5264 color_vector.alpha=geometry_info.chi;
5266 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5267 color_vector.red=(MagickRealType) (color_vector.red*tint->red/100.0-
5269 color_vector.green=(MagickRealType) (color_vector.green*tint->green/100.0-
5271 color_vector.blue=(MagickRealType) (color_vector.blue*tint->blue/100.0-
5273 color_vector.black=(MagickRealType) (color_vector.black*tint->black/100.0-
5275 color_vector.alpha=(MagickRealType) (color_vector.alpha*tint->alpha/100.0-
5282 image_view=AcquireCacheView(image);
5283 tint_view=AcquireCacheView(tint_image);
5284 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5285 #pragma omp parallel for schedule(static,4) shared(progress,status)
5287 for (y=0; y < (ssize_t) image->rows; y++)
5289 register const Quantum
5298 if (status == MagickFalse)
5300 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5301 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5303 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5308 for (x=0; x < (ssize_t) image->columns; x++)
5319 if (GetPixelMask(image,p) != 0)
5321 p+=GetPixelChannels(image);
5322 q+=GetPixelChannels(tint_image);
5325 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5334 channel=GetPixelChannelMapChannel(image,i);
5335 traits=GetPixelChannelMapTraits(image,channel);
5336 tint_traits=GetPixelChannelMapTraits(tint_image,channel);
5337 if ((traits == UndefinedPixelTrait) ||
5338 (tint_traits == UndefinedPixelTrait))
5340 if ((tint_traits & CopyPixelTrait) != 0)
5342 SetPixelChannel(tint_image,channel,p[i],q);
5346 GetPixelInfo(image,&pixel);
5347 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5348 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5349 (1.0-(4.0*(weight*weight)));
5350 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5351 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5352 (1.0-(4.0*(weight*weight)));
5353 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5354 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5355 (1.0-(4.0*(weight*weight)));
5356 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5357 pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black*
5358 (1.0-(4.0*(weight*weight)));
5359 SetPixelInfoPixel(tint_image,&pixel,q);
5360 p+=GetPixelChannels(image);
5361 q+=GetPixelChannels(tint_image);
5363 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5365 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5370 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5371 #pragma omp critical (MagickCore_TintImage)
5373 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5374 if (proceed == MagickFalse)
5378 tint_view=DestroyCacheView(tint_view);
5379 image_view=DestroyCacheView(image_view);
5380 if (status == MagickFalse)
5381 tint_image=DestroyImage(tint_image);
5386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5390 % V i g n e t t e I m a g e %
5394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5396 % VignetteImage() softens the edges of the image in vignette style.
5398 % The format of the VignetteImage method is:
5400 % Image *VignetteImage(const Image *image,const double radius,
5401 % const double sigma,const ssize_t x,const ssize_t y,
5402 % ExceptionInfo *exception)
5404 % A description of each parameter follows:
5406 % o image: the image.
5408 % o radius: the radius of the pixel neighborhood.
5410 % o sigma: the standard deviation of the Gaussian, in pixels.
5412 % o x, y: Define the x and y ellipse offset.
5414 % o exception: return any errors or warnings in this structure.
5417 MagickExport Image *VignetteImage(const Image *image,const double radius,
5418 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5421 ellipse[MaxTextExtent];
5432 assert(image != (Image *) NULL);
5433 assert(image->signature == MagickSignature);
5434 if (image->debug != MagickFalse)
5435 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5436 assert(exception != (ExceptionInfo *) NULL);
5437 assert(exception->signature == MagickSignature);
5438 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5439 if (canvas_image == (Image *) NULL)
5440 return((Image *) NULL);
5441 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5443 canvas_image=DestroyImage(canvas_image);
5444 return((Image *) NULL);
5446 canvas_image->matte=MagickTrue;
5447 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5448 MagickTrue,exception);
5449 if (oval_image == (Image *) NULL)
5451 canvas_image=DestroyImage(canvas_image);
5452 return((Image *) NULL);
5454 (void) QueryColorCompliance("#000000",AllCompliance,
5455 &oval_image->background_color,exception);
5456 (void) SetImageBackgroundColor(oval_image,exception);
5457 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5458 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5460 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5462 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5463 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5465 draw_info->primitive=AcquireString(ellipse);
5466 (void) DrawImage(oval_image,draw_info,exception);
5467 draw_info=DestroyDrawInfo(draw_info);
5468 blur_image=BlurImage(oval_image,radius,sigma,exception);
5469 oval_image=DestroyImage(oval_image);
5470 if (blur_image == (Image *) NULL)
5472 canvas_image=DestroyImage(canvas_image);
5473 return((Image *) NULL);
5475 blur_image->matte=MagickFalse;
5476 (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue,
5478 blur_image=DestroyImage(blur_image);
5479 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5480 canvas_image=DestroyImage(canvas_image);
5481 return(vignette_image);
5485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5489 % W a v e I m a g e %
5493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5495 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5496 % vertically along a sine wave whose amplitude and wavelength is specified
5497 % by the given parameters.
5499 % The format of the WaveImage method is:
5501 % Image *WaveImage(const Image *image,const double amplitude,
5502 % const double wave_length,const PixelInterpolateMethod method,
5503 % ExceptionInfo *exception)
5505 % A description of each parameter follows:
5507 % o image: the image.
5509 % o amplitude, wave_length: Define the amplitude and wave length of the
5512 % o interpolate: the pixel interpolation method.
5514 % o exception: return any errors or warnings in this structure.
5517 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5518 const double wave_length,const PixelInterpolateMethod method,
5519 ExceptionInfo *exception)
5521 #define WaveImageTag "Wave/Image"
5546 Initialize wave image attributes.
5548 assert(image != (Image *) NULL);
5549 assert(image->signature == MagickSignature);
5550 if (image->debug != MagickFalse)
5551 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5552 assert(exception != (ExceptionInfo *) NULL);
5553 assert(exception->signature == MagickSignature);
5554 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5555 fabs(amplitude)),MagickTrue,exception);
5556 if (wave_image == (Image *) NULL)
5557 return((Image *) NULL);
5558 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5560 wave_image=DestroyImage(wave_image);
5561 return((Image *) NULL);
5563 if (wave_image->background_color.alpha != OpaqueAlpha)
5564 wave_image->matte=MagickTrue;
5568 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5570 if (sine_map == (MagickRealType *) NULL)
5572 wave_image=DestroyImage(wave_image);
5573 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5575 for (i=0; i < (ssize_t) wave_image->columns; i++)
5576 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5583 image_view=AcquireCacheView(image);
5584 wave_view=AcquireCacheView(wave_image);
5585 (void) SetCacheViewVirtualPixelMethod(image_view,
5586 BackgroundVirtualPixelMethod);
5587 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5588 #pragma omp parallel for schedule(static,4) shared(progress,status)
5590 for (y=0; y < (ssize_t) wave_image->rows; y++)
5598 if (status == MagickFalse)
5600 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5602 if (q == (Quantum *) NULL)
5607 for (x=0; x < (ssize_t) wave_image->columns; x++)
5609 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5610 (double) x,(double) (y-sine_map[x]),q,exception);
5611 q+=GetPixelChannels(wave_image);
5613 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5615 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5620 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5621 #pragma omp critical (MagickCore_WaveImage)
5623 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5624 if (proceed == MagickFalse)
5628 wave_view=DestroyCacheView(wave_view);
5629 image_view=DestroyCacheView(image_view);
5630 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5631 if (status == MagickFalse)
5632 wave_image=DestroyImage(wave_image);