2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/annotate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/cache-view.h"
49 #include "MagickCore/color.h"
50 #include "MagickCore/color-private.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/decorate.h"
53 #include "MagickCore/draw.h"
54 #include "MagickCore/effect.h"
55 #include "MagickCore/enhance.h"
56 #include "MagickCore/exception.h"
57 #include "MagickCore/exception-private.h"
58 #include "MagickCore/fx.h"
59 #include "MagickCore/fx-private.h"
60 #include "MagickCore/gem.h"
61 #include "MagickCore/gem-private.h"
62 #include "MagickCore/geometry.h"
63 #include "MagickCore/layer.h"
64 #include "MagickCore/list.h"
65 #include "MagickCore/log.h"
66 #include "MagickCore/image.h"
67 #include "MagickCore/image-private.h"
68 #include "MagickCore/magick.h"
69 #include "MagickCore/memory_.h"
70 #include "MagickCore/monitor.h"
71 #include "MagickCore/monitor-private.h"
72 #include "MagickCore/option.h"
73 #include "MagickCore/pixel.h"
74 #include "MagickCore/pixel-accessor.h"
75 #include "MagickCore/property.h"
76 #include "MagickCore/quantum.h"
77 #include "MagickCore/quantum-private.h"
78 #include "MagickCore/random_.h"
79 #include "MagickCore/random-private.h"
80 #include "MagickCore/resample.h"
81 #include "MagickCore/resample-private.h"
82 #include "MagickCore/resize.h"
83 #include "MagickCore/shear.h"
84 #include "MagickCore/splay-tree.h"
85 #include "MagickCore/statistic.h"
86 #include "MagickCore/string_.h"
87 #include "MagickCore/string-private.h"
88 #include "MagickCore/thread-private.h"
89 #include "MagickCore/transform.h"
90 #include "MagickCore/utility.h"
95 #define LeftShiftOperator 0xf5
96 #define RightShiftOperator 0xf6
97 #define LessThanEqualOperator 0xf7
98 #define GreaterThanEqualOperator 0xf8
99 #define EqualOperator 0xf9
100 #define NotEqualOperator 0xfa
101 #define LogicalAndOperator 0xfb
102 #define LogicalOrOperator 0xfc
103 #define ExponentialNotation 0xfd
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 + A c q u i r e F x I n f o %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % AcquireFxInfo() allocates the FxInfo structure.
143 % The format of the AcquireFxInfo method is:
145 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
147 % A description of each parameter follows:
149 % o image: the image.
151 % o expression: the expression.
154 MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
168 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
169 if (fx_info == (FxInfo *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
172 fx_info->exception=AcquireExceptionInfo();
173 fx_info->images=image;
174 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
177 RelinquishMagickMemory);
178 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
179 fx_info->images),sizeof(*fx_info->view));
180 if (fx_info->view == (CacheView **) NULL)
181 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
183 next=GetFirstImageInList(fx_info->images);
184 for ( ; next != (Image *) NULL; next=next->next)
186 fx_info->view[i]=AcquireCacheView(next);
189 fx_info->random_info=AcquireRandomInfo();
190 fx_info->expression=ConstantString(expression);
191 fx_info->file=stderr;
192 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
194 Force right-to-left associativity for unary negation.
196 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
197 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
198 (strstr(fx_info->expression,"e-") != (char *) NULL))
201 Convert scientific notation.
203 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
204 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
205 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
206 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
207 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
208 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
209 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
210 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
211 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
212 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
213 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
214 (void) SubstituteString(&fx_info->expression,"1e-1.0*","1**10^-");
215 (void) SubstituteString(&fx_info->expression,"2e-1.0*","2**10^-");
216 (void) SubstituteString(&fx_info->expression,"3e-1.0*","3**10^-");
217 (void) SubstituteString(&fx_info->expression,"4e-1.0*","4**10^-");
218 (void) SubstituteString(&fx_info->expression,"5e-1.0*","5**10^-");
219 (void) SubstituteString(&fx_info->expression,"6e-1.0*","6**10^-");
220 (void) SubstituteString(&fx_info->expression,"7e-1.0*","7**10^-");
221 (void) SubstituteString(&fx_info->expression,"8e-1.0*","8**10^-");
222 (void) SubstituteString(&fx_info->expression,"9e-1.0*","9**10^-");
224 if ((strstr(fx_info->expression,"E+") != (char *) NULL) ||
225 (strstr(fx_info->expression,"E-") != (char *) NULL))
228 Convert scientific notation.
230 (void) SubstituteString(&fx_info->expression,"0E+","0**10^");
231 (void) SubstituteString(&fx_info->expression,"1E+","1**10^");
232 (void) SubstituteString(&fx_info->expression,"2E+","2**10^");
233 (void) SubstituteString(&fx_info->expression,"3E+","3**10^");
234 (void) SubstituteString(&fx_info->expression,"4E+","4**10^");
235 (void) SubstituteString(&fx_info->expression,"5E+","5**10^");
236 (void) SubstituteString(&fx_info->expression,"6E+","6**10^");
237 (void) SubstituteString(&fx_info->expression,"7E+","7**10^");
238 (void) SubstituteString(&fx_info->expression,"8E+","8**10^");
239 (void) SubstituteString(&fx_info->expression,"9E+","9**10^");
240 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
241 (void) SubstituteString(&fx_info->expression,"1E-1.0*","1**10^-");
242 (void) SubstituteString(&fx_info->expression,"2E-1.0*","2**10^-");
243 (void) SubstituteString(&fx_info->expression,"3E-1.0*","3**10^-");
244 (void) SubstituteString(&fx_info->expression,"4E-1.0*","4**10^-");
245 (void) SubstituteString(&fx_info->expression,"5E-1.0*","5**10^-");
246 (void) SubstituteString(&fx_info->expression,"6E-1.0*","6**10^-");
247 (void) SubstituteString(&fx_info->expression,"7E-1.0*","7**10^-");
248 (void) SubstituteString(&fx_info->expression,"8E-1.0*","8**10^-");
249 (void) SubstituteString(&fx_info->expression,"9E-1.0*","9**10^-");
252 Convert complex to simple operators.
255 *fx_op=(char) LeftShiftOperator;
256 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
257 *fx_op=(char) RightShiftOperator;
258 (void) SubstituteString(&fx_info->expression,">>",fx_op);
259 *fx_op=(char) LessThanEqualOperator;
260 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
261 *fx_op=(char) GreaterThanEqualOperator;
262 (void) SubstituteString(&fx_info->expression,">=",fx_op);
263 *fx_op=(char) EqualOperator;
264 (void) SubstituteString(&fx_info->expression,"==",fx_op);
265 *fx_op=(char) NotEqualOperator;
266 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
267 *fx_op=(char) LogicalAndOperator;
268 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
269 *fx_op=(char) LogicalOrOperator;
270 (void) SubstituteString(&fx_info->expression,"||",fx_op);
271 *fx_op=(char) ExponentialNotation;
272 (void) SubstituteString(&fx_info->expression,"**",fx_op);
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 % A d d N o i s e I m a g e %
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 % AddNoiseImage() adds random noise to the image.
289 % The format of the AddNoiseImage method is:
291 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
292 % ExceptionInfo *exception)
294 % A description of each parameter follows:
296 % o image: the image.
298 % o channel: the channel type.
300 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
301 % Impulse, Laplacian, or Poisson.
303 % o exception: return any errors or warnings in this structure.
306 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, ExceptionInfo *exception)
308 #define AddNoiseImageTag "AddNoise/Image"
330 **restrict random_info;
336 Initialize noise image attributes.
338 assert(image != (const Image *) NULL);
339 assert(image->signature == MagickSignature);
340 if (image->debug != MagickFalse)
341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
342 assert(exception != (ExceptionInfo *) NULL);
343 assert(exception->signature == MagickSignature);
344 noise_image=CloneImage(image,0,0,MagickTrue,exception);
345 if (noise_image == (Image *) NULL)
346 return((Image *) NULL);
347 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
349 noise_image=DestroyImage(noise_image);
350 return((Image *) NULL);
353 Add noise in each row.
356 option=GetImageArtifact(image,"attenuate");
357 if (option != (char *) NULL)
358 attenuate=InterpretLocaleValue(option,(char **) NULL);
361 random_info=AcquireRandomInfoThreadSet();
362 image_view=AcquireCacheView(image);
363 noise_view=AcquireCacheView(noise_image);
364 #if defined(MAGICKCORE_OPENMP_SUPPORT)
365 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
367 for (y=0; y < (ssize_t) image->rows; y++)
370 id = GetOpenMPThreadId();
375 register const Quantum
384 if (status == MagickFalse)
386 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
387 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
389 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
394 for (x=0; x < (ssize_t) image->columns; x++)
396 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
397 SetPixelRed(noise_image,ClampToQuantum(GenerateDifferentialNoise(
398 random_info[id],GetPixelRed(image,p),noise_type,attenuate)),q);
399 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
400 SetPixelGreen(noise_image,ClampToQuantum(GenerateDifferentialNoise(
401 random_info[id],GetPixelGreen(image,p),noise_type,attenuate)),q);
402 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
403 SetPixelBlue(noise_image,ClampToQuantum(GenerateDifferentialNoise(
404 random_info[id],GetPixelBlue(image,p),noise_type,attenuate)),q);
405 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
406 (image->colorspace == CMYKColorspace))
407 SetPixelBlack(noise_image,ClampToQuantum(GenerateDifferentialNoise(
408 random_info[id],GetPixelBlack(image,p),noise_type,attenuate)),q);
409 if ((GetPixelAlphaTraits(image) & CopyPixelTrait) != 0)
410 SetPixelAlpha(noise_image,GetPixelAlpha(image,p),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,const double bias,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.
624 % o exception: return any errors or warnings in this structure.
627 MagickExport Image *CharcoalImage(const Image *image,const double radius,
628 const double sigma,const double bias,ExceptionInfo *exception)
635 assert(image != (Image *) NULL);
636 assert(image->signature == MagickSignature);
637 if (image->debug != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
639 assert(exception != (ExceptionInfo *) NULL);
640 assert(exception->signature == MagickSignature);
641 clone_image=CloneImage(image,0,0,MagickTrue,exception);
642 if (clone_image == (Image *) NULL)
643 return((Image *) NULL);
644 (void) SetImageType(clone_image,GrayscaleType,exception);
645 edge_image=EdgeImage(clone_image,radius,sigma,exception);
646 clone_image=DestroyImage(clone_image);
647 if (edge_image == (Image *) NULL)
648 return((Image *) NULL);
649 charcoal_image=BlurImage(edge_image,radius,sigma,bias,exception);
650 edge_image=DestroyImage(edge_image);
651 if (charcoal_image == (Image *) NULL)
652 return((Image *) NULL);
653 (void) NormalizeImage(charcoal_image,exception);
654 (void) NegateImage(charcoal_image,MagickFalse,exception);
655 (void) SetImageType(charcoal_image,GrayscaleType,exception);
656 return(charcoal_image);
660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 % C o l o r i z e I m a g e %
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 % ColorizeImage() blends the fill color with each pixel in the image.
671 % A percentage blend is specified with opacity. Control the application
672 % of different color components by specifying a different percentage for
673 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
675 % The format of the ColorizeImage method is:
677 % Image *ColorizeImage(const Image *image,const char *blend,
678 % const PixelInfo *colorize,ExceptionInfo *exception)
680 % A description of each parameter follows:
682 % o image: the image.
684 % o blend: A character string indicating the level of blending as a
687 % o colorize: A color value.
689 % o exception: return any errors or warnings in this structure.
692 MagickExport Image *ColorizeImage(const Image *image,const char *blend,
693 const PixelInfo *colorize,ExceptionInfo *exception)
695 #define ColorizeImageTag "Colorize/Image"
723 Allocate colorized image.
725 assert(image != (const Image *) NULL);
726 assert(image->signature == MagickSignature);
727 if (image->debug != MagickFalse)
728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
729 assert(exception != (ExceptionInfo *) NULL);
730 assert(exception->signature == MagickSignature);
731 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
733 if (colorize_image == (Image *) NULL)
734 return((Image *) NULL);
735 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
737 colorize_image=DestroyImage(colorize_image);
738 return((Image *) NULL);
740 if (blend == (const char *) NULL)
741 return(colorize_image);
743 Determine RGB values of the pen color.
745 GetPixelInfo(image,&pixel);
746 flags=ParseGeometry(blend,&geometry_info);
747 pixel.red=geometry_info.rho;
748 pixel.green=geometry_info.rho;
749 pixel.blue=geometry_info.rho;
751 if ((flags & SigmaValue) != 0)
752 pixel.green=geometry_info.sigma;
753 if ((flags & XiValue) != 0)
754 pixel.blue=geometry_info.xi;
755 if ((flags & PsiValue) != 0)
756 pixel.alpha=geometry_info.psi;
757 if (pixel.colorspace == CMYKColorspace)
759 pixel.black=geometry_info.rho;
760 if ((flags & PsiValue) != 0)
761 pixel.black=geometry_info.psi;
762 if ((flags & ChiValue) != 0)
763 pixel.alpha=geometry_info.chi;
766 Colorize DirectClass image.
770 image_view=AcquireCacheView(image);
771 colorize_view=AcquireCacheView(colorize_image);
772 #if defined(MAGICKCORE_OPENMP_SUPPORT)
773 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
775 for (y=0; y < (ssize_t) image->rows; y++)
780 register const Quantum
789 if (status == MagickFalse)
791 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
792 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
794 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
799 for (x=0; x < (ssize_t) image->columns; x++)
804 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
813 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
814 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
815 colorize_traits=GetPixelChannelMapTraits(colorize_image,channel);
816 if ((traits == UndefinedPixelTrait) ||
817 (colorize_traits == UndefinedPixelTrait))
819 if ((colorize_traits & CopyPixelTrait) != 0)
821 SetPixelChannel(colorize_image,channel,p[i],q);
826 case RedPixelChannel:
828 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
829 (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q);
832 case GreenPixelChannel:
834 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
835 (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q);
838 case BluePixelChannel:
840 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
841 (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q);
844 case BlackPixelChannel:
846 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
847 (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q);
850 case AlphaPixelChannel:
852 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
853 (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q);
858 SetPixelChannel(colorize_image,channel,p[i],q);
863 p+=GetPixelChannels(image);
864 q+=GetPixelChannels(colorize_image);
866 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
867 if (sync == MagickFalse)
869 if (image->progress_monitor != (MagickProgressMonitor) NULL)
874 #if defined(MAGICKCORE_OPENMP_SUPPORT)
875 #pragma omp critical (MagickCore_ColorizeImage)
877 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
878 if (proceed == MagickFalse)
882 image_view=DestroyCacheView(image_view);
883 colorize_view=DestroyCacheView(colorize_view);
884 if (status == MagickFalse)
885 colorize_image=DestroyImage(colorize_image);
886 return(colorize_image);
890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 % C o l o r M a t r i x I m a g e %
898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 % ColorMatrixImage() applies color transformation to an image. This method
901 % permits saturation changes, hue rotation, luminance to alpha, and various
902 % other effects. Although variable-sized transformation matrices can be used,
903 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
904 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
905 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
906 % and offsets are normalized (divide Flash offset by 255).
908 % The format of the ColorMatrixImage method is:
910 % Image *ColorMatrixImage(const Image *image,
911 % const KernelInfo *color_matrix,ExceptionInfo *exception)
913 % A description of each parameter follows:
915 % o image: the image.
917 % o color_matrix: the color matrix.
919 % o exception: return any errors or warnings in this structure.
922 MagickExport Image *ColorMatrixImage(const Image *image,
923 const KernelInfo *color_matrix,ExceptionInfo *exception)
925 #define ColorMatrixImageTag "ColorMatrix/Image"
934 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
935 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
936 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
937 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
938 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
939 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
962 assert(image != (Image *) NULL);
963 assert(image->signature == MagickSignature);
964 if (image->debug != MagickFalse)
965 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
966 assert(exception != (ExceptionInfo *) NULL);
967 assert(exception->signature == MagickSignature);
969 for (v=0; v < (ssize_t) color_matrix->height; v++)
970 for (u=0; u < (ssize_t) color_matrix->width; u++)
972 if ((v < 6) && (u < 6))
973 ColorMatrix[v][u]=color_matrix->values[i];
977 Initialize color image.
979 color_image=CloneImage(image,0,0,MagickTrue,exception);
980 if (color_image == (Image *) NULL)
981 return((Image *) NULL);
982 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
984 color_image=DestroyImage(color_image);
985 return((Image *) NULL);
987 if (image->debug != MagickFalse)
990 format[MaxTextExtent],
993 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
994 " ColorMatrix image with color matrix:");
995 message=AcquireString("");
996 for (v=0; v < 6; v++)
999 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
1000 (void) ConcatenateString(&message,format);
1001 for (u=0; u < 6; u++)
1003 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
1005 (void) ConcatenateString(&message,format);
1007 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
1009 message=DestroyString(message);
1016 image_view=AcquireCacheView(image);
1017 color_view=AcquireCacheView(color_image);
1018 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1019 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1021 for (y=0; y < (ssize_t) image->rows; y++)
1026 register const Quantum
1035 if (status == MagickFalse)
1037 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1038 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
1040 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1045 for (x=0; x < (ssize_t) image->columns; x++)
1053 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
1054 for (v=0; v < (ssize_t) height; v++)
1056 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
1057 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
1058 if (image->colorspace == CMYKColorspace)
1059 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
1060 if (image->matte != MagickFalse)
1061 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1062 pixel+=QuantumRange*ColorMatrix[v][5];
1065 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1066 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1067 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
1070 if (image->colorspace == CMYKColorspace)
1071 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
1076 if (image->matte != MagickFalse)
1077 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
1082 p+=GetPixelChannels(image);
1083 q+=GetPixelChannels(color_image);
1085 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1087 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1092 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1093 #pragma omp critical (MagickCore_ColorMatrixImage)
1095 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1097 if (proceed == MagickFalse)
1101 color_view=DestroyCacheView(color_view);
1102 image_view=DestroyCacheView(image_view);
1103 if (status == MagickFalse)
1104 color_image=DestroyImage(color_image);
1105 return(color_image);
1109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1113 + D e s t r o y F x I n f o %
1117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1119 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1121 % The format of the DestroyFxInfo method is:
1123 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1125 % A description of each parameter follows:
1127 % o fx_info: the fx info.
1130 MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
1135 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1136 fx_info->expression=DestroyString(fx_info->expression);
1137 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1138 fx_info->colors=DestroySplayTree(fx_info->colors);
1139 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1140 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1141 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1142 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1143 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1152 + 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 %
1156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1158 % FxEvaluateChannelExpression() evaluates an expression and returns the
1161 % The format of the FxEvaluateExpression method is:
1163 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1164 % const PixelChannel channel,const ssize_t x,const ssize_t y,
1165 % MagickRealType *alpha,Exceptioninfo *exception)
1166 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1167 % MagickRealType *alpha,Exceptioninfo *exception)
1169 % A description of each parameter follows:
1171 % o fx_info: the fx info.
1173 % o channel: the channel.
1175 % o x,y: the pixel position.
1177 % o alpha: the result.
1179 % o exception: return any errors or warnings in this structure.
1183 static inline double MagickMax(const double x,const double y)
1190 static inline double MagickMin(const double x,const double y)
1197 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1198 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
1202 statistic[MaxTextExtent];
1210 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1212 switch (*++p) /* e.g. depth.r */
1214 case 'r': channel=RedPixelChannel; break;
1215 case 'g': channel=GreenPixelChannel; break;
1216 case 'b': channel=BluePixelChannel; break;
1217 case 'c': channel=CyanPixelChannel; break;
1218 case 'm': channel=MagentaPixelChannel; break;
1219 case 'y': channel=YellowPixelChannel; break;
1220 case 'k': channel=BlackPixelChannel; break;
1223 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1224 (double) channel,symbol);
1225 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1226 if (value != (const char *) NULL)
1227 return(QuantumScale*InterpretLocaleValue(value,(char **) NULL));
1228 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1229 if (LocaleNCompare(symbol,"depth",5) == 0)
1234 depth=GetImageDepth(image,exception);
1235 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
1237 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1243 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1244 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
1246 if (LocaleNCompare(symbol,"maxima",6) == 0)
1252 (void) GetImageRange(image,&minima,&maxima,exception);
1253 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
1255 if (LocaleNCompare(symbol,"mean",4) == 0)
1261 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1262 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
1264 if (LocaleNCompare(symbol,"minima",6) == 0)
1270 (void) GetImageRange(image,&minima,&maxima,exception);
1271 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
1273 if (LocaleNCompare(symbol,"skewness",8) == 0)
1279 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
1280 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
1282 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1288 (void) GetImageMean(image,&mean,&standard_deviation,exception);
1289 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
1290 standard_deviation);
1292 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1293 ConstantString(statistic));
1294 return(QuantumScale*InterpretLocaleValue(statistic,(char **) NULL));
1297 static MagickRealType
1298 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
1299 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1301 static inline MagickRealType FxMax(FxInfo *fx_info,const PixelChannel channel,
1302 const ssize_t x,const ssize_t y,const char *expression,
1303 ExceptionInfo *exception)
1309 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1310 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1313 static inline MagickRealType FxMin(FxInfo *fx_info,PixelChannel channel,
1314 const ssize_t x,const ssize_t y,const char *expression,
1315 ExceptionInfo *exception)
1321 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1322 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1325 static inline const char *FxSubexpression(const char *expression,
1326 ExceptionInfo *exception)
1335 subexpression=expression;
1336 while ((*subexpression != '\0') &&
1337 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1339 if (strchr("(",(int) *subexpression) != (char *) NULL)
1342 if (strchr(")",(int) *subexpression) != (char *) NULL)
1346 if (*subexpression == '\0')
1347 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1348 "UnbalancedParenthesis","`%s'",expression);
1349 return(subexpression);
1352 static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
1353 const ssize_t x,const ssize_t y,const char *expression,
1354 ExceptionInfo *exception)
1358 subexpression[MaxTextExtent],
1359 symbol[MaxTextExtent];
1388 i=GetImageIndexInList(fx_info->images);
1392 if (isalpha((int) *(p+1)) == 0)
1394 if (strchr("suv",(int) *p) != (char *) NULL)
1401 i=GetImageIndexInList(fx_info->images);
1404 case 'u': i=0; break;
1405 case 'v': i=1; break;
1412 for (p++; *p != '\0'; )
1426 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1428 i=(ssize_t) (alpha+0.5);
1434 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1441 for (p++; *p != '\0'; )
1455 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1466 for (p++; *p != '\0'; )
1480 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1490 length=GetImageListLength(fx_info->images);
1492 i+=(ssize_t) length;
1494 image=GetImageFromList(fx_info->images,i);
1495 if (image == (Image *) NULL)
1497 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1498 "NoSuchImage","`%s'",expression);
1501 GetPixelInfo(image,&pixel);
1502 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
1503 point.x,point.y,&pixel,exception);
1504 if ((strlen(p) > 2) &&
1505 (LocaleCompare(p,"intensity") != 0) &&
1506 (LocaleCompare(p,"luminance") != 0) &&
1507 (LocaleCompare(p,"hue") != 0) &&
1508 (LocaleCompare(p,"saturation") != 0) &&
1509 (LocaleCompare(p,"lightness") != 0))
1512 name[MaxTextExtent];
1514 (void) CopyMagickString(name,p,MaxTextExtent);
1515 for (q=name+(strlen(name)-1); q > name; q--)
1525 if ((strlen(name) > 2) &&
1526 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1531 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1532 if (color != (PixelInfo *) NULL)
1538 if (QueryMagickColorCompliance(name,AllCompliance,&pixel,fx_info->exception) != MagickFalse)
1540 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1541 ClonePixelInfo(&pixel));
1546 (void) CopyMagickString(symbol,p,MaxTextExtent);
1547 StripString(symbol);
1548 if (*symbol == '\0')
1552 case RedPixelChannel: return(QuantumScale*pixel.red);
1553 case GreenPixelChannel: return(QuantumScale*pixel.green);
1554 case BluePixelChannel: return(QuantumScale*pixel.blue);
1555 case BlackPixelChannel:
1557 if (image->colorspace != CMYKColorspace)
1559 (void) ThrowMagickException(exception,GetMagickModule(),
1560 OptionError,"ColorSeparatedImageRequired","`%s'",
1564 return(QuantumScale*pixel.black);
1566 case AlphaPixelChannel:
1571 if (pixel.matte == MagickFalse)
1573 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1576 case IntensityPixelChannel:
1578 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1583 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1584 "UnableToParseExpression","`%s'",p);
1592 if (LocaleCompare(symbol,"a") == 0)
1593 return((MagickRealType) (QuantumScale*pixel.alpha));
1599 if (LocaleCompare(symbol,"b") == 0)
1600 return(QuantumScale*pixel.blue);
1606 if (LocaleNCompare(symbol,"channel",7) == 0)
1614 flags=ParseGeometry(symbol+7,&channel_info);
1615 if (image->colorspace == CMYKColorspace)
1618 case CyanPixelChannel:
1620 if ((flags & RhoValue) == 0)
1622 return(channel_info.rho);
1624 case MagentaPixelChannel:
1626 if ((flags & SigmaValue) == 0)
1628 return(channel_info.sigma);
1630 case YellowPixelChannel:
1632 if ((flags & XiValue) == 0)
1634 return(channel_info.xi);
1636 case BlackPixelChannel:
1638 if ((flags & PsiValue) == 0)
1640 return(channel_info.psi);
1642 case AlphaPixelChannel:
1644 if ((flags & ChiValue) == 0)
1646 return(channel_info.chi);
1653 case RedPixelChannel:
1655 if ((flags & RhoValue) == 0)
1657 return(channel_info.rho);
1659 case GreenPixelChannel:
1661 if ((flags & SigmaValue) == 0)
1663 return(channel_info.sigma);
1665 case BluePixelChannel:
1667 if ((flags & XiValue) == 0)
1669 return(channel_info.xi);
1671 case BlackPixelChannel:
1673 if ((flags & ChiValue) == 0)
1675 return(channel_info.chi);
1677 case AlphaPixelChannel:
1679 if ((flags & PsiValue) == 0)
1681 return(channel_info.psi);
1688 if (LocaleCompare(symbol,"c") == 0)
1689 return(QuantumScale*pixel.red);
1695 if (LocaleNCompare(symbol,"depth",5) == 0)
1696 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1702 if (LocaleCompare(symbol,"g") == 0)
1703 return(QuantumScale*pixel.green);
1709 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1710 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1711 if (LocaleCompare(symbol,"k") == 0)
1713 if (image->colorspace != CMYKColorspace)
1715 (void) ThrowMagickException(exception,GetMagickModule(),
1716 OptionError,"ColorSeparatedImageRequired","`%s'",
1720 return(QuantumScale*pixel.black);
1727 if (LocaleCompare(symbol,"h") == 0)
1728 return((MagickRealType) image->rows);
1729 if (LocaleCompare(symbol,"hue") == 0)
1736 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1745 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1746 (LocaleCompare(symbol,"image.minima") == 0) ||
1747 (LocaleCompare(symbol,"image.maxima") == 0) ||
1748 (LocaleCompare(symbol,"image.mean") == 0) ||
1749 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1750 (LocaleCompare(symbol,"image.skewness") == 0) ||
1751 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1752 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1753 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1754 return(image->x_resolution);
1755 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1756 return(image->y_resolution);
1757 if (LocaleCompare(symbol,"intensity") == 0)
1758 return(QuantumScale*GetPixelInfoIntensity(&pixel));
1759 if (LocaleCompare(symbol,"i") == 0)
1760 return((MagickRealType) x);
1766 if (LocaleCompare(symbol,"j") == 0)
1767 return((MagickRealType) y);
1773 if (LocaleCompare(symbol,"lightness") == 0)
1780 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1784 if (LocaleCompare(symbol,"luminance") == 0)
1789 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1790 return(QuantumScale*luminence);
1797 if (LocaleNCompare(symbol,"maxima",6) == 0)
1798 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1799 if (LocaleNCompare(symbol,"mean",4) == 0)
1800 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1801 if (LocaleNCompare(symbol,"minima",6) == 0)
1802 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1803 if (LocaleCompare(symbol,"m") == 0)
1804 return(QuantumScale*pixel.blue);
1810 if (LocaleCompare(symbol,"n") == 0)
1811 return((MagickRealType) GetImageListLength(fx_info->images));
1817 if (LocaleCompare(symbol,"o") == 0)
1818 return(QuantumScale*pixel.alpha);
1824 if (LocaleCompare(symbol,"page.height") == 0)
1825 return((MagickRealType) image->page.height);
1826 if (LocaleCompare(symbol,"page.width") == 0)
1827 return((MagickRealType) image->page.width);
1828 if (LocaleCompare(symbol,"page.x") == 0)
1829 return((MagickRealType) image->page.x);
1830 if (LocaleCompare(symbol,"page.y") == 0)
1831 return((MagickRealType) image->page.y);
1837 if (LocaleCompare(symbol,"resolution.x") == 0)
1838 return(image->x_resolution);
1839 if (LocaleCompare(symbol,"resolution.y") == 0)
1840 return(image->y_resolution);
1841 if (LocaleCompare(symbol,"r") == 0)
1842 return(QuantumScale*pixel.red);
1848 if (LocaleCompare(symbol,"saturation") == 0)
1855 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1859 if (LocaleNCompare(symbol,"skewness",8) == 0)
1860 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1861 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1862 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1868 if (LocaleCompare(symbol,"t") == 0)
1869 return((MagickRealType) GetImageIndexInList(fx_info->images));
1875 if (LocaleCompare(symbol,"w") == 0)
1876 return((MagickRealType) image->columns);
1882 if (LocaleCompare(symbol,"y") == 0)
1883 return(QuantumScale*pixel.green);
1889 if (LocaleCompare(symbol,"z") == 0)
1894 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
1902 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1903 if (value != (const char *) NULL)
1904 return((MagickRealType) InterpretLocaleValue(value,(char **) NULL));
1905 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1906 "UnableToParseExpression","`%s'",symbol);
1910 static const char *FxOperatorPrecedence(const char *expression,
1911 ExceptionInfo *exception)
1915 UndefinedPrecedence,
1917 BitwiseComplementPrecedence,
1919 ExponentialNotationPrecedence,
1923 RelationalPrecedence,
1924 EquivalencyPrecedence,
1925 BitwiseAndPrecedence,
1926 BitwiseOrPrecedence,
1927 LogicalAndPrecedence,
1928 LogicalOrPrecedence,
1930 AssignmentPrecedence,
1950 subexpression=(const char *) NULL;
1951 target=NullPrecedence;
1952 while (*expression != '\0')
1954 precedence=UndefinedPrecedence;
1955 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1960 switch (*expression)
1965 #if defined(MAGICKCORE_HAVE_ACOSH)
1966 if (LocaleNCompare(expression,"acosh",5) == 0)
1972 #if defined(MAGICKCORE_HAVE_ASINH)
1973 if (LocaleNCompare(expression,"asinh",5) == 0)
1979 #if defined(MAGICKCORE_HAVE_ATANH)
1980 if (LocaleNCompare(expression,"atanh",5) == 0)
1991 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1992 (LocaleNCompare(expression,"j1",2) == 0))
2001 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
2008 if ((c == (int) '{') || (c == (int) '['))
2011 if ((c == (int) '}') || (c == (int) ']'))
2014 switch ((unsigned char) *expression)
2019 precedence=BitwiseComplementPrecedence;
2025 precedence=ExponentPrecedence;
2030 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
2031 (strchr(")",c) != (char *) NULL))) &&
2032 (((islower((int) ((char) *expression)) != 0) ||
2033 (strchr("(",(int) *expression) != (char *) NULL)) ||
2034 ((isdigit((int) ((char) c)) == 0) &&
2035 (isdigit((int) ((char) *expression)) != 0))) &&
2036 (strchr("xy",(int) *expression) == (char *) NULL))
2037 precedence=MultiplyPrecedence;
2044 precedence=MultiplyPrecedence;
2050 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2052 precedence=AdditionPrecedence;
2055 case LeftShiftOperator:
2056 case RightShiftOperator:
2058 precedence=ShiftPrecedence;
2062 case LessThanEqualOperator:
2063 case GreaterThanEqualOperator:
2066 precedence=RelationalPrecedence;
2070 case NotEqualOperator:
2072 precedence=EquivalencyPrecedence;
2077 precedence=BitwiseAndPrecedence;
2082 precedence=BitwiseOrPrecedence;
2085 case LogicalAndOperator:
2087 precedence=LogicalAndPrecedence;
2090 case LogicalOrOperator:
2092 precedence=LogicalOrPrecedence;
2095 case ExponentialNotation:
2097 precedence=ExponentialNotationPrecedence;
2103 precedence=TernaryPrecedence;
2108 precedence=AssignmentPrecedence;
2113 precedence=CommaPrecedence;
2118 precedence=SeparatorPrecedence;
2122 if ((precedence == BitwiseComplementPrecedence) ||
2123 (precedence == TernaryPrecedence) ||
2124 (precedence == AssignmentPrecedence))
2126 if (precedence > target)
2129 Right-to-left associativity.
2132 subexpression=expression;
2136 if (precedence >= target)
2139 Left-to-right associativity.
2142 subexpression=expression;
2144 if (strchr("(",(int) *expression) != (char *) NULL)
2145 expression=FxSubexpression(expression,exception);
2146 c=(int) (*expression++);
2148 return(subexpression);
2151 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2152 const PixelChannel channel,const ssize_t x,const ssize_t y,
2153 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2157 subexpression[MaxTextExtent];
2167 if (exception->severity != UndefinedException)
2169 while (isspace((int) *expression) != 0)
2171 if (*expression == '\0')
2173 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2174 "MissingExpression","`%s'",expression);
2177 *subexpression='\0';
2178 p=FxOperatorPrecedence(expression,exception);
2179 if (p != (const char *) NULL)
2181 (void) CopyMagickString(subexpression,expression,(size_t)
2183 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2185 switch ((unsigned char) *p)
2189 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2190 *beta=(MagickRealType) (~(size_t) *beta);
2195 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2196 return(*beta == 0.0 ? 1.0 : 0.0);
2200 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2201 channel,x,y,++p,beta,exception));
2205 case ExponentialNotation:
2207 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2208 return(alpha*(*beta));
2212 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2215 if (exception->severity == UndefinedException)
2216 (void) ThrowMagickException(exception,GetMagickModule(),
2217 OptionError,"DivideByZero","`%s'",expression);
2220 return(alpha/(*beta));
2224 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2225 *beta=fabs(floor(((double) *beta)+0.5));
2228 (void) ThrowMagickException(exception,GetMagickModule(),
2229 OptionError,"DivideByZero","`%s'",expression);
2232 return(fmod((double) alpha,(double) *beta));
2236 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2237 return(alpha+(*beta));
2241 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2242 return(alpha-(*beta));
2244 case LeftShiftOperator:
2246 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2247 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2251 case RightShiftOperator:
2253 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2254 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2260 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2261 return(alpha < *beta ? 1.0 : 0.0);
2263 case LessThanEqualOperator:
2265 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2266 return(alpha <= *beta ? 1.0 : 0.0);
2270 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2271 return(alpha > *beta ? 1.0 : 0.0);
2273 case GreaterThanEqualOperator:
2275 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2276 return(alpha >= *beta ? 1.0 : 0.0);
2280 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2281 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2283 case NotEqualOperator:
2285 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2286 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2290 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2291 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2297 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2298 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2302 case LogicalAndOperator:
2304 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2305 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2308 case LogicalOrOperator:
2310 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2311 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2319 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2321 p=StringToken(":",&q);
2322 if (q == (char *) NULL)
2324 (void) ThrowMagickException(exception,GetMagickModule(),
2325 OptionError,"UnableToParseExpression","`%s'",subexpression);
2328 if (fabs((double) alpha) > MagickEpsilon)
2329 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2331 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2337 numeric[MaxTextExtent];
2340 while (isalpha((int) ((unsigned char) *q)) != 0)
2344 (void) ThrowMagickException(exception,GetMagickModule(),
2345 OptionError,"UnableToParseExpression","`%s'",subexpression);
2348 ClearMagickException(exception);
2349 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2350 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
2352 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2353 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2354 subexpression),ConstantString(numeric));
2359 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2364 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2369 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2375 if (strchr("(",(int) *expression) != (char *) NULL)
2377 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2378 subexpression[strlen(subexpression)-1]='\0';
2379 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2383 switch (*expression)
2387 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2393 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2399 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2401 return((MagickRealType) (~(size_t) (gamma+0.5)));
2406 if (LocaleNCompare(expression,"abs",3) == 0)
2408 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2410 return((MagickRealType) fabs((double) alpha));
2412 #if defined(MAGICKCORE_HAVE_ACOSH)
2413 if (LocaleNCompare(expression,"acosh",5) == 0)
2415 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2417 return((MagickRealType) acosh((double) alpha));
2420 if (LocaleNCompare(expression,"acos",4) == 0)
2422 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2424 return((MagickRealType) acos((double) alpha));
2426 #if defined(MAGICKCORE_HAVE_J1)
2427 if (LocaleNCompare(expression,"airy",4) == 0)
2429 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2433 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2434 return(gamma*gamma);
2437 #if defined(MAGICKCORE_HAVE_ASINH)
2438 if (LocaleNCompare(expression,"asinh",5) == 0)
2440 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2442 return((MagickRealType) asinh((double) alpha));
2445 if (LocaleNCompare(expression,"asin",4) == 0)
2447 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2449 return((MagickRealType) asin((double) alpha));
2451 if (LocaleNCompare(expression,"alt",3) == 0)
2453 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2455 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2457 if (LocaleNCompare(expression,"atan2",5) == 0)
2459 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2461 return((MagickRealType) atan2((double) alpha,(double) *beta));
2463 #if defined(MAGICKCORE_HAVE_ATANH)
2464 if (LocaleNCompare(expression,"atanh",5) == 0)
2466 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2468 return((MagickRealType) atanh((double) alpha));
2471 if (LocaleNCompare(expression,"atan",4) == 0)
2473 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2475 return((MagickRealType) atan((double) alpha));
2477 if (LocaleCompare(expression,"a") == 0)
2478 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2484 if (LocaleCompare(expression,"b") == 0)
2485 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2491 if (LocaleNCompare(expression,"ceil",4) == 0)
2493 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2495 return((MagickRealType) ceil((double) alpha));
2497 if (LocaleNCompare(expression,"cosh",4) == 0)
2499 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2501 return((MagickRealType) cosh((double) alpha));
2503 if (LocaleNCompare(expression,"cos",3) == 0)
2505 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2507 return((MagickRealType) cos((double) alpha));
2509 if (LocaleCompare(expression,"c") == 0)
2510 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2516 if (LocaleNCompare(expression,"debug",5) == 0)
2521 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2523 if (fx_info->images->colorspace == CMYKColorspace)
2526 case CyanPixelChannel: type="cyan"; break;
2527 case MagentaPixelChannel: type="magenta"; break;
2528 case YellowPixelChannel: type="yellow"; break;
2529 case AlphaPixelChannel: type="opacity"; break;
2530 case BlackPixelChannel: type="black"; break;
2531 default: type="unknown"; break;
2536 case RedPixelChannel: type="red"; break;
2537 case GreenPixelChannel: type="green"; break;
2538 case BluePixelChannel: type="blue"; break;
2539 case AlphaPixelChannel: type="opacity"; break;
2540 default: type="unknown"; break;
2542 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2543 if (strlen(subexpression) > 1)
2544 subexpression[strlen(subexpression)-1]='\0';
2545 if (fx_info->file != (FILE *) NULL)
2546 (void) FormatLocaleFile(fx_info->file,
2547 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2548 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2557 if (LocaleCompare(expression,"epsilon") == 0)
2558 return((MagickRealType) MagickEpsilon);
2559 if (LocaleNCompare(expression,"exp",3) == 0)
2561 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2563 return((MagickRealType) exp((double) alpha));
2565 if (LocaleCompare(expression,"e") == 0)
2566 return((MagickRealType) 2.7182818284590452354);
2572 if (LocaleNCompare(expression,"floor",5) == 0)
2574 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2576 return((MagickRealType) floor((double) alpha));
2583 if (LocaleCompare(expression,"g") == 0)
2584 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2590 if (LocaleCompare(expression,"h") == 0)
2591 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2592 if (LocaleCompare(expression,"hue") == 0)
2593 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2594 if (LocaleNCompare(expression,"hypot",5) == 0)
2596 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2598 return((MagickRealType) hypot((double) alpha,(double) *beta));
2605 if (LocaleCompare(expression,"k") == 0)
2606 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2612 if (LocaleCompare(expression,"intensity") == 0)
2613 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2614 if (LocaleNCompare(expression,"int",3) == 0)
2616 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2618 return((MagickRealType) floor(alpha));
2620 if (LocaleCompare(expression,"i") == 0)
2621 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2627 if (LocaleCompare(expression,"j") == 0)
2628 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2629 #if defined(MAGICKCORE_HAVE_J0)
2630 if (LocaleNCompare(expression,"j0",2) == 0)
2632 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2634 return((MagickRealType) j0((double) alpha));
2637 #if defined(MAGICKCORE_HAVE_J1)
2638 if (LocaleNCompare(expression,"j1",2) == 0)
2640 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2642 return((MagickRealType) j1((double) alpha));
2645 #if defined(MAGICKCORE_HAVE_J1)
2646 if (LocaleNCompare(expression,"jinc",4) == 0)
2648 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2652 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2662 if (LocaleNCompare(expression,"ln",2) == 0)
2664 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2666 return((MagickRealType) log((double) alpha));
2668 if (LocaleNCompare(expression,"logtwo",6) == 0)
2670 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2672 return((MagickRealType) log10((double) alpha))/log10(2.0);
2674 if (LocaleNCompare(expression,"log",3) == 0)
2676 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2678 return((MagickRealType) log10((double) alpha));
2680 if (LocaleCompare(expression,"lightness") == 0)
2681 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2687 if (LocaleCompare(expression,"MaxRGB") == 0)
2688 return((MagickRealType) QuantumRange);
2689 if (LocaleNCompare(expression,"maxima",6) == 0)
2691 if (LocaleNCompare(expression,"max",3) == 0)
2692 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2693 if (LocaleNCompare(expression,"minima",6) == 0)
2695 if (LocaleNCompare(expression,"min",3) == 0)
2696 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2697 if (LocaleNCompare(expression,"mod",3) == 0)
2699 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2701 return((MagickRealType) fmod((double) alpha,(double) *beta));
2703 if (LocaleCompare(expression,"m") == 0)
2704 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2710 if (LocaleCompare(expression,"n") == 0)
2711 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2717 if (LocaleCompare(expression,"Opaque") == 0)
2719 if (LocaleCompare(expression,"o") == 0)
2720 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2726 if (LocaleCompare(expression,"pi") == 0)
2727 return((MagickRealType) MagickPI);
2728 if (LocaleNCompare(expression,"pow",3) == 0)
2730 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2732 return((MagickRealType) pow((double) alpha,(double) *beta));
2734 if (LocaleCompare(expression,"p") == 0)
2735 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2741 if (LocaleCompare(expression,"QuantumRange") == 0)
2742 return((MagickRealType) QuantumRange);
2743 if (LocaleCompare(expression,"QuantumScale") == 0)
2744 return((MagickRealType) QuantumScale);
2750 if (LocaleNCompare(expression,"rand",4) == 0)
2751 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2752 if (LocaleNCompare(expression,"round",5) == 0)
2754 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2756 return((MagickRealType) floor((double) alpha+0.5));
2758 if (LocaleCompare(expression,"r") == 0)
2759 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2765 if (LocaleCompare(expression,"saturation") == 0)
2766 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2767 if (LocaleNCompare(expression,"sign",4) == 0)
2769 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2771 return(alpha < 0.0 ? -1.0 : 1.0);
2773 if (LocaleNCompare(expression,"sinc",4) == 0)
2775 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2779 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2783 if (LocaleNCompare(expression,"sinh",4) == 0)
2785 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2787 return((MagickRealType) sinh((double) alpha));
2789 if (LocaleNCompare(expression,"sin",3) == 0)
2791 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2793 return((MagickRealType) sin((double) alpha));
2795 if (LocaleNCompare(expression,"sqrt",4) == 0)
2797 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2799 return((MagickRealType) sqrt((double) alpha));
2801 if (LocaleCompare(expression,"s") == 0)
2802 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2808 if (LocaleNCompare(expression,"tanh",4) == 0)
2810 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2812 return((MagickRealType) tanh((double) alpha));
2814 if (LocaleNCompare(expression,"tan",3) == 0)
2816 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2818 return((MagickRealType) tan((double) alpha));
2820 if (LocaleCompare(expression,"Transparent") == 0)
2822 if (LocaleNCompare(expression,"trunc",5) == 0)
2824 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2827 return((MagickRealType) floor((double) alpha));
2828 return((MagickRealType) ceil((double) alpha));
2830 if (LocaleCompare(expression,"t") == 0)
2831 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2837 if (LocaleCompare(expression,"u") == 0)
2838 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2844 if (LocaleCompare(expression,"v") == 0)
2845 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2851 if (LocaleCompare(expression,"w") == 0)
2852 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2858 if (LocaleCompare(expression,"y") == 0)
2859 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2865 if (LocaleCompare(expression,"z") == 0)
2866 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2872 q=(char *) expression;
2873 alpha=InterpretLocaleValue(expression,&q);
2874 if (q == expression)
2875 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2879 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2880 MagickRealType *alpha,ExceptionInfo *exception)
2885 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2890 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2891 MagickRealType *alpha,ExceptionInfo *exception)
2900 fx_info->file=(FILE *) NULL;
2901 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2907 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2908 const PixelChannel channel,const ssize_t x,const ssize_t y,
2909 MagickRealType *alpha,ExceptionInfo *exception)
2915 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2917 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2931 % FxImage() applies a mathematical expression to the specified image.
2933 % The format of the FxImage method is:
2935 % Image *FxImage(const Image *image,const char *expression,
2936 % ExceptionInfo *exception)
2938 % A description of each parameter follows:
2940 % o image: the image.
2942 % o expression: A mathematical expression.
2944 % o exception: return any errors or warnings in this structure.
2948 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2953 assert(fx_info != (FxInfo **) NULL);
2954 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2955 if (fx_info[i] != (FxInfo *) NULL)
2956 fx_info[i]=DestroyFxInfo(fx_info[i]);
2957 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2961 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2962 ExceptionInfo *exception)
2979 number_threads=GetOpenMPMaximumThreads();
2980 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2981 if (fx_info == (FxInfo **) NULL)
2982 return((FxInfo **) NULL);
2983 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2984 if (*expression != '@')
2985 fx_expression=ConstantString(expression);
2987 fx_expression=FileToString(expression+1,~0,exception);
2988 for (i=0; i < (ssize_t) number_threads; i++)
2990 fx_info[i]=AcquireFxInfo(image,fx_expression);
2991 if (fx_info[i] == (FxInfo *) NULL)
2992 return(DestroyFxThreadSet(fx_info));
2993 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2995 fx_expression=DestroyString(fx_expression);
2999 MagickExport Image *FxImage(const Image *image,const char *expression,
3000 ExceptionInfo *exception)
3002 #define FxImageTag "Fx/Image"
3026 assert(image != (Image *) NULL);
3027 assert(image->signature == MagickSignature);
3028 if (image->debug != MagickFalse)
3029 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3030 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3031 if (fx_image == (Image *) NULL)
3032 return((Image *) NULL);
3033 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3035 fx_image=DestroyImage(fx_image);
3036 return((Image *) NULL);
3038 fx_info=AcquireFxThreadSet(image,expression,exception);
3039 if (fx_info == (FxInfo **) NULL)
3041 fx_image=DestroyImage(fx_image);
3042 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3044 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3045 if (status == MagickFalse)
3047 fx_image=DestroyImage(fx_image);
3048 fx_info=DestroyFxThreadSet(fx_info);
3049 return((Image *) NULL);
3056 image_view=AcquireCacheView(image);
3057 fx_view=AcquireCacheView(fx_image);
3058 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3059 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3061 for (y=0; y < (ssize_t) fx_image->rows; y++)
3064 id = GetOpenMPThreadId();
3066 register const Quantum
3075 if (status == MagickFalse)
3077 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3078 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3079 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3084 for (x=0; x < (ssize_t) fx_image->columns; x++)
3089 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3101 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3102 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3103 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
3104 if ((traits == UndefinedPixelTrait) ||
3105 (fx_traits == UndefinedPixelTrait))
3107 if ((fx_traits & CopyPixelTrait) != 0)
3109 SetPixelChannel(fx_image,channel,p[i],q);
3113 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3115 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3117 p+=GetPixelChannels(image);
3118 q+=GetPixelChannels(fx_image);
3120 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3122 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3127 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3128 #pragma omp critical (MagickCore_FxImage)
3130 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3131 if (proceed == MagickFalse)
3135 fx_view=DestroyCacheView(fx_view);
3136 image_view=DestroyCacheView(image_view);
3137 fx_info=DestroyFxThreadSet(fx_info);
3138 if (status == MagickFalse)
3139 fx_image=DestroyImage(fx_image);
3144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3148 % I m p l o d e I m a g e %
3152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3154 % ImplodeImage() creates a new image that is a copy of an existing
3155 % one with the image pixels "implode" by the specified percentage. It
3156 % allocates the memory necessary for the new Image structure and returns a
3157 % pointer to the new image.
3159 % The format of the ImplodeImage method is:
3161 % Image *ImplodeImage(const Image *image,const double amount,
3162 % const PixelInterpolateMethod method,ExceptionInfo *exception)
3164 % A description of each parameter follows:
3166 % o implode_image: Method ImplodeImage returns a pointer to the image
3167 % after it is implode. A null image is returned if there is a memory
3170 % o image: the image.
3172 % o amount: Define the extent of the implosion.
3174 % o method: the pixel interpolation method.
3176 % o exception: return any errors or warnings in this structure.
3179 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3180 const PixelInterpolateMethod method,ExceptionInfo *exception)
3182 #define ImplodeImageTag "Implode/Image"
3208 Initialize implode image attributes.
3210 assert(image != (Image *) NULL);
3211 assert(image->signature == MagickSignature);
3212 if (image->debug != MagickFalse)
3213 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3214 assert(exception != (ExceptionInfo *) NULL);
3215 assert(exception->signature == MagickSignature);
3216 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3218 if (implode_image == (Image *) NULL)
3219 return((Image *) NULL);
3220 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
3222 implode_image=DestroyImage(implode_image);
3223 return((Image *) NULL);
3225 if (implode_image->background_color.alpha != OpaqueAlpha)
3226 implode_image->matte=MagickTrue;
3228 Compute scaling factor.
3232 center.x=0.5*image->columns;
3233 center.y=0.5*image->rows;
3235 if (image->columns > image->rows)
3236 scale.y=(double) image->columns/(double) image->rows;
3238 if (image->columns < image->rows)
3240 scale.x=(double) image->rows/(double) image->columns;
3248 image_view=AcquireCacheView(image);
3249 implode_view=AcquireCacheView(implode_image);
3250 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3251 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3253 for (y=0; y < (ssize_t) image->rows; y++)
3261 register const Quantum
3270 if (status == MagickFalse)
3272 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3273 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3275 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3280 delta.y=scale.y*(double) (y-center.y);
3281 for (x=0; x < (ssize_t) image->columns; x++)
3287 Determine if the pixel is within an ellipse.
3289 delta.x=scale.x*(double) (x-center.x);
3290 distance=delta.x*delta.x+delta.y*delta.y;
3291 if (distance >= (radius*radius))
3293 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3306 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3307 radius/2)),-amount);
3308 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3309 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3310 scale.y+center.y),q,exception);
3312 p+=GetPixelChannels(image);
3313 q+=GetPixelChannels(implode_image);
3315 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3317 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3322 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3323 #pragma omp critical (MagickCore_ImplodeImage)
3325 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3326 if (proceed == MagickFalse)
3330 implode_view=DestroyCacheView(implode_view);
3331 image_view=DestroyCacheView(image_view);
3332 if (status == MagickFalse)
3333 implode_image=DestroyImage(implode_image);
3334 return(implode_image);
3338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3342 % M o r p h I m a g e s %
3346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3348 % The MorphImages() method requires a minimum of two images. The first
3349 % image is transformed into the second by a number of intervening images
3350 % as specified by frames.
3352 % The format of the MorphImage method is:
3354 % Image *MorphImages(const Image *image,const size_t number_frames,
3355 % ExceptionInfo *exception)
3357 % A description of each parameter follows:
3359 % o image: the image.
3361 % o number_frames: Define the number of in-between image to generate.
3362 % The more in-between frames, the smoother the morph.
3364 % o exception: return any errors or warnings in this structure.
3367 MagickExport Image *MorphImages(const Image *image,
3368 const size_t number_frames,ExceptionInfo *exception)
3370 #define MorphImageTag "Morph/Image"
3386 register const Image
3396 Clone first frame in sequence.
3398 assert(image != (Image *) NULL);
3399 assert(image->signature == MagickSignature);
3400 if (image->debug != MagickFalse)
3401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3402 assert(exception != (ExceptionInfo *) NULL);
3403 assert(exception->signature == MagickSignature);
3404 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3405 if (morph_images == (Image *) NULL)
3406 return((Image *) NULL);
3407 if (GetNextImageInList(image) == (Image *) NULL)
3412 for (i=1; i < (ssize_t) number_frames; i++)
3414 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3415 if (morph_image == (Image *) NULL)
3417 morph_images=DestroyImageList(morph_images);
3418 return((Image *) NULL);
3420 AppendImageToList(&morph_images,morph_image);
3421 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3426 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3428 if (proceed == MagickFalse)
3432 return(GetFirstImageInList(morph_images));
3435 Morph image sequence.
3440 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3442 for (i=0; i < (ssize_t) number_frames; i++)
3448 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3450 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3451 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3452 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3453 next->filter,next->blur,exception);
3454 if (morph_image == (Image *) NULL)
3456 morph_images=DestroyImageList(morph_images);
3457 return((Image *) NULL);
3459 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
3461 morph_image=DestroyImage(morph_image);
3462 return((Image *) NULL);
3464 AppendImageToList(&morph_images,morph_image);
3465 morph_images=GetLastImageInList(morph_images);
3466 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3467 morph_images->rows,GetNextImageInList(next)->filter,
3468 GetNextImageInList(next)->blur,exception);
3469 if (morph_image == (Image *) NULL)
3471 morph_images=DestroyImageList(morph_images);
3472 return((Image *) NULL);
3474 image_view=AcquireCacheView(morph_image);
3475 morph_view=AcquireCacheView(morph_images);
3476 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3477 #pragma omp parallel for schedule(dynamic,4) shared(status)
3479 for (y=0; y < (ssize_t) morph_images->rows; y++)
3484 register const Quantum
3493 if (status == MagickFalse)
3495 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3497 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3499 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3504 for (x=0; x < (ssize_t) morph_images->columns; x++)
3506 SetPixelRed(morph_images,ClampToQuantum(alpha*
3507 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3508 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3509 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3510 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3511 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3512 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3513 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3514 if ((morph_image->colorspace == CMYKColorspace) &&
3515 (morph_images->colorspace == CMYKColorspace))
3516 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3517 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3519 p+=GetPixelChannels(morph_image);
3520 q+=GetPixelChannels(morph_images);
3522 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3523 if (sync == MagickFalse)
3526 morph_view=DestroyCacheView(morph_view);
3527 image_view=DestroyCacheView(image_view);
3528 morph_image=DestroyImage(morph_image);
3530 if (i < (ssize_t) number_frames)
3533 Clone last frame in sequence.
3535 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3536 if (morph_image == (Image *) NULL)
3538 morph_images=DestroyImageList(morph_images);
3539 return((Image *) NULL);
3541 AppendImageToList(&morph_images,morph_image);
3542 morph_images=GetLastImageInList(morph_images);
3543 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3548 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3549 #pragma omp critical (MagickCore_MorphImages)
3551 proceed=SetImageProgress(image,MorphImageTag,scene,
3552 GetImageListLength(image));
3553 if (proceed == MagickFalse)
3558 if (GetNextImageInList(next) != (Image *) NULL)
3560 morph_images=DestroyImageList(morph_images);
3561 return((Image *) NULL);
3563 return(GetFirstImageInList(morph_images));
3567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3571 % P l a s m a I m a g e %
3575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3577 % PlasmaImage() initializes an image with plasma fractal values. The image
3578 % must be initialized with a base color and the random number generator
3579 % seeded before this method is called.
3581 % The format of the PlasmaImage method is:
3583 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3584 % size_t attenuate,size_t depth,ExceptionInfo *exception)
3586 % A description of each parameter follows:
3588 % o image: the image.
3590 % o segment: Define the region to apply plasma fractals values.
3592 % o attenuate: Define the plasma attenuation factor.
3594 % o depth: Limit the plasma recursion depth.
3596 % o exception: return any errors or warnings in this structure.
3600 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3601 const MagickRealType pixel,const MagickRealType noise)
3606 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3611 static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3612 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3613 const SegmentInfo *segment,size_t attenuate,size_t depth,
3614 ExceptionInfo *exception)
3625 register const Quantum
3641 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3649 Divide the area into quadrants and recurse.
3653 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3654 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3655 local_info=(*segment);
3656 local_info.x2=(double) x_mid;
3657 local_info.y2=(double) y_mid;
3658 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3659 &local_info,attenuate,depth,exception);
3660 local_info=(*segment);
3661 local_info.y1=(double) y_mid;
3662 local_info.x2=(double) x_mid;
3663 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3664 &local_info,attenuate,depth,exception);
3665 local_info=(*segment);
3666 local_info.x1=(double) x_mid;
3667 local_info.y2=(double) y_mid;
3668 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3669 &local_info,attenuate,depth,exception);
3670 local_info=(*segment);
3671 local_info.x1=(double) x_mid;
3672 local_info.y1=(double) y_mid;
3673 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3674 &local_info,attenuate,depth,exception));
3676 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3677 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3678 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3679 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3680 return(MagickFalse);
3682 Average pixels and apply plasma.
3684 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3685 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3690 x=(ssize_t) ceil(segment->x1-0.5);
3691 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3693 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3695 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3696 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3697 (q == (Quantum *) NULL))
3699 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3701 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3702 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3703 if (traits == UndefinedPixelTrait)
3705 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3707 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3708 if (segment->x1 != segment->x2)
3713 x=(ssize_t) ceil(segment->x2-0.5);
3714 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3716 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3718 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3719 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3720 (q == (Quantum *) NULL))
3722 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3724 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3725 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3726 if (traits == UndefinedPixelTrait)
3728 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3730 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3733 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3735 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3740 y=(ssize_t) ceil(segment->y2-0.5);
3741 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3743 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3745 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3746 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3747 (q == (Quantum *) NULL))
3749 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3751 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3752 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3753 if (traits == UndefinedPixelTrait)
3755 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3757 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3759 if (segment->y1 != segment->y2)
3764 y=(ssize_t) ceil(segment->y1-0.5);
3765 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3767 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3769 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3770 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3771 (q == (Quantum *) NULL))
3773 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3775 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3776 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3777 if (traits == UndefinedPixelTrait)
3779 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3781 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3784 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3789 x=(ssize_t) ceil(segment->x1-0.5);
3790 y=(ssize_t) ceil(segment->y1-0.5);
3791 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
3792 x=(ssize_t) ceil(segment->x2-0.5);
3793 y=(ssize_t) ceil(segment->y2-0.5);
3794 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
3795 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3796 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3797 (q == (Quantum *) NULL))
3799 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3801 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3802 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3803 if (traits == UndefinedPixelTrait)
3805 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3807 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3809 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3811 return(MagickFalse);
3814 MagickExport MagickBooleanType PlasmaImage(Image *image,
3815 const SegmentInfo *segment,size_t attenuate,size_t depth,
3816 ExceptionInfo *exception)
3829 if (image->debug != MagickFalse)
3830 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3831 assert(image != (Image *) NULL);
3832 assert(image->signature == MagickSignature);
3833 if (image->debug != MagickFalse)
3834 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3835 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3836 return(MagickFalse);
3837 image_view=AcquireCacheView(image);
3838 u_view=AcquireCacheView(image);
3839 v_view=AcquireCacheView(image);
3840 random_info=AcquireRandomInfo();
3841 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3842 attenuate,depth,exception);
3843 random_info=DestroyRandomInfo(random_info);
3844 v_view=DestroyCacheView(v_view);
3845 u_view=DestroyCacheView(u_view);
3846 image_view=DestroyCacheView(image_view);
3851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3855 % P o l a r o i d I m a g e %
3859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3861 % PolaroidImage() simulates a Polaroid picture.
3863 % The format of the AnnotateImage method is:
3865 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3866 % const double angle,const PixelInterpolateMethod method,
3867 % ExceptionInfo exception)
3869 % A description of each parameter follows:
3871 % o image: the image.
3873 % o draw_info: the draw info.
3875 % o angle: Apply the effect along this angle.
3877 % o method: the pixel interpolation method.
3879 % o exception: return any errors or warnings in this structure.
3882 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3883 const double angle,const PixelInterpolateMethod method,
3884 ExceptionInfo *exception)
3905 Simulate a Polaroid picture.
3907 assert(image != (Image *) NULL);
3908 assert(image->signature == MagickSignature);
3909 if (image->debug != MagickFalse)
3910 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3911 assert(exception != (ExceptionInfo *) NULL);
3912 assert(exception->signature == MagickSignature);
3913 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3914 image->rows)/25.0,10.0);
3915 height=image->rows+2*quantum;
3916 caption_image=(Image *) NULL;
3917 value=GetImageProperty(image,"Caption");
3918 if (value != (const char *) NULL)
3922 geometry[MaxTextExtent];
3937 Generate caption image.
3939 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3940 if (caption_image == (Image *) NULL)
3941 return((Image *) NULL);
3942 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3943 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3945 (void) CloneString(&annotate_info->text,caption);
3946 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3947 &caption,exception);
3948 status=SetImageExtent(caption_image,image->columns,(size_t)
3949 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
3950 if (status == MagickFalse)
3951 caption_image=DestroyImage(caption_image);
3954 caption_image->background_color=image->border_color;
3955 (void) SetImageBackgroundColor(caption_image);
3956 (void) CloneString(&annotate_info->text,caption);
3957 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
3959 if (annotate_info->gravity == UndefinedGravity)
3960 (void) CloneString(&annotate_info->geometry,AcquireString(
3962 (void) AnnotateImage(caption_image,annotate_info,exception);
3963 height+=caption_image->rows;
3965 annotate_info=DestroyDrawInfo(annotate_info);
3966 caption=DestroyString(caption);
3968 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3970 if (picture_image == (Image *) NULL)
3972 if (caption_image != (Image *) NULL)
3973 caption_image=DestroyImage(caption_image);
3974 return((Image *) NULL);
3976 picture_image->background_color=image->border_color;
3977 (void) SetImageBackgroundColor(picture_image);
3978 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3979 if (caption_image != (Image *) NULL)
3981 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3982 quantum,(ssize_t) (image->rows+3*quantum/2));
3983 caption_image=DestroyImage(caption_image);
3985 (void) QueryColorCompliance("none",AllCompliance,
3986 &picture_image->background_color,exception);
3987 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
3988 rotate_image=RotateImage(picture_image,90.0,exception);
3989 picture_image=DestroyImage(picture_image);
3990 if (rotate_image == (Image *) NULL)
3991 return((Image *) NULL);
3992 picture_image=rotate_image;
3993 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3994 picture_image->columns,method,exception);
3995 picture_image=DestroyImage(picture_image);
3996 if (bend_image == (Image *) NULL)
3997 return((Image *) NULL);
3998 InheritException(&bend_image->exception,exception);
3999 picture_image=bend_image;
4000 rotate_image=RotateImage(picture_image,-90.0,exception);
4001 picture_image=DestroyImage(picture_image);
4002 if (rotate_image == (Image *) NULL)
4003 return((Image *) NULL);
4004 picture_image=rotate_image;
4005 picture_image->background_color=image->background_color;
4006 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4008 if (polaroid_image == (Image *) NULL)
4010 picture_image=DestroyImage(picture_image);
4011 return(picture_image);
4013 flop_image=FlopImage(polaroid_image,exception);
4014 polaroid_image=DestroyImage(polaroid_image);
4015 if (flop_image == (Image *) NULL)
4017 picture_image=DestroyImage(picture_image);
4018 return(picture_image);
4020 polaroid_image=flop_image;
4021 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
4022 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
4023 picture_image=DestroyImage(picture_image);
4024 (void) QueryColorCompliance("none",AllCompliance,
4025 &polaroid_image->background_color,exception);
4026 rotate_image=RotateImage(polaroid_image,angle,exception);
4027 polaroid_image=DestroyImage(polaroid_image);
4028 if (rotate_image == (Image *) NULL)
4029 return((Image *) NULL);
4030 polaroid_image=rotate_image;
4031 trim_image=TrimImage(polaroid_image,exception);
4032 polaroid_image=DestroyImage(polaroid_image);
4033 if (trim_image == (Image *) NULL)
4034 return((Image *) NULL);
4035 polaroid_image=trim_image;
4036 return(polaroid_image);
4040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4044 % S e p i a T o n e I m a g e %
4048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4050 % MagickSepiaToneImage() applies a special effect to the image, similar to the
4051 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4052 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4053 % threshold of 80% is a good starting point for a reasonable tone.
4055 % The format of the SepiaToneImage method is:
4057 % Image *SepiaToneImage(const Image *image,const double threshold,
4058 % ExceptionInfo *exception)
4060 % A description of each parameter follows:
4062 % o image: the image.
4064 % o threshold: the tone threshold.
4066 % o exception: return any errors or warnings in this structure.
4069 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4070 ExceptionInfo *exception)
4072 #define SepiaToneImageTag "SepiaTone/Image"
4091 Initialize sepia-toned image attributes.
4093 assert(image != (const Image *) NULL);
4094 assert(image->signature == MagickSignature);
4095 if (image->debug != MagickFalse)
4096 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4097 assert(exception != (ExceptionInfo *) NULL);
4098 assert(exception->signature == MagickSignature);
4099 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4100 if (sepia_image == (Image *) NULL)
4101 return((Image *) NULL);
4102 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
4104 sepia_image=DestroyImage(sepia_image);
4105 return((Image *) NULL);
4108 Tone each row of the image.
4112 image_view=AcquireCacheView(image);
4113 sepia_view=AcquireCacheView(sepia_image);
4114 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4115 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4117 for (y=0; y < (ssize_t) image->rows; y++)
4119 register const Quantum
4128 if (status == MagickFalse)
4130 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4131 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4133 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
4138 for (x=0; x < (ssize_t) image->columns; x++)
4144 intensity=(MagickRealType) GetPixelIntensity(image,p);
4145 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4146 (MagickRealType) QuantumRange-threshold;
4147 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
4148 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4149 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4150 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4151 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4152 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4154 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4155 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4156 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4157 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
4158 p+=GetPixelChannels(image);
4159 q+=GetPixelChannels(sepia_image);
4161 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4163 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4168 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4169 #pragma omp critical (MagickCore_SepiaToneImage)
4171 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4173 if (proceed == MagickFalse)
4177 sepia_view=DestroyCacheView(sepia_view);
4178 image_view=DestroyCacheView(image_view);
4179 (void) NormalizeImage(sepia_image,exception);
4180 (void) ContrastImage(sepia_image,MagickTrue,exception);
4181 if (status == MagickFalse)
4182 sepia_image=DestroyImage(sepia_image);
4183 return(sepia_image);
4187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4191 % S h a d o w I m a g e %
4195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4197 % ShadowImage() simulates a shadow from the specified image and returns it.
4199 % The format of the ShadowImage method is:
4201 % Image *ShadowImage(const Image *image,const double opacity,
4202 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4203 % ExceptionInfo *exception)
4205 % A description of each parameter follows:
4207 % o image: the image.
4209 % o opacity: percentage transparency.
4211 % o sigma: the standard deviation of the Gaussian, in pixels.
4213 % o x_offset: the shadow x-offset.
4215 % o y_offset: the shadow y-offset.
4217 % o exception: return any errors or warnings in this structure.
4220 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4221 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4222 ExceptionInfo *exception)
4224 #define ShadowImageTag "Shadow/Image"
4237 assert(image != (Image *) NULL);
4238 assert(image->signature == MagickSignature);
4239 if (image->debug != MagickFalse)
4240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4241 assert(exception != (ExceptionInfo *) NULL);
4242 assert(exception->signature == MagickSignature);
4243 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4244 if (clone_image == (Image *) NULL)
4245 return((Image *) NULL);
4246 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4247 clone_image->compose=OverCompositeOp;
4248 border_info.width=(size_t) floor(2.0*sigma+0.5);
4249 border_info.height=(size_t) floor(2.0*sigma+0.5);
4252 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4254 border_image=BorderImage(clone_image,&border_info,image->compose,exception);
4255 clone_image=DestroyImage(clone_image);
4256 if (border_image == (Image *) NULL)
4257 return((Image *) NULL);
4258 if (border_image->matte == MagickFalse)
4259 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
4263 (void) SetImageBackgroundColor(border_image);
4264 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
4265 shadow_image=BlurImage(border_image,0.0,sigma,image->bias,exception);
4266 (void) SetPixelChannelMap(border_image,channel_mask);
4267 border_image=DestroyImage(border_image);
4268 if (shadow_image == (Image *) NULL)
4269 return((Image *) NULL);
4270 if (shadow_image->page.width == 0)
4271 shadow_image->page.width=shadow_image->columns;
4272 if (shadow_image->page.height == 0)
4273 shadow_image->page.height=shadow_image->rows;
4274 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4275 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4276 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4277 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4278 return(shadow_image);
4282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4286 % S k e t c h I m a g e %
4290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4292 % SketchImage() simulates a pencil sketch. We convolve the image with a
4293 % Gaussian operator of the given radius and standard deviation (sigma). For
4294 % reasonable results, radius should be larger than sigma. Use a radius of 0
4295 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4298 % The format of the SketchImage method is:
4300 % Image *SketchImage(const Image *image,const double radius,
4301 % const double sigma,const double angle,const double bias,
4302 % ExceptionInfo *exception)
4304 % A description of each parameter follows:
4306 % o image: the image.
4308 % o radius: the radius of the Gaussian, in pixels, not counting the
4311 % o sigma: the standard deviation of the Gaussian, in pixels.
4313 % o angle: apply the effect along this angle.
4317 % o exception: return any errors or warnings in this structure.
4320 MagickExport Image *SketchImage(const Image *image,const double radius,
4321 const double sigma,const double angle,const double bias,
4322 ExceptionInfo *exception)
4338 **restrict random_info;
4346 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4347 MagickTrue,exception);
4348 if (random_image == (Image *) NULL)
4349 return((Image *) NULL);
4351 random_info=AcquireRandomInfoThreadSet();
4352 random_view=AcquireCacheView(random_image);
4353 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4354 #pragma omp parallel for schedule(dynamic,4) shared(status)
4356 for (y=0; y < (ssize_t) random_image->rows; y++)
4359 id = GetOpenMPThreadId();
4367 if (status == MagickFalse)
4369 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4371 if (q == (Quantum *) NULL)
4376 for (x=0; x < (ssize_t) random_image->columns; x++)
4384 value=GetPseudoRandomValue(random_info[id]);
4385 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4390 traits=GetPixelChannelMapTraits(random_image,(PixelChannel) i);
4391 if (traits == UndefinedPixelTrait)
4393 q[i]=ClampToQuantum(QuantumRange*value);
4395 q+=GetPixelChannels(random_image);
4397 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4400 random_view=DestroyCacheView(random_view);
4401 random_info=DestroyRandomInfoThreadSet(random_info);
4402 if (status == MagickFalse)
4404 random_image=DestroyImage(random_image);
4405 return(random_image);
4407 blur_image=MotionBlurImage(random_image,radius,sigma,angle,bias,exception);
4408 random_image=DestroyImage(random_image);
4409 if (blur_image == (Image *) NULL)
4410 return((Image *) NULL);
4411 dodge_image=EdgeImage(blur_image,radius,sigma,exception);
4412 blur_image=DestroyImage(blur_image);
4413 if (dodge_image == (Image *) NULL)
4414 return((Image *) NULL);
4415 (void) NormalizeImage(dodge_image,exception);
4416 (void) NegateImage(dodge_image,MagickFalse,exception);
4417 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4418 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4419 if (sketch_image == (Image *) NULL)
4421 dodge_image=DestroyImage(dodge_image);
4422 return((Image *) NULL);
4424 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4425 dodge_image=DestroyImage(dodge_image);
4426 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4427 if (blend_image == (Image *) NULL)
4429 sketch_image=DestroyImage(sketch_image);
4430 return((Image *) NULL);
4432 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4433 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4434 blend_image=DestroyImage(blend_image);
4435 return(sketch_image);
4439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4443 % S o l a r i z e I m a g e %
4447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4449 % SolarizeImage() applies a special effect to the image, similar to the effect
4450 % achieved in a photo darkroom by selectively exposing areas of photo
4451 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4452 % measure of the extent of the solarization.
4454 % The format of the SolarizeImage method is:
4456 % MagickBooleanType SolarizeImage(Image *image,const double threshold,
4457 % ExceptionInfo *exception)
4459 % A description of each parameter follows:
4461 % o image: the image.
4463 % o threshold: Define the extent of the solarization.
4465 % o exception: return any errors or warnings in this structure.
4468 MagickExport MagickBooleanType SolarizeImage(Image *image,
4469 const double threshold,ExceptionInfo *exception)
4471 #define SolarizeImageTag "Solarize/Image"
4485 assert(image != (Image *) NULL);
4486 assert(image->signature == MagickSignature);
4487 if (image->debug != MagickFalse)
4488 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4489 if (image->storage_class == PseudoClass)
4497 for (i=0; i < (ssize_t) image->colors; i++)
4499 if ((MagickRealType) image->colormap[i].red > threshold)
4500 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4501 if ((MagickRealType) image->colormap[i].green > threshold)
4502 image->colormap[i].green=(Quantum) QuantumRange-
4503 image->colormap[i].green;
4504 if ((MagickRealType) image->colormap[i].blue > threshold)
4505 image->colormap[i].blue=(Quantum) QuantumRange-
4506 image->colormap[i].blue;
4514 image_view=AcquireCacheView(image);
4515 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4516 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4518 for (y=0; y < (ssize_t) image->rows; y++)
4526 if (status == MagickFalse)
4528 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4529 if (q == (Quantum *) NULL)
4534 for (x=0; x < (ssize_t) image->columns; x++)
4539 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4544 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
4545 if ((traits == UndefinedPixelTrait) ||
4546 ((traits & CopyPixelTrait) != 0))
4548 if ((MagickRealType) q[i] > threshold)
4549 q[i]=QuantumRange-q[i];
4551 q+=GetPixelChannels(image);
4553 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4555 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4560 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4561 #pragma omp critical (MagickCore_SolarizeImage)
4563 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4564 if (proceed == MagickFalse)
4568 image_view=DestroyCacheView(image_view);
4573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4577 % S t e g a n o I m a g e %
4581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4583 % SteganoImage() hides a digital watermark within the image. Recover
4584 % the hidden watermark later to prove that the authenticity of an image.
4585 % Offset defines the start position within the image to hide the watermark.
4587 % The format of the SteganoImage method is:
4589 % Image *SteganoImage(const Image *image,Image *watermark,
4590 % ExceptionInfo *exception)
4592 % A description of each parameter follows:
4594 % o image: the image.
4596 % o watermark: the watermark image.
4598 % o exception: return any errors or warnings in this structure.
4601 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4602 ExceptionInfo *exception)
4604 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4605 #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
4606 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4607 #define SteganoImageTag "Stegano/Image"
4642 Initialize steganographic image attributes.
4644 assert(image != (const Image *) NULL);
4645 assert(image->signature == MagickSignature);
4646 if (image->debug != MagickFalse)
4647 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4648 assert(watermark != (const Image *) NULL);
4649 assert(watermark->signature == MagickSignature);
4650 assert(exception != (ExceptionInfo *) NULL);
4651 assert(exception->signature == MagickSignature);
4653 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4654 if (stegano_image == (Image *) NULL)
4655 return((Image *) NULL);
4656 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
4658 stegano_image=DestroyImage(stegano_image);
4659 return((Image *) NULL);
4661 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4663 Hide watermark in low-order bits of image.
4668 depth=stegano_image->depth;
4671 watermark_view=AcquireCacheView(watermark);
4672 stegano_view=AcquireCacheView(stegano_image);
4673 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4675 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4677 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4680 virtual_pixel[MaxPixelChannels];
4682 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,virtual_pixel,
4684 pixel.red=(double) virtual_pixel[RedPixelChannel];
4685 pixel.green=(double) virtual_pixel[GreenPixelChannel];
4686 pixel.blue=(double) virtual_pixel[BluePixelChannel];
4687 pixel.alpha=(double) virtual_pixel[AlphaPixelChannel];
4688 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4690 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4691 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4693 if (q == (Quantum *) NULL)
4699 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
4700 GetPixelPacketIntensity(&pixel),i)),q);
4705 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
4706 GetPixelPacketIntensity(&pixel),i)),q);
4711 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
4712 GetPixelPacketIntensity(&pixel),i)),q);
4716 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4722 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4724 if (k == image->offset)
4728 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4733 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4735 if (proceed == MagickFalse)
4739 stegano_view=DestroyCacheView(stegano_view);
4740 watermark_view=DestroyCacheView(watermark_view);
4741 if (stegano_image->storage_class == PseudoClass)
4742 (void) SyncImage(stegano_image);
4743 if (status == MagickFalse)
4745 stegano_image=DestroyImage(stegano_image);
4746 return((Image *) NULL);
4748 return(stegano_image);
4752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4756 % S t e r e o A n a g l y p h I m a g e %
4760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4762 % StereoAnaglyphImage() combines two images and produces a single image that
4763 % is the composite of a left and right image of a stereo pair. Special
4764 % red-green stereo glasses are required to view this effect.
4766 % The format of the StereoAnaglyphImage method is:
4768 % Image *StereoImage(const Image *left_image,const Image *right_image,
4769 % ExceptionInfo *exception)
4770 % Image *StereoAnaglyphImage(const Image *left_image,
4771 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4772 % ExceptionInfo *exception)
4774 % A description of each parameter follows:
4776 % o left_image: the left image.
4778 % o right_image: the right image.
4780 % o exception: return any errors or warnings in this structure.
4782 % o x_offset: amount, in pixels, by which the left image is offset to the
4783 % right of the right image.
4785 % o y_offset: amount, in pixels, by which the left image is offset to the
4786 % bottom of the right image.
4790 MagickExport Image *StereoImage(const Image *left_image,
4791 const Image *right_image,ExceptionInfo *exception)
4793 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4796 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4797 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4798 ExceptionInfo *exception)
4800 #define StereoImageTag "Stereo/Image"
4814 assert(left_image != (const Image *) NULL);
4815 assert(left_image->signature == MagickSignature);
4816 if (left_image->debug != MagickFalse)
4817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4818 left_image->filename);
4819 assert(right_image != (const Image *) NULL);
4820 assert(right_image->signature == MagickSignature);
4821 assert(exception != (ExceptionInfo *) NULL);
4822 assert(exception->signature == MagickSignature);
4823 assert(right_image != (const Image *) NULL);
4825 if ((left_image->columns != right_image->columns) ||
4826 (left_image->rows != right_image->rows))
4827 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4829 Initialize stereo image attributes.
4831 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4832 MagickTrue,exception);
4833 if (stereo_image == (Image *) NULL)
4834 return((Image *) NULL);
4835 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
4837 stereo_image=DestroyImage(stereo_image);
4838 return((Image *) NULL);
4841 Copy left image to red channel and right image to blue channel.
4844 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4846 register const Quantum
4856 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4858 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4859 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4860 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4861 (r == (Quantum *) NULL))
4863 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4865 SetPixelRed(image,GetPixelRed(left_image,p),r);
4866 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4867 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4868 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4869 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4870 GetPixelAlpha(right_image,q))/2,r);
4871 p+=GetPixelChannels(left_image);
4872 q+=GetPixelChannels(right_image);
4873 r+=GetPixelChannels(stereo_image);
4875 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4877 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4882 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4883 stereo_image->rows);
4884 if (proceed == MagickFalse)
4888 if (status == MagickFalse)
4890 stereo_image=DestroyImage(stereo_image);
4891 return((Image *) NULL);
4893 return(stereo_image);
4897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4901 % S w i r l I m a g e %
4905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4907 % SwirlImage() swirls the pixels about the center of the image, where
4908 % degrees indicates the sweep of the arc through which each pixel is moved.
4909 % You get a more dramatic effect as the degrees move from 1 to 360.
4911 % The format of the SwirlImage method is:
4913 % Image *SwirlImage(const Image *image,double degrees,
4914 % const PixelInterpolateMethod method,ExceptionInfo *exception)
4916 % A description of each parameter follows:
4918 % o image: the image.
4920 % o degrees: Define the tightness of the swirling effect.
4922 % o method: the pixel interpolation method.
4924 % o exception: return any errors or warnings in this structure.
4927 MagickExport Image *SwirlImage(const Image *image,double degrees,
4928 const PixelInterpolateMethod method,ExceptionInfo *exception)
4930 #define SwirlImageTag "Swirl/Image"
4956 Initialize swirl image attributes.
4958 assert(image != (const Image *) NULL);
4959 assert(image->signature == MagickSignature);
4960 if (image->debug != MagickFalse)
4961 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4962 assert(exception != (ExceptionInfo *) NULL);
4963 assert(exception->signature == MagickSignature);
4964 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4965 if (swirl_image == (Image *) NULL)
4966 return((Image *) NULL);
4967 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
4969 swirl_image=DestroyImage(swirl_image);
4970 return((Image *) NULL);
4972 if (swirl_image->background_color.alpha != OpaqueAlpha)
4973 swirl_image->matte=MagickTrue;
4975 Compute scaling factor.
4977 center.x=(double) image->columns/2.0;
4978 center.y=(double) image->rows/2.0;
4979 radius=MagickMax(center.x,center.y);
4982 if (image->columns > image->rows)
4983 scale.y=(double) image->columns/(double) image->rows;
4985 if (image->columns < image->rows)
4986 scale.x=(double) image->rows/(double) image->columns;
4987 degrees=(double) DegreesToRadians(degrees);
4993 image_view=AcquireCacheView(image);
4994 swirl_view=AcquireCacheView(swirl_image);
4995 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4996 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4998 for (y=0; y < (ssize_t) image->rows; y++)
5006 register const Quantum
5015 if (status == MagickFalse)
5017 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
5018 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5020 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5025 delta.y=scale.y*(double) (y-center.y);
5026 for (x=0; x < (ssize_t) image->columns; x++)
5032 Determine if the pixel is within an ellipse.
5034 delta.x=scale.x*(double) (x-center.x);
5035 distance=delta.x*delta.x+delta.y*delta.y;
5036 if (distance >= (radius*radius))
5038 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5051 factor=1.0-sqrt((double) distance)/radius;
5052 sine=sin((double) (degrees*factor*factor));
5053 cosine=cos((double) (degrees*factor*factor));
5054 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5055 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5056 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
5058 p+=GetPixelChannels(image);
5059 q+=GetPixelChannels(swirl_image);
5061 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5063 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5068 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5069 #pragma omp critical (MagickCore_SwirlImage)
5071 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5072 if (proceed == MagickFalse)
5076 swirl_view=DestroyCacheView(swirl_view);
5077 image_view=DestroyCacheView(image_view);
5078 if (status == MagickFalse)
5079 swirl_image=DestroyImage(swirl_image);
5080 return(swirl_image);
5084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5088 % T i n t I m a g e %
5092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5094 % TintImage() applies a color vector to each pixel in the image. The length
5095 % of the vector is 0 for black and white and at its maximum for the midtones.
5096 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5098 % The format of the TintImage method is:
5100 % Image *TintImage(const Image *image,const char *blend,
5101 % const PixelInfo *tint,ExceptionInfo *exception)
5103 % A description of each parameter follows:
5105 % o image: the image.
5107 % o blend: A color value used for tinting.
5109 % o tint: A color value used for tinting.
5111 % o exception: return any errors or warnings in this structure.
5114 MagickExport Image *TintImage(const Image *image,const char *blend,
5115 const PixelInfo *tint,ExceptionInfo *exception)
5117 #define TintImageTag "Tint/Image"
5149 Allocate tint image.
5151 assert(image != (const Image *) NULL);
5152 assert(image->signature == MagickSignature);
5153 if (image->debug != MagickFalse)
5154 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5155 assert(exception != (ExceptionInfo *) NULL);
5156 assert(exception->signature == MagickSignature);
5157 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5158 if (tint_image == (Image *) NULL)
5159 return((Image *) NULL);
5160 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
5162 tint_image=DestroyImage(tint_image);
5163 return((Image *) NULL);
5165 if (blend == (const char *) NULL)
5168 Determine RGB values of the color.
5170 GetPixelInfo(image,&pixel);
5171 flags=ParseGeometry(blend,&geometry_info);
5172 pixel.red=geometry_info.rho;
5173 pixel.green=geometry_info.rho;
5174 pixel.blue=geometry_info.rho;
5175 pixel.alpha=OpaqueAlpha;
5176 if ((flags & SigmaValue) != 0)
5177 pixel.green=geometry_info.sigma;
5178 if ((flags & XiValue) != 0)
5179 pixel.blue=geometry_info.xi;
5180 if ((flags & PsiValue) != 0)
5181 pixel.alpha=geometry_info.psi;
5182 if (image->colorspace == CMYKColorspace)
5184 pixel.black=geometry_info.rho;
5185 if ((flags & PsiValue) != 0)
5186 pixel.black=geometry_info.psi;
5187 if ((flags & ChiValue) != 0)
5188 pixel.alpha=geometry_info.chi;
5190 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5191 color_vector.red=(MagickRealType) (pixel.red*tint->red/100.0-intensity);
5192 color_vector.green=(MagickRealType) (pixel.green*tint->green/100.0-intensity);
5193 color_vector.blue=(MagickRealType) (pixel.blue*tint->blue/100.0-intensity);
5194 color_vector.black=(MagickRealType) (pixel.black*tint->black/100.0-intensity);
5195 color_vector.alpha=(MagickRealType) (pixel.alpha*tint->alpha/100.0-intensity);
5201 image_view=AcquireCacheView(image);
5202 tint_view=AcquireCacheView(tint_image);
5203 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5204 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5206 for (y=0; y < (ssize_t) image->rows; y++)
5208 register const Quantum
5217 if (status == MagickFalse)
5219 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5220 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5222 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
5227 for (x=0; x < (ssize_t) image->columns; x++)
5235 if ((GetPixelRedTraits(tint_image) & UpdatePixelTrait) != 0)
5237 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5238 pixel.red=(MagickRealType) GetPixelRed(image,p)+
5239 color_vector.red*(1.0-(4.0*(weight*weight)));
5240 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5242 if ((GetPixelGreenTraits(tint_image) & UpdatePixelTrait) != 0)
5244 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5245 pixel.green=(MagickRealType) GetPixelGreen(image,p)+
5246 color_vector.green*(1.0-(4.0*(weight*weight)));
5247 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5249 if ((GetPixelBlueTraits(tint_image) & UpdatePixelTrait) != 0)
5251 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5252 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+
5253 color_vector.blue*(1.0-(4.0*(weight*weight)));
5254 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5256 if ((GetPixelBlackTraits(tint_image) & UpdatePixelTrait) != 0)
5258 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5259 pixel.black=(MagickRealType) GetPixelBlack(image,p)+
5260 color_vector.black*(1.0-(4.0*(weight*weight)));
5261 SetPixelBlack(tint_image,ClampToQuantum(pixel.black),q);
5263 if ((GetPixelAlphaTraits(tint_image) & CopyPixelTrait) != 0)
5264 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
5265 p+=GetPixelChannels(image);
5266 q+=GetPixelChannels(tint_image);
5268 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5270 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5275 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5276 #pragma omp critical (MagickCore_TintImage)
5278 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5279 if (proceed == MagickFalse)
5283 tint_view=DestroyCacheView(tint_view);
5284 image_view=DestroyCacheView(image_view);
5285 if (status == MagickFalse)
5286 tint_image=DestroyImage(tint_image);
5291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5295 % V i g n e t t e I m a g e %
5299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5301 % VignetteImage() softens the edges of the image in vignette style.
5303 % The format of the VignetteImage method is:
5305 % Image *VignetteImage(const Image *image,const double radius,
5306 % const double sigma,const ssize_t x,const ssize_t y,
5307 % ExceptionInfo *exception)
5309 % A description of each parameter follows:
5311 % o image: the image.
5313 % o radius: the radius of the pixel neighborhood.
5315 % o sigma: the standard deviation of the Gaussian, in pixels.
5317 % o x, y: Define the x and y ellipse offset.
5319 % o exception: return any errors or warnings in this structure.
5322 MagickExport Image *VignetteImage(const Image *image,const double radius,
5323 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5326 ellipse[MaxTextExtent];
5337 assert(image != (Image *) NULL);
5338 assert(image->signature == MagickSignature);
5339 if (image->debug != MagickFalse)
5340 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5341 assert(exception != (ExceptionInfo *) NULL);
5342 assert(exception->signature == MagickSignature);
5343 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5344 if (canvas_image == (Image *) NULL)
5345 return((Image *) NULL);
5346 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
5348 canvas_image=DestroyImage(canvas_image);
5349 return((Image *) NULL);
5351 canvas_image->matte=MagickTrue;
5352 oval_image=CloneImage(canvas_image,canvas_image->columns,
5353 canvas_image->rows,MagickTrue,exception);
5354 if (oval_image == (Image *) NULL)
5356 canvas_image=DestroyImage(canvas_image);
5357 return((Image *) NULL);
5359 (void) QueryColorCompliance("#000000",AllCompliance,
5360 &oval_image->background_color,exception);
5361 (void) SetImageBackgroundColor(oval_image);
5362 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5363 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5365 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5367 (void) FormatLocaleString(ellipse,MaxTextExtent,
5368 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5369 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5370 draw_info->primitive=AcquireString(ellipse);
5371 (void) DrawImage(oval_image,draw_info,exception);
5372 draw_info=DestroyDrawInfo(draw_info);
5373 blur_image=BlurImage(oval_image,radius,sigma,image->bias,exception);
5374 oval_image=DestroyImage(oval_image);
5375 if (blur_image == (Image *) NULL)
5377 canvas_image=DestroyImage(canvas_image);
5378 return((Image *) NULL);
5380 blur_image->matte=MagickFalse;
5381 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5382 blur_image=DestroyImage(blur_image);
5383 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5384 canvas_image=DestroyImage(canvas_image);
5385 return(vignette_image);
5389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5393 % W a v e I m a g e %
5397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5399 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5400 % vertically along a sine wave whose amplitude and wavelength is specified
5401 % by the given parameters.
5403 % The format of the WaveImage method is:
5405 % Image *WaveImage(const Image *image,const double amplitude,
5406 % const double wave_length,const PixelInterpolateMethod method,
5407 % ExceptionInfo *exception)
5409 % A description of each parameter follows:
5411 % o image: the image.
5413 % o amplitude, wave_length: Define the amplitude and wave length of the
5416 % o interpolate: the pixel interpolation method.
5418 % o exception: return any errors or warnings in this structure.
5421 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5422 const double wave_length,const PixelInterpolateMethod method,
5423 ExceptionInfo *exception)
5425 #define WaveImageTag "Wave/Image"
5450 Initialize wave image attributes.
5452 assert(image != (Image *) NULL);
5453 assert(image->signature == MagickSignature);
5454 if (image->debug != MagickFalse)
5455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5456 assert(exception != (ExceptionInfo *) NULL);
5457 assert(exception->signature == MagickSignature);
5458 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5459 fabs(amplitude)),MagickTrue,exception);
5460 if (wave_image == (Image *) NULL)
5461 return((Image *) NULL);
5462 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
5464 wave_image=DestroyImage(wave_image);
5465 return((Image *) NULL);
5467 if (wave_image->background_color.alpha != OpaqueAlpha)
5468 wave_image->matte=MagickTrue;
5472 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5474 if (sine_map == (MagickRealType *) NULL)
5476 wave_image=DestroyImage(wave_image);
5477 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5479 for (i=0; i < (ssize_t) wave_image->columns; i++)
5480 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5487 image_view=AcquireCacheView(image);
5488 wave_view=AcquireCacheView(wave_image);
5489 (void) SetCacheViewVirtualPixelMethod(image_view,
5490 BackgroundVirtualPixelMethod);
5491 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5492 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5494 for (y=0; y < (ssize_t) wave_image->rows; y++)
5502 if (status == MagickFalse)
5504 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5506 if (q == (Quantum *) NULL)
5511 for (x=0; x < (ssize_t) wave_image->columns; x++)
5513 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5514 (double) x,(double) (y-sine_map[x]),q,exception);
5515 q+=GetPixelChannels(wave_image);
5517 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5519 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5524 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5525 #pragma omp critical (MagickCore_WaveImage)
5527 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5528 if (proceed == MagickFalse)
5532 wave_view=DestroyCacheView(wave_view);
5533 image_view=DestroyCacheView(image_view);
5534 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5535 if (status == MagickFalse)
5536 wave_image=DestroyImage(wave_image);