2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects Methods %
20 % Copyright 1999-2010 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 "magick/studio.h"
44 #include "magick/annotate.h"
45 #include "magick/artifact.h"
46 #include "magick/attribute.h"
47 #include "magick/cache.h"
48 #include "magick/cache-view.h"
49 #include "magick/color.h"
50 #include "magick/color-private.h"
51 #include "magick/composite.h"
52 #include "magick/decorate.h"
53 #include "magick/draw.h"
54 #include "magick/effect.h"
55 #include "magick/enhance.h"
56 #include "magick/exception.h"
57 #include "magick/exception-private.h"
58 #include "magick/fx.h"
59 #include "magick/fx-private.h"
60 #include "magick/gem.h"
61 #include "magick/geometry.h"
62 #include "magick/layer.h"
63 #include "magick/list.h"
64 #include "magick/log.h"
65 #include "magick/image.h"
66 #include "magick/image-private.h"
67 #include "magick/magick.h"
68 #include "magick/memory_.h"
69 #include "magick/monitor.h"
70 #include "magick/monitor-private.h"
71 #include "magick/option.h"
72 #include "magick/pixel-private.h"
73 #include "magick/property.h"
74 #include "magick/quantum.h"
75 #include "magick/quantum-private.h"
76 #include "magick/random_.h"
77 #include "magick/random-private.h"
78 #include "magick/resample.h"
79 #include "magick/resample-private.h"
80 #include "magick/resize.h"
81 #include "magick/shear.h"
82 #include "magick/splay-tree.h"
83 #include "magick/statistic.h"
84 #include "magick/string_.h"
85 #include "magick/string-private.h"
86 #include "magick/thread-private.h"
87 #include "magick/transform.h"
88 #include "magick/utility.h"
93 #define LeftShiftOperator 0xf5
94 #define RightShiftOperator 0xf6
95 #define LessThanEqualOperator 0xf7
96 #define GreaterThanEqualOperator 0xf8
97 #define EqualOperator 0xf9
98 #define NotEqualOperator 0xfa
99 #define LogicalAndOperator 0xfb
100 #define LogicalOrOperator 0xfc
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)
146 % A description of each parameter follows:
148 % o image: the image.
150 % o expression: the expression.
153 MagickExport FxInfo *AcquireFxInfo(const Image *image,const char *expression)
164 fx_info=(FxInfo *) AcquireAlignedMemory(1,sizeof(*fx_info));
165 if (fx_info == (FxInfo *) NULL)
166 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
167 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
168 fx_info->exception=AcquireExceptionInfo();
169 fx_info->images=image;
170 fx_info->matte=image->matte;
171 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
172 RelinquishMagickMemory);
173 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
174 RelinquishMagickMemory);
175 fx_info->resample_filter=(ResampleFilter **) AcquireQuantumMemory(
176 GetImageListLength(fx_info->images),sizeof(*fx_info->resample_filter));
177 if (fx_info->resample_filter == (ResampleFilter **) NULL)
178 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
179 for (i=0; i < (long) GetImageListLength(fx_info->images); i++)
181 fx_info->resample_filter[i]=AcquireResampleFilter(GetImageFromList(
182 fx_info->images,i),fx_info->exception);
183 SetResampleFilter(fx_info->resample_filter[i],PointFilter,1.0);
185 fx_info->random_info=AcquireRandomInfo();
186 fx_info->expression=ConstantString(expression);
187 fx_info->file=stderr;
188 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
189 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
190 (strstr(fx_info->expression,"e-") != (char *) NULL))
193 Convert scientific notation.
195 (void) SubstituteString(&fx_info->expression,"0e+","0*10^");
196 (void) SubstituteString(&fx_info->expression,"1e+","1*10^");
197 (void) SubstituteString(&fx_info->expression,"2e+","2*10^");
198 (void) SubstituteString(&fx_info->expression,"3e+","3*10^");
199 (void) SubstituteString(&fx_info->expression,"4e+","4*10^");
200 (void) SubstituteString(&fx_info->expression,"5e+","5*10^");
201 (void) SubstituteString(&fx_info->expression,"6e+","6*10^");
202 (void) SubstituteString(&fx_info->expression,"7e+","7*10^");
203 (void) SubstituteString(&fx_info->expression,"8e+","8*10^");
204 (void) SubstituteString(&fx_info->expression,"9e+","9*10^");
205 (void) SubstituteString(&fx_info->expression,"0e-","0*10^-");
206 (void) SubstituteString(&fx_info->expression,"1e-","1*10^-");
207 (void) SubstituteString(&fx_info->expression,"2e-","2*10^-");
208 (void) SubstituteString(&fx_info->expression,"3e-","3*10^-");
209 (void) SubstituteString(&fx_info->expression,"4e-","4*10^-");
210 (void) SubstituteString(&fx_info->expression,"5e-","5*10^-");
211 (void) SubstituteString(&fx_info->expression,"6e-","6*10^-");
212 (void) SubstituteString(&fx_info->expression,"7e-","7*10^-");
213 (void) SubstituteString(&fx_info->expression,"8e-","8*10^-");
214 (void) SubstituteString(&fx_info->expression,"9e-","9*10^-");
217 Convert complex to simple operators.
220 *fx_op=(char) LeftShiftOperator;
221 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
222 *fx_op=(char) RightShiftOperator;
223 (void) SubstituteString(&fx_info->expression,">>",fx_op);
224 *fx_op=(char) LessThanEqualOperator;
225 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
226 *fx_op=(char) GreaterThanEqualOperator;
227 (void) SubstituteString(&fx_info->expression,">=",fx_op);
228 *fx_op=(char) EqualOperator;
229 (void) SubstituteString(&fx_info->expression,"==",fx_op);
230 *fx_op=(char) NotEqualOperator;
231 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
232 *fx_op=(char) LogicalAndOperator;
233 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
234 *fx_op=(char) LogicalOrOperator;
235 (void) SubstituteString(&fx_info->expression,"||",fx_op);
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % A d d N o i s e I m a g e %
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % AddNoiseImage() adds random noise to the image.
252 % The format of the AddNoiseImage method is:
254 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
255 % ExceptionInfo *exception)
256 % Image *AddNoiseImageChannel(const Image *image,const ChannelType channel,
257 % const NoiseType noise_type,ExceptionInfo *exception)
259 % A description of each parameter follows:
261 % o image: the image.
263 % o channel: the channel type.
265 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
266 % Impulse, Laplacian, or Poisson.
268 % o exception: return any errors or warnings in this structure.
271 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
272 ExceptionInfo *exception)
277 noise_image=AddNoiseImageChannel(image,DefaultChannels,noise_type,exception);
281 MagickExport Image *AddNoiseImageChannel(const Image *image,
282 const ChannelType channel,const NoiseType noise_type,ExceptionInfo *exception)
284 #define AddNoiseImageTag "AddNoise/Image"
307 **restrict random_info;
310 Initialize noise image attributes.
312 assert(image != (const Image *) NULL);
313 assert(image->signature == MagickSignature);
314 if (image->debug != MagickFalse)
315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
316 assert(exception != (ExceptionInfo *) NULL);
317 assert(exception->signature == MagickSignature);
318 noise_image=CloneImage(image,0,0,MagickTrue,exception);
319 if (noise_image == (Image *) NULL)
320 return((Image *) NULL);
321 if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
323 InheritException(exception,&noise_image->exception);
324 noise_image=DestroyImage(noise_image);
325 return((Image *) NULL);
328 Add noise in each row.
331 option=GetImageArtifact(image,"attenuate");
332 if (option != (char *) NULL)
333 attenuate=StringToDouble(option);
336 random_info=AcquireRandomInfoThreadSet();
337 image_view=AcquireCacheView(image);
338 noise_view=AcquireCacheView(noise_image);
339 #if defined(MAGICKCORE_OPENMP_SUPPORT)
340 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
342 for (y=0; y < (long) image->rows; y++)
347 register const IndexPacket
350 register const PixelPacket
354 *restrict noise_indexes;
363 if (status == MagickFalse)
365 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
366 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
368 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
373 indexes=GetCacheViewVirtualIndexQueue(image_view);
374 noise_indexes=GetCacheViewAuthenticIndexQueue(noise_view);
375 id=GetOpenMPThreadId();
376 for (x=0; x < (long) image->columns; x++)
378 if ((channel & RedChannel) != 0)
379 q->red=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
380 p->red,noise_type,attenuate));
381 if ((channel & GreenChannel) != 0)
382 q->green=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
383 p->green,noise_type,attenuate));
384 if ((channel & BlueChannel) != 0)
385 q->blue=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
386 p->blue,noise_type,attenuate));
387 if ((channel & OpacityChannel) != 0)
388 q->opacity=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
389 p->opacity,noise_type,attenuate));
390 if (((channel & IndexChannel) != 0) &&
391 (image->colorspace == CMYKColorspace))
392 noise_indexes[x]=(IndexPacket) ClampToQuantum(GenerateDifferentialNoise(
393 random_info[id],indexes[x],noise_type,attenuate));
397 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
398 if (sync == MagickFalse)
400 if (image->progress_monitor != (MagickProgressMonitor) NULL)
405 #if defined(MAGICKCORE_OPENMP_SUPPORT)
406 #pragma omp critical (MagickCore_AddNoiseImage)
408 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
410 if (proceed == MagickFalse)
414 noise_view=DestroyCacheView(noise_view);
415 image_view=DestroyCacheView(image_view);
416 random_info=DestroyRandomInfoThreadSet(random_info);
417 if (status == MagickFalse)
418 noise_image=DestroyImage(noise_image);
423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 % B l u e S h i f t I m a g e %
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 % BlueShiftImage() mutes the colors of the image to simulate a scene at
434 % nighttime in the moonlight.
436 % The format of the BlueShiftImage method is:
438 % Image *BlueShiftImage(const Image *image,const double factor,
439 % ExceptionInfo *exception)
441 % A description of each parameter follows:
443 % o image: the image.
445 % o factor: the shift factor.
447 % o exception: return any errors or warnings in this structure.
450 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
451 ExceptionInfo *exception)
453 #define BlueShiftImageTag "BlueShift/Image"
470 Allocate blue shift image.
472 assert(image != (const Image *) NULL);
473 assert(image->signature == MagickSignature);
474 if (image->debug != MagickFalse)
475 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
476 assert(exception != (ExceptionInfo *) NULL);
477 assert(exception->signature == MagickSignature);
478 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
480 if (shift_image == (Image *) NULL)
481 return((Image *) NULL);
482 if (SetImageStorageClass(shift_image,DirectClass) == MagickFalse)
484 InheritException(exception,&shift_image->exception);
485 shift_image=DestroyImage(shift_image);
486 return((Image *) NULL);
489 Blue-shift DirectClass image.
493 image_view=AcquireCacheView(image);
494 shift_view=AcquireCacheView(shift_image);
495 #if defined(MAGICKCORE_OPENMP_SUPPORT)
496 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
498 for (y=0; y < (long) image->rows; y++)
509 register const PixelPacket
518 if (status == MagickFalse)
520 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
521 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
523 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
528 for (x=0; x < (long) image->columns; x++)
530 quantum=GetRedPixelComponent(p);
531 if (p->green < quantum)
532 quantum=GetGreenPixelComponent(p);
533 if (p->blue < quantum)
534 quantum=GetBluePixelComponent(p);
535 pixel.red=0.5*(p->red+factor*quantum);
536 pixel.green=0.5*(p->green+factor*quantum);
537 pixel.blue=0.5*(p->blue+factor*quantum);
538 quantum=GetRedPixelComponent(p);
539 if (p->green > quantum)
540 quantum=GetGreenPixelComponent(p);
541 if (p->blue > quantum)
542 quantum=GetBluePixelComponent(p);
543 pixel.red=0.5*(pixel.red+factor*quantum);
544 pixel.green=0.5*(pixel.green+factor*quantum);
545 pixel.blue=0.5*(pixel.blue+factor*quantum);
546 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
547 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
548 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
552 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
553 if (sync == MagickFalse)
555 if (image->progress_monitor != (MagickProgressMonitor) NULL)
560 #if defined(MAGICKCORE_OPENMP_SUPPORT)
561 #pragma omp critical (MagickCore_BlueShiftImage)
563 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
565 if (proceed == MagickFalse)
569 image_view=DestroyCacheView(image_view);
570 shift_view=DestroyCacheView(shift_view);
571 if (status == MagickFalse)
572 shift_image=DestroyImage(shift_image);
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 % C h a r c o a l I m a g e %
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 % CharcoalImage() creates a new image that is a copy of an existing one with
588 % the edge highlighted. It allocates the memory necessary for the new Image
589 % structure and returns a pointer to the new image.
591 % The format of the CharcoalImage method is:
593 % Image *CharcoalImage(const Image *image,const double radius,
594 % const double sigma,ExceptionInfo *exception)
596 % A description of each parameter follows:
598 % o image: the image.
600 % o radius: the radius of the pixel neighborhood.
602 % o sigma: the standard deviation of the Gaussian, in pixels.
604 % o exception: return any errors or warnings in this structure.
607 MagickExport Image *CharcoalImage(const Image *image,const double radius,
608 const double sigma,ExceptionInfo *exception)
615 assert(image != (Image *) NULL);
616 assert(image->signature == MagickSignature);
617 if (image->debug != MagickFalse)
618 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
619 assert(exception != (ExceptionInfo *) NULL);
620 assert(exception->signature == MagickSignature);
621 clone_image=CloneImage(image,0,0,MagickTrue,exception);
622 if (clone_image == (Image *) NULL)
623 return((Image *) NULL);
624 (void) SetImageType(clone_image,GrayscaleType);
625 edge_image=EdgeImage(clone_image,radius,exception);
626 clone_image=DestroyImage(clone_image);
627 if (edge_image == (Image *) NULL)
628 return((Image *) NULL);
629 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
630 edge_image=DestroyImage(edge_image);
631 if (charcoal_image == (Image *) NULL)
632 return((Image *) NULL);
633 (void) NormalizeImage(charcoal_image);
634 (void) NegateImage(charcoal_image,MagickFalse);
635 (void) SetImageType(charcoal_image,GrayscaleType);
636 return(charcoal_image);
640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 % C o l o r i z e I m a g e %
648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650 % ColorizeImage() blends the fill color with each pixel in the image.
651 % A percentage blend is specified with opacity. Control the application
652 % of different color components by specifying a different percentage for
653 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
655 % The format of the ColorizeImage method is:
657 % Image *ColorizeImage(const Image *image,const char *opacity,
658 % const PixelPacket colorize,ExceptionInfo *exception)
660 % A description of each parameter follows:
662 % o image: the image.
664 % o opacity: A character string indicating the level of opacity as a
667 % o colorize: A color value.
669 % o exception: return any errors or warnings in this structure.
672 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
673 const PixelPacket colorize,ExceptionInfo *exception)
675 #define ColorizeImageTag "Colorize/Image"
701 Allocate colorized image.
703 assert(image != (const Image *) NULL);
704 assert(image->signature == MagickSignature);
705 if (image->debug != MagickFalse)
706 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
707 assert(exception != (ExceptionInfo *) NULL);
708 assert(exception->signature == MagickSignature);
709 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
711 if (colorize_image == (Image *) NULL)
712 return((Image *) NULL);
713 if (SetImageStorageClass(colorize_image,DirectClass) == MagickFalse)
715 InheritException(exception,&colorize_image->exception);
716 colorize_image=DestroyImage(colorize_image);
717 return((Image *) NULL);
719 if (opacity == (const char *) NULL)
720 return(colorize_image);
722 Determine RGB values of the pen color.
724 flags=ParseGeometry(opacity,&geometry_info);
725 pixel.red=geometry_info.rho;
726 pixel.green=geometry_info.rho;
727 pixel.blue=geometry_info.rho;
728 pixel.opacity=(MagickRealType) OpaqueOpacity;
729 if ((flags & SigmaValue) != 0)
730 pixel.green=geometry_info.sigma;
731 if ((flags & XiValue) != 0)
732 pixel.blue=geometry_info.xi;
733 if ((flags & PsiValue) != 0)
734 pixel.opacity=geometry_info.psi;
736 Colorize DirectClass image.
740 image_view=AcquireCacheView(image);
741 colorize_view=AcquireCacheView(colorize_image);
742 #if defined(MAGICKCORE_OPENMP_SUPPORT)
743 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
745 for (y=0; y < (long) image->rows; y++)
750 register const PixelPacket
759 if (status == MagickFalse)
761 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
762 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
764 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
769 for (x=0; x < (long) image->columns; x++)
771 q->red=(Quantum) ((p->red*(100.0-pixel.red)+
772 colorize.red*pixel.red)/100.0);
773 q->green=(Quantum) ((p->green*(100.0-pixel.green)+
774 colorize.green*pixel.green)/100.0);
775 q->blue=(Quantum) ((p->blue*(100.0-pixel.blue)+
776 colorize.blue*pixel.blue)/100.0);
777 q->opacity=(Quantum) ((p->opacity*(100.0-pixel.opacity)+
778 colorize.opacity*pixel.opacity)/100.0);
782 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
783 if (sync == MagickFalse)
785 if (image->progress_monitor != (MagickProgressMonitor) NULL)
790 #if defined(MAGICKCORE_OPENMP_SUPPORT)
791 #pragma omp critical (MagickCore_ColorizeImage)
793 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
794 if (proceed == MagickFalse)
798 image_view=DestroyCacheView(image_view);
799 colorize_view=DestroyCacheView(colorize_view);
800 if (status == MagickFalse)
801 colorize_image=DestroyImage(colorize_image);
802 return(colorize_image);
806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
810 + D e s t r o y F x I n f o %
814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
818 % The format of the DestroyFxInfo method is:
820 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
822 % A description of each parameter follows:
824 % o fx_info: the fx info.
827 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
832 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
833 fx_info->expression=DestroyString(fx_info->expression);
834 fx_info->symbols=DestroySplayTree(fx_info->symbols);
835 fx_info->colors=DestroySplayTree(fx_info->colors);
836 for (i=0; i < (long) GetImageListLength(fx_info->images); i++)
837 fx_info->resample_filter[i]=DestroyResampleFilter(
838 fx_info->resample_filter[i]);
839 fx_info->resample_filter=(ResampleFilter **) RelinquishMagickMemory(
840 fx_info->resample_filter);
841 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
842 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851 + 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 %
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 % FxEvaluateChannelExpression() evaluates an expression and returns the
860 % The format of the FxEvaluateExpression method is:
862 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
863 % const ChannelType channel,const long x,const long y,
864 % MagickRealType *alpha,Exceptioninfo *exception)
865 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
866 % MagickRealType *alpha,Exceptioninfo *exception)
868 % A description of each parameter follows:
870 % o fx_info: the fx info.
872 % o channel: the channel.
874 % o x,y: the pixel position.
876 % o alpha: the result.
878 % o exception: return any errors or warnings in this structure.
882 static inline double MagickMax(const double x,const double y)
889 static inline double MagickMin(const double x,const double y)
896 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
897 ChannelType channel,const char *symbol,ExceptionInfo *exception)
901 statistic[MaxTextExtent];
909 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
911 switch (*++p) /* e.g. depth.r */
913 case 'r': channel=RedChannel; break;
914 case 'g': channel=GreenChannel; break;
915 case 'b': channel=BlueChannel; break;
916 case 'c': channel=CyanChannel; break;
917 case 'm': channel=MagentaChannel; break;
918 case 'y': channel=YellowChannel; break;
919 case 'k': channel=BlackChannel; break;
922 (void) FormatMagickString(key,MaxTextExtent,"%p.%ld.%s",(void *) image,
923 (long) channel,symbol);
924 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
925 if (value != (const char *) NULL)
926 return(QuantumScale*StringToDouble(value));
927 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
928 if (LocaleNCompare(symbol,"depth",5) == 0)
933 depth=GetImageChannelDepth(image,channel,exception);
934 (void) FormatMagickString(statistic,MaxTextExtent,"%lu",depth);
936 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
942 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
944 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
946 if (LocaleNCompare(symbol,"maxima",6) == 0)
952 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
953 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
955 if (LocaleNCompare(symbol,"mean",4) == 0)
961 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
963 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
965 if (LocaleNCompare(symbol,"minima",6) == 0)
971 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
972 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
974 if (LocaleNCompare(symbol,"skewness",8) == 0)
980 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
982 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
984 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
990 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
992 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
995 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
996 ConstantString(statistic));
997 return(QuantumScale*StringToDouble(statistic));
1000 static MagickRealType
1001 FxEvaluateSubexpression(FxInfo *,const ChannelType,const long,const long,
1002 const char *,MagickRealType *,ExceptionInfo *);
1004 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1005 const long x,const long y,const char *expression,ExceptionInfo *exception)
1011 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1012 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1015 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1016 const long x,const long y,const char *expression,ExceptionInfo *exception)
1022 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1023 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1026 static inline const char *FxSubexpression(const char *expression,
1027 ExceptionInfo *exception)
1036 subexpression=expression;
1037 while ((*subexpression != '\0') &&
1038 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1040 if (strchr("(",(int) *subexpression) != (char *) NULL)
1043 if (strchr(")",(int) *subexpression) != (char *) NULL)
1047 if (*subexpression == '\0')
1048 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1049 "UnbalancedParenthesis","`%s'",expression);
1050 return(subexpression);
1053 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1054 const long x,const long y,const char *expression,ExceptionInfo *exception)
1058 subexpression[MaxTextExtent],
1059 symbol[MaxTextExtent];
1088 i=GetImageIndexInList(fx_info->images);
1092 if (isalpha((int) *(p+1)) == 0)
1094 if (strchr("suv",(int) *p) != (char *) NULL)
1101 i=GetImageIndexInList(fx_info->images);
1104 case 'u': i=0; break;
1105 case 'v': i=1; break;
1112 for (p++; *p != '\0'; )
1126 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1128 i=(long) (alpha+0.5);
1134 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1141 for (p++; *p != '\0'; )
1155 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1166 for (p++; *p != '\0'; )
1180 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1190 length=GetImageListLength(fx_info->images);
1194 image=GetImageFromList(fx_info->images,i);
1195 if (image == (Image *) NULL)
1197 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1198 "NoSuchImage","`%s'",expression);
1201 (void) ResamplePixelColor(fx_info->resample_filter[i],point.x,point.y,&pixel);
1202 if ((strlen(p) > 2) &&
1203 (LocaleCompare(p,"intensity") != 0) &&
1204 (LocaleCompare(p,"luminance") != 0) &&
1205 (LocaleCompare(p,"hue") != 0) &&
1206 (LocaleCompare(p,"saturation") != 0) &&
1207 (LocaleCompare(p,"lightness") != 0))
1210 name[MaxTextExtent];
1212 (void) CopyMagickString(name,p,MaxTextExtent);
1213 for (q=name+(strlen(name)-1); q > name; q--)
1223 if ((strlen(name) > 2) &&
1224 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1229 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1231 if (color != (MagickPixelPacket *) NULL)
1237 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1239 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1240 CloneMagickPixelPacket(&pixel));
1245 (void) CopyMagickString(symbol,p,MaxTextExtent);
1246 StripString(symbol);
1247 if (*symbol == '\0')
1251 case RedChannel: return(QuantumScale*pixel.red);
1252 case GreenChannel: return(QuantumScale*pixel.green);
1253 case BlueChannel: return(QuantumScale*pixel.blue);
1254 case OpacityChannel:
1256 if (pixel.matte == MagickFalse)
1258 fx_info->matte=MagickFalse;
1261 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1265 if (image->colorspace != CMYKColorspace)
1267 (void) ThrowMagickException(exception,GetMagickModule(),
1268 OptionError,"ColorSeparatedImageRequired","`%s'",
1272 return(QuantumScale*pixel.index);
1277 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1278 "UnableToParseExpression","`%s'",p);
1286 if (LocaleCompare(symbol,"a") == 0)
1287 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1293 if (LocaleCompare(symbol,"b") == 0)
1294 return(QuantumScale*pixel.blue);
1300 if (LocaleNCompare(symbol,"channel",7) == 0)
1308 flags=ParseGeometry(symbol+7,&channel_info);
1309 if (image->colorspace == CMYKColorspace)
1314 if ((flags & RhoValue) == 0)
1316 return(channel_info.rho);
1318 case MagentaChannel:
1320 if ((flags & SigmaValue) == 0)
1322 return(channel_info.sigma);
1326 if ((flags & XiValue) == 0)
1328 return(channel_info.xi);
1332 if ((flags & PsiValue) == 0)
1334 return(channel_info.psi);
1336 case OpacityChannel:
1338 if ((flags & ChiValue) == 0)
1340 return(channel_info.chi);
1349 if ((flags & RhoValue) == 0)
1351 return(channel_info.rho);
1355 if ((flags & SigmaValue) == 0)
1357 return(channel_info.sigma);
1361 if ((flags & XiValue) == 0)
1363 return(channel_info.xi);
1365 case OpacityChannel:
1367 if ((flags & PsiValue) == 0)
1369 return(channel_info.psi);
1373 if ((flags & ChiValue) == 0)
1375 return(channel_info.chi);
1382 if (LocaleCompare(symbol,"c") == 0)
1383 return(QuantumScale*pixel.red);
1389 if (LocaleNCompare(symbol,"depth",5) == 0)
1390 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1396 if (LocaleCompare(symbol,"g") == 0)
1397 return(QuantumScale*pixel.green);
1403 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1404 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1405 if (LocaleCompare(symbol,"k") == 0)
1407 if (image->colorspace != CMYKColorspace)
1409 (void) ThrowMagickException(exception,GetMagickModule(),
1410 OptionError,"ColorSeparatedImageRequired","`%s'",
1414 return(QuantumScale*pixel.index);
1421 if (LocaleCompare(symbol,"h") == 0)
1422 return((MagickRealType) image->rows);
1423 if (LocaleCompare(symbol,"hue") == 0)
1430 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1431 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1439 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1440 (LocaleCompare(symbol,"image.minima") == 0) ||
1441 (LocaleCompare(symbol,"image.maxima") == 0) ||
1442 (LocaleCompare(symbol,"image.mean") == 0) ||
1443 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1444 (LocaleCompare(symbol,"image.skewness") == 0) ||
1445 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1446 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1447 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1448 return(image->x_resolution);
1449 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1450 return(image->y_resolution);
1451 if (LocaleCompare(symbol,"intensity") == 0)
1452 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1453 if (LocaleCompare(symbol,"i") == 0)
1454 return((MagickRealType) x);
1460 if (LocaleCompare(symbol,"j") == 0)
1461 return((MagickRealType) y);
1467 if (LocaleCompare(symbol,"lightness") == 0)
1474 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1475 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1478 if (LocaleCompare(symbol,"luminance") == 0)
1483 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1484 return(QuantumScale*luminence);
1491 if (LocaleNCompare(symbol,"maxima",6) == 0)
1492 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1493 if (LocaleNCompare(symbol,"mean",4) == 0)
1494 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1495 if (LocaleNCompare(symbol,"minima",6) == 0)
1496 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1497 if (LocaleCompare(symbol,"m") == 0)
1498 return(QuantumScale*pixel.blue);
1504 if (LocaleCompare(symbol,"n") == 0)
1505 return((MagickRealType) GetImageListLength(fx_info->images));
1511 if (LocaleCompare(symbol,"o") == 0)
1512 return(QuantumScale*pixel.opacity);
1518 if (LocaleCompare(symbol,"page.height") == 0)
1519 return((MagickRealType) image->page.height);
1520 if (LocaleCompare(symbol,"page.width") == 0)
1521 return((MagickRealType) image->page.width);
1522 if (LocaleCompare(symbol,"page.x") == 0)
1523 return((MagickRealType) image->page.x);
1524 if (LocaleCompare(symbol,"page.y") == 0)
1525 return((MagickRealType) image->page.y);
1531 if (LocaleCompare(symbol,"resolution.x") == 0)
1532 return(image->x_resolution);
1533 if (LocaleCompare(symbol,"resolution.y") == 0)
1534 return(image->y_resolution);
1535 if (LocaleCompare(symbol,"r") == 0)
1536 return(QuantumScale*pixel.red);
1542 if (LocaleCompare(symbol,"saturation") == 0)
1549 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1550 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1553 if (LocaleNCompare(symbol,"skewness",8) == 0)
1554 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1555 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1556 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1562 if (LocaleCompare(symbol,"t") == 0)
1563 return((MagickRealType) fx_info->images->scene);
1569 if (LocaleCompare(symbol,"w") == 0)
1570 return((MagickRealType) image->columns);
1576 if (LocaleCompare(symbol,"y") == 0)
1577 return(QuantumScale*pixel.green);
1583 if (LocaleCompare(symbol,"z") == 0)
1588 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1589 fx_info->exception);
1597 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1598 if (value != (const char *) NULL)
1599 return((MagickRealType) StringToDouble(value));
1600 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1601 "UnableToParseExpression","`%s'",symbol);
1605 static const char *FxOperatorPrecedence(const char *expression,
1606 ExceptionInfo *exception)
1610 UndefinedPrecedence,
1612 BitwiseComplementPrecedence,
1617 RelationalPrecedence,
1618 EquivalencyPrecedence,
1619 BitwiseAndPrecedence,
1620 BitwiseOrPrecedence,
1621 LogicalAndPrecedence,
1622 LogicalOrPrecedence,
1624 AssignmentPrecedence,
1644 subexpression=(const char *) NULL;
1645 target=NullPrecedence;
1646 while (*expression != '\0')
1648 precedence=UndefinedPrecedence;
1649 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1654 switch (*expression)
1659 if (LocaleNCompare(expression,"atan2",5) == 0)
1669 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1670 (LocaleNCompare(expression,"j1",2) == 0))
1680 if ((c == (int) '{') || (c == (int) '['))
1683 if ((c == (int) '}') || (c == (int) ']'))
1686 switch ((unsigned char) *expression)
1691 precedence=BitwiseComplementPrecedence;
1696 precedence=ExponentPrecedence;
1701 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1702 (strchr(")",c) != (char *) NULL))) &&
1703 (((islower((int) ((char) *expression)) != 0) ||
1704 (strchr("(",(int) *expression) != (char *) NULL)) ||
1705 ((isdigit((int) ((char) c)) == 0) &&
1706 (isdigit((int) ((char) *expression)) != 0))) &&
1707 (strchr("xy",(int) *expression) == (char *) NULL))
1708 precedence=MultiplyPrecedence;
1715 precedence=MultiplyPrecedence;
1721 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1723 precedence=AdditionPrecedence;
1726 case LeftShiftOperator:
1727 case RightShiftOperator:
1729 precedence=ShiftPrecedence;
1733 case LessThanEqualOperator:
1734 case GreaterThanEqualOperator:
1737 precedence=RelationalPrecedence;
1741 case NotEqualOperator:
1743 precedence=EquivalencyPrecedence;
1748 precedence=BitwiseAndPrecedence;
1753 precedence=BitwiseOrPrecedence;
1756 case LogicalAndOperator:
1758 precedence=LogicalAndPrecedence;
1761 case LogicalOrOperator:
1763 precedence=LogicalOrPrecedence;
1769 precedence=TernaryPrecedence;
1774 precedence=AssignmentPrecedence;
1779 precedence=CommaPrecedence;
1784 precedence=SeparatorPrecedence;
1788 if ((precedence == BitwiseComplementPrecedence) ||
1789 (precedence == TernaryPrecedence) ||
1790 (precedence == AssignmentPrecedence))
1792 if (precedence > target)
1795 Right-to-left associativity.
1798 subexpression=expression;
1802 if (precedence >= target)
1805 Left-to-right associativity.
1808 subexpression=expression;
1810 if (strchr("(",(int) *expression) != (char *) NULL)
1811 expression=FxSubexpression(expression,exception);
1812 c=(int) (*expression++);
1814 return(subexpression);
1817 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
1818 const ChannelType channel,const long x,const long y,const char *expression,
1819 MagickRealType *beta,ExceptionInfo *exception)
1823 subexpression[MaxTextExtent];
1833 if (exception->severity != UndefinedException)
1835 while (isspace((int) *expression) != 0)
1837 if (*expression == '\0')
1839 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1840 "MissingExpression","`%s'",expression);
1843 p=FxOperatorPrecedence(expression,exception);
1844 if (p != (const char *) NULL)
1846 (void) CopyMagickString(subexpression,expression,(size_t)
1848 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
1850 switch ((unsigned char) *p)
1854 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1855 *beta=(MagickRealType) (~(unsigned long) *beta);
1860 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1861 return(*beta == 0.0 ? 1.0 : 0.0);
1865 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
1866 channel,x,y,++p,beta,exception));
1871 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1872 return(alpha*(*beta));
1876 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1879 if (exception->severity == UndefinedException)
1880 (void) ThrowMagickException(exception,GetMagickModule(),
1881 OptionError,"DivideByZero","`%s'",expression);
1884 return(alpha/(*beta));
1888 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1889 *beta=fabs(floor(((double) *beta)+0.5));
1892 (void) ThrowMagickException(exception,GetMagickModule(),
1893 OptionError,"DivideByZero","`%s'",expression);
1896 return(fmod((double) alpha,(double) *beta));
1900 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1901 return(alpha+(*beta));
1905 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1906 return(alpha-(*beta));
1908 case LeftShiftOperator:
1910 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1911 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) << (unsigned long)
1915 case RightShiftOperator:
1917 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1918 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) >> (unsigned long)
1924 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1925 return(alpha < *beta ? 1.0 : 0.0);
1927 case LessThanEqualOperator:
1929 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1930 return(alpha <= *beta ? 1.0 : 0.0);
1934 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1935 return(alpha > *beta ? 1.0 : 0.0);
1937 case GreaterThanEqualOperator:
1939 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1940 return(alpha >= *beta ? 1.0 : 0.0);
1944 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1945 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
1947 case NotEqualOperator:
1949 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1950 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
1954 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1955 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) & (unsigned long)
1961 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1962 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) | (unsigned long)
1966 case LogicalAndOperator:
1968 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1969 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
1972 case LogicalOrOperator:
1974 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
1975 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
1983 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
1985 p=StringToken(":",&q);
1986 if (q == (char *) NULL)
1988 (void) ThrowMagickException(exception,GetMagickModule(),
1989 OptionError,"UnableToParseExpression","`%s'",subexpression);
1992 if (fabs((double) alpha) > MagickEpsilon)
1993 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
1995 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2001 numeric[MaxTextExtent];
2004 while (isalpha((int) ((unsigned char) *q)) != 0)
2008 (void) ThrowMagickException(exception,GetMagickModule(),
2009 OptionError,"UnableToParseExpression","`%s'",subexpression);
2012 ClearMagickException(exception);
2013 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2014 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2016 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2017 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2018 subexpression),ConstantString(numeric));
2023 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2028 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2033 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2039 if (strchr("(",(int) *expression) != (char *) NULL)
2041 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2042 subexpression[strlen(subexpression)-1]='\0';
2043 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2047 switch (*expression)
2051 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2057 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2063 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2065 return((MagickRealType) (~(unsigned long) (gamma+0.5)));
2070 if (LocaleNCompare(expression,"abs",3) == 0)
2072 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2074 return((MagickRealType) fabs((double) alpha));
2076 if (LocaleNCompare(expression,"acos",4) == 0)
2078 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2080 return((MagickRealType) acos((double) alpha));
2082 if (LocaleNCompare(expression,"airy",4) == 0)
2084 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2088 return((MagickRealType) (j0((double) alpha)/alpha));
2090 if (LocaleNCompare(expression,"asin",4) == 0)
2092 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2094 return((MagickRealType) asin((double) alpha));
2096 if (LocaleNCompare(expression,"alt",3) == 0)
2098 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2100 return(((long) alpha) & 0x01 ? -1.0 : 1.0);
2102 if (LocaleNCompare(expression,"atan2",5) == 0)
2104 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2106 return((MagickRealType) atan2((double) alpha,(double) *beta));
2108 if (LocaleNCompare(expression,"atan",4) == 0)
2110 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2112 return((MagickRealType) atan((double) alpha));
2114 if (LocaleCompare(expression,"a") == 0)
2115 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2121 if (LocaleCompare(expression,"b") == 0)
2122 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2128 if (LocaleNCompare(expression,"ceil",4) == 0)
2130 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2132 return((MagickRealType) ceil((double) alpha));
2134 if (LocaleNCompare(expression,"cosh",4) == 0)
2136 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2138 return((MagickRealType) cosh((double) alpha));
2140 if (LocaleNCompare(expression,"cos",3) == 0)
2142 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2144 return((MagickRealType) cos((double) alpha));
2146 if (LocaleCompare(expression,"c") == 0)
2147 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2153 if (LocaleNCompare(expression,"debug",5) == 0)
2158 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2160 if (fx_info->images->colorspace == CMYKColorspace)
2163 case CyanChannel: type="cyan"; break;
2164 case MagentaChannel: type="magenta"; break;
2165 case YellowChannel: type="yellow"; break;
2166 case OpacityChannel: type="opacity"; break;
2167 case BlackChannel: type="black"; break;
2168 default: type="unknown"; break;
2173 case RedChannel: type="red"; break;
2174 case GreenChannel: type="green"; break;
2175 case BlueChannel: type="blue"; break;
2176 case OpacityChannel: type="opacity"; break;
2177 default: type="unknown"; break;
2179 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2180 if (strlen(subexpression) > 1)
2181 subexpression[strlen(subexpression)-1]='\0';
2182 if (fx_info->file != (FILE *) NULL)
2183 (void) fprintf(fx_info->file,"%s[%ld,%ld].%s: %s=%.*g\n",
2184 fx_info->images->filename,x,y,type,subexpression,
2185 GetMagickPrecision(),(double) alpha);
2193 if (LocaleCompare(expression,"epsilon") == 0)
2194 return((MagickRealType) MagickEpsilon);
2195 if (LocaleNCompare(expression,"exp",3) == 0)
2197 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2199 return((MagickRealType) exp((double) alpha));
2201 if (LocaleCompare(expression,"e") == 0)
2202 return((MagickRealType) 2.7182818284590452354);
2208 if (LocaleNCompare(expression,"floor",5) == 0)
2210 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2212 return((MagickRealType) floor((double) alpha));
2219 if (LocaleCompare(expression,"g") == 0)
2220 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2226 if (LocaleCompare(expression,"h") == 0)
2227 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2228 if (LocaleCompare(expression,"hue") == 0)
2229 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2230 if (LocaleNCompare(expression,"hypot",5) == 0)
2232 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2234 return((MagickRealType) hypot((double) alpha,(double) *beta));
2241 if (LocaleCompare(expression,"k") == 0)
2242 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2248 if (LocaleCompare(expression,"intensity") == 0)
2249 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2250 if (LocaleNCompare(expression,"int",3) == 0)
2252 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2254 return((MagickRealType) floor(alpha+0.5));
2256 if (LocaleCompare(expression,"i") == 0)
2257 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2263 if (LocaleCompare(expression,"j") == 0)
2264 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2265 if (LocaleNCompare(expression,"j0",2) == 0)
2267 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2269 return((MagickRealType) j0((double) alpha));
2271 if (LocaleNCompare(expression,"j1",2) == 0)
2273 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2275 return((MagickRealType) j1((double) alpha));
2277 if (LocaleNCompare(expression,"jinc",4) == 0)
2279 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2282 return((MagickRealType) (MagickPI/4.0));
2283 return((MagickRealType) j1((double) (MagickPI*alpha))/(2.0*alpha));
2290 if (LocaleNCompare(expression,"ln",2) == 0)
2292 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2294 return((MagickRealType) log((double) alpha));
2296 if (LocaleNCompare(expression,"logtwo",4) == 0)
2298 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2300 return((MagickRealType) log10((double) alpha))/log10(2.0);
2302 if (LocaleNCompare(expression,"log",3) == 0)
2304 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2306 return((MagickRealType) log10((double) alpha));
2308 if (LocaleCompare(expression,"lightness") == 0)
2309 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2315 if (LocaleCompare(expression,"MaxRGB") == 0)
2316 return((MagickRealType) QuantumRange);
2317 if (LocaleNCompare(expression,"maxima",6) == 0)
2319 if (LocaleNCompare(expression,"max",3) == 0)
2320 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2321 if (LocaleNCompare(expression,"minima",6) == 0)
2323 if (LocaleNCompare(expression,"min",3) == 0)
2324 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2325 if (LocaleNCompare(expression,"mod",3) == 0)
2327 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2329 return((MagickRealType) fmod((double) alpha,(double) *beta));
2331 if (LocaleCompare(expression,"m") == 0)
2332 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2338 if (LocaleCompare(expression,"n") == 0)
2339 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2345 if (LocaleCompare(expression,"Opaque") == 0)
2347 if (LocaleCompare(expression,"o") == 0)
2348 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2354 if (LocaleCompare(expression,"pi") == 0)
2355 return((MagickRealType) MagickPI);
2356 if (LocaleNCompare(expression,"pow",3) == 0)
2358 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2360 return((MagickRealType) pow((double) alpha,(double) *beta));
2362 if (LocaleCompare(expression,"p") == 0)
2363 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2369 if (LocaleCompare(expression,"QuantumRange") == 0)
2370 return((MagickRealType) QuantumRange);
2371 if (LocaleCompare(expression,"QuantumScale") == 0)
2372 return((MagickRealType) QuantumScale);
2378 if (LocaleNCompare(expression,"rand",4) == 0)
2379 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2380 if (LocaleNCompare(expression,"round",5) == 0)
2382 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2385 return((MagickRealType) floor((double) alpha+0.5));
2386 return((MagickRealType) ceil((double) alpha-0.5));
2388 if (LocaleCompare(expression,"r") == 0)
2389 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2395 if (LocaleCompare(expression,"saturation") == 0)
2396 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2397 if (LocaleNCompare(expression,"sign",4) == 0)
2399 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2401 return(alpha < 0.0 ? -1.0 : 1.0);
2403 if (LocaleNCompare(expression,"sinc",4) == 0)
2405 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2409 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2413 if (LocaleNCompare(expression,"sinh",4) == 0)
2415 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2417 return((MagickRealType) sinh((double) alpha));
2419 if (LocaleNCompare(expression,"sin",3) == 0)
2421 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2423 return((MagickRealType) sin((double) alpha));
2425 if (LocaleNCompare(expression,"sqrt",4) == 0)
2427 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2429 return((MagickRealType) sqrt((double) alpha));
2431 if (LocaleCompare(expression,"s") == 0)
2432 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2438 if (LocaleNCompare(expression,"tanh",4) == 0)
2440 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2442 return((MagickRealType) tanh((double) alpha));
2444 if (LocaleNCompare(expression,"tan",3) == 0)
2446 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2448 return((MagickRealType) tan((double) alpha));
2450 if (LocaleCompare(expression,"Transparent") == 0)
2452 if (LocaleCompare(expression,"t") == 0)
2453 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2459 if (LocaleCompare(expression,"u") == 0)
2460 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2466 if (LocaleCompare(expression,"v") == 0)
2467 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2473 if (LocaleCompare(expression,"w") == 0)
2474 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2480 if (LocaleCompare(expression,"y") == 0)
2481 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2487 if (LocaleCompare(expression,"z") == 0)
2488 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2494 q=(char *) expression;
2495 alpha=strtod(expression,&q);
2496 if (q == expression)
2497 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2501 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2502 MagickRealType *alpha,ExceptionInfo *exception)
2507 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2511 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2512 MagickRealType *alpha,ExceptionInfo *exception)
2521 fx_info->file=(FILE *) NULL;
2522 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2527 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2528 const ChannelType channel,const long x,const long y,MagickRealType *alpha,
2529 ExceptionInfo *exception)
2535 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2537 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2551 % FxImage() applies a mathematical expression to the specified image.
2553 % The format of the FxImage method is:
2555 % Image *FxImage(const Image *image,const char *expression,
2556 % ExceptionInfo *exception)
2557 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2558 % const char *expression,ExceptionInfo *exception)
2560 % A description of each parameter follows:
2562 % o image: the image.
2564 % o channel: the channel.
2566 % o expression: A mathematical expression.
2568 % o exception: return any errors or warnings in this structure.
2572 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2577 assert(fx_info != (FxInfo **) NULL);
2578 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
2579 if (fx_info[i] != (FxInfo *) NULL)
2580 fx_info[i]=DestroyFxInfo(fx_info[i]);
2581 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2585 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2586 ExceptionInfo *exception)
2603 number_threads=GetOpenMPMaximumThreads();
2604 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2605 if (fx_info == (FxInfo **) NULL)
2606 return((FxInfo **) NULL);
2607 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2608 if (*expression != '@')
2609 fx_expression=ConstantString(expression);
2611 fx_expression=FileToString(expression+1,~0,exception);
2612 for (i=0; i < (long) number_threads; i++)
2614 fx_info[i]=AcquireFxInfo(image,fx_expression);
2615 if (fx_info[i] == (FxInfo *) NULL)
2616 return(DestroyFxThreadSet(fx_info));
2617 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2619 fx_expression=DestroyString(fx_expression);
2623 MagickExport Image *FxImage(const Image *image,const char *expression,
2624 ExceptionInfo *exception)
2629 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2633 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2634 const char *expression,ExceptionInfo *exception)
2636 #define FxImageTag "Fx/Image"
2657 assert(image != (Image *) NULL);
2658 assert(image->signature == MagickSignature);
2659 if (image->debug != MagickFalse)
2660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2661 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2662 if (fx_image == (Image *) NULL)
2663 return((Image *) NULL);
2664 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2666 InheritException(exception,&fx_image->exception);
2667 fx_image=DestroyImage(fx_image);
2668 return((Image *) NULL);
2670 fx_info=AcquireFxThreadSet(image,expression,exception);
2671 if (fx_info == (FxInfo **) NULL)
2673 fx_image=DestroyImage(fx_image);
2674 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2676 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2677 if (status == MagickFalse)
2679 fx_image=DestroyImage(fx_image);
2680 fx_info=DestroyFxThreadSet(fx_info);
2681 return((Image *) NULL);
2688 fx_view=AcquireCacheView(fx_image);
2689 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2690 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2692 for (y=0; y < (long) fx_image->rows; y++)
2697 register IndexPacket
2698 *restrict fx_indexes;
2704 register PixelPacket
2707 if (status == MagickFalse)
2709 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2710 if (q == (PixelPacket *) NULL)
2715 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2716 id=GetOpenMPThreadId();
2718 for (x=0; x < (long) fx_image->columns; x++)
2720 if ((channel & RedChannel) != 0)
2722 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
2724 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2726 if ((channel & GreenChannel) != 0)
2728 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
2730 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2732 if ((channel & BlueChannel) != 0)
2734 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
2736 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2738 if ((channel & OpacityChannel) != 0)
2740 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
2742 if (image->matte == MagickFalse)
2743 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2745 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
2746 QuantumRange*alpha));
2748 if (((channel & IndexChannel) != 0) &&
2749 (fx_image->colorspace == CMYKColorspace))
2751 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
2753 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
2754 QuantumRange*alpha);
2758 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
2760 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2765 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2766 #pragma omp critical (MagickCore_FxImageChannel)
2768 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
2769 if (proceed == MagickFalse)
2773 fx_image->matte=fx_info[0]->matte;
2774 fx_view=DestroyCacheView(fx_view);
2775 fx_info=DestroyFxThreadSet(fx_info);
2776 if (status == MagickFalse)
2777 fx_image=DestroyImage(fx_image);
2782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2786 % I m p l o d e I m a g e %
2790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2792 % ImplodeImage() creates a new image that is a copy of an existing
2793 % one with the image pixels "implode" by the specified percentage. It
2794 % allocates the memory necessary for the new Image structure and returns a
2795 % pointer to the new image.
2797 % The format of the ImplodeImage method is:
2799 % Image *ImplodeImage(const Image *image,const double amount,
2800 % ExceptionInfo *exception)
2802 % A description of each parameter follows:
2804 % o implode_image: Method ImplodeImage returns a pointer to the image
2805 % after it is implode. A null image is returned if there is a memory
2808 % o image: the image.
2810 % o amount: Define the extent of the implosion.
2812 % o exception: return any errors or warnings in this structure.
2815 MagickExport Image *ImplodeImage(const Image *image,const double amount,
2816 ExceptionInfo *exception)
2818 #define ImplodeImageTag "Implode/Image"
2845 **restrict resample_filter;
2848 Initialize implode image attributes.
2850 assert(image != (Image *) NULL);
2851 assert(image->signature == MagickSignature);
2852 if (image->debug != MagickFalse)
2853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2854 assert(exception != (ExceptionInfo *) NULL);
2855 assert(exception->signature == MagickSignature);
2856 implode_image=CloneImage(image,0,0,MagickTrue,exception);
2857 if (implode_image == (Image *) NULL)
2858 return((Image *) NULL);
2859 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
2861 InheritException(exception,&implode_image->exception);
2862 implode_image=DestroyImage(implode_image);
2863 return((Image *) NULL);
2865 if (implode_image->background_color.opacity != OpaqueOpacity)
2866 implode_image->matte=MagickTrue;
2868 Compute scaling factor.
2872 center.x=0.5*image->columns;
2873 center.y=0.5*image->rows;
2875 if (image->columns > image->rows)
2876 scale.y=(double) image->columns/(double) image->rows;
2878 if (image->columns < image->rows)
2880 scale.x=(double) image->rows/(double) image->columns;
2888 GetMagickPixelPacket(implode_image,&zero);
2889 resample_filter=AcquireResampleFilterThreadSet(image,
2890 UndefinedVirtualPixelMethod,MagickTrue,exception);
2891 image_view=AcquireCacheView(image);
2892 implode_view=AcquireCacheView(implode_image);
2893 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2894 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2896 for (y=0; y < (long) image->rows; y++)
2907 register IndexPacket
2908 *restrict implode_indexes;
2914 register PixelPacket
2917 if (status == MagickFalse)
2919 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
2921 if (q == (PixelPacket *) NULL)
2926 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
2927 delta.y=scale.y*(double) (y-center.y);
2929 id=GetOpenMPThreadId();
2930 for (x=0; x < (long) image->columns; x++)
2933 Determine if the pixel is within an ellipse.
2935 delta.x=scale.x*(double) (x-center.x);
2936 distance=delta.x*delta.x+delta.y*delta.y;
2937 if (distance < (radius*radius))
2947 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
2948 radius/2)),-amount);
2949 (void) ResamplePixelColor(resample_filter[id],(double)
2950 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
2951 scale.y+center.y),&pixel);
2952 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
2956 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
2958 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2963 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2964 #pragma omp critical (MagickCore_ImplodeImage)
2966 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
2967 if (proceed == MagickFalse)
2971 implode_view=DestroyCacheView(implode_view);
2972 image_view=DestroyCacheView(image_view);
2973 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
2974 if (status == MagickFalse)
2975 implode_image=DestroyImage(implode_image);
2976 return(implode_image);
2980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2984 % M o r p h I m a g e s %
2988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2990 % The MorphImages() method requires a minimum of two images. The first
2991 % image is transformed into the second by a number of intervening images
2992 % as specified by frames.
2994 % The format of the MorphImage method is:
2996 % Image *MorphImages(const Image *image,const unsigned long number_frames,
2997 % ExceptionInfo *exception)
2999 % A description of each parameter follows:
3001 % o image: the image.
3003 % o number_frames: Define the number of in-between image to generate.
3004 % The more in-between frames, the smoother the morph.
3006 % o exception: return any errors or warnings in this structure.
3009 MagickExport Image *MorphImages(const Image *image,
3010 const unsigned long number_frames,ExceptionInfo *exception)
3012 #define MorphImageTag "Morph/Image"
3028 register const Image
3038 Clone first frame in sequence.
3040 assert(image != (Image *) NULL);
3041 assert(image->signature == MagickSignature);
3042 if (image->debug != MagickFalse)
3043 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3044 assert(exception != (ExceptionInfo *) NULL);
3045 assert(exception->signature == MagickSignature);
3046 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3047 if (morph_images == (Image *) NULL)
3048 return((Image *) NULL);
3049 if (GetNextImageInList(image) == (Image *) NULL)
3054 for (i=1; i < (long) number_frames; i++)
3056 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3057 if (morph_image == (Image *) NULL)
3059 morph_images=DestroyImageList(morph_images);
3060 return((Image *) NULL);
3062 AppendImageToList(&morph_images,morph_image);
3063 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3068 proceed=SetImageProgress(image,MorphImageTag,i,number_frames);
3069 if (proceed == MagickFalse)
3073 return(GetFirstImageInList(morph_images));
3076 Morph image sequence.
3081 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3083 for (i=0; i < (long) number_frames; i++)
3089 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3091 morph_image=ZoomImage(next,(unsigned long) (alpha*next->columns+beta*
3092 GetNextImageInList(next)->columns+0.5),(unsigned long) (alpha*
3093 next->rows+beta*GetNextImageInList(next)->rows+0.5),exception);
3094 if (morph_image == (Image *) NULL)
3096 morph_images=DestroyImageList(morph_images);
3097 return((Image *) NULL);
3099 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3101 InheritException(exception,&morph_image->exception);
3102 morph_image=DestroyImage(morph_image);
3103 return((Image *) NULL);
3105 AppendImageToList(&morph_images,morph_image);
3106 morph_images=GetLastImageInList(morph_images);
3107 morph_image=ZoomImage(GetNextImageInList(next),morph_images->columns,
3108 morph_images->rows,exception);
3109 if (morph_image == (Image *) NULL)
3111 morph_images=DestroyImageList(morph_images);
3112 return((Image *) NULL);
3114 image_view=AcquireCacheView(morph_image);
3115 morph_view=AcquireCacheView(morph_images);
3116 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3117 #pragma omp parallel for schedule(dynamic,4) shared(status)
3119 for (y=0; y < (long) morph_images->rows; y++)
3124 register const PixelPacket
3130 register PixelPacket
3133 if (status == MagickFalse)
3135 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3137 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3139 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3144 for (x=0; x < (long) morph_images->columns; x++)
3146 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3147 q->green=ClampToQuantum(alpha*q->green+beta*
3148 GetGreenPixelComponent(p));
3149 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3150 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3151 GetOpacityPixelComponent(p));
3155 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3156 if (sync == MagickFalse)
3159 morph_view=DestroyCacheView(morph_view);
3160 image_view=DestroyCacheView(image_view);
3161 morph_image=DestroyImage(morph_image);
3163 if (i < (long) number_frames)
3166 Clone last frame in sequence.
3168 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3169 if (morph_image == (Image *) NULL)
3171 morph_images=DestroyImageList(morph_images);
3172 return((Image *) NULL);
3174 AppendImageToList(&morph_images,morph_image);
3175 morph_images=GetLastImageInList(morph_images);
3176 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3181 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3182 #pragma omp critical (MagickCore_MorphImages)
3184 proceed=SetImageProgress(image,MorphImageTag,scene,
3185 GetImageListLength(image));
3186 if (proceed == MagickFalse)
3191 if (GetNextImageInList(next) != (Image *) NULL)
3193 morph_images=DestroyImageList(morph_images);
3194 return((Image *) NULL);
3196 return(GetFirstImageInList(morph_images));
3200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3204 % P l a s m a I m a g e %
3208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3210 % PlasmaImage() initializes an image with plasma fractal values. The image
3211 % must be initialized with a base color and the random number generator
3212 % seeded before this method is called.
3214 % The format of the PlasmaImage method is:
3216 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3217 % unsigned long attenuate,unsigned long depth)
3219 % A description of each parameter follows:
3221 % o image: the image.
3223 % o segment: Define the region to apply plasma fractals values.
3225 % o attenuate: Define the plasmattenuation factor.
3227 % o depth: Limit the plasma recursion depth.
3231 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3232 const MagickRealType pixel,const MagickRealType noise)
3237 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3242 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3243 RandomInfo *random_info,const SegmentInfo *segment,unsigned long attenuate,
3244 unsigned long depth)
3262 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3270 Divide the area into quadrants and recurse.
3274 x_mid=(long) (segment->x1+segment->x2+0.5)/2;
3275 y_mid=(long) (segment->y1+segment->y2+0.5)/2;
3276 local_info=(*segment);
3277 local_info.x2=(double) x_mid;
3278 local_info.y2=(double) y_mid;
3279 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3280 local_info=(*segment);
3281 local_info.y1=(double) y_mid;
3282 local_info.x2=(double) x_mid;
3283 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3284 local_info=(*segment);
3285 local_info.x1=(double) x_mid;
3286 local_info.y2=(double) y_mid;
3287 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3288 local_info=(*segment);
3289 local_info.x1=(double) x_mid;
3290 local_info.y1=(double) y_mid;
3291 return(PlasmaImageProxy(image,random_info,&local_info,attenuate,depth));
3293 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3294 return(MagickFalse);
3295 x_mid=(long) (segment->x1+segment->x2+0.5)/2;
3296 y_mid=(long) (segment->y1+segment->y2+0.5)/2;
3297 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3298 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3299 return(MagickFalse);
3301 Average pixels and apply plasma.
3303 exception=(&image->exception);
3304 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3305 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3307 register PixelPacket
3313 x=(long) (segment->x1+0.5);
3314 (void) GetOneVirtualPixel(image,x,(long) (segment->y1+0.5),&u,exception);
3315 (void) GetOneVirtualPixel(image,x,(long) (segment->y2+0.5),&v,exception);
3316 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3317 if (q == (PixelPacket *) NULL)
3319 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3321 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3323 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3325 (void) SyncAuthenticPixels(image,exception);
3326 if (segment->x1 != segment->x2)
3331 x=(long) (segment->x2+0.5);
3332 (void) GetOneVirtualPixel(image,x,(long) (segment->y1+0.5),&u,
3334 (void) GetOneVirtualPixel(image,x,(long) (segment->y2+0.5),&v,
3336 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3337 if (q == (PixelPacket *) NULL)
3339 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3341 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3343 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3345 (void) SyncAuthenticPixels(image,exception);
3348 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3350 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3352 register PixelPacket
3358 y=(long) (segment->y2+0.5);
3359 (void) GetOneVirtualPixel(image,(long) (segment->x1+0.5),y,&u,
3361 (void) GetOneVirtualPixel(image,(long) (segment->x2+0.5),y,&v,
3363 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3364 if (q == (PixelPacket *) NULL)
3366 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3368 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3370 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3372 (void) SyncAuthenticPixels(image,exception);
3374 if (segment->y1 != segment->y2)
3376 register PixelPacket
3382 y=(long) (segment->y1+0.5);
3383 (void) GetOneVirtualPixel(image,(long) (segment->x1+0.5),y,&u,
3385 (void) GetOneVirtualPixel(image,(long) (segment->x2+0.5),y,&v,
3387 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3388 if (q == (PixelPacket *) NULL)
3390 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3392 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3394 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3396 (void) SyncAuthenticPixels(image,exception);
3399 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3401 register PixelPacket
3407 x=(long) (segment->x1+0.5);
3408 y=(long) (segment->y1+0.5);
3409 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3410 x=(long) (segment->x2+0.5);
3411 y=(long) (segment->y2+0.5);
3412 (void) GetOneVirtualPixel(image,x,y,&v,exception);
3413 q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception);
3414 if (q == (PixelPacket *) NULL)
3416 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3418 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3420 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3422 (void) SyncAuthenticPixels(image,exception);
3424 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3426 return(MagickFalse);
3429 MagickExport MagickBooleanType PlasmaImage(Image *image,
3430 const SegmentInfo *segment,unsigned long attenuate,unsigned long depth)
3438 if (image->debug != MagickFalse)
3439 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3440 assert(image != (Image *) NULL);
3441 assert(image->signature == MagickSignature);
3442 if (image->debug != MagickFalse)
3443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3444 random_info=AcquireRandomInfo();
3445 status=PlasmaImageProxy(image,random_info,segment,attenuate,depth);
3446 random_info=DestroyRandomInfo(random_info);
3451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3455 % P o l a r o i d I m a g e %
3459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3461 % PolaroidImage() simulates a Polaroid picture.
3463 % The format of the AnnotateImage method is:
3465 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3466 % const double angle,ExceptionInfo exception)
3468 % A description of each parameter follows:
3470 % o image: the image.
3472 % o draw_info: the draw info.
3474 % o angle: Apply the effect along this angle.
3476 % o exception: return any errors or warnings in this structure.
3479 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3480 const double angle,ExceptionInfo *exception)
3501 Simulate a Polaroid picture.
3503 assert(image != (Image *) NULL);
3504 assert(image->signature == MagickSignature);
3505 if (image->debug != MagickFalse)
3506 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3507 assert(exception != (ExceptionInfo *) NULL);
3508 assert(exception->signature == MagickSignature);
3509 quantum=(long) MagickMax(MagickMax((double) image->columns,(double)
3510 image->rows)/25.0,10.0);
3511 height=image->rows+2*quantum;
3512 caption_image=(Image *) NULL;
3513 value=GetImageProperty(image,"Caption");
3514 if (value != (const char *) NULL)
3518 geometry[MaxTextExtent];
3533 Generate caption image.
3535 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3536 if (caption_image == (Image *) NULL)
3537 return((Image *) NULL);
3538 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3539 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3541 (void) CloneString(&annotate_info->text,caption);
3542 count=FormatMagickCaption(caption_image,annotate_info,&metrics,&caption);
3543 status=SetImageExtent(caption_image,image->columns,(unsigned long)
3544 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3545 if (status == MagickFalse)
3546 caption_image=DestroyImage(caption_image);
3549 caption_image->background_color=image->border_color;
3550 (void) SetImageBackgroundColor(caption_image);
3551 (void) CloneString(&annotate_info->text,caption);
3552 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3554 if (annotate_info->gravity == UndefinedGravity)
3555 (void) CloneString(&annotate_info->geometry,AcquireString(
3557 (void) AnnotateImage(caption_image,annotate_info);
3558 height+=caption_image->rows;
3560 annotate_info=DestroyDrawInfo(annotate_info);
3561 caption=DestroyString(caption);
3563 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3565 if (picture_image == (Image *) NULL)
3567 if (caption_image != (Image *) NULL)
3568 caption_image=DestroyImage(caption_image);
3569 return((Image *) NULL);
3571 picture_image->background_color=image->border_color;
3572 (void) SetImageBackgroundColor(picture_image);
3573 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3574 if (caption_image != (Image *) NULL)
3576 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3577 quantum,(long) (image->rows+3*quantum/2));
3578 caption_image=DestroyImage(caption_image);
3580 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3581 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3582 rotate_image=RotateImage(picture_image,90.0,exception);
3583 picture_image=DestroyImage(picture_image);
3584 if (rotate_image == (Image *) NULL)
3585 return((Image *) NULL);
3586 picture_image=rotate_image;
3587 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3588 picture_image->columns,exception);
3589 picture_image=DestroyImage(picture_image);
3590 if (bend_image == (Image *) NULL)
3591 return((Image *) NULL);
3592 InheritException(&bend_image->exception,exception);
3593 picture_image=bend_image;
3594 rotate_image=RotateImage(picture_image,-90.0,exception);
3595 picture_image=DestroyImage(picture_image);
3596 if (rotate_image == (Image *) NULL)
3597 return((Image *) NULL);
3598 picture_image=rotate_image;
3599 picture_image->background_color=image->background_color;
3600 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3602 if (polaroid_image == (Image *) NULL)
3604 picture_image=DestroyImage(picture_image);
3605 return(picture_image);
3607 flop_image=FlopImage(polaroid_image,exception);
3608 polaroid_image=DestroyImage(polaroid_image);
3609 if (flop_image == (Image *) NULL)
3611 picture_image=DestroyImage(picture_image);
3612 return(picture_image);
3614 polaroid_image=flop_image;
3615 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3616 (long) (-0.01*picture_image->columns/2.0),0L);
3617 picture_image=DestroyImage(picture_image);
3618 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3619 rotate_image=RotateImage(polaroid_image,angle,exception);
3620 polaroid_image=DestroyImage(polaroid_image);
3621 if (rotate_image == (Image *) NULL)
3622 return((Image *) NULL);
3623 polaroid_image=rotate_image;
3624 trim_image=TrimImage(polaroid_image,exception);
3625 polaroid_image=DestroyImage(polaroid_image);
3626 if (trim_image == (Image *) NULL)
3627 return((Image *) NULL);
3628 polaroid_image=trim_image;
3629 return(polaroid_image);
3633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3637 % R e c o l o r I m a g e %
3641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3643 % RecolorImage() translate, scale, shear, or rotate image colors. Although
3644 % you can use variable sized matrices, typically you use a 5 x 5 for an RGBA
3645 % image and a 6x6 for CMYKA. Populate the last row with normalized values to
3648 % The format of the RecolorImage method is:
3650 % Image *RecolorImage(const Image *image,const unsigned long order,
3651 % const double *color_matrix,ExceptionInfo *exception)
3653 % A description of each parameter follows:
3655 % o image: the image.
3657 % o order: the number of columns and rows in the recolor matrix.
3659 % o color_matrix: An array of double representing the recolor matrix.
3661 % o exception: return any errors or warnings in this structure.
3664 MagickExport Image *RecolorImage(const Image *image,const unsigned long order,
3665 const double *color_matrix,ExceptionInfo *exception)
3667 #define RecolorImageTag "Recolor/Image"
3684 Initialize image attributes.
3686 assert(image != (Image *) NULL);
3687 assert(image->signature == MagickSignature);
3688 if (image->debug != MagickFalse)
3689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3690 assert(exception != (ExceptionInfo *) NULL);
3691 assert(exception->signature == MagickSignature);
3692 recolor_image=CloneImage(image,0,0,MagickTrue,exception);
3693 if (recolor_image == (Image *) NULL)
3694 return((Image *) NULL);
3695 if (SetImageStorageClass(recolor_image,DirectClass) == MagickFalse)
3697 InheritException(exception,&recolor_image->exception);
3698 recolor_image=DestroyImage(recolor_image);
3699 return((Image *) NULL);
3701 if (image->debug != MagickFalse)
3704 format[MaxTextExtent],
3711 register const double
3714 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
3715 " Recolor image with %ldx%ld color matrix:",order,order);
3716 message=AcquireString("");
3718 for (v=0; v < (long) order; v++)
3721 (void) FormatMagickString(format,MaxTextExtent,"%ld: ",v);
3722 (void) ConcatenateString(&message,format);
3723 for (u=0; u < (long) order; u++)
3725 (void) FormatMagickString(format,MaxTextExtent,"%+f ",*k++);
3726 (void) ConcatenateString(&message,format);
3728 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
3730 message=DestroyString(message);
3737 image_view=AcquireCacheView(image);
3738 recolor_view=AcquireCacheView(recolor_image);
3739 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3740 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3742 for (y=0; y < (long) image->rows; y++)
3744 register const double
3747 register const IndexPacket
3750 register const PixelPacket
3756 register IndexPacket
3757 *restrict recolor_indexes;
3759 register PixelPacket
3762 if (status == MagickFalse)
3764 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3765 q=GetCacheViewAuthenticPixels(recolor_view,0,y,recolor_image->columns,1,
3767 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3772 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3773 recolor_indexes=GetCacheViewAuthenticIndexQueue(recolor_view);
3781 for (x=0; x < (long) image->columns; x++)
3783 q->red=ClampToQuantum(k[0]*GetRedPixelComponent(p));
3791 for (x=0; x < (long) image->columns; x++)
3793 q->red=ClampToQuantum(k[0]*p->red+k[1]*GetGreenPixelComponent(p));
3794 q->green=ClampToQuantum(k[2]*p->red+k[3]*GetGreenPixelComponent(p));
3802 for (x=0; x < (long) image->columns; x++)
3804 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*GetBluePixelComponent(p));
3805 q->green=ClampToQuantum(k[3]*p->red+k[4]*p->green+k[5]*GetBluePixelComponent(p));
3806 q->blue=ClampToQuantum(k[6]*p->red+k[7]*p->green+k[8]*GetBluePixelComponent(p));
3814 for (x=0; x < (long) image->columns; x++)
3816 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*p->blue+
3817 k[12]*QuantumRange);
3818 q->green=ClampToQuantum(k[4]*p->red+k[5]*p->green+k[6]*p->blue+
3819 k[13]*QuantumRange);
3820 q->blue=ClampToQuantum(k[8]*p->red+k[9]*p->green+k[10]*p->blue+
3821 k[14]*QuantumRange);
3829 for (x=0; x < (long) image->columns; x++)
3831 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*p->blue+
3832 k[3]*(GetAlphaPixelComponent(p))+k[20]*QuantumRange);
3833 q->green=ClampToQuantum(k[5]*p->red+k[6]*p->green+k[7]*p->blue+
3834 k[8]*(GetAlphaPixelComponent(p))+k[21]*QuantumRange);
3835 q->blue=ClampToQuantum(k[10]*p->red+k[11]*p->green+k[12]*p->blue+
3836 k[13]*(GetAlphaPixelComponent(p))+k[22]*QuantumRange);
3837 if (image->matte != MagickFalse)
3838 q->opacity=ClampToQuantum((MagickRealType) QuantumRange-(k[15]*
3839 p->red+k[16]*p->green+k[17]*p->blue+k[18]*
3840 GetAlphaPixelComponent(p)+k[23]*QuantumRange));
3848 for (x=0; x < (long) image->columns; x++)
3850 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*p->blue+
3851 k[3]*indexes[x]+k[4]*((Quantum) GetAlphaPixelComponent(p))+
3852 k[30]*QuantumRange);
3853 q->green=ClampToQuantum(k[6]*p->red+k[7]*p->green+k[8]*p->blue+
3854 k[9]*indexes[x]+k[10]*((Quantum) GetAlphaPixelComponent(p))+
3855 k[31]*QuantumRange);
3856 q->blue=ClampToQuantum(k[12]*p->red+k[13]*p->green+k[14]*p->blue+
3857 k[15]*indexes[x]+k[16]*((Quantum) GetAlphaPixelComponent(p))+
3858 k[32]*QuantumRange);
3859 if (image->matte != MagickFalse)
3860 q->opacity=ClampToQuantum((MagickRealType) QuantumRange-(k[24]*
3861 p->red+k[25]*p->green+k[26]*p->blue+k[27]*indexes[x]+
3862 k[28]*(GetAlphaPixelComponent(p))+k[34]*QuantumRange));
3863 if (image->colorspace == CMYKColorspace)
3864 recolor_indexes[x]=ClampToQuantum(k[18]*p->red+k[19]*p->green+k[20]*
3865 p->blue+k[21]*indexes[x]+k[22]*((Quantum) QuantumRange-
3866 GetOpacityPixelComponent(p))+k[33]*QuantumRange);
3873 if (SyncCacheViewAuthenticPixels(recolor_view,exception) == MagickFalse)
3875 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3880 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3881 #pragma omp critical (MagickCore_RecolorImage)
3883 proceed=SetImageProgress(image,RecolorImageTag,progress++,image->rows);
3884 if (proceed == MagickFalse)
3888 recolor_view=DestroyCacheView(recolor_view);
3889 image_view=DestroyCacheView(image_view);
3890 if (status == MagickFalse)
3891 recolor_image=DestroyImage(recolor_image);
3892 return(recolor_image);
3896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3900 % S e p i a T o n e I m a g e %
3904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3906 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3907 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3908 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3909 % threshold of 80% is a good starting point for a reasonable tone.
3911 % The format of the SepiaToneImage method is:
3913 % Image *SepiaToneImage(const Image *image,const double threshold,
3914 % ExceptionInfo *exception)
3916 % A description of each parameter follows:
3918 % o image: the image.
3920 % o threshold: the tone threshold.
3922 % o exception: return any errors or warnings in this structure.
3925 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3926 ExceptionInfo *exception)
3928 #define SepiaToneImageTag "SepiaTone/Image"
3945 Initialize sepia-toned image attributes.
3947 assert(image != (const Image *) NULL);
3948 assert(image->signature == MagickSignature);
3949 if (image->debug != MagickFalse)
3950 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3951 assert(exception != (ExceptionInfo *) NULL);
3952 assert(exception->signature == MagickSignature);
3953 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3954 if (sepia_image == (Image *) NULL)
3955 return((Image *) NULL);
3956 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3958 InheritException(exception,&sepia_image->exception);
3959 sepia_image=DestroyImage(sepia_image);
3960 return((Image *) NULL);
3963 Tone each row of the image.
3967 image_view=AcquireCacheView(image);
3968 sepia_view=AcquireCacheView(sepia_image);
3969 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3970 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3972 for (y=0; y < (long) image->rows; y++)
3974 register const PixelPacket
3980 register PixelPacket
3983 if (status == MagickFalse)
3985 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3986 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
3988 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3993 for (x=0; x < (long) image->columns; x++)
3999 intensity=(MagickRealType) PixelIntensityToQuantum(p);
4000 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4001 (MagickRealType) QuantumRange-threshold;
4002 q->red=ClampToQuantum(tone);
4003 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4004 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4005 q->green=ClampToQuantum(tone);
4006 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4007 q->blue=ClampToQuantum(tone);
4009 if ((MagickRealType) q->green < tone)
4010 q->green=ClampToQuantum(tone);
4011 if ((MagickRealType) q->blue < tone)
4012 q->blue=ClampToQuantum(tone);
4016 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4018 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4023 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4024 #pragma omp critical (MagickCore_SepiaToneImage)
4026 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4028 if (proceed == MagickFalse)
4032 sepia_view=DestroyCacheView(sepia_view);
4033 image_view=DestroyCacheView(image_view);
4034 (void) NormalizeImage(sepia_image);
4035 (void) ContrastImage(sepia_image,MagickTrue);
4036 if (status == MagickFalse)
4037 sepia_image=DestroyImage(sepia_image);
4038 return(sepia_image);
4042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4046 % S h a d o w I m a g e %
4050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4052 % ShadowImage() simulates a shadow from the specified image and returns it.
4054 % The format of the ShadowImage method is:
4056 % Image *ShadowImage(const Image *image,const double opacity,
4057 % const double sigma,const long x_offset,const long y_offset,
4058 % ExceptionInfo *exception)
4060 % A description of each parameter follows:
4062 % o image: the image.
4064 % o opacity: percentage transparency.
4066 % o sigma: the standard deviation of the Gaussian, in pixels.
4068 % o x_offset: the shadow x-offset.
4070 % o y_offset: the shadow y-offset.
4072 % o exception: return any errors or warnings in this structure.
4075 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4076 const double sigma,const long x_offset,const long y_offset,
4077 ExceptionInfo *exception)
4079 #define ShadowImageTag "Shadow/Image"
4099 assert(image != (Image *) NULL);
4100 assert(image->signature == MagickSignature);
4101 if (image->debug != MagickFalse)
4102 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4103 assert(exception != (ExceptionInfo *) NULL);
4104 assert(exception->signature == MagickSignature);
4105 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4106 if (clone_image == (Image *) NULL)
4107 return((Image *) NULL);
4108 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4109 clone_image->compose=OverCompositeOp;
4110 border_info.width=(unsigned long) (2.0*sigma+0.5);
4111 border_info.height=(unsigned long) (2.0*sigma+0.5);
4114 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4115 border_image=BorderImage(clone_image,&border_info,exception);
4116 clone_image=DestroyImage(clone_image);
4117 if (border_image == (Image *) NULL)
4118 return((Image *) NULL);
4119 if (border_image->matte == MagickFalse)
4120 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4126 image_view=AcquireCacheView(border_image);
4127 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4128 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4130 for (y=0; y < (long) border_image->rows; y++)
4135 register PixelPacket
4138 if (status == MagickFalse)
4140 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4142 if (q == (PixelPacket *) NULL)
4147 for (x=0; x < (long) border_image->columns; x++)
4149 q->red=border_image->background_color.red;
4150 q->green=border_image->background_color.green;
4151 q->blue=border_image->background_color.blue;
4152 if (border_image->matte == MagickFalse)
4153 q->opacity=border_image->background_color.opacity;
4155 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4156 GetAlphaPixelComponent(q)*opacity/100.0));
4159 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4161 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4166 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4167 #pragma omp critical (MagickCore_ShadowImage)
4169 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4170 border_image->rows);
4171 if (proceed == MagickFalse)
4175 image_view=DestroyCacheView(image_view);
4176 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4177 border_image=DestroyImage(border_image);
4178 if (shadow_image == (Image *) NULL)
4179 return((Image *) NULL);
4180 if (shadow_image->page.width == 0)
4181 shadow_image->page.width=shadow_image->columns;
4182 if (shadow_image->page.height == 0)
4183 shadow_image->page.height=shadow_image->rows;
4184 shadow_image->page.width+=x_offset-(long) border_info.width;
4185 shadow_image->page.height+=y_offset-(long) border_info.height;
4186 shadow_image->page.x+=x_offset-(long) border_info.width;
4187 shadow_image->page.y+=y_offset-(long) border_info.height;
4188 return(shadow_image);
4192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4196 % S k e t c h I m a g e %
4200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4202 % SketchImage() simulates a pencil sketch. We convolve the image with a
4203 % Gaussian operator of the given radius and standard deviation (sigma). For
4204 % reasonable results, radius should be larger than sigma. Use a radius of 0
4205 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4208 % The format of the SketchImage method is:
4210 % Image *SketchImage(const Image *image,const double radius,
4211 % const double sigma,const double angle,ExceptionInfo *exception)
4213 % A description of each parameter follows:
4215 % o image: the image.
4217 % o radius: the radius of the Gaussian, in pixels, not counting
4220 % o sigma: the standard deviation of the Gaussian, in pixels.
4222 % o angle: Apply the effect along this angle.
4224 % o exception: return any errors or warnings in this structure.
4227 MagickExport Image *SketchImage(const Image *image,const double radius,
4228 const double sigma,const double angle,ExceptionInfo *exception)
4250 **restrict random_info;
4255 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4256 MagickTrue,exception);
4257 if (random_image == (Image *) NULL)
4258 return((Image *) NULL);
4260 GetMagickPixelPacket(random_image,&zero);
4261 random_info=AcquireRandomInfoThreadSet();
4262 random_view=AcquireCacheView(random_image);
4263 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4264 #pragma omp parallel for schedule(dynamic,4) shared(status)
4266 for (y=0; y < (long) random_image->rows; y++)
4271 register IndexPacket
4278 register PixelPacket
4281 if (status == MagickFalse)
4283 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4285 if (q == (PixelPacket *) NULL)
4290 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4292 id=GetOpenMPThreadId();
4293 for (x=0; x < (long) random_image->columns; x++)
4295 pixel.red=(MagickRealType) (QuantumRange*
4296 GetPseudoRandomValue(random_info[id]));
4297 pixel.green=pixel.red;
4298 pixel.blue=pixel.red;
4299 if (image->colorspace == CMYKColorspace)
4300 pixel.index=pixel.red;
4301 SetPixelPacket(random_image,&pixel,q,indexes+x);
4304 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4307 random_view=DestroyCacheView(random_view);
4308 random_info=DestroyRandomInfoThreadSet(random_info);
4309 if (status == MagickFalse)
4311 random_image=DestroyImage(random_image);
4312 return(random_image);
4314 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4315 random_image=DestroyImage(random_image);
4316 if (blur_image == (Image *) NULL)
4317 return((Image *) NULL);
4318 dodge_image=EdgeImage(blur_image,radius,exception);
4319 blur_image=DestroyImage(blur_image);
4320 if (dodge_image == (Image *) NULL)
4321 return((Image *) NULL);
4322 (void) NormalizeImage(dodge_image);
4323 (void) NegateImage(dodge_image,MagickFalse);
4324 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4325 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4326 if (sketch_image == (Image *) NULL)
4328 dodge_image=DestroyImage(dodge_image);
4329 return((Image *) NULL);
4331 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4332 dodge_image=DestroyImage(dodge_image);
4333 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4334 if (blend_image == (Image *) NULL)
4336 sketch_image=DestroyImage(sketch_image);
4337 return((Image *) NULL);
4339 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4340 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4341 blend_image=DestroyImage(blend_image);
4342 return(sketch_image);
4346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4350 % S o l a r i z e I m a g e %
4354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4356 % SolarizeImage() applies a special effect to the image, similar to the effect
4357 % achieved in a photo darkroom by selectively exposing areas of photo
4358 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4359 % measure of the extent of the solarization.
4361 % The format of the SolarizeImage method is:
4363 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4365 % A description of each parameter follows:
4367 % o image: the image.
4369 % o threshold: Define the extent of the solarization.
4372 MagickExport MagickBooleanType SolarizeImage(Image *image,
4373 const double threshold)
4375 #define SolarizeImageTag "Solarize/Image"
4390 assert(image != (Image *) NULL);
4391 assert(image->signature == MagickSignature);
4392 if (image->debug != MagickFalse)
4393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4394 if (image->storage_class == PseudoClass)
4402 for (i=0; i < (long) image->colors; i++)
4404 if ((MagickRealType) image->colormap[i].red > threshold)
4405 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4406 if ((MagickRealType) image->colormap[i].green > threshold)
4407 image->colormap[i].green=(Quantum) QuantumRange-
4408 image->colormap[i].green;
4409 if ((MagickRealType) image->colormap[i].blue > threshold)
4410 image->colormap[i].blue=(Quantum) QuantumRange-
4411 image->colormap[i].blue;
4419 exception=(&image->exception);
4420 image_view=AcquireCacheView(image);
4421 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4422 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4424 for (y=0; y < (long) image->rows; y++)
4429 register PixelPacket
4432 if (status == MagickFalse)
4434 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4436 if (q == (PixelPacket *) NULL)
4441 for (x=0; x < (long) image->columns; x++)
4443 if ((MagickRealType) q->red > threshold)
4444 q->red=(Quantum) QuantumRange-q->red;
4445 if ((MagickRealType) q->green > threshold)
4446 q->green=(Quantum) QuantumRange-q->green;
4447 if ((MagickRealType) q->blue > threshold)
4448 q->blue=(Quantum) QuantumRange-q->blue;
4451 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4453 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4458 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4459 #pragma omp critical (MagickCore_SolarizeImage)
4461 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4462 if (proceed == MagickFalse)
4466 image_view=DestroyCacheView(image_view);
4471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4475 % S t e g a n o I m a g e %
4479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4481 % SteganoImage() hides a digital watermark within the image. Recover
4482 % the hidden watermark later to prove that the authenticity of an image.
4483 % Offset defines the start position within the image to hide the watermark.
4485 % The format of the SteganoImage method is:
4487 % Image *SteganoImage(const Image *image,Image *watermark,
4488 % ExceptionInfo *exception)
4490 % A description of each parameter follows:
4492 % o image: the image.
4494 % o watermark: the watermark image.
4496 % o exception: return any errors or warnings in this structure.
4499 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4500 ExceptionInfo *exception)
4502 #define GetBit(alpha,i) ((((unsigned long) (alpha) >> (unsigned long) \
4504 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) ? (unsigned long) (alpha) \
4505 | (1UL << (unsigned long) (i)) : (unsigned long) (alpha) & \
4506 ~(1UL << (unsigned long) (i)))
4507 #define SteganoImageTag "Stegano/Image"
4530 register PixelPacket
4537 Initialize steganographic image attributes.
4539 assert(image != (const Image *) NULL);
4540 assert(image->signature == MagickSignature);
4541 if (image->debug != MagickFalse)
4542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4543 assert(watermark != (const Image *) NULL);
4544 assert(watermark->signature == MagickSignature);
4545 assert(exception != (ExceptionInfo *) NULL);
4546 assert(exception->signature == MagickSignature);
4547 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4548 if (stegano_image == (Image *) NULL)
4549 return((Image *) NULL);
4550 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4552 InheritException(exception,&stegano_image->exception);
4553 stegano_image=DestroyImage(stegano_image);
4554 return((Image *) NULL);
4556 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4558 Hide watermark in low-order bits of image.
4563 depth=stegano_image->depth;
4565 for (i=(long) depth-1; (i >= 0) && (j < (long) depth); i--)
4567 for (y=0; (y < (long) watermark->rows) && (j < (long) depth); y++)
4569 for (x=0; (x < (long) watermark->columns) && (j < (long) depth); x++)
4571 (void) GetOneVirtualPixel(watermark,x,y,&pixel,exception);
4572 if ((k/(long) stegano_image->columns) >= (long) stegano_image->rows)
4574 q=GetAuthenticPixels(stegano_image,k % (long) stegano_image->columns,
4575 k/(long) stegano_image->columns,1,1,exception);
4576 if (q == (PixelPacket *) NULL)
4582 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4587 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4592 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4596 if (SyncAuthenticPixels(stegano_image,exception) == MagickFalse)
4602 if (k == (long) (stegano_image->columns*stegano_image->columns))
4604 if (k == image->offset)
4608 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4613 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4615 if (proceed == MagickFalse)
4619 if (stegano_image->storage_class == PseudoClass)
4620 (void) SyncImage(stegano_image);
4621 return(stegano_image);
4625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4629 % S t e r e o A n a g l y p h I m a g e %
4633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4635 % StereoAnaglyphImage() combines two images and produces a single image that
4636 % is the composite of a left and right image of a stereo pair. Special
4637 % red-green stereo glasses are required to view this effect.
4639 % The format of the StereoAnaglyphImage method is:
4641 % Image *StereoImage(const Image *left_image,const Image *right_image,
4642 % ExceptionInfo *exception)
4643 % Image *StereoAnaglyphImage(const Image *left_image,
4644 % const Image *right_image,const long x_offset,const long y_offset,
4645 % ExceptionInfo *exception)
4647 % A description of each parameter follows:
4649 % o left_image: the left image.
4651 % o right_image: the right image.
4653 % o exception: return any errors or warnings in this structure.
4655 % o x_offset: amount, in pixels, by which the left image is offset to the
4656 % right of the right image.
4658 % o y_offset: amount, in pixels, by which the left image is offset to the
4659 % bottom of the right image.
4663 MagickExport Image *StereoImage(const Image *left_image,
4664 const Image *right_image,ExceptionInfo *exception)
4666 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4669 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4670 const Image *right_image,const long x_offset,const long y_offset,
4671 ExceptionInfo *exception)
4673 #define StereoImageTag "Stereo/Image"
4687 assert(left_image != (const Image *) NULL);
4688 assert(left_image->signature == MagickSignature);
4689 if (left_image->debug != MagickFalse)
4690 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4691 left_image->filename);
4692 assert(right_image != (const Image *) NULL);
4693 assert(right_image->signature == MagickSignature);
4694 assert(exception != (ExceptionInfo *) NULL);
4695 assert(exception->signature == MagickSignature);
4696 assert(right_image != (const Image *) NULL);
4698 if ((left_image->columns != right_image->columns) ||
4699 (left_image->rows != right_image->rows))
4700 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4702 Initialize stereo image attributes.
4704 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4705 MagickTrue,exception);
4706 if (stereo_image == (Image *) NULL)
4707 return((Image *) NULL);
4708 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4710 InheritException(exception,&stereo_image->exception);
4711 stereo_image=DestroyImage(stereo_image);
4712 return((Image *) NULL);
4715 Copy left image to red channel and right image to blue channel.
4717 for (y=0; y < (long) stereo_image->rows; y++)
4719 register const PixelPacket
4726 register PixelPacket
4729 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4731 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4732 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4733 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4734 (r == (PixelPacket *) NULL))
4736 for (x=0; x < (long) stereo_image->columns; x++)
4738 r->red=GetRedPixelComponent(p);
4741 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4746 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4748 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4753 proceed=SetImageProgress(image,StereoImageTag,y,stereo_image->rows);
4754 if (proceed == MagickFalse)
4758 return(stereo_image);
4762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4766 % S w i r l I m a g e %
4770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4772 % SwirlImage() swirls the pixels about the center of the image, where
4773 % degrees indicates the sweep of the arc through which each pixel is moved.
4774 % You get a more dramatic effect as the degrees move from 1 to 360.
4776 % The format of the SwirlImage method is:
4778 % Image *SwirlImage(const Image *image,double degrees,
4779 % ExceptionInfo *exception)
4781 % A description of each parameter follows:
4783 % o image: the image.
4785 % o degrees: Define the tightness of the swirling effect.
4787 % o exception: return any errors or warnings in this structure.
4790 MagickExport Image *SwirlImage(const Image *image,double degrees,
4791 ExceptionInfo *exception)
4793 #define SwirlImageTag "Swirl/Image"
4820 **restrict resample_filter;
4823 Initialize swirl image attributes.
4825 assert(image != (const Image *) NULL);
4826 assert(image->signature == MagickSignature);
4827 if (image->debug != MagickFalse)
4828 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4829 assert(exception != (ExceptionInfo *) NULL);
4830 assert(exception->signature == MagickSignature);
4831 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4832 if (swirl_image == (Image *) NULL)
4833 return((Image *) NULL);
4834 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4836 InheritException(exception,&swirl_image->exception);
4837 swirl_image=DestroyImage(swirl_image);
4838 return((Image *) NULL);
4840 if (swirl_image->background_color.opacity != OpaqueOpacity)
4841 swirl_image->matte=MagickTrue;
4843 Compute scaling factor.
4845 center.x=(double) image->columns/2.0;
4846 center.y=(double) image->rows/2.0;
4847 radius=MagickMax(center.x,center.y);
4850 if (image->columns > image->rows)
4851 scale.y=(double) image->columns/(double) image->rows;
4853 if (image->columns < image->rows)
4854 scale.x=(double) image->rows/(double) image->columns;
4855 degrees=(double) DegreesToRadians(degrees);
4861 GetMagickPixelPacket(swirl_image,&zero);
4862 resample_filter=AcquireResampleFilterThreadSet(image,
4863 UndefinedVirtualPixelMethod,MagickTrue,exception);
4864 image_view=AcquireCacheView(image);
4865 swirl_view=AcquireCacheView(swirl_image);
4866 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4867 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4869 for (y=0; y < (long) image->rows; y++)
4880 register IndexPacket
4881 *restrict swirl_indexes;
4887 register PixelPacket
4890 if (status == MagickFalse)
4892 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4894 if (q == (PixelPacket *) NULL)
4899 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4900 delta.y=scale.y*(double) (y-center.y);
4902 id=GetOpenMPThreadId();
4903 for (x=0; x < (long) image->columns; x++)
4906 Determine if the pixel is within an ellipse.
4908 delta.x=scale.x*(double) (x-center.x);
4909 distance=delta.x*delta.x+delta.y*delta.y;
4910 if (distance < (radius*radius))
4920 factor=1.0-sqrt((double) distance)/radius;
4921 sine=sin((double) (degrees*factor*factor));
4922 cosine=cos((double) (degrees*factor*factor));
4923 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4924 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4925 cosine*delta.y)/scale.y+center.y),&pixel);
4926 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4930 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4932 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4937 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4938 #pragma omp critical (MagickCore_SwirlImage)
4940 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4941 if (proceed == MagickFalse)
4945 swirl_view=DestroyCacheView(swirl_view);
4946 image_view=DestroyCacheView(image_view);
4947 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
4948 if (status == MagickFalse)
4949 swirl_image=DestroyImage(swirl_image);
4950 return(swirl_image);
4954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4958 % T i n t I m a g e %
4962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4964 % TintImage() applies a color vector to each pixel in the image. The length
4965 % of the vector is 0 for black and white and at its maximum for the midtones.
4966 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
4968 % The format of the TintImage method is:
4970 % Image *TintImage(const Image *image,const char *opacity,
4971 % const PixelPacket tint,ExceptionInfo *exception)
4973 % A description of each parameter follows:
4975 % o image: the image.
4977 % o opacity: A color value used for tinting.
4979 % o tint: A color value used for tinting.
4981 % o exception: return any errors or warnings in this structure.
4984 MagickExport Image *TintImage(const Image *image,const char *opacity,
4985 const PixelPacket tint,ExceptionInfo *exception)
4987 #define TintImageTag "Tint/Image"
5014 Allocate tint image.
5016 assert(image != (const Image *) NULL);
5017 assert(image->signature == MagickSignature);
5018 if (image->debug != MagickFalse)
5019 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5020 assert(exception != (ExceptionInfo *) NULL);
5021 assert(exception->signature == MagickSignature);
5022 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5023 if (tint_image == (Image *) NULL)
5024 return((Image *) NULL);
5025 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5027 InheritException(exception,&tint_image->exception);
5028 tint_image=DestroyImage(tint_image);
5029 return((Image *) NULL);
5031 if (opacity == (const char *) NULL)
5034 Determine RGB values of the color.
5036 flags=ParseGeometry(opacity,&geometry_info);
5037 pixel.red=geometry_info.rho;
5038 if ((flags & SigmaValue) != 0)
5039 pixel.green=geometry_info.sigma;
5041 pixel.green=pixel.red;
5042 if ((flags & XiValue) != 0)
5043 pixel.blue=geometry_info.xi;
5045 pixel.blue=pixel.red;
5046 if ((flags & PsiValue) != 0)
5047 pixel.opacity=geometry_info.psi;
5049 pixel.opacity=(MagickRealType) OpaqueOpacity;
5050 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5051 PixelIntensity(&tint));
5052 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5053 PixelIntensity(&tint));
5054 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5055 PixelIntensity(&tint));
5061 image_view=AcquireCacheView(image);
5062 tint_view=AcquireCacheView(tint_image);
5063 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5064 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5066 for (y=0; y < (long) image->rows; y++)
5068 register const PixelPacket
5074 register PixelPacket
5077 if (status == MagickFalse)
5079 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5080 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5082 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5087 for (x=0; x < (long) image->columns; x++)
5095 weight=QuantumScale*p->red-0.5;
5096 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5098 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5099 weight=QuantumScale*p->green-0.5;
5100 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5102 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5103 weight=QuantumScale*p->blue-0.5;
5104 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5106 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5107 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5111 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5113 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5118 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5119 #pragma omp critical (MagickCore_TintImage)
5121 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5122 if (proceed == MagickFalse)
5126 tint_view=DestroyCacheView(tint_view);
5127 image_view=DestroyCacheView(image_view);
5128 if (status == MagickFalse)
5129 tint_image=DestroyImage(tint_image);
5134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5138 % V i g n e t t e I m a g e %
5142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5144 % VignetteImage() softens the edges of the image in vignette style.
5146 % The format of the VignetteImage method is:
5148 % Image *VignetteImage(const Image *image,const double radius,
5149 % const double sigma,const long x,const long y,ExceptionInfo *exception)
5151 % A description of each parameter follows:
5153 % o image: the image.
5155 % o radius: the radius of the pixel neighborhood.
5157 % o sigma: the standard deviation of the Gaussian, in pixels.
5159 % o x, y: Define the x and y ellipse offset.
5161 % o exception: return any errors or warnings in this structure.
5164 MagickExport Image *VignetteImage(const Image *image,const double radius,
5165 const double sigma,const long x,const long y,ExceptionInfo *exception)
5168 ellipse[MaxTextExtent];
5179 assert(image != (Image *) NULL);
5180 assert(image->signature == MagickSignature);
5181 if (image->debug != MagickFalse)
5182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5183 assert(exception != (ExceptionInfo *) NULL);
5184 assert(exception->signature == MagickSignature);
5185 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5186 if (canvas_image == (Image *) NULL)
5187 return((Image *) NULL);
5188 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5190 InheritException(exception,&canvas_image->exception);
5191 canvas_image=DestroyImage(canvas_image);
5192 return((Image *) NULL);
5194 canvas_image->matte=MagickTrue;
5195 oval_image=CloneImage(canvas_image,canvas_image->columns,
5196 canvas_image->rows,MagickTrue,exception);
5197 if (oval_image == (Image *) NULL)
5199 canvas_image=DestroyImage(canvas_image);
5200 return((Image *) NULL);
5202 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5203 (void) SetImageBackgroundColor(oval_image);
5204 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5205 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5206 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5207 (void) FormatMagickString(ellipse,MaxTextExtent,
5208 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5209 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5210 draw_info->primitive=AcquireString(ellipse);
5211 (void) DrawImage(oval_image,draw_info);
5212 draw_info=DestroyDrawInfo(draw_info);
5213 blur_image=BlurImage(oval_image,radius,sigma,exception);
5214 oval_image=DestroyImage(oval_image);
5215 if (blur_image == (Image *) NULL)
5217 canvas_image=DestroyImage(canvas_image);
5218 return((Image *) NULL);
5220 blur_image->matte=MagickFalse;
5221 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5222 blur_image=DestroyImage(blur_image);
5223 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5224 canvas_image=DestroyImage(canvas_image);
5225 return(vignette_image);
5229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5233 % W a v e I m a g e %
5237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5239 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5240 % vertically along a sine wave whose amplitude and wavelength is specified
5241 % by the given parameters.
5243 % The format of the WaveImage method is:
5245 % Image *WaveImage(const Image *image,const double amplitude,
5246 % const double wave_length,ExceptionInfo *exception)
5248 % A description of each parameter follows:
5250 % o image: the image.
5252 % o amplitude, wave_length: Define the amplitude and wave length of the
5255 % o exception: return any errors or warnings in this structure.
5258 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5259 const double wave_length,ExceptionInfo *exception)
5261 #define WaveImageTag "Wave/Image"
5286 **restrict resample_filter;
5289 Initialize wave image attributes.
5291 assert(image != (Image *) NULL);
5292 assert(image->signature == MagickSignature);
5293 if (image->debug != MagickFalse)
5294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5295 assert(exception != (ExceptionInfo *) NULL);
5296 assert(exception->signature == MagickSignature);
5297 wave_image=CloneImage(image,image->columns,(unsigned long) (image->rows+2.0*
5298 fabs(amplitude)),MagickTrue,exception);
5299 if (wave_image == (Image *) NULL)
5300 return((Image *) NULL);
5301 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5303 InheritException(exception,&wave_image->exception);
5304 wave_image=DestroyImage(wave_image);
5305 return((Image *) NULL);
5307 if (wave_image->background_color.opacity != OpaqueOpacity)
5308 wave_image->matte=MagickTrue;
5312 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5314 if (sine_map == (MagickRealType *) NULL)
5316 wave_image=DestroyImage(wave_image);
5317 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5319 for (i=0; i < (long) wave_image->columns; i++)
5320 sine_map[i]=fabs(amplitude)+amplitude*sin((2*MagickPI*i)/wave_length);
5326 GetMagickPixelPacket(wave_image,&zero);
5327 resample_filter=AcquireResampleFilterThreadSet(image,
5328 BackgroundVirtualPixelMethod,MagickTrue,exception);
5329 wave_view=AcquireCacheView(wave_image);
5330 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5331 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5333 for (y=0; y < (long) wave_image->rows; y++)
5338 register IndexPacket
5345 register PixelPacket
5348 if (status == MagickFalse)
5350 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5352 if (q == (PixelPacket *) NULL)
5357 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5359 id=GetOpenMPThreadId();
5360 for (x=0; x < (long) wave_image->columns; x++)
5362 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5363 sine_map[x]),&pixel);
5364 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5367 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5369 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5374 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5375 #pragma omp critical (MagickCore_WaveImage)
5377 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5378 if (proceed == MagickFalse)
5382 wave_view=DestroyCacheView(wave_view);
5383 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5384 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5385 if (status == MagickFalse)
5386 wave_image=DestroyImage(wave_image);