2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/annotate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/cache-view.h"
49 #include "MagickCore/color.h"
50 #include "MagickCore/color-private.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/decorate.h"
53 #include "MagickCore/draw.h"
54 #include "MagickCore/effect.h"
55 #include "MagickCore/enhance.h"
56 #include "MagickCore/exception.h"
57 #include "MagickCore/exception-private.h"
58 #include "MagickCore/fx.h"
59 #include "MagickCore/fx-private.h"
60 #include "MagickCore/gem.h"
61 #include "MagickCore/geometry.h"
62 #include "MagickCore/layer.h"
63 #include "MagickCore/list.h"
64 #include "MagickCore/log.h"
65 #include "MagickCore/image.h"
66 #include "MagickCore/image-private.h"
67 #include "MagickCore/magick.h"
68 #include "MagickCore/memory_.h"
69 #include "MagickCore/monitor.h"
70 #include "MagickCore/monitor-private.h"
71 #include "MagickCore/option.h"
72 #include "MagickCore/pixel.h"
73 #include "MagickCore/pixel-accessor.h"
74 #include "MagickCore/property.h"
75 #include "MagickCore/quantum.h"
76 #include "MagickCore/quantum-private.h"
77 #include "MagickCore/random_.h"
78 #include "MagickCore/random-private.h"
79 #include "MagickCore/resample.h"
80 #include "MagickCore/resample-private.h"
81 #include "MagickCore/resize.h"
82 #include "MagickCore/shear.h"
83 #include "MagickCore/splay-tree.h"
84 #include "MagickCore/statistic.h"
85 #include "MagickCore/string_.h"
86 #include "MagickCore/string-private.h"
87 #include "MagickCore/thread-private.h"
88 #include "MagickCore/transform.h"
89 #include "MagickCore/utility.h"
94 #define LeftShiftOperator 0xf5
95 #define RightShiftOperator 0xf6
96 #define LessThanEqualOperator 0xf7
97 #define GreaterThanEqualOperator 0xf8
98 #define EqualOperator 0xf9
99 #define NotEqualOperator 0xfa
100 #define LogicalAndOperator 0xfb
101 #define LogicalOrOperator 0xfc
102 #define ExponentialNotation 0xfd
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 + A c q u i r e F x I n f o %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % AcquireFxInfo() allocates the FxInfo structure.
142 % The format of the AcquireFxInfo method is:
144 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
146 % A description of each parameter follows:
148 % o image: the image.
150 % o expression: the expression.
153 MagickExport FxInfo *AcquireFxInfo(const Image *image,const char *expression)
167 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
168 if (fx_info == (FxInfo *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
171 fx_info->exception=AcquireExceptionInfo();
172 fx_info->images=image;
173 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
174 RelinquishMagickMemory);
175 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
176 RelinquishMagickMemory);
177 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
178 fx_info->images),sizeof(*fx_info->view));
179 if (fx_info->view == (CacheView **) NULL)
180 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
182 next=GetFirstImageInList(fx_info->images);
183 for ( ; next != (Image *) NULL; next=next->next)
185 fx_info->view[i]=AcquireCacheView(next);
188 fx_info->random_info=AcquireRandomInfo();
189 fx_info->expression=ConstantString(expression);
190 fx_info->file=stderr;
191 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
193 Force right-to-left associativity for unary negation.
195 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
196 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
197 (strstr(fx_info->expression,"e-") != (char *) NULL))
200 Convert scientific notation.
202 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
203 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
204 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
205 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
206 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
207 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
208 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
209 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
210 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
211 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
212 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
213 (void) SubstituteString(&fx_info->expression,"1e-1.0*","1**10^-");
214 (void) SubstituteString(&fx_info->expression,"2e-1.0*","2**10^-");
215 (void) SubstituteString(&fx_info->expression,"3e-1.0*","3**10^-");
216 (void) SubstituteString(&fx_info->expression,"4e-1.0*","4**10^-");
217 (void) SubstituteString(&fx_info->expression,"5e-1.0*","5**10^-");
218 (void) SubstituteString(&fx_info->expression,"6e-1.0*","6**10^-");
219 (void) SubstituteString(&fx_info->expression,"7e-1.0*","7**10^-");
220 (void) SubstituteString(&fx_info->expression,"8e-1.0*","8**10^-");
221 (void) SubstituteString(&fx_info->expression,"9e-1.0*","9**10^-");
223 if ((strstr(fx_info->expression,"E+") != (char *) NULL) ||
224 (strstr(fx_info->expression,"E-") != (char *) NULL))
227 Convert scientific notation.
229 (void) SubstituteString(&fx_info->expression,"0E+","0**10^");
230 (void) SubstituteString(&fx_info->expression,"1E+","1**10^");
231 (void) SubstituteString(&fx_info->expression,"2E+","2**10^");
232 (void) SubstituteString(&fx_info->expression,"3E+","3**10^");
233 (void) SubstituteString(&fx_info->expression,"4E+","4**10^");
234 (void) SubstituteString(&fx_info->expression,"5E+","5**10^");
235 (void) SubstituteString(&fx_info->expression,"6E+","6**10^");
236 (void) SubstituteString(&fx_info->expression,"7E+","7**10^");
237 (void) SubstituteString(&fx_info->expression,"8E+","8**10^");
238 (void) SubstituteString(&fx_info->expression,"9E+","9**10^");
239 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
240 (void) SubstituteString(&fx_info->expression,"1E-1.0*","1**10^-");
241 (void) SubstituteString(&fx_info->expression,"2E-1.0*","2**10^-");
242 (void) SubstituteString(&fx_info->expression,"3E-1.0*","3**10^-");
243 (void) SubstituteString(&fx_info->expression,"4E-1.0*","4**10^-");
244 (void) SubstituteString(&fx_info->expression,"5E-1.0*","5**10^-");
245 (void) SubstituteString(&fx_info->expression,"6E-1.0*","6**10^-");
246 (void) SubstituteString(&fx_info->expression,"7E-1.0*","7**10^-");
247 (void) SubstituteString(&fx_info->expression,"8E-1.0*","8**10^-");
248 (void) SubstituteString(&fx_info->expression,"9E-1.0*","9**10^-");
251 Convert complex to simple operators.
254 *fx_op=(char) LeftShiftOperator;
255 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
256 *fx_op=(char) RightShiftOperator;
257 (void) SubstituteString(&fx_info->expression,">>",fx_op);
258 *fx_op=(char) LessThanEqualOperator;
259 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
260 *fx_op=(char) GreaterThanEqualOperator;
261 (void) SubstituteString(&fx_info->expression,">=",fx_op);
262 *fx_op=(char) EqualOperator;
263 (void) SubstituteString(&fx_info->expression,"==",fx_op);
264 *fx_op=(char) NotEqualOperator;
265 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
266 *fx_op=(char) LogicalAndOperator;
267 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
268 *fx_op=(char) LogicalOrOperator;
269 (void) SubstituteString(&fx_info->expression,"||",fx_op);
270 *fx_op=(char) ExponentialNotation;
271 (void) SubstituteString(&fx_info->expression,"**",fx_op);
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % A d d N o i s e I m a g e %
284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 % AddNoiseImage() adds random noise to the image.
288 % The format of the AddNoiseImage method is:
290 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
291 % ExceptionInfo *exception)
293 % A description of each parameter follows:
295 % o image: the image.
297 % o channel: the channel type.
299 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
300 % Impulse, Laplacian, or Poisson.
302 % o exception: return any errors or warnings in this structure.
305 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, ExceptionInfo *exception)
307 #define AddNoiseImageTag "AddNoise/Image"
329 **restrict random_info;
335 Initialize noise image attributes.
337 assert(image != (const Image *) NULL);
338 assert(image->signature == MagickSignature);
339 if (image->debug != MagickFalse)
340 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
341 assert(exception != (ExceptionInfo *) NULL);
342 assert(exception->signature == MagickSignature);
343 noise_image=CloneImage(image,0,0,MagickTrue,exception);
344 if (noise_image == (Image *) NULL)
345 return((Image *) NULL);
346 if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
348 InheritException(exception,&noise_image->exception);
349 noise_image=DestroyImage(noise_image);
350 return((Image *) NULL);
353 Add noise in each row.
356 option=GetImageArtifact(image,"attenuate");
357 if (option != (char *) NULL)
358 attenuate=InterpretLocaleValue(option,(char **) NULL);
361 random_info=AcquireRandomInfoThreadSet();
362 image_view=AcquireCacheView(image);
363 noise_view=AcquireCacheView(noise_image);
364 #if defined(MAGICKCORE_OPENMP_SUPPORT)
365 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
367 for (y=0; y < (ssize_t) image->rows; y++)
370 id = GetOpenMPThreadId();
375 register const Quantum
384 if (status == MagickFalse)
386 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
387 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
389 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
394 for (x=0; x < (ssize_t) image->columns; x++)
396 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
397 SetPixelRed(noise_image,ClampToQuantum(GenerateDifferentialNoise(
398 random_info[id],GetPixelRed(image,p),noise_type,attenuate)),q);
399 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
400 SetPixelGreen(noise_image,ClampToQuantum(GenerateDifferentialNoise(
401 random_info[id],GetPixelGreen(image,p),noise_type,attenuate)),q);
402 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
403 SetPixelBlue(noise_image,ClampToQuantum(GenerateDifferentialNoise(
404 random_info[id],GetPixelBlue(image,p),noise_type,attenuate)),q);
405 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
406 (image->colorspace == CMYKColorspace))
407 SetPixelBlack(noise_image,ClampToQuantum(GenerateDifferentialNoise(
408 random_info[id],GetPixelBlack(image,p),noise_type,attenuate)),q);
409 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
410 SetPixelAlpha(noise_image,ClampToQuantum(GenerateDifferentialNoise(
411 random_info[id],GetPixelAlpha(image,p),noise_type,attenuate)),q);
412 p+=GetPixelChannels(image);
413 q+=GetPixelChannels(noise_image);
415 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
416 if (sync == MagickFalse)
418 if (image->progress_monitor != (MagickProgressMonitor) NULL)
423 #if defined(MAGICKCORE_OPENMP_SUPPORT)
424 #pragma omp critical (MagickCore_AddNoiseImage)
426 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
428 if (proceed == MagickFalse)
432 noise_view=DestroyCacheView(noise_view);
433 image_view=DestroyCacheView(image_view);
434 random_info=DestroyRandomInfoThreadSet(random_info);
435 if (status == MagickFalse)
436 noise_image=DestroyImage(noise_image);
441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
445 % B l u e S h i f t I m a g e %
449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451 % BlueShiftImage() mutes the colors of the image to simulate a scene at
452 % nighttime in the moonlight.
454 % The format of the BlueShiftImage method is:
456 % Image *BlueShiftImage(const Image *image,const double factor,
457 % ExceptionInfo *exception)
459 % A description of each parameter follows:
461 % o image: the image.
463 % o factor: the shift factor.
465 % o exception: return any errors or warnings in this structure.
468 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
469 ExceptionInfo *exception)
471 #define BlueShiftImageTag "BlueShift/Image"
490 Allocate blue shift image.
492 assert(image != (const Image *) NULL);
493 assert(image->signature == MagickSignature);
494 if (image->debug != MagickFalse)
495 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
496 assert(exception != (ExceptionInfo *) NULL);
497 assert(exception->signature == MagickSignature);
498 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
500 if (shift_image == (Image *) NULL)
501 return((Image *) NULL);
502 if (SetImageStorageClass(shift_image,DirectClass) == MagickFalse)
504 InheritException(exception,&shift_image->exception);
505 shift_image=DestroyImage(shift_image);
506 return((Image *) NULL);
509 Blue-shift DirectClass image.
513 image_view=AcquireCacheView(image);
514 shift_view=AcquireCacheView(shift_image);
515 #if defined(MAGICKCORE_OPENMP_SUPPORT)
516 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
518 for (y=0; y < (ssize_t) image->rows; y++)
529 register const Quantum
538 if (status == MagickFalse)
540 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
541 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
543 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
548 for (x=0; x < (ssize_t) image->columns; x++)
550 quantum=GetPixelRed(image,p);
551 if (GetPixelGreen(image,p) < quantum)
552 quantum=GetPixelGreen(image,p);
553 if (GetPixelBlue(image,p) < quantum)
554 quantum=GetPixelBlue(image,p);
555 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
556 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
557 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
558 quantum=GetPixelRed(image,p);
559 if (GetPixelGreen(image,p) > quantum)
560 quantum=GetPixelGreen(image,p);
561 if (GetPixelBlue(image,p) > quantum)
562 quantum=GetPixelBlue(image,p);
563 pixel.red=0.5*(pixel.red+factor*quantum);
564 pixel.green=0.5*(pixel.green+factor*quantum);
565 pixel.blue=0.5*(pixel.blue+factor*quantum);
566 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
567 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
568 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
569 p+=GetPixelChannels(image);
570 q+=GetPixelChannels(shift_image);
572 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
573 if (sync == MagickFalse)
575 if (image->progress_monitor != (MagickProgressMonitor) NULL)
580 #if defined(MAGICKCORE_OPENMP_SUPPORT)
581 #pragma omp critical (MagickCore_BlueShiftImage)
583 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
585 if (proceed == MagickFalse)
589 image_view=DestroyCacheView(image_view);
590 shift_view=DestroyCacheView(shift_view);
591 if (status == MagickFalse)
592 shift_image=DestroyImage(shift_image);
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % C h a r c o a l I m a g e %
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607 % CharcoalImage() creates a new image that is a copy of an existing one with
608 % the edge highlighted. It allocates the memory necessary for the new Image
609 % structure and returns a pointer to the new image.
611 % The format of the CharcoalImage method is:
613 % Image *CharcoalImage(const Image *image,const double radius,
614 % const double sigma,ExceptionInfo *exception)
616 % A description of each parameter follows:
618 % o image: the image.
620 % o radius: the radius of the pixel neighborhood.
622 % o sigma: the standard deviation of the Gaussian, in pixels.
624 % o exception: return any errors or warnings in this structure.
627 MagickExport Image *CharcoalImage(const Image *image,const double radius,
628 const double sigma,ExceptionInfo *exception)
635 assert(image != (Image *) NULL);
636 assert(image->signature == MagickSignature);
637 if (image->debug != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
639 assert(exception != (ExceptionInfo *) NULL);
640 assert(exception->signature == MagickSignature);
641 clone_image=CloneImage(image,0,0,MagickTrue,exception);
642 if (clone_image == (Image *) NULL)
643 return((Image *) NULL);
644 (void) SetImageType(clone_image,GrayscaleType);
645 edge_image=EdgeImage(clone_image,radius,exception);
646 clone_image=DestroyImage(clone_image);
647 if (edge_image == (Image *) NULL)
648 return((Image *) NULL);
649 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
650 edge_image=DestroyImage(edge_image);
651 if (charcoal_image == (Image *) NULL)
652 return((Image *) NULL);
653 (void) NormalizeImage(charcoal_image);
654 (void) NegateImage(charcoal_image,MagickFalse,exception);
655 (void) SetImageType(charcoal_image,GrayscaleType);
656 return(charcoal_image);
660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 % C o l o r i z e I m a g e %
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 % ColorizeImage() blends the fill color with each pixel in the image.
671 % A percentage blend is specified with opacity. Control the application
672 % of different color components by specifying a different percentage for
673 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
675 % The format of the ColorizeImage method is:
677 % Image *ColorizeImage(const Image *image,const char *opacity,
678 % const PixelPacket colorize,ExceptionInfo *exception)
680 % A description of each parameter follows:
682 % o image: the image.
684 % o opacity: A character string indicating the level of opacity as a
687 % o colorize: A color value.
689 % o exception: return any errors or warnings in this structure.
692 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
693 const PixelPacket colorize,ExceptionInfo *exception)
695 #define ColorizeImageTag "Colorize/Image"
723 Allocate colorized image.
725 assert(image != (const Image *) NULL);
726 assert(image->signature == MagickSignature);
727 if (image->debug != MagickFalse)
728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
729 assert(exception != (ExceptionInfo *) NULL);
730 assert(exception->signature == MagickSignature);
731 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
733 if (colorize_image == (Image *) NULL)
734 return((Image *) NULL);
735 if (SetImageStorageClass(colorize_image,DirectClass) == MagickFalse)
737 InheritException(exception,&colorize_image->exception);
738 colorize_image=DestroyImage(colorize_image);
739 return((Image *) NULL);
741 if (opacity == (const char *) NULL)
742 return(colorize_image);
744 Determine RGB values of the pen color.
746 flags=ParseGeometry(opacity,&geometry_info);
747 pixel.red=geometry_info.rho;
748 pixel.green=geometry_info.rho;
749 pixel.blue=geometry_info.rho;
750 pixel.alpha=(MagickRealType) OpaqueAlpha;
751 if ((flags & SigmaValue) != 0)
752 pixel.green=geometry_info.sigma;
753 if ((flags & XiValue) != 0)
754 pixel.blue=geometry_info.xi;
755 if ((flags & PsiValue) != 0)
756 pixel.alpha=geometry_info.psi;
758 Colorize DirectClass image.
762 image_view=AcquireCacheView(image);
763 colorize_view=AcquireCacheView(colorize_image);
764 #if defined(MAGICKCORE_OPENMP_SUPPORT)
765 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
767 for (y=0; y < (ssize_t) image->rows; y++)
772 register const Quantum
781 if (status == MagickFalse)
783 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
784 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
786 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
791 for (x=0; x < (ssize_t) image->columns; x++)
793 SetPixelRed(colorize_image,ClampToQuantum((GetPixelRed(image,p)*
794 (100.0-pixel.red)+colorize.red*pixel.red)/100.0),q);
795 SetPixelGreen(colorize_image,ClampToQuantum((GetPixelGreen(image,p)*
796 (100.0-pixel.green)+colorize.green*pixel.green)/100.0),q);
797 SetPixelBlue(colorize_image,ClampToQuantum((GetPixelBlue(image,p)*
798 (100.0-pixel.blue)+colorize.blue*pixel.blue)/100.0),q);
799 SetPixelAlpha(colorize_image,ClampToQuantum((GetPixelAlpha(image,p)*
800 (100.0-pixel.alpha)+colorize.alpha*pixel.alpha)/100.0),q);
801 p+=GetPixelChannels(image);
802 q+=GetPixelChannels(colorize_image);
804 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
805 if (sync == MagickFalse)
807 if (image->progress_monitor != (MagickProgressMonitor) NULL)
812 #if defined(MAGICKCORE_OPENMP_SUPPORT)
813 #pragma omp critical (MagickCore_ColorizeImage)
815 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
816 if (proceed == MagickFalse)
820 image_view=DestroyCacheView(image_view);
821 colorize_view=DestroyCacheView(colorize_view);
822 if (status == MagickFalse)
823 colorize_image=DestroyImage(colorize_image);
824 return(colorize_image);
828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
832 % C o l o r M a t r i x I m a g e %
836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838 % ColorMatrixImage() applies color transformation to an image. This method
839 % permits saturation changes, hue rotation, luminance to alpha, and various
840 % other effects. Although variable-sized transformation matrices can be used,
841 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
842 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
843 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
844 % and offsets are normalized (divide Flash offset by 255).
846 % The format of the ColorMatrixImage method is:
848 % Image *ColorMatrixImage(const Image *image,
849 % const KernelInfo *color_matrix,ExceptionInfo *exception)
851 % A description of each parameter follows:
853 % o image: the image.
855 % o color_matrix: the color matrix.
857 % o exception: return any errors or warnings in this structure.
860 MagickExport Image *ColorMatrixImage(const Image *image,
861 const KernelInfo *color_matrix,ExceptionInfo *exception)
863 #define ColorMatrixImageTag "ColorMatrix/Image"
872 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
873 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
874 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
875 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
876 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
877 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
900 assert(image != (Image *) NULL);
901 assert(image->signature == MagickSignature);
902 if (image->debug != MagickFalse)
903 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
904 assert(exception != (ExceptionInfo *) NULL);
905 assert(exception->signature == MagickSignature);
907 for (v=0; v < (ssize_t) color_matrix->height; v++)
908 for (u=0; u < (ssize_t) color_matrix->width; u++)
910 if ((v < 6) && (u < 6))
911 ColorMatrix[v][u]=color_matrix->values[i];
915 Initialize color image.
917 color_image=CloneImage(image,0,0,MagickTrue,exception);
918 if (color_image == (Image *) NULL)
919 return((Image *) NULL);
920 if (SetImageStorageClass(color_image,DirectClass) == MagickFalse)
922 InheritException(exception,&color_image->exception);
923 color_image=DestroyImage(color_image);
924 return((Image *) NULL);
926 if (image->debug != MagickFalse)
929 format[MaxTextExtent],
932 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
933 " ColorMatrix image with color matrix:");
934 message=AcquireString("");
935 for (v=0; v < 6; v++)
938 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
939 (void) ConcatenateString(&message,format);
940 for (u=0; u < 6; u++)
942 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
944 (void) ConcatenateString(&message,format);
946 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
948 message=DestroyString(message);
955 image_view=AcquireCacheView(image);
956 color_view=AcquireCacheView(color_image);
957 #if defined(MAGICKCORE_OPENMP_SUPPORT)
958 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
960 for (y=0; y < (ssize_t) image->rows; y++)
965 register const Quantum
974 if (status == MagickFalse)
976 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
977 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
979 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
984 for (x=0; x < (ssize_t) image->columns; x++)
992 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
993 for (v=0; v < (ssize_t) height; v++)
995 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
996 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
997 if (image->colorspace == CMYKColorspace)
998 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
999 if (image->matte != MagickFalse)
1000 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1001 pixel+=QuantumRange*ColorMatrix[v][5];
1004 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1005 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1006 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
1009 if (image->colorspace == CMYKColorspace)
1010 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
1015 if (image->matte != MagickFalse)
1016 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
1021 p+=GetPixelChannels(image);
1022 q+=GetPixelChannels(color_image);
1024 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1026 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1031 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1032 #pragma omp critical (MagickCore_ColorMatrixImage)
1034 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1036 if (proceed == MagickFalse)
1040 color_view=DestroyCacheView(color_view);
1041 image_view=DestroyCacheView(image_view);
1042 if (status == MagickFalse)
1043 color_image=DestroyImage(color_image);
1044 return(color_image);
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1052 + D e s t r o y F x I n f o %
1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1060 % The format of the DestroyFxInfo method is:
1062 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1064 % A description of each parameter follows:
1066 % o fx_info: the fx info.
1069 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1074 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1075 fx_info->expression=DestroyString(fx_info->expression);
1076 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1077 fx_info->colors=DestroySplayTree(fx_info->colors);
1078 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1079 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1080 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1081 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1082 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091 + 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 %
1095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097 % FxEvaluateChannelExpression() evaluates an expression and returns the
1100 % The format of the FxEvaluateExpression method is:
1102 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1103 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1104 % MagickRealType *alpha,Exceptioninfo *exception)
1105 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1106 % MagickRealType *alpha,Exceptioninfo *exception)
1108 % A description of each parameter follows:
1110 % o fx_info: the fx info.
1112 % o channel: the channel.
1114 % o x,y: the pixel position.
1116 % o alpha: the result.
1118 % o exception: return any errors or warnings in this structure.
1122 static inline double MagickMax(const double x,const double y)
1129 static inline double MagickMin(const double x,const double y)
1136 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1137 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1141 statistic[MaxTextExtent];
1149 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1151 switch (*++p) /* e.g. depth.r */
1153 case 'r': channel=RedChannel; break;
1154 case 'g': channel=GreenChannel; break;
1155 case 'b': channel=BlueChannel; break;
1156 case 'c': channel=CyanChannel; break;
1157 case 'm': channel=MagentaChannel; break;
1158 case 'y': channel=YellowChannel; break;
1159 case 'k': channel=BlackChannel; break;
1162 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1163 (double) channel,symbol);
1164 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1165 if (value != (const char *) NULL)
1166 return(QuantumScale*InterpretLocaleValue(value,(char **) NULL));
1167 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1168 if (LocaleNCompare(symbol,"depth",5) == 0)
1173 depth=GetImageDepth(image,exception);
1174 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1176 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1182 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1183 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1185 if (LocaleNCompare(symbol,"maxima",6) == 0)
1191 (void) GetImageRange(image,&minima,&maxima,exception);
1192 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1194 if (LocaleNCompare(symbol,"mean",4) == 0)
1200 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1201 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1203 if (LocaleNCompare(symbol,"minima",6) == 0)
1209 (void) GetImageRange(image,&minima,&maxima,exception);
1210 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1212 if (LocaleNCompare(symbol,"skewness",8) == 0)
1218 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1219 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1221 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1227 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1228 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1229 standard_deviation);
1231 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1232 ConstantString(statistic));
1233 return(QuantumScale*InterpretLocaleValue(statistic,(char **) NULL));
1236 static MagickRealType
1237 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1238 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1240 static inline MagickRealType FxMax(FxInfo *fx_info,const PixelChannel channel,
1241 const ssize_t x,const ssize_t y,const char *expression,
1242 ExceptionInfo *exception)
1248 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1249 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1252 static inline MagickRealType FxMin(FxInfo *fx_info,PixelChannel channel,
1253 const ssize_t x,const ssize_t y,const char *expression,
1254 ExceptionInfo *exception)
1260 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1261 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1264 static inline const char *FxSubexpression(const char *expression,
1265 ExceptionInfo *exception)
1274 subexpression=expression;
1275 while ((*subexpression != '\0') &&
1276 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1278 if (strchr("(",(int) *subexpression) != (char *) NULL)
1281 if (strchr(")",(int) *subexpression) != (char *) NULL)
1285 if (*subexpression == '\0')
1286 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1287 "UnbalancedParenthesis","`%s'",expression);
1288 return(subexpression);
1291 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1292 const ssize_t x,const ssize_t y,const char *expression,
1293 ExceptionInfo *exception)
1297 subexpression[MaxTextExtent],
1298 symbol[MaxTextExtent];
1327 i=GetImageIndexInList(fx_info->images);
1331 if (isalpha((int) *(p+1)) == 0)
1333 if (strchr("suv",(int) *p) != (char *) NULL)
1340 i=GetImageIndexInList(fx_info->images);
1343 case 'u': i=0; break;
1344 case 'v': i=1; break;
1351 for (p++; *p != '\0'; )
1365 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1367 i=(ssize_t) (alpha+0.5);
1373 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1380 for (p++; *p != '\0'; )
1394 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1405 for (p++; *p != '\0'; )
1419 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1429 length=GetImageListLength(fx_info->images);
1431 i+=(ssize_t) length;
1433 image=GetImageFromList(fx_info->images,i);
1434 if (image == (Image *) NULL)
1436 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1437 "NoSuchImage","`%s'",expression);
1440 GetPixelInfo(image,&pixel);
1441 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1442 point.x,point.y,&pixel,exception);
1443 if ((strlen(p) > 2) &&
1444 (LocaleCompare(p,"intensity") != 0) &&
1445 (LocaleCompare(p,"luminance") != 0) &&
1446 (LocaleCompare(p,"hue") != 0) &&
1447 (LocaleCompare(p,"saturation") != 0) &&
1448 (LocaleCompare(p,"lightness") != 0))
1451 name[MaxTextExtent];
1453 (void) CopyMagickString(name,p,MaxTextExtent);
1454 for (q=name+(strlen(name)-1); q > name; q--)
1464 if ((strlen(name) > 2) &&
1465 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1470 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1471 if (color != (PixelInfo *) NULL)
1477 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1479 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1480 ClonePixelInfo(&pixel));
1485 (void) CopyMagickString(symbol,p,MaxTextExtent);
1486 StripString(symbol);
1487 if (*symbol == '\0')
1491 case RedPixelChannel: return(QuantumScale*pixel.red);
1492 case GreenPixelChannel: return(QuantumScale*pixel.green);
1493 case BluePixelChannel: return(QuantumScale*pixel.blue);
1494 case BlackPixelChannel:
1496 if (image->colorspace != CMYKColorspace)
1498 (void) ThrowMagickException(exception,GetMagickModule(),
1499 OptionError,"ColorSeparatedImageRequired","`%s'",
1503 return(QuantumScale*pixel.black);
1505 case AlphaPixelChannel:
1510 if (pixel.matte == MagickFalse)
1512 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1515 case IntensityPixelChannel:
1517 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1522 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1523 "UnableToParseExpression","`%s'",p);
1531 if (LocaleCompare(symbol,"a") == 0)
1532 return((MagickRealType) (QuantumScale*pixel.alpha));
1538 if (LocaleCompare(symbol,"b") == 0)
1539 return(QuantumScale*pixel.blue);
1545 if (LocaleNCompare(symbol,"channel",7) == 0)
1553 flags=ParseGeometry(symbol+7,&channel_info);
1554 if (image->colorspace == CMYKColorspace)
1557 case CyanPixelChannel:
1559 if ((flags & RhoValue) == 0)
1561 return(channel_info.rho);
1563 case MagentaPixelChannel:
1565 if ((flags & SigmaValue) == 0)
1567 return(channel_info.sigma);
1569 case YellowPixelChannel:
1571 if ((flags & XiValue) == 0)
1573 return(channel_info.xi);
1575 case BlackPixelChannel:
1577 if ((flags & PsiValue) == 0)
1579 return(channel_info.psi);
1581 case AlphaPixelChannel:
1583 if ((flags & ChiValue) == 0)
1585 return(channel_info.chi);
1592 case RedPixelChannel:
1594 if ((flags & RhoValue) == 0)
1596 return(channel_info.rho);
1598 case GreenPixelChannel:
1600 if ((flags & SigmaValue) == 0)
1602 return(channel_info.sigma);
1604 case BluePixelChannel:
1606 if ((flags & XiValue) == 0)
1608 return(channel_info.xi);
1610 case BlackPixelChannel:
1612 if ((flags & ChiValue) == 0)
1614 return(channel_info.chi);
1616 case AlphaPixelChannel:
1618 if ((flags & PsiValue) == 0)
1620 return(channel_info.psi);
1627 if (LocaleCompare(symbol,"c") == 0)
1628 return(QuantumScale*pixel.red);
1634 if (LocaleNCompare(symbol,"depth",5) == 0)
1635 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1641 if (LocaleCompare(symbol,"g") == 0)
1642 return(QuantumScale*pixel.green);
1648 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1649 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1650 if (LocaleCompare(symbol,"k") == 0)
1652 if (image->colorspace != CMYKColorspace)
1654 (void) ThrowMagickException(exception,GetMagickModule(),
1655 OptionError,"ColorSeparatedImageRequired","`%s'",
1659 return(QuantumScale*pixel.black);
1666 if (LocaleCompare(symbol,"h") == 0)
1667 return((MagickRealType) image->rows);
1668 if (LocaleCompare(symbol,"hue") == 0)
1675 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1676 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1684 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1685 (LocaleCompare(symbol,"image.minima") == 0) ||
1686 (LocaleCompare(symbol,"image.maxima") == 0) ||
1687 (LocaleCompare(symbol,"image.mean") == 0) ||
1688 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1689 (LocaleCompare(symbol,"image.skewness") == 0) ||
1690 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1691 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1692 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1693 return(image->x_resolution);
1694 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1695 return(image->y_resolution);
1696 if (LocaleCompare(symbol,"intensity") == 0)
1697 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1698 if (LocaleCompare(symbol,"i") == 0)
1699 return((MagickRealType) x);
1705 if (LocaleCompare(symbol,"j") == 0)
1706 return((MagickRealType) y);
1712 if (LocaleCompare(symbol,"lightness") == 0)
1719 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1720 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1723 if (LocaleCompare(symbol,"luminance") == 0)
1728 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1729 return(QuantumScale*luminence);
1736 if (LocaleNCompare(symbol,"maxima",6) == 0)
1737 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1738 if (LocaleNCompare(symbol,"mean",4) == 0)
1739 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1740 if (LocaleNCompare(symbol,"minima",6) == 0)
1741 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1742 if (LocaleCompare(symbol,"m") == 0)
1743 return(QuantumScale*pixel.blue);
1749 if (LocaleCompare(symbol,"n") == 0)
1750 return((MagickRealType) GetImageListLength(fx_info->images));
1756 if (LocaleCompare(symbol,"o") == 0)
1757 return(QuantumScale*pixel.alpha);
1763 if (LocaleCompare(symbol,"page.height") == 0)
1764 return((MagickRealType) image->page.height);
1765 if (LocaleCompare(symbol,"page.width") == 0)
1766 return((MagickRealType) image->page.width);
1767 if (LocaleCompare(symbol,"page.x") == 0)
1768 return((MagickRealType) image->page.x);
1769 if (LocaleCompare(symbol,"page.y") == 0)
1770 return((MagickRealType) image->page.y);
1776 if (LocaleCompare(symbol,"resolution.x") == 0)
1777 return(image->x_resolution);
1778 if (LocaleCompare(symbol,"resolution.y") == 0)
1779 return(image->y_resolution);
1780 if (LocaleCompare(symbol,"r") == 0)
1781 return(QuantumScale*pixel.red);
1787 if (LocaleCompare(symbol,"saturation") == 0)
1794 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1795 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1798 if (LocaleNCompare(symbol,"skewness",8) == 0)
1799 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1800 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1801 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1807 if (LocaleCompare(symbol,"t") == 0)
1808 return((MagickRealType) GetImageIndexInList(fx_info->images));
1814 if (LocaleCompare(symbol,"w") == 0)
1815 return((MagickRealType) image->columns);
1821 if (LocaleCompare(symbol,"y") == 0)
1822 return(QuantumScale*pixel.green);
1828 if (LocaleCompare(symbol,"z") == 0)
1833 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1841 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1842 if (value != (const char *) NULL)
1843 return((MagickRealType) InterpretLocaleValue(value,(char **) NULL));
1844 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1845 "UnableToParseExpression","`%s'",symbol);
1849 static const char *FxOperatorPrecedence(const char *expression,
1850 ExceptionInfo *exception)
1854 UndefinedPrecedence,
1856 BitwiseComplementPrecedence,
1858 ExponentialNotationPrecedence,
1862 RelationalPrecedence,
1863 EquivalencyPrecedence,
1864 BitwiseAndPrecedence,
1865 BitwiseOrPrecedence,
1866 LogicalAndPrecedence,
1867 LogicalOrPrecedence,
1869 AssignmentPrecedence,
1889 subexpression=(const char *) NULL;
1890 target=NullPrecedence;
1891 while (*expression != '\0')
1893 precedence=UndefinedPrecedence;
1894 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1899 switch (*expression)
1904 if (LocaleNCompare(expression,"atan2",5) == 0)
1914 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1915 (LocaleNCompare(expression,"j1",2) == 0))
1924 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1931 if ((c == (int) '{') || (c == (int) '['))
1934 if ((c == (int) '}') || (c == (int) ']'))
1937 switch ((unsigned char) *expression)
1942 precedence=BitwiseComplementPrecedence;
1948 precedence=ExponentPrecedence;
1953 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1954 (strchr(")",c) != (char *) NULL))) &&
1955 (((islower((int) ((char) *expression)) != 0) ||
1956 (strchr("(",(int) *expression) != (char *) NULL)) ||
1957 ((isdigit((int) ((char) c)) == 0) &&
1958 (isdigit((int) ((char) *expression)) != 0))) &&
1959 (strchr("xy",(int) *expression) == (char *) NULL))
1960 precedence=MultiplyPrecedence;
1967 precedence=MultiplyPrecedence;
1973 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1975 precedence=AdditionPrecedence;
1978 case LeftShiftOperator:
1979 case RightShiftOperator:
1981 precedence=ShiftPrecedence;
1985 case LessThanEqualOperator:
1986 case GreaterThanEqualOperator:
1989 precedence=RelationalPrecedence;
1993 case NotEqualOperator:
1995 precedence=EquivalencyPrecedence;
2000 precedence=BitwiseAndPrecedence;
2005 precedence=BitwiseOrPrecedence;
2008 case LogicalAndOperator:
2010 precedence=LogicalAndPrecedence;
2013 case LogicalOrOperator:
2015 precedence=LogicalOrPrecedence;
2018 case ExponentialNotation:
2020 precedence=ExponentialNotationPrecedence;
2026 precedence=TernaryPrecedence;
2031 precedence=AssignmentPrecedence;
2036 precedence=CommaPrecedence;
2041 precedence=SeparatorPrecedence;
2045 if ((precedence == BitwiseComplementPrecedence) ||
2046 (precedence == TernaryPrecedence) ||
2047 (precedence == AssignmentPrecedence))
2049 if (precedence > target)
2052 Right-to-left associativity.
2055 subexpression=expression;
2059 if (precedence >= target)
2062 Left-to-right associativity.
2065 subexpression=expression;
2067 if (strchr("(",(int) *expression) != (char *) NULL)
2068 expression=FxSubexpression(expression,exception);
2069 c=(int) (*expression++);
2071 return(subexpression);
2074 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2075 const PixelChannel channel,const ssize_t x,const ssize_t y,
2076 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2080 subexpression[MaxTextExtent];
2090 if (exception->severity != UndefinedException)
2092 while (isspace((int) *expression) != 0)
2094 if (*expression == '\0')
2096 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2097 "MissingExpression","`%s'",expression);
2100 *subexpression='\0';
2101 p=FxOperatorPrecedence(expression,exception);
2102 if (p != (const char *) NULL)
2104 (void) CopyMagickString(subexpression,expression,(size_t)
2106 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2108 switch ((unsigned char) *p)
2112 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2113 *beta=(MagickRealType) (~(size_t) *beta);
2118 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2119 return(*beta == 0.0 ? 1.0 : 0.0);
2123 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2124 channel,x,y,++p,beta,exception));
2128 case ExponentialNotation:
2130 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2131 return(alpha*(*beta));
2135 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2138 if (exception->severity == UndefinedException)
2139 (void) ThrowMagickException(exception,GetMagickModule(),
2140 OptionError,"DivideByZero","`%s'",expression);
2143 return(alpha/(*beta));
2147 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2148 *beta=fabs(floor(((double) *beta)+0.5));
2151 (void) ThrowMagickException(exception,GetMagickModule(),
2152 OptionError,"DivideByZero","`%s'",expression);
2155 return(fmod((double) alpha,(double) *beta));
2159 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2160 return(alpha+(*beta));
2164 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2165 return(alpha-(*beta));
2167 case LeftShiftOperator:
2169 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2170 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2174 case RightShiftOperator:
2176 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2177 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2183 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2184 return(alpha < *beta ? 1.0 : 0.0);
2186 case LessThanEqualOperator:
2188 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2189 return(alpha <= *beta ? 1.0 : 0.0);
2193 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2194 return(alpha > *beta ? 1.0 : 0.0);
2196 case GreaterThanEqualOperator:
2198 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2199 return(alpha >= *beta ? 1.0 : 0.0);
2203 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2204 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2206 case NotEqualOperator:
2208 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2209 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2213 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2214 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2220 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2221 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2225 case LogicalAndOperator:
2227 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2228 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2231 case LogicalOrOperator:
2233 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2234 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2242 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2244 p=StringToken(":",&q);
2245 if (q == (char *) NULL)
2247 (void) ThrowMagickException(exception,GetMagickModule(),
2248 OptionError,"UnableToParseExpression","`%s'",subexpression);
2251 if (fabs((double) alpha) > MagickEpsilon)
2252 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2254 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2260 numeric[MaxTextExtent];
2263 while (isalpha((int) ((unsigned char) *q)) != 0)
2267 (void) ThrowMagickException(exception,GetMagickModule(),
2268 OptionError,"UnableToParseExpression","`%s'",subexpression);
2271 ClearMagickException(exception);
2272 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2273 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2275 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2276 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2277 subexpression),ConstantString(numeric));
2282 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2287 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2292 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2298 if (strchr("(",(int) *expression) != (char *) NULL)
2300 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2301 subexpression[strlen(subexpression)-1]='\0';
2302 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2306 switch (*expression)
2310 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2316 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2322 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2324 return((MagickRealType) (~(size_t) (gamma+0.5)));
2329 if (LocaleNCompare(expression,"abs",3) == 0)
2331 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2333 return((MagickRealType) fabs((double) alpha));
2335 if (LocaleNCompare(expression,"acos",4) == 0)
2337 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2339 return((MagickRealType) acos((double) alpha));
2341 #if defined(MAGICKCORE_HAVE_J1)
2342 if (LocaleNCompare(expression,"airy",4) == 0)
2344 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2348 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2349 return(gamma*gamma);
2352 if (LocaleNCompare(expression,"asin",4) == 0)
2354 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2356 return((MagickRealType) asin((double) alpha));
2358 if (LocaleNCompare(expression,"alt",3) == 0)
2360 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2362 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2364 if (LocaleNCompare(expression,"atan2",5) == 0)
2366 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2368 return((MagickRealType) atan2((double) alpha,(double) *beta));
2370 if (LocaleNCompare(expression,"atan",4) == 0)
2372 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2374 return((MagickRealType) atan((double) alpha));
2376 if (LocaleCompare(expression,"a") == 0)
2377 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2383 if (LocaleCompare(expression,"b") == 0)
2384 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2390 if (LocaleNCompare(expression,"ceil",4) == 0)
2392 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2394 return((MagickRealType) ceil((double) alpha));
2396 if (LocaleNCompare(expression,"cosh",4) == 0)
2398 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2400 return((MagickRealType) cosh((double) alpha));
2402 if (LocaleNCompare(expression,"cos",3) == 0)
2404 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2406 return((MagickRealType) cos((double) alpha));
2408 if (LocaleCompare(expression,"c") == 0)
2409 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2415 if (LocaleNCompare(expression,"debug",5) == 0)
2420 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2422 if (fx_info->images->colorspace == CMYKColorspace)
2425 case CyanPixelChannel: type="cyan"; break;
2426 case MagentaPixelChannel: type="magenta"; break;
2427 case YellowPixelChannel: type="yellow"; break;
2428 case AlphaPixelChannel: type="opacity"; break;
2429 case BlackPixelChannel: type="black"; break;
2430 default: type="unknown"; break;
2435 case RedPixelChannel: type="red"; break;
2436 case GreenPixelChannel: type="green"; break;
2437 case BluePixelChannel: type="blue"; break;
2438 case AlphaPixelChannel: type="opacity"; break;
2439 default: type="unknown"; break;
2441 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2442 if (strlen(subexpression) > 1)
2443 subexpression[strlen(subexpression)-1]='\0';
2444 if (fx_info->file != (FILE *) NULL)
2445 (void) FormatLocaleFile(fx_info->file,
2446 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2447 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2456 if (LocaleCompare(expression,"epsilon") == 0)
2457 return((MagickRealType) MagickEpsilon);
2458 if (LocaleNCompare(expression,"exp",3) == 0)
2460 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2462 return((MagickRealType) exp((double) alpha));
2464 if (LocaleCompare(expression,"e") == 0)
2465 return((MagickRealType) 2.7182818284590452354);
2471 if (LocaleNCompare(expression,"floor",5) == 0)
2473 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2475 return((MagickRealType) floor((double) alpha));
2482 if (LocaleCompare(expression,"g") == 0)
2483 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2489 if (LocaleCompare(expression,"h") == 0)
2490 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2491 if (LocaleCompare(expression,"hue") == 0)
2492 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2493 if (LocaleNCompare(expression,"hypot",5) == 0)
2495 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2497 return((MagickRealType) hypot((double) alpha,(double) *beta));
2504 if (LocaleCompare(expression,"k") == 0)
2505 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2511 if (LocaleCompare(expression,"intensity") == 0)
2512 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2513 if (LocaleNCompare(expression,"int",3) == 0)
2515 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2517 return((MagickRealType) floor(alpha));
2519 if (LocaleCompare(expression,"i") == 0)
2520 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2526 if (LocaleCompare(expression,"j") == 0)
2527 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2528 #if defined(MAGICKCORE_HAVE_J0)
2529 if (LocaleNCompare(expression,"j0",2) == 0)
2531 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2533 return((MagickRealType) j0((double) alpha));
2536 #if defined(MAGICKCORE_HAVE_J1)
2537 if (LocaleNCompare(expression,"j1",2) == 0)
2539 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2541 return((MagickRealType) j1((double) alpha));
2544 #if defined(MAGICKCORE_HAVE_J1)
2545 if (LocaleNCompare(expression,"jinc",4) == 0)
2547 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2551 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2561 if (LocaleNCompare(expression,"ln",2) == 0)
2563 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2565 return((MagickRealType) log((double) alpha));
2567 if (LocaleNCompare(expression,"logtwo",6) == 0)
2569 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2571 return((MagickRealType) log10((double) alpha))/log10(2.0);
2573 if (LocaleNCompare(expression,"log",3) == 0)
2575 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2577 return((MagickRealType) log10((double) alpha));
2579 if (LocaleCompare(expression,"lightness") == 0)
2580 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2586 if (LocaleCompare(expression,"MaxRGB") == 0)
2587 return((MagickRealType) QuantumRange);
2588 if (LocaleNCompare(expression,"maxima",6) == 0)
2590 if (LocaleNCompare(expression,"max",3) == 0)
2591 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2592 if (LocaleNCompare(expression,"minima",6) == 0)
2594 if (LocaleNCompare(expression,"min",3) == 0)
2595 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2596 if (LocaleNCompare(expression,"mod",3) == 0)
2598 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2600 return((MagickRealType) fmod((double) alpha,(double) *beta));
2602 if (LocaleCompare(expression,"m") == 0)
2603 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2609 if (LocaleCompare(expression,"n") == 0)
2610 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2616 if (LocaleCompare(expression,"Opaque") == 0)
2618 if (LocaleCompare(expression,"o") == 0)
2619 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2625 if (LocaleCompare(expression,"pi") == 0)
2626 return((MagickRealType) MagickPI);
2627 if (LocaleNCompare(expression,"pow",3) == 0)
2629 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2631 return((MagickRealType) pow((double) alpha,(double) *beta));
2633 if (LocaleCompare(expression,"p") == 0)
2634 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2640 if (LocaleCompare(expression,"QuantumRange") == 0)
2641 return((MagickRealType) QuantumRange);
2642 if (LocaleCompare(expression,"QuantumScale") == 0)
2643 return((MagickRealType) QuantumScale);
2649 if (LocaleNCompare(expression,"rand",4) == 0)
2650 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2651 if (LocaleNCompare(expression,"round",5) == 0)
2653 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2655 return((MagickRealType) floor((double) alpha+0.5));
2657 if (LocaleCompare(expression,"r") == 0)
2658 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2664 if (LocaleCompare(expression,"saturation") == 0)
2665 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2666 if (LocaleNCompare(expression,"sign",4) == 0)
2668 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2670 return(alpha < 0.0 ? -1.0 : 1.0);
2672 if (LocaleNCompare(expression,"sinc",4) == 0)
2674 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2678 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2682 if (LocaleNCompare(expression,"sinh",4) == 0)
2684 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2686 return((MagickRealType) sinh((double) alpha));
2688 if (LocaleNCompare(expression,"sin",3) == 0)
2690 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2692 return((MagickRealType) sin((double) alpha));
2694 if (LocaleNCompare(expression,"sqrt",4) == 0)
2696 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2698 return((MagickRealType) sqrt((double) alpha));
2700 if (LocaleCompare(expression,"s") == 0)
2701 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2707 if (LocaleNCompare(expression,"tanh",4) == 0)
2709 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2711 return((MagickRealType) tanh((double) alpha));
2713 if (LocaleNCompare(expression,"tan",3) == 0)
2715 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2717 return((MagickRealType) tan((double) alpha));
2719 if (LocaleCompare(expression,"Transparent") == 0)
2721 if (LocaleNCompare(expression,"trunc",5) == 0)
2723 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2726 return((MagickRealType) floor((double) alpha));
2727 return((MagickRealType) ceil((double) alpha));
2729 if (LocaleCompare(expression,"t") == 0)
2730 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2736 if (LocaleCompare(expression,"u") == 0)
2737 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2743 if (LocaleCompare(expression,"v") == 0)
2744 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2750 if (LocaleCompare(expression,"w") == 0)
2751 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2757 if (LocaleCompare(expression,"y") == 0)
2758 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2764 if (LocaleCompare(expression,"z") == 0)
2765 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2771 q=(char *) expression;
2772 alpha=InterpretLocaleValue(expression,&q);
2773 if (q == expression)
2774 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2778 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2779 MagickRealType *alpha,ExceptionInfo *exception)
2784 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2788 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2789 MagickRealType *alpha,ExceptionInfo *exception)
2798 fx_info->file=(FILE *) NULL;
2799 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2804 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2805 const PixelChannel channel,const ssize_t x,const ssize_t y,
2806 MagickRealType *alpha,ExceptionInfo *exception)
2812 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2814 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2828 % FxImage() applies a mathematical expression to the specified image.
2830 % The format of the FxImage method is:
2832 % Image *FxImage(const Image *image,const char *expression,
2833 % ExceptionInfo *exception)
2835 % A description of each parameter follows:
2837 % o image: the image.
2839 % o expression: A mathematical expression.
2841 % o exception: return any errors or warnings in this structure.
2845 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2850 assert(fx_info != (FxInfo **) NULL);
2851 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2852 if (fx_info[i] != (FxInfo *) NULL)
2853 fx_info[i]=DestroyFxInfo(fx_info[i]);
2854 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2858 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2859 ExceptionInfo *exception)
2876 number_threads=GetOpenMPMaximumThreads();
2877 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2878 if (fx_info == (FxInfo **) NULL)
2879 return((FxInfo **) NULL);
2880 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2881 if (*expression != '@')
2882 fx_expression=ConstantString(expression);
2884 fx_expression=FileToString(expression+1,~0,exception);
2885 for (i=0; i < (ssize_t) number_threads; i++)
2887 fx_info[i]=AcquireFxInfo(image,fx_expression);
2888 if (fx_info[i] == (FxInfo *) NULL)
2889 return(DestroyFxThreadSet(fx_info));
2890 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2892 fx_expression=DestroyString(fx_expression);
2896 MagickExport Image *FxImage(const Image *image,const char *expression,
2897 ExceptionInfo *exception)
2899 #define FxImageTag "Fx/Image"
2923 assert(image != (Image *) NULL);
2924 assert(image->signature == MagickSignature);
2925 if (image->debug != MagickFalse)
2926 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2927 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2928 if (fx_image == (Image *) NULL)
2929 return((Image *) NULL);
2930 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2932 InheritException(exception,&fx_image->exception);
2933 fx_image=DestroyImage(fx_image);
2934 return((Image *) NULL);
2936 fx_info=AcquireFxThreadSet(image,expression,exception);
2937 if (fx_info == (FxInfo **) NULL)
2939 fx_image=DestroyImage(fx_image);
2940 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2942 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2943 if (status == MagickFalse)
2945 fx_image=DestroyImage(fx_image);
2946 fx_info=DestroyFxThreadSet(fx_info);
2947 return((Image *) NULL);
2954 image_view=AcquireCacheView(image);
2955 fx_view=AcquireCacheView(fx_image);
2956 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2957 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2959 for (y=0; y < (ssize_t) fx_image->rows; y++)
2962 id = GetOpenMPThreadId();
2964 register const Quantum
2973 if (status == MagickFalse)
2975 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2976 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2977 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2982 for (x=0; x < (ssize_t) fx_image->columns; x++)
2987 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2999 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3000 if (traits == UndefinedPixelTrait)
3002 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3003 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3004 if (fx_traits == UndefinedPixelTrait)
3006 if ((fx_traits & CopyPixelTrait) != 0)
3012 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3014 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3016 p+=GetPixelChannels(image);
3017 q+=GetPixelChannels(fx_image);
3019 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3021 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3026 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3027 #pragma omp critical (MagickCore_FxImage)
3029 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3030 if (proceed == MagickFalse)
3034 fx_view=DestroyCacheView(fx_view);
3035 image_view=DestroyCacheView(image_view);
3036 fx_info=DestroyFxThreadSet(fx_info);
3037 if (status == MagickFalse)
3038 fx_image=DestroyImage(fx_image);
3043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3047 % I m p l o d e I m a g e %
3051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3053 % ImplodeImage() creates a new image that is a copy of an existing
3054 % one with the image pixels "implode" by the specified percentage. It
3055 % allocates the memory necessary for the new Image structure and returns a
3056 % pointer to the new image.
3058 % The format of the ImplodeImage method is:
3060 % Image *ImplodeImage(const Image *image,const double amount,
3061 % ExceptionInfo *exception)
3063 % A description of each parameter follows:
3065 % o implode_image: Method ImplodeImage returns a pointer to the image
3066 % after it is implode. A null image is returned if there is a memory
3069 % o image: the image.
3071 % o amount: Define the extent of the implosion.
3073 % o exception: return any errors or warnings in this structure.
3076 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3077 ExceptionInfo *exception)
3079 #define ImplodeImageTag "Implode/Image"
3108 Initialize implode image attributes.
3110 assert(image != (Image *) NULL);
3111 assert(image->signature == MagickSignature);
3112 if (image->debug != MagickFalse)
3113 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3114 assert(exception != (ExceptionInfo *) NULL);
3115 assert(exception->signature == MagickSignature);
3116 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3117 if (implode_image == (Image *) NULL)
3118 return((Image *) NULL);
3119 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3121 InheritException(exception,&implode_image->exception);
3122 implode_image=DestroyImage(implode_image);
3123 return((Image *) NULL);
3125 if (implode_image->background_color.alpha != OpaqueAlpha)
3126 implode_image->matte=MagickTrue;
3128 Compute scaling factor.
3132 center.x=0.5*image->columns;
3133 center.y=0.5*image->rows;
3135 if (image->columns > image->rows)
3136 scale.y=(double) image->columns/(double) image->rows;
3138 if (image->columns < image->rows)
3140 scale.x=(double) image->rows/(double) image->columns;
3148 GetPixelInfo(implode_image,&zero);
3149 image_view=AcquireCacheView(image);
3150 implode_view=AcquireCacheView(implode_image);
3151 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3152 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3154 for (y=0; y < (ssize_t) image->rows; y++)
3171 if (status == MagickFalse)
3173 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3175 if (q == (const Quantum *) NULL)
3180 delta.y=scale.y*(double) (y-center.y);
3182 for (x=0; x < (ssize_t) image->columns; x++)
3185 Determine if the pixel is within an ellipse.
3187 delta.x=scale.x*(double) (x-center.x);
3188 distance=delta.x*delta.x+delta.y*delta.y;
3189 if (distance < (radius*radius))
3199 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3200 radius/2)),-amount);
3201 (void) InterpolatePixelInfo(image,image_view,
3202 UndefinedInterpolatePixel,(double) (factor*delta.x/scale.x+
3203 center.x),(double) (factor*delta.y/scale.y+center.y),&pixel,
3205 SetPixelPixelInfo(implode_image,&pixel,q);
3207 q+=GetPixelChannels(implode_image);
3209 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3211 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3216 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3217 #pragma omp critical (MagickCore_ImplodeImage)
3219 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3220 if (proceed == MagickFalse)
3224 implode_view=DestroyCacheView(implode_view);
3225 image_view=DestroyCacheView(image_view);
3226 if (status == MagickFalse)
3227 implode_image=DestroyImage(implode_image);
3228 return(implode_image);
3232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3236 % M o r p h I m a g e s %
3240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3242 % The MorphImages() method requires a minimum of two images. The first
3243 % image is transformed into the second by a number of intervening images
3244 % as specified by frames.
3246 % The format of the MorphImage method is:
3248 % Image *MorphImages(const Image *image,const size_t number_frames,
3249 % ExceptionInfo *exception)
3251 % A description of each parameter follows:
3253 % o image: the image.
3255 % o number_frames: Define the number of in-between image to generate.
3256 % The more in-between frames, the smoother the morph.
3258 % o exception: return any errors or warnings in this structure.
3261 MagickExport Image *MorphImages(const Image *image,
3262 const size_t number_frames,ExceptionInfo *exception)
3264 #define MorphImageTag "Morph/Image"
3280 register const Image
3290 Clone first frame in sequence.
3292 assert(image != (Image *) NULL);
3293 assert(image->signature == MagickSignature);
3294 if (image->debug != MagickFalse)
3295 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3296 assert(exception != (ExceptionInfo *) NULL);
3297 assert(exception->signature == MagickSignature);
3298 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3299 if (morph_images == (Image *) NULL)
3300 return((Image *) NULL);
3301 if (GetNextImageInList(image) == (Image *) NULL)
3306 for (i=1; i < (ssize_t) number_frames; i++)
3308 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3309 if (morph_image == (Image *) NULL)
3311 morph_images=DestroyImageList(morph_images);
3312 return((Image *) NULL);
3314 AppendImageToList(&morph_images,morph_image);
3315 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3320 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3322 if (proceed == MagickFalse)
3326 return(GetFirstImageInList(morph_images));
3329 Morph image sequence.
3334 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3336 for (i=0; i < (ssize_t) number_frames; i++)
3342 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3344 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3345 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3346 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3347 next->filter,next->blur,exception);
3348 if (morph_image == (Image *) NULL)
3350 morph_images=DestroyImageList(morph_images);
3351 return((Image *) NULL);
3353 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3355 InheritException(exception,&morph_image->exception);
3356 morph_image=DestroyImage(morph_image);
3357 return((Image *) NULL);
3359 AppendImageToList(&morph_images,morph_image);
3360 morph_images=GetLastImageInList(morph_images);
3361 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3362 morph_images->rows,GetNextImageInList(next)->filter,
3363 GetNextImageInList(next)->blur,exception);
3364 if (morph_image == (Image *) NULL)
3366 morph_images=DestroyImageList(morph_images);
3367 return((Image *) NULL);
3369 image_view=AcquireCacheView(morph_image);
3370 morph_view=AcquireCacheView(morph_images);
3371 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3372 #pragma omp parallel for schedule(dynamic,4) shared(status)
3374 for (y=0; y < (ssize_t) morph_images->rows; y++)
3379 register const Quantum
3388 if (status == MagickFalse)
3390 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3392 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3394 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3399 for (x=0; x < (ssize_t) morph_images->columns; x++)
3401 SetPixelRed(morph_images,ClampToQuantum(alpha*
3402 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3403 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3404 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3405 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3406 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3407 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3408 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3409 if ((morph_image->colorspace == CMYKColorspace) &&
3410 (morph_images->colorspace == CMYKColorspace))
3411 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3412 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3414 p+=GetPixelChannels(morph_image);
3415 q+=GetPixelChannels(morph_images);
3417 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3418 if (sync == MagickFalse)
3421 morph_view=DestroyCacheView(morph_view);
3422 image_view=DestroyCacheView(image_view);
3423 morph_image=DestroyImage(morph_image);
3425 if (i < (ssize_t) number_frames)
3428 Clone last frame in sequence.
3430 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3431 if (morph_image == (Image *) NULL)
3433 morph_images=DestroyImageList(morph_images);
3434 return((Image *) NULL);
3436 AppendImageToList(&morph_images,morph_image);
3437 morph_images=GetLastImageInList(morph_images);
3438 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3443 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3444 #pragma omp critical (MagickCore_MorphImages)
3446 proceed=SetImageProgress(image,MorphImageTag,scene,
3447 GetImageListLength(image));
3448 if (proceed == MagickFalse)
3453 if (GetNextImageInList(next) != (Image *) NULL)
3455 morph_images=DestroyImageList(morph_images);
3456 return((Image *) NULL);
3458 return(GetFirstImageInList(morph_images));
3462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3466 % P l a s m a I m a g e %
3470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3472 % PlasmaImage() initializes an image with plasma fractal values. The image
3473 % must be initialized with a base color and the random number generator
3474 % seeded before this method is called.
3476 % The format of the PlasmaImage method is:
3478 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3479 % size_t attenuate,size_t depth)
3481 % A description of each parameter follows:
3483 % o image: the image.
3485 % o segment: Define the region to apply plasma fractals values.
3487 % o attenuate: Define the plasma attenuation factor.
3489 % o depth: Limit the plasma recursion depth.
3493 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3494 const MagickRealType pixel,const MagickRealType noise)
3499 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3504 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3505 CacheView *image_view,RandomInfo *random_info,const SegmentInfo *segment,
3506 size_t attenuate,size_t depth)
3524 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3532 Divide the area into quadrants and recurse.
3536 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3537 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3538 local_info=(*segment);
3539 local_info.x2=(double) x_mid;
3540 local_info.y2=(double) y_mid;
3541 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3543 local_info=(*segment);
3544 local_info.y1=(double) y_mid;
3545 local_info.x2=(double) x_mid;
3546 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3548 local_info=(*segment);
3549 local_info.x1=(double) x_mid;
3550 local_info.y2=(double) y_mid;
3551 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3553 local_info=(*segment);
3554 local_info.x1=(double) x_mid;
3555 local_info.y1=(double) y_mid;
3556 return(PlasmaImageProxy(image,image_view,random_info,&local_info,
3559 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3560 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3561 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3562 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3563 return(MagickFalse);
3565 Average pixels and apply plasma.
3567 exception=(&image->exception);
3568 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3569 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3577 x=(ssize_t) ceil(segment->x1-0.5);
3578 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3579 ceil(segment->y1-0.5),&u,exception);
3580 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3581 ceil(segment->y2-0.5),&v,exception);
3582 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3583 if (q == (const Quantum *) NULL)
3585 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3586 (u.red+v.red)/2.0,plasma),q);
3587 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3588 (u.green+v.green)/2.0,plasma),q);
3589 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3590 (u.blue+v.blue)/2.0,plasma),q);
3591 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3592 if (segment->x1 != segment->x2)
3597 x=(ssize_t) ceil(segment->x2-0.5);
3598 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3599 ceil(segment->y1-0.5),&u,exception);
3600 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3601 ceil(segment->y2-0.5),&v,exception);
3602 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3603 if (q == (const Quantum *) NULL)
3605 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3606 (u.red+v.red)/2.0,plasma),q);
3607 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3608 (u.green+v.green)/2.0,plasma),q);
3609 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3610 (u.blue+v.blue)/2.0,plasma),q);
3611 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3614 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3616 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3624 y=(ssize_t) ceil(segment->y2-0.5);
3625 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3626 ceil(segment->x1-0.5),y,&u,exception);
3627 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3628 ceil(segment->x2-0.5),y,&v,exception);
3629 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3630 if (q == (const Quantum *) NULL)
3632 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3633 (u.red+v.red)/2.0,plasma),q);
3634 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3635 (u.green+v.green)/2.0,plasma),q);
3636 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3637 (u.blue+v.blue)/2.0,plasma),q);
3638 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3640 if (segment->y1 != segment->y2)
3648 y=(ssize_t) ceil(segment->y1-0.5);
3649 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3650 ceil(segment->x1-0.5),y,&u,exception);
3651 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3652 ceil(segment->x2-0.5),y,&v,exception);
3653 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3654 if (q == (const Quantum *) NULL)
3656 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3657 (u.red+v.red)/2.0,plasma),q);
3658 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3659 (u.green+v.green)/2.0,plasma),q);
3660 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3661 (u.blue+v.blue)/2.0,plasma),q);
3662 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3665 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3673 x=(ssize_t) ceil(segment->x1-0.5);
3674 y=(ssize_t) ceil(segment->y1-0.5);
3675 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3676 x=(ssize_t) ceil(segment->x2-0.5);
3677 y=(ssize_t) ceil(segment->y2-0.5);
3678 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&v,exception);
3679 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3680 if (q == (const Quantum *) NULL)
3682 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3683 (u.red+v.red)/2.0,plasma),q);
3684 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3685 (u.green+v.green)/2.0,plasma),q);
3686 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3687 (u.blue+v.blue)/2.0,plasma),q);
3688 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3690 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3692 return(MagickFalse);
3695 MagickExport MagickBooleanType PlasmaImage(Image *image,
3696 const SegmentInfo *segment,size_t attenuate,size_t depth)
3707 if (image->debug != MagickFalse)
3708 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3709 assert(image != (Image *) NULL);
3710 assert(image->signature == MagickSignature);
3711 if (image->debug != MagickFalse)
3712 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3713 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3714 return(MagickFalse);
3715 image_view=AcquireCacheView(image);
3716 random_info=AcquireRandomInfo();
3717 status=PlasmaImageProxy(image,image_view,random_info,segment,attenuate,depth);
3718 random_info=DestroyRandomInfo(random_info);
3719 image_view=DestroyCacheView(image_view);
3724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3728 % P o l a r o i d I m a g e %
3732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3734 % PolaroidImage() simulates a Polaroid picture.
3736 % The format of the AnnotateImage method is:
3738 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3739 % const double angle,ExceptionInfo exception)
3741 % A description of each parameter follows:
3743 % o image: the image.
3745 % o draw_info: the draw info.
3747 % o angle: Apply the effect along this angle.
3749 % o exception: return any errors or warnings in this structure.
3752 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3753 const double angle,ExceptionInfo *exception)
3774 Simulate a Polaroid picture.
3776 assert(image != (Image *) NULL);
3777 assert(image->signature == MagickSignature);
3778 if (image->debug != MagickFalse)
3779 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3780 assert(exception != (ExceptionInfo *) NULL);
3781 assert(exception->signature == MagickSignature);
3782 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3783 image->rows)/25.0,10.0);
3784 height=image->rows+2*quantum;
3785 caption_image=(Image *) NULL;
3786 value=GetImageProperty(image,"Caption");
3787 if (value != (const char *) NULL)
3791 geometry[MaxTextExtent];
3806 Generate caption image.
3808 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3809 if (caption_image == (Image *) NULL)
3810 return((Image *) NULL);
3811 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3812 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3814 (void) CloneString(&annotate_info->text,caption);
3815 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3817 status=SetImageExtent(caption_image,image->columns,(size_t)
3818 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3819 if (status == MagickFalse)
3820 caption_image=DestroyImage(caption_image);
3823 caption_image->background_color=image->border_color;
3824 (void) SetImageBackgroundColor(caption_image);
3825 (void) CloneString(&annotate_info->text,caption);
3826 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
3828 if (annotate_info->gravity == UndefinedGravity)
3829 (void) CloneString(&annotate_info->geometry,AcquireString(
3831 (void) AnnotateImage(caption_image,annotate_info);
3832 height+=caption_image->rows;
3834 annotate_info=DestroyDrawInfo(annotate_info);
3835 caption=DestroyString(caption);
3837 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3839 if (picture_image == (Image *) NULL)
3841 if (caption_image != (Image *) NULL)
3842 caption_image=DestroyImage(caption_image);
3843 return((Image *) NULL);
3845 picture_image->background_color=image->border_color;
3846 (void) SetImageBackgroundColor(picture_image);
3847 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3848 if (caption_image != (Image *) NULL)
3850 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3851 quantum,(ssize_t) (image->rows+3*quantum/2));
3852 caption_image=DestroyImage(caption_image);
3854 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3855 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3856 rotate_image=RotateImage(picture_image,90.0,exception);
3857 picture_image=DestroyImage(picture_image);
3858 if (rotate_image == (Image *) NULL)
3859 return((Image *) NULL);
3860 picture_image=rotate_image;
3861 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3862 picture_image->columns,exception);
3863 picture_image=DestroyImage(picture_image);
3864 if (bend_image == (Image *) NULL)
3865 return((Image *) NULL);
3866 InheritException(&bend_image->exception,exception);
3867 picture_image=bend_image;
3868 rotate_image=RotateImage(picture_image,-90.0,exception);
3869 picture_image=DestroyImage(picture_image);
3870 if (rotate_image == (Image *) NULL)
3871 return((Image *) NULL);
3872 picture_image=rotate_image;
3873 picture_image->background_color=image->background_color;
3874 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3876 if (polaroid_image == (Image *) NULL)
3878 picture_image=DestroyImage(picture_image);
3879 return(picture_image);
3881 flop_image=FlopImage(polaroid_image,exception);
3882 polaroid_image=DestroyImage(polaroid_image);
3883 if (flop_image == (Image *) NULL)
3885 picture_image=DestroyImage(picture_image);
3886 return(picture_image);
3888 polaroid_image=flop_image;
3889 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3890 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3891 picture_image=DestroyImage(picture_image);
3892 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3893 rotate_image=RotateImage(polaroid_image,angle,exception);
3894 polaroid_image=DestroyImage(polaroid_image);
3895 if (rotate_image == (Image *) NULL)
3896 return((Image *) NULL);
3897 polaroid_image=rotate_image;
3898 trim_image=TrimImage(polaroid_image,exception);
3899 polaroid_image=DestroyImage(polaroid_image);
3900 if (trim_image == (Image *) NULL)
3901 return((Image *) NULL);
3902 polaroid_image=trim_image;
3903 return(polaroid_image);
3907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3911 % S e p i a T o n e I m a g e %
3915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3917 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3918 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3919 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3920 % threshold of 80% is a good starting point for a reasonable tone.
3922 % The format of the SepiaToneImage method is:
3924 % Image *SepiaToneImage(const Image *image,const double threshold,
3925 % ExceptionInfo *exception)
3927 % A description of each parameter follows:
3929 % o image: the image.
3931 % o threshold: the tone threshold.
3933 % o exception: return any errors or warnings in this structure.
3936 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3937 ExceptionInfo *exception)
3939 #define SepiaToneImageTag "SepiaTone/Image"
3958 Initialize sepia-toned image attributes.
3960 assert(image != (const Image *) NULL);
3961 assert(image->signature == MagickSignature);
3962 if (image->debug != MagickFalse)
3963 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3964 assert(exception != (ExceptionInfo *) NULL);
3965 assert(exception->signature == MagickSignature);
3966 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3967 if (sepia_image == (Image *) NULL)
3968 return((Image *) NULL);
3969 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3971 InheritException(exception,&sepia_image->exception);
3972 sepia_image=DestroyImage(sepia_image);
3973 return((Image *) NULL);
3976 Tone each row of the image.
3980 image_view=AcquireCacheView(image);
3981 sepia_view=AcquireCacheView(sepia_image);
3982 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3983 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3985 for (y=0; y < (ssize_t) image->rows; y++)
3987 register const Quantum
3996 if (status == MagickFalse)
3998 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3999 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4001 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4006 for (x=0; x < (ssize_t) image->columns; x++)
4012 intensity=(MagickRealType) GetPixelIntensity(image,p);
4013 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4014 (MagickRealType) QuantumRange-threshold;
4015 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4016 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4017 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4018 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4019 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4020 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4022 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4023 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4024 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4025 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4026 p+=GetPixelChannels(image);
4027 q+=GetPixelChannels(sepia_image);
4029 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4031 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4036 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4037 #pragma omp critical (MagickCore_SepiaToneImage)
4039 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4041 if (proceed == MagickFalse)
4045 sepia_view=DestroyCacheView(sepia_view);
4046 image_view=DestroyCacheView(image_view);
4047 (void) NormalizeImage(sepia_image);
4048 (void) ContrastImage(sepia_image,MagickTrue);
4049 if (status == MagickFalse)
4050 sepia_image=DestroyImage(sepia_image);
4051 return(sepia_image);
4055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4059 % S h a d o w I m a g e %
4063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4065 % ShadowImage() simulates a shadow from the specified image and returns it.
4067 % The format of the ShadowImage method is:
4069 % Image *ShadowImage(const Image *image,const double opacity,
4070 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4071 % ExceptionInfo *exception)
4073 % A description of each parameter follows:
4075 % o image: the image.
4077 % o opacity: percentage transparency.
4079 % o sigma: the standard deviation of the Gaussian, in pixels.
4081 % o x_offset: the shadow x-offset.
4083 % o y_offset: the shadow y-offset.
4085 % o exception: return any errors or warnings in this structure.
4088 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4089 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4090 ExceptionInfo *exception)
4092 #define ShadowImageTag "Shadow/Image"
4114 assert(image != (Image *) NULL);
4115 assert(image->signature == MagickSignature);
4116 if (image->debug != MagickFalse)
4117 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4118 assert(exception != (ExceptionInfo *) NULL);
4119 assert(exception->signature == MagickSignature);
4120 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4121 if (clone_image == (Image *) NULL)
4122 return((Image *) NULL);
4123 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4124 clone_image->compose=OverCompositeOp;
4125 border_info.width=(size_t) floor(2.0*sigma+0.5);
4126 border_info.height=(size_t) floor(2.0*sigma+0.5);
4129 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4130 border_image=BorderImage(clone_image,&border_info,exception);
4131 clone_image=DestroyImage(clone_image);
4132 if (border_image == (Image *) NULL)
4133 return((Image *) NULL);
4134 if (border_image->matte == MagickFalse)
4135 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4141 border_view=AcquireCacheView(border_image);
4142 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4143 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4145 for (y=0; y < (ssize_t) border_image->rows; y++)
4153 if (status == MagickFalse)
4155 q=GetCacheViewAuthenticPixels(border_view,0,y,border_image->columns,1,
4157 if (q == (const Quantum *) NULL)
4162 for (x=0; x < (ssize_t) border_image->columns; x++)
4164 SetPixelRed(border_image,border_image->background_color.red,q);
4165 SetPixelGreen(border_image,border_image->background_color.green,q);
4166 SetPixelBlue(border_image,border_image->background_color.blue,q);
4167 if (border_image->matte == MagickFalse)
4168 SetPixelAlpha(border_image,border_image->background_color.alpha,q);
4170 SetPixelAlpha(border_image,ClampToQuantum((MagickRealType)
4171 (GetPixelAlpha(border_image,q)*opacity/100.0)),q);
4172 q+=GetPixelChannels(border_image);
4174 if (SyncCacheViewAuthenticPixels(border_view,exception) == MagickFalse)
4176 if (border_image->progress_monitor != (MagickProgressMonitor) NULL)
4181 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4182 #pragma omp critical (MagickCore_ShadowImage)
4184 proceed=SetImageProgress(border_image,ShadowImageTag,progress++,
4185 border_image->rows);
4186 if (proceed == MagickFalse)
4190 border_view=DestroyCacheView(border_view);
4191 PushPixelChannelMap(border_image,AlphaChannel);
4192 shadow_image=BlurImage(border_image,0.0,sigma,exception);
4193 PopPixelChannelMap(border_image);
4194 border_image=DestroyImage(border_image);
4195 if (shadow_image == (Image *) NULL)
4196 return((Image *) NULL);
4197 if (shadow_image->page.width == 0)
4198 shadow_image->page.width=shadow_image->columns;
4199 if (shadow_image->page.height == 0)
4200 shadow_image->page.height=shadow_image->rows;
4201 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4202 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4203 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4204 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4205 return(shadow_image);
4209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4213 % S k e t c h I m a g e %
4217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4219 % SketchImage() simulates a pencil sketch. We convolve the image with a
4220 % Gaussian operator of the given radius and standard deviation (sigma). For
4221 % reasonable results, radius should be larger than sigma. Use a radius of 0
4222 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4225 % The format of the SketchImage method is:
4227 % Image *SketchImage(const Image *image,const double radius,
4228 % const double sigma,const double angle,ExceptionInfo *exception)
4230 % A description of each parameter follows:
4232 % o image: the image.
4234 % o radius: the radius of the Gaussian, in pixels, not counting
4237 % o sigma: the standard deviation of the Gaussian, in pixels.
4239 % o angle: Apply the effect along this angle.
4241 % o exception: return any errors or warnings in this structure.
4244 MagickExport Image *SketchImage(const Image *image,const double radius,
4245 const double sigma,const double angle,ExceptionInfo *exception)
4264 **restrict random_info;
4272 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4273 MagickTrue,exception);
4274 if (random_image == (Image *) NULL)
4275 return((Image *) NULL);
4277 GetPixelInfo(random_image,&zero);
4278 random_info=AcquireRandomInfoThreadSet();
4279 random_view=AcquireCacheView(random_image);
4280 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4281 #pragma omp parallel for schedule(dynamic,4) shared(status)
4283 for (y=0; y < (ssize_t) random_image->rows; y++)
4286 id = GetOpenMPThreadId();
4297 if (status == MagickFalse)
4299 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4301 if (q == (const Quantum *) NULL)
4307 for (x=0; x < (ssize_t) random_image->columns; x++)
4309 pixel.red=(MagickRealType) (QuantumRange*
4310 GetPseudoRandomValue(random_info[id]));
4311 pixel.green=pixel.red;
4312 pixel.blue=pixel.red;
4313 if (image->colorspace == CMYKColorspace)
4314 pixel.black=pixel.red;
4315 SetPixelPixelInfo(random_image,&pixel,q);
4316 q+=GetPixelChannels(random_image);
4318 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4321 random_view=DestroyCacheView(random_view);
4322 random_info=DestroyRandomInfoThreadSet(random_info);
4323 if (status == MagickFalse)
4325 random_image=DestroyImage(random_image);
4326 return(random_image);
4328 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4329 random_image=DestroyImage(random_image);
4330 if (blur_image == (Image *) NULL)
4331 return((Image *) NULL);
4332 dodge_image=EdgeImage(blur_image,radius,exception);
4333 blur_image=DestroyImage(blur_image);
4334 if (dodge_image == (Image *) NULL)
4335 return((Image *) NULL);
4336 (void) NormalizeImage(dodge_image);
4337 (void) NegateImage(dodge_image,MagickFalse,exception);
4338 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4339 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4340 if (sketch_image == (Image *) NULL)
4342 dodge_image=DestroyImage(dodge_image);
4343 return((Image *) NULL);
4345 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4346 dodge_image=DestroyImage(dodge_image);
4347 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4348 if (blend_image == (Image *) NULL)
4350 sketch_image=DestroyImage(sketch_image);
4351 return((Image *) NULL);
4353 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4354 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4355 blend_image=DestroyImage(blend_image);
4356 return(sketch_image);
4360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4364 % S o l a r i z e I m a g e %
4368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4370 % SolarizeImage() applies a special effect to the image, similar to the effect
4371 % achieved in a photo darkroom by selectively exposing areas of photo
4372 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4373 % measure of the extent of the solarization.
4375 % The format of the SolarizeImage method is:
4377 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4379 % A description of each parameter follows:
4381 % o image: the image.
4383 % o threshold: Define the extent of the solarization.
4386 MagickExport MagickBooleanType SolarizeImage(Image *image,
4387 const double threshold)
4389 #define SolarizeImageTag "Solarize/Image"
4406 assert(image != (Image *) NULL);
4407 assert(image->signature == MagickSignature);
4408 if (image->debug != MagickFalse)
4409 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4410 if (image->storage_class == PseudoClass)
4418 for (i=0; i < (ssize_t) image->colors; i++)
4420 if ((MagickRealType) image->colormap[i].red > threshold)
4421 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4422 if ((MagickRealType) image->colormap[i].green > threshold)
4423 image->colormap[i].green=(Quantum) QuantumRange-
4424 image->colormap[i].green;
4425 if ((MagickRealType) image->colormap[i].blue > threshold)
4426 image->colormap[i].blue=(Quantum) QuantumRange-
4427 image->colormap[i].blue;
4435 exception=(&image->exception);
4436 image_view=AcquireCacheView(image);
4437 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4438 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4440 for (y=0; y < (ssize_t) image->rows; y++)
4448 if (status == MagickFalse)
4450 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4452 if (q == (const Quantum *) NULL)
4457 for (x=0; x < (ssize_t) image->columns; x++)
4459 if ((MagickRealType) GetPixelRed(image,q) > threshold)
4460 SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
4461 if ((MagickRealType) GetPixelGreen(image,q) > threshold)
4462 SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
4463 if ((MagickRealType) GetPixelBlue(image,q) > threshold)
4464 SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
4465 q+=GetPixelChannels(image);
4467 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4469 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4474 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4475 #pragma omp critical (MagickCore_SolarizeImage)
4477 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4478 if (proceed == MagickFalse)
4482 image_view=DestroyCacheView(image_view);
4487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4491 % S t e g a n o I m a g e %
4495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4497 % SteganoImage() hides a digital watermark within the image. Recover
4498 % the hidden watermark later to prove that the authenticity of an image.
4499 % Offset defines the start position within the image to hide the watermark.
4501 % The format of the SteganoImage method is:
4503 % Image *SteganoImage(const Image *image,Image *watermark,
4504 % ExceptionInfo *exception)
4506 % A description of each parameter follows:
4508 % o image: the image.
4510 % o watermark: the watermark image.
4512 % o exception: return any errors or warnings in this structure.
4515 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4516 ExceptionInfo *exception)
4518 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4519 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4520 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4521 #define SteganoImageTag "Stegano/Image"
4556 Initialize steganographic image attributes.
4558 assert(image != (const Image *) NULL);
4559 assert(image->signature == MagickSignature);
4560 if (image->debug != MagickFalse)
4561 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4562 assert(watermark != (const Image *) NULL);
4563 assert(watermark->signature == MagickSignature);
4564 assert(exception != (ExceptionInfo *) NULL);
4565 assert(exception->signature == MagickSignature);
4567 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4568 if (stegano_image == (Image *) NULL)
4569 return((Image *) NULL);
4570 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4572 InheritException(exception,&stegano_image->exception);
4573 stegano_image=DestroyImage(stegano_image);
4574 return((Image *) NULL);
4576 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4578 Hide watermark in low-order bits of image.
4583 depth=stegano_image->depth;
4586 watermark_view=AcquireCacheView(watermark);
4587 stegano_view=AcquireCacheView(stegano_image);
4588 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4590 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4592 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4594 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,&pixel,exception);
4595 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4597 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4598 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4600 if (q == (const Quantum *) NULL)
4606 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
4607 GetPixelPacketIntensity(&pixel),i)),q);
4612 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
4613 GetPixelPacketIntensity(&pixel),i)),q);
4618 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
4619 GetPixelPacketIntensity(&pixel),i)),q);
4623 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4629 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4631 if (k == image->offset)
4635 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4640 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4642 if (proceed == MagickFalse)
4646 stegano_view=DestroyCacheView(stegano_view);
4647 watermark_view=DestroyCacheView(watermark_view);
4648 if (stegano_image->storage_class == PseudoClass)
4649 (void) SyncImage(stegano_image);
4650 if (status == MagickFalse)
4652 stegano_image=DestroyImage(stegano_image);
4653 return((Image *) NULL);
4655 return(stegano_image);
4659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4663 % S t e r e o A n a g l y p h I m a g e %
4667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4669 % StereoAnaglyphImage() combines two images and produces a single image that
4670 % is the composite of a left and right image of a stereo pair. Special
4671 % red-green stereo glasses are required to view this effect.
4673 % The format of the StereoAnaglyphImage method is:
4675 % Image *StereoImage(const Image *left_image,const Image *right_image,
4676 % ExceptionInfo *exception)
4677 % Image *StereoAnaglyphImage(const Image *left_image,
4678 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4679 % ExceptionInfo *exception)
4681 % A description of each parameter follows:
4683 % o left_image: the left image.
4685 % o right_image: the right image.
4687 % o exception: return any errors or warnings in this structure.
4689 % o x_offset: amount, in pixels, by which the left image is offset to the
4690 % right of the right image.
4692 % o y_offset: amount, in pixels, by which the left image is offset to the
4693 % bottom of the right image.
4697 MagickExport Image *StereoImage(const Image *left_image,
4698 const Image *right_image,ExceptionInfo *exception)
4700 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4703 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4704 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4705 ExceptionInfo *exception)
4707 #define StereoImageTag "Stereo/Image"
4721 assert(left_image != (const Image *) NULL);
4722 assert(left_image->signature == MagickSignature);
4723 if (left_image->debug != MagickFalse)
4724 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4725 left_image->filename);
4726 assert(right_image != (const Image *) NULL);
4727 assert(right_image->signature == MagickSignature);
4728 assert(exception != (ExceptionInfo *) NULL);
4729 assert(exception->signature == MagickSignature);
4730 assert(right_image != (const Image *) NULL);
4732 if ((left_image->columns != right_image->columns) ||
4733 (left_image->rows != right_image->rows))
4734 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4736 Initialize stereo image attributes.
4738 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4739 MagickTrue,exception);
4740 if (stereo_image == (Image *) NULL)
4741 return((Image *) NULL);
4742 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4744 InheritException(exception,&stereo_image->exception);
4745 stereo_image=DestroyImage(stereo_image);
4746 return((Image *) NULL);
4749 Copy left image to red channel and right image to blue channel.
4752 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4754 register const Quantum
4764 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4766 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4767 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4768 if ((p == (const Quantum *) NULL) ||
4769 (q == (const Quantum *) NULL) || (r == (Quantum *) NULL))
4771 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4773 SetPixelRed(image,GetPixelRed(left_image,p),r);
4774 SetPixelGreen(image,GetPixelGreen(left_image,q),r);
4775 SetPixelBlue(image,GetPixelBlue(left_image,q),r);
4776 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4777 GetPixelAlpha(left_image,q))/2,r);
4778 p+=GetPixelChannels(left_image);
4782 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4784 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4789 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4790 stereo_image->rows);
4791 if (proceed == MagickFalse)
4795 if (status == MagickFalse)
4797 stereo_image=DestroyImage(stereo_image);
4798 return((Image *) NULL);
4800 return(stereo_image);
4804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4808 % S w i r l I m a g e %
4812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4814 % SwirlImage() swirls the pixels about the center of the image, where
4815 % degrees indicates the sweep of the arc through which each pixel is moved.
4816 % You get a more dramatic effect as the degrees move from 1 to 360.
4818 % The format of the SwirlImage method is:
4820 % Image *SwirlImage(const Image *image,double degrees,
4821 % ExceptionInfo *exception)
4823 % A description of each parameter follows:
4825 % o image: the image.
4827 % o degrees: Define the tightness of the swirling effect.
4829 % o exception: return any errors or warnings in this structure.
4832 MagickExport Image *SwirlImage(const Image *image,double degrees,
4833 ExceptionInfo *exception)
4835 #define SwirlImageTag "Swirl/Image"
4864 Initialize swirl image attributes.
4866 assert(image != (const Image *) NULL);
4867 assert(image->signature == MagickSignature);
4868 if (image->debug != MagickFalse)
4869 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4870 assert(exception != (ExceptionInfo *) NULL);
4871 assert(exception->signature == MagickSignature);
4872 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4873 if (swirl_image == (Image *) NULL)
4874 return((Image *) NULL);
4875 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4877 InheritException(exception,&swirl_image->exception);
4878 swirl_image=DestroyImage(swirl_image);
4879 return((Image *) NULL);
4881 if (swirl_image->background_color.alpha != OpaqueAlpha)
4882 swirl_image->matte=MagickTrue;
4884 Compute scaling factor.
4886 center.x=(double) image->columns/2.0;
4887 center.y=(double) image->rows/2.0;
4888 radius=MagickMax(center.x,center.y);
4891 if (image->columns > image->rows)
4892 scale.y=(double) image->columns/(double) image->rows;
4894 if (image->columns < image->rows)
4895 scale.x=(double) image->rows/(double) image->columns;
4896 degrees=(double) DegreesToRadians(degrees);
4902 GetPixelInfo(swirl_image,&zero);
4903 image_view=AcquireCacheView(image);
4904 swirl_view=AcquireCacheView(swirl_image);
4905 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4906 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4908 for (y=0; y < (ssize_t) image->rows; y++)
4925 if (status == MagickFalse)
4927 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4929 if (q == (const Quantum *) NULL)
4934 delta.y=scale.y*(double) (y-center.y);
4936 for (x=0; x < (ssize_t) image->columns; x++)
4939 Determine if the pixel is within an ellipse.
4941 delta.x=scale.x*(double) (x-center.x);
4942 distance=delta.x*delta.x+delta.y*delta.y;
4943 if (distance < (radius*radius))
4953 factor=1.0-sqrt((double) distance)/radius;
4954 sine=sin((double) (degrees*factor*factor));
4955 cosine=cos((double) (degrees*factor*factor));
4956 (void) InterpolatePixelInfo(image,image_view,
4957 UndefinedInterpolatePixel,(double) ((cosine*delta.x-sine*delta.y)/
4958 scale.x+center.x),(double) ((sine*delta.x+cosine*delta.y)/scale.y+
4959 center.y),&pixel,exception);
4960 SetPixelPixelInfo(swirl_image,&pixel,q);
4962 q+=GetPixelChannels(swirl_image);
4964 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4966 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4971 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4972 #pragma omp critical (MagickCore_SwirlImage)
4974 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4975 if (proceed == MagickFalse)
4979 swirl_view=DestroyCacheView(swirl_view);
4980 image_view=DestroyCacheView(image_view);
4981 if (status == MagickFalse)
4982 swirl_image=DestroyImage(swirl_image);
4983 return(swirl_image);
4987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4991 % T i n t I m a g e %
4995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4997 % TintImage() applies a color vector to each pixel in the image. The length
4998 % of the vector is 0 for black and white and at its maximum for the midtones.
4999 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5001 % The format of the TintImage method is:
5003 % Image *TintImage(const Image *image,const char *opacity,
5004 % const PixelPacket tint,ExceptionInfo *exception)
5006 % A description of each parameter follows:
5008 % o image: the image.
5010 % o opacity: A color value used for tinting.
5012 % o tint: A color value used for tinting.
5014 % o exception: return any errors or warnings in this structure.
5017 MagickExport Image *TintImage(const Image *image,const char *opacity,
5018 const PixelPacket tint,ExceptionInfo *exception)
5020 #define TintImageTag "Tint/Image"
5049 Allocate tint image.
5051 assert(image != (const Image *) NULL);
5052 assert(image->signature == MagickSignature);
5053 if (image->debug != MagickFalse)
5054 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5055 assert(exception != (ExceptionInfo *) NULL);
5056 assert(exception->signature == MagickSignature);
5057 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5058 if (tint_image == (Image *) NULL)
5059 return((Image *) NULL);
5060 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5062 InheritException(exception,&tint_image->exception);
5063 tint_image=DestroyImage(tint_image);
5064 return((Image *) NULL);
5066 if (opacity == (const char *) NULL)
5069 Determine RGB values of the color.
5071 flags=ParseGeometry(opacity,&geometry_info);
5072 pixel.red=geometry_info.rho;
5073 if ((flags & SigmaValue) != 0)
5074 pixel.green=geometry_info.sigma;
5076 pixel.green=pixel.red;
5077 if ((flags & XiValue) != 0)
5078 pixel.blue=geometry_info.xi;
5080 pixel.blue=pixel.red;
5081 if ((flags & PsiValue) != 0)
5082 pixel.alpha=geometry_info.psi;
5084 pixel.alpha=(MagickRealType) OpaqueAlpha;
5085 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5086 GetPixelPacketIntensity(&tint));
5087 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5088 GetPixelPacketIntensity(&tint));
5089 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5090 GetPixelPacketIntensity(&tint));
5096 image_view=AcquireCacheView(image);
5097 tint_view=AcquireCacheView(tint_image);
5098 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5099 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5101 for (y=0; y < (ssize_t) image->rows; y++)
5103 register const Quantum
5112 if (status == MagickFalse)
5114 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5115 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5117 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5122 for (x=0; x < (ssize_t) image->columns; x++)
5130 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5131 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5132 (1.0-(4.0*(weight*weight)));
5133 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5134 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5135 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5136 (1.0-(4.0*(weight*weight)));
5137 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5138 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5139 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5140 (1.0-(4.0*(weight*weight)));
5141 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5142 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
5143 p+=GetPixelChannels(image);
5144 q+=GetPixelChannels(tint_image);
5146 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5148 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5153 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5154 #pragma omp critical (MagickCore_TintImage)
5156 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5157 if (proceed == MagickFalse)
5161 tint_view=DestroyCacheView(tint_view);
5162 image_view=DestroyCacheView(image_view);
5163 if (status == MagickFalse)
5164 tint_image=DestroyImage(tint_image);
5169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5173 % V i g n e t t e I m a g e %
5177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5179 % VignetteImage() softens the edges of the image in vignette style.
5181 % The format of the VignetteImage method is:
5183 % Image *VignetteImage(const Image *image,const double radius,
5184 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5186 % A description of each parameter follows:
5188 % o image: the image.
5190 % o radius: the radius of the pixel neighborhood.
5192 % o sigma: the standard deviation of the Gaussian, in pixels.
5194 % o x, y: Define the x and y ellipse offset.
5196 % o exception: return any errors or warnings in this structure.
5199 MagickExport Image *VignetteImage(const Image *image,const double radius,
5200 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5203 ellipse[MaxTextExtent];
5214 assert(image != (Image *) NULL);
5215 assert(image->signature == MagickSignature);
5216 if (image->debug != MagickFalse)
5217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5218 assert(exception != (ExceptionInfo *) NULL);
5219 assert(exception->signature == MagickSignature);
5220 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5221 if (canvas_image == (Image *) NULL)
5222 return((Image *) NULL);
5223 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5225 InheritException(exception,&canvas_image->exception);
5226 canvas_image=DestroyImage(canvas_image);
5227 return((Image *) NULL);
5229 canvas_image->matte=MagickTrue;
5230 oval_image=CloneImage(canvas_image,canvas_image->columns,
5231 canvas_image->rows,MagickTrue,exception);
5232 if (oval_image == (Image *) NULL)
5234 canvas_image=DestroyImage(canvas_image);
5235 return((Image *) NULL);
5237 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5238 (void) SetImageBackgroundColor(oval_image);
5239 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5240 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5241 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5242 (void) FormatLocaleString(ellipse,MaxTextExtent,
5243 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5244 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5245 draw_info->primitive=AcquireString(ellipse);
5246 (void) DrawImage(oval_image,draw_info);
5247 draw_info=DestroyDrawInfo(draw_info);
5248 blur_image=BlurImage(oval_image,radius,sigma,exception);
5249 oval_image=DestroyImage(oval_image);
5250 if (blur_image == (Image *) NULL)
5252 canvas_image=DestroyImage(canvas_image);
5253 return((Image *) NULL);
5255 blur_image->matte=MagickFalse;
5256 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5257 blur_image=DestroyImage(blur_image);
5258 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5259 canvas_image=DestroyImage(canvas_image);
5260 return(vignette_image);
5264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5268 % W a v e I m a g e %
5272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5274 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5275 % vertically along a sine wave whose amplitude and wavelength is specified
5276 % by the given parameters.
5278 % The format of the WaveImage method is:
5280 % Image *WaveImage(const Image *image,const double amplitude,
5281 % const double wave_length,ExceptionInfo *exception)
5283 % A description of each parameter follows:
5285 % o image: the image.
5287 % o amplitude, wave_length: Define the amplitude and wave length of the
5290 % o exception: return any errors or warnings in this structure.
5293 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5294 const double wave_length,ExceptionInfo *exception)
5296 #define WaveImageTag "Wave/Image"
5324 Initialize wave image attributes.
5326 assert(image != (Image *) NULL);
5327 assert(image->signature == MagickSignature);
5328 if (image->debug != MagickFalse)
5329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5330 assert(exception != (ExceptionInfo *) NULL);
5331 assert(exception->signature == MagickSignature);
5332 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5333 fabs(amplitude)),MagickTrue,exception);
5334 if (wave_image == (Image *) NULL)
5335 return((Image *) NULL);
5336 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5338 InheritException(exception,&wave_image->exception);
5339 wave_image=DestroyImage(wave_image);
5340 return((Image *) NULL);
5342 if (wave_image->background_color.alpha != OpaqueAlpha)
5343 wave_image->matte=MagickTrue;
5347 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5349 if (sine_map == (MagickRealType *) NULL)
5351 wave_image=DestroyImage(wave_image);
5352 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5354 for (i=0; i < (ssize_t) wave_image->columns; i++)
5355 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5362 GetPixelInfo(wave_image,&zero);
5363 image_view=AcquireCacheView(image);
5364 wave_view=AcquireCacheView(wave_image);
5365 (void) SetCacheViewVirtualPixelMethod(image_view,
5366 BackgroundVirtualPixelMethod);
5367 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5368 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5370 for (y=0; y < (ssize_t) wave_image->rows; y++)
5381 if (status == MagickFalse)
5383 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5385 if (q == (const Quantum *) NULL)
5391 for (x=0; x < (ssize_t) wave_image->columns; x++)
5393 (void) InterpolatePixelInfo(image,image_view,
5394 UndefinedInterpolatePixel,(double) x,(double) (y-sine_map[x]),&pixel,
5396 SetPixelPixelInfo(wave_image,&pixel,q);
5397 q+=GetPixelChannels(wave_image);
5399 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5401 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5406 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5407 #pragma omp critical (MagickCore_WaveImage)
5409 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5410 if (proceed == MagickFalse)
5414 wave_view=DestroyCacheView(wave_view);
5415 image_view=DestroyCacheView(image_view);
5416 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5417 if (status == MagickFalse)
5418 wave_image=DestroyImage(wave_image);