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"
275 **restrict random_info;
281 Initialize noise image attributes.
283 assert(image != (const Image *) NULL);
284 assert(image->signature == MagickSignature);
285 if (image->debug != MagickFalse)
286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
287 assert(exception != (ExceptionInfo *) NULL);
288 assert(exception->signature == MagickSignature);
289 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
290 if (noise_image == (Image *) NULL)
291 return((Image *) NULL);
292 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
294 noise_image=DestroyImage(noise_image);
295 return((Image *) NULL);
298 Add noise in each row.
302 random_info=AcquireRandomInfoThreadSet();
303 concurrent=GetRandomSecretKey(random_info[0]) == ~0UL ? MagickTrue :
305 image_view=AcquireCacheView(image);
306 noise_view=AcquireCacheView(noise_image);
307 #if defined(MAGICKCORE_OPENMP_SUPPORT)
308 #pragma omp parallel for schedule(static,4) shared(progress,status) omp_concurrent(concurrent)
310 for (y=0; y < (ssize_t) image->rows; y++)
313 id = GetOpenMPThreadId();
318 register const Quantum
327 if (status == MagickFalse)
329 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
330 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
332 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
337 for (x=0; x < (ssize_t) image->columns; x++)
342 if (GetPixelMask(image,p) != 0)
344 p+=GetPixelChannels(image);
345 q+=GetPixelChannels(noise_image);
348 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
357 channel=GetPixelChannelMapChannel(image,i);
358 traits=GetPixelChannelMapTraits(image,channel);
359 noise_traits=GetPixelChannelMapTraits(noise_image,channel);
360 if ((traits == UndefinedPixelTrait) ||
361 (noise_traits == UndefinedPixelTrait))
363 if ((noise_traits & CopyPixelTrait) != 0)
365 SetPixelChannel(noise_image,channel,p[i],q);
368 SetPixelChannel(noise_image,channel,ClampToQuantum(
369 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
372 p+=GetPixelChannels(image);
373 q+=GetPixelChannels(noise_image);
375 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
376 if (sync == MagickFalse)
378 if (image->progress_monitor != (MagickProgressMonitor) NULL)
383 #if defined(MAGICKCORE_OPENMP_SUPPORT)
384 #pragma omp critical (MagickCore_AddNoiseImage)
386 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
388 if (proceed == MagickFalse)
392 noise_view=DestroyCacheView(noise_view);
393 image_view=DestroyCacheView(image_view);
394 random_info=DestroyRandomInfoThreadSet(random_info);
395 if (status == MagickFalse)
396 noise_image=DestroyImage(noise_image);
401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405 % B l u e S h i f t I m a g e %
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 % BlueShiftImage() mutes the colors of the image to simulate a scene at
412 % nighttime in the moonlight.
414 % The format of the BlueShiftImage method is:
416 % Image *BlueShiftImage(const Image *image,const double factor,
417 % ExceptionInfo *exception)
419 % A description of each parameter follows:
421 % o image: the image.
423 % o factor: the shift factor.
425 % o exception: return any errors or warnings in this structure.
428 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
429 ExceptionInfo *exception)
431 #define BlueShiftImageTag "BlueShift/Image"
450 Allocate blue shift image.
452 assert(image != (const Image *) NULL);
453 assert(image->signature == MagickSignature);
454 if (image->debug != MagickFalse)
455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
456 assert(exception != (ExceptionInfo *) NULL);
457 assert(exception->signature == MagickSignature);
458 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
459 if (shift_image == (Image *) NULL)
460 return((Image *) NULL);
461 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
463 shift_image=DestroyImage(shift_image);
464 return((Image *) NULL);
467 Blue-shift DirectClass image.
471 image_view=AcquireCacheView(image);
472 shift_view=AcquireCacheView(shift_image);
473 #if defined(MAGICKCORE_OPENMP_SUPPORT)
474 #pragma omp parallel for schedule(static,4) shared(progress,status)
476 for (y=0; y < (ssize_t) image->rows; y++)
487 register const Quantum
496 if (status == MagickFalse)
498 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
499 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
501 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
506 for (x=0; x < (ssize_t) image->columns; x++)
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*(GetPixelRed(image,p)+factor*quantum);
514 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
515 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
516 quantum=GetPixelRed(image,p);
517 if (GetPixelGreen(image,p) > quantum)
518 quantum=GetPixelGreen(image,p);
519 if (GetPixelBlue(image,p) > quantum)
520 quantum=GetPixelBlue(image,p);
521 pixel.red=0.5*(pixel.red+factor*quantum);
522 pixel.green=0.5*(pixel.green+factor*quantum);
523 pixel.blue=0.5*(pixel.blue+factor*quantum);
524 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
525 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
526 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
527 p+=GetPixelChannels(image);
528 q+=GetPixelChannels(shift_image);
530 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
531 if (sync == MagickFalse)
533 if (image->progress_monitor != (MagickProgressMonitor) NULL)
538 #if defined(MAGICKCORE_OPENMP_SUPPORT)
539 #pragma omp critical (MagickCore_BlueShiftImage)
541 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
543 if (proceed == MagickFalse)
547 image_view=DestroyCacheView(image_view);
548 shift_view=DestroyCacheView(shift_view);
549 if (status == MagickFalse)
550 shift_image=DestroyImage(shift_image);
555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
559 % C h a r c o a l I m a g e %
563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565 % CharcoalImage() creates a new image that is a copy of an existing one with
566 % the edge highlighted. It allocates the memory necessary for the new Image
567 % structure and returns a pointer to the new image.
569 % The format of the CharcoalImage method is:
571 % Image *CharcoalImage(const Image *image,const double radius,
572 % const double sigma,ExceptionInfo *exception)
574 % A description of each parameter follows:
576 % o image: the image.
578 % o radius: the radius of the pixel neighborhood.
580 % o sigma: the standard deviation of the Gaussian, in pixels.
582 % o exception: return any errors or warnings in this structure.
585 MagickExport Image *CharcoalImage(const Image *image,const double radius,
586 const double sigma,ExceptionInfo *exception)
593 assert(image != (Image *) NULL);
594 assert(image->signature == MagickSignature);
595 if (image->debug != MagickFalse)
596 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
597 assert(exception != (ExceptionInfo *) NULL);
598 assert(exception->signature == MagickSignature);
599 clone_image=CloneImage(image,0,0,MagickTrue,exception);
600 if (clone_image == (Image *) NULL)
601 return((Image *) NULL);
602 (void) SetImageType(clone_image,GrayscaleType,exception);
603 edge_image=EdgeImage(clone_image,radius,sigma,exception);
604 clone_image=DestroyImage(clone_image);
605 if (edge_image == (Image *) NULL)
606 return((Image *) NULL);
607 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
608 edge_image=DestroyImage(edge_image);
609 if (charcoal_image == (Image *) NULL)
610 return((Image *) NULL);
611 (void) NormalizeImage(charcoal_image,exception);
612 (void) NegateImage(charcoal_image,MagickFalse,exception);
613 (void) SetImageType(charcoal_image,GrayscaleType,exception);
614 return(charcoal_image);
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % C o l o r i z e I m a g e %
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % ColorizeImage() blends the fill color with each pixel in the image.
629 % A percentage blend is specified with opacity. Control the application
630 % of different color components by specifying a different percentage for
631 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
633 % The format of the ColorizeImage method is:
635 % Image *ColorizeImage(const Image *image,const char *blend,
636 % const PixelInfo *colorize,ExceptionInfo *exception)
638 % A description of each parameter follows:
640 % o image: the image.
642 % o blend: A character string indicating the level of blending as a
645 % o colorize: A color value.
647 % o exception: return any errors or warnings in this structure.
650 MagickExport Image *ColorizeImage(const Image *image,const char *blend,
651 const PixelInfo *colorize,ExceptionInfo *exception)
653 #define ColorizeImageTag "Colorize/Image"
654 #define Colorize(pixel,blend_percentage,colorize) \
655 (pixel)=((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0;
683 Allocate colorized image.
685 assert(image != (const Image *) NULL);
686 assert(image->signature == MagickSignature);
687 if (image->debug != MagickFalse)
688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
689 assert(exception != (ExceptionInfo *) NULL);
690 assert(exception->signature == MagickSignature);
691 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
693 if (colorize_image == (Image *) NULL)
694 return((Image *) NULL);
695 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
697 colorize_image=DestroyImage(colorize_image);
698 return((Image *) NULL);
700 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
701 (IsPixelInfoGray(colorize) != MagickFalse))
702 (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
703 if ((colorize_image->matte == MagickFalse) &&
704 (colorize->matte != MagickFalse))
705 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
706 if (blend == (const char *) NULL)
707 return(colorize_image);
708 GetPixelInfo(image,&blend_percentage);
709 flags=ParseGeometry(blend,&geometry_info);
710 blend_percentage.red=geometry_info.rho;
711 blend_percentage.green=geometry_info.rho;
712 blend_percentage.blue=geometry_info.rho;
713 blend_percentage.black=geometry_info.rho;
714 blend_percentage.alpha=geometry_info.rho;
715 if ((flags & SigmaValue) != 0)
716 blend_percentage.green=geometry_info.sigma;
717 if ((flags & XiValue) != 0)
718 blend_percentage.blue=geometry_info.xi;
719 if ((flags & PsiValue) != 0)
720 blend_percentage.alpha=geometry_info.psi;
721 if (blend_percentage.colorspace == CMYKColorspace)
723 if ((flags & PsiValue) != 0)
724 blend_percentage.black=geometry_info.psi;
725 if ((flags & ChiValue) != 0)
726 blend_percentage.alpha=geometry_info.chi;
729 Colorize DirectClass image.
733 image_view=AcquireCacheView(image);
734 colorize_view=AcquireCacheView(colorize_image);
735 #if defined(MAGICKCORE_OPENMP_SUPPORT)
736 #pragma omp parallel for schedule(static,4) shared(progress,status)
738 for (y=0; y < (ssize_t) image->rows; y++)
746 register const Quantum
755 if (status == MagickFalse)
757 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
758 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
760 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
765 GetPixelInfo(colorize_image,&pixel);
766 for (x=0; x < (ssize_t) image->columns; x++)
768 if (GetPixelMask(colorize_image,q) != 0)
770 p+=GetPixelChannels(image);
771 q+=GetPixelChannels(colorize_image);
774 GetPixelInfoPixel(image,p,&pixel);
775 Colorize(pixel.red,blend_percentage.red,colorize->red);
776 Colorize(pixel.green,blend_percentage.green,colorize->green);
777 Colorize(pixel.blue,blend_percentage.blue,colorize->blue);
778 Colorize(pixel.black,blend_percentage.black,colorize->black);
779 Colorize(pixel.alpha,blend_percentage.alpha,colorize->alpha);
780 SetPixelInfoPixel(colorize_image,&pixel,q);
781 p+=GetPixelChannels(image);
782 q+=GetPixelChannels(colorize_image);
784 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
785 if (sync == MagickFalse)
787 if (image->progress_monitor != (MagickProgressMonitor) NULL)
792 #if defined(MAGICKCORE_OPENMP_SUPPORT)
793 #pragma omp critical (MagickCore_ColorizeImage)
795 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
796 if (proceed == MagickFalse)
800 image_view=DestroyCacheView(image_view);
801 colorize_view=DestroyCacheView(colorize_view);
802 if (status == MagickFalse)
803 colorize_image=DestroyImage(colorize_image);
804 return(colorize_image);
808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 % C o l o r M a t r i x I m a g e %
816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
818 % ColorMatrixImage() applies color transformation to an image. This method
819 % permits saturation changes, hue rotation, luminance to alpha, and various
820 % other effects. Although variable-sized transformation matrices can be used,
821 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
822 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
823 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
824 % and offsets are normalized (divide Flash offset by 255).
826 % The format of the ColorMatrixImage method is:
828 % Image *ColorMatrixImage(const Image *image,
829 % const KernelInfo *color_matrix,ExceptionInfo *exception)
831 % A description of each parameter follows:
833 % o image: the image.
835 % o color_matrix: the color matrix.
837 % o exception: return any errors or warnings in this structure.
840 /* FUTURE: modify to make use of a MagickMatrix Mutliply function
841 That should be provided in "matrix.c"
842 (ASIDE: actually distorts should do this too but currently doesn't)
845 MagickExport Image *ColorMatrixImage(const Image *image,
846 const KernelInfo *color_matrix,ExceptionInfo *exception)
848 #define ColorMatrixImageTag "ColorMatrix/Image"
857 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
858 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
859 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
860 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
861 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
862 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
883 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
885 assert(image != (Image *) NULL);
886 assert(image->signature == MagickSignature);
887 if (image->debug != MagickFalse)
888 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
889 assert(exception != (ExceptionInfo *) NULL);
890 assert(exception->signature == MagickSignature);
892 for (v=0; v < (ssize_t) color_matrix->height; v++)
893 for (u=0; u < (ssize_t) color_matrix->width; u++)
895 if ((v < 6) && (u < 6))
896 ColorMatrix[v][u]=color_matrix->values[i];
900 Initialize color image.
902 color_image=CloneImage(image,0,0,MagickTrue,exception);
903 if (color_image == (Image *) NULL)
904 return((Image *) NULL);
905 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
907 color_image=DestroyImage(color_image);
908 return((Image *) NULL);
910 if (image->debug != MagickFalse)
913 format[MaxTextExtent],
916 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
917 " ColorMatrix image with color matrix:");
918 message=AcquireString("");
919 for (v=0; v < 6; v++)
922 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
923 (void) ConcatenateString(&message,format);
924 for (u=0; u < 6; u++)
926 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
928 (void) ConcatenateString(&message,format);
930 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
932 message=DestroyString(message);
935 Apply the ColorMatrix to image.
939 image_view=AcquireCacheView(image);
940 color_view=AcquireCacheView(color_image);
941 #if defined(MAGICKCORE_OPENMP_SUPPORT)
942 #pragma omp parallel for schedule(static,4) shared(progress,status)
944 for (y=0; y < (ssize_t) image->rows; y++)
949 register const Quantum
958 if (status == MagickFalse)
960 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
961 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
963 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
968 GetPixelInfo(image,&pixel);
969 for (x=0; x < (ssize_t) image->columns; x++)
977 GetPixelInfoPixel(image,p,&pixel);
978 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
979 for (v=0; v < (ssize_t) height; v++)
984 sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
985 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
986 if (image->colorspace == CMYKColorspace)
987 sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
988 if (image->matte != MagickFalse)
989 sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
990 sum+=QuantumRange*ColorMatrix[v][5];
993 case 0: pixel.red=sum; break;
994 case 1: pixel.green=sum; break;
995 case 2: pixel.blue=sum; break;
996 case 3: pixel.black=sum; break;
997 case 4: pixel.alpha=sum; break;
1001 SetPixelInfoPixel(color_image,&pixel,q);
1002 p+=GetPixelChannels(image);
1003 q+=GetPixelChannels(color_image);
1005 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1007 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1012 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1013 #pragma omp critical (MagickCore_ColorMatrixImage)
1015 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1017 if (proceed == MagickFalse)
1021 color_view=DestroyCacheView(color_view);
1022 image_view=DestroyCacheView(image_view);
1023 if (status == MagickFalse)
1024 color_image=DestroyImage(color_image);
1025 return(color_image);
1029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1033 + D e s t r o y F x I n f o %
1037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1041 % The format of the DestroyFxInfo method is:
1043 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1045 % A description of each parameter follows:
1047 % o fx_info: the fx info.
1050 MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
1055 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1056 fx_info->expression=DestroyString(fx_info->expression);
1057 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1058 fx_info->colors=DestroySplayTree(fx_info->colors);
1059 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1060 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1061 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1062 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1063 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1072 + 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 %
1076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1078 % FxEvaluateChannelExpression() evaluates an expression and returns the
1081 % The format of the FxEvaluateExpression method is:
1083 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1084 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1085 % MagickRealType *alpha,Exceptioninfo *exception)
1086 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1087 % MagickRealType *alpha,Exceptioninfo *exception)
1089 % A description of each parameter follows:
1091 % o fx_info: the fx info.
1093 % o channel: the channel.
1095 % o x,y: the pixel position.
1097 % o alpha: the result.
1099 % o exception: return any errors or warnings in this structure.
1103 static inline double MagickMax(const double x,const double y)
1110 static inline double MagickMin(const double x,const double y)
1117 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1118 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1122 statistic[MaxTextExtent];
1130 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1132 switch (*++p) /* e.g. depth.r */
1134 case 'r': channel=RedPixelChannel; break;
1135 case 'g': channel=GreenPixelChannel; break;
1136 case 'b': channel=BluePixelChannel; break;
1137 case 'c': channel=CyanPixelChannel; break;
1138 case 'm': channel=MagentaPixelChannel; break;
1139 case 'y': channel=YellowPixelChannel; break;
1140 case 'k': channel=BlackPixelChannel; break;
1143 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1144 (double) channel,symbol);
1145 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1146 if (value != (const char *) NULL)
1147 return(QuantumScale*StringToDouble(value,(char **) NULL));
1148 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1149 if (LocaleNCompare(symbol,"depth",5) == 0)
1154 depth=GetImageDepth(image,exception);
1155 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1157 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1163 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1164 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1166 if (LocaleNCompare(symbol,"maxima",6) == 0)
1172 (void) GetImageRange(image,&minima,&maxima,exception);
1173 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1175 if (LocaleNCompare(symbol,"mean",4) == 0)
1181 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1182 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1184 if (LocaleNCompare(symbol,"minima",6) == 0)
1190 (void) GetImageRange(image,&minima,&maxima,exception);
1191 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1193 if (LocaleNCompare(symbol,"skewness",8) == 0)
1199 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1200 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1202 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1208 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1209 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1210 standard_deviation);
1212 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1213 ConstantString(statistic));
1214 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
1217 static MagickRealType
1218 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1219 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1221 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1224 return(FxGCD(beta,alpha % beta));
1228 static inline const char *FxSubexpression(const char *expression,
1229 ExceptionInfo *exception)
1238 subexpression=expression;
1239 while ((*subexpression != '\0') &&
1240 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1242 if (strchr("(",(int) *subexpression) != (char *) NULL)
1245 if (strchr(")",(int) *subexpression) != (char *) NULL)
1249 if (*subexpression == '\0')
1250 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1251 "UnbalancedParenthesis","`%s'",expression);
1252 return(subexpression);
1255 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1256 const ssize_t x,const ssize_t y,const char *expression,
1257 ExceptionInfo *exception)
1261 subexpression[MaxTextExtent],
1262 symbol[MaxTextExtent];
1289 i=GetImageIndexInList(fx_info->images);
1293 if (isalpha((int) *(p+1)) == 0)
1295 if (strchr("suv",(int) *p) != (char *) NULL)
1302 i=GetImageIndexInList(fx_info->images);
1305 case 'u': i=0; break;
1306 case 'v': i=1; break;
1313 for (p++; *p != '\0'; )
1327 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1329 i=(ssize_t) (alpha+0.5);
1335 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1342 for (p++; *p != '\0'; )
1356 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1367 for (p++; *p != '\0'; )
1381 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1391 length=GetImageListLength(fx_info->images);
1393 i+=(ssize_t) length;
1395 image=GetImageFromList(fx_info->images,i);
1396 if (image == (Image *) NULL)
1398 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1399 "NoSuchImage","`%s'",expression);
1402 GetPixelInfo(image,&pixel);
1403 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1404 point.x,point.y,&pixel,exception);
1405 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1406 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
1407 (LocaleCompare(p,"saturation") != 0) &&
1408 (LocaleCompare(p,"lightness") != 0))
1411 name[MaxTextExtent];
1413 (void) CopyMagickString(name,p,MaxTextExtent);
1414 for (q=name+(strlen(name)-1); q > name; q--)
1424 if ((strlen(name) > 2) &&
1425 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1430 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1431 if (color != (PixelInfo *) NULL)
1441 status=QueryColorCompliance(name,AllCompliance,&pixel,
1442 fx_info->exception);
1443 if (status != MagickFalse)
1445 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1446 name),ClonePixelInfo(&pixel));
1452 (void) CopyMagickString(symbol,p,MaxTextExtent);
1453 StripString(symbol);
1454 if (*symbol == '\0')
1458 case RedPixelChannel: return(QuantumScale*pixel.red);
1459 case GreenPixelChannel: return(QuantumScale*pixel.green);
1460 case BluePixelChannel: return(QuantumScale*pixel.blue);
1461 case BlackPixelChannel:
1463 if (image->colorspace != CMYKColorspace)
1465 (void) ThrowMagickException(exception,GetMagickModule(),
1466 ImageError,"ColorSeparatedImageRequired","`%s'",
1470 return(QuantumScale*pixel.black);
1472 case AlphaPixelChannel:
1477 if (pixel.matte == MagickFalse)
1479 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1482 case IndexPixelChannel:
1484 case IntensityPixelChannel:
1486 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1491 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1492 "UnableToParseExpression","`%s'",p);
1500 if (LocaleCompare(symbol,"a") == 0)
1501 return((MagickRealType) (QuantumScale*pixel.alpha));
1507 if (LocaleCompare(symbol,"b") == 0)
1508 return(QuantumScale*pixel.blue);
1514 if (LocaleNCompare(symbol,"channel",7) == 0)
1522 flags=ParseGeometry(symbol+7,&channel_info);
1523 if (image->colorspace == CMYKColorspace)
1526 case CyanPixelChannel:
1528 if ((flags & RhoValue) == 0)
1530 return(channel_info.rho);
1532 case MagentaPixelChannel:
1534 if ((flags & SigmaValue) == 0)
1536 return(channel_info.sigma);
1538 case YellowPixelChannel:
1540 if ((flags & XiValue) == 0)
1542 return(channel_info.xi);
1544 case BlackPixelChannel:
1546 if ((flags & PsiValue) == 0)
1548 return(channel_info.psi);
1550 case AlphaPixelChannel:
1552 if ((flags & ChiValue) == 0)
1554 return(channel_info.chi);
1561 case RedPixelChannel:
1563 if ((flags & RhoValue) == 0)
1565 return(channel_info.rho);
1567 case GreenPixelChannel:
1569 if ((flags & SigmaValue) == 0)
1571 return(channel_info.sigma);
1573 case BluePixelChannel:
1575 if ((flags & XiValue) == 0)
1577 return(channel_info.xi);
1579 case BlackPixelChannel:
1581 if ((flags & ChiValue) == 0)
1583 return(channel_info.chi);
1585 case AlphaPixelChannel:
1587 if ((flags & PsiValue) == 0)
1589 return(channel_info.psi);
1596 if (LocaleCompare(symbol,"c") == 0)
1597 return(QuantumScale*pixel.red);
1603 if (LocaleNCompare(symbol,"depth",5) == 0)
1604 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1610 if (LocaleCompare(symbol,"g") == 0)
1611 return(QuantumScale*pixel.green);
1617 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1618 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1619 if (LocaleCompare(symbol,"k") == 0)
1621 if (image->colorspace != CMYKColorspace)
1623 (void) ThrowMagickException(exception,GetMagickModule(),
1624 OptionError,"ColorSeparatedImageRequired","`%s'",
1628 return(QuantumScale*pixel.black);
1635 if (LocaleCompare(symbol,"h") == 0)
1636 return((MagickRealType) image->rows);
1637 if (LocaleCompare(symbol,"hue") == 0)
1644 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1653 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1654 (LocaleCompare(symbol,"image.minima") == 0) ||
1655 (LocaleCompare(symbol,"image.maxima") == 0) ||
1656 (LocaleCompare(symbol,"image.mean") == 0) ||
1657 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1658 (LocaleCompare(symbol,"image.skewness") == 0) ||
1659 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1660 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1661 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1662 return(image->resolution.x);
1663 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1664 return(image->resolution.y);
1665 if (LocaleCompare(symbol,"intensity") == 0)
1666 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1667 if (LocaleCompare(symbol,"i") == 0)
1668 return((MagickRealType) x);
1674 if (LocaleCompare(symbol,"j") == 0)
1675 return((MagickRealType) y);
1681 if (LocaleCompare(symbol,"lightness") == 0)
1688 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1692 if (LocaleCompare(symbol,"luminance") == 0)
1697 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1698 return(QuantumScale*luminence);
1705 if (LocaleNCompare(symbol,"maxima",6) == 0)
1706 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1707 if (LocaleNCompare(symbol,"mean",4) == 0)
1708 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1709 if (LocaleNCompare(symbol,"minima",6) == 0)
1710 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1711 if (LocaleCompare(symbol,"m") == 0)
1712 return(QuantumScale*pixel.blue);
1718 if (LocaleCompare(symbol,"n") == 0)
1719 return((MagickRealType) GetImageListLength(fx_info->images));
1725 if (LocaleCompare(symbol,"o") == 0)
1726 return(QuantumScale*pixel.alpha);
1732 if (LocaleCompare(symbol,"page.height") == 0)
1733 return((MagickRealType) image->page.height);
1734 if (LocaleCompare(symbol,"page.width") == 0)
1735 return((MagickRealType) image->page.width);
1736 if (LocaleCompare(symbol,"page.x") == 0)
1737 return((MagickRealType) image->page.x);
1738 if (LocaleCompare(symbol,"page.y") == 0)
1739 return((MagickRealType) image->page.y);
1745 if (LocaleCompare(symbol,"resolution.x") == 0)
1746 return(image->resolution.x);
1747 if (LocaleCompare(symbol,"resolution.y") == 0)
1748 return(image->resolution.y);
1749 if (LocaleCompare(symbol,"r") == 0)
1750 return(QuantumScale*pixel.red);
1756 if (LocaleCompare(symbol,"saturation") == 0)
1763 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1767 if (LocaleNCompare(symbol,"skewness",8) == 0)
1768 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1769 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1770 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1776 if (LocaleCompare(symbol,"t") == 0)
1777 return((MagickRealType) GetImageIndexInList(fx_info->images));
1783 if (LocaleCompare(symbol,"w") == 0)
1784 return((MagickRealType) image->columns);
1790 if (LocaleCompare(symbol,"y") == 0)
1791 return(QuantumScale*pixel.green);
1797 if (LocaleCompare(symbol,"z") == 0)
1802 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1810 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1811 if (value != (const char *) NULL)
1812 return((MagickRealType) StringToDouble(value,(char **) NULL));
1813 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1814 "UnableToParseExpression","`%s'",symbol);
1818 static const char *FxOperatorPrecedence(const char *expression,
1819 ExceptionInfo *exception)
1823 UndefinedPrecedence,
1825 BitwiseComplementPrecedence,
1827 ExponentialNotationPrecedence,
1831 RelationalPrecedence,
1832 EquivalencyPrecedence,
1833 BitwiseAndPrecedence,
1834 BitwiseOrPrecedence,
1835 LogicalAndPrecedence,
1836 LogicalOrPrecedence,
1838 AssignmentPrecedence,
1858 subexpression=(const char *) NULL;
1859 target=NullPrecedence;
1860 while (*expression != '\0')
1862 precedence=UndefinedPrecedence;
1863 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1868 switch (*expression)
1873 #if defined(MAGICKCORE_HAVE_ACOSH)
1874 if (LocaleNCompare(expression,"acosh",5) == 0)
1880 #if defined(MAGICKCORE_HAVE_ASINH)
1881 if (LocaleNCompare(expression,"asinh",5) == 0)
1887 #if defined(MAGICKCORE_HAVE_ATANH)
1888 if (LocaleNCompare(expression,"atanh",5) == 0)
1899 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1900 (LocaleNCompare(expression,"E-",2) == 0))
1902 expression+=2; /* scientific notation */
1909 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1910 (LocaleNCompare(expression,"j1",2) == 0))
1919 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1926 if ((c == (int) '{') || (c == (int) '['))
1929 if ((c == (int) '}') || (c == (int) ']'))
1932 switch ((unsigned char) *expression)
1937 precedence=BitwiseComplementPrecedence;
1943 precedence=ExponentPrecedence;
1948 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1949 (strchr(")",c) != (char *) NULL))) &&
1950 (((islower((int) ((char) *expression)) != 0) ||
1951 (strchr("(",(int) *expression) != (char *) NULL)) ||
1952 ((isdigit((int) ((char) c)) == 0) &&
1953 (isdigit((int) ((char) *expression)) != 0))) &&
1954 (strchr("xy",(int) *expression) == (char *) NULL))
1955 precedence=MultiplyPrecedence;
1962 precedence=MultiplyPrecedence;
1968 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1970 precedence=AdditionPrecedence;
1973 case LeftShiftOperator:
1974 case RightShiftOperator:
1976 precedence=ShiftPrecedence;
1980 case LessThanEqualOperator:
1981 case GreaterThanEqualOperator:
1984 precedence=RelationalPrecedence;
1988 case NotEqualOperator:
1990 precedence=EquivalencyPrecedence;
1995 precedence=BitwiseAndPrecedence;
2000 precedence=BitwiseOrPrecedence;
2003 case LogicalAndOperator:
2005 precedence=LogicalAndPrecedence;
2008 case LogicalOrOperator:
2010 precedence=LogicalOrPrecedence;
2013 case ExponentialNotation:
2015 precedence=ExponentialNotationPrecedence;
2021 precedence=TernaryPrecedence;
2026 precedence=AssignmentPrecedence;
2031 precedence=CommaPrecedence;
2036 precedence=SeparatorPrecedence;
2040 if ((precedence == BitwiseComplementPrecedence) ||
2041 (precedence == TernaryPrecedence) ||
2042 (precedence == AssignmentPrecedence))
2044 if (precedence > target)
2047 Right-to-left associativity.
2050 subexpression=expression;
2054 if (precedence >= target)
2057 Left-to-right associativity.
2060 subexpression=expression;
2062 if (strchr("(",(int) *expression) != (char *) NULL)
2063 expression=FxSubexpression(expression,exception);
2064 c=(int) (*expression++);
2066 return(subexpression);
2069 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2070 const PixelChannel channel,const ssize_t x,const ssize_t y,
2071 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2075 subexpression[MaxTextExtent];
2085 if (exception->severity != UndefinedException)
2087 while (isspace((int) *expression) != 0)
2089 if (*expression == '\0')
2091 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2092 "MissingExpression","`%s'",expression);
2095 *subexpression='\0';
2096 p=FxOperatorPrecedence(expression,exception);
2097 if (p != (const char *) NULL)
2099 (void) CopyMagickString(subexpression,expression,(size_t)
2101 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2103 switch ((unsigned char) *p)
2107 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2108 *beta=(MagickRealType) (~(size_t) *beta);
2113 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2114 return(*beta == 0.0 ? 1.0 : 0.0);
2118 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2119 channel,x,y,++p,beta,exception));
2123 case ExponentialNotation:
2125 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2126 return(alpha*(*beta));
2130 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2133 if (exception->severity == UndefinedException)
2134 (void) ThrowMagickException(exception,GetMagickModule(),
2135 OptionError,"DivideByZero","`%s'",expression);
2138 return(alpha/(*beta));
2142 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2143 *beta=fabs(floor(((double) *beta)+0.5));
2146 (void) ThrowMagickException(exception,GetMagickModule(),
2147 OptionError,"DivideByZero","`%s'",expression);
2150 return(fmod((double) alpha,(double) *beta));
2154 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2155 return(alpha+(*beta));
2159 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2160 return(alpha-(*beta));
2162 case LeftShiftOperator:
2164 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2165 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
2168 case RightShiftOperator:
2170 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2171 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
2176 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2177 return(alpha < *beta ? 1.0 : 0.0);
2179 case LessThanEqualOperator:
2181 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2182 return(alpha <= *beta ? 1.0 : 0.0);
2186 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2187 return(alpha > *beta ? 1.0 : 0.0);
2189 case GreaterThanEqualOperator:
2191 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2192 return(alpha >= *beta ? 1.0 : 0.0);
2196 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2197 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2199 case NotEqualOperator:
2201 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2202 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2206 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2207 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
2212 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2213 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
2216 case LogicalAndOperator:
2218 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2219 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2222 case LogicalOrOperator:
2224 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2225 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2233 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2235 p=StringToken(":",&q);
2236 if (q == (char *) NULL)
2238 (void) ThrowMagickException(exception,GetMagickModule(),
2239 OptionError,"UnableToParseExpression","`%s'",subexpression);
2242 if (fabs((double) alpha) > MagickEpsilon)
2243 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2245 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2251 numeric[MaxTextExtent];
2254 while (isalpha((int) ((unsigned char) *q)) != 0)
2258 (void) ThrowMagickException(exception,GetMagickModule(),
2259 OptionError,"UnableToParseExpression","`%s'",subexpression);
2262 ClearMagickException(exception);
2263 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2264 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2266 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2267 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2268 subexpression),ConstantString(numeric));
2273 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2278 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2283 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2289 if (strchr("(",(int) *expression) != (char *) NULL)
2291 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2292 subexpression[strlen(subexpression)-1]='\0';
2293 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2297 switch (*expression)
2301 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2307 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2313 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2315 return((MagickRealType) (~(size_t) (gamma+0.5)));
2320 if (LocaleNCompare(expression,"abs",3) == 0)
2322 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2324 return((MagickRealType) fabs((double) alpha));
2326 #if defined(MAGICKCORE_HAVE_ACOSH)
2327 if (LocaleNCompare(expression,"acosh",5) == 0)
2329 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2331 return((MagickRealType) acosh((double) alpha));
2334 if (LocaleNCompare(expression,"acos",4) == 0)
2336 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2338 return((MagickRealType) acos((double) alpha));
2340 #if defined(MAGICKCORE_HAVE_J1)
2341 if (LocaleNCompare(expression,"airy",4) == 0)
2343 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2347 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2348 return(gamma*gamma);
2351 #if defined(MAGICKCORE_HAVE_ASINH)
2352 if (LocaleNCompare(expression,"asinh",5) == 0)
2354 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2356 return((MagickRealType) asinh((double) alpha));
2359 if (LocaleNCompare(expression,"asin",4) == 0)
2361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2363 return((MagickRealType) asin((double) alpha));
2365 if (LocaleNCompare(expression,"alt",3) == 0)
2367 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2369 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2371 if (LocaleNCompare(expression,"atan2",5) == 0)
2373 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2375 return((MagickRealType) atan2((double) alpha,(double) *beta));
2377 #if defined(MAGICKCORE_HAVE_ATANH)
2378 if (LocaleNCompare(expression,"atanh",5) == 0)
2380 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2382 return((MagickRealType) atanh((double) alpha));
2385 if (LocaleNCompare(expression,"atan",4) == 0)
2387 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2389 return((MagickRealType) atan((double) alpha));
2391 if (LocaleCompare(expression,"a") == 0)
2392 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2398 if (LocaleCompare(expression,"b") == 0)
2399 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2405 if (LocaleNCompare(expression,"ceil",4) == 0)
2407 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2409 return((MagickRealType) ceil((double) alpha));
2411 if (LocaleNCompare(expression,"cosh",4) == 0)
2413 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2415 return((MagickRealType) cosh((double) alpha));
2417 if (LocaleNCompare(expression,"cos",3) == 0)
2419 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2421 return((MagickRealType) cos((double) alpha));
2423 if (LocaleCompare(expression,"c") == 0)
2424 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2430 if (LocaleNCompare(expression,"debug",5) == 0)
2435 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2437 if (fx_info->images->colorspace == CMYKColorspace)
2440 case CyanPixelChannel: type="cyan"; break;
2441 case MagentaPixelChannel: type="magenta"; break;
2442 case YellowPixelChannel: type="yellow"; break;
2443 case AlphaPixelChannel: type="opacity"; break;
2444 case BlackPixelChannel: type="black"; break;
2445 default: type="unknown"; break;
2450 case RedPixelChannel: type="red"; break;
2451 case GreenPixelChannel: type="green"; break;
2452 case BluePixelChannel: type="blue"; break;
2453 case AlphaPixelChannel: type="opacity"; break;
2454 default: type="unknown"; break;
2456 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2457 if (strlen(subexpression) > 1)
2458 subexpression[strlen(subexpression)-1]='\0';
2459 if (fx_info->file != (FILE *) NULL)
2460 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2461 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2462 subexpression,GetMagickPrecision(),(double) alpha);
2465 if (LocaleNCompare(expression,"drc",3) == 0)
2467 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2469 return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0)));
2476 if (LocaleCompare(expression,"epsilon") == 0)
2477 return((MagickRealType) MagickEpsilon);
2478 if (LocaleNCompare(expression,"exp",3) == 0)
2480 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2482 return((MagickRealType) exp((double) alpha));
2484 if (LocaleCompare(expression,"e") == 0)
2485 return((MagickRealType) 2.7182818284590452354);
2491 if (LocaleNCompare(expression,"floor",5) == 0)
2493 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2495 return((MagickRealType) floor((double) alpha));
2502 if (LocaleNCompare(expression,"gauss",5) == 0)
2504 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2506 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2507 return((MagickRealType) gamma);
2509 if (LocaleNCompare(expression,"gcd",3) == 0)
2514 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2516 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2518 return((MagickRealType) gcd);
2520 if (LocaleCompare(expression,"g") == 0)
2521 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2527 if (LocaleCompare(expression,"h") == 0)
2528 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2529 if (LocaleCompare(expression,"hue") == 0)
2530 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2531 if (LocaleNCompare(expression,"hypot",5) == 0)
2533 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2535 return((MagickRealType) hypot((double) alpha,(double) *beta));
2542 if (LocaleCompare(expression,"k") == 0)
2543 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2549 if (LocaleCompare(expression,"intensity") == 0)
2550 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2551 if (LocaleNCompare(expression,"int",3) == 0)
2553 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2555 return((MagickRealType) floor(alpha));
2557 #if defined(MAGICKCORE_HAVE_ISNAN)
2558 if (LocaleNCompare(expression,"isnan",5) == 0)
2560 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2562 return((MagickRealType) !!isnan((double) alpha));
2565 if (LocaleCompare(expression,"i") == 0)
2566 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2572 if (LocaleCompare(expression,"j") == 0)
2573 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2574 #if defined(MAGICKCORE_HAVE_J0)
2575 if (LocaleNCompare(expression,"j0",2) == 0)
2577 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2579 return((MagickRealType) j0((double) alpha));
2582 #if defined(MAGICKCORE_HAVE_J1)
2583 if (LocaleNCompare(expression,"j1",2) == 0)
2585 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2587 return((MagickRealType) j1((double) alpha));
2590 #if defined(MAGICKCORE_HAVE_J1)
2591 if (LocaleNCompare(expression,"jinc",4) == 0)
2593 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2597 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
2607 if (LocaleNCompare(expression,"ln",2) == 0)
2609 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2611 return((MagickRealType) log((double) alpha));
2613 if (LocaleNCompare(expression,"logtwo",6) == 0)
2615 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2617 return((MagickRealType) log10((double) alpha))/log10(2.0);
2619 if (LocaleNCompare(expression,"log",3) == 0)
2621 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2623 return((MagickRealType) log10((double) alpha));
2625 if (LocaleCompare(expression,"lightness") == 0)
2626 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2632 if (LocaleCompare(expression,"MaxRGB") == 0)
2633 return((MagickRealType) QuantumRange);
2634 if (LocaleNCompare(expression,"maxima",6) == 0)
2636 if (LocaleNCompare(expression,"max",3) == 0)
2638 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2640 return(alpha > *beta ? alpha : *beta);
2642 if (LocaleNCompare(expression,"minima",6) == 0)
2644 if (LocaleNCompare(expression,"min",3) == 0)
2646 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2648 return(alpha < *beta ? alpha : *beta);
2650 if (LocaleNCompare(expression,"mod",3) == 0)
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2654 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2657 if (LocaleCompare(expression,"m") == 0)
2658 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2664 if (LocaleNCompare(expression,"not",3) == 0)
2666 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2668 return((MagickRealType) (alpha < MagickEpsilon));
2670 if (LocaleCompare(expression,"n") == 0)
2671 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2677 if (LocaleCompare(expression,"Opaque") == 0)
2679 if (LocaleCompare(expression,"o") == 0)
2680 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2686 if (LocaleCompare(expression,"phi") == 0)
2687 return((MagickRealType) MagickPHI);
2688 if (LocaleCompare(expression,"pi") == 0)
2689 return((MagickRealType) MagickPI);
2690 if (LocaleNCompare(expression,"pow",3) == 0)
2692 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2694 return((MagickRealType) pow((double) alpha,(double) *beta));
2696 if (LocaleCompare(expression,"p") == 0)
2697 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2703 if (LocaleCompare(expression,"QuantumRange") == 0)
2704 return((MagickRealType) QuantumRange);
2705 if (LocaleCompare(expression,"QuantumScale") == 0)
2706 return((MagickRealType) QuantumScale);
2712 if (LocaleNCompare(expression,"rand",4) == 0)
2713 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2714 if (LocaleNCompare(expression,"round",5) == 0)
2716 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2718 return((MagickRealType) floor((double) alpha+0.5));
2720 if (LocaleCompare(expression,"r") == 0)
2721 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2727 if (LocaleCompare(expression,"saturation") == 0)
2728 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2729 if (LocaleNCompare(expression,"sign",4) == 0)
2731 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2733 return(alpha < 0.0 ? -1.0 : 1.0);
2735 if (LocaleNCompare(expression,"sinc",4) == 0)
2737 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2741 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2745 if (LocaleNCompare(expression,"sinh",4) == 0)
2747 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2749 return((MagickRealType) sinh((double) alpha));
2751 if (LocaleNCompare(expression,"sin",3) == 0)
2753 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2755 return((MagickRealType) sin((double) alpha));
2757 if (LocaleNCompare(expression,"sqrt",4) == 0)
2759 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2761 return((MagickRealType) sqrt((double) alpha));
2763 if (LocaleNCompare(expression,"squish",6) == 0)
2765 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2767 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2769 if (LocaleCompare(expression,"s") == 0)
2770 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2776 if (LocaleNCompare(expression,"tanh",4) == 0)
2778 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2780 return((MagickRealType) tanh((double) alpha));
2782 if (LocaleNCompare(expression,"tan",3) == 0)
2784 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2786 return((MagickRealType) tan((double) alpha));
2788 if (LocaleCompare(expression,"Transparent") == 0)
2790 if (LocaleNCompare(expression,"trunc",5) == 0)
2792 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2795 return((MagickRealType) floor((double) alpha));
2796 return((MagickRealType) ceil((double) alpha));
2798 if (LocaleCompare(expression,"t") == 0)
2799 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2805 if (LocaleCompare(expression,"u") == 0)
2806 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2812 if (LocaleCompare(expression,"v") == 0)
2813 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2819 if (LocaleNCompare(expression,"while",5) == 0)
2823 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2825 } while (fabs((double) alpha) >= MagickEpsilon);
2826 return((MagickRealType) *beta);
2828 if (LocaleCompare(expression,"w") == 0)
2829 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2835 if (LocaleCompare(expression,"y") == 0)
2836 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2842 if (LocaleCompare(expression,"z") == 0)
2843 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2849 q=(char *) expression;
2850 alpha=InterpretSiPrefixValue(expression,&q);
2851 if (q == expression)
2852 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2856 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2857 MagickRealType *alpha,ExceptionInfo *exception)
2862 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2867 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2868 MagickRealType *alpha,ExceptionInfo *exception)
2877 fx_info->file=(FILE *) NULL;
2878 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2884 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2885 const PixelChannel channel,const ssize_t x,const ssize_t y,
2886 MagickRealType *alpha,ExceptionInfo *exception)
2892 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2894 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2908 % FxImage() applies a mathematical expression to the specified image.
2910 % The format of the FxImage method is:
2912 % Image *FxImage(const Image *image,const char *expression,
2913 % ExceptionInfo *exception)
2915 % A description of each parameter follows:
2917 % o image: the image.
2919 % o expression: A mathematical expression.
2921 % o exception: return any errors or warnings in this structure.
2925 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2930 assert(fx_info != (FxInfo **) NULL);
2931 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2932 if (fx_info[i] != (FxInfo *) NULL)
2933 fx_info[i]=DestroyFxInfo(fx_info[i]);
2934 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2938 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2939 ExceptionInfo *exception)
2956 number_threads=GetOpenMPMaximumThreads();
2957 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2958 if (fx_info == (FxInfo **) NULL)
2959 return((FxInfo **) NULL);
2960 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2961 if (*expression != '@')
2962 fx_expression=ConstantString(expression);
2964 fx_expression=FileToString(expression+1,~0,exception);
2965 for (i=0; i < (ssize_t) number_threads; i++)
2967 fx_info[i]=AcquireFxInfo(image,fx_expression);
2968 if (fx_info[i] == (FxInfo *) NULL)
2969 return(DestroyFxThreadSet(fx_info));
2970 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2972 fx_expression=DestroyString(fx_expression);
2976 MagickExport Image *FxImage(const Image *image,const char *expression,
2977 ExceptionInfo *exception)
2979 #define FxImageTag "Fx/Image"
3003 assert(image != (Image *) NULL);
3004 assert(image->signature == MagickSignature);
3005 if (image->debug != MagickFalse)
3006 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3007 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3008 if (fx_image == (Image *) NULL)
3009 return((Image *) NULL);
3010 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3012 fx_image=DestroyImage(fx_image);
3013 return((Image *) NULL);
3015 fx_info=AcquireFxThreadSet(image,expression,exception);
3016 if (fx_info == (FxInfo **) NULL)
3018 fx_image=DestroyImage(fx_image);
3019 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3021 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3022 if (status == MagickFalse)
3024 fx_image=DestroyImage(fx_image);
3025 fx_info=DestroyFxThreadSet(fx_info);
3026 return((Image *) NULL);
3033 image_view=AcquireCacheView(image);
3034 fx_view=AcquireCacheView(fx_image);
3035 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3036 #pragma omp parallel for schedule(static,4) shared(progress,status)
3038 for (y=0; y < (ssize_t) fx_image->rows; y++)
3041 id = GetOpenMPThreadId();
3043 register const Quantum
3052 if (status == MagickFalse)
3054 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3055 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3056 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3061 for (x=0; x < (ssize_t) fx_image->columns; x++)
3066 if (GetPixelMask(image,p) != 0)
3068 p+=GetPixelChannels(image);
3069 q+=GetPixelChannels(fx_image);
3072 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3084 channel=GetPixelChannelMapChannel(image,i);
3085 traits=GetPixelChannelMapTraits(image,channel);
3086 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3087 if ((traits == UndefinedPixelTrait) ||
3088 (fx_traits == UndefinedPixelTrait))
3090 if ((fx_traits & CopyPixelTrait) != 0)
3092 SetPixelChannel(fx_image,channel,p[i],q);
3096 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3098 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3100 p+=GetPixelChannels(image);
3101 q+=GetPixelChannels(fx_image);
3103 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3105 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3110 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3111 #pragma omp critical (MagickCore_FxImage)
3113 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3114 if (proceed == MagickFalse)
3118 fx_view=DestroyCacheView(fx_view);
3119 image_view=DestroyCacheView(image_view);
3120 fx_info=DestroyFxThreadSet(fx_info);
3121 if (status == MagickFalse)
3122 fx_image=DestroyImage(fx_image);
3127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3131 % I m p l o d e I m a g e %
3135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3137 % ImplodeImage() creates a new image that is a copy of an existing
3138 % one with the image pixels "implode" by the specified percentage. It
3139 % allocates the memory necessary for the new Image structure and returns a
3140 % pointer to the new image.
3142 % The format of the ImplodeImage method is:
3144 % Image *ImplodeImage(const Image *image,const double amount,
3145 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3147 % A description of each parameter follows:
3149 % o implode_image: Method ImplodeImage returns a pointer to the image
3150 % after it is implode. A null image is returned if there is a memory
3153 % o image: the image.
3155 % o amount: Define the extent of the implosion.
3157 % o method: the pixel interpolation method.
3159 % o exception: return any errors or warnings in this structure.
3162 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3163 const PixelInterpolateMethod method,ExceptionInfo *exception)
3165 #define ImplodeImageTag "Implode/Image"
3191 Initialize implode image attributes.
3193 assert(image != (Image *) NULL);
3194 assert(image->signature == MagickSignature);
3195 if (image->debug != MagickFalse)
3196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3197 assert(exception != (ExceptionInfo *) NULL);
3198 assert(exception->signature == MagickSignature);
3199 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3201 if (implode_image == (Image *) NULL)
3202 return((Image *) NULL);
3203 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3205 implode_image=DestroyImage(implode_image);
3206 return((Image *) NULL);
3208 if (implode_image->background_color.alpha != OpaqueAlpha)
3209 implode_image->matte=MagickTrue;
3211 Compute scaling factor.
3215 center.x=0.5*image->columns;
3216 center.y=0.5*image->rows;
3218 if (image->columns > image->rows)
3219 scale.y=(double) image->columns/(double) image->rows;
3221 if (image->columns < image->rows)
3223 scale.x=(double) image->rows/(double) image->columns;
3231 image_view=AcquireCacheView(image);
3232 implode_view=AcquireCacheView(implode_image);
3233 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3234 #pragma omp parallel for schedule(static,4) shared(progress,status)
3236 for (y=0; y < (ssize_t) image->rows; y++)
3244 register const Quantum
3253 if (status == MagickFalse)
3255 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3256 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3258 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3263 delta.y=scale.y*(double) (y-center.y);
3264 for (x=0; x < (ssize_t) image->columns; x++)
3270 Determine if the pixel is within an ellipse.
3272 if (GetPixelMask(image,p) != 0)
3274 p+=GetPixelChannels(image);
3275 q+=GetPixelChannels(implode_image);
3278 delta.x=scale.x*(double) (x-center.x);
3279 distance=delta.x*delta.x+delta.y*delta.y;
3280 if (distance >= (radius*radius))
3281 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3290 channel=GetPixelChannelMapChannel(image,i);
3291 traits=GetPixelChannelMapTraits(image,channel);
3292 implode_traits=GetPixelChannelMapTraits(implode_image,channel);
3293 if ((traits == UndefinedPixelTrait) ||
3294 (implode_traits == UndefinedPixelTrait))
3296 SetPixelChannel(implode_image,channel,p[i],q);
3308 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3310 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3311 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3312 scale.y+center.y),q,exception);
3314 p+=GetPixelChannels(image);
3315 q+=GetPixelChannels(implode_image);
3317 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3319 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3324 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3325 #pragma omp critical (MagickCore_ImplodeImage)
3327 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3328 if (proceed == MagickFalse)
3332 implode_view=DestroyCacheView(implode_view);
3333 image_view=DestroyCacheView(image_view);
3334 if (status == MagickFalse)
3335 implode_image=DestroyImage(implode_image);
3336 return(implode_image);
3340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3344 % M o r p h I m a g e s %
3348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3350 % The MorphImages() method requires a minimum of two images. The first
3351 % image is transformed into the second by a number of intervening images
3352 % as specified by frames.
3354 % The format of the MorphImage method is:
3356 % Image *MorphImages(const Image *image,const size_t number_frames,
3357 % ExceptionInfo *exception)
3359 % A description of each parameter follows:
3361 % o image: the image.
3363 % o number_frames: Define the number of in-between image to generate.
3364 % The more in-between frames, the smoother the morph.
3366 % o exception: return any errors or warnings in this structure.
3369 MagickExport Image *MorphImages(const Image *image,
3370 const size_t number_frames,ExceptionInfo *exception)
3372 #define MorphImageTag "Morph/Image"
3388 register const Image
3398 Clone first frame in sequence.
3400 assert(image != (Image *) NULL);
3401 assert(image->signature == MagickSignature);
3402 if (image->debug != MagickFalse)
3403 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3404 assert(exception != (ExceptionInfo *) NULL);
3405 assert(exception->signature == MagickSignature);
3406 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3407 if (morph_images == (Image *) NULL)
3408 return((Image *) NULL);
3409 if (GetNextImageInList(image) == (Image *) NULL)
3414 for (i=1; i < (ssize_t) number_frames; i++)
3416 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3417 if (morph_image == (Image *) NULL)
3419 morph_images=DestroyImageList(morph_images);
3420 return((Image *) NULL);
3422 AppendImageToList(&morph_images,morph_image);
3423 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3428 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3430 if (proceed == MagickFalse)
3434 return(GetFirstImageInList(morph_images));
3437 Morph image sequence.
3442 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3444 for (i=0; i < (ssize_t) number_frames; i++)
3450 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3452 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3453 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
3454 GetNextImageInList(next)->rows+0.5),next->filter,exception);
3455 if (morph_image == (Image *) NULL)
3457 morph_images=DestroyImageList(morph_images);
3458 return((Image *) NULL);
3460 status=SetImageStorageClass(morph_image,DirectClass,exception);
3461 if (status == MagickFalse)
3463 morph_image=DestroyImage(morph_image);
3464 return((Image *) NULL);
3466 AppendImageToList(&morph_images,morph_image);
3467 morph_images=GetLastImageInList(morph_images);
3468 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3469 morph_images->rows,GetNextImageInList(next)->filter,exception);
3470 if (morph_image == (Image *) NULL)
3472 morph_images=DestroyImageList(morph_images);
3473 return((Image *) NULL);
3475 image_view=AcquireCacheView(morph_image);
3476 morph_view=AcquireCacheView(morph_images);
3477 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3478 #pragma omp parallel for schedule(static,4) shared(status)
3480 for (y=0; y < (ssize_t) morph_images->rows; y++)
3485 register const Quantum
3494 if (status == MagickFalse)
3496 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3498 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3500 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3505 for (x=0; x < (ssize_t) morph_images->columns; x++)
3510 if (GetPixelMask(image,p) != 0)
3512 p+=GetPixelChannels(image);
3513 q+=GetPixelChannels(morph_image);
3516 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
3525 channel=GetPixelChannelMapChannel(image,i);
3526 traits=GetPixelChannelMapTraits(image,channel);
3527 morph_traits=GetPixelChannelMapTraits(morph_image,channel);
3528 if ((traits == UndefinedPixelTrait) ||
3529 (morph_traits == UndefinedPixelTrait))
3531 if ((morph_traits & CopyPixelTrait) != 0)
3533 SetPixelChannel(morph_image,channel,p[i],q);
3536 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3537 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3539 p+=GetPixelChannels(morph_image);
3540 q+=GetPixelChannels(morph_images);
3542 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3543 if (sync == MagickFalse)
3546 morph_view=DestroyCacheView(morph_view);
3547 image_view=DestroyCacheView(image_view);
3548 morph_image=DestroyImage(morph_image);
3550 if (i < (ssize_t) number_frames)
3553 Clone last frame in sequence.
3555 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3556 if (morph_image == (Image *) NULL)
3558 morph_images=DestroyImageList(morph_images);
3559 return((Image *) NULL);
3561 AppendImageToList(&morph_images,morph_image);
3562 morph_images=GetLastImageInList(morph_images);
3563 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3568 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3569 #pragma omp critical (MagickCore_MorphImages)
3571 proceed=SetImageProgress(image,MorphImageTag,scene,
3572 GetImageListLength(image));
3573 if (proceed == MagickFalse)
3578 if (GetNextImageInList(next) != (Image *) NULL)
3580 morph_images=DestroyImageList(morph_images);
3581 return((Image *) NULL);
3583 return(GetFirstImageInList(morph_images));
3587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3591 % P l a s m a I m a g e %
3595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3597 % PlasmaImage() initializes an image with plasma fractal values. The image
3598 % must be initialized with a base color and the random number generator
3599 % seeded before this method is called.
3601 % The format of the PlasmaImage method is:
3603 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3604 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3606 % A description of each parameter follows:
3608 % o image: the image.
3610 % o segment: Define the region to apply plasma fractals values.
3612 % o attenuate: Define the plasma attenuation factor.
3614 % o depth: Limit the plasma recursion depth.
3616 % o exception: return any errors or warnings in this structure.
3620 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3621 const MagickRealType pixel,const MagickRealType noise)
3626 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3631 static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3632 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3633 const SegmentInfo *segment,size_t attenuate,size_t depth,
3634 ExceptionInfo *exception)
3645 register const Quantum
3661 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3669 Divide the area into quadrants and recurse.
3673 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3674 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3675 local_info=(*segment);
3676 local_info.x2=(double) x_mid;
3677 local_info.y2=(double) y_mid;
3678 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3679 &local_info,attenuate,depth,exception);
3680 local_info=(*segment);
3681 local_info.y1=(double) y_mid;
3682 local_info.x2=(double) x_mid;
3683 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3684 &local_info,attenuate,depth,exception);
3685 local_info=(*segment);
3686 local_info.x1=(double) x_mid;
3687 local_info.y2=(double) y_mid;
3688 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3689 &local_info,attenuate,depth,exception);
3690 local_info=(*segment);
3691 local_info.x1=(double) x_mid;
3692 local_info.y1=(double) y_mid;
3693 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3694 &local_info,attenuate,depth,exception));
3696 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3697 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3698 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3699 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3700 return(MagickFalse);
3702 Average pixels and apply plasma.
3704 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3705 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3710 x=(ssize_t) ceil(segment->x1-0.5);
3711 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3713 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3715 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3716 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3717 (q == (Quantum *) NULL))
3719 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3721 channel=GetPixelChannelMapChannel(image,i);
3722 traits=GetPixelChannelMapTraits(image,channel);
3723 if (traits == UndefinedPixelTrait)
3725 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3727 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3728 if (segment->x1 != segment->x2)
3733 x=(ssize_t) ceil(segment->x2-0.5);
3734 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3736 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3738 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3739 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3740 (q == (Quantum *) NULL))
3742 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3744 channel=GetPixelChannelMapChannel(image,i);
3745 traits=GetPixelChannelMapTraits(image,channel);
3746 if (traits == UndefinedPixelTrait)
3748 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3750 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3753 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3755 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3760 y=(ssize_t) ceil(segment->y2-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);
3779 if (segment->y1 != segment->y2)
3784 y=(ssize_t) ceil(segment->y1-0.5);
3785 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3787 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3789 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3790 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3791 (q == (Quantum *) NULL))
3793 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3795 channel=GetPixelChannelMapChannel(image,i);
3796 traits=GetPixelChannelMapTraits(image,channel);
3797 if (traits == UndefinedPixelTrait)
3799 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3801 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3804 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3809 x=(ssize_t) ceil(segment->x1-0.5);
3810 y=(ssize_t) ceil(segment->y1-0.5);
3811 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
3812 x=(ssize_t) ceil(segment->x2-0.5);
3813 y=(ssize_t) ceil(segment->y2-0.5);
3814 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
3815 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3816 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3817 (q == (Quantum *) NULL))
3819 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3821 channel=GetPixelChannelMapChannel(image,i);
3822 traits=GetPixelChannelMapTraits(image,channel);
3823 if (traits == UndefinedPixelTrait)
3825 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3827 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3829 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3831 return(MagickFalse);
3834 MagickExport MagickBooleanType PlasmaImage(Image *image,
3835 const SegmentInfo *segment,size_t attenuate,size_t depth,
3836 ExceptionInfo *exception)
3849 if (image->debug != MagickFalse)
3850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3851 assert(image != (Image *) NULL);
3852 assert(image->signature == MagickSignature);
3853 if (image->debug != MagickFalse)
3854 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3855 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3856 return(MagickFalse);
3857 image_view=AcquireCacheView(image);
3858 u_view=AcquireCacheView(image);
3859 v_view=AcquireCacheView(image);
3860 random_info=AcquireRandomInfo();
3861 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3862 attenuate,depth,exception);
3863 random_info=DestroyRandomInfo(random_info);
3864 v_view=DestroyCacheView(v_view);
3865 u_view=DestroyCacheView(u_view);
3866 image_view=DestroyCacheView(image_view);
3871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3875 % P o l a r o i d I m a g e %
3879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3881 % PolaroidImage() simulates a Polaroid picture.
3883 % The format of the AnnotateImage method is:
3885 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3886 % const char *caption,const double angle,
3887 % const PixelInterpolateMethod method,ExceptionInfo exception)
3889 % A description of each parameter follows:
3891 % o image: the image.
3893 % o draw_info: the draw info.
3895 % o caption: the Polaroid caption.
3897 % o angle: Apply the effect along this angle.
3899 % o method: the pixel interpolation method.
3901 % o exception: return any errors or warnings in this structure.
3904 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3905 const char *caption,const double angle,const PixelInterpolateMethod method,
3906 ExceptionInfo *exception)
3924 Simulate a Polaroid picture.
3926 assert(image != (Image *) NULL);
3927 assert(image->signature == MagickSignature);
3928 if (image->debug != MagickFalse)
3929 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3930 assert(exception != (ExceptionInfo *) NULL);
3931 assert(exception->signature == MagickSignature);
3932 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3933 image->rows)/25.0,10.0);
3934 height=image->rows+2*quantum;
3935 caption_image=(Image *) NULL;
3936 if (caption != (const char *) NULL)
3939 geometry[MaxTextExtent],
3955 Generate caption image.
3957 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3958 if (caption_image == (Image *) NULL)
3959 return((Image *) NULL);
3960 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3961 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3963 (void) CloneString(&annotate_info->text,text);
3964 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3966 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
3967 (metrics.ascent-metrics.descent)+0.5),exception);
3968 if (status == MagickFalse)
3969 caption_image=DestroyImage(caption_image);
3972 caption_image->background_color=image->border_color;
3973 (void) SetImageBackgroundColor(caption_image,exception);
3974 (void) CloneString(&annotate_info->text,text);
3975 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
3977 if (annotate_info->gravity == UndefinedGravity)
3978 (void) CloneString(&annotate_info->geometry,AcquireString(
3980 (void) AnnotateImage(caption_image,annotate_info,exception);
3981 height+=caption_image->rows;
3983 annotate_info=DestroyDrawInfo(annotate_info);
3984 text=DestroyString(text);
3986 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3988 if (picture_image == (Image *) NULL)
3990 if (caption_image != (Image *) NULL)
3991 caption_image=DestroyImage(caption_image);
3992 return((Image *) NULL);
3994 picture_image->background_color=image->border_color;
3995 (void) SetImageBackgroundColor(picture_image,exception);
3996 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum,
3998 if (caption_image != (Image *) NULL)
4000 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
4001 MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception);
4002 caption_image=DestroyImage(caption_image);
4004 (void) QueryColorCompliance("none",AllCompliance,
4005 &picture_image->background_color,exception);
4006 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
4007 rotate_image=RotateImage(picture_image,90.0,exception);
4008 picture_image=DestroyImage(picture_image);
4009 if (rotate_image == (Image *) NULL)
4010 return((Image *) NULL);
4011 picture_image=rotate_image;
4012 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
4013 picture_image->columns,method,exception);
4014 picture_image=DestroyImage(picture_image);
4015 if (bend_image == (Image *) NULL)
4016 return((Image *) NULL);
4017 picture_image=bend_image;
4018 rotate_image=RotateImage(picture_image,-90.0,exception);
4019 picture_image=DestroyImage(picture_image);
4020 if (rotate_image == (Image *) NULL)
4021 return((Image *) NULL);
4022 picture_image=rotate_image;
4023 picture_image->background_color=image->background_color;
4024 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4026 if (polaroid_image == (Image *) NULL)
4028 picture_image=DestroyImage(picture_image);
4029 return(picture_image);
4031 flop_image=FlopImage(polaroid_image,exception);
4032 polaroid_image=DestroyImage(polaroid_image);
4033 if (flop_image == (Image *) NULL)
4035 picture_image=DestroyImage(picture_image);
4036 return(picture_image);
4038 polaroid_image=flop_image;
4039 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
4040 MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
4041 picture_image=DestroyImage(picture_image);
4042 (void) QueryColorCompliance("none",AllCompliance,
4043 &polaroid_image->background_color,exception);
4044 rotate_image=RotateImage(polaroid_image,angle,exception);
4045 polaroid_image=DestroyImage(polaroid_image);
4046 if (rotate_image == (Image *) NULL)
4047 return((Image *) NULL);
4048 polaroid_image=rotate_image;
4049 trim_image=TrimImage(polaroid_image,exception);
4050 polaroid_image=DestroyImage(polaroid_image);
4051 if (trim_image == (Image *) NULL)
4052 return((Image *) NULL);
4053 polaroid_image=trim_image;
4054 return(polaroid_image);
4058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4062 % S e p i a T o n e I m a g e %
4066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4068 % MagickSepiaToneImage() applies a special effect to the image, similar to the
4069 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4070 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4071 % threshold of 80% is a good starting point for a reasonable tone.
4073 % The format of the SepiaToneImage method is:
4075 % Image *SepiaToneImage(const Image *image,const double threshold,
4076 % ExceptionInfo *exception)
4078 % A description of each parameter follows:
4080 % o image: the image.
4082 % o threshold: the tone threshold.
4084 % o exception: return any errors or warnings in this structure.
4087 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4088 ExceptionInfo *exception)
4090 #define SepiaToneImageTag "SepiaTone/Image"
4109 Initialize sepia-toned image attributes.
4111 assert(image != (const Image *) NULL);
4112 assert(image->signature == MagickSignature);
4113 if (image->debug != MagickFalse)
4114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4115 assert(exception != (ExceptionInfo *) NULL);
4116 assert(exception->signature == MagickSignature);
4117 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
4118 if (sepia_image == (Image *) NULL)
4119 return((Image *) NULL);
4120 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4122 sepia_image=DestroyImage(sepia_image);
4123 return((Image *) NULL);
4126 Tone each row of the image.
4130 image_view=AcquireCacheView(image);
4131 sepia_view=AcquireCacheView(sepia_image);
4132 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4133 #pragma omp parallel for schedule(static,4) shared(progress,status)
4135 for (y=0; y < (ssize_t) image->rows; y++)
4137 register const Quantum
4146 if (status == MagickFalse)
4148 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4149 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4151 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4156 for (x=0; x < (ssize_t) image->columns; x++)
4162 intensity=(MagickRealType) GetPixelIntensity(image,p);
4163 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4164 (MagickRealType) QuantumRange-threshold;
4165 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4166 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4167 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4168 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4169 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4170 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4172 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4173 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4174 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4175 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4176 p+=GetPixelChannels(image);
4177 q+=GetPixelChannels(sepia_image);
4179 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4181 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4186 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4187 #pragma omp critical (MagickCore_SepiaToneImage)
4189 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4191 if (proceed == MagickFalse)
4195 sepia_view=DestroyCacheView(sepia_view);
4196 image_view=DestroyCacheView(image_view);
4197 (void) NormalizeImage(sepia_image,exception);
4198 (void) ContrastImage(sepia_image,MagickTrue,exception);
4199 if (status == MagickFalse)
4200 sepia_image=DestroyImage(sepia_image);
4201 return(sepia_image);
4205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4209 % S h a d o w I m a g e %
4213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4215 % ShadowImage() simulates a shadow from the specified image and returns it.
4217 % The format of the ShadowImage method is:
4219 % Image *ShadowImage(const Image *image,const double alpha,
4220 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4221 % ExceptionInfo *exception)
4223 % A description of each parameter follows:
4225 % o image: the image.
4227 % o alpha: percentage transparency.
4229 % o sigma: the standard deviation of the Gaussian, in pixels.
4231 % o x_offset: the shadow x-offset.
4233 % o y_offset: the shadow y-offset.
4235 % o exception: return any errors or warnings in this structure.
4238 MagickExport Image *ShadowImage(const Image *image,const double alpha,
4239 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4240 ExceptionInfo *exception)
4242 #define ShadowImageTag "Shadow/Image"
4264 assert(image != (Image *) NULL);
4265 assert(image->signature == MagickSignature);
4266 if (image->debug != MagickFalse)
4267 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4268 assert(exception != (ExceptionInfo *) NULL);
4269 assert(exception->signature == MagickSignature);
4270 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4271 if (clone_image == (Image *) NULL)
4272 return((Image *) NULL);
4273 if (IsGrayColorspace(image->colorspace) != MagickFalse)
4274 (void) TransformImageColorspace(clone_image,sRGBColorspace,exception);
4275 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod,
4277 border_info.width=(size_t) floor(2.0*sigma+0.5);
4278 border_info.height=(size_t) floor(2.0*sigma+0.5);
4281 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4283 clone_image->matte=MagickTrue;
4284 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
4285 clone_image=DestroyImage(clone_image);
4286 if (border_image == (Image *) NULL)
4287 return((Image *) NULL);
4288 if (border_image->matte == MagickFalse)
4289 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4294 image_view=AcquireCacheView(border_image);
4295 for (y=0; y < (ssize_t) border_image->rows; y++)
4306 if (status == MagickFalse)
4308 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4310 if (q == (Quantum *) NULL)
4315 background_color=border_image->background_color;
4316 background_color.matte=MagickTrue;
4317 for (x=0; x < (ssize_t) border_image->columns; x++)
4319 if (border_image->matte != MagickFalse)
4320 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4321 SetPixelInfoPixel(border_image,&background_color,q);
4322 q+=GetPixelChannels(border_image);
4324 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4327 image_view=DestroyCacheView(image_view);
4328 if (status == MagickFalse)
4330 border_image=DestroyImage(border_image);
4331 return((Image *) NULL);
4333 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4334 shadow_image=BlurImage(border_image,0.0,sigma,exception);
4335 border_image=DestroyImage(border_image);
4336 if (shadow_image == (Image *) NULL)
4337 return((Image *) NULL);
4338 (void) SetPixelChannelMapMask(shadow_image,channel_mask);
4339 if (shadow_image->page.width == 0)
4340 shadow_image->page.width=shadow_image->columns;
4341 if (shadow_image->page.height == 0)
4342 shadow_image->page.height=shadow_image->rows;
4343 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4344 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4345 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4346 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4347 return(shadow_image);
4351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4355 % S k e t c h I m a g e %
4359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4361 % SketchImage() simulates a pencil sketch. We convolve the image with a
4362 % Gaussian operator of the given radius and standard deviation (sigma). For
4363 % reasonable results, radius should be larger than sigma. Use a radius of 0
4364 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4367 % The format of the SketchImage method is:
4369 % Image *SketchImage(const Image *image,const double radius,
4370 % const double sigma,const double angle,ExceptionInfo *exception)
4372 % A description of each parameter follows:
4374 % o image: the image.
4376 % o radius: the radius of the Gaussian, in pixels, not counting the
4379 % o sigma: the standard deviation of the Gaussian, in pixels.
4381 % o angle: apply the effect along this angle.
4383 % o exception: return any errors or warnings in this structure.
4386 MagickExport Image *SketchImage(const Image *image,const double radius,
4387 const double sigma,const double angle,ExceptionInfo *exception)
4404 **restrict random_info;
4412 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4413 MagickTrue,exception);
4414 if (random_image == (Image *) NULL)
4415 return((Image *) NULL);
4417 random_info=AcquireRandomInfoThreadSet();
4418 concurrent=GetRandomSecretKey(random_info[0]) == ~0UL ? MagickTrue :
4420 random_view=AcquireCacheView(random_image);
4421 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4422 #pragma omp parallel for schedule(static,4) shared(status) omp_concurrent(concurrent)
4424 for (y=0; y < (ssize_t) random_image->rows; y++)
4427 id = GetOpenMPThreadId();
4435 if (status == MagickFalse)
4437 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4439 if (q == (Quantum *) NULL)
4444 for (x=0; x < (ssize_t) random_image->columns; x++)
4452 if (GetPixelMask(random_image,q) != 0)
4454 q+=GetPixelChannels(random_image);
4457 value=GetPseudoRandomValue(random_info[id]);
4458 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4466 channel=GetPixelChannelMapChannel(image,i);
4467 traits=GetPixelChannelMapTraits(image,channel);
4468 if (traits == UndefinedPixelTrait)
4470 q[i]=ClampToQuantum(QuantumRange*value);
4472 q+=GetPixelChannels(random_image);
4474 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4477 random_view=DestroyCacheView(random_view);
4478 random_info=DestroyRandomInfoThreadSet(random_info);
4479 if (status == MagickFalse)
4481 random_image=DestroyImage(random_image);
4482 return(random_image);
4484 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4485 random_image=DestroyImage(random_image);
4486 if (blur_image == (Image *) NULL)
4487 return((Image *) NULL);
4488 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
4489 blur_image=DestroyImage(blur_image);
4490 if (dodge_image == (Image *) NULL)
4491 return((Image *) NULL);
4492 (void) NormalizeImage(dodge_image,exception);
4493 (void) NegateImage(dodge_image,MagickFalse,exception);
4494 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
4495 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4496 if (sketch_image == (Image *) NULL)
4498 dodge_image=DestroyImage(dodge_image);
4499 return((Image *) NULL);
4501 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
4502 MagickTrue,0,0,exception);
4503 dodge_image=DestroyImage(dodge_image);
4504 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4505 if (blend_image == (Image *) NULL)
4507 sketch_image=DestroyImage(sketch_image);
4508 return((Image *) NULL);
4510 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4511 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue,
4513 blend_image=DestroyImage(blend_image);
4514 return(sketch_image);
4518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4522 % S o l a r i z e I m a g e %
4526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4528 % SolarizeImage() applies a special effect to the image, similar to the effect
4529 % achieved in a photo darkroom by selectively exposing areas of photo
4530 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4531 % measure of the extent of the solarization.
4533 % The format of the SolarizeImage method is:
4535 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4536 % ExceptionInfo *exception)
4538 % A description of each parameter follows:
4540 % o image: the image.
4542 % o threshold: Define the extent of the solarization.
4544 % o exception: return any errors or warnings in this structure.
4547 MagickExport MagickBooleanType SolarizeImage(Image *image,
4548 const double threshold,ExceptionInfo *exception)
4550 #define SolarizeImageTag "Solarize/Image"
4564 assert(image != (Image *) NULL);
4565 assert(image->signature == MagickSignature);
4566 if (image->debug != MagickFalse)
4567 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4568 if (image->storage_class == PseudoClass)
4576 for (i=0; i < (ssize_t) image->colors; i++)
4578 if ((MagickRealType) image->colormap[i].red > threshold)
4579 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4580 if ((MagickRealType) image->colormap[i].green > threshold)
4581 image->colormap[i].green=(Quantum) QuantumRange-
4582 image->colormap[i].green;
4583 if ((MagickRealType) image->colormap[i].blue > threshold)
4584 image->colormap[i].blue=(Quantum) QuantumRange-
4585 image->colormap[i].blue;
4593 image_view=AcquireCacheView(image);
4594 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4595 #pragma omp parallel for schedule(static,4) shared(progress,status)
4597 for (y=0; y < (ssize_t) image->rows; y++)
4605 if (status == MagickFalse)
4607 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4608 if (q == (Quantum *) NULL)
4613 for (x=0; x < (ssize_t) image->columns; x++)
4618 if (GetPixelMask(image,q) != 0)
4620 q+=GetPixelChannels(image);
4623 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4631 channel=GetPixelChannelMapChannel(image,i);
4632 traits=GetPixelChannelMapTraits(image,channel);
4633 if ((traits == UndefinedPixelTrait) ||
4634 ((traits & CopyPixelTrait) != 0))
4636 if ((MagickRealType) q[i] > threshold)
4637 q[i]=QuantumRange-q[i];
4639 q+=GetPixelChannels(image);
4641 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4643 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4648 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4649 #pragma omp critical (MagickCore_SolarizeImage)
4651 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4652 if (proceed == MagickFalse)
4656 image_view=DestroyCacheView(image_view);
4661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4665 % S t e g a n o I m a g e %
4669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4671 % SteganoImage() hides a digital watermark within the image. Recover
4672 % the hidden watermark later to prove that the authenticity of an image.
4673 % Offset defines the start position within the image to hide the watermark.
4675 % The format of the SteganoImage method is:
4677 % Image *SteganoImage(const Image *image,Image *watermark,
4678 % ExceptionInfo *exception)
4680 % A description of each parameter follows:
4682 % o image: the image.
4684 % o watermark: the watermark image.
4686 % o exception: return any errors or warnings in this structure.
4689 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4690 ExceptionInfo *exception)
4692 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4693 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4694 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4695 #define SteganoImageTag "Stegano/Image"
4730 Initialize steganographic image attributes.
4732 assert(image != (const Image *) NULL);
4733 assert(image->signature == MagickSignature);
4734 if (image->debug != MagickFalse)
4735 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4736 assert(watermark != (const Image *) NULL);
4737 assert(watermark->signature == MagickSignature);
4738 assert(exception != (ExceptionInfo *) NULL);
4739 assert(exception->signature == MagickSignature);
4741 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4742 if (stegano_image == (Image *) NULL)
4743 return((Image *) NULL);
4744 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4745 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4747 stegano_image=DestroyImage(stegano_image);
4748 return((Image *) NULL);
4751 Hide watermark in low-order bits of image.
4756 depth=stegano_image->depth;
4757 k=stegano_image->offset;
4759 watermark_view=AcquireCacheView(watermark);
4760 stegano_view=AcquireCacheView(stegano_image);
4761 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4763 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4765 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4770 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
4772 offset=k/(ssize_t) stegano_image->columns;
4773 if (offset >= (ssize_t) stegano_image->rows)
4775 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4776 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4778 if (q == (Quantum *) NULL)
4784 SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
4785 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
4790 SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
4791 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
4796 SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
4797 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
4801 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4807 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4809 if (k == stegano_image->offset)
4813 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4818 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4820 if (proceed == MagickFalse)
4824 stegano_view=DestroyCacheView(stegano_view);
4825 watermark_view=DestroyCacheView(watermark_view);
4826 if (status == MagickFalse)
4828 stegano_image=DestroyImage(stegano_image);
4829 return((Image *) NULL);
4831 return(stegano_image);
4835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4839 % S t e r e o A n a g l y p h I m a g e %
4843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4845 % StereoAnaglyphImage() combines two images and produces a single image that
4846 % is the composite of a left and right image of a stereo pair. Special
4847 % red-green stereo glasses are required to view this effect.
4849 % The format of the StereoAnaglyphImage method is:
4851 % Image *StereoImage(const Image *left_image,const Image *right_image,
4852 % ExceptionInfo *exception)
4853 % Image *StereoAnaglyphImage(const Image *left_image,
4854 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4855 % ExceptionInfo *exception)
4857 % A description of each parameter follows:
4859 % o left_image: the left image.
4861 % o right_image: the right image.
4863 % o exception: return any errors or warnings in this structure.
4865 % o x_offset: amount, in pixels, by which the left image is offset to the
4866 % right of the right image.
4868 % o y_offset: amount, in pixels, by which the left image is offset to the
4869 % bottom of the right image.
4873 MagickExport Image *StereoImage(const Image *left_image,
4874 const Image *right_image,ExceptionInfo *exception)
4876 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4879 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4880 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4881 ExceptionInfo *exception)
4883 #define StereoImageTag "Stereo/Image"
4897 assert(left_image != (const Image *) NULL);
4898 assert(left_image->signature == MagickSignature);
4899 if (left_image->debug != MagickFalse)
4900 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4901 left_image->filename);
4902 assert(right_image != (const Image *) NULL);
4903 assert(right_image->signature == MagickSignature);
4904 assert(exception != (ExceptionInfo *) NULL);
4905 assert(exception->signature == MagickSignature);
4906 assert(right_image != (const Image *) NULL);
4908 if ((left_image->columns != right_image->columns) ||
4909 (left_image->rows != right_image->rows))
4910 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4912 Initialize stereo image attributes.
4914 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4915 MagickTrue,exception);
4916 if (stereo_image == (Image *) NULL)
4917 return((Image *) NULL);
4918 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4920 stereo_image=DestroyImage(stereo_image);
4921 return((Image *) NULL);
4924 Copy left image to red channel and right image to blue channel.
4927 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4929 register const Quantum
4939 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4941 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4942 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4943 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4944 (r == (Quantum *) NULL))
4946 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4948 SetPixelRed(image,GetPixelRed(left_image,p),r);
4949 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4950 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4951 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4952 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4953 GetPixelAlpha(right_image,q))/2,r);
4954 p+=GetPixelChannels(left_image);
4955 q+=GetPixelChannels(right_image);
4956 r+=GetPixelChannels(stereo_image);
4958 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4960 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4965 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4966 stereo_image->rows);
4967 if (proceed == MagickFalse)
4971 if (status == MagickFalse)
4973 stereo_image=DestroyImage(stereo_image);
4974 return((Image *) NULL);
4976 return(stereo_image);
4980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4984 % S w i r l I m a g e %
4988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4990 % SwirlImage() swirls the pixels about the center of the image, where
4991 % degrees indicates the sweep of the arc through which each pixel is moved.
4992 % You get a more dramatic effect as the degrees move from 1 to 360.
4994 % The format of the SwirlImage method is:
4996 % Image *SwirlImage(const Image *image,double degrees,
4997 % const PixelInterpolateMethod method,ExceptionInfo *exception)
4999 % A description of each parameter follows:
5001 % o image: the image.
5003 % o degrees: Define the tightness of the swirling effect.
5005 % o method: the pixel interpolation method.
5007 % o exception: return any errors or warnings in this structure.
5010 MagickExport Image *SwirlImage(const Image *image,double degrees,
5011 const PixelInterpolateMethod method,ExceptionInfo *exception)
5013 #define SwirlImageTag "Swirl/Image"
5039 Initialize swirl image attributes.
5041 assert(image != (const Image *) NULL);
5042 assert(image->signature == MagickSignature);
5043 if (image->debug != MagickFalse)
5044 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5045 assert(exception != (ExceptionInfo *) NULL);
5046 assert(exception->signature == MagickSignature);
5047 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5048 if (swirl_image == (Image *) NULL)
5049 return((Image *) NULL);
5050 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
5052 swirl_image=DestroyImage(swirl_image);
5053 return((Image *) NULL);
5055 if (swirl_image->background_color.alpha != OpaqueAlpha)
5056 swirl_image->matte=MagickTrue;
5058 Compute scaling factor.
5060 center.x=(double) image->columns/2.0;
5061 center.y=(double) image->rows/2.0;
5062 radius=MagickMax(center.x,center.y);
5065 if (image->columns > image->rows)
5066 scale.y=(double) image->columns/(double) image->rows;
5068 if (image->columns < image->rows)
5069 scale.x=(double) image->rows/(double) image->columns;
5070 degrees=(double) DegreesToRadians(degrees);
5076 image_view=AcquireCacheView(image);
5077 swirl_view=AcquireCacheView(swirl_image);
5078 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5079 #pragma omp parallel for schedule(static,4) shared(progress,status)
5081 for (y=0; y < (ssize_t) image->rows; y++)
5089 register const Quantum
5098 if (status == MagickFalse)
5100 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
5101 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5103 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5108 delta.y=scale.y*(double) (y-center.y);
5109 for (x=0; x < (ssize_t) image->columns; x++)
5112 Determine if the pixel is within an ellipse.
5114 if (GetPixelMask(image,p) != 0)
5116 p+=GetPixelChannels(image);
5117 q+=GetPixelChannels(swirl_image);
5120 delta.x=scale.x*(double) (x-center.x);
5121 distance=delta.x*delta.x+delta.y*delta.y;
5122 if (distance >= (radius*radius))
5127 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5136 channel=GetPixelChannelMapChannel(image,i);
5137 traits=GetPixelChannelMapTraits(image,channel);
5138 swirl_traits=GetPixelChannelMapTraits(swirl_image,channel);
5139 if ((traits == UndefinedPixelTrait) ||
5140 (swirl_traits == UndefinedPixelTrait))
5142 SetPixelChannel(swirl_image,channel,p[i],q);
5155 factor=1.0-sqrt((double) distance)/radius;
5156 sine=sin((double) (degrees*factor*factor));
5157 cosine=cos((double) (degrees*factor*factor));
5158 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5159 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5160 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
5162 p+=GetPixelChannels(image);
5163 q+=GetPixelChannels(swirl_image);
5165 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5167 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5172 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5173 #pragma omp critical (MagickCore_SwirlImage)
5175 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5176 if (proceed == MagickFalse)
5180 swirl_view=DestroyCacheView(swirl_view);
5181 image_view=DestroyCacheView(image_view);
5182 if (status == MagickFalse)
5183 swirl_image=DestroyImage(swirl_image);
5184 return(swirl_image);
5188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5192 % T i n t I m a g e %
5196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5198 % TintImage() applies a color vector to each pixel in the image. The length
5199 % of the vector is 0 for black and white and at its maximum for the midtones.
5200 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5202 % The format of the TintImage method is:
5204 % Image *TintImage(const Image *image,const char *blend,
5205 % const PixelInfo *tint,ExceptionInfo *exception)
5207 % A description of each parameter follows:
5209 % o image: the image.
5211 % o blend: A color value used for tinting.
5213 % o tint: A color value used for tinting.
5215 % o exception: return any errors or warnings in this structure.
5218 MagickExport Image *TintImage(const Image *image,const char *blend,
5219 const PixelInfo *tint,ExceptionInfo *exception)
5221 #define TintImageTag "Tint/Image"
5252 Allocate tint image.
5254 assert(image != (const Image *) NULL);
5255 assert(image->signature == MagickSignature);
5256 if (image->debug != MagickFalse)
5257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5258 assert(exception != (ExceptionInfo *) NULL);
5259 assert(exception->signature == MagickSignature);
5260 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5261 if (tint_image == (Image *) NULL)
5262 return((Image *) NULL);
5263 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5265 tint_image=DestroyImage(tint_image);
5266 return((Image *) NULL);
5268 if (blend == (const char *) NULL)
5271 Determine RGB values of the color.
5273 GetPixelInfo(image,&color_vector);
5274 flags=ParseGeometry(blend,&geometry_info);
5275 color_vector.red=geometry_info.rho;
5276 color_vector.green=geometry_info.rho;
5277 color_vector.blue=geometry_info.rho;
5278 color_vector.alpha=OpaqueAlpha;
5279 if ((flags & SigmaValue) != 0)
5280 color_vector.green=geometry_info.sigma;
5281 if ((flags & XiValue) != 0)
5282 color_vector.blue=geometry_info.xi;
5283 if ((flags & PsiValue) != 0)
5284 color_vector.alpha=geometry_info.psi;
5285 if (image->colorspace == CMYKColorspace)
5287 color_vector.black=geometry_info.rho;
5288 if ((flags & PsiValue) != 0)
5289 color_vector.black=geometry_info.psi;
5290 if ((flags & ChiValue) != 0)
5291 color_vector.alpha=geometry_info.chi;
5293 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5294 color_vector.red=(MagickRealType) (color_vector.red*tint->red/100.0-
5296 color_vector.green=(MagickRealType) (color_vector.green*tint->green/100.0-
5298 color_vector.blue=(MagickRealType) (color_vector.blue*tint->blue/100.0-
5300 color_vector.black=(MagickRealType) (color_vector.black*tint->black/100.0-
5302 color_vector.alpha=(MagickRealType) (color_vector.alpha*tint->alpha/100.0-
5309 image_view=AcquireCacheView(image);
5310 tint_view=AcquireCacheView(tint_image);
5311 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5312 #pragma omp parallel for schedule(static,4) shared(progress,status)
5314 for (y=0; y < (ssize_t) image->rows; y++)
5316 register const Quantum
5325 if (status == MagickFalse)
5327 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5328 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5330 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5335 for (x=0; x < (ssize_t) image->columns; x++)
5346 if (GetPixelMask(image,p) != 0)
5348 p+=GetPixelChannels(image);
5349 q+=GetPixelChannels(tint_image);
5352 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5361 channel=GetPixelChannelMapChannel(image,i);
5362 traits=GetPixelChannelMapTraits(image,channel);
5363 tint_traits=GetPixelChannelMapTraits(tint_image,channel);
5364 if ((traits == UndefinedPixelTrait) ||
5365 (tint_traits == UndefinedPixelTrait))
5367 if ((tint_traits & CopyPixelTrait) != 0)
5369 SetPixelChannel(tint_image,channel,p[i],q);
5373 GetPixelInfo(image,&pixel);
5374 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5375 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5376 (1.0-(4.0*(weight*weight)));
5377 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5378 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5379 (1.0-(4.0*(weight*weight)));
5380 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5381 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5382 (1.0-(4.0*(weight*weight)));
5383 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5384 pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black*
5385 (1.0-(4.0*(weight*weight)));
5386 SetPixelInfoPixel(tint_image,&pixel,q);
5387 p+=GetPixelChannels(image);
5388 q+=GetPixelChannels(tint_image);
5390 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5392 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5397 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5398 #pragma omp critical (MagickCore_TintImage)
5400 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5401 if (proceed == MagickFalse)
5405 tint_view=DestroyCacheView(tint_view);
5406 image_view=DestroyCacheView(image_view);
5407 if (status == MagickFalse)
5408 tint_image=DestroyImage(tint_image);
5413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5417 % V i g n e t t e I m a g e %
5421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5423 % VignetteImage() softens the edges of the image in vignette style.
5425 % The format of the VignetteImage method is:
5427 % Image *VignetteImage(const Image *image,const double radius,
5428 % const double sigma,const ssize_t x,const ssize_t y,
5429 % ExceptionInfo *exception)
5431 % A description of each parameter follows:
5433 % o image: the image.
5435 % o radius: the radius of the pixel neighborhood.
5437 % o sigma: the standard deviation of the Gaussian, in pixels.
5439 % o x, y: Define the x and y ellipse offset.
5441 % o exception: return any errors or warnings in this structure.
5444 MagickExport Image *VignetteImage(const Image *image,const double radius,
5445 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5448 ellipse[MaxTextExtent];
5459 assert(image != (Image *) NULL);
5460 assert(image->signature == MagickSignature);
5461 if (image->debug != MagickFalse)
5462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5463 assert(exception != (ExceptionInfo *) NULL);
5464 assert(exception->signature == MagickSignature);
5465 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5466 if (canvas_image == (Image *) NULL)
5467 return((Image *) NULL);
5468 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5470 canvas_image=DestroyImage(canvas_image);
5471 return((Image *) NULL);
5473 canvas_image->matte=MagickTrue;
5474 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5475 MagickTrue,exception);
5476 if (oval_image == (Image *) NULL)
5478 canvas_image=DestroyImage(canvas_image);
5479 return((Image *) NULL);
5481 (void) QueryColorCompliance("#000000",AllCompliance,
5482 &oval_image->background_color,exception);
5483 (void) SetImageBackgroundColor(oval_image,exception);
5484 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5485 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5487 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5489 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5490 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5492 draw_info->primitive=AcquireString(ellipse);
5493 (void) DrawImage(oval_image,draw_info,exception);
5494 draw_info=DestroyDrawInfo(draw_info);
5495 blur_image=BlurImage(oval_image,radius,sigma,exception);
5496 oval_image=DestroyImage(oval_image);
5497 if (blur_image == (Image *) NULL)
5499 canvas_image=DestroyImage(canvas_image);
5500 return((Image *) NULL);
5502 blur_image->matte=MagickFalse;
5503 (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue,
5505 blur_image=DestroyImage(blur_image);
5506 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5507 canvas_image=DestroyImage(canvas_image);
5508 return(vignette_image);
5512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5516 % W a v e I m a g e %
5520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5522 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5523 % vertically along a sine wave whose amplitude and wavelength is specified
5524 % by the given parameters.
5526 % The format of the WaveImage method is:
5528 % Image *WaveImage(const Image *image,const double amplitude,
5529 % const double wave_length,const PixelInterpolateMethod method,
5530 % ExceptionInfo *exception)
5532 % A description of each parameter follows:
5534 % o image: the image.
5536 % o amplitude, wave_length: Define the amplitude and wave length of the
5539 % o interpolate: the pixel interpolation method.
5541 % o exception: return any errors or warnings in this structure.
5544 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5545 const double wave_length,const PixelInterpolateMethod method,
5546 ExceptionInfo *exception)
5548 #define WaveImageTag "Wave/Image"
5573 Initialize wave image attributes.
5575 assert(image != (Image *) NULL);
5576 assert(image->signature == MagickSignature);
5577 if (image->debug != MagickFalse)
5578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5579 assert(exception != (ExceptionInfo *) NULL);
5580 assert(exception->signature == MagickSignature);
5581 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5582 fabs(amplitude)),MagickTrue,exception);
5583 if (wave_image == (Image *) NULL)
5584 return((Image *) NULL);
5585 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5587 wave_image=DestroyImage(wave_image);
5588 return((Image *) NULL);
5590 if (wave_image->background_color.alpha != OpaqueAlpha)
5591 wave_image->matte=MagickTrue;
5595 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5597 if (sine_map == (MagickRealType *) NULL)
5599 wave_image=DestroyImage(wave_image);
5600 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5602 for (i=0; i < (ssize_t) wave_image->columns; i++)
5603 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5610 image_view=AcquireCacheView(image);
5611 wave_view=AcquireCacheView(wave_image);
5612 (void) SetCacheViewVirtualPixelMethod(image_view,
5613 BackgroundVirtualPixelMethod);
5614 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5615 #pragma omp parallel for schedule(static,4) shared(progress,status)
5617 for (y=0; y < (ssize_t) wave_image->rows; y++)
5625 if (status == MagickFalse)
5627 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5629 if (q == (Quantum *) NULL)
5634 for (x=0; x < (ssize_t) wave_image->columns; x++)
5636 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5637 (double) x,(double) (y-sine_map[x]),q,exception);
5638 q+=GetPixelChannels(wave_image);
5640 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5642 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5647 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5648 #pragma omp critical (MagickCore_WaveImage)
5650 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5651 if (proceed == MagickFalse)
5655 wave_view=DestroyCacheView(wave_view);
5656 image_view=DestroyCacheView(image_view);
5657 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5658 if (status == MagickFalse)
5659 wave_image=DestroyImage(wave_image);