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/gem-private.h"
62 #include "MagickCore/geometry.h"
63 #include "MagickCore/layer.h"
64 #include "MagickCore/list.h"
65 #include "MagickCore/log.h"
66 #include "MagickCore/image.h"
67 #include "MagickCore/image-private.h"
68 #include "MagickCore/magick.h"
69 #include "MagickCore/memory_.h"
70 #include "MagickCore/monitor.h"
71 #include "MagickCore/monitor-private.h"
72 #include "MagickCore/option.h"
73 #include "MagickCore/pixel.h"
74 #include "MagickCore/pixel-accessor.h"
75 #include "MagickCore/property.h"
76 #include "MagickCore/quantum.h"
77 #include "MagickCore/quantum-private.h"
78 #include "MagickCore/random_.h"
79 #include "MagickCore/random-private.h"
80 #include "MagickCore/resample.h"
81 #include "MagickCore/resample-private.h"
82 #include "MagickCore/resize.h"
83 #include "MagickCore/shear.h"
84 #include "MagickCore/splay-tree.h"
85 #include "MagickCore/statistic.h"
86 #include "MagickCore/string_.h"
87 #include "MagickCore/string-private.h"
88 #include "MagickCore/thread-private.h"
89 #include "MagickCore/transform.h"
90 #include "MagickCore/utility.h"
95 #define LeftShiftOperator 0xf5
96 #define RightShiftOperator 0xf6
97 #define LessThanEqualOperator 0xf7
98 #define GreaterThanEqualOperator 0xf8
99 #define EqualOperator 0xf9
100 #define NotEqualOperator 0xfa
101 #define LogicalAndOperator 0xfb
102 #define LogicalOrOperator 0xfc
103 #define ExponentialNotation 0xfd
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 + A c q u i r e F x I n f o %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % AcquireFxInfo() allocates the FxInfo structure.
143 % The format of the AcquireFxInfo method is:
145 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
147 % A description of each parameter follows:
149 % o image: the image.
151 % o expression: the expression.
154 MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
168 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
169 if (fx_info == (FxInfo *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
172 fx_info->exception=AcquireExceptionInfo();
173 fx_info->images=image;
174 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
177 RelinquishMagickMemory);
178 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
179 fx_info->images),sizeof(*fx_info->view));
180 if (fx_info->view == (CacheView **) NULL)
181 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
183 next=GetFirstImageInList(fx_info->images);
184 for ( ; next != (Image *) NULL; next=next->next)
186 fx_info->view[i]=AcquireCacheView(next);
189 fx_info->random_info=AcquireRandomInfo();
190 fx_info->expression=ConstantString(expression);
191 fx_info->file=stderr;
192 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
194 Force right-to-left associativity for unary negation.
196 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
197 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
198 (strstr(fx_info->expression,"e-") != (char *) NULL))
201 Convert scientific notation.
203 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
204 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
205 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
206 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
207 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
208 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
209 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
210 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
211 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
212 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
213 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
214 (void) SubstituteString(&fx_info->expression,"1e-1.0*","1**10^-");
215 (void) SubstituteString(&fx_info->expression,"2e-1.0*","2**10^-");
216 (void) SubstituteString(&fx_info->expression,"3e-1.0*","3**10^-");
217 (void) SubstituteString(&fx_info->expression,"4e-1.0*","4**10^-");
218 (void) SubstituteString(&fx_info->expression,"5e-1.0*","5**10^-");
219 (void) SubstituteString(&fx_info->expression,"6e-1.0*","6**10^-");
220 (void) SubstituteString(&fx_info->expression,"7e-1.0*","7**10^-");
221 (void) SubstituteString(&fx_info->expression,"8e-1.0*","8**10^-");
222 (void) SubstituteString(&fx_info->expression,"9e-1.0*","9**10^-");
224 if ((strstr(fx_info->expression,"E+") != (char *) NULL) ||
225 (strstr(fx_info->expression,"E-") != (char *) NULL))
228 Convert scientific notation.
230 (void) SubstituteString(&fx_info->expression,"0E+","0**10^");
231 (void) SubstituteString(&fx_info->expression,"1E+","1**10^");
232 (void) SubstituteString(&fx_info->expression,"2E+","2**10^");
233 (void) SubstituteString(&fx_info->expression,"3E+","3**10^");
234 (void) SubstituteString(&fx_info->expression,"4E+","4**10^");
235 (void) SubstituteString(&fx_info->expression,"5E+","5**10^");
236 (void) SubstituteString(&fx_info->expression,"6E+","6**10^");
237 (void) SubstituteString(&fx_info->expression,"7E+","7**10^");
238 (void) SubstituteString(&fx_info->expression,"8E+","8**10^");
239 (void) SubstituteString(&fx_info->expression,"9E+","9**10^");
240 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
241 (void) SubstituteString(&fx_info->expression,"1E-1.0*","1**10^-");
242 (void) SubstituteString(&fx_info->expression,"2E-1.0*","2**10^-");
243 (void) SubstituteString(&fx_info->expression,"3E-1.0*","3**10^-");
244 (void) SubstituteString(&fx_info->expression,"4E-1.0*","4**10^-");
245 (void) SubstituteString(&fx_info->expression,"5E-1.0*","5**10^-");
246 (void) SubstituteString(&fx_info->expression,"6E-1.0*","6**10^-");
247 (void) SubstituteString(&fx_info->expression,"7E-1.0*","7**10^-");
248 (void) SubstituteString(&fx_info->expression,"8E-1.0*","8**10^-");
249 (void) SubstituteString(&fx_info->expression,"9E-1.0*","9**10^-");
252 Convert complex to simple operators.
255 *fx_op=(char) LeftShiftOperator;
256 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
257 *fx_op=(char) RightShiftOperator;
258 (void) SubstituteString(&fx_info->expression,">>",fx_op);
259 *fx_op=(char) LessThanEqualOperator;
260 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
261 *fx_op=(char) GreaterThanEqualOperator;
262 (void) SubstituteString(&fx_info->expression,">=",fx_op);
263 *fx_op=(char) EqualOperator;
264 (void) SubstituteString(&fx_info->expression,"==",fx_op);
265 *fx_op=(char) NotEqualOperator;
266 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
267 *fx_op=(char) LogicalAndOperator;
268 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
269 *fx_op=(char) LogicalOrOperator;
270 (void) SubstituteString(&fx_info->expression,"||",fx_op);
271 *fx_op=(char) ExponentialNotation;
272 (void) SubstituteString(&fx_info->expression,"**",fx_op);
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 % A d d N o i s e I m a g e %
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 % AddNoiseImage() adds random noise to the image.
289 % The format of the AddNoiseImage method is:
291 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
292 % ExceptionInfo *exception)
294 % A description of each parameter follows:
296 % o image: the image.
298 % o channel: the channel type.
300 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
301 % Impulse, Laplacian, or Poisson.
303 % o exception: return any errors or warnings in this structure.
306 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, ExceptionInfo *exception)
308 #define AddNoiseImageTag "AddNoise/Image"
330 **restrict random_info;
336 Initialize noise image attributes.
338 assert(image != (const Image *) NULL);
339 assert(image->signature == MagickSignature);
340 if (image->debug != MagickFalse)
341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
342 assert(exception != (ExceptionInfo *) NULL);
343 assert(exception->signature == MagickSignature);
344 noise_image=CloneImage(image,0,0,MagickTrue,exception);
345 if (noise_image == (Image *) NULL)
346 return((Image *) NULL);
347 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
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,exception) == MagickFalse)
504 shift_image=DestroyImage(shift_image);
505 return((Image *) NULL);
508 Blue-shift DirectClass image.
512 image_view=AcquireCacheView(image);
513 shift_view=AcquireCacheView(shift_image);
514 #if defined(MAGICKCORE_OPENMP_SUPPORT)
515 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
517 for (y=0; y < (ssize_t) image->rows; y++)
528 register const Quantum
537 if (status == MagickFalse)
539 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
540 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
542 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
547 for (x=0; x < (ssize_t) image->columns; x++)
549 quantum=GetPixelRed(image,p);
550 if (GetPixelGreen(image,p) < quantum)
551 quantum=GetPixelGreen(image,p);
552 if (GetPixelBlue(image,p) < quantum)
553 quantum=GetPixelBlue(image,p);
554 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
555 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
556 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
557 quantum=GetPixelRed(image,p);
558 if (GetPixelGreen(image,p) > quantum)
559 quantum=GetPixelGreen(image,p);
560 if (GetPixelBlue(image,p) > quantum)
561 quantum=GetPixelBlue(image,p);
562 pixel.red=0.5*(pixel.red+factor*quantum);
563 pixel.green=0.5*(pixel.green+factor*quantum);
564 pixel.blue=0.5*(pixel.blue+factor*quantum);
565 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
566 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
567 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
568 p+=GetPixelChannels(image);
569 q+=GetPixelChannels(shift_image);
571 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
572 if (sync == MagickFalse)
574 if (image->progress_monitor != (MagickProgressMonitor) NULL)
579 #if defined(MAGICKCORE_OPENMP_SUPPORT)
580 #pragma omp critical (MagickCore_BlueShiftImage)
582 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
584 if (proceed == MagickFalse)
588 image_view=DestroyCacheView(image_view);
589 shift_view=DestroyCacheView(shift_view);
590 if (status == MagickFalse)
591 shift_image=DestroyImage(shift_image);
596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600 % C h a r c o a l I m a g e %
604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606 % CharcoalImage() creates a new image that is a copy of an existing one with
607 % the edge highlighted. It allocates the memory necessary for the new Image
608 % structure and returns a pointer to the new image.
610 % The format of the CharcoalImage method is:
612 % Image *CharcoalImage(const Image *image,const double radius,
613 % const double sigma,const double bias,ExceptionInfo *exception)
615 % A description of each parameter follows:
617 % o image: the image.
619 % o radius: the radius of the pixel neighborhood.
621 % o sigma: the standard deviation of the Gaussian, in pixels.
625 % o exception: return any errors or warnings in this structure.
628 MagickExport Image *CharcoalImage(const Image *image,const double radius,
629 const double sigma,const double bias,ExceptionInfo *exception)
636 assert(image != (Image *) NULL);
637 assert(image->signature == MagickSignature);
638 if (image->debug != MagickFalse)
639 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
640 assert(exception != (ExceptionInfo *) NULL);
641 assert(exception->signature == MagickSignature);
642 clone_image=CloneImage(image,0,0,MagickTrue,exception);
643 if (clone_image == (Image *) NULL)
644 return((Image *) NULL);
645 (void) SetImageType(clone_image,GrayscaleType,exception);
646 edge_image=EdgeImage(clone_image,radius,sigma,exception);
647 clone_image=DestroyImage(clone_image);
648 if (edge_image == (Image *) NULL)
649 return((Image *) NULL);
650 charcoal_image=BlurImage(edge_image,radius,sigma,bias,exception);
651 edge_image=DestroyImage(edge_image);
652 if (charcoal_image == (Image *) NULL)
653 return((Image *) NULL);
654 (void) NormalizeImage(charcoal_image,exception);
655 (void) NegateImage(charcoal_image,MagickFalse,exception);
656 (void) SetImageType(charcoal_image,GrayscaleType,exception);
657 return(charcoal_image);
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 % C o l o r i z e I m a g e %
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 % ColorizeImage() blends the fill color with each pixel in the image.
672 % A percentage blend is specified with opacity. Control the application
673 % of different color components by specifying a different percentage for
674 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
676 % The format of the ColorizeImage method is:
678 % Image *ColorizeImage(const Image *image,const char *opacity,
679 % const PixelPacket colorize,ExceptionInfo *exception)
681 % A description of each parameter follows:
683 % o image: the image.
685 % o opacity: A character string indicating the level of opacity as a
688 % o colorize: A color value.
690 % o exception: return any errors or warnings in this structure.
693 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
694 const PixelPacket colorize,ExceptionInfo *exception)
696 #define ColorizeImageTag "Colorize/Image"
724 Allocate colorized image.
726 assert(image != (const Image *) NULL);
727 assert(image->signature == MagickSignature);
728 if (image->debug != MagickFalse)
729 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
730 assert(exception != (ExceptionInfo *) NULL);
731 assert(exception->signature == MagickSignature);
732 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
734 if (colorize_image == (Image *) NULL)
735 return((Image *) NULL);
736 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
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,exception) == MagickFalse)
922 color_image=DestroyImage(color_image);
923 return((Image *) NULL);
925 if (image->debug != MagickFalse)
928 format[MaxTextExtent],
931 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
932 " ColorMatrix image with color matrix:");
933 message=AcquireString("");
934 for (v=0; v < 6; v++)
937 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
938 (void) ConcatenateString(&message,format);
939 for (u=0; u < 6; u++)
941 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
943 (void) ConcatenateString(&message,format);
945 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
947 message=DestroyString(message);
954 image_view=AcquireCacheView(image);
955 color_view=AcquireCacheView(color_image);
956 #if defined(MAGICKCORE_OPENMP_SUPPORT)
957 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
959 for (y=0; y < (ssize_t) image->rows; y++)
964 register const Quantum
973 if (status == MagickFalse)
975 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
976 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
978 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
983 for (x=0; x < (ssize_t) image->columns; x++)
991 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
992 for (v=0; v < (ssize_t) height; v++)
994 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
995 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
996 if (image->colorspace == CMYKColorspace)
997 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
998 if (image->matte != MagickFalse)
999 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1000 pixel+=QuantumRange*ColorMatrix[v][5];
1003 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1004 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1005 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
1008 if (image->colorspace == CMYKColorspace)
1009 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
1014 if (image->matte != MagickFalse)
1015 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
1020 p+=GetPixelChannels(image);
1021 q+=GetPixelChannels(color_image);
1023 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1025 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1030 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1031 #pragma omp critical (MagickCore_ColorMatrixImage)
1033 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1035 if (proceed == MagickFalse)
1039 color_view=DestroyCacheView(color_view);
1040 image_view=DestroyCacheView(image_view);
1041 if (status == MagickFalse)
1042 color_image=DestroyImage(color_image);
1043 return(color_image);
1047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051 + D e s t r o y F x I n f o %
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1057 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1059 % The format of the DestroyFxInfo method is:
1061 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1063 % A description of each parameter follows:
1065 % o fx_info: the fx info.
1068 MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
1073 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1074 fx_info->expression=DestroyString(fx_info->expression);
1075 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1076 fx_info->colors=DestroySplayTree(fx_info->colors);
1077 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1078 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1079 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1080 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1081 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090 + 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 %
1094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096 % FxEvaluateChannelExpression() evaluates an expression and returns the
1099 % The format of the FxEvaluateExpression method is:
1101 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1102 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1103 % MagickRealType *alpha,Exceptioninfo *exception)
1104 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1105 % MagickRealType *alpha,Exceptioninfo *exception)
1107 % A description of each parameter follows:
1109 % o fx_info: the fx info.
1111 % o channel: the channel.
1113 % o x,y: the pixel position.
1115 % o alpha: the result.
1117 % o exception: return any errors or warnings in this structure.
1121 static inline double MagickMax(const double x,const double y)
1128 static inline double MagickMin(const double x,const double y)
1135 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1136 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1140 statistic[MaxTextExtent];
1148 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1150 switch (*++p) /* e.g. depth.r */
1152 case 'r': channel=RedPixelChannel; break;
1153 case 'g': channel=GreenPixelChannel; break;
1154 case 'b': channel=BluePixelChannel; break;
1155 case 'c': channel=CyanPixelChannel; break;
1156 case 'm': channel=MagentaPixelChannel; break;
1157 case 'y': channel=YellowPixelChannel; break;
1158 case 'k': channel=BlackPixelChannel; break;
1161 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1162 (double) channel,symbol);
1163 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1164 if (value != (const char *) NULL)
1165 return(QuantumScale*InterpretLocaleValue(value,(char **) NULL));
1166 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1167 if (LocaleNCompare(symbol,"depth",5) == 0)
1172 depth=GetImageDepth(image,exception);
1173 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1175 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1181 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1182 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1184 if (LocaleNCompare(symbol,"maxima",6) == 0)
1190 (void) GetImageRange(image,&minima,&maxima,exception);
1191 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1193 if (LocaleNCompare(symbol,"mean",4) == 0)
1199 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1200 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1202 if (LocaleNCompare(symbol,"minima",6) == 0)
1208 (void) GetImageRange(image,&minima,&maxima,exception);
1209 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1211 if (LocaleNCompare(symbol,"skewness",8) == 0)
1217 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1218 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1220 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1226 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1227 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1228 standard_deviation);
1230 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1231 ConstantString(statistic));
1232 return(QuantumScale*InterpretLocaleValue(statistic,(char **) NULL));
1235 static MagickRealType
1236 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1237 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1239 static inline MagickRealType FxMax(FxInfo *fx_info,const PixelChannel channel,
1240 const ssize_t x,const ssize_t y,const char *expression,
1241 ExceptionInfo *exception)
1247 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1248 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1251 static inline MagickRealType FxMin(FxInfo *fx_info,PixelChannel channel,
1252 const ssize_t x,const ssize_t y,const char *expression,
1253 ExceptionInfo *exception)
1259 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1260 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1263 static inline const char *FxSubexpression(const char *expression,
1264 ExceptionInfo *exception)
1273 subexpression=expression;
1274 while ((*subexpression != '\0') &&
1275 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1277 if (strchr("(",(int) *subexpression) != (char *) NULL)
1280 if (strchr(")",(int) *subexpression) != (char *) NULL)
1284 if (*subexpression == '\0')
1285 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1286 "UnbalancedParenthesis","`%s'",expression);
1287 return(subexpression);
1290 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1291 const ssize_t x,const ssize_t y,const char *expression,
1292 ExceptionInfo *exception)
1296 subexpression[MaxTextExtent],
1297 symbol[MaxTextExtent];
1326 i=GetImageIndexInList(fx_info->images);
1330 if (isalpha((int) *(p+1)) == 0)
1332 if (strchr("suv",(int) *p) != (char *) NULL)
1339 i=GetImageIndexInList(fx_info->images);
1342 case 'u': i=0; break;
1343 case 'v': i=1; break;
1350 for (p++; *p != '\0'; )
1364 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1366 i=(ssize_t) (alpha+0.5);
1372 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1379 for (p++; *p != '\0'; )
1393 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1404 for (p++; *p != '\0'; )
1418 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1428 length=GetImageListLength(fx_info->images);
1430 i+=(ssize_t) length;
1432 image=GetImageFromList(fx_info->images,i);
1433 if (image == (Image *) NULL)
1435 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1436 "NoSuchImage","`%s'",expression);
1439 GetPixelInfo(image,&pixel);
1440 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1441 point.x,point.y,&pixel,exception);
1442 if ((strlen(p) > 2) &&
1443 (LocaleCompare(p,"intensity") != 0) &&
1444 (LocaleCompare(p,"luminance") != 0) &&
1445 (LocaleCompare(p,"hue") != 0) &&
1446 (LocaleCompare(p,"saturation") != 0) &&
1447 (LocaleCompare(p,"lightness") != 0))
1450 name[MaxTextExtent];
1452 (void) CopyMagickString(name,p,MaxTextExtent);
1453 for (q=name+(strlen(name)-1); q > name; q--)
1463 if ((strlen(name) > 2) &&
1464 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1469 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1470 if (color != (PixelInfo *) NULL)
1476 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1478 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1479 ClonePixelInfo(&pixel));
1484 (void) CopyMagickString(symbol,p,MaxTextExtent);
1485 StripString(symbol);
1486 if (*symbol == '\0')
1490 case RedPixelChannel: return(QuantumScale*pixel.red);
1491 case GreenPixelChannel: return(QuantumScale*pixel.green);
1492 case BluePixelChannel: return(QuantumScale*pixel.blue);
1493 case BlackPixelChannel:
1495 if (image->colorspace != CMYKColorspace)
1497 (void) ThrowMagickException(exception,GetMagickModule(),
1498 OptionError,"ColorSeparatedImageRequired","`%s'",
1502 return(QuantumScale*pixel.black);
1504 case AlphaPixelChannel:
1509 if (pixel.matte == MagickFalse)
1511 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1514 case IntensityPixelChannel:
1516 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1521 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1522 "UnableToParseExpression","`%s'",p);
1530 if (LocaleCompare(symbol,"a") == 0)
1531 return((MagickRealType) (QuantumScale*pixel.alpha));
1537 if (LocaleCompare(symbol,"b") == 0)
1538 return(QuantumScale*pixel.blue);
1544 if (LocaleNCompare(symbol,"channel",7) == 0)
1552 flags=ParseGeometry(symbol+7,&channel_info);
1553 if (image->colorspace == CMYKColorspace)
1556 case CyanPixelChannel:
1558 if ((flags & RhoValue) == 0)
1560 return(channel_info.rho);
1562 case MagentaPixelChannel:
1564 if ((flags & SigmaValue) == 0)
1566 return(channel_info.sigma);
1568 case YellowPixelChannel:
1570 if ((flags & XiValue) == 0)
1572 return(channel_info.xi);
1574 case BlackPixelChannel:
1576 if ((flags & PsiValue) == 0)
1578 return(channel_info.psi);
1580 case AlphaPixelChannel:
1582 if ((flags & ChiValue) == 0)
1584 return(channel_info.chi);
1591 case RedPixelChannel:
1593 if ((flags & RhoValue) == 0)
1595 return(channel_info.rho);
1597 case GreenPixelChannel:
1599 if ((flags & SigmaValue) == 0)
1601 return(channel_info.sigma);
1603 case BluePixelChannel:
1605 if ((flags & XiValue) == 0)
1607 return(channel_info.xi);
1609 case BlackPixelChannel:
1611 if ((flags & ChiValue) == 0)
1613 return(channel_info.chi);
1615 case AlphaPixelChannel:
1617 if ((flags & PsiValue) == 0)
1619 return(channel_info.psi);
1626 if (LocaleCompare(symbol,"c") == 0)
1627 return(QuantumScale*pixel.red);
1633 if (LocaleNCompare(symbol,"depth",5) == 0)
1634 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1640 if (LocaleCompare(symbol,"g") == 0)
1641 return(QuantumScale*pixel.green);
1647 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1648 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1649 if (LocaleCompare(symbol,"k") == 0)
1651 if (image->colorspace != CMYKColorspace)
1653 (void) ThrowMagickException(exception,GetMagickModule(),
1654 OptionError,"ColorSeparatedImageRequired","`%s'",
1658 return(QuantumScale*pixel.black);
1665 if (LocaleCompare(symbol,"h") == 0)
1666 return((MagickRealType) image->rows);
1667 if (LocaleCompare(symbol,"hue") == 0)
1674 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1675 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1683 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1684 (LocaleCompare(symbol,"image.minima") == 0) ||
1685 (LocaleCompare(symbol,"image.maxima") == 0) ||
1686 (LocaleCompare(symbol,"image.mean") == 0) ||
1687 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1688 (LocaleCompare(symbol,"image.skewness") == 0) ||
1689 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1690 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1691 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1692 return(image->x_resolution);
1693 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1694 return(image->y_resolution);
1695 if (LocaleCompare(symbol,"intensity") == 0)
1696 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1697 if (LocaleCompare(symbol,"i") == 0)
1698 return((MagickRealType) x);
1704 if (LocaleCompare(symbol,"j") == 0)
1705 return((MagickRealType) y);
1711 if (LocaleCompare(symbol,"lightness") == 0)
1718 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1719 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1722 if (LocaleCompare(symbol,"luminance") == 0)
1727 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1728 return(QuantumScale*luminence);
1735 if (LocaleNCompare(symbol,"maxima",6) == 0)
1736 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1737 if (LocaleNCompare(symbol,"mean",4) == 0)
1738 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1739 if (LocaleNCompare(symbol,"minima",6) == 0)
1740 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1741 if (LocaleCompare(symbol,"m") == 0)
1742 return(QuantumScale*pixel.blue);
1748 if (LocaleCompare(symbol,"n") == 0)
1749 return((MagickRealType) GetImageListLength(fx_info->images));
1755 if (LocaleCompare(symbol,"o") == 0)
1756 return(QuantumScale*pixel.alpha);
1762 if (LocaleCompare(symbol,"page.height") == 0)
1763 return((MagickRealType) image->page.height);
1764 if (LocaleCompare(symbol,"page.width") == 0)
1765 return((MagickRealType) image->page.width);
1766 if (LocaleCompare(symbol,"page.x") == 0)
1767 return((MagickRealType) image->page.x);
1768 if (LocaleCompare(symbol,"page.y") == 0)
1769 return((MagickRealType) image->page.y);
1775 if (LocaleCompare(symbol,"resolution.x") == 0)
1776 return(image->x_resolution);
1777 if (LocaleCompare(symbol,"resolution.y") == 0)
1778 return(image->y_resolution);
1779 if (LocaleCompare(symbol,"r") == 0)
1780 return(QuantumScale*pixel.red);
1786 if (LocaleCompare(symbol,"saturation") == 0)
1793 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1794 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1797 if (LocaleNCompare(symbol,"skewness",8) == 0)
1798 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1799 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1800 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1806 if (LocaleCompare(symbol,"t") == 0)
1807 return((MagickRealType) GetImageIndexInList(fx_info->images));
1813 if (LocaleCompare(symbol,"w") == 0)
1814 return((MagickRealType) image->columns);
1820 if (LocaleCompare(symbol,"y") == 0)
1821 return(QuantumScale*pixel.green);
1827 if (LocaleCompare(symbol,"z") == 0)
1832 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1840 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1841 if (value != (const char *) NULL)
1842 return((MagickRealType) InterpretLocaleValue(value,(char **) NULL));
1843 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1844 "UnableToParseExpression","`%s'",symbol);
1848 static const char *FxOperatorPrecedence(const char *expression,
1849 ExceptionInfo *exception)
1853 UndefinedPrecedence,
1855 BitwiseComplementPrecedence,
1857 ExponentialNotationPrecedence,
1861 RelationalPrecedence,
1862 EquivalencyPrecedence,
1863 BitwiseAndPrecedence,
1864 BitwiseOrPrecedence,
1865 LogicalAndPrecedence,
1866 LogicalOrPrecedence,
1868 AssignmentPrecedence,
1888 subexpression=(const char *) NULL;
1889 target=NullPrecedence;
1890 while (*expression != '\0')
1892 precedence=UndefinedPrecedence;
1893 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1898 switch (*expression)
1903 #if defined(MAGICKCORE_HAVE_ACOSH)
1904 if (LocaleNCompare(expression,"acosh",5) == 0)
1910 #if defined(MAGICKCORE_HAVE_ASINH)
1911 if (LocaleNCompare(expression,"asinh",5) == 0)
1917 #if defined(MAGICKCORE_HAVE_ATANH)
1918 if (LocaleNCompare(expression,"atanh",5) == 0)
1929 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1930 (LocaleNCompare(expression,"j1",2) == 0))
1939 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1946 if ((c == (int) '{') || (c == (int) '['))
1949 if ((c == (int) '}') || (c == (int) ']'))
1952 switch ((unsigned char) *expression)
1957 precedence=BitwiseComplementPrecedence;
1963 precedence=ExponentPrecedence;
1968 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1969 (strchr(")",c) != (char *) NULL))) &&
1970 (((islower((int) ((char) *expression)) != 0) ||
1971 (strchr("(",(int) *expression) != (char *) NULL)) ||
1972 ((isdigit((int) ((char) c)) == 0) &&
1973 (isdigit((int) ((char) *expression)) != 0))) &&
1974 (strchr("xy",(int) *expression) == (char *) NULL))
1975 precedence=MultiplyPrecedence;
1982 precedence=MultiplyPrecedence;
1988 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1990 precedence=AdditionPrecedence;
1993 case LeftShiftOperator:
1994 case RightShiftOperator:
1996 precedence=ShiftPrecedence;
2000 case LessThanEqualOperator:
2001 case GreaterThanEqualOperator:
2004 precedence=RelationalPrecedence;
2008 case NotEqualOperator:
2010 precedence=EquivalencyPrecedence;
2015 precedence=BitwiseAndPrecedence;
2020 precedence=BitwiseOrPrecedence;
2023 case LogicalAndOperator:
2025 precedence=LogicalAndPrecedence;
2028 case LogicalOrOperator:
2030 precedence=LogicalOrPrecedence;
2033 case ExponentialNotation:
2035 precedence=ExponentialNotationPrecedence;
2041 precedence=TernaryPrecedence;
2046 precedence=AssignmentPrecedence;
2051 precedence=CommaPrecedence;
2056 precedence=SeparatorPrecedence;
2060 if ((precedence == BitwiseComplementPrecedence) ||
2061 (precedence == TernaryPrecedence) ||
2062 (precedence == AssignmentPrecedence))
2064 if (precedence > target)
2067 Right-to-left associativity.
2070 subexpression=expression;
2074 if (precedence >= target)
2077 Left-to-right associativity.
2080 subexpression=expression;
2082 if (strchr("(",(int) *expression) != (char *) NULL)
2083 expression=FxSubexpression(expression,exception);
2084 c=(int) (*expression++);
2086 return(subexpression);
2089 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2090 const PixelChannel channel,const ssize_t x,const ssize_t y,
2091 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2095 subexpression[MaxTextExtent];
2105 if (exception->severity != UndefinedException)
2107 while (isspace((int) *expression) != 0)
2109 if (*expression == '\0')
2111 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2112 "MissingExpression","`%s'",expression);
2115 *subexpression='\0';
2116 p=FxOperatorPrecedence(expression,exception);
2117 if (p != (const char *) NULL)
2119 (void) CopyMagickString(subexpression,expression,(size_t)
2121 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2123 switch ((unsigned char) *p)
2127 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2128 *beta=(MagickRealType) (~(size_t) *beta);
2133 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2134 return(*beta == 0.0 ? 1.0 : 0.0);
2138 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2139 channel,x,y,++p,beta,exception));
2143 case ExponentialNotation:
2145 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2146 return(alpha*(*beta));
2150 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2153 if (exception->severity == UndefinedException)
2154 (void) ThrowMagickException(exception,GetMagickModule(),
2155 OptionError,"DivideByZero","`%s'",expression);
2158 return(alpha/(*beta));
2162 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2163 *beta=fabs(floor(((double) *beta)+0.5));
2166 (void) ThrowMagickException(exception,GetMagickModule(),
2167 OptionError,"DivideByZero","`%s'",expression);
2170 return(fmod((double) alpha,(double) *beta));
2174 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2175 return(alpha+(*beta));
2179 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2180 return(alpha-(*beta));
2182 case LeftShiftOperator:
2184 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2185 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2189 case RightShiftOperator:
2191 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2192 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2198 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2199 return(alpha < *beta ? 1.0 : 0.0);
2201 case LessThanEqualOperator:
2203 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2204 return(alpha <= *beta ? 1.0 : 0.0);
2208 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2209 return(alpha > *beta ? 1.0 : 0.0);
2211 case GreaterThanEqualOperator:
2213 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2214 return(alpha >= *beta ? 1.0 : 0.0);
2218 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2219 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2221 case NotEqualOperator:
2223 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2224 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2228 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2229 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2235 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2236 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2240 case LogicalAndOperator:
2242 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2243 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2246 case LogicalOrOperator:
2248 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2249 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2257 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2259 p=StringToken(":",&q);
2260 if (q == (char *) NULL)
2262 (void) ThrowMagickException(exception,GetMagickModule(),
2263 OptionError,"UnableToParseExpression","`%s'",subexpression);
2266 if (fabs((double) alpha) > MagickEpsilon)
2267 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2269 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2275 numeric[MaxTextExtent];
2278 while (isalpha((int) ((unsigned char) *q)) != 0)
2282 (void) ThrowMagickException(exception,GetMagickModule(),
2283 OptionError,"UnableToParseExpression","`%s'",subexpression);
2286 ClearMagickException(exception);
2287 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2288 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2290 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2291 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2292 subexpression),ConstantString(numeric));
2297 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2302 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2307 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2313 if (strchr("(",(int) *expression) != (char *) NULL)
2315 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2316 subexpression[strlen(subexpression)-1]='\0';
2317 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2321 switch (*expression)
2325 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2331 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2337 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2339 return((MagickRealType) (~(size_t) (gamma+0.5)));
2344 if (LocaleNCompare(expression,"abs",3) == 0)
2346 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2348 return((MagickRealType) fabs((double) alpha));
2350 #if defined(MAGICKCORE_HAVE_ACOSH)
2351 if (LocaleNCompare(expression,"acosh",5) == 0)
2353 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2355 return((MagickRealType) acosh((double) alpha));
2358 if (LocaleNCompare(expression,"acos",4) == 0)
2360 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2362 return((MagickRealType) acos((double) alpha));
2364 #if defined(MAGICKCORE_HAVE_J1)
2365 if (LocaleNCompare(expression,"airy",4) == 0)
2367 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2371 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2372 return(gamma*gamma);
2375 #if defined(MAGICKCORE_HAVE_ASINH)
2376 if (LocaleNCompare(expression,"asinh",5) == 0)
2378 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2380 return((MagickRealType) asinh((double) alpha));
2383 if (LocaleNCompare(expression,"asin",4) == 0)
2385 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2387 return((MagickRealType) asin((double) alpha));
2389 if (LocaleNCompare(expression,"alt",3) == 0)
2391 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2393 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2395 if (LocaleNCompare(expression,"atan2",5) == 0)
2397 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2399 return((MagickRealType) atan2((double) alpha,(double) *beta));
2401 #if defined(MAGICKCORE_HAVE_ATANH)
2402 if (LocaleNCompare(expression,"atanh",5) == 0)
2404 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2406 return((MagickRealType) atanh((double) alpha));
2409 if (LocaleNCompare(expression,"atan",4) == 0)
2411 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2413 return((MagickRealType) atan((double) alpha));
2415 if (LocaleCompare(expression,"a") == 0)
2416 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2422 if (LocaleCompare(expression,"b") == 0)
2423 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2429 if (LocaleNCompare(expression,"ceil",4) == 0)
2431 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2433 return((MagickRealType) ceil((double) alpha));
2435 if (LocaleNCompare(expression,"cosh",4) == 0)
2437 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2439 return((MagickRealType) cosh((double) alpha));
2441 if (LocaleNCompare(expression,"cos",3) == 0)
2443 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2445 return((MagickRealType) cos((double) alpha));
2447 if (LocaleCompare(expression,"c") == 0)
2448 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2454 if (LocaleNCompare(expression,"debug",5) == 0)
2459 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2461 if (fx_info->images->colorspace == CMYKColorspace)
2464 case CyanPixelChannel: type="cyan"; break;
2465 case MagentaPixelChannel: type="magenta"; break;
2466 case YellowPixelChannel: type="yellow"; break;
2467 case AlphaPixelChannel: type="opacity"; break;
2468 case BlackPixelChannel: type="black"; break;
2469 default: type="unknown"; break;
2474 case RedPixelChannel: type="red"; break;
2475 case GreenPixelChannel: type="green"; break;
2476 case BluePixelChannel: type="blue"; break;
2477 case AlphaPixelChannel: type="opacity"; break;
2478 default: type="unknown"; break;
2480 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2481 if (strlen(subexpression) > 1)
2482 subexpression[strlen(subexpression)-1]='\0';
2483 if (fx_info->file != (FILE *) NULL)
2484 (void) FormatLocaleFile(fx_info->file,
2485 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2486 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2495 if (LocaleCompare(expression,"epsilon") == 0)
2496 return((MagickRealType) MagickEpsilon);
2497 if (LocaleNCompare(expression,"exp",3) == 0)
2499 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2501 return((MagickRealType) exp((double) alpha));
2503 if (LocaleCompare(expression,"e") == 0)
2504 return((MagickRealType) 2.7182818284590452354);
2510 if (LocaleNCompare(expression,"floor",5) == 0)
2512 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2514 return((MagickRealType) floor((double) alpha));
2521 if (LocaleCompare(expression,"g") == 0)
2522 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2528 if (LocaleCompare(expression,"h") == 0)
2529 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2530 if (LocaleCompare(expression,"hue") == 0)
2531 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2532 if (LocaleNCompare(expression,"hypot",5) == 0)
2534 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2536 return((MagickRealType) hypot((double) alpha,(double) *beta));
2543 if (LocaleCompare(expression,"k") == 0)
2544 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2550 if (LocaleCompare(expression,"intensity") == 0)
2551 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2552 if (LocaleNCompare(expression,"int",3) == 0)
2554 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2556 return((MagickRealType) floor(alpha));
2558 if (LocaleCompare(expression,"i") == 0)
2559 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2565 if (LocaleCompare(expression,"j") == 0)
2566 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2567 #if defined(MAGICKCORE_HAVE_J0)
2568 if (LocaleNCompare(expression,"j0",2) == 0)
2570 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2572 return((MagickRealType) j0((double) alpha));
2575 #if defined(MAGICKCORE_HAVE_J1)
2576 if (LocaleNCompare(expression,"j1",2) == 0)
2578 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2580 return((MagickRealType) j1((double) alpha));
2583 #if defined(MAGICKCORE_HAVE_J1)
2584 if (LocaleNCompare(expression,"jinc",4) == 0)
2586 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2590 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2600 if (LocaleNCompare(expression,"ln",2) == 0)
2602 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2604 return((MagickRealType) log((double) alpha));
2606 if (LocaleNCompare(expression,"logtwo",6) == 0)
2608 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2610 return((MagickRealType) log10((double) alpha))/log10(2.0);
2612 if (LocaleNCompare(expression,"log",3) == 0)
2614 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2616 return((MagickRealType) log10((double) alpha));
2618 if (LocaleCompare(expression,"lightness") == 0)
2619 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2625 if (LocaleCompare(expression,"MaxRGB") == 0)
2626 return((MagickRealType) QuantumRange);
2627 if (LocaleNCompare(expression,"maxima",6) == 0)
2629 if (LocaleNCompare(expression,"max",3) == 0)
2630 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2631 if (LocaleNCompare(expression,"minima",6) == 0)
2633 if (LocaleNCompare(expression,"min",3) == 0)
2634 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2635 if (LocaleNCompare(expression,"mod",3) == 0)
2637 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2639 return((MagickRealType) fmod((double) alpha,(double) *beta));
2641 if (LocaleCompare(expression,"m") == 0)
2642 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2648 if (LocaleCompare(expression,"n") == 0)
2649 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2655 if (LocaleCompare(expression,"Opaque") == 0)
2657 if (LocaleCompare(expression,"o") == 0)
2658 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2664 if (LocaleCompare(expression,"pi") == 0)
2665 return((MagickRealType) MagickPI);
2666 if (LocaleNCompare(expression,"pow",3) == 0)
2668 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2670 return((MagickRealType) pow((double) alpha,(double) *beta));
2672 if (LocaleCompare(expression,"p") == 0)
2673 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2679 if (LocaleCompare(expression,"QuantumRange") == 0)
2680 return((MagickRealType) QuantumRange);
2681 if (LocaleCompare(expression,"QuantumScale") == 0)
2682 return((MagickRealType) QuantumScale);
2688 if (LocaleNCompare(expression,"rand",4) == 0)
2689 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2690 if (LocaleNCompare(expression,"round",5) == 0)
2692 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2694 return((MagickRealType) floor((double) alpha+0.5));
2696 if (LocaleCompare(expression,"r") == 0)
2697 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2703 if (LocaleCompare(expression,"saturation") == 0)
2704 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2705 if (LocaleNCompare(expression,"sign",4) == 0)
2707 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2709 return(alpha < 0.0 ? -1.0 : 1.0);
2711 if (LocaleNCompare(expression,"sinc",4) == 0)
2713 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2717 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2721 if (LocaleNCompare(expression,"sinh",4) == 0)
2723 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2725 return((MagickRealType) sinh((double) alpha));
2727 if (LocaleNCompare(expression,"sin",3) == 0)
2729 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2731 return((MagickRealType) sin((double) alpha));
2733 if (LocaleNCompare(expression,"sqrt",4) == 0)
2735 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2737 return((MagickRealType) sqrt((double) alpha));
2739 if (LocaleCompare(expression,"s") == 0)
2740 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2746 if (LocaleNCompare(expression,"tanh",4) == 0)
2748 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2750 return((MagickRealType) tanh((double) alpha));
2752 if (LocaleNCompare(expression,"tan",3) == 0)
2754 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2756 return((MagickRealType) tan((double) alpha));
2758 if (LocaleCompare(expression,"Transparent") == 0)
2760 if (LocaleNCompare(expression,"trunc",5) == 0)
2762 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2765 return((MagickRealType) floor((double) alpha));
2766 return((MagickRealType) ceil((double) alpha));
2768 if (LocaleCompare(expression,"t") == 0)
2769 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2775 if (LocaleCompare(expression,"u") == 0)
2776 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2782 if (LocaleCompare(expression,"v") == 0)
2783 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2789 if (LocaleCompare(expression,"w") == 0)
2790 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2796 if (LocaleCompare(expression,"y") == 0)
2797 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2803 if (LocaleCompare(expression,"z") == 0)
2804 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2810 q=(char *) expression;
2811 alpha=InterpretLocaleValue(expression,&q);
2812 if (q == expression)
2813 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2817 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2818 MagickRealType *alpha,ExceptionInfo *exception)
2823 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2828 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2829 MagickRealType *alpha,ExceptionInfo *exception)
2838 fx_info->file=(FILE *) NULL;
2839 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2845 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2846 const PixelChannel channel,const ssize_t x,const ssize_t y,
2847 MagickRealType *alpha,ExceptionInfo *exception)
2853 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2855 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2869 % FxImage() applies a mathematical expression to the specified image.
2871 % The format of the FxImage method is:
2873 % Image *FxImage(const Image *image,const char *expression,
2874 % ExceptionInfo *exception)
2876 % A description of each parameter follows:
2878 % o image: the image.
2880 % o expression: A mathematical expression.
2882 % o exception: return any errors or warnings in this structure.
2886 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2891 assert(fx_info != (FxInfo **) NULL);
2892 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2893 if (fx_info[i] != (FxInfo *) NULL)
2894 fx_info[i]=DestroyFxInfo(fx_info[i]);
2895 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2899 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2900 ExceptionInfo *exception)
2917 number_threads=GetOpenMPMaximumThreads();
2918 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2919 if (fx_info == (FxInfo **) NULL)
2920 return((FxInfo **) NULL);
2921 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2922 if (*expression != '@')
2923 fx_expression=ConstantString(expression);
2925 fx_expression=FileToString(expression+1,~0,exception);
2926 for (i=0; i < (ssize_t) number_threads; i++)
2928 fx_info[i]=AcquireFxInfo(image,fx_expression);
2929 if (fx_info[i] == (FxInfo *) NULL)
2930 return(DestroyFxThreadSet(fx_info));
2931 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2933 fx_expression=DestroyString(fx_expression);
2937 MagickExport Image *FxImage(const Image *image,const char *expression,
2938 ExceptionInfo *exception)
2940 #define FxImageTag "Fx/Image"
2964 assert(image != (Image *) NULL);
2965 assert(image->signature == MagickSignature);
2966 if (image->debug != MagickFalse)
2967 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2968 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2969 if (fx_image == (Image *) NULL)
2970 return((Image *) NULL);
2971 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
2973 fx_image=DestroyImage(fx_image);
2974 return((Image *) NULL);
2976 fx_info=AcquireFxThreadSet(image,expression,exception);
2977 if (fx_info == (FxInfo **) NULL)
2979 fx_image=DestroyImage(fx_image);
2980 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2982 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2983 if (status == MagickFalse)
2985 fx_image=DestroyImage(fx_image);
2986 fx_info=DestroyFxThreadSet(fx_info);
2987 return((Image *) NULL);
2994 image_view=AcquireCacheView(image);
2995 fx_view=AcquireCacheView(fx_image);
2996 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2997 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2999 for (y=0; y < (ssize_t) fx_image->rows; y++)
3002 id = GetOpenMPThreadId();
3004 register const Quantum
3013 if (status == MagickFalse)
3015 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3016 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3017 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3022 for (x=0; x < (ssize_t) fx_image->columns; x++)
3027 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3039 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3040 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3041 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3042 if ((traits == UndefinedPixelTrait) ||
3043 (fx_traits == UndefinedPixelTrait))
3045 if ((fx_traits & CopyPixelTrait) != 0)
3051 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3053 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3055 p+=GetPixelChannels(image);
3056 q+=GetPixelChannels(fx_image);
3058 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3060 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3065 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3066 #pragma omp critical (MagickCore_FxImage)
3068 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3069 if (proceed == MagickFalse)
3073 fx_view=DestroyCacheView(fx_view);
3074 image_view=DestroyCacheView(image_view);
3075 fx_info=DestroyFxThreadSet(fx_info);
3076 if (status == MagickFalse)
3077 fx_image=DestroyImage(fx_image);
3082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3086 % I m p l o d e I m a g e %
3090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3092 % ImplodeImage() creates a new image that is a copy of an existing
3093 % one with the image pixels "implode" by the specified percentage. It
3094 % allocates the memory necessary for the new Image structure and returns a
3095 % pointer to the new image.
3097 % The format of the ImplodeImage method is:
3099 % Image *ImplodeImage(const Image *image,const double amount,
3100 % ExceptionInfo *exception)
3102 % A description of each parameter follows:
3104 % o implode_image: Method ImplodeImage returns a pointer to the image
3105 % after it is implode. A null image is returned if there is a memory
3108 % o image: the image.
3110 % o amount: Define the extent of the implosion.
3112 % o exception: return any errors or warnings in this structure.
3115 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3116 ExceptionInfo *exception)
3118 #define ImplodeImageTag "Implode/Image"
3147 Initialize implode image attributes.
3149 assert(image != (Image *) NULL);
3150 assert(image->signature == MagickSignature);
3151 if (image->debug != MagickFalse)
3152 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3153 assert(exception != (ExceptionInfo *) NULL);
3154 assert(exception->signature == MagickSignature);
3155 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3156 if (implode_image == (Image *) NULL)
3157 return((Image *) NULL);
3158 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3160 implode_image=DestroyImage(implode_image);
3161 return((Image *) NULL);
3163 if (implode_image->background_color.alpha != OpaqueAlpha)
3164 implode_image->matte=MagickTrue;
3166 Compute scaling factor.
3170 center.x=0.5*image->columns;
3171 center.y=0.5*image->rows;
3173 if (image->columns > image->rows)
3174 scale.y=(double) image->columns/(double) image->rows;
3176 if (image->columns < image->rows)
3178 scale.x=(double) image->rows/(double) image->columns;
3186 GetPixelInfo(implode_image,&zero);
3187 image_view=AcquireCacheView(image);
3188 implode_view=AcquireCacheView(implode_image);
3189 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3190 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3192 for (y=0; y < (ssize_t) image->rows; y++)
3209 if (status == MagickFalse)
3211 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3213 if (q == (Quantum *) NULL)
3218 delta.y=scale.y*(double) (y-center.y);
3220 for (x=0; x < (ssize_t) image->columns; x++)
3223 Determine if the pixel is within an ellipse.
3225 delta.x=scale.x*(double) (x-center.x);
3226 distance=delta.x*delta.x+delta.y*delta.y;
3227 if (distance < (radius*radius))
3237 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3238 radius/2)),-amount);
3239 (void) InterpolatePixelInfo(image,image_view,
3240 UndefinedInterpolatePixel,(double) (factor*delta.x/scale.x+
3241 center.x),(double) (factor*delta.y/scale.y+center.y),&pixel,
3243 SetPixelPixelInfo(implode_image,&pixel,q);
3245 q+=GetPixelChannels(implode_image);
3247 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3249 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3254 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3255 #pragma omp critical (MagickCore_ImplodeImage)
3257 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3258 if (proceed == MagickFalse)
3262 implode_view=DestroyCacheView(implode_view);
3263 image_view=DestroyCacheView(image_view);
3264 if (status == MagickFalse)
3265 implode_image=DestroyImage(implode_image);
3266 return(implode_image);
3270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3274 % M o r p h I m a g e s %
3278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3280 % The MorphImages() method requires a minimum of two images. The first
3281 % image is transformed into the second by a number of intervening images
3282 % as specified by frames.
3284 % The format of the MorphImage method is:
3286 % Image *MorphImages(const Image *image,const size_t number_frames,
3287 % ExceptionInfo *exception)
3289 % A description of each parameter follows:
3291 % o image: the image.
3293 % o number_frames: Define the number of in-between image to generate.
3294 % The more in-between frames, the smoother the morph.
3296 % o exception: return any errors or warnings in this structure.
3299 MagickExport Image *MorphImages(const Image *image,
3300 const size_t number_frames,ExceptionInfo *exception)
3302 #define MorphImageTag "Morph/Image"
3318 register const Image
3328 Clone first frame in sequence.
3330 assert(image != (Image *) NULL);
3331 assert(image->signature == MagickSignature);
3332 if (image->debug != MagickFalse)
3333 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3334 assert(exception != (ExceptionInfo *) NULL);
3335 assert(exception->signature == MagickSignature);
3336 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3337 if (morph_images == (Image *) NULL)
3338 return((Image *) NULL);
3339 if (GetNextImageInList(image) == (Image *) NULL)
3344 for (i=1; i < (ssize_t) number_frames; i++)
3346 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3347 if (morph_image == (Image *) NULL)
3349 morph_images=DestroyImageList(morph_images);
3350 return((Image *) NULL);
3352 AppendImageToList(&morph_images,morph_image);
3353 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3358 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3360 if (proceed == MagickFalse)
3364 return(GetFirstImageInList(morph_images));
3367 Morph image sequence.
3372 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3374 for (i=0; i < (ssize_t) number_frames; i++)
3380 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3382 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3383 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3384 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3385 next->filter,next->blur,exception);
3386 if (morph_image == (Image *) NULL)
3388 morph_images=DestroyImageList(morph_images);
3389 return((Image *) NULL);
3391 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
3393 morph_image=DestroyImage(morph_image);
3394 return((Image *) NULL);
3396 AppendImageToList(&morph_images,morph_image);
3397 morph_images=GetLastImageInList(morph_images);
3398 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3399 morph_images->rows,GetNextImageInList(next)->filter,
3400 GetNextImageInList(next)->blur,exception);
3401 if (morph_image == (Image *) NULL)
3403 morph_images=DestroyImageList(morph_images);
3404 return((Image *) NULL);
3406 image_view=AcquireCacheView(morph_image);
3407 morph_view=AcquireCacheView(morph_images);
3408 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3409 #pragma omp parallel for schedule(dynamic,4) shared(status)
3411 for (y=0; y < (ssize_t) morph_images->rows; y++)
3416 register const Quantum
3425 if (status == MagickFalse)
3427 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3429 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3431 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3436 for (x=0; x < (ssize_t) morph_images->columns; x++)
3438 SetPixelRed(morph_images,ClampToQuantum(alpha*
3439 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3440 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3441 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3442 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3443 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3444 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3445 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3446 if ((morph_image->colorspace == CMYKColorspace) &&
3447 (morph_images->colorspace == CMYKColorspace))
3448 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3449 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3451 p+=GetPixelChannels(morph_image);
3452 q+=GetPixelChannels(morph_images);
3454 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3455 if (sync == MagickFalse)
3458 morph_view=DestroyCacheView(morph_view);
3459 image_view=DestroyCacheView(image_view);
3460 morph_image=DestroyImage(morph_image);
3462 if (i < (ssize_t) number_frames)
3465 Clone last frame in sequence.
3467 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3468 if (morph_image == (Image *) NULL)
3470 morph_images=DestroyImageList(morph_images);
3471 return((Image *) NULL);
3473 AppendImageToList(&morph_images,morph_image);
3474 morph_images=GetLastImageInList(morph_images);
3475 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3480 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3481 #pragma omp critical (MagickCore_MorphImages)
3483 proceed=SetImageProgress(image,MorphImageTag,scene,
3484 GetImageListLength(image));
3485 if (proceed == MagickFalse)
3490 if (GetNextImageInList(next) != (Image *) NULL)
3492 morph_images=DestroyImageList(morph_images);
3493 return((Image *) NULL);
3495 return(GetFirstImageInList(morph_images));
3499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3503 % P l a s m a I m a g e %
3507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3509 % PlasmaImage() initializes an image with plasma fractal values. The image
3510 % must be initialized with a base color and the random number generator
3511 % seeded before this method is called.
3513 % The format of the PlasmaImage method is:
3515 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3516 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3518 % A description of each parameter follows:
3520 % o image: the image.
3522 % o segment: Define the region to apply plasma fractals values.
3524 % o attenuate: Define the plasma attenuation factor.
3526 % o depth: Limit the plasma recursion depth.
3528 % o exception: return any errors or warnings in this structure.
3532 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3533 const MagickRealType pixel,const MagickRealType noise)
3538 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3543 static MagickBooleanType PlasmaImageProxy(Image *image,
3544 CacheView *image_view,RandomInfo *random_info,const SegmentInfo *segment,
3545 size_t attenuate,size_t depth,ExceptionInfo *exception)
3560 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3568 Divide the area into quadrants and recurse.
3572 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3573 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3574 local_info=(*segment);
3575 local_info.x2=(double) x_mid;
3576 local_info.y2=(double) y_mid;
3577 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3578 attenuate,depth,exception);
3579 local_info=(*segment);
3580 local_info.y1=(double) y_mid;
3581 local_info.x2=(double) x_mid;
3582 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3583 attenuate,depth,exception);
3584 local_info=(*segment);
3585 local_info.x1=(double) x_mid;
3586 local_info.y2=(double) y_mid;
3587 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3588 attenuate,depth,exception);
3589 local_info=(*segment);
3590 local_info.x1=(double) x_mid;
3591 local_info.y1=(double) y_mid;
3592 return(PlasmaImageProxy(image,image_view,random_info,&local_info,
3593 attenuate,depth,exception));
3595 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3596 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3597 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3598 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3599 return(MagickFalse);
3601 Average pixels and apply plasma.
3603 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3604 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3612 x=(ssize_t) ceil(segment->x1-0.5);
3613 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3614 ceil(segment->y1-0.5),&u,exception);
3615 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3616 ceil(segment->y2-0.5),&v,exception);
3617 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3618 if (q == (Quantum *) NULL)
3620 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3621 (u.red+v.red)/2.0,plasma),q);
3622 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3623 (u.green+v.green)/2.0,plasma),q);
3624 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3625 (u.blue+v.blue)/2.0,plasma),q);
3626 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3627 if (segment->x1 != segment->x2)
3632 x=(ssize_t) ceil(segment->x2-0.5);
3633 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3634 ceil(segment->y1-0.5),&u,exception);
3635 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3636 ceil(segment->y2-0.5),&v,exception);
3637 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3638 if (q == (Quantum *) NULL)
3640 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3641 (u.red+v.red)/2.0,plasma),q);
3642 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3643 (u.green+v.green)/2.0,plasma),q);
3644 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3645 (u.blue+v.blue)/2.0,plasma),q);
3646 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3649 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3651 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3659 y=(ssize_t) ceil(segment->y2-0.5);
3660 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3661 ceil(segment->x1-0.5),y,&u,exception);
3662 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3663 ceil(segment->x2-0.5),y,&v,exception);
3664 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3665 if (q == (Quantum *) NULL)
3667 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3668 (u.red+v.red)/2.0,plasma),q);
3669 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3670 (u.green+v.green)/2.0,plasma),q);
3671 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3672 (u.blue+v.blue)/2.0,plasma),q);
3673 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3675 if (segment->y1 != segment->y2)
3683 y=(ssize_t) ceil(segment->y1-0.5);
3684 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3685 ceil(segment->x1-0.5),y,&u,exception);
3686 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3687 ceil(segment->x2-0.5),y,&v,exception);
3688 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3689 if (q == (Quantum *) NULL)
3691 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3692 (u.red+v.red)/2.0,plasma),q);
3693 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3694 (u.green+v.green)/2.0,plasma),q);
3695 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3696 (u.blue+v.blue)/2.0,plasma),q);
3697 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3700 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3708 x=(ssize_t) ceil(segment->x1-0.5);
3709 y=(ssize_t) ceil(segment->y1-0.5);
3710 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3711 x=(ssize_t) ceil(segment->x2-0.5);
3712 y=(ssize_t) ceil(segment->y2-0.5);
3713 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&v,exception);
3714 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3715 if (q == (Quantum *) NULL)
3717 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3718 (u.red+v.red)/2.0,plasma),q);
3719 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3720 (u.green+v.green)/2.0,plasma),q);
3721 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3722 (u.blue+v.blue)/2.0,plasma),q);
3723 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3725 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3727 return(MagickFalse);
3730 MagickExport MagickBooleanType PlasmaImage(Image *image,
3731 const SegmentInfo *segment,size_t attenuate,size_t depth,
3732 ExceptionInfo *exception)
3743 if (image->debug != MagickFalse)
3744 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3745 assert(image != (Image *) NULL);
3746 assert(image->signature == MagickSignature);
3747 if (image->debug != MagickFalse)
3748 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3749 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3750 return(MagickFalse);
3751 image_view=AcquireCacheView(image);
3752 random_info=AcquireRandomInfo();
3753 status=PlasmaImageProxy(image,image_view,random_info,segment,attenuate,depth,
3755 random_info=DestroyRandomInfo(random_info);
3756 image_view=DestroyCacheView(image_view);
3761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3765 % P o l a r o i d I m a g e %
3769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3771 % PolaroidImage() simulates a Polaroid picture.
3773 % The format of the AnnotateImage method is:
3775 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3776 % const double angle,ExceptionInfo exception)
3778 % A description of each parameter follows:
3780 % o image: the image.
3782 % o draw_info: the draw info.
3784 % o angle: Apply the effect along this angle.
3786 % o exception: return any errors or warnings in this structure.
3789 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3790 const double angle,ExceptionInfo *exception)
3811 Simulate a Polaroid picture.
3813 assert(image != (Image *) NULL);
3814 assert(image->signature == MagickSignature);
3815 if (image->debug != MagickFalse)
3816 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3817 assert(exception != (ExceptionInfo *) NULL);
3818 assert(exception->signature == MagickSignature);
3819 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3820 image->rows)/25.0,10.0);
3821 height=image->rows+2*quantum;
3822 caption_image=(Image *) NULL;
3823 value=GetImageProperty(image,"Caption");
3824 if (value != (const char *) NULL)
3828 geometry[MaxTextExtent];
3843 Generate caption image.
3845 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3846 if (caption_image == (Image *) NULL)
3847 return((Image *) NULL);
3848 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3849 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3851 (void) CloneString(&annotate_info->text,caption);
3852 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3853 &caption,exception);
3854 status=SetImageExtent(caption_image,image->columns,(size_t)
3855 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
3856 if (status == MagickFalse)
3857 caption_image=DestroyImage(caption_image);
3860 caption_image->background_color=image->border_color;
3861 (void) SetImageBackgroundColor(caption_image);
3862 (void) CloneString(&annotate_info->text,caption);
3863 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
3865 if (annotate_info->gravity == UndefinedGravity)
3866 (void) CloneString(&annotate_info->geometry,AcquireString(
3868 (void) AnnotateImage(caption_image,annotate_info,exception);
3869 height+=caption_image->rows;
3871 annotate_info=DestroyDrawInfo(annotate_info);
3872 caption=DestroyString(caption);
3874 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3876 if (picture_image == (Image *) NULL)
3878 if (caption_image != (Image *) NULL)
3879 caption_image=DestroyImage(caption_image);
3880 return((Image *) NULL);
3882 picture_image->background_color=image->border_color;
3883 (void) SetImageBackgroundColor(picture_image);
3884 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3885 if (caption_image != (Image *) NULL)
3887 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3888 quantum,(ssize_t) (image->rows+3*quantum/2));
3889 caption_image=DestroyImage(caption_image);
3891 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3892 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
3893 rotate_image=RotateImage(picture_image,90.0,exception);
3894 picture_image=DestroyImage(picture_image);
3895 if (rotate_image == (Image *) NULL)
3896 return((Image *) NULL);
3897 picture_image=rotate_image;
3898 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3899 picture_image->columns,exception);
3900 picture_image=DestroyImage(picture_image);
3901 if (bend_image == (Image *) NULL)
3902 return((Image *) NULL);
3903 InheritException(&bend_image->exception,exception);
3904 picture_image=bend_image;
3905 rotate_image=RotateImage(picture_image,-90.0,exception);
3906 picture_image=DestroyImage(picture_image);
3907 if (rotate_image == (Image *) NULL)
3908 return((Image *) NULL);
3909 picture_image=rotate_image;
3910 picture_image->background_color=image->background_color;
3911 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3913 if (polaroid_image == (Image *) NULL)
3915 picture_image=DestroyImage(picture_image);
3916 return(picture_image);
3918 flop_image=FlopImage(polaroid_image,exception);
3919 polaroid_image=DestroyImage(polaroid_image);
3920 if (flop_image == (Image *) NULL)
3922 picture_image=DestroyImage(picture_image);
3923 return(picture_image);
3925 polaroid_image=flop_image;
3926 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3927 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3928 picture_image=DestroyImage(picture_image);
3929 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3930 rotate_image=RotateImage(polaroid_image,angle,exception);
3931 polaroid_image=DestroyImage(polaroid_image);
3932 if (rotate_image == (Image *) NULL)
3933 return((Image *) NULL);
3934 polaroid_image=rotate_image;
3935 trim_image=TrimImage(polaroid_image,exception);
3936 polaroid_image=DestroyImage(polaroid_image);
3937 if (trim_image == (Image *) NULL)
3938 return((Image *) NULL);
3939 polaroid_image=trim_image;
3940 return(polaroid_image);
3944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3948 % S e p i a T o n e I m a g e %
3952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3954 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3955 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3956 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3957 % threshold of 80% is a good starting point for a reasonable tone.
3959 % The format of the SepiaToneImage method is:
3961 % Image *SepiaToneImage(const Image *image,const double threshold,
3962 % ExceptionInfo *exception)
3964 % A description of each parameter follows:
3966 % o image: the image.
3968 % o threshold: the tone threshold.
3970 % o exception: return any errors or warnings in this structure.
3973 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3974 ExceptionInfo *exception)
3976 #define SepiaToneImageTag "SepiaTone/Image"
3995 Initialize sepia-toned image attributes.
3997 assert(image != (const Image *) NULL);
3998 assert(image->signature == MagickSignature);
3999 if (image->debug != MagickFalse)
4000 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4001 assert(exception != (ExceptionInfo *) NULL);
4002 assert(exception->signature == MagickSignature);
4003 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4004 if (sepia_image == (Image *) NULL)
4005 return((Image *) NULL);
4006 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4008 sepia_image=DestroyImage(sepia_image);
4009 return((Image *) NULL);
4012 Tone each row of the image.
4016 image_view=AcquireCacheView(image);
4017 sepia_view=AcquireCacheView(sepia_image);
4018 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4019 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4021 for (y=0; y < (ssize_t) image->rows; y++)
4023 register const Quantum
4032 if (status == MagickFalse)
4034 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4035 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4037 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4042 for (x=0; x < (ssize_t) image->columns; x++)
4048 intensity=(MagickRealType) GetPixelIntensity(image,p);
4049 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4050 (MagickRealType) QuantumRange-threshold;
4051 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4052 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4053 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4054 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4055 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4056 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4058 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4059 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4060 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4061 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4062 p+=GetPixelChannels(image);
4063 q+=GetPixelChannels(sepia_image);
4065 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4067 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4072 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4073 #pragma omp critical (MagickCore_SepiaToneImage)
4075 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4077 if (proceed == MagickFalse)
4081 sepia_view=DestroyCacheView(sepia_view);
4082 image_view=DestroyCacheView(image_view);
4083 (void) NormalizeImage(sepia_image,exception);
4084 (void) ContrastImage(sepia_image,MagickTrue,exception);
4085 if (status == MagickFalse)
4086 sepia_image=DestroyImage(sepia_image);
4087 return(sepia_image);
4091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4095 % S h a d o w I m a g e %
4099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4101 % ShadowImage() simulates a shadow from the specified image and returns it.
4103 % The format of the ShadowImage method is:
4105 % Image *ShadowImage(const Image *image,const double opacity,
4106 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4107 % ExceptionInfo *exception)
4109 % A description of each parameter follows:
4111 % o image: the image.
4113 % o opacity: percentage transparency.
4115 % o sigma: the standard deviation of the Gaussian, in pixels.
4117 % o x_offset: the shadow x-offset.
4119 % o y_offset: the shadow y-offset.
4121 % o exception: return any errors or warnings in this structure.
4124 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4125 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4126 ExceptionInfo *exception)
4128 #define ShadowImageTag "Shadow/Image"
4153 assert(image != (Image *) NULL);
4154 assert(image->signature == MagickSignature);
4155 if (image->debug != MagickFalse)
4156 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4157 assert(exception != (ExceptionInfo *) NULL);
4158 assert(exception->signature == MagickSignature);
4159 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4160 if (clone_image == (Image *) NULL)
4161 return((Image *) NULL);
4162 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4163 clone_image->compose=OverCompositeOp;
4164 border_info.width=(size_t) floor(2.0*sigma+0.5);
4165 border_info.height=(size_t) floor(2.0*sigma+0.5);
4168 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4169 border_image=BorderImage(clone_image,&border_info,exception);
4170 clone_image=DestroyImage(clone_image);
4171 if (border_image == (Image *) NULL)
4172 return((Image *) NULL);
4173 if (border_image->matte == MagickFalse)
4174 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4180 border_view=AcquireCacheView(border_image);
4181 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4182 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4184 for (y=0; y < (ssize_t) border_image->rows; y++)
4192 if (status == MagickFalse)
4194 q=GetCacheViewAuthenticPixels(border_view,0,y,border_image->columns,1,
4196 if (q == (Quantum *) NULL)
4201 for (x=0; x < (ssize_t) border_image->columns; x++)
4203 SetPixelRed(border_image,border_image->background_color.red,q);
4204 SetPixelGreen(border_image,border_image->background_color.green,q);
4205 SetPixelBlue(border_image,border_image->background_color.blue,q);
4206 if (border_image->matte == MagickFalse)
4207 SetPixelAlpha(border_image,border_image->background_color.alpha,q);
4209 SetPixelAlpha(border_image,ClampToQuantum((MagickRealType)
4210 (GetPixelAlpha(border_image,q)*opacity/100.0)),q);
4211 q+=GetPixelChannels(border_image);
4213 if (SyncCacheViewAuthenticPixels(border_view,exception) == MagickFalse)
4215 if (border_image->progress_monitor != (MagickProgressMonitor) NULL)
4220 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4221 #pragma omp critical (MagickCore_ShadowImage)
4223 proceed=SetImageProgress(border_image,ShadowImageTag,progress++,
4224 border_image->rows);
4225 if (proceed == MagickFalse)
4229 border_view=DestroyCacheView(border_view);
4230 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4231 shadow_image=BlurImage(border_image,0.0,sigma,image->bias,exception);
4232 (void) SetPixelChannelMap(border_image,channel_mask);
4233 border_image=DestroyImage(border_image);
4234 if (shadow_image == (Image *) NULL)
4235 return((Image *) NULL);
4236 if (shadow_image->page.width == 0)
4237 shadow_image->page.width=shadow_image->columns;
4238 if (shadow_image->page.height == 0)
4239 shadow_image->page.height=shadow_image->rows;
4240 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4241 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4242 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4243 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4244 return(shadow_image);
4248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4252 % S k e t c h I m a g e %
4256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4258 % SketchImage() simulates a pencil sketch. We convolve the image with a
4259 % Gaussian operator of the given radius and standard deviation (sigma). For
4260 % reasonable results, radius should be larger than sigma. Use a radius of 0
4261 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4264 % The format of the SketchImage method is:
4266 % Image *SketchImage(const Image *image,const double radius,
4267 % const double sigma,const double angle,ExceptionInfo *exception)
4269 % A description of each parameter follows:
4271 % o image: the image.
4273 % o radius: the radius of the Gaussian, in pixels, not counting the
4276 % o sigma: the standard deviation of the Gaussian, in pixels.
4278 % o angle: Apply the effect along this angle.
4280 % o exception: return any errors or warnings in this structure.
4283 MagickExport Image *SketchImage(const Image *image,const double radius,
4284 const double sigma,const double angle,ExceptionInfo *exception)
4303 **restrict random_info;
4311 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4312 MagickTrue,exception);
4313 if (random_image == (Image *) NULL)
4314 return((Image *) NULL);
4316 GetPixelInfo(random_image,&zero);
4317 random_info=AcquireRandomInfoThreadSet();
4318 random_view=AcquireCacheView(random_image);
4319 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4320 #pragma omp parallel for schedule(dynamic,4) shared(status)
4322 for (y=0; y < (ssize_t) random_image->rows; y++)
4325 id = GetOpenMPThreadId();
4336 if (status == MagickFalse)
4338 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4340 if (q == (Quantum *) NULL)
4346 for (x=0; x < (ssize_t) random_image->columns; x++)
4348 pixel.red=(MagickRealType) (QuantumRange*
4349 GetPseudoRandomValue(random_info[id]));
4350 pixel.green=pixel.red;
4351 pixel.blue=pixel.red;
4352 if (image->colorspace == CMYKColorspace)
4353 pixel.black=pixel.red;
4354 SetPixelPixelInfo(random_image,&pixel,q);
4355 q+=GetPixelChannels(random_image);
4357 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4360 random_view=DestroyCacheView(random_view);
4361 random_info=DestroyRandomInfoThreadSet(random_info);
4362 if (status == MagickFalse)
4364 random_image=DestroyImage(random_image);
4365 return(random_image);
4367 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4368 random_image=DestroyImage(random_image);
4369 if (blur_image == (Image *) NULL)
4370 return((Image *) NULL);
4371 dodge_image=EdgeImage(blur_image,radius,sigma,exception);
4372 blur_image=DestroyImage(blur_image);
4373 if (dodge_image == (Image *) NULL)
4374 return((Image *) NULL);
4375 (void) NormalizeImage(dodge_image,exception);
4376 (void) NegateImage(dodge_image,MagickFalse,exception);
4377 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4378 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4379 if (sketch_image == (Image *) NULL)
4381 dodge_image=DestroyImage(dodge_image);
4382 return((Image *) NULL);
4384 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4385 dodge_image=DestroyImage(dodge_image);
4386 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4387 if (blend_image == (Image *) NULL)
4389 sketch_image=DestroyImage(sketch_image);
4390 return((Image *) NULL);
4392 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4393 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4394 blend_image=DestroyImage(blend_image);
4395 return(sketch_image);
4399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4403 % S o l a r i z e I m a g e %
4407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4409 % SolarizeImage() applies a special effect to the image, similar to the effect
4410 % achieved in a photo darkroom by selectively exposing areas of photo
4411 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4412 % measure of the extent of the solarization.
4414 % The format of the SolarizeImage method is:
4416 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4417 % ExceptionInfo *exception)
4419 % A description of each parameter follows:
4421 % o image: the image.
4423 % o threshold: Define the extent of the solarization.
4425 % o exception: return any errors or warnings in this structure.
4428 MagickExport MagickBooleanType SolarizeImage(Image *image,
4429 const double threshold,ExceptionInfo *exception)
4431 #define SolarizeImageTag "Solarize/Image"
4445 assert(image != (Image *) NULL);
4446 assert(image->signature == MagickSignature);
4447 if (image->debug != MagickFalse)
4448 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4449 if (image->storage_class == PseudoClass)
4457 for (i=0; i < (ssize_t) image->colors; i++)
4459 if ((MagickRealType) image->colormap[i].red > threshold)
4460 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4461 if ((MagickRealType) image->colormap[i].green > threshold)
4462 image->colormap[i].green=(Quantum) QuantumRange-
4463 image->colormap[i].green;
4464 if ((MagickRealType) image->colormap[i].blue > threshold)
4465 image->colormap[i].blue=(Quantum) QuantumRange-
4466 image->colormap[i].blue;
4474 image_view=AcquireCacheView(image);
4475 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4476 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4478 for (y=0; y < (ssize_t) image->rows; y++)
4486 if (status == MagickFalse)
4488 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4489 if (q == (Quantum *) NULL)
4494 for (x=0; x < (ssize_t) image->columns; x++)
4496 if ((MagickRealType) GetPixelRed(image,q) > threshold)
4497 SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
4498 if ((MagickRealType) GetPixelGreen(image,q) > threshold)
4499 SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
4500 if ((MagickRealType) GetPixelBlue(image,q) > threshold)
4501 SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
4502 q+=GetPixelChannels(image);
4504 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4506 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4511 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4512 #pragma omp critical (MagickCore_SolarizeImage)
4514 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4515 if (proceed == MagickFalse)
4519 image_view=DestroyCacheView(image_view);
4524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4528 % S t e g a n o I m a g e %
4532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4534 % SteganoImage() hides a digital watermark within the image. Recover
4535 % the hidden watermark later to prove that the authenticity of an image.
4536 % Offset defines the start position within the image to hide the watermark.
4538 % The format of the SteganoImage method is:
4540 % Image *SteganoImage(const Image *image,Image *watermark,
4541 % ExceptionInfo *exception)
4543 % A description of each parameter follows:
4545 % o image: the image.
4547 % o watermark: the watermark image.
4549 % o exception: return any errors or warnings in this structure.
4552 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4553 ExceptionInfo *exception)
4555 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4556 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4557 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4558 #define SteganoImageTag "Stegano/Image"
4593 Initialize steganographic image attributes.
4595 assert(image != (const Image *) NULL);
4596 assert(image->signature == MagickSignature);
4597 if (image->debug != MagickFalse)
4598 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4599 assert(watermark != (const Image *) NULL);
4600 assert(watermark->signature == MagickSignature);
4601 assert(exception != (ExceptionInfo *) NULL);
4602 assert(exception->signature == MagickSignature);
4604 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4605 if (stegano_image == (Image *) NULL)
4606 return((Image *) NULL);
4607 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4609 stegano_image=DestroyImage(stegano_image);
4610 return((Image *) NULL);
4612 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4614 Hide watermark in low-order bits of image.
4619 depth=stegano_image->depth;
4622 watermark_view=AcquireCacheView(watermark);
4623 stegano_view=AcquireCacheView(stegano_image);
4624 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4626 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4628 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4630 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,&pixel,exception);
4631 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4633 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4634 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4636 if (q == (Quantum *) NULL)
4642 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
4643 GetPixelPacketIntensity(&pixel),i)),q);
4648 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
4649 GetPixelPacketIntensity(&pixel),i)),q);
4654 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
4655 GetPixelPacketIntensity(&pixel),i)),q);
4659 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4665 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4667 if (k == image->offset)
4671 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4676 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4678 if (proceed == MagickFalse)
4682 stegano_view=DestroyCacheView(stegano_view);
4683 watermark_view=DestroyCacheView(watermark_view);
4684 if (stegano_image->storage_class == PseudoClass)
4685 (void) SyncImage(stegano_image);
4686 if (status == MagickFalse)
4688 stegano_image=DestroyImage(stegano_image);
4689 return((Image *) NULL);
4691 return(stegano_image);
4695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4699 % S t e r e o A n a g l y p h I m a g e %
4703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4705 % StereoAnaglyphImage() combines two images and produces a single image that
4706 % is the composite of a left and right image of a stereo pair. Special
4707 % red-green stereo glasses are required to view this effect.
4709 % The format of the StereoAnaglyphImage method is:
4711 % Image *StereoImage(const Image *left_image,const Image *right_image,
4712 % ExceptionInfo *exception)
4713 % Image *StereoAnaglyphImage(const Image *left_image,
4714 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4715 % ExceptionInfo *exception)
4717 % A description of each parameter follows:
4719 % o left_image: the left image.
4721 % o right_image: the right image.
4723 % o exception: return any errors or warnings in this structure.
4725 % o x_offset: amount, in pixels, by which the left image is offset to the
4726 % right of the right image.
4728 % o y_offset: amount, in pixels, by which the left image is offset to the
4729 % bottom of the right image.
4733 MagickExport Image *StereoImage(const Image *left_image,
4734 const Image *right_image,ExceptionInfo *exception)
4736 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4739 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4740 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4741 ExceptionInfo *exception)
4743 #define StereoImageTag "Stereo/Image"
4757 assert(left_image != (const Image *) NULL);
4758 assert(left_image->signature == MagickSignature);
4759 if (left_image->debug != MagickFalse)
4760 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4761 left_image->filename);
4762 assert(right_image != (const Image *) NULL);
4763 assert(right_image->signature == MagickSignature);
4764 assert(exception != (ExceptionInfo *) NULL);
4765 assert(exception->signature == MagickSignature);
4766 assert(right_image != (const Image *) NULL);
4768 if ((left_image->columns != right_image->columns) ||
4769 (left_image->rows != right_image->rows))
4770 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4772 Initialize stereo image attributes.
4774 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4775 MagickTrue,exception);
4776 if (stereo_image == (Image *) NULL)
4777 return((Image *) NULL);
4778 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4780 stereo_image=DestroyImage(stereo_image);
4781 return((Image *) NULL);
4784 Copy left image to red channel and right image to blue channel.
4787 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4789 register const Quantum
4799 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4801 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4802 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4803 if ((p == (const Quantum *) NULL) ||
4804 (q == (Quantum *) NULL) || (r == (Quantum *) NULL))
4806 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4808 SetPixelRed(image,GetPixelRed(left_image,p),r);
4809 SetPixelGreen(image,GetPixelGreen(left_image,q),r);
4810 SetPixelBlue(image,GetPixelBlue(left_image,q),r);
4811 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4812 GetPixelAlpha(left_image,q))/2,r);
4813 p+=GetPixelChannels(left_image);
4817 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4819 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4824 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4825 stereo_image->rows);
4826 if (proceed == MagickFalse)
4830 if (status == MagickFalse)
4832 stereo_image=DestroyImage(stereo_image);
4833 return((Image *) NULL);
4835 return(stereo_image);
4839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4843 % S w i r l I m a g e %
4847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4849 % SwirlImage() swirls the pixels about the center of the image, where
4850 % degrees indicates the sweep of the arc through which each pixel is moved.
4851 % You get a more dramatic effect as the degrees move from 1 to 360.
4853 % The format of the SwirlImage method is:
4855 % Image *SwirlImage(const Image *image,double degrees,
4856 % ExceptionInfo *exception)
4858 % A description of each parameter follows:
4860 % o image: the image.
4862 % o degrees: Define the tightness of the swirling effect.
4864 % o exception: return any errors or warnings in this structure.
4867 MagickExport Image *SwirlImage(const Image *image,double degrees,
4868 ExceptionInfo *exception)
4870 #define SwirlImageTag "Swirl/Image"
4899 Initialize swirl image attributes.
4901 assert(image != (const Image *) NULL);
4902 assert(image->signature == MagickSignature);
4903 if (image->debug != MagickFalse)
4904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4905 assert(exception != (ExceptionInfo *) NULL);
4906 assert(exception->signature == MagickSignature);
4907 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4908 if (swirl_image == (Image *) NULL)
4909 return((Image *) NULL);
4910 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
4912 swirl_image=DestroyImage(swirl_image);
4913 return((Image *) NULL);
4915 if (swirl_image->background_color.alpha != OpaqueAlpha)
4916 swirl_image->matte=MagickTrue;
4918 Compute scaling factor.
4920 center.x=(double) image->columns/2.0;
4921 center.y=(double) image->rows/2.0;
4922 radius=MagickMax(center.x,center.y);
4925 if (image->columns > image->rows)
4926 scale.y=(double) image->columns/(double) image->rows;
4928 if (image->columns < image->rows)
4929 scale.x=(double) image->rows/(double) image->columns;
4930 degrees=(double) DegreesToRadians(degrees);
4936 GetPixelInfo(swirl_image,&zero);
4937 image_view=AcquireCacheView(image);
4938 swirl_view=AcquireCacheView(swirl_image);
4939 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4940 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4942 for (y=0; y < (ssize_t) image->rows; y++)
4959 if (status == MagickFalse)
4961 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4963 if (q == (Quantum *) NULL)
4968 delta.y=scale.y*(double) (y-center.y);
4970 for (x=0; x < (ssize_t) image->columns; x++)
4973 Determine if the pixel is within an ellipse.
4975 delta.x=scale.x*(double) (x-center.x);
4976 distance=delta.x*delta.x+delta.y*delta.y;
4977 if (distance < (radius*radius))
4987 factor=1.0-sqrt((double) distance)/radius;
4988 sine=sin((double) (degrees*factor*factor));
4989 cosine=cos((double) (degrees*factor*factor));
4990 (void) InterpolatePixelInfo(image,image_view,
4991 UndefinedInterpolatePixel,(double) ((cosine*delta.x-sine*delta.y)/
4992 scale.x+center.x),(double) ((sine*delta.x+cosine*delta.y)/scale.y+
4993 center.y),&pixel,exception);
4994 SetPixelPixelInfo(swirl_image,&pixel,q);
4996 q+=GetPixelChannels(swirl_image);
4998 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5000 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5005 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5006 #pragma omp critical (MagickCore_SwirlImage)
5008 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5009 if (proceed == MagickFalse)
5013 swirl_view=DestroyCacheView(swirl_view);
5014 image_view=DestroyCacheView(image_view);
5015 if (status == MagickFalse)
5016 swirl_image=DestroyImage(swirl_image);
5017 return(swirl_image);
5021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5025 % T i n t I m a g e %
5029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5031 % TintImage() applies a color vector to each pixel in the image. The length
5032 % of the vector is 0 for black and white and at its maximum for the midtones.
5033 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5035 % The format of the TintImage method is:
5037 % Image *TintImage(const Image *image,const char *opacity,
5038 % const PixelPacket tint,ExceptionInfo *exception)
5040 % A description of each parameter follows:
5042 % o image: the image.
5044 % o opacity: A color value used for tinting.
5046 % o tint: A color value used for tinting.
5048 % o exception: return any errors or warnings in this structure.
5051 MagickExport Image *TintImage(const Image *image,const char *opacity,
5052 const PixelPacket tint,ExceptionInfo *exception)
5054 #define TintImageTag "Tint/Image"
5083 Allocate tint image.
5085 assert(image != (const Image *) NULL);
5086 assert(image->signature == MagickSignature);
5087 if (image->debug != MagickFalse)
5088 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5089 assert(exception != (ExceptionInfo *) NULL);
5090 assert(exception->signature == MagickSignature);
5091 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5092 if (tint_image == (Image *) NULL)
5093 return((Image *) NULL);
5094 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5096 tint_image=DestroyImage(tint_image);
5097 return((Image *) NULL);
5099 if (opacity == (const char *) NULL)
5102 Determine RGB values of the color.
5104 flags=ParseGeometry(opacity,&geometry_info);
5105 pixel.red=geometry_info.rho;
5106 if ((flags & SigmaValue) != 0)
5107 pixel.green=geometry_info.sigma;
5109 pixel.green=pixel.red;
5110 if ((flags & XiValue) != 0)
5111 pixel.blue=geometry_info.xi;
5113 pixel.blue=pixel.red;
5114 if ((flags & PsiValue) != 0)
5115 pixel.alpha=geometry_info.psi;
5117 pixel.alpha=(MagickRealType) OpaqueAlpha;
5118 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5119 GetPixelPacketIntensity(&tint));
5120 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5121 GetPixelPacketIntensity(&tint));
5122 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5123 GetPixelPacketIntensity(&tint));
5129 image_view=AcquireCacheView(image);
5130 tint_view=AcquireCacheView(tint_image);
5131 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5132 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5134 for (y=0; y < (ssize_t) image->rows; y++)
5136 register const Quantum
5145 if (status == MagickFalse)
5147 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5148 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5150 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5155 for (x=0; x < (ssize_t) image->columns; x++)
5163 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5164 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5165 (1.0-(4.0*(weight*weight)));
5166 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5167 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5168 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5169 (1.0-(4.0*(weight*weight)));
5170 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5171 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5172 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5173 (1.0-(4.0*(weight*weight)));
5174 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5175 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
5176 p+=GetPixelChannels(image);
5177 q+=GetPixelChannels(tint_image);
5179 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5181 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5186 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5187 #pragma omp critical (MagickCore_TintImage)
5189 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5190 if (proceed == MagickFalse)
5194 tint_view=DestroyCacheView(tint_view);
5195 image_view=DestroyCacheView(image_view);
5196 if (status == MagickFalse)
5197 tint_image=DestroyImage(tint_image);
5202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5206 % V i g n e t t e I m a g e %
5210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5212 % VignetteImage() softens the edges of the image in vignette style.
5214 % The format of the VignetteImage method is:
5216 % Image *VignetteImage(const Image *image,const double radius,
5217 % const double sigma,const ssize_t x,const ssize_t y,
5218 % ExceptionInfo *exception)
5220 % A description of each parameter follows:
5222 % o image: the image.
5224 % o radius: the radius of the pixel neighborhood.
5226 % o sigma: the standard deviation of the Gaussian, in pixels.
5228 % o x, y: Define the x and y ellipse offset.
5230 % o exception: return any errors or warnings in this structure.
5233 MagickExport Image *VignetteImage(const Image *image,const double radius,
5234 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5237 ellipse[MaxTextExtent];
5248 assert(image != (Image *) NULL);
5249 assert(image->signature == MagickSignature);
5250 if (image->debug != MagickFalse)
5251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5252 assert(exception != (ExceptionInfo *) NULL);
5253 assert(exception->signature == MagickSignature);
5254 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5255 if (canvas_image == (Image *) NULL)
5256 return((Image *) NULL);
5257 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5259 canvas_image=DestroyImage(canvas_image);
5260 return((Image *) NULL);
5262 canvas_image->matte=MagickTrue;
5263 oval_image=CloneImage(canvas_image,canvas_image->columns,
5264 canvas_image->rows,MagickTrue,exception);
5265 if (oval_image == (Image *) NULL)
5267 canvas_image=DestroyImage(canvas_image);
5268 return((Image *) NULL);
5270 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5271 (void) SetImageBackgroundColor(oval_image);
5272 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5273 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5274 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5275 (void) FormatLocaleString(ellipse,MaxTextExtent,
5276 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5277 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5278 draw_info->primitive=AcquireString(ellipse);
5279 (void) DrawImage(oval_image,draw_info,exception);
5280 draw_info=DestroyDrawInfo(draw_info);
5281 blur_image=BlurImage(oval_image,radius,sigma,image->bias,exception);
5282 oval_image=DestroyImage(oval_image);
5283 if (blur_image == (Image *) NULL)
5285 canvas_image=DestroyImage(canvas_image);
5286 return((Image *) NULL);
5288 blur_image->matte=MagickFalse;
5289 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5290 blur_image=DestroyImage(blur_image);
5291 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5292 canvas_image=DestroyImage(canvas_image);
5293 return(vignette_image);
5297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5301 % W a v e I m a g e %
5305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5307 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5308 % vertically along a sine wave whose amplitude and wavelength is specified
5309 % by the given parameters.
5311 % The format of the WaveImage method is:
5313 % Image *WaveImage(const Image *image,const double amplitude,
5314 % const double wave_length,ExceptionInfo *exception)
5316 % A description of each parameter follows:
5318 % o image: the image.
5320 % o amplitude, wave_length: Define the amplitude and wave length of the
5323 % o exception: return any errors or warnings in this structure.
5326 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5327 const double wave_length,ExceptionInfo *exception)
5329 #define WaveImageTag "Wave/Image"
5357 Initialize wave image attributes.
5359 assert(image != (Image *) NULL);
5360 assert(image->signature == MagickSignature);
5361 if (image->debug != MagickFalse)
5362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5363 assert(exception != (ExceptionInfo *) NULL);
5364 assert(exception->signature == MagickSignature);
5365 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5366 fabs(amplitude)),MagickTrue,exception);
5367 if (wave_image == (Image *) NULL)
5368 return((Image *) NULL);
5369 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5371 wave_image=DestroyImage(wave_image);
5372 return((Image *) NULL);
5374 if (wave_image->background_color.alpha != OpaqueAlpha)
5375 wave_image->matte=MagickTrue;
5379 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5381 if (sine_map == (MagickRealType *) NULL)
5383 wave_image=DestroyImage(wave_image);
5384 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5386 for (i=0; i < (ssize_t) wave_image->columns; i++)
5387 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5394 GetPixelInfo(wave_image,&zero);
5395 image_view=AcquireCacheView(image);
5396 wave_view=AcquireCacheView(wave_image);
5397 (void) SetCacheViewVirtualPixelMethod(image_view,
5398 BackgroundVirtualPixelMethod);
5399 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5400 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5402 for (y=0; y < (ssize_t) wave_image->rows; y++)
5413 if (status == MagickFalse)
5415 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5417 if (q == (Quantum *) NULL)
5423 for (x=0; x < (ssize_t) wave_image->columns; x++)
5425 (void) InterpolatePixelInfo(image,image_view,
5426 UndefinedInterpolatePixel,(double) x,(double) (y-sine_map[x]),&pixel,
5428 SetPixelPixelInfo(wave_image,&pixel,q);
5429 q+=GetPixelChannels(wave_image);
5431 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5433 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5438 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5439 #pragma omp critical (MagickCore_WaveImage)
5441 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5442 if (proceed == MagickFalse)
5446 wave_view=DestroyCacheView(wave_view);
5447 image_view=DestroyCacheView(image_view);
5448 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5449 if (status == MagickFalse)
5450 wave_image=DestroyImage(wave_image);