2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/annotate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/cache-view.h"
49 #include "MagickCore/color.h"
50 #include "MagickCore/color-private.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/decorate.h"
53 #include "MagickCore/draw.h"
54 #include "MagickCore/effect.h"
55 #include "MagickCore/enhance.h"
56 #include "MagickCore/exception.h"
57 #include "MagickCore/exception-private.h"
58 #include "MagickCore/fx.h"
59 #include "MagickCore/fx-private.h"
60 #include "MagickCore/gem.h"
61 #include "MagickCore/geometry.h"
62 #include "MagickCore/layer.h"
63 #include "MagickCore/list.h"
64 #include "MagickCore/log.h"
65 #include "MagickCore/image.h"
66 #include "MagickCore/image-private.h"
67 #include "MagickCore/magick.h"
68 #include "MagickCore/memory_.h"
69 #include "MagickCore/monitor.h"
70 #include "MagickCore/monitor-private.h"
71 #include "MagickCore/option.h"
72 #include "MagickCore/pixel.h"
73 #include "MagickCore/pixel-accessor.h"
74 #include "MagickCore/property.h"
75 #include "MagickCore/quantum.h"
76 #include "MagickCore/quantum-private.h"
77 #include "MagickCore/random_.h"
78 #include "MagickCore/random-private.h"
79 #include "MagickCore/resample.h"
80 #include "MagickCore/resample-private.h"
81 #include "MagickCore/resize.h"
82 #include "MagickCore/shear.h"
83 #include "MagickCore/splay-tree.h"
84 #include "MagickCore/statistic.h"
85 #include "MagickCore/string_.h"
86 #include "MagickCore/string-private.h"
87 #include "MagickCore/thread-private.h"
88 #include "MagickCore/transform.h"
89 #include "MagickCore/utility.h"
94 #define LeftShiftOperator 0xf5
95 #define RightShiftOperator 0xf6
96 #define LessThanEqualOperator 0xf7
97 #define GreaterThanEqualOperator 0xf8
98 #define EqualOperator 0xf9
99 #define NotEqualOperator 0xfa
100 #define LogicalAndOperator 0xfb
101 #define LogicalOrOperator 0xfc
102 #define ExponentialNotation 0xfd
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 + A c q u i r e F x I n f o %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % AcquireFxInfo() allocates the FxInfo structure.
142 % The format of the AcquireFxInfo method is:
144 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
146 % A description of each parameter follows:
148 % o image: the image.
150 % o expression: the expression.
153 MagickExport FxInfo *AcquireFxInfo(const Image *image,const char *expression)
167 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
168 if (fx_info == (FxInfo *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
171 fx_info->exception=AcquireExceptionInfo();
172 fx_info->images=image;
173 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
174 RelinquishMagickMemory);
175 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
176 RelinquishMagickMemory);
177 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
178 fx_info->images),sizeof(*fx_info->view));
179 if (fx_info->view == (CacheView **) NULL)
180 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
182 next=GetFirstImageInList(fx_info->images);
183 for ( ; next != (Image *) NULL; next=next->next)
185 fx_info->view[i]=AcquireCacheView(next);
188 fx_info->random_info=AcquireRandomInfo();
189 fx_info->expression=ConstantString(expression);
190 fx_info->file=stderr;
191 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
193 Force right-to-left associativity for unary negation.
195 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
196 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
197 (strstr(fx_info->expression,"e-") != (char *) NULL))
200 Convert scientific notation.
202 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
203 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
204 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
205 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
206 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
207 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
208 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
209 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
210 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
211 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
212 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
213 (void) SubstituteString(&fx_info->expression,"1e-1.0*","1**10^-");
214 (void) SubstituteString(&fx_info->expression,"2e-1.0*","2**10^-");
215 (void) SubstituteString(&fx_info->expression,"3e-1.0*","3**10^-");
216 (void) SubstituteString(&fx_info->expression,"4e-1.0*","4**10^-");
217 (void) SubstituteString(&fx_info->expression,"5e-1.0*","5**10^-");
218 (void) SubstituteString(&fx_info->expression,"6e-1.0*","6**10^-");
219 (void) SubstituteString(&fx_info->expression,"7e-1.0*","7**10^-");
220 (void) SubstituteString(&fx_info->expression,"8e-1.0*","8**10^-");
221 (void) SubstituteString(&fx_info->expression,"9e-1.0*","9**10^-");
223 if ((strstr(fx_info->expression,"E+") != (char *) NULL) ||
224 (strstr(fx_info->expression,"E-") != (char *) NULL))
227 Convert scientific notation.
229 (void) SubstituteString(&fx_info->expression,"0E+","0**10^");
230 (void) SubstituteString(&fx_info->expression,"1E+","1**10^");
231 (void) SubstituteString(&fx_info->expression,"2E+","2**10^");
232 (void) SubstituteString(&fx_info->expression,"3E+","3**10^");
233 (void) SubstituteString(&fx_info->expression,"4E+","4**10^");
234 (void) SubstituteString(&fx_info->expression,"5E+","5**10^");
235 (void) SubstituteString(&fx_info->expression,"6E+","6**10^");
236 (void) SubstituteString(&fx_info->expression,"7E+","7**10^");
237 (void) SubstituteString(&fx_info->expression,"8E+","8**10^");
238 (void) SubstituteString(&fx_info->expression,"9E+","9**10^");
239 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
240 (void) SubstituteString(&fx_info->expression,"1E-1.0*","1**10^-");
241 (void) SubstituteString(&fx_info->expression,"2E-1.0*","2**10^-");
242 (void) SubstituteString(&fx_info->expression,"3E-1.0*","3**10^-");
243 (void) SubstituteString(&fx_info->expression,"4E-1.0*","4**10^-");
244 (void) SubstituteString(&fx_info->expression,"5E-1.0*","5**10^-");
245 (void) SubstituteString(&fx_info->expression,"6E-1.0*","6**10^-");
246 (void) SubstituteString(&fx_info->expression,"7E-1.0*","7**10^-");
247 (void) SubstituteString(&fx_info->expression,"8E-1.0*","8**10^-");
248 (void) SubstituteString(&fx_info->expression,"9E-1.0*","9**10^-");
251 Convert complex to simple operators.
254 *fx_op=(char) LeftShiftOperator;
255 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
256 *fx_op=(char) RightShiftOperator;
257 (void) SubstituteString(&fx_info->expression,">>",fx_op);
258 *fx_op=(char) LessThanEqualOperator;
259 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
260 *fx_op=(char) GreaterThanEqualOperator;
261 (void) SubstituteString(&fx_info->expression,">=",fx_op);
262 *fx_op=(char) EqualOperator;
263 (void) SubstituteString(&fx_info->expression,"==",fx_op);
264 *fx_op=(char) NotEqualOperator;
265 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
266 *fx_op=(char) LogicalAndOperator;
267 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
268 *fx_op=(char) LogicalOrOperator;
269 (void) SubstituteString(&fx_info->expression,"||",fx_op);
270 *fx_op=(char) ExponentialNotation;
271 (void) SubstituteString(&fx_info->expression,"**",fx_op);
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % A d d N o i s e I m a g e %
284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 % AddNoiseImage() adds random noise to the image.
288 % The format of the AddNoiseImage method is:
290 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
291 % ExceptionInfo *exception)
293 % A description of each parameter follows:
295 % o image: the image.
297 % o channel: the channel type.
299 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
300 % Impulse, Laplacian, or Poisson.
302 % o exception: return any errors or warnings in this structure.
305 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, ExceptionInfo *exception)
307 #define AddNoiseImageTag "AddNoise/Image"
329 **restrict random_info;
335 Initialize noise image attributes.
337 assert(image != (const Image *) NULL);
338 assert(image->signature == MagickSignature);
339 if (image->debug != MagickFalse)
340 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
341 assert(exception != (ExceptionInfo *) NULL);
342 assert(exception->signature == MagickSignature);
343 noise_image=CloneImage(image,0,0,MagickTrue,exception);
344 if (noise_image == (Image *) NULL)
345 return((Image *) NULL);
346 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
348 noise_image=DestroyImage(noise_image);
349 return((Image *) NULL);
352 Add noise in each row.
355 option=GetImageArtifact(image,"attenuate");
356 if (option != (char *) NULL)
357 attenuate=InterpretLocaleValue(option,(char **) NULL);
360 random_info=AcquireRandomInfoThreadSet();
361 image_view=AcquireCacheView(image);
362 noise_view=AcquireCacheView(noise_image);
363 #if defined(MAGICKCORE_OPENMP_SUPPORT)
364 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
366 for (y=0; y < (ssize_t) image->rows; y++)
369 id = GetOpenMPThreadId();
374 register const Quantum
383 if (status == MagickFalse)
385 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
386 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
388 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
393 for (x=0; x < (ssize_t) image->columns; x++)
395 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
396 SetPixelRed(noise_image,ClampToQuantum(GenerateDifferentialNoise(
397 random_info[id],GetPixelRed(image,p),noise_type,attenuate)),q);
398 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
399 SetPixelGreen(noise_image,ClampToQuantum(GenerateDifferentialNoise(
400 random_info[id],GetPixelGreen(image,p),noise_type,attenuate)),q);
401 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
402 SetPixelBlue(noise_image,ClampToQuantum(GenerateDifferentialNoise(
403 random_info[id],GetPixelBlue(image,p),noise_type,attenuate)),q);
404 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
405 (image->colorspace == CMYKColorspace))
406 SetPixelBlack(noise_image,ClampToQuantum(GenerateDifferentialNoise(
407 random_info[id],GetPixelBlack(image,p),noise_type,attenuate)),q);
408 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
409 SetPixelAlpha(noise_image,ClampToQuantum(GenerateDifferentialNoise(
410 random_info[id],GetPixelAlpha(image,p),noise_type,attenuate)),q);
411 p+=GetPixelChannels(image);
412 q+=GetPixelChannels(noise_image);
414 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
415 if (sync == MagickFalse)
417 if (image->progress_monitor != (MagickProgressMonitor) NULL)
422 #if defined(MAGICKCORE_OPENMP_SUPPORT)
423 #pragma omp critical (MagickCore_AddNoiseImage)
425 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
427 if (proceed == MagickFalse)
431 noise_view=DestroyCacheView(noise_view);
432 image_view=DestroyCacheView(image_view);
433 random_info=DestroyRandomInfoThreadSet(random_info);
434 if (status == MagickFalse)
435 noise_image=DestroyImage(noise_image);
440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 % B l u e S h i f t I m a g e %
448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 % BlueShiftImage() mutes the colors of the image to simulate a scene at
451 % nighttime in the moonlight.
453 % The format of the BlueShiftImage method is:
455 % Image *BlueShiftImage(const Image *image,const double factor,
456 % ExceptionInfo *exception)
458 % A description of each parameter follows:
460 % o image: the image.
462 % o factor: the shift factor.
464 % o exception: return any errors or warnings in this structure.
467 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
468 ExceptionInfo *exception)
470 #define BlueShiftImageTag "BlueShift/Image"
489 Allocate blue shift image.
491 assert(image != (const Image *) NULL);
492 assert(image->signature == MagickSignature);
493 if (image->debug != MagickFalse)
494 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
495 assert(exception != (ExceptionInfo *) NULL);
496 assert(exception->signature == MagickSignature);
497 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
499 if (shift_image == (Image *) NULL)
500 return((Image *) NULL);
501 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
503 shift_image=DestroyImage(shift_image);
504 return((Image *) NULL);
507 Blue-shift DirectClass image.
511 image_view=AcquireCacheView(image);
512 shift_view=AcquireCacheView(shift_image);
513 #if defined(MAGICKCORE_OPENMP_SUPPORT)
514 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
516 for (y=0; y < (ssize_t) image->rows; y++)
527 register const Quantum
536 if (status == MagickFalse)
538 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
539 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
541 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
546 for (x=0; x < (ssize_t) image->columns; x++)
548 quantum=GetPixelRed(image,p);
549 if (GetPixelGreen(image,p) < quantum)
550 quantum=GetPixelGreen(image,p);
551 if (GetPixelBlue(image,p) < quantum)
552 quantum=GetPixelBlue(image,p);
553 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
554 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
555 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
556 quantum=GetPixelRed(image,p);
557 if (GetPixelGreen(image,p) > quantum)
558 quantum=GetPixelGreen(image,p);
559 if (GetPixelBlue(image,p) > quantum)
560 quantum=GetPixelBlue(image,p);
561 pixel.red=0.5*(pixel.red+factor*quantum);
562 pixel.green=0.5*(pixel.green+factor*quantum);
563 pixel.blue=0.5*(pixel.blue+factor*quantum);
564 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
565 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
566 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
567 p+=GetPixelChannels(image);
568 q+=GetPixelChannels(shift_image);
570 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
571 if (sync == MagickFalse)
573 if (image->progress_monitor != (MagickProgressMonitor) NULL)
578 #if defined(MAGICKCORE_OPENMP_SUPPORT)
579 #pragma omp critical (MagickCore_BlueShiftImage)
581 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
583 if (proceed == MagickFalse)
587 image_view=DestroyCacheView(image_view);
588 shift_view=DestroyCacheView(shift_view);
589 if (status == MagickFalse)
590 shift_image=DestroyImage(shift_image);
595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599 % C h a r c o a l I m a g e %
603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
605 % CharcoalImage() creates a new image that is a copy of an existing one with
606 % the edge highlighted. It allocates the memory necessary for the new Image
607 % structure and returns a pointer to the new image.
609 % The format of the CharcoalImage method is:
611 % Image *CharcoalImage(const Image *image,const double radius,
612 % const double sigma,ExceptionInfo *exception)
614 % A description of each parameter follows:
616 % o image: the image.
618 % o radius: the radius of the pixel neighborhood.
620 % o sigma: the standard deviation of the Gaussian, in pixels.
622 % o exception: return any errors or warnings in this structure.
625 MagickExport Image *CharcoalImage(const Image *image,const double radius,
626 const double sigma,ExceptionInfo *exception)
633 assert(image != (Image *) NULL);
634 assert(image->signature == MagickSignature);
635 if (image->debug != MagickFalse)
636 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
637 assert(exception != (ExceptionInfo *) NULL);
638 assert(exception->signature == MagickSignature);
639 clone_image=CloneImage(image,0,0,MagickTrue,exception);
640 if (clone_image == (Image *) NULL)
641 return((Image *) NULL);
642 (void) SetImageType(clone_image,GrayscaleType);
643 edge_image=EdgeImage(clone_image,radius,exception);
644 clone_image=DestroyImage(clone_image);
645 if (edge_image == (Image *) NULL)
646 return((Image *) NULL);
647 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
648 edge_image=DestroyImage(edge_image);
649 if (charcoal_image == (Image *) NULL)
650 return((Image *) NULL);
651 (void) NormalizeImage(charcoal_image,exception);
652 (void) NegateImage(charcoal_image,MagickFalse,exception);
653 (void) SetImageType(charcoal_image,GrayscaleType);
654 return(charcoal_image);
658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662 % C o l o r i z e I m a g e %
666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
668 % ColorizeImage() blends the fill color with each pixel in the image.
669 % A percentage blend is specified with opacity. Control the application
670 % of different color components by specifying a different percentage for
671 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
673 % The format of the ColorizeImage method is:
675 % Image *ColorizeImage(const Image *image,const char *opacity,
676 % const PixelPacket colorize,ExceptionInfo *exception)
678 % A description of each parameter follows:
680 % o image: the image.
682 % o opacity: A character string indicating the level of opacity as a
685 % o colorize: A color value.
687 % o exception: return any errors or warnings in this structure.
690 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
691 const PixelPacket colorize,ExceptionInfo *exception)
693 #define ColorizeImageTag "Colorize/Image"
721 Allocate colorized image.
723 assert(image != (const Image *) NULL);
724 assert(image->signature == MagickSignature);
725 if (image->debug != MagickFalse)
726 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
727 assert(exception != (ExceptionInfo *) NULL);
728 assert(exception->signature == MagickSignature);
729 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
731 if (colorize_image == (Image *) NULL)
732 return((Image *) NULL);
733 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
735 colorize_image=DestroyImage(colorize_image);
736 return((Image *) NULL);
738 if (opacity == (const char *) NULL)
739 return(colorize_image);
741 Determine RGB values of the pen color.
743 flags=ParseGeometry(opacity,&geometry_info);
744 pixel.red=geometry_info.rho;
745 pixel.green=geometry_info.rho;
746 pixel.blue=geometry_info.rho;
747 pixel.alpha=(MagickRealType) OpaqueAlpha;
748 if ((flags & SigmaValue) != 0)
749 pixel.green=geometry_info.sigma;
750 if ((flags & XiValue) != 0)
751 pixel.blue=geometry_info.xi;
752 if ((flags & PsiValue) != 0)
753 pixel.alpha=geometry_info.psi;
755 Colorize DirectClass image.
759 image_view=AcquireCacheView(image);
760 colorize_view=AcquireCacheView(colorize_image);
761 #if defined(MAGICKCORE_OPENMP_SUPPORT)
762 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
764 for (y=0; y < (ssize_t) image->rows; y++)
769 register const Quantum
778 if (status == MagickFalse)
780 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
781 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
783 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
788 for (x=0; x < (ssize_t) image->columns; x++)
790 SetPixelRed(colorize_image,ClampToQuantum((GetPixelRed(image,p)*
791 (100.0-pixel.red)+colorize.red*pixel.red)/100.0),q);
792 SetPixelGreen(colorize_image,ClampToQuantum((GetPixelGreen(image,p)*
793 (100.0-pixel.green)+colorize.green*pixel.green)/100.0),q);
794 SetPixelBlue(colorize_image,ClampToQuantum((GetPixelBlue(image,p)*
795 (100.0-pixel.blue)+colorize.blue*pixel.blue)/100.0),q);
796 SetPixelAlpha(colorize_image,ClampToQuantum((GetPixelAlpha(image,p)*
797 (100.0-pixel.alpha)+colorize.alpha*pixel.alpha)/100.0),q);
798 p+=GetPixelChannels(image);
799 q+=GetPixelChannels(colorize_image);
801 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
802 if (sync == MagickFalse)
804 if (image->progress_monitor != (MagickProgressMonitor) NULL)
809 #if defined(MAGICKCORE_OPENMP_SUPPORT)
810 #pragma omp critical (MagickCore_ColorizeImage)
812 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
813 if (proceed == MagickFalse)
817 image_view=DestroyCacheView(image_view);
818 colorize_view=DestroyCacheView(colorize_view);
819 if (status == MagickFalse)
820 colorize_image=DestroyImage(colorize_image);
821 return(colorize_image);
825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 % C o l o r M a t r i x I m a g e %
833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
835 % ColorMatrixImage() applies color transformation to an image. This method
836 % permits saturation changes, hue rotation, luminance to alpha, and various
837 % other effects. Although variable-sized transformation matrices can be used,
838 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
839 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
840 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
841 % and offsets are normalized (divide Flash offset by 255).
843 % The format of the ColorMatrixImage method is:
845 % Image *ColorMatrixImage(const Image *image,
846 % const KernelInfo *color_matrix,ExceptionInfo *exception)
848 % A description of each parameter follows:
850 % o image: the image.
852 % o color_matrix: the color matrix.
854 % o exception: return any errors or warnings in this structure.
857 MagickExport Image *ColorMatrixImage(const Image *image,
858 const KernelInfo *color_matrix,ExceptionInfo *exception)
860 #define ColorMatrixImageTag "ColorMatrix/Image"
869 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
870 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
871 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
872 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
873 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
874 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
897 assert(image != (Image *) NULL);
898 assert(image->signature == MagickSignature);
899 if (image->debug != MagickFalse)
900 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
901 assert(exception != (ExceptionInfo *) NULL);
902 assert(exception->signature == MagickSignature);
904 for (v=0; v < (ssize_t) color_matrix->height; v++)
905 for (u=0; u < (ssize_t) color_matrix->width; u++)
907 if ((v < 6) && (u < 6))
908 ColorMatrix[v][u]=color_matrix->values[i];
912 Initialize color image.
914 color_image=CloneImage(image,0,0,MagickTrue,exception);
915 if (color_image == (Image *) NULL)
916 return((Image *) NULL);
917 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
919 color_image=DestroyImage(color_image);
920 return((Image *) NULL);
922 if (image->debug != MagickFalse)
925 format[MaxTextExtent],
928 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
929 " ColorMatrix image with color matrix:");
930 message=AcquireString("");
931 for (v=0; v < 6; v++)
934 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
935 (void) ConcatenateString(&message,format);
936 for (u=0; u < 6; u++)
938 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
940 (void) ConcatenateString(&message,format);
942 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
944 message=DestroyString(message);
951 image_view=AcquireCacheView(image);
952 color_view=AcquireCacheView(color_image);
953 #if defined(MAGICKCORE_OPENMP_SUPPORT)
954 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
956 for (y=0; y < (ssize_t) image->rows; y++)
961 register const Quantum
970 if (status == MagickFalse)
972 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
973 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
975 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
980 for (x=0; x < (ssize_t) image->columns; x++)
988 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
989 for (v=0; v < (ssize_t) height; v++)
991 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
992 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
993 if (image->colorspace == CMYKColorspace)
994 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
995 if (image->matte != MagickFalse)
996 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
997 pixel+=QuantumRange*ColorMatrix[v][5];
1000 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1001 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1002 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
1005 if (image->colorspace == CMYKColorspace)
1006 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
1011 if (image->matte != MagickFalse)
1012 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
1017 p+=GetPixelChannels(image);
1018 q+=GetPixelChannels(color_image);
1020 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1022 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1027 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1028 #pragma omp critical (MagickCore_ColorMatrixImage)
1030 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1032 if (proceed == MagickFalse)
1036 color_view=DestroyCacheView(color_view);
1037 image_view=DestroyCacheView(image_view);
1038 if (status == MagickFalse)
1039 color_image=DestroyImage(color_image);
1040 return(color_image);
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 + D e s t r o y F x I n f o %
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1056 % The format of the DestroyFxInfo method is:
1058 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1060 % A description of each parameter follows:
1062 % o fx_info: the fx info.
1065 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1070 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1071 fx_info->expression=DestroyString(fx_info->expression);
1072 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1073 fx_info->colors=DestroySplayTree(fx_info->colors);
1074 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1075 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1076 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1077 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1078 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 + 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 %
1091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093 % FxEvaluateChannelExpression() evaluates an expression and returns the
1096 % The format of the FxEvaluateExpression method is:
1098 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1099 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1100 % MagickRealType *alpha,Exceptioninfo *exception)
1101 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1102 % MagickRealType *alpha,Exceptioninfo *exception)
1104 % A description of each parameter follows:
1106 % o fx_info: the fx info.
1108 % o channel: the channel.
1110 % o x,y: the pixel position.
1112 % o alpha: the result.
1114 % o exception: return any errors or warnings in this structure.
1118 static inline double MagickMax(const double x,const double y)
1125 static inline double MagickMin(const double x,const double y)
1132 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1133 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1137 statistic[MaxTextExtent];
1145 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1147 switch (*++p) /* e.g. depth.r */
1149 case 'r': channel=RedPixelChannel; break;
1150 case 'g': channel=GreenPixelChannel; break;
1151 case 'b': channel=BluePixelChannel; break;
1152 case 'c': channel=CyanPixelChannel; break;
1153 case 'm': channel=MagentaPixelChannel; break;
1154 case 'y': channel=YellowPixelChannel; break;
1155 case 'k': channel=BlackPixelChannel; break;
1158 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1159 (double) channel,symbol);
1160 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1161 if (value != (const char *) NULL)
1162 return(QuantumScale*InterpretLocaleValue(value,(char **) NULL));
1163 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1164 if (LocaleNCompare(symbol,"depth",5) == 0)
1169 depth=GetImageDepth(image,exception);
1170 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1172 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1178 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1179 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1181 if (LocaleNCompare(symbol,"maxima",6) == 0)
1187 (void) GetImageRange(image,&minima,&maxima,exception);
1188 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1190 if (LocaleNCompare(symbol,"mean",4) == 0)
1196 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1197 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1199 if (LocaleNCompare(symbol,"minima",6) == 0)
1205 (void) GetImageRange(image,&minima,&maxima,exception);
1206 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1208 if (LocaleNCompare(symbol,"skewness",8) == 0)
1214 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1215 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1217 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1223 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1224 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1225 standard_deviation);
1227 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1228 ConstantString(statistic));
1229 return(QuantumScale*InterpretLocaleValue(statistic,(char **) NULL));
1232 static MagickRealType
1233 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1234 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1236 static inline MagickRealType FxMax(FxInfo *fx_info,const PixelChannel channel,
1237 const ssize_t x,const ssize_t y,const char *expression,
1238 ExceptionInfo *exception)
1244 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1245 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1248 static inline MagickRealType FxMin(FxInfo *fx_info,PixelChannel channel,
1249 const ssize_t x,const ssize_t y,const char *expression,
1250 ExceptionInfo *exception)
1256 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1257 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1260 static inline const char *FxSubexpression(const char *expression,
1261 ExceptionInfo *exception)
1270 subexpression=expression;
1271 while ((*subexpression != '\0') &&
1272 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1274 if (strchr("(",(int) *subexpression) != (char *) NULL)
1277 if (strchr(")",(int) *subexpression) != (char *) NULL)
1281 if (*subexpression == '\0')
1282 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1283 "UnbalancedParenthesis","`%s'",expression);
1284 return(subexpression);
1287 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1288 const ssize_t x,const ssize_t y,const char *expression,
1289 ExceptionInfo *exception)
1293 subexpression[MaxTextExtent],
1294 symbol[MaxTextExtent];
1323 i=GetImageIndexInList(fx_info->images);
1327 if (isalpha((int) *(p+1)) == 0)
1329 if (strchr("suv",(int) *p) != (char *) NULL)
1336 i=GetImageIndexInList(fx_info->images);
1339 case 'u': i=0; break;
1340 case 'v': i=1; break;
1347 for (p++; *p != '\0'; )
1361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1363 i=(ssize_t) (alpha+0.5);
1369 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1376 for (p++; *p != '\0'; )
1390 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1401 for (p++; *p != '\0'; )
1415 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1425 length=GetImageListLength(fx_info->images);
1427 i+=(ssize_t) length;
1429 image=GetImageFromList(fx_info->images,i);
1430 if (image == (Image *) NULL)
1432 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1433 "NoSuchImage","`%s'",expression);
1436 GetPixelInfo(image,&pixel);
1437 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1438 point.x,point.y,&pixel,exception);
1439 if ((strlen(p) > 2) &&
1440 (LocaleCompare(p,"intensity") != 0) &&
1441 (LocaleCompare(p,"luminance") != 0) &&
1442 (LocaleCompare(p,"hue") != 0) &&
1443 (LocaleCompare(p,"saturation") != 0) &&
1444 (LocaleCompare(p,"lightness") != 0))
1447 name[MaxTextExtent];
1449 (void) CopyMagickString(name,p,MaxTextExtent);
1450 for (q=name+(strlen(name)-1); q > name; q--)
1460 if ((strlen(name) > 2) &&
1461 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1466 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1467 if (color != (PixelInfo *) NULL)
1473 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1475 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1476 ClonePixelInfo(&pixel));
1481 (void) CopyMagickString(symbol,p,MaxTextExtent);
1482 StripString(symbol);
1483 if (*symbol == '\0')
1487 case RedPixelChannel: return(QuantumScale*pixel.red);
1488 case GreenPixelChannel: return(QuantumScale*pixel.green);
1489 case BluePixelChannel: return(QuantumScale*pixel.blue);
1490 case BlackPixelChannel:
1492 if (image->colorspace != CMYKColorspace)
1494 (void) ThrowMagickException(exception,GetMagickModule(),
1495 OptionError,"ColorSeparatedImageRequired","`%s'",
1499 return(QuantumScale*pixel.black);
1501 case AlphaPixelChannel:
1506 if (pixel.matte == MagickFalse)
1508 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1511 case IntensityPixelChannel:
1513 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1518 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1519 "UnableToParseExpression","`%s'",p);
1527 if (LocaleCompare(symbol,"a") == 0)
1528 return((MagickRealType) (QuantumScale*pixel.alpha));
1534 if (LocaleCompare(symbol,"b") == 0)
1535 return(QuantumScale*pixel.blue);
1541 if (LocaleNCompare(symbol,"channel",7) == 0)
1549 flags=ParseGeometry(symbol+7,&channel_info);
1550 if (image->colorspace == CMYKColorspace)
1553 case CyanPixelChannel:
1555 if ((flags & RhoValue) == 0)
1557 return(channel_info.rho);
1559 case MagentaPixelChannel:
1561 if ((flags & SigmaValue) == 0)
1563 return(channel_info.sigma);
1565 case YellowPixelChannel:
1567 if ((flags & XiValue) == 0)
1569 return(channel_info.xi);
1571 case BlackPixelChannel:
1573 if ((flags & PsiValue) == 0)
1575 return(channel_info.psi);
1577 case AlphaPixelChannel:
1579 if ((flags & ChiValue) == 0)
1581 return(channel_info.chi);
1588 case RedPixelChannel:
1590 if ((flags & RhoValue) == 0)
1592 return(channel_info.rho);
1594 case GreenPixelChannel:
1596 if ((flags & SigmaValue) == 0)
1598 return(channel_info.sigma);
1600 case BluePixelChannel:
1602 if ((flags & XiValue) == 0)
1604 return(channel_info.xi);
1606 case BlackPixelChannel:
1608 if ((flags & ChiValue) == 0)
1610 return(channel_info.chi);
1612 case AlphaPixelChannel:
1614 if ((flags & PsiValue) == 0)
1616 return(channel_info.psi);
1623 if (LocaleCompare(symbol,"c") == 0)
1624 return(QuantumScale*pixel.red);
1630 if (LocaleNCompare(symbol,"depth",5) == 0)
1631 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1637 if (LocaleCompare(symbol,"g") == 0)
1638 return(QuantumScale*pixel.green);
1644 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1645 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1646 if (LocaleCompare(symbol,"k") == 0)
1648 if (image->colorspace != CMYKColorspace)
1650 (void) ThrowMagickException(exception,GetMagickModule(),
1651 OptionError,"ColorSeparatedImageRequired","`%s'",
1655 return(QuantumScale*pixel.black);
1662 if (LocaleCompare(symbol,"h") == 0)
1663 return((MagickRealType) image->rows);
1664 if (LocaleCompare(symbol,"hue") == 0)
1671 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1672 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1680 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1681 (LocaleCompare(symbol,"image.minima") == 0) ||
1682 (LocaleCompare(symbol,"image.maxima") == 0) ||
1683 (LocaleCompare(symbol,"image.mean") == 0) ||
1684 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1685 (LocaleCompare(symbol,"image.skewness") == 0) ||
1686 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1687 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1688 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1689 return(image->x_resolution);
1690 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1691 return(image->y_resolution);
1692 if (LocaleCompare(symbol,"intensity") == 0)
1693 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1694 if (LocaleCompare(symbol,"i") == 0)
1695 return((MagickRealType) x);
1701 if (LocaleCompare(symbol,"j") == 0)
1702 return((MagickRealType) y);
1708 if (LocaleCompare(symbol,"lightness") == 0)
1715 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1716 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1719 if (LocaleCompare(symbol,"luminance") == 0)
1724 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1725 return(QuantumScale*luminence);
1732 if (LocaleNCompare(symbol,"maxima",6) == 0)
1733 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1734 if (LocaleNCompare(symbol,"mean",4) == 0)
1735 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1736 if (LocaleNCompare(symbol,"minima",6) == 0)
1737 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1738 if (LocaleCompare(symbol,"m") == 0)
1739 return(QuantumScale*pixel.blue);
1745 if (LocaleCompare(symbol,"n") == 0)
1746 return((MagickRealType) GetImageListLength(fx_info->images));
1752 if (LocaleCompare(symbol,"o") == 0)
1753 return(QuantumScale*pixel.alpha);
1759 if (LocaleCompare(symbol,"page.height") == 0)
1760 return((MagickRealType) image->page.height);
1761 if (LocaleCompare(symbol,"page.width") == 0)
1762 return((MagickRealType) image->page.width);
1763 if (LocaleCompare(symbol,"page.x") == 0)
1764 return((MagickRealType) image->page.x);
1765 if (LocaleCompare(symbol,"page.y") == 0)
1766 return((MagickRealType) image->page.y);
1772 if (LocaleCompare(symbol,"resolution.x") == 0)
1773 return(image->x_resolution);
1774 if (LocaleCompare(symbol,"resolution.y") == 0)
1775 return(image->y_resolution);
1776 if (LocaleCompare(symbol,"r") == 0)
1777 return(QuantumScale*pixel.red);
1783 if (LocaleCompare(symbol,"saturation") == 0)
1790 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1791 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1794 if (LocaleNCompare(symbol,"skewness",8) == 0)
1795 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1796 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1797 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1803 if (LocaleCompare(symbol,"t") == 0)
1804 return((MagickRealType) GetImageIndexInList(fx_info->images));
1810 if (LocaleCompare(symbol,"w") == 0)
1811 return((MagickRealType) image->columns);
1817 if (LocaleCompare(symbol,"y") == 0)
1818 return(QuantumScale*pixel.green);
1824 if (LocaleCompare(symbol,"z") == 0)
1829 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1837 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1838 if (value != (const char *) NULL)
1839 return((MagickRealType) InterpretLocaleValue(value,(char **) NULL));
1840 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1841 "UnableToParseExpression","`%s'",symbol);
1845 static const char *FxOperatorPrecedence(const char *expression,
1846 ExceptionInfo *exception)
1850 UndefinedPrecedence,
1852 BitwiseComplementPrecedence,
1854 ExponentialNotationPrecedence,
1858 RelationalPrecedence,
1859 EquivalencyPrecedence,
1860 BitwiseAndPrecedence,
1861 BitwiseOrPrecedence,
1862 LogicalAndPrecedence,
1863 LogicalOrPrecedence,
1865 AssignmentPrecedence,
1885 subexpression=(const char *) NULL;
1886 target=NullPrecedence;
1887 while (*expression != '\0')
1889 precedence=UndefinedPrecedence;
1890 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1895 switch (*expression)
1900 #if defined(MAGICKCORE_HAVE_ACOSH)
1901 if (LocaleNCompare(expression,"acosh",5) == 0)
1907 #if defined(MAGICKCORE_HAVE_ASINH)
1908 if (LocaleNCompare(expression,"asinh",5) == 0)
1914 #if defined(MAGICKCORE_HAVE_ATANH)
1915 if (LocaleNCompare(expression,"atanh",5) == 0)
1926 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1927 (LocaleNCompare(expression,"j1",2) == 0))
1936 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1943 if ((c == (int) '{') || (c == (int) '['))
1946 if ((c == (int) '}') || (c == (int) ']'))
1949 switch ((unsigned char) *expression)
1954 precedence=BitwiseComplementPrecedence;
1960 precedence=ExponentPrecedence;
1965 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1966 (strchr(")",c) != (char *) NULL))) &&
1967 (((islower((int) ((char) *expression)) != 0) ||
1968 (strchr("(",(int) *expression) != (char *) NULL)) ||
1969 ((isdigit((int) ((char) c)) == 0) &&
1970 (isdigit((int) ((char) *expression)) != 0))) &&
1971 (strchr("xy",(int) *expression) == (char *) NULL))
1972 precedence=MultiplyPrecedence;
1979 precedence=MultiplyPrecedence;
1985 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1987 precedence=AdditionPrecedence;
1990 case LeftShiftOperator:
1991 case RightShiftOperator:
1993 precedence=ShiftPrecedence;
1997 case LessThanEqualOperator:
1998 case GreaterThanEqualOperator:
2001 precedence=RelationalPrecedence;
2005 case NotEqualOperator:
2007 precedence=EquivalencyPrecedence;
2012 precedence=BitwiseAndPrecedence;
2017 precedence=BitwiseOrPrecedence;
2020 case LogicalAndOperator:
2022 precedence=LogicalAndPrecedence;
2025 case LogicalOrOperator:
2027 precedence=LogicalOrPrecedence;
2030 case ExponentialNotation:
2032 precedence=ExponentialNotationPrecedence;
2038 precedence=TernaryPrecedence;
2043 precedence=AssignmentPrecedence;
2048 precedence=CommaPrecedence;
2053 precedence=SeparatorPrecedence;
2057 if ((precedence == BitwiseComplementPrecedence) ||
2058 (precedence == TernaryPrecedence) ||
2059 (precedence == AssignmentPrecedence))
2061 if (precedence > target)
2064 Right-to-left associativity.
2067 subexpression=expression;
2071 if (precedence >= target)
2074 Left-to-right associativity.
2077 subexpression=expression;
2079 if (strchr("(",(int) *expression) != (char *) NULL)
2080 expression=FxSubexpression(expression,exception);
2081 c=(int) (*expression++);
2083 return(subexpression);
2086 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2087 const PixelChannel channel,const ssize_t x,const ssize_t y,
2088 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2092 subexpression[MaxTextExtent];
2102 if (exception->severity != UndefinedException)
2104 while (isspace((int) *expression) != 0)
2106 if (*expression == '\0')
2108 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2109 "MissingExpression","`%s'",expression);
2112 *subexpression='\0';
2113 p=FxOperatorPrecedence(expression,exception);
2114 if (p != (const char *) NULL)
2116 (void) CopyMagickString(subexpression,expression,(size_t)
2118 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2120 switch ((unsigned char) *p)
2124 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2125 *beta=(MagickRealType) (~(size_t) *beta);
2130 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2131 return(*beta == 0.0 ? 1.0 : 0.0);
2135 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2136 channel,x,y,++p,beta,exception));
2140 case ExponentialNotation:
2142 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2143 return(alpha*(*beta));
2147 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2150 if (exception->severity == UndefinedException)
2151 (void) ThrowMagickException(exception,GetMagickModule(),
2152 OptionError,"DivideByZero","`%s'",expression);
2155 return(alpha/(*beta));
2159 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2160 *beta=fabs(floor(((double) *beta)+0.5));
2163 (void) ThrowMagickException(exception,GetMagickModule(),
2164 OptionError,"DivideByZero","`%s'",expression);
2167 return(fmod((double) alpha,(double) *beta));
2171 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2172 return(alpha+(*beta));
2176 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2177 return(alpha-(*beta));
2179 case LeftShiftOperator:
2181 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2182 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2186 case RightShiftOperator:
2188 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2189 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2195 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2196 return(alpha < *beta ? 1.0 : 0.0);
2198 case LessThanEqualOperator:
2200 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2201 return(alpha <= *beta ? 1.0 : 0.0);
2205 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2206 return(alpha > *beta ? 1.0 : 0.0);
2208 case GreaterThanEqualOperator:
2210 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2211 return(alpha >= *beta ? 1.0 : 0.0);
2215 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2216 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2218 case NotEqualOperator:
2220 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2221 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2225 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2226 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2232 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2233 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2237 case LogicalAndOperator:
2239 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2240 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2243 case LogicalOrOperator:
2245 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2246 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2254 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2256 p=StringToken(":",&q);
2257 if (q == (char *) NULL)
2259 (void) ThrowMagickException(exception,GetMagickModule(),
2260 OptionError,"UnableToParseExpression","`%s'",subexpression);
2263 if (fabs((double) alpha) > MagickEpsilon)
2264 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2266 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2272 numeric[MaxTextExtent];
2275 while (isalpha((int) ((unsigned char) *q)) != 0)
2279 (void) ThrowMagickException(exception,GetMagickModule(),
2280 OptionError,"UnableToParseExpression","`%s'",subexpression);
2283 ClearMagickException(exception);
2284 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2285 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2287 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2288 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2289 subexpression),ConstantString(numeric));
2294 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2299 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2304 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2310 if (strchr("(",(int) *expression) != (char *) NULL)
2312 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2313 subexpression[strlen(subexpression)-1]='\0';
2314 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2318 switch (*expression)
2322 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2328 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2334 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2336 return((MagickRealType) (~(size_t) (gamma+0.5)));
2341 if (LocaleNCompare(expression,"abs",3) == 0)
2343 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2345 return((MagickRealType) fabs((double) alpha));
2347 #if defined(MAGICKCORE_HAVE_ACOSH)
2348 if (LocaleNCompare(expression,"acosh",5) == 0)
2350 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2352 return((MagickRealType) acosh((double) alpha));
2355 if (LocaleNCompare(expression,"acos",4) == 0)
2357 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2359 return((MagickRealType) acos((double) alpha));
2361 #if defined(MAGICKCORE_HAVE_J1)
2362 if (LocaleNCompare(expression,"airy",4) == 0)
2364 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2368 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2369 return(gamma*gamma);
2372 #if defined(MAGICKCORE_HAVE_ASINH)
2373 if (LocaleNCompare(expression,"asinh",5) == 0)
2375 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2377 return((MagickRealType) asinh((double) alpha));
2380 if (LocaleNCompare(expression,"asin",4) == 0)
2382 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2384 return((MagickRealType) asin((double) alpha));
2386 if (LocaleNCompare(expression,"alt",3) == 0)
2388 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2390 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2392 if (LocaleNCompare(expression,"atan2",5) == 0)
2394 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2396 return((MagickRealType) atan2((double) alpha,(double) *beta));
2398 #if defined(MAGICKCORE_HAVE_ATANH)
2399 if (LocaleNCompare(expression,"atanh",5) == 0)
2401 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2403 return((MagickRealType) atanh((double) alpha));
2406 if (LocaleNCompare(expression,"atan",4) == 0)
2408 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2410 return((MagickRealType) atan((double) alpha));
2412 if (LocaleCompare(expression,"a") == 0)
2413 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2419 if (LocaleCompare(expression,"b") == 0)
2420 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2426 if (LocaleNCompare(expression,"ceil",4) == 0)
2428 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2430 return((MagickRealType) ceil((double) alpha));
2432 if (LocaleNCompare(expression,"cosh",4) == 0)
2434 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2436 return((MagickRealType) cosh((double) alpha));
2438 if (LocaleNCompare(expression,"cos",3) == 0)
2440 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2442 return((MagickRealType) cos((double) alpha));
2444 if (LocaleCompare(expression,"c") == 0)
2445 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2451 if (LocaleNCompare(expression,"debug",5) == 0)
2456 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2458 if (fx_info->images->colorspace == CMYKColorspace)
2461 case CyanPixelChannel: type="cyan"; break;
2462 case MagentaPixelChannel: type="magenta"; break;
2463 case YellowPixelChannel: type="yellow"; break;
2464 case AlphaPixelChannel: type="opacity"; break;
2465 case BlackPixelChannel: type="black"; break;
2466 default: type="unknown"; break;
2471 case RedPixelChannel: type="red"; break;
2472 case GreenPixelChannel: type="green"; break;
2473 case BluePixelChannel: type="blue"; break;
2474 case AlphaPixelChannel: type="opacity"; break;
2475 default: type="unknown"; break;
2477 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2478 if (strlen(subexpression) > 1)
2479 subexpression[strlen(subexpression)-1]='\0';
2480 if (fx_info->file != (FILE *) NULL)
2481 (void) FormatLocaleFile(fx_info->file,
2482 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2483 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2492 if (LocaleCompare(expression,"epsilon") == 0)
2493 return((MagickRealType) MagickEpsilon);
2494 if (LocaleNCompare(expression,"exp",3) == 0)
2496 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2498 return((MagickRealType) exp((double) alpha));
2500 if (LocaleCompare(expression,"e") == 0)
2501 return((MagickRealType) 2.7182818284590452354);
2507 if (LocaleNCompare(expression,"floor",5) == 0)
2509 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2511 return((MagickRealType) floor((double) alpha));
2518 if (LocaleCompare(expression,"g") == 0)
2519 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2525 if (LocaleCompare(expression,"h") == 0)
2526 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2527 if (LocaleCompare(expression,"hue") == 0)
2528 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2529 if (LocaleNCompare(expression,"hypot",5) == 0)
2531 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2533 return((MagickRealType) hypot((double) alpha,(double) *beta));
2540 if (LocaleCompare(expression,"k") == 0)
2541 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2547 if (LocaleCompare(expression,"intensity") == 0)
2548 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2549 if (LocaleNCompare(expression,"int",3) == 0)
2551 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2553 return((MagickRealType) floor(alpha));
2555 if (LocaleCompare(expression,"i") == 0)
2556 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2562 if (LocaleCompare(expression,"j") == 0)
2563 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2564 #if defined(MAGICKCORE_HAVE_J0)
2565 if (LocaleNCompare(expression,"j0",2) == 0)
2567 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2569 return((MagickRealType) j0((double) alpha));
2572 #if defined(MAGICKCORE_HAVE_J1)
2573 if (LocaleNCompare(expression,"j1",2) == 0)
2575 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2577 return((MagickRealType) j1((double) alpha));
2580 #if defined(MAGICKCORE_HAVE_J1)
2581 if (LocaleNCompare(expression,"jinc",4) == 0)
2583 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2587 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2597 if (LocaleNCompare(expression,"ln",2) == 0)
2599 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2601 return((MagickRealType) log((double) alpha));
2603 if (LocaleNCompare(expression,"logtwo",6) == 0)
2605 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2607 return((MagickRealType) log10((double) alpha))/log10(2.0);
2609 if (LocaleNCompare(expression,"log",3) == 0)
2611 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2613 return((MagickRealType) log10((double) alpha));
2615 if (LocaleCompare(expression,"lightness") == 0)
2616 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2622 if (LocaleCompare(expression,"MaxRGB") == 0)
2623 return((MagickRealType) QuantumRange);
2624 if (LocaleNCompare(expression,"maxima",6) == 0)
2626 if (LocaleNCompare(expression,"max",3) == 0)
2627 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2628 if (LocaleNCompare(expression,"minima",6) == 0)
2630 if (LocaleNCompare(expression,"min",3) == 0)
2631 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2632 if (LocaleNCompare(expression,"mod",3) == 0)
2634 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2636 return((MagickRealType) fmod((double) alpha,(double) *beta));
2638 if (LocaleCompare(expression,"m") == 0)
2639 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2645 if (LocaleCompare(expression,"n") == 0)
2646 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2652 if (LocaleCompare(expression,"Opaque") == 0)
2654 if (LocaleCompare(expression,"o") == 0)
2655 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2661 if (LocaleCompare(expression,"pi") == 0)
2662 return((MagickRealType) MagickPI);
2663 if (LocaleNCompare(expression,"pow",3) == 0)
2665 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2667 return((MagickRealType) pow((double) alpha,(double) *beta));
2669 if (LocaleCompare(expression,"p") == 0)
2670 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2676 if (LocaleCompare(expression,"QuantumRange") == 0)
2677 return((MagickRealType) QuantumRange);
2678 if (LocaleCompare(expression,"QuantumScale") == 0)
2679 return((MagickRealType) QuantumScale);
2685 if (LocaleNCompare(expression,"rand",4) == 0)
2686 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2687 if (LocaleNCompare(expression,"round",5) == 0)
2689 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2691 return((MagickRealType) floor((double) alpha+0.5));
2693 if (LocaleCompare(expression,"r") == 0)
2694 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2700 if (LocaleCompare(expression,"saturation") == 0)
2701 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2702 if (LocaleNCompare(expression,"sign",4) == 0)
2704 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2706 return(alpha < 0.0 ? -1.0 : 1.0);
2708 if (LocaleNCompare(expression,"sinc",4) == 0)
2710 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2714 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2718 if (LocaleNCompare(expression,"sinh",4) == 0)
2720 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2722 return((MagickRealType) sinh((double) alpha));
2724 if (LocaleNCompare(expression,"sin",3) == 0)
2726 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2728 return((MagickRealType) sin((double) alpha));
2730 if (LocaleNCompare(expression,"sqrt",4) == 0)
2732 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2734 return((MagickRealType) sqrt((double) alpha));
2736 if (LocaleCompare(expression,"s") == 0)
2737 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2743 if (LocaleNCompare(expression,"tanh",4) == 0)
2745 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2747 return((MagickRealType) tanh((double) alpha));
2749 if (LocaleNCompare(expression,"tan",3) == 0)
2751 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2753 return((MagickRealType) tan((double) alpha));
2755 if (LocaleCompare(expression,"Transparent") == 0)
2757 if (LocaleNCompare(expression,"trunc",5) == 0)
2759 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2762 return((MagickRealType) floor((double) alpha));
2763 return((MagickRealType) ceil((double) alpha));
2765 if (LocaleCompare(expression,"t") == 0)
2766 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2772 if (LocaleCompare(expression,"u") == 0)
2773 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2779 if (LocaleCompare(expression,"v") == 0)
2780 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2786 if (LocaleCompare(expression,"w") == 0)
2787 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2793 if (LocaleCompare(expression,"y") == 0)
2794 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2800 if (LocaleCompare(expression,"z") == 0)
2801 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2807 q=(char *) expression;
2808 alpha=InterpretLocaleValue(expression,&q);
2809 if (q == expression)
2810 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2814 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2815 MagickRealType *alpha,ExceptionInfo *exception)
2820 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2825 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2826 MagickRealType *alpha,ExceptionInfo *exception)
2835 fx_info->file=(FILE *) NULL;
2836 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2842 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2843 const PixelChannel channel,const ssize_t x,const ssize_t y,
2844 MagickRealType *alpha,ExceptionInfo *exception)
2850 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2852 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2856 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2866 % FxImage() applies a mathematical expression to the specified image.
2868 % The format of the FxImage method is:
2870 % Image *FxImage(const Image *image,const char *expression,
2871 % ExceptionInfo *exception)
2873 % A description of each parameter follows:
2875 % o image: the image.
2877 % o expression: A mathematical expression.
2879 % o exception: return any errors or warnings in this structure.
2883 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2888 assert(fx_info != (FxInfo **) NULL);
2889 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2890 if (fx_info[i] != (FxInfo *) NULL)
2891 fx_info[i]=DestroyFxInfo(fx_info[i]);
2892 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2896 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2897 ExceptionInfo *exception)
2914 number_threads=GetOpenMPMaximumThreads();
2915 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2916 if (fx_info == (FxInfo **) NULL)
2917 return((FxInfo **) NULL);
2918 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2919 if (*expression != '@')
2920 fx_expression=ConstantString(expression);
2922 fx_expression=FileToString(expression+1,~0,exception);
2923 for (i=0; i < (ssize_t) number_threads; i++)
2925 fx_info[i]=AcquireFxInfo(image,fx_expression);
2926 if (fx_info[i] == (FxInfo *) NULL)
2927 return(DestroyFxThreadSet(fx_info));
2928 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2930 fx_expression=DestroyString(fx_expression);
2934 MagickExport Image *FxImage(const Image *image,const char *expression,
2935 ExceptionInfo *exception)
2937 #define FxImageTag "Fx/Image"
2961 assert(image != (Image *) NULL);
2962 assert(image->signature == MagickSignature);
2963 if (image->debug != MagickFalse)
2964 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2965 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
2966 if (fx_image == (Image *) NULL)
2967 return((Image *) NULL);
2968 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
2970 fx_image=DestroyImage(fx_image);
2971 return((Image *) NULL);
2973 fx_info=AcquireFxThreadSet(image,expression,exception);
2974 if (fx_info == (FxInfo **) NULL)
2976 fx_image=DestroyImage(fx_image);
2977 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2979 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2980 if (status == MagickFalse)
2982 fx_image=DestroyImage(fx_image);
2983 fx_info=DestroyFxThreadSet(fx_info);
2984 return((Image *) NULL);
2991 image_view=AcquireCacheView(image);
2992 fx_view=AcquireCacheView(fx_image);
2993 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2994 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2996 for (y=0; y < (ssize_t) fx_image->rows; y++)
2999 id = GetOpenMPThreadId();
3001 register const Quantum
3010 if (status == MagickFalse)
3012 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3013 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3014 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3019 for (x=0; x < (ssize_t) fx_image->columns; x++)
3024 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3036 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3037 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3038 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3039 if ((traits == UndefinedPixelTrait) ||
3040 (fx_traits == UndefinedPixelTrait))
3042 if ((fx_traits & CopyPixelTrait) != 0)
3048 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3050 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3052 p+=GetPixelChannels(image);
3053 q+=GetPixelChannels(fx_image);
3055 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3057 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3062 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3063 #pragma omp critical (MagickCore_FxImage)
3065 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3066 if (proceed == MagickFalse)
3070 fx_view=DestroyCacheView(fx_view);
3071 image_view=DestroyCacheView(image_view);
3072 fx_info=DestroyFxThreadSet(fx_info);
3073 if (status == MagickFalse)
3074 fx_image=DestroyImage(fx_image);
3079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3083 % I m p l o d e I m a g e %
3087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3089 % ImplodeImage() creates a new image that is a copy of an existing
3090 % one with the image pixels "implode" by the specified percentage. It
3091 % allocates the memory necessary for the new Image structure and returns a
3092 % pointer to the new image.
3094 % The format of the ImplodeImage method is:
3096 % Image *ImplodeImage(const Image *image,const double amount,
3097 % ExceptionInfo *exception)
3099 % A description of each parameter follows:
3101 % o implode_image: Method ImplodeImage returns a pointer to the image
3102 % after it is implode. A null image is returned if there is a memory
3105 % o image: the image.
3107 % o amount: Define the extent of the implosion.
3109 % o exception: return any errors or warnings in this structure.
3112 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3113 ExceptionInfo *exception)
3115 #define ImplodeImageTag "Implode/Image"
3144 Initialize implode image attributes.
3146 assert(image != (Image *) NULL);
3147 assert(image->signature == MagickSignature);
3148 if (image->debug != MagickFalse)
3149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3150 assert(exception != (ExceptionInfo *) NULL);
3151 assert(exception->signature == MagickSignature);
3152 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3153 if (implode_image == (Image *) NULL)
3154 return((Image *) NULL);
3155 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3157 implode_image=DestroyImage(implode_image);
3158 return((Image *) NULL);
3160 if (implode_image->background_color.alpha != OpaqueAlpha)
3161 implode_image->matte=MagickTrue;
3163 Compute scaling factor.
3167 center.x=0.5*image->columns;
3168 center.y=0.5*image->rows;
3170 if (image->columns > image->rows)
3171 scale.y=(double) image->columns/(double) image->rows;
3173 if (image->columns < image->rows)
3175 scale.x=(double) image->rows/(double) image->columns;
3183 GetPixelInfo(implode_image,&zero);
3184 image_view=AcquireCacheView(image);
3185 implode_view=AcquireCacheView(implode_image);
3186 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3187 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3189 for (y=0; y < (ssize_t) image->rows; y++)
3206 if (status == MagickFalse)
3208 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3210 if (q == (Quantum *) NULL)
3215 delta.y=scale.y*(double) (y-center.y);
3217 for (x=0; x < (ssize_t) image->columns; x++)
3220 Determine if the pixel is within an ellipse.
3222 delta.x=scale.x*(double) (x-center.x);
3223 distance=delta.x*delta.x+delta.y*delta.y;
3224 if (distance < (radius*radius))
3234 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3235 radius/2)),-amount);
3236 (void) InterpolatePixelInfo(image,image_view,
3237 UndefinedInterpolatePixel,(double) (factor*delta.x/scale.x+
3238 center.x),(double) (factor*delta.y/scale.y+center.y),&pixel,
3240 SetPixelPixelInfo(implode_image,&pixel,q);
3242 q+=GetPixelChannels(implode_image);
3244 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3246 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3251 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3252 #pragma omp critical (MagickCore_ImplodeImage)
3254 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3255 if (proceed == MagickFalse)
3259 implode_view=DestroyCacheView(implode_view);
3260 image_view=DestroyCacheView(image_view);
3261 if (status == MagickFalse)
3262 implode_image=DestroyImage(implode_image);
3263 return(implode_image);
3267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3271 % M o r p h I m a g e s %
3275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3277 % The MorphImages() method requires a minimum of two images. The first
3278 % image is transformed into the second by a number of intervening images
3279 % as specified by frames.
3281 % The format of the MorphImage method is:
3283 % Image *MorphImages(const Image *image,const size_t number_frames,
3284 % ExceptionInfo *exception)
3286 % A description of each parameter follows:
3288 % o image: the image.
3290 % o number_frames: Define the number of in-between image to generate.
3291 % The more in-between frames, the smoother the morph.
3293 % o exception: return any errors or warnings in this structure.
3296 MagickExport Image *MorphImages(const Image *image,
3297 const size_t number_frames,ExceptionInfo *exception)
3299 #define MorphImageTag "Morph/Image"
3315 register const Image
3325 Clone first frame in sequence.
3327 assert(image != (Image *) NULL);
3328 assert(image->signature == MagickSignature);
3329 if (image->debug != MagickFalse)
3330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3331 assert(exception != (ExceptionInfo *) NULL);
3332 assert(exception->signature == MagickSignature);
3333 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3334 if (morph_images == (Image *) NULL)
3335 return((Image *) NULL);
3336 if (GetNextImageInList(image) == (Image *) NULL)
3341 for (i=1; i < (ssize_t) number_frames; i++)
3343 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3344 if (morph_image == (Image *) NULL)
3346 morph_images=DestroyImageList(morph_images);
3347 return((Image *) NULL);
3349 AppendImageToList(&morph_images,morph_image);
3350 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3355 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3357 if (proceed == MagickFalse)
3361 return(GetFirstImageInList(morph_images));
3364 Morph image sequence.
3369 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3371 for (i=0; i < (ssize_t) number_frames; i++)
3377 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3379 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3380 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3381 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3382 next->filter,next->blur,exception);
3383 if (morph_image == (Image *) NULL)
3385 morph_images=DestroyImageList(morph_images);
3386 return((Image *) NULL);
3388 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
3390 morph_image=DestroyImage(morph_image);
3391 return((Image *) NULL);
3393 AppendImageToList(&morph_images,morph_image);
3394 morph_images=GetLastImageInList(morph_images);
3395 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3396 morph_images->rows,GetNextImageInList(next)->filter,
3397 GetNextImageInList(next)->blur,exception);
3398 if (morph_image == (Image *) NULL)
3400 morph_images=DestroyImageList(morph_images);
3401 return((Image *) NULL);
3403 image_view=AcquireCacheView(morph_image);
3404 morph_view=AcquireCacheView(morph_images);
3405 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3406 #pragma omp parallel for schedule(dynamic,4) shared(status)
3408 for (y=0; y < (ssize_t) morph_images->rows; y++)
3413 register const Quantum
3422 if (status == MagickFalse)
3424 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3426 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3428 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3433 for (x=0; x < (ssize_t) morph_images->columns; x++)
3435 SetPixelRed(morph_images,ClampToQuantum(alpha*
3436 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3437 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3438 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3439 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3440 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3441 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3442 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3443 if ((morph_image->colorspace == CMYKColorspace) &&
3444 (morph_images->colorspace == CMYKColorspace))
3445 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3446 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3448 p+=GetPixelChannels(morph_image);
3449 q+=GetPixelChannels(morph_images);
3451 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3452 if (sync == MagickFalse)
3455 morph_view=DestroyCacheView(morph_view);
3456 image_view=DestroyCacheView(image_view);
3457 morph_image=DestroyImage(morph_image);
3459 if (i < (ssize_t) number_frames)
3462 Clone last frame in sequence.
3464 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3465 if (morph_image == (Image *) NULL)
3467 morph_images=DestroyImageList(morph_images);
3468 return((Image *) NULL);
3470 AppendImageToList(&morph_images,morph_image);
3471 morph_images=GetLastImageInList(morph_images);
3472 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3477 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3478 #pragma omp critical (MagickCore_MorphImages)
3480 proceed=SetImageProgress(image,MorphImageTag,scene,
3481 GetImageListLength(image));
3482 if (proceed == MagickFalse)
3487 if (GetNextImageInList(next) != (Image *) NULL)
3489 morph_images=DestroyImageList(morph_images);
3490 return((Image *) NULL);
3492 return(GetFirstImageInList(morph_images));
3496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3500 % P l a s m a I m a g e %
3504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3506 % PlasmaImage() initializes an image with plasma fractal values. The image
3507 % must be initialized with a base color and the random number generator
3508 % seeded before this method is called.
3510 % The format of the PlasmaImage method is:
3512 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3513 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3515 % A description of each parameter follows:
3517 % o image: the image.
3519 % o segment: Define the region to apply plasma fractals values.
3521 % o attenuate: Define the plasma attenuation factor.
3523 % o depth: Limit the plasma recursion depth.
3525 % o exception: return any errors or warnings in this structure.
3529 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3530 const MagickRealType pixel,const MagickRealType noise)
3535 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3540 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3541 CacheView *image_view,RandomInfo *random_info,const SegmentInfo *segment,
3542 size_t attenuate,size_t depth,ExceptionInfo *exception)
3557 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3565 Divide the area into quadrants and recurse.
3569 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3570 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3571 local_info=(*segment);
3572 local_info.x2=(double) x_mid;
3573 local_info.y2=(double) y_mid;
3574 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3575 attenuate,depth,exception);
3576 local_info=(*segment);
3577 local_info.y1=(double) y_mid;
3578 local_info.x2=(double) x_mid;
3579 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3580 attenuate,depth,exception);
3581 local_info=(*segment);
3582 local_info.x1=(double) x_mid;
3583 local_info.y2=(double) y_mid;
3584 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3585 attenuate,depth,exception);
3586 local_info=(*segment);
3587 local_info.x1=(double) x_mid;
3588 local_info.y1=(double) y_mid;
3589 return(PlasmaImageProxy(image,image_view,random_info,&local_info,
3590 attenuate,depth,exception));
3592 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3593 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3594 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3595 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3596 return(MagickFalse);
3598 Average pixels and apply plasma.
3600 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3601 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3609 x=(ssize_t) ceil(segment->x1-0.5);
3610 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3611 ceil(segment->y1-0.5),&u,exception);
3612 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3613 ceil(segment->y2-0.5),&v,exception);
3614 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3615 if (q == (Quantum *) NULL)
3617 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3618 (u.red+v.red)/2.0,plasma),q);
3619 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3620 (u.green+v.green)/2.0,plasma),q);
3621 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3622 (u.blue+v.blue)/2.0,plasma),q);
3623 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3624 if (segment->x1 != segment->x2)
3629 x=(ssize_t) ceil(segment->x2-0.5);
3630 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3631 ceil(segment->y1-0.5),&u,exception);
3632 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3633 ceil(segment->y2-0.5),&v,exception);
3634 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3635 if (q == (Quantum *) NULL)
3637 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3638 (u.red+v.red)/2.0,plasma),q);
3639 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3640 (u.green+v.green)/2.0,plasma),q);
3641 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3642 (u.blue+v.blue)/2.0,plasma),q);
3643 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3646 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3648 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3656 y=(ssize_t) ceil(segment->y2-0.5);
3657 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3658 ceil(segment->x1-0.5),y,&u,exception);
3659 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3660 ceil(segment->x2-0.5),y,&v,exception);
3661 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3662 if (q == (Quantum *) NULL)
3664 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3665 (u.red+v.red)/2.0,plasma),q);
3666 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3667 (u.green+v.green)/2.0,plasma),q);
3668 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3669 (u.blue+v.blue)/2.0,plasma),q);
3670 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3672 if (segment->y1 != segment->y2)
3680 y=(ssize_t) ceil(segment->y1-0.5);
3681 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3682 ceil(segment->x1-0.5),y,&u,exception);
3683 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3684 ceil(segment->x2-0.5),y,&v,exception);
3685 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3686 if (q == (Quantum *) NULL)
3688 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3689 (u.red+v.red)/2.0,plasma),q);
3690 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3691 (u.green+v.green)/2.0,plasma),q);
3692 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3693 (u.blue+v.blue)/2.0,plasma),q);
3694 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3697 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3705 x=(ssize_t) ceil(segment->x1-0.5);
3706 y=(ssize_t) ceil(segment->y1-0.5);
3707 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3708 x=(ssize_t) ceil(segment->x2-0.5);
3709 y=(ssize_t) ceil(segment->y2-0.5);
3710 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&v,exception);
3711 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3712 if (q == (Quantum *) NULL)
3714 SetPixelRed(image,PlasmaPixel(random_info,(MagickRealType)
3715 (u.red+v.red)/2.0,plasma),q);
3716 SetPixelGreen(image,PlasmaPixel(random_info,(MagickRealType)
3717 (u.green+v.green)/2.0,plasma),q);
3718 SetPixelBlue(image,PlasmaPixel(random_info,(MagickRealType)
3719 (u.blue+v.blue)/2.0,plasma),q);
3720 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3722 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3724 return(MagickFalse);
3727 MagickExport MagickBooleanType PlasmaImage(Image *image,
3728 const SegmentInfo *segment,size_t attenuate,size_t depth,
3729 ExceptionInfo *exception)
3740 if (image->debug != MagickFalse)
3741 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3742 assert(image != (Image *) NULL);
3743 assert(image->signature == MagickSignature);
3744 if (image->debug != MagickFalse)
3745 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3746 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3747 return(MagickFalse);
3748 image_view=AcquireCacheView(image);
3749 random_info=AcquireRandomInfo();
3750 status=PlasmaImageProxy(image,image_view,random_info,segment,attenuate,depth,
3752 random_info=DestroyRandomInfo(random_info);
3753 image_view=DestroyCacheView(image_view);
3758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3762 % P o l a r o i d I m a g e %
3766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3768 % PolaroidImage() simulates a Polaroid picture.
3770 % The format of the AnnotateImage method is:
3772 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3773 % const double angle,ExceptionInfo exception)
3775 % A description of each parameter follows:
3777 % o image: the image.
3779 % o draw_info: the draw info.
3781 % o angle: Apply the effect along this angle.
3783 % o exception: return any errors or warnings in this structure.
3786 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3787 const double angle,ExceptionInfo *exception)
3808 Simulate a Polaroid picture.
3810 assert(image != (Image *) NULL);
3811 assert(image->signature == MagickSignature);
3812 if (image->debug != MagickFalse)
3813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3814 assert(exception != (ExceptionInfo *) NULL);
3815 assert(exception->signature == MagickSignature);
3816 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3817 image->rows)/25.0,10.0);
3818 height=image->rows+2*quantum;
3819 caption_image=(Image *) NULL;
3820 value=GetImageProperty(image,"Caption");
3821 if (value != (const char *) NULL)
3825 geometry[MaxTextExtent];
3840 Generate caption image.
3842 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3843 if (caption_image == (Image *) NULL)
3844 return((Image *) NULL);
3845 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3846 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3848 (void) CloneString(&annotate_info->text,caption);
3849 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3850 &caption,exception);
3851 status=SetImageExtent(caption_image,image->columns,(size_t)
3852 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
3853 if (status == MagickFalse)
3854 caption_image=DestroyImage(caption_image);
3857 caption_image->background_color=image->border_color;
3858 (void) SetImageBackgroundColor(caption_image);
3859 (void) CloneString(&annotate_info->text,caption);
3860 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
3862 if (annotate_info->gravity == UndefinedGravity)
3863 (void) CloneString(&annotate_info->geometry,AcquireString(
3865 (void) AnnotateImage(caption_image,annotate_info,exception);
3866 height+=caption_image->rows;
3868 annotate_info=DestroyDrawInfo(annotate_info);
3869 caption=DestroyString(caption);
3871 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3873 if (picture_image == (Image *) NULL)
3875 if (caption_image != (Image *) NULL)
3876 caption_image=DestroyImage(caption_image);
3877 return((Image *) NULL);
3879 picture_image->background_color=image->border_color;
3880 (void) SetImageBackgroundColor(picture_image);
3881 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3882 if (caption_image != (Image *) NULL)
3884 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3885 quantum,(ssize_t) (image->rows+3*quantum/2));
3886 caption_image=DestroyImage(caption_image);
3888 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3889 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
3890 rotate_image=RotateImage(picture_image,90.0,exception);
3891 picture_image=DestroyImage(picture_image);
3892 if (rotate_image == (Image *) NULL)
3893 return((Image *) NULL);
3894 picture_image=rotate_image;
3895 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3896 picture_image->columns,exception);
3897 picture_image=DestroyImage(picture_image);
3898 if (bend_image == (Image *) NULL)
3899 return((Image *) NULL);
3900 InheritException(&bend_image->exception,exception);
3901 picture_image=bend_image;
3902 rotate_image=RotateImage(picture_image,-90.0,exception);
3903 picture_image=DestroyImage(picture_image);
3904 if (rotate_image == (Image *) NULL)
3905 return((Image *) NULL);
3906 picture_image=rotate_image;
3907 picture_image->background_color=image->background_color;
3908 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3910 if (polaroid_image == (Image *) NULL)
3912 picture_image=DestroyImage(picture_image);
3913 return(picture_image);
3915 flop_image=FlopImage(polaroid_image,exception);
3916 polaroid_image=DestroyImage(polaroid_image);
3917 if (flop_image == (Image *) NULL)
3919 picture_image=DestroyImage(picture_image);
3920 return(picture_image);
3922 polaroid_image=flop_image;
3923 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3924 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3925 picture_image=DestroyImage(picture_image);
3926 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3927 rotate_image=RotateImage(polaroid_image,angle,exception);
3928 polaroid_image=DestroyImage(polaroid_image);
3929 if (rotate_image == (Image *) NULL)
3930 return((Image *) NULL);
3931 polaroid_image=rotate_image;
3932 trim_image=TrimImage(polaroid_image,exception);
3933 polaroid_image=DestroyImage(polaroid_image);
3934 if (trim_image == (Image *) NULL)
3935 return((Image *) NULL);
3936 polaroid_image=trim_image;
3937 return(polaroid_image);
3941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3945 % S e p i a T o n e I m a g e %
3949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3951 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3952 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3953 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3954 % threshold of 80% is a good starting point for a reasonable tone.
3956 % The format of the SepiaToneImage method is:
3958 % Image *SepiaToneImage(const Image *image,const double threshold,
3959 % ExceptionInfo *exception)
3961 % A description of each parameter follows:
3963 % o image: the image.
3965 % o threshold: the tone threshold.
3967 % o exception: return any errors or warnings in this structure.
3970 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3971 ExceptionInfo *exception)
3973 #define SepiaToneImageTag "SepiaTone/Image"
3992 Initialize sepia-toned image attributes.
3994 assert(image != (const Image *) NULL);
3995 assert(image->signature == MagickSignature);
3996 if (image->debug != MagickFalse)
3997 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3998 assert(exception != (ExceptionInfo *) NULL);
3999 assert(exception->signature == MagickSignature);
4000 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4001 if (sepia_image == (Image *) NULL)
4002 return((Image *) NULL);
4003 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4005 sepia_image=DestroyImage(sepia_image);
4006 return((Image *) NULL);
4009 Tone each row of the image.
4013 image_view=AcquireCacheView(image);
4014 sepia_view=AcquireCacheView(sepia_image);
4015 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4016 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4018 for (y=0; y < (ssize_t) image->rows; y++)
4020 register const Quantum
4029 if (status == MagickFalse)
4031 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4032 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4034 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4039 for (x=0; x < (ssize_t) image->columns; x++)
4045 intensity=(MagickRealType) GetPixelIntensity(image,p);
4046 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4047 (MagickRealType) QuantumRange-threshold;
4048 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4049 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4050 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4051 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4052 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4053 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4055 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4056 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4057 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4058 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4059 p+=GetPixelChannels(image);
4060 q+=GetPixelChannels(sepia_image);
4062 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4064 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4069 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4070 #pragma omp critical (MagickCore_SepiaToneImage)
4072 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4074 if (proceed == MagickFalse)
4078 sepia_view=DestroyCacheView(sepia_view);
4079 image_view=DestroyCacheView(image_view);
4080 (void) NormalizeImage(sepia_image,exception);
4081 (void) ContrastImage(sepia_image,MagickTrue,exception);
4082 if (status == MagickFalse)
4083 sepia_image=DestroyImage(sepia_image);
4084 return(sepia_image);
4088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4092 % S h a d o w I m a g e %
4096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4098 % ShadowImage() simulates a shadow from the specified image and returns it.
4100 % The format of the ShadowImage method is:
4102 % Image *ShadowImage(const Image *image,const double opacity,
4103 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4104 % ExceptionInfo *exception)
4106 % A description of each parameter follows:
4108 % o image: the image.
4110 % o opacity: percentage transparency.
4112 % o sigma: the standard deviation of the Gaussian, in pixels.
4114 % o x_offset: the shadow x-offset.
4116 % o y_offset: the shadow y-offset.
4118 % o exception: return any errors or warnings in this structure.
4121 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4122 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4123 ExceptionInfo *exception)
4125 #define ShadowImageTag "Shadow/Image"
4150 assert(image != (Image *) NULL);
4151 assert(image->signature == MagickSignature);
4152 if (image->debug != MagickFalse)
4153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4154 assert(exception != (ExceptionInfo *) NULL);
4155 assert(exception->signature == MagickSignature);
4156 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4157 if (clone_image == (Image *) NULL)
4158 return((Image *) NULL);
4159 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4160 clone_image->compose=OverCompositeOp;
4161 border_info.width=(size_t) floor(2.0*sigma+0.5);
4162 border_info.height=(size_t) floor(2.0*sigma+0.5);
4165 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4166 border_image=BorderImage(clone_image,&border_info,exception);
4167 clone_image=DestroyImage(clone_image);
4168 if (border_image == (Image *) NULL)
4169 return((Image *) NULL);
4170 if (border_image->matte == MagickFalse)
4171 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4177 border_view=AcquireCacheView(border_image);
4178 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4179 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4181 for (y=0; y < (ssize_t) border_image->rows; y++)
4189 if (status == MagickFalse)
4191 q=GetCacheViewAuthenticPixels(border_view,0,y,border_image->columns,1,
4193 if (q == (Quantum *) NULL)
4198 for (x=0; x < (ssize_t) border_image->columns; x++)
4200 SetPixelRed(border_image,border_image->background_color.red,q);
4201 SetPixelGreen(border_image,border_image->background_color.green,q);
4202 SetPixelBlue(border_image,border_image->background_color.blue,q);
4203 if (border_image->matte == MagickFalse)
4204 SetPixelAlpha(border_image,border_image->background_color.alpha,q);
4206 SetPixelAlpha(border_image,ClampToQuantum((MagickRealType)
4207 (GetPixelAlpha(border_image,q)*opacity/100.0)),q);
4208 q+=GetPixelChannels(border_image);
4210 if (SyncCacheViewAuthenticPixels(border_view,exception) == MagickFalse)
4212 if (border_image->progress_monitor != (MagickProgressMonitor) NULL)
4217 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4218 #pragma omp critical (MagickCore_ShadowImage)
4220 proceed=SetImageProgress(border_image,ShadowImageTag,progress++,
4221 border_image->rows);
4222 if (proceed == MagickFalse)
4226 border_view=DestroyCacheView(border_view);
4227 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4228 shadow_image=BlurImage(border_image,0.0,sigma,exception);
4229 (void) SetPixelChannelMap(border_image,channel_mask);
4230 border_image=DestroyImage(border_image);
4231 if (shadow_image == (Image *) NULL)
4232 return((Image *) NULL);
4233 if (shadow_image->page.width == 0)
4234 shadow_image->page.width=shadow_image->columns;
4235 if (shadow_image->page.height == 0)
4236 shadow_image->page.height=shadow_image->rows;
4237 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4238 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4239 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4240 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4241 return(shadow_image);
4245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4249 % S k e t c h I m a g e %
4253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4255 % SketchImage() simulates a pencil sketch. We convolve the image with a
4256 % Gaussian operator of the given radius and standard deviation (sigma). For
4257 % reasonable results, radius should be larger than sigma. Use a radius of 0
4258 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4261 % The format of the SketchImage method is:
4263 % Image *SketchImage(const Image *image,const double radius,
4264 % const double sigma,const double angle,ExceptionInfo *exception)
4266 % A description of each parameter follows:
4268 % o image: the image.
4270 % o radius: the radius of the Gaussian, in pixels, not counting the
4273 % o sigma: the standard deviation of the Gaussian, in pixels.
4275 % o angle: Apply the effect along this angle.
4277 % o exception: return any errors or warnings in this structure.
4280 MagickExport Image *SketchImage(const Image *image,const double radius,
4281 const double sigma,const double angle,ExceptionInfo *exception)
4300 **restrict random_info;
4308 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4309 MagickTrue,exception);
4310 if (random_image == (Image *) NULL)
4311 return((Image *) NULL);
4313 GetPixelInfo(random_image,&zero);
4314 random_info=AcquireRandomInfoThreadSet();
4315 random_view=AcquireCacheView(random_image);
4316 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4317 #pragma omp parallel for schedule(dynamic,4) shared(status)
4319 for (y=0; y < (ssize_t) random_image->rows; y++)
4322 id = GetOpenMPThreadId();
4333 if (status == MagickFalse)
4335 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4337 if (q == (Quantum *) NULL)
4343 for (x=0; x < (ssize_t) random_image->columns; x++)
4345 pixel.red=(MagickRealType) (QuantumRange*
4346 GetPseudoRandomValue(random_info[id]));
4347 pixel.green=pixel.red;
4348 pixel.blue=pixel.red;
4349 if (image->colorspace == CMYKColorspace)
4350 pixel.black=pixel.red;
4351 SetPixelPixelInfo(random_image,&pixel,q);
4352 q+=GetPixelChannels(random_image);
4354 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4357 random_view=DestroyCacheView(random_view);
4358 random_info=DestroyRandomInfoThreadSet(random_info);
4359 if (status == MagickFalse)
4361 random_image=DestroyImage(random_image);
4362 return(random_image);
4364 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4365 random_image=DestroyImage(random_image);
4366 if (blur_image == (Image *) NULL)
4367 return((Image *) NULL);
4368 dodge_image=EdgeImage(blur_image,radius,exception);
4369 blur_image=DestroyImage(blur_image);
4370 if (dodge_image == (Image *) NULL)
4371 return((Image *) NULL);
4372 (void) NormalizeImage(dodge_image,exception);
4373 (void) NegateImage(dodge_image,MagickFalse,exception);
4374 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4375 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4376 if (sketch_image == (Image *) NULL)
4378 dodge_image=DestroyImage(dodge_image);
4379 return((Image *) NULL);
4381 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4382 dodge_image=DestroyImage(dodge_image);
4383 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4384 if (blend_image == (Image *) NULL)
4386 sketch_image=DestroyImage(sketch_image);
4387 return((Image *) NULL);
4389 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4390 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4391 blend_image=DestroyImage(blend_image);
4392 return(sketch_image);
4396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4400 % S o l a r i z e I m a g e %
4404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4406 % SolarizeImage() applies a special effect to the image, similar to the effect
4407 % achieved in a photo darkroom by selectively exposing areas of photo
4408 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4409 % measure of the extent of the solarization.
4411 % The format of the SolarizeImage method is:
4413 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4414 % ExceptionInfo *exception)
4416 % A description of each parameter follows:
4418 % o image: the image.
4420 % o threshold: Define the extent of the solarization.
4422 % o exception: return any errors or warnings in this structure.
4425 MagickExport MagickBooleanType SolarizeImage(Image *image,
4426 const double threshold,ExceptionInfo *exception)
4428 #define SolarizeImageTag "Solarize/Image"
4442 assert(image != (Image *) NULL);
4443 assert(image->signature == MagickSignature);
4444 if (image->debug != MagickFalse)
4445 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4446 if (image->storage_class == PseudoClass)
4454 for (i=0; i < (ssize_t) image->colors; i++)
4456 if ((MagickRealType) image->colormap[i].red > threshold)
4457 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4458 if ((MagickRealType) image->colormap[i].green > threshold)
4459 image->colormap[i].green=(Quantum) QuantumRange-
4460 image->colormap[i].green;
4461 if ((MagickRealType) image->colormap[i].blue > threshold)
4462 image->colormap[i].blue=(Quantum) QuantumRange-
4463 image->colormap[i].blue;
4471 image_view=AcquireCacheView(image);
4472 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4473 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4475 for (y=0; y < (ssize_t) image->rows; y++)
4483 if (status == MagickFalse)
4485 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4486 if (q == (Quantum *) NULL)
4491 for (x=0; x < (ssize_t) image->columns; x++)
4493 if ((MagickRealType) GetPixelRed(image,q) > threshold)
4494 SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
4495 if ((MagickRealType) GetPixelGreen(image,q) > threshold)
4496 SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
4497 if ((MagickRealType) GetPixelBlue(image,q) > threshold)
4498 SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
4499 q+=GetPixelChannels(image);
4501 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4503 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4508 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4509 #pragma omp critical (MagickCore_SolarizeImage)
4511 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4512 if (proceed == MagickFalse)
4516 image_view=DestroyCacheView(image_view);
4521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4525 % S t e g a n o I m a g e %
4529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4531 % SteganoImage() hides a digital watermark within the image. Recover
4532 % the hidden watermark later to prove that the authenticity of an image.
4533 % Offset defines the start position within the image to hide the watermark.
4535 % The format of the SteganoImage method is:
4537 % Image *SteganoImage(const Image *image,Image *watermark,
4538 % ExceptionInfo *exception)
4540 % A description of each parameter follows:
4542 % o image: the image.
4544 % o watermark: the watermark image.
4546 % o exception: return any errors or warnings in this structure.
4549 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4550 ExceptionInfo *exception)
4552 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4553 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4554 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4555 #define SteganoImageTag "Stegano/Image"
4590 Initialize steganographic image attributes.
4592 assert(image != (const Image *) NULL);
4593 assert(image->signature == MagickSignature);
4594 if (image->debug != MagickFalse)
4595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4596 assert(watermark != (const Image *) NULL);
4597 assert(watermark->signature == MagickSignature);
4598 assert(exception != (ExceptionInfo *) NULL);
4599 assert(exception->signature == MagickSignature);
4601 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4602 if (stegano_image == (Image *) NULL)
4603 return((Image *) NULL);
4604 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4606 stegano_image=DestroyImage(stegano_image);
4607 return((Image *) NULL);
4609 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4611 Hide watermark in low-order bits of image.
4616 depth=stegano_image->depth;
4619 watermark_view=AcquireCacheView(watermark);
4620 stegano_view=AcquireCacheView(stegano_image);
4621 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4623 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4625 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4627 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,&pixel,exception);
4628 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4630 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4631 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4633 if (q == (Quantum *) NULL)
4639 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
4640 GetPixelPacketIntensity(&pixel),i)),q);
4645 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
4646 GetPixelPacketIntensity(&pixel),i)),q);
4651 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
4652 GetPixelPacketIntensity(&pixel),i)),q);
4656 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4662 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4664 if (k == image->offset)
4668 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4673 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4675 if (proceed == MagickFalse)
4679 stegano_view=DestroyCacheView(stegano_view);
4680 watermark_view=DestroyCacheView(watermark_view);
4681 if (stegano_image->storage_class == PseudoClass)
4682 (void) SyncImage(stegano_image);
4683 if (status == MagickFalse)
4685 stegano_image=DestroyImage(stegano_image);
4686 return((Image *) NULL);
4688 return(stegano_image);
4692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4696 % S t e r e o A n a g l y p h I m a g e %
4700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4702 % StereoAnaglyphImage() combines two images and produces a single image that
4703 % is the composite of a left and right image of a stereo pair. Special
4704 % red-green stereo glasses are required to view this effect.
4706 % The format of the StereoAnaglyphImage method is:
4708 % Image *StereoImage(const Image *left_image,const Image *right_image,
4709 % ExceptionInfo *exception)
4710 % Image *StereoAnaglyphImage(const Image *left_image,
4711 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4712 % ExceptionInfo *exception)
4714 % A description of each parameter follows:
4716 % o left_image: the left image.
4718 % o right_image: the right image.
4720 % o exception: return any errors or warnings in this structure.
4722 % o x_offset: amount, in pixels, by which the left image is offset to the
4723 % right of the right image.
4725 % o y_offset: amount, in pixels, by which the left image is offset to the
4726 % bottom of the right image.
4730 MagickExport Image *StereoImage(const Image *left_image,
4731 const Image *right_image,ExceptionInfo *exception)
4733 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4736 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4737 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4738 ExceptionInfo *exception)
4740 #define StereoImageTag "Stereo/Image"
4754 assert(left_image != (const Image *) NULL);
4755 assert(left_image->signature == MagickSignature);
4756 if (left_image->debug != MagickFalse)
4757 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4758 left_image->filename);
4759 assert(right_image != (const Image *) NULL);
4760 assert(right_image->signature == MagickSignature);
4761 assert(exception != (ExceptionInfo *) NULL);
4762 assert(exception->signature == MagickSignature);
4763 assert(right_image != (const Image *) NULL);
4765 if ((left_image->columns != right_image->columns) ||
4766 (left_image->rows != right_image->rows))
4767 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4769 Initialize stereo image attributes.
4771 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4772 MagickTrue,exception);
4773 if (stereo_image == (Image *) NULL)
4774 return((Image *) NULL);
4775 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4777 stereo_image=DestroyImage(stereo_image);
4778 return((Image *) NULL);
4781 Copy left image to red channel and right image to blue channel.
4784 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4786 register const Quantum
4796 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4798 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4799 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4800 if ((p == (const Quantum *) NULL) ||
4801 (q == (Quantum *) NULL) || (r == (Quantum *) NULL))
4803 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4805 SetPixelRed(image,GetPixelRed(left_image,p),r);
4806 SetPixelGreen(image,GetPixelGreen(left_image,q),r);
4807 SetPixelBlue(image,GetPixelBlue(left_image,q),r);
4808 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4809 GetPixelAlpha(left_image,q))/2,r);
4810 p+=GetPixelChannels(left_image);
4814 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4816 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4821 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4822 stereo_image->rows);
4823 if (proceed == MagickFalse)
4827 if (status == MagickFalse)
4829 stereo_image=DestroyImage(stereo_image);
4830 return((Image *) NULL);
4832 return(stereo_image);
4836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4840 % S w i r l I m a g e %
4844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4846 % SwirlImage() swirls the pixels about the center of the image, where
4847 % degrees indicates the sweep of the arc through which each pixel is moved.
4848 % You get a more dramatic effect as the degrees move from 1 to 360.
4850 % The format of the SwirlImage method is:
4852 % Image *SwirlImage(const Image *image,double degrees,
4853 % ExceptionInfo *exception)
4855 % A description of each parameter follows:
4857 % o image: the image.
4859 % o degrees: Define the tightness of the swirling effect.
4861 % o exception: return any errors or warnings in this structure.
4864 MagickExport Image *SwirlImage(const Image *image,double degrees,
4865 ExceptionInfo *exception)
4867 #define SwirlImageTag "Swirl/Image"
4896 Initialize swirl image attributes.
4898 assert(image != (const Image *) NULL);
4899 assert(image->signature == MagickSignature);
4900 if (image->debug != MagickFalse)
4901 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4902 assert(exception != (ExceptionInfo *) NULL);
4903 assert(exception->signature == MagickSignature);
4904 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4905 if (swirl_image == (Image *) NULL)
4906 return((Image *) NULL);
4907 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
4909 swirl_image=DestroyImage(swirl_image);
4910 return((Image *) NULL);
4912 if (swirl_image->background_color.alpha != OpaqueAlpha)
4913 swirl_image->matte=MagickTrue;
4915 Compute scaling factor.
4917 center.x=(double) image->columns/2.0;
4918 center.y=(double) image->rows/2.0;
4919 radius=MagickMax(center.x,center.y);
4922 if (image->columns > image->rows)
4923 scale.y=(double) image->columns/(double) image->rows;
4925 if (image->columns < image->rows)
4926 scale.x=(double) image->rows/(double) image->columns;
4927 degrees=(double) DegreesToRadians(degrees);
4933 GetPixelInfo(swirl_image,&zero);
4934 image_view=AcquireCacheView(image);
4935 swirl_view=AcquireCacheView(swirl_image);
4936 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4937 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4939 for (y=0; y < (ssize_t) image->rows; y++)
4956 if (status == MagickFalse)
4958 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4960 if (q == (Quantum *) NULL)
4965 delta.y=scale.y*(double) (y-center.y);
4967 for (x=0; x < (ssize_t) image->columns; x++)
4970 Determine if the pixel is within an ellipse.
4972 delta.x=scale.x*(double) (x-center.x);
4973 distance=delta.x*delta.x+delta.y*delta.y;
4974 if (distance < (radius*radius))
4984 factor=1.0-sqrt((double) distance)/radius;
4985 sine=sin((double) (degrees*factor*factor));
4986 cosine=cos((double) (degrees*factor*factor));
4987 (void) InterpolatePixelInfo(image,image_view,
4988 UndefinedInterpolatePixel,(double) ((cosine*delta.x-sine*delta.y)/
4989 scale.x+center.x),(double) ((sine*delta.x+cosine*delta.y)/scale.y+
4990 center.y),&pixel,exception);
4991 SetPixelPixelInfo(swirl_image,&pixel,q);
4993 q+=GetPixelChannels(swirl_image);
4995 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4997 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5002 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5003 #pragma omp critical (MagickCore_SwirlImage)
5005 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5006 if (proceed == MagickFalse)
5010 swirl_view=DestroyCacheView(swirl_view);
5011 image_view=DestroyCacheView(image_view);
5012 if (status == MagickFalse)
5013 swirl_image=DestroyImage(swirl_image);
5014 return(swirl_image);
5018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5022 % T i n t I m a g e %
5026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5028 % TintImage() applies a color vector to each pixel in the image. The length
5029 % of the vector is 0 for black and white and at its maximum for the midtones.
5030 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5032 % The format of the TintImage method is:
5034 % Image *TintImage(const Image *image,const char *opacity,
5035 % const PixelPacket tint,ExceptionInfo *exception)
5037 % A description of each parameter follows:
5039 % o image: the image.
5041 % o opacity: A color value used for tinting.
5043 % o tint: A color value used for tinting.
5045 % o exception: return any errors or warnings in this structure.
5048 MagickExport Image *TintImage(const Image *image,const char *opacity,
5049 const PixelPacket tint,ExceptionInfo *exception)
5051 #define TintImageTag "Tint/Image"
5080 Allocate tint image.
5082 assert(image != (const Image *) NULL);
5083 assert(image->signature == MagickSignature);
5084 if (image->debug != MagickFalse)
5085 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5086 assert(exception != (ExceptionInfo *) NULL);
5087 assert(exception->signature == MagickSignature);
5088 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5089 if (tint_image == (Image *) NULL)
5090 return((Image *) NULL);
5091 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5093 tint_image=DestroyImage(tint_image);
5094 return((Image *) NULL);
5096 if (opacity == (const char *) NULL)
5099 Determine RGB values of the color.
5101 flags=ParseGeometry(opacity,&geometry_info);
5102 pixel.red=geometry_info.rho;
5103 if ((flags & SigmaValue) != 0)
5104 pixel.green=geometry_info.sigma;
5106 pixel.green=pixel.red;
5107 if ((flags & XiValue) != 0)
5108 pixel.blue=geometry_info.xi;
5110 pixel.blue=pixel.red;
5111 if ((flags & PsiValue) != 0)
5112 pixel.alpha=geometry_info.psi;
5114 pixel.alpha=(MagickRealType) OpaqueAlpha;
5115 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5116 GetPixelPacketIntensity(&tint));
5117 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5118 GetPixelPacketIntensity(&tint));
5119 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5120 GetPixelPacketIntensity(&tint));
5126 image_view=AcquireCacheView(image);
5127 tint_view=AcquireCacheView(tint_image);
5128 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5129 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5131 for (y=0; y < (ssize_t) image->rows; y++)
5133 register const Quantum
5142 if (status == MagickFalse)
5144 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5145 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5147 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5152 for (x=0; x < (ssize_t) image->columns; x++)
5160 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5161 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
5162 (1.0-(4.0*(weight*weight)));
5163 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5164 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5165 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
5166 (1.0-(4.0*(weight*weight)));
5167 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5168 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5169 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
5170 (1.0-(4.0*(weight*weight)));
5171 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5172 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
5173 p+=GetPixelChannels(image);
5174 q+=GetPixelChannels(tint_image);
5176 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5178 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5183 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5184 #pragma omp critical (MagickCore_TintImage)
5186 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5187 if (proceed == MagickFalse)
5191 tint_view=DestroyCacheView(tint_view);
5192 image_view=DestroyCacheView(image_view);
5193 if (status == MagickFalse)
5194 tint_image=DestroyImage(tint_image);
5199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5203 % V i g n e t t e I m a g e %
5207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5209 % VignetteImage() softens the edges of the image in vignette style.
5211 % The format of the VignetteImage method is:
5213 % Image *VignetteImage(const Image *image,const double radius,
5214 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5216 % A description of each parameter follows:
5218 % o image: the image.
5220 % o radius: the radius of the pixel neighborhood.
5222 % o sigma: the standard deviation of the Gaussian, in pixels.
5224 % o x, y: Define the x and y ellipse offset.
5226 % o exception: return any errors or warnings in this structure.
5229 MagickExport Image *VignetteImage(const Image *image,const double radius,
5230 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5233 ellipse[MaxTextExtent];
5244 assert(image != (Image *) NULL);
5245 assert(image->signature == MagickSignature);
5246 if (image->debug != MagickFalse)
5247 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5248 assert(exception != (ExceptionInfo *) NULL);
5249 assert(exception->signature == MagickSignature);
5250 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5251 if (canvas_image == (Image *) NULL)
5252 return((Image *) NULL);
5253 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5255 canvas_image=DestroyImage(canvas_image);
5256 return((Image *) NULL);
5258 canvas_image->matte=MagickTrue;
5259 oval_image=CloneImage(canvas_image,canvas_image->columns,
5260 canvas_image->rows,MagickTrue,exception);
5261 if (oval_image == (Image *) NULL)
5263 canvas_image=DestroyImage(canvas_image);
5264 return((Image *) NULL);
5266 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5267 (void) SetImageBackgroundColor(oval_image);
5268 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5269 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5270 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5271 (void) FormatLocaleString(ellipse,MaxTextExtent,
5272 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5273 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5274 draw_info->primitive=AcquireString(ellipse);
5275 (void) DrawImage(oval_image,draw_info);
5276 draw_info=DestroyDrawInfo(draw_info);
5277 blur_image=BlurImage(oval_image,radius,sigma,exception);
5278 oval_image=DestroyImage(oval_image);
5279 if (blur_image == (Image *) NULL)
5281 canvas_image=DestroyImage(canvas_image);
5282 return((Image *) NULL);
5284 blur_image->matte=MagickFalse;
5285 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5286 blur_image=DestroyImage(blur_image);
5287 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5288 canvas_image=DestroyImage(canvas_image);
5289 return(vignette_image);
5293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5297 % W a v e I m a g e %
5301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5303 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5304 % vertically along a sine wave whose amplitude and wavelength is specified
5305 % by the given parameters.
5307 % The format of the WaveImage method is:
5309 % Image *WaveImage(const Image *image,const double amplitude,
5310 % const double wave_length,ExceptionInfo *exception)
5312 % A description of each parameter follows:
5314 % o image: the image.
5316 % o amplitude, wave_length: Define the amplitude and wave length of the
5319 % o exception: return any errors or warnings in this structure.
5322 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5323 const double wave_length,ExceptionInfo *exception)
5325 #define WaveImageTag "Wave/Image"
5353 Initialize wave image attributes.
5355 assert(image != (Image *) NULL);
5356 assert(image->signature == MagickSignature);
5357 if (image->debug != MagickFalse)
5358 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5359 assert(exception != (ExceptionInfo *) NULL);
5360 assert(exception->signature == MagickSignature);
5361 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5362 fabs(amplitude)),MagickTrue,exception);
5363 if (wave_image == (Image *) NULL)
5364 return((Image *) NULL);
5365 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5367 wave_image=DestroyImage(wave_image);
5368 return((Image *) NULL);
5370 if (wave_image->background_color.alpha != OpaqueAlpha)
5371 wave_image->matte=MagickTrue;
5375 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5377 if (sine_map == (MagickRealType *) NULL)
5379 wave_image=DestroyImage(wave_image);
5380 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5382 for (i=0; i < (ssize_t) wave_image->columns; i++)
5383 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5390 GetPixelInfo(wave_image,&zero);
5391 image_view=AcquireCacheView(image);
5392 wave_view=AcquireCacheView(wave_image);
5393 (void) SetCacheViewVirtualPixelMethod(image_view,
5394 BackgroundVirtualPixelMethod);
5395 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5396 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5398 for (y=0; y < (ssize_t) wave_image->rows; y++)
5409 if (status == MagickFalse)
5411 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5413 if (q == (Quantum *) NULL)
5419 for (x=0; x < (ssize_t) wave_image->columns; x++)
5421 (void) InterpolatePixelInfo(image,image_view,
5422 UndefinedInterpolatePixel,(double) x,(double) (y-sine_map[x]),&pixel,
5424 SetPixelPixelInfo(wave_image,&pixel,q);
5425 q+=GetPixelChannels(wave_image);
5427 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5429 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5434 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5435 #pragma omp critical (MagickCore_WaveImage)
5437 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5438 if (proceed == MagickFalse)
5442 wave_view=DestroyCacheView(wave_view);
5443 image_view=DestroyCacheView(image_view);
5444 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5445 if (status == MagickFalse)
5446 wave_image=DestroyImage(wave_image);