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,
2283 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2292 if (LocaleNCompare(expression,"ln",2) == 0)
2294 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2296 return((MagickRealType) log((double) alpha));
2298 if (LocaleNCompare(expression,"logtwo",4) == 0)
2300 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2302 return((MagickRealType) log10((double) alpha))/log10(2.0);
2304 if (LocaleNCompare(expression,"log",3) == 0)
2306 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2308 return((MagickRealType) log10((double) alpha));
2310 if (LocaleCompare(expression,"lightness") == 0)
2311 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2317 if (LocaleCompare(expression,"MaxRGB") == 0)
2318 return((MagickRealType) QuantumRange);
2319 if (LocaleNCompare(expression,"maxima",6) == 0)
2321 if (LocaleNCompare(expression,"max",3) == 0)
2322 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2323 if (LocaleNCompare(expression,"minima",6) == 0)
2325 if (LocaleNCompare(expression,"min",3) == 0)
2326 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2327 if (LocaleNCompare(expression,"mod",3) == 0)
2329 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2331 return((MagickRealType) fmod((double) alpha,(double) *beta));
2333 if (LocaleCompare(expression,"m") == 0)
2334 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2340 if (LocaleCompare(expression,"n") == 0)
2341 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2347 if (LocaleCompare(expression,"Opaque") == 0)
2349 if (LocaleCompare(expression,"o") == 0)
2350 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2356 if (LocaleCompare(expression,"pi") == 0)
2357 return((MagickRealType) MagickPI);
2358 if (LocaleNCompare(expression,"pow",3) == 0)
2360 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2362 return((MagickRealType) pow((double) alpha,(double) *beta));
2364 if (LocaleCompare(expression,"p") == 0)
2365 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2371 if (LocaleCompare(expression,"QuantumRange") == 0)
2372 return((MagickRealType) QuantumRange);
2373 if (LocaleCompare(expression,"QuantumScale") == 0)
2374 return((MagickRealType) QuantumScale);
2380 if (LocaleNCompare(expression,"rand",4) == 0)
2381 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2382 if (LocaleNCompare(expression,"round",5) == 0)
2384 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2387 return((MagickRealType) floor((double) alpha+0.5));
2388 return((MagickRealType) ceil((double) alpha-0.5));
2390 if (LocaleCompare(expression,"r") == 0)
2391 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2397 if (LocaleCompare(expression,"saturation") == 0)
2398 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2399 if (LocaleNCompare(expression,"sign",4) == 0)
2401 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2403 return(alpha < 0.0 ? -1.0 : 1.0);
2405 if (LocaleNCompare(expression,"sinc",4) == 0)
2407 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2411 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2415 if (LocaleNCompare(expression,"sinh",4) == 0)
2417 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2419 return((MagickRealType) sinh((double) alpha));
2421 if (LocaleNCompare(expression,"sin",3) == 0)
2423 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2425 return((MagickRealType) sin((double) alpha));
2427 if (LocaleNCompare(expression,"sqrt",4) == 0)
2429 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2431 return((MagickRealType) sqrt((double) alpha));
2433 if (LocaleCompare(expression,"s") == 0)
2434 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2440 if (LocaleNCompare(expression,"tanh",4) == 0)
2442 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2444 return((MagickRealType) tanh((double) alpha));
2446 if (LocaleNCompare(expression,"tan",3) == 0)
2448 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2450 return((MagickRealType) tan((double) alpha));
2452 if (LocaleCompare(expression,"Transparent") == 0)
2454 if (LocaleCompare(expression,"t") == 0)
2455 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2461 if (LocaleCompare(expression,"u") == 0)
2462 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2468 if (LocaleCompare(expression,"v") == 0)
2469 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2475 if (LocaleCompare(expression,"w") == 0)
2476 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2482 if (LocaleCompare(expression,"y") == 0)
2483 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2489 if (LocaleCompare(expression,"z") == 0)
2490 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2496 q=(char *) expression;
2497 alpha=strtod(expression,&q);
2498 if (q == expression)
2499 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2503 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2504 MagickRealType *alpha,ExceptionInfo *exception)
2509 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2513 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2514 MagickRealType *alpha,ExceptionInfo *exception)
2523 fx_info->file=(FILE *) NULL;
2524 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2529 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2530 const ChannelType channel,const long x,const long y,MagickRealType *alpha,
2531 ExceptionInfo *exception)
2537 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2539 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2553 % FxImage() applies a mathematical expression to the specified image.
2555 % The format of the FxImage method is:
2557 % Image *FxImage(const Image *image,const char *expression,
2558 % ExceptionInfo *exception)
2559 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2560 % const char *expression,ExceptionInfo *exception)
2562 % A description of each parameter follows:
2564 % o image: the image.
2566 % o channel: the channel.
2568 % o expression: A mathematical expression.
2570 % o exception: return any errors or warnings in this structure.
2574 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2579 assert(fx_info != (FxInfo **) NULL);
2580 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
2581 if (fx_info[i] != (FxInfo *) NULL)
2582 fx_info[i]=DestroyFxInfo(fx_info[i]);
2583 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2587 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2588 ExceptionInfo *exception)
2605 number_threads=GetOpenMPMaximumThreads();
2606 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2607 if (fx_info == (FxInfo **) NULL)
2608 return((FxInfo **) NULL);
2609 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2610 if (*expression != '@')
2611 fx_expression=ConstantString(expression);
2613 fx_expression=FileToString(expression+1,~0,exception);
2614 for (i=0; i < (long) number_threads; i++)
2616 fx_info[i]=AcquireFxInfo(image,fx_expression);
2617 if (fx_info[i] == (FxInfo *) NULL)
2618 return(DestroyFxThreadSet(fx_info));
2619 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2621 fx_expression=DestroyString(fx_expression);
2625 MagickExport Image *FxImage(const Image *image,const char *expression,
2626 ExceptionInfo *exception)
2631 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2635 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2636 const char *expression,ExceptionInfo *exception)
2638 #define FxImageTag "Fx/Image"
2659 assert(image != (Image *) NULL);
2660 assert(image->signature == MagickSignature);
2661 if (image->debug != MagickFalse)
2662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2663 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2664 if (fx_image == (Image *) NULL)
2665 return((Image *) NULL);
2666 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2668 InheritException(exception,&fx_image->exception);
2669 fx_image=DestroyImage(fx_image);
2670 return((Image *) NULL);
2672 fx_info=AcquireFxThreadSet(image,expression,exception);
2673 if (fx_info == (FxInfo **) NULL)
2675 fx_image=DestroyImage(fx_image);
2676 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2678 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2679 if (status == MagickFalse)
2681 fx_image=DestroyImage(fx_image);
2682 fx_info=DestroyFxThreadSet(fx_info);
2683 return((Image *) NULL);
2690 fx_view=AcquireCacheView(fx_image);
2691 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2692 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2694 for (y=0; y < (long) fx_image->rows; y++)
2699 register IndexPacket
2700 *restrict fx_indexes;
2706 register PixelPacket
2709 if (status == MagickFalse)
2711 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2712 if (q == (PixelPacket *) NULL)
2717 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2718 id=GetOpenMPThreadId();
2720 for (x=0; x < (long) fx_image->columns; x++)
2722 if ((channel & RedChannel) != 0)
2724 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
2726 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2728 if ((channel & GreenChannel) != 0)
2730 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
2732 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2734 if ((channel & BlueChannel) != 0)
2736 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
2738 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2740 if ((channel & OpacityChannel) != 0)
2742 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
2744 if (image->matte == MagickFalse)
2745 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2747 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
2748 QuantumRange*alpha));
2750 if (((channel & IndexChannel) != 0) &&
2751 (fx_image->colorspace == CMYKColorspace))
2753 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
2755 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
2756 QuantumRange*alpha);
2760 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
2762 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2767 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2768 #pragma omp critical (MagickCore_FxImageChannel)
2770 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
2771 if (proceed == MagickFalse)
2775 fx_image->matte=fx_info[0]->matte;
2776 fx_view=DestroyCacheView(fx_view);
2777 fx_info=DestroyFxThreadSet(fx_info);
2778 if (status == MagickFalse)
2779 fx_image=DestroyImage(fx_image);
2784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2788 % I m p l o d e I m a g e %
2792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2794 % ImplodeImage() creates a new image that is a copy of an existing
2795 % one with the image pixels "implode" by the specified percentage. It
2796 % allocates the memory necessary for the new Image structure and returns a
2797 % pointer to the new image.
2799 % The format of the ImplodeImage method is:
2801 % Image *ImplodeImage(const Image *image,const double amount,
2802 % ExceptionInfo *exception)
2804 % A description of each parameter follows:
2806 % o implode_image: Method ImplodeImage returns a pointer to the image
2807 % after it is implode. A null image is returned if there is a memory
2810 % o image: the image.
2812 % o amount: Define the extent of the implosion.
2814 % o exception: return any errors or warnings in this structure.
2817 MagickExport Image *ImplodeImage(const Image *image,const double amount,
2818 ExceptionInfo *exception)
2820 #define ImplodeImageTag "Implode/Image"
2847 **restrict resample_filter;
2850 Initialize implode image attributes.
2852 assert(image != (Image *) NULL);
2853 assert(image->signature == MagickSignature);
2854 if (image->debug != MagickFalse)
2855 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2856 assert(exception != (ExceptionInfo *) NULL);
2857 assert(exception->signature == MagickSignature);
2858 implode_image=CloneImage(image,0,0,MagickTrue,exception);
2859 if (implode_image == (Image *) NULL)
2860 return((Image *) NULL);
2861 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
2863 InheritException(exception,&implode_image->exception);
2864 implode_image=DestroyImage(implode_image);
2865 return((Image *) NULL);
2867 if (implode_image->background_color.opacity != OpaqueOpacity)
2868 implode_image->matte=MagickTrue;
2870 Compute scaling factor.
2874 center.x=0.5*image->columns;
2875 center.y=0.5*image->rows;
2877 if (image->columns > image->rows)
2878 scale.y=(double) image->columns/(double) image->rows;
2880 if (image->columns < image->rows)
2882 scale.x=(double) image->rows/(double) image->columns;
2890 GetMagickPixelPacket(implode_image,&zero);
2891 resample_filter=AcquireResampleFilterThreadSet(image,
2892 UndefinedVirtualPixelMethod,MagickTrue,exception);
2893 image_view=AcquireCacheView(image);
2894 implode_view=AcquireCacheView(implode_image);
2895 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2896 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2898 for (y=0; y < (long) image->rows; y++)
2909 register IndexPacket
2910 *restrict implode_indexes;
2916 register PixelPacket
2919 if (status == MagickFalse)
2921 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
2923 if (q == (PixelPacket *) NULL)
2928 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
2929 delta.y=scale.y*(double) (y-center.y);
2931 id=GetOpenMPThreadId();
2932 for (x=0; x < (long) image->columns; x++)
2935 Determine if the pixel is within an ellipse.
2937 delta.x=scale.x*(double) (x-center.x);
2938 distance=delta.x*delta.x+delta.y*delta.y;
2939 if (distance < (radius*radius))
2949 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
2950 radius/2)),-amount);
2951 (void) ResamplePixelColor(resample_filter[id],(double)
2952 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
2953 scale.y+center.y),&pixel);
2954 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
2958 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
2960 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2965 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2966 #pragma omp critical (MagickCore_ImplodeImage)
2968 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
2969 if (proceed == MagickFalse)
2973 implode_view=DestroyCacheView(implode_view);
2974 image_view=DestroyCacheView(image_view);
2975 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
2976 if (status == MagickFalse)
2977 implode_image=DestroyImage(implode_image);
2978 return(implode_image);
2982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2986 % M o r p h I m a g e s %
2990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2992 % The MorphImages() method requires a minimum of two images. The first
2993 % image is transformed into the second by a number of intervening images
2994 % as specified by frames.
2996 % The format of the MorphImage method is:
2998 % Image *MorphImages(const Image *image,const unsigned long number_frames,
2999 % ExceptionInfo *exception)
3001 % A description of each parameter follows:
3003 % o image: the image.
3005 % o number_frames: Define the number of in-between image to generate.
3006 % The more in-between frames, the smoother the morph.
3008 % o exception: return any errors or warnings in this structure.
3011 MagickExport Image *MorphImages(const Image *image,
3012 const unsigned long number_frames,ExceptionInfo *exception)
3014 #define MorphImageTag "Morph/Image"
3030 register const Image
3040 Clone first frame in sequence.
3042 assert(image != (Image *) NULL);
3043 assert(image->signature == MagickSignature);
3044 if (image->debug != MagickFalse)
3045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3046 assert(exception != (ExceptionInfo *) NULL);
3047 assert(exception->signature == MagickSignature);
3048 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3049 if (morph_images == (Image *) NULL)
3050 return((Image *) NULL);
3051 if (GetNextImageInList(image) == (Image *) NULL)
3056 for (i=1; i < (long) number_frames; i++)
3058 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3059 if (morph_image == (Image *) NULL)
3061 morph_images=DestroyImageList(morph_images);
3062 return((Image *) NULL);
3064 AppendImageToList(&morph_images,morph_image);
3065 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3070 proceed=SetImageProgress(image,MorphImageTag,i,number_frames);
3071 if (proceed == MagickFalse)
3075 return(GetFirstImageInList(morph_images));
3078 Morph image sequence.
3083 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3085 for (i=0; i < (long) number_frames; i++)
3091 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3093 morph_image=ZoomImage(next,(unsigned long) (alpha*next->columns+beta*
3094 GetNextImageInList(next)->columns+0.5),(unsigned long) (alpha*
3095 next->rows+beta*GetNextImageInList(next)->rows+0.5),exception);
3096 if (morph_image == (Image *) NULL)
3098 morph_images=DestroyImageList(morph_images);
3099 return((Image *) NULL);
3101 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3103 InheritException(exception,&morph_image->exception);
3104 morph_image=DestroyImage(morph_image);
3105 return((Image *) NULL);
3107 AppendImageToList(&morph_images,morph_image);
3108 morph_images=GetLastImageInList(morph_images);
3109 morph_image=ZoomImage(GetNextImageInList(next),morph_images->columns,
3110 morph_images->rows,exception);
3111 if (morph_image == (Image *) NULL)
3113 morph_images=DestroyImageList(morph_images);
3114 return((Image *) NULL);
3116 image_view=AcquireCacheView(morph_image);
3117 morph_view=AcquireCacheView(morph_images);
3118 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3119 #pragma omp parallel for schedule(dynamic,4) shared(status)
3121 for (y=0; y < (long) morph_images->rows; y++)
3126 register const PixelPacket
3132 register PixelPacket
3135 if (status == MagickFalse)
3137 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3139 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3141 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3146 for (x=0; x < (long) morph_images->columns; x++)
3148 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3149 q->green=ClampToQuantum(alpha*q->green+beta*
3150 GetGreenPixelComponent(p));
3151 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3152 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3153 GetOpacityPixelComponent(p));
3157 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3158 if (sync == MagickFalse)
3161 morph_view=DestroyCacheView(morph_view);
3162 image_view=DestroyCacheView(image_view);
3163 morph_image=DestroyImage(morph_image);
3165 if (i < (long) number_frames)
3168 Clone last frame in sequence.
3170 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3171 if (morph_image == (Image *) NULL)
3173 morph_images=DestroyImageList(morph_images);
3174 return((Image *) NULL);
3176 AppendImageToList(&morph_images,morph_image);
3177 morph_images=GetLastImageInList(morph_images);
3178 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3183 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3184 #pragma omp critical (MagickCore_MorphImages)
3186 proceed=SetImageProgress(image,MorphImageTag,scene,
3187 GetImageListLength(image));
3188 if (proceed == MagickFalse)
3193 if (GetNextImageInList(next) != (Image *) NULL)
3195 morph_images=DestroyImageList(morph_images);
3196 return((Image *) NULL);
3198 return(GetFirstImageInList(morph_images));
3202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3206 % P l a s m a I m a g e %
3210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3212 % PlasmaImage() initializes an image with plasma fractal values. The image
3213 % must be initialized with a base color and the random number generator
3214 % seeded before this method is called.
3216 % The format of the PlasmaImage method is:
3218 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3219 % unsigned long attenuate,unsigned long depth)
3221 % A description of each parameter follows:
3223 % o image: the image.
3225 % o segment: Define the region to apply plasma fractals values.
3227 % o attenuate: Define the plasmattenuation factor.
3229 % o depth: Limit the plasma recursion depth.
3233 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3234 const MagickRealType pixel,const MagickRealType noise)
3239 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3244 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3245 RandomInfo *random_info,const SegmentInfo *segment,unsigned long attenuate,
3246 unsigned long depth)
3264 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3272 Divide the area into quadrants and recurse.
3276 x_mid=(long) ceil(segment->x1+segment->x2-0.5)/2;
3277 y_mid=(long) ceil(segment->y1+segment->y2-0.5)/2;
3278 local_info=(*segment);
3279 local_info.x2=(double) x_mid;
3280 local_info.y2=(double) y_mid;
3281 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3282 local_info=(*segment);
3283 local_info.y1=(double) y_mid;
3284 local_info.x2=(double) x_mid;
3285 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3286 local_info=(*segment);
3287 local_info.x1=(double) x_mid;
3288 local_info.y2=(double) y_mid;
3289 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3290 local_info=(*segment);
3291 local_info.x1=(double) x_mid;
3292 local_info.y1=(double) y_mid;
3293 return(PlasmaImageProxy(image,random_info,&local_info,attenuate,depth));
3295 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3296 return(MagickFalse);
3297 x_mid=(long) ceil(segment->x1+segment->x2-0.5)/2;
3298 y_mid=(long) ceil(segment->y1+segment->y2-0.5)/2;
3299 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3300 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3301 return(MagickFalse);
3303 Average pixels and apply plasma.
3305 exception=(&image->exception);
3306 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3307 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3309 register PixelPacket
3315 x=(long) ceil(segment->x1-0.5);
3316 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y1-0.5),&u,
3318 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y2-0.5),&v,
3320 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3321 if (q == (PixelPacket *) NULL)
3323 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3325 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3327 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3329 (void) SyncAuthenticPixels(image,exception);
3330 if (segment->x1 != segment->x2)
3335 x=(long) ceil(segment->x2-0.5);
3336 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y1-0.5),&u,
3338 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y2-0.5),&v,
3340 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3341 if (q == (PixelPacket *) NULL)
3343 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3345 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3347 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3349 (void) SyncAuthenticPixels(image,exception);
3352 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3354 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3356 register PixelPacket
3362 y=(long) ceil(segment->y2-0.5);
3363 (void) GetOneVirtualPixel(image,(long) ceil(segment->x1-0.5),y,&u,
3365 (void) GetOneVirtualPixel(image,(long) ceil(segment->x2-0.5),y,&v,
3367 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3368 if (q == (PixelPacket *) NULL)
3370 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3372 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3374 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3376 (void) SyncAuthenticPixels(image,exception);
3378 if (segment->y1 != segment->y2)
3380 register PixelPacket
3386 y=(long) ceil(segment->y1-0.5);
3387 (void) GetOneVirtualPixel(image,(long) ceil(segment->x1-0.5),y,&u,
3389 (void) GetOneVirtualPixel(image,(long) ceil(segment->x2-0.5),y,&v,
3391 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3392 if (q == (PixelPacket *) NULL)
3394 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3396 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3398 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3400 (void) SyncAuthenticPixels(image,exception);
3403 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3405 register PixelPacket
3411 x=(long) ceil(segment->x1-0.5);
3412 y=(long) ceil(segment->y1-0.5);
3413 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3414 x=(long) ceil(segment->x2-0.5);
3415 y=(long) ceil(segment->y2-0.5);
3416 (void) GetOneVirtualPixel(image,x,y,&v,exception);
3417 q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception);
3418 if (q == (PixelPacket *) NULL)
3420 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3422 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3424 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3426 (void) SyncAuthenticPixels(image,exception);
3428 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3430 return(MagickFalse);
3433 MagickExport MagickBooleanType PlasmaImage(Image *image,
3434 const SegmentInfo *segment,unsigned long attenuate,unsigned long depth)
3442 if (image->debug != MagickFalse)
3443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3444 assert(image != (Image *) NULL);
3445 assert(image->signature == MagickSignature);
3446 if (image->debug != MagickFalse)
3447 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3448 random_info=AcquireRandomInfo();
3449 status=PlasmaImageProxy(image,random_info,segment,attenuate,depth);
3450 random_info=DestroyRandomInfo(random_info);
3455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3459 % P o l a r o i d I m a g e %
3463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3465 % PolaroidImage() simulates a Polaroid picture.
3467 % The format of the AnnotateImage method is:
3469 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3470 % const double angle,ExceptionInfo exception)
3472 % A description of each parameter follows:
3474 % o image: the image.
3476 % o draw_info: the draw info.
3478 % o angle: Apply the effect along this angle.
3480 % o exception: return any errors or warnings in this structure.
3483 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3484 const double angle,ExceptionInfo *exception)
3505 Simulate a Polaroid picture.
3507 assert(image != (Image *) NULL);
3508 assert(image->signature == MagickSignature);
3509 if (image->debug != MagickFalse)
3510 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3511 assert(exception != (ExceptionInfo *) NULL);
3512 assert(exception->signature == MagickSignature);
3513 quantum=(long) MagickMax(MagickMax((double) image->columns,(double)
3514 image->rows)/25.0,10.0);
3515 height=image->rows+2*quantum;
3516 caption_image=(Image *) NULL;
3517 value=GetImageProperty(image,"Caption");
3518 if (value != (const char *) NULL)
3522 geometry[MaxTextExtent];
3537 Generate caption image.
3539 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3540 if (caption_image == (Image *) NULL)
3541 return((Image *) NULL);
3542 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3543 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3545 (void) CloneString(&annotate_info->text,caption);
3546 count=FormatMagickCaption(caption_image,annotate_info,&metrics,&caption);
3547 status=SetImageExtent(caption_image,image->columns,(unsigned long)
3548 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3549 if (status == MagickFalse)
3550 caption_image=DestroyImage(caption_image);
3553 caption_image->background_color=image->border_color;
3554 (void) SetImageBackgroundColor(caption_image);
3555 (void) CloneString(&annotate_info->text,caption);
3556 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3558 if (annotate_info->gravity == UndefinedGravity)
3559 (void) CloneString(&annotate_info->geometry,AcquireString(
3561 (void) AnnotateImage(caption_image,annotate_info);
3562 height+=caption_image->rows;
3564 annotate_info=DestroyDrawInfo(annotate_info);
3565 caption=DestroyString(caption);
3567 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3569 if (picture_image == (Image *) NULL)
3571 if (caption_image != (Image *) NULL)
3572 caption_image=DestroyImage(caption_image);
3573 return((Image *) NULL);
3575 picture_image->background_color=image->border_color;
3576 (void) SetImageBackgroundColor(picture_image);
3577 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3578 if (caption_image != (Image *) NULL)
3580 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3581 quantum,(long) (image->rows+3*quantum/2));
3582 caption_image=DestroyImage(caption_image);
3584 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3585 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3586 rotate_image=RotateImage(picture_image,90.0,exception);
3587 picture_image=DestroyImage(picture_image);
3588 if (rotate_image == (Image *) NULL)
3589 return((Image *) NULL);
3590 picture_image=rotate_image;
3591 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3592 picture_image->columns,exception);
3593 picture_image=DestroyImage(picture_image);
3594 if (bend_image == (Image *) NULL)
3595 return((Image *) NULL);
3596 InheritException(&bend_image->exception,exception);
3597 picture_image=bend_image;
3598 rotate_image=RotateImage(picture_image,-90.0,exception);
3599 picture_image=DestroyImage(picture_image);
3600 if (rotate_image == (Image *) NULL)
3601 return((Image *) NULL);
3602 picture_image=rotate_image;
3603 picture_image->background_color=image->background_color;
3604 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3606 if (polaroid_image == (Image *) NULL)
3608 picture_image=DestroyImage(picture_image);
3609 return(picture_image);
3611 flop_image=FlopImage(polaroid_image,exception);
3612 polaroid_image=DestroyImage(polaroid_image);
3613 if (flop_image == (Image *) NULL)
3615 picture_image=DestroyImage(picture_image);
3616 return(picture_image);
3618 polaroid_image=flop_image;
3619 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3620 (long) (-0.01*picture_image->columns/2.0),0L);
3621 picture_image=DestroyImage(picture_image);
3622 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3623 rotate_image=RotateImage(polaroid_image,angle,exception);
3624 polaroid_image=DestroyImage(polaroid_image);
3625 if (rotate_image == (Image *) NULL)
3626 return((Image *) NULL);
3627 polaroid_image=rotate_image;
3628 trim_image=TrimImage(polaroid_image,exception);
3629 polaroid_image=DestroyImage(polaroid_image);
3630 if (trim_image == (Image *) NULL)
3631 return((Image *) NULL);
3632 polaroid_image=trim_image;
3633 return(polaroid_image);
3637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3641 % R e c o l o r I m a g e %
3645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3647 % RecolorImage() translate, scale, shear, or rotate image colors. Although
3648 % you can use variable sized matrices, typically you use a 5 x 5 for an RGBA
3649 % image and a 6x6 for CMYKA. Populate the last row with normalized values to
3652 % The format of the RecolorImage method is:
3654 % Image *RecolorImage(const Image *image,const unsigned long order,
3655 % const double *color_matrix,ExceptionInfo *exception)
3657 % A description of each parameter follows:
3659 % o image: the image.
3661 % o order: the number of columns and rows in the recolor matrix.
3663 % o color_matrix: An array of double representing the recolor matrix.
3665 % o exception: return any errors or warnings in this structure.
3668 MagickExport Image *RecolorImage(const Image *image,const unsigned long order,
3669 const double *color_matrix,ExceptionInfo *exception)
3671 #define RecolorImageTag "Recolor/Image"
3688 Initialize image attributes.
3690 assert(image != (Image *) NULL);
3691 assert(image->signature == MagickSignature);
3692 if (image->debug != MagickFalse)
3693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3694 assert(exception != (ExceptionInfo *) NULL);
3695 assert(exception->signature == MagickSignature);
3696 recolor_image=CloneImage(image,0,0,MagickTrue,exception);
3697 if (recolor_image == (Image *) NULL)
3698 return((Image *) NULL);
3699 if (SetImageStorageClass(recolor_image,DirectClass) == MagickFalse)
3701 InheritException(exception,&recolor_image->exception);
3702 recolor_image=DestroyImage(recolor_image);
3703 return((Image *) NULL);
3705 if (image->debug != MagickFalse)
3708 format[MaxTextExtent],
3715 register const double
3718 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
3719 " Recolor image with %ldx%ld color matrix:",order,order);
3720 message=AcquireString("");
3722 for (v=0; v < (long) order; v++)
3725 (void) FormatMagickString(format,MaxTextExtent,"%ld: ",v);
3726 (void) ConcatenateString(&message,format);
3727 for (u=0; u < (long) order; u++)
3729 (void) FormatMagickString(format,MaxTextExtent,"%+f ",*k++);
3730 (void) ConcatenateString(&message,format);
3732 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
3734 message=DestroyString(message);
3741 image_view=AcquireCacheView(image);
3742 recolor_view=AcquireCacheView(recolor_image);
3743 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3744 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3746 for (y=0; y < (long) image->rows; y++)
3748 register const double
3751 register const IndexPacket
3754 register const PixelPacket
3760 register IndexPacket
3761 *restrict recolor_indexes;
3763 register PixelPacket
3766 if (status == MagickFalse)
3768 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3769 q=GetCacheViewAuthenticPixels(recolor_view,0,y,recolor_image->columns,1,
3771 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3776 indexes=GetCacheViewVirtualIndexQueue(image_view);
3777 recolor_indexes=GetCacheViewAuthenticIndexQueue(recolor_view);
3785 for (x=0; x < (long) image->columns; x++)
3787 q->red=ClampToQuantum(k[0]*GetRedPixelComponent(p));
3795 for (x=0; x < (long) image->columns; x++)
3797 q->red=ClampToQuantum(k[0]*p->red+k[1]*GetGreenPixelComponent(p));
3798 q->green=ClampToQuantum(k[2]*p->red+k[3]*GetGreenPixelComponent(p));
3806 for (x=0; x < (long) image->columns; x++)
3808 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*GetBluePixelComponent(p));
3809 q->green=ClampToQuantum(k[3]*p->red+k[4]*p->green+k[5]*GetBluePixelComponent(p));
3810 q->blue=ClampToQuantum(k[6]*p->red+k[7]*p->green+k[8]*GetBluePixelComponent(p));
3818 for (x=0; x < (long) image->columns; x++)
3820 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*p->blue+
3821 k[12]*QuantumRange);
3822 q->green=ClampToQuantum(k[4]*p->red+k[5]*p->green+k[6]*p->blue+
3823 k[13]*QuantumRange);
3824 q->blue=ClampToQuantum(k[8]*p->red+k[9]*p->green+k[10]*p->blue+
3825 k[14]*QuantumRange);
3833 for (x=0; x < (long) image->columns; x++)
3835 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*p->blue+
3836 k[3]*(GetAlphaPixelComponent(p))+k[20]*QuantumRange);
3837 q->green=ClampToQuantum(k[5]*p->red+k[6]*p->green+k[7]*p->blue+
3838 k[8]*(GetAlphaPixelComponent(p))+k[21]*QuantumRange);
3839 q->blue=ClampToQuantum(k[10]*p->red+k[11]*p->green+k[12]*p->blue+
3840 k[13]*(GetAlphaPixelComponent(p))+k[22]*QuantumRange);
3841 if (image->matte != MagickFalse)
3842 q->opacity=ClampToQuantum((MagickRealType) QuantumRange-(k[15]*
3843 p->red+k[16]*p->green+k[17]*p->blue+k[18]*
3844 GetAlphaPixelComponent(p)+k[23]*QuantumRange));
3852 for (x=0; x < (long) image->columns; x++)
3854 q->red=ClampToQuantum(k[0]*p->red+k[1]*p->green+k[2]*p->blue+
3855 k[3]*indexes[x]+k[4]*((Quantum) GetAlphaPixelComponent(p))+
3856 k[30]*QuantumRange);
3857 q->green=ClampToQuantum(k[6]*p->red+k[7]*p->green+k[8]*p->blue+
3858 k[9]*indexes[x]+k[10]*((Quantum) GetAlphaPixelComponent(p))+
3859 k[31]*QuantumRange);
3860 q->blue=ClampToQuantum(k[12]*p->red+k[13]*p->green+k[14]*p->blue+
3861 k[15]*indexes[x]+k[16]*((Quantum) GetAlphaPixelComponent(p))+
3862 k[32]*QuantumRange);
3863 if (image->matte != MagickFalse)
3864 q->opacity=ClampToQuantum((MagickRealType) QuantumRange-(k[24]*
3865 p->red+k[25]*p->green+k[26]*p->blue+k[27]*indexes[x]+
3866 k[28]*(GetAlphaPixelComponent(p))+k[34]*QuantumRange));
3867 if (image->colorspace == CMYKColorspace)
3868 recolor_indexes[x]=ClampToQuantum(k[18]*p->red+k[19]*p->green+k[20]*
3869 p->blue+k[21]*indexes[x]+k[22]*((Quantum) QuantumRange-
3870 GetOpacityPixelComponent(p))+k[33]*QuantumRange);
3877 if (SyncCacheViewAuthenticPixels(recolor_view,exception) == MagickFalse)
3879 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3884 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3885 #pragma omp critical (MagickCore_RecolorImage)
3887 proceed=SetImageProgress(image,RecolorImageTag,progress++,image->rows);
3888 if (proceed == MagickFalse)
3892 recolor_view=DestroyCacheView(recolor_view);
3893 image_view=DestroyCacheView(image_view);
3894 if (status == MagickFalse)
3895 recolor_image=DestroyImage(recolor_image);
3896 return(recolor_image);
3900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3904 % S e p i a T o n e I m a g e %
3908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3910 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3911 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3912 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3913 % threshold of 80% is a good starting point for a reasonable tone.
3915 % The format of the SepiaToneImage method is:
3917 % Image *SepiaToneImage(const Image *image,const double threshold,
3918 % ExceptionInfo *exception)
3920 % A description of each parameter follows:
3922 % o image: the image.
3924 % o threshold: the tone threshold.
3926 % o exception: return any errors or warnings in this structure.
3929 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3930 ExceptionInfo *exception)
3932 #define SepiaToneImageTag "SepiaTone/Image"
3949 Initialize sepia-toned image attributes.
3951 assert(image != (const Image *) NULL);
3952 assert(image->signature == MagickSignature);
3953 if (image->debug != MagickFalse)
3954 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3955 assert(exception != (ExceptionInfo *) NULL);
3956 assert(exception->signature == MagickSignature);
3957 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3958 if (sepia_image == (Image *) NULL)
3959 return((Image *) NULL);
3960 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3962 InheritException(exception,&sepia_image->exception);
3963 sepia_image=DestroyImage(sepia_image);
3964 return((Image *) NULL);
3967 Tone each row of the image.
3971 image_view=AcquireCacheView(image);
3972 sepia_view=AcquireCacheView(sepia_image);
3973 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3974 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3976 for (y=0; y < (long) image->rows; y++)
3978 register const PixelPacket
3984 register PixelPacket
3987 if (status == MagickFalse)
3989 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3990 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
3992 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3997 for (x=0; x < (long) image->columns; x++)
4003 intensity=(MagickRealType) PixelIntensityToQuantum(p);
4004 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4005 (MagickRealType) QuantumRange-threshold;
4006 q->red=ClampToQuantum(tone);
4007 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4008 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4009 q->green=ClampToQuantum(tone);
4010 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4011 q->blue=ClampToQuantum(tone);
4013 if ((MagickRealType) q->green < tone)
4014 q->green=ClampToQuantum(tone);
4015 if ((MagickRealType) q->blue < tone)
4016 q->blue=ClampToQuantum(tone);
4020 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4022 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4027 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4028 #pragma omp critical (MagickCore_SepiaToneImage)
4030 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4032 if (proceed == MagickFalse)
4036 sepia_view=DestroyCacheView(sepia_view);
4037 image_view=DestroyCacheView(image_view);
4038 (void) NormalizeImage(sepia_image);
4039 (void) ContrastImage(sepia_image,MagickTrue);
4040 if (status == MagickFalse)
4041 sepia_image=DestroyImage(sepia_image);
4042 return(sepia_image);
4046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4050 % S h a d o w I m a g e %
4054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4056 % ShadowImage() simulates a shadow from the specified image and returns it.
4058 % The format of the ShadowImage method is:
4060 % Image *ShadowImage(const Image *image,const double opacity,
4061 % const double sigma,const long x_offset,const long y_offset,
4062 % ExceptionInfo *exception)
4064 % A description of each parameter follows:
4066 % o image: the image.
4068 % o opacity: percentage transparency.
4070 % o sigma: the standard deviation of the Gaussian, in pixels.
4072 % o x_offset: the shadow x-offset.
4074 % o y_offset: the shadow y-offset.
4076 % o exception: return any errors or warnings in this structure.
4079 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4080 const double sigma,const long x_offset,const long y_offset,
4081 ExceptionInfo *exception)
4083 #define ShadowImageTag "Shadow/Image"
4103 assert(image != (Image *) NULL);
4104 assert(image->signature == MagickSignature);
4105 if (image->debug != MagickFalse)
4106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4107 assert(exception != (ExceptionInfo *) NULL);
4108 assert(exception->signature == MagickSignature);
4109 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4110 if (clone_image == (Image *) NULL)
4111 return((Image *) NULL);
4112 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4113 clone_image->compose=OverCompositeOp;
4114 border_info.width=(unsigned long) floor(2.0*sigma+0.5);
4115 border_info.height=(unsigned long) floor(2.0*sigma+0.5);
4118 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4119 border_image=BorderImage(clone_image,&border_info,exception);
4120 clone_image=DestroyImage(clone_image);
4121 if (border_image == (Image *) NULL)
4122 return((Image *) NULL);
4123 if (border_image->matte == MagickFalse)
4124 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4130 image_view=AcquireCacheView(border_image);
4131 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4132 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4134 for (y=0; y < (long) border_image->rows; y++)
4139 register PixelPacket
4142 if (status == MagickFalse)
4144 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4146 if (q == (PixelPacket *) NULL)
4151 for (x=0; x < (long) border_image->columns; x++)
4153 q->red=border_image->background_color.red;
4154 q->green=border_image->background_color.green;
4155 q->blue=border_image->background_color.blue;
4156 if (border_image->matte == MagickFalse)
4157 q->opacity=border_image->background_color.opacity;
4159 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4160 GetAlphaPixelComponent(q)*opacity/100.0));
4163 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4165 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4170 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4171 #pragma omp critical (MagickCore_ShadowImage)
4173 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4174 border_image->rows);
4175 if (proceed == MagickFalse)
4179 image_view=DestroyCacheView(image_view);
4180 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4181 border_image=DestroyImage(border_image);
4182 if (shadow_image == (Image *) NULL)
4183 return((Image *) NULL);
4184 if (shadow_image->page.width == 0)
4185 shadow_image->page.width=shadow_image->columns;
4186 if (shadow_image->page.height == 0)
4187 shadow_image->page.height=shadow_image->rows;
4188 shadow_image->page.width+=x_offset-(long) border_info.width;
4189 shadow_image->page.height+=y_offset-(long) border_info.height;
4190 shadow_image->page.x+=x_offset-(long) border_info.width;
4191 shadow_image->page.y+=y_offset-(long) border_info.height;
4192 return(shadow_image);
4196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4200 % S k e t c h I m a g e %
4204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4206 % SketchImage() simulates a pencil sketch. We convolve the image with a
4207 % Gaussian operator of the given radius and standard deviation (sigma). For
4208 % reasonable results, radius should be larger than sigma. Use a radius of 0
4209 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4212 % The format of the SketchImage method is:
4214 % Image *SketchImage(const Image *image,const double radius,
4215 % const double sigma,const double angle,ExceptionInfo *exception)
4217 % A description of each parameter follows:
4219 % o image: the image.
4221 % o radius: the radius of the Gaussian, in pixels, not counting
4224 % o sigma: the standard deviation of the Gaussian, in pixels.
4226 % o angle: Apply the effect along this angle.
4228 % o exception: return any errors or warnings in this structure.
4231 MagickExport Image *SketchImage(const Image *image,const double radius,
4232 const double sigma,const double angle,ExceptionInfo *exception)
4254 **restrict random_info;
4259 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4260 MagickTrue,exception);
4261 if (random_image == (Image *) NULL)
4262 return((Image *) NULL);
4264 GetMagickPixelPacket(random_image,&zero);
4265 random_info=AcquireRandomInfoThreadSet();
4266 random_view=AcquireCacheView(random_image);
4267 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4268 #pragma omp parallel for schedule(dynamic,4) shared(status)
4270 for (y=0; y < (long) random_image->rows; y++)
4275 register IndexPacket
4282 register PixelPacket
4285 if (status == MagickFalse)
4287 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4289 if (q == (PixelPacket *) NULL)
4294 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4296 id=GetOpenMPThreadId();
4297 for (x=0; x < (long) random_image->columns; x++)
4299 pixel.red=(MagickRealType) (QuantumRange*
4300 GetPseudoRandomValue(random_info[id]));
4301 pixel.green=pixel.red;
4302 pixel.blue=pixel.red;
4303 if (image->colorspace == CMYKColorspace)
4304 pixel.index=pixel.red;
4305 SetPixelPacket(random_image,&pixel,q,indexes+x);
4308 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4311 random_view=DestroyCacheView(random_view);
4312 random_info=DestroyRandomInfoThreadSet(random_info);
4313 if (status == MagickFalse)
4315 random_image=DestroyImage(random_image);
4316 return(random_image);
4318 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4319 random_image=DestroyImage(random_image);
4320 if (blur_image == (Image *) NULL)
4321 return((Image *) NULL);
4322 dodge_image=EdgeImage(blur_image,radius,exception);
4323 blur_image=DestroyImage(blur_image);
4324 if (dodge_image == (Image *) NULL)
4325 return((Image *) NULL);
4326 (void) NormalizeImage(dodge_image);
4327 (void) NegateImage(dodge_image,MagickFalse);
4328 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4329 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4330 if (sketch_image == (Image *) NULL)
4332 dodge_image=DestroyImage(dodge_image);
4333 return((Image *) NULL);
4335 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4336 dodge_image=DestroyImage(dodge_image);
4337 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4338 if (blend_image == (Image *) NULL)
4340 sketch_image=DestroyImage(sketch_image);
4341 return((Image *) NULL);
4343 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4344 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4345 blend_image=DestroyImage(blend_image);
4346 return(sketch_image);
4350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4354 % S o l a r i z e I m a g e %
4358 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4360 % SolarizeImage() applies a special effect to the image, similar to the effect
4361 % achieved in a photo darkroom by selectively exposing areas of photo
4362 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4363 % measure of the extent of the solarization.
4365 % The format of the SolarizeImage method is:
4367 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4369 % A description of each parameter follows:
4371 % o image: the image.
4373 % o threshold: Define the extent of the solarization.
4376 MagickExport MagickBooleanType SolarizeImage(Image *image,
4377 const double threshold)
4379 #define SolarizeImageTag "Solarize/Image"
4394 assert(image != (Image *) NULL);
4395 assert(image->signature == MagickSignature);
4396 if (image->debug != MagickFalse)
4397 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4398 if (image->storage_class == PseudoClass)
4406 for (i=0; i < (long) image->colors; i++)
4408 if ((MagickRealType) image->colormap[i].red > threshold)
4409 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4410 if ((MagickRealType) image->colormap[i].green > threshold)
4411 image->colormap[i].green=(Quantum) QuantumRange-
4412 image->colormap[i].green;
4413 if ((MagickRealType) image->colormap[i].blue > threshold)
4414 image->colormap[i].blue=(Quantum) QuantumRange-
4415 image->colormap[i].blue;
4423 exception=(&image->exception);
4424 image_view=AcquireCacheView(image);
4425 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4426 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4428 for (y=0; y < (long) image->rows; y++)
4433 register PixelPacket
4436 if (status == MagickFalse)
4438 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4440 if (q == (PixelPacket *) NULL)
4445 for (x=0; x < (long) image->columns; x++)
4447 if ((MagickRealType) q->red > threshold)
4448 q->red=(Quantum) QuantumRange-q->red;
4449 if ((MagickRealType) q->green > threshold)
4450 q->green=(Quantum) QuantumRange-q->green;
4451 if ((MagickRealType) q->blue > threshold)
4452 q->blue=(Quantum) QuantumRange-q->blue;
4455 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4457 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4462 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4463 #pragma omp critical (MagickCore_SolarizeImage)
4465 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4466 if (proceed == MagickFalse)
4470 image_view=DestroyCacheView(image_view);
4475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4479 % S t e g a n o I m a g e %
4483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4485 % SteganoImage() hides a digital watermark within the image. Recover
4486 % the hidden watermark later to prove that the authenticity of an image.
4487 % Offset defines the start position within the image to hide the watermark.
4489 % The format of the SteganoImage method is:
4491 % Image *SteganoImage(const Image *image,Image *watermark,
4492 % ExceptionInfo *exception)
4494 % A description of each parameter follows:
4496 % o image: the image.
4498 % o watermark: the watermark image.
4500 % o exception: return any errors or warnings in this structure.
4503 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4504 ExceptionInfo *exception)
4506 #define GetBit(alpha,i) ((((unsigned long) (alpha) >> (unsigned long) \
4508 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) ? (unsigned long) (alpha) \
4509 | (1UL << (unsigned long) (i)) : (unsigned long) (alpha) & \
4510 ~(1UL << (unsigned long) (i)))
4511 #define SteganoImageTag "Stegano/Image"
4534 register PixelPacket
4541 Initialize steganographic image attributes.
4543 assert(image != (const Image *) NULL);
4544 assert(image->signature == MagickSignature);
4545 if (image->debug != MagickFalse)
4546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4547 assert(watermark != (const Image *) NULL);
4548 assert(watermark->signature == MagickSignature);
4549 assert(exception != (ExceptionInfo *) NULL);
4550 assert(exception->signature == MagickSignature);
4551 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4552 if (stegano_image == (Image *) NULL)
4553 return((Image *) NULL);
4554 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4556 InheritException(exception,&stegano_image->exception);
4557 stegano_image=DestroyImage(stegano_image);
4558 return((Image *) NULL);
4560 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4562 Hide watermark in low-order bits of image.
4567 depth=stegano_image->depth;
4569 for (i=(long) depth-1; (i >= 0) && (j < (long) depth); i--)
4571 for (y=0; (y < (long) watermark->rows) && (j < (long) depth); y++)
4573 for (x=0; (x < (long) watermark->columns) && (j < (long) depth); x++)
4575 (void) GetOneVirtualPixel(watermark,x,y,&pixel,exception);
4576 if ((k/(long) stegano_image->columns) >= (long) stegano_image->rows)
4578 q=GetAuthenticPixels(stegano_image,k % (long) stegano_image->columns,
4579 k/(long) stegano_image->columns,1,1,exception);
4580 if (q == (PixelPacket *) NULL)
4586 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4591 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4596 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4600 if (SyncAuthenticPixels(stegano_image,exception) == MagickFalse)
4606 if (k == (long) (stegano_image->columns*stegano_image->columns))
4608 if (k == image->offset)
4612 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4617 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4619 if (proceed == MagickFalse)
4623 if (stegano_image->storage_class == PseudoClass)
4624 (void) SyncImage(stegano_image);
4625 return(stegano_image);
4629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4633 % S t e r e o A n a g l y p h I m a g e %
4637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4639 % StereoAnaglyphImage() combines two images and produces a single image that
4640 % is the composite of a left and right image of a stereo pair. Special
4641 % red-green stereo glasses are required to view this effect.
4643 % The format of the StereoAnaglyphImage method is:
4645 % Image *StereoImage(const Image *left_image,const Image *right_image,
4646 % ExceptionInfo *exception)
4647 % Image *StereoAnaglyphImage(const Image *left_image,
4648 % const Image *right_image,const long x_offset,const long y_offset,
4649 % ExceptionInfo *exception)
4651 % A description of each parameter follows:
4653 % o left_image: the left image.
4655 % o right_image: the right image.
4657 % o exception: return any errors or warnings in this structure.
4659 % o x_offset: amount, in pixels, by which the left image is offset to the
4660 % right of the right image.
4662 % o y_offset: amount, in pixels, by which the left image is offset to the
4663 % bottom of the right image.
4667 MagickExport Image *StereoImage(const Image *left_image,
4668 const Image *right_image,ExceptionInfo *exception)
4670 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4673 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4674 const Image *right_image,const long x_offset,const long y_offset,
4675 ExceptionInfo *exception)
4677 #define StereoImageTag "Stereo/Image"
4691 assert(left_image != (const Image *) NULL);
4692 assert(left_image->signature == MagickSignature);
4693 if (left_image->debug != MagickFalse)
4694 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4695 left_image->filename);
4696 assert(right_image != (const Image *) NULL);
4697 assert(right_image->signature == MagickSignature);
4698 assert(exception != (ExceptionInfo *) NULL);
4699 assert(exception->signature == MagickSignature);
4700 assert(right_image != (const Image *) NULL);
4702 if ((left_image->columns != right_image->columns) ||
4703 (left_image->rows != right_image->rows))
4704 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4706 Initialize stereo image attributes.
4708 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4709 MagickTrue,exception);
4710 if (stereo_image == (Image *) NULL)
4711 return((Image *) NULL);
4712 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4714 InheritException(exception,&stereo_image->exception);
4715 stereo_image=DestroyImage(stereo_image);
4716 return((Image *) NULL);
4719 Copy left image to red channel and right image to blue channel.
4721 for (y=0; y < (long) stereo_image->rows; y++)
4723 register const PixelPacket
4730 register PixelPacket
4733 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4735 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4736 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4737 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4738 (r == (PixelPacket *) NULL))
4740 for (x=0; x < (long) stereo_image->columns; x++)
4742 r->red=GetRedPixelComponent(p);
4745 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4750 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4752 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4757 proceed=SetImageProgress(image,StereoImageTag,y,stereo_image->rows);
4758 if (proceed == MagickFalse)
4762 return(stereo_image);
4766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4770 % S w i r l I m a g e %
4774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4776 % SwirlImage() swirls the pixels about the center of the image, where
4777 % degrees indicates the sweep of the arc through which each pixel is moved.
4778 % You get a more dramatic effect as the degrees move from 1 to 360.
4780 % The format of the SwirlImage method is:
4782 % Image *SwirlImage(const Image *image,double degrees,
4783 % ExceptionInfo *exception)
4785 % A description of each parameter follows:
4787 % o image: the image.
4789 % o degrees: Define the tightness of the swirling effect.
4791 % o exception: return any errors or warnings in this structure.
4794 MagickExport Image *SwirlImage(const Image *image,double degrees,
4795 ExceptionInfo *exception)
4797 #define SwirlImageTag "Swirl/Image"
4824 **restrict resample_filter;
4827 Initialize swirl image attributes.
4829 assert(image != (const Image *) NULL);
4830 assert(image->signature == MagickSignature);
4831 if (image->debug != MagickFalse)
4832 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4833 assert(exception != (ExceptionInfo *) NULL);
4834 assert(exception->signature == MagickSignature);
4835 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4836 if (swirl_image == (Image *) NULL)
4837 return((Image *) NULL);
4838 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4840 InheritException(exception,&swirl_image->exception);
4841 swirl_image=DestroyImage(swirl_image);
4842 return((Image *) NULL);
4844 if (swirl_image->background_color.opacity != OpaqueOpacity)
4845 swirl_image->matte=MagickTrue;
4847 Compute scaling factor.
4849 center.x=(double) image->columns/2.0;
4850 center.y=(double) image->rows/2.0;
4851 radius=MagickMax(center.x,center.y);
4854 if (image->columns > image->rows)
4855 scale.y=(double) image->columns/(double) image->rows;
4857 if (image->columns < image->rows)
4858 scale.x=(double) image->rows/(double) image->columns;
4859 degrees=(double) DegreesToRadians(degrees);
4865 GetMagickPixelPacket(swirl_image,&zero);
4866 resample_filter=AcquireResampleFilterThreadSet(image,
4867 UndefinedVirtualPixelMethod,MagickTrue,exception);
4868 image_view=AcquireCacheView(image);
4869 swirl_view=AcquireCacheView(swirl_image);
4870 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4871 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4873 for (y=0; y < (long) image->rows; y++)
4884 register IndexPacket
4885 *restrict swirl_indexes;
4891 register PixelPacket
4894 if (status == MagickFalse)
4896 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4898 if (q == (PixelPacket *) NULL)
4903 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4904 delta.y=scale.y*(double) (y-center.y);
4906 id=GetOpenMPThreadId();
4907 for (x=0; x < (long) image->columns; x++)
4910 Determine if the pixel is within an ellipse.
4912 delta.x=scale.x*(double) (x-center.x);
4913 distance=delta.x*delta.x+delta.y*delta.y;
4914 if (distance < (radius*radius))
4924 factor=1.0-sqrt((double) distance)/radius;
4925 sine=sin((double) (degrees*factor*factor));
4926 cosine=cos((double) (degrees*factor*factor));
4927 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4928 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4929 cosine*delta.y)/scale.y+center.y),&pixel);
4930 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4934 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4936 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4941 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4942 #pragma omp critical (MagickCore_SwirlImage)
4944 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4945 if (proceed == MagickFalse)
4949 swirl_view=DestroyCacheView(swirl_view);
4950 image_view=DestroyCacheView(image_view);
4951 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
4952 if (status == MagickFalse)
4953 swirl_image=DestroyImage(swirl_image);
4954 return(swirl_image);
4958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4962 % T i n t I m a g e %
4966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4968 % TintImage() applies a color vector to each pixel in the image. The length
4969 % of the vector is 0 for black and white and at its maximum for the midtones.
4970 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
4972 % The format of the TintImage method is:
4974 % Image *TintImage(const Image *image,const char *opacity,
4975 % const PixelPacket tint,ExceptionInfo *exception)
4977 % A description of each parameter follows:
4979 % o image: the image.
4981 % o opacity: A color value used for tinting.
4983 % o tint: A color value used for tinting.
4985 % o exception: return any errors or warnings in this structure.
4988 MagickExport Image *TintImage(const Image *image,const char *opacity,
4989 const PixelPacket tint,ExceptionInfo *exception)
4991 #define TintImageTag "Tint/Image"
5018 Allocate tint image.
5020 assert(image != (const Image *) NULL);
5021 assert(image->signature == MagickSignature);
5022 if (image->debug != MagickFalse)
5023 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5024 assert(exception != (ExceptionInfo *) NULL);
5025 assert(exception->signature == MagickSignature);
5026 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5027 if (tint_image == (Image *) NULL)
5028 return((Image *) NULL);
5029 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5031 InheritException(exception,&tint_image->exception);
5032 tint_image=DestroyImage(tint_image);
5033 return((Image *) NULL);
5035 if (opacity == (const char *) NULL)
5038 Determine RGB values of the color.
5040 flags=ParseGeometry(opacity,&geometry_info);
5041 pixel.red=geometry_info.rho;
5042 if ((flags & SigmaValue) != 0)
5043 pixel.green=geometry_info.sigma;
5045 pixel.green=pixel.red;
5046 if ((flags & XiValue) != 0)
5047 pixel.blue=geometry_info.xi;
5049 pixel.blue=pixel.red;
5050 if ((flags & PsiValue) != 0)
5051 pixel.opacity=geometry_info.psi;
5053 pixel.opacity=(MagickRealType) OpaqueOpacity;
5054 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5055 PixelIntensity(&tint));
5056 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5057 PixelIntensity(&tint));
5058 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5059 PixelIntensity(&tint));
5065 image_view=AcquireCacheView(image);
5066 tint_view=AcquireCacheView(tint_image);
5067 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5068 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5070 for (y=0; y < (long) image->rows; y++)
5072 register const PixelPacket
5078 register PixelPacket
5081 if (status == MagickFalse)
5083 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5084 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5086 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5091 for (x=0; x < (long) image->columns; x++)
5099 weight=QuantumScale*p->red-0.5;
5100 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5102 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5103 weight=QuantumScale*p->green-0.5;
5104 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5106 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5107 weight=QuantumScale*p->blue-0.5;
5108 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5110 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5111 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5115 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5117 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5122 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5123 #pragma omp critical (MagickCore_TintImage)
5125 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5126 if (proceed == MagickFalse)
5130 tint_view=DestroyCacheView(tint_view);
5131 image_view=DestroyCacheView(image_view);
5132 if (status == MagickFalse)
5133 tint_image=DestroyImage(tint_image);
5138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5142 % V i g n e t t e I m a g e %
5146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5148 % VignetteImage() softens the edges of the image in vignette style.
5150 % The format of the VignetteImage method is:
5152 % Image *VignetteImage(const Image *image,const double radius,
5153 % const double sigma,const long x,const long y,ExceptionInfo *exception)
5155 % A description of each parameter follows:
5157 % o image: the image.
5159 % o radius: the radius of the pixel neighborhood.
5161 % o sigma: the standard deviation of the Gaussian, in pixels.
5163 % o x, y: Define the x and y ellipse offset.
5165 % o exception: return any errors or warnings in this structure.
5168 MagickExport Image *VignetteImage(const Image *image,const double radius,
5169 const double sigma,const long x,const long y,ExceptionInfo *exception)
5172 ellipse[MaxTextExtent];
5183 assert(image != (Image *) NULL);
5184 assert(image->signature == MagickSignature);
5185 if (image->debug != MagickFalse)
5186 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5187 assert(exception != (ExceptionInfo *) NULL);
5188 assert(exception->signature == MagickSignature);
5189 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5190 if (canvas_image == (Image *) NULL)
5191 return((Image *) NULL);
5192 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5194 InheritException(exception,&canvas_image->exception);
5195 canvas_image=DestroyImage(canvas_image);
5196 return((Image *) NULL);
5198 canvas_image->matte=MagickTrue;
5199 oval_image=CloneImage(canvas_image,canvas_image->columns,
5200 canvas_image->rows,MagickTrue,exception);
5201 if (oval_image == (Image *) NULL)
5203 canvas_image=DestroyImage(canvas_image);
5204 return((Image *) NULL);
5206 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5207 (void) SetImageBackgroundColor(oval_image);
5208 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5209 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5210 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5211 (void) FormatMagickString(ellipse,MaxTextExtent,
5212 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5213 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5214 draw_info->primitive=AcquireString(ellipse);
5215 (void) DrawImage(oval_image,draw_info);
5216 draw_info=DestroyDrawInfo(draw_info);
5217 blur_image=BlurImage(oval_image,radius,sigma,exception);
5218 oval_image=DestroyImage(oval_image);
5219 if (blur_image == (Image *) NULL)
5221 canvas_image=DestroyImage(canvas_image);
5222 return((Image *) NULL);
5224 blur_image->matte=MagickFalse;
5225 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5226 blur_image=DestroyImage(blur_image);
5227 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5228 canvas_image=DestroyImage(canvas_image);
5229 return(vignette_image);
5233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5237 % W a v e I m a g e %
5241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5243 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5244 % vertically along a sine wave whose amplitude and wavelength is specified
5245 % by the given parameters.
5247 % The format of the WaveImage method is:
5249 % Image *WaveImage(const Image *image,const double amplitude,
5250 % const double wave_length,ExceptionInfo *exception)
5252 % A description of each parameter follows:
5254 % o image: the image.
5256 % o amplitude, wave_length: Define the amplitude and wave length of the
5259 % o exception: return any errors or warnings in this structure.
5262 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5263 const double wave_length,ExceptionInfo *exception)
5265 #define WaveImageTag "Wave/Image"
5290 **restrict resample_filter;
5293 Initialize wave image attributes.
5295 assert(image != (Image *) NULL);
5296 assert(image->signature == MagickSignature);
5297 if (image->debug != MagickFalse)
5298 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5299 assert(exception != (ExceptionInfo *) NULL);
5300 assert(exception->signature == MagickSignature);
5301 wave_image=CloneImage(image,image->columns,(unsigned long) (image->rows+2.0*
5302 fabs(amplitude)),MagickTrue,exception);
5303 if (wave_image == (Image *) NULL)
5304 return((Image *) NULL);
5305 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5307 InheritException(exception,&wave_image->exception);
5308 wave_image=DestroyImage(wave_image);
5309 return((Image *) NULL);
5311 if (wave_image->background_color.opacity != OpaqueOpacity)
5312 wave_image->matte=MagickTrue;
5316 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5318 if (sine_map == (MagickRealType *) NULL)
5320 wave_image=DestroyImage(wave_image);
5321 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5323 for (i=0; i < (long) wave_image->columns; i++)
5324 sine_map[i]=fabs(amplitude)+amplitude*sin((2*MagickPI*i)/wave_length);
5330 GetMagickPixelPacket(wave_image,&zero);
5331 resample_filter=AcquireResampleFilterThreadSet(image,
5332 BackgroundVirtualPixelMethod,MagickTrue,exception);
5333 wave_view=AcquireCacheView(wave_image);
5334 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5335 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5337 for (y=0; y < (long) wave_image->rows; y++)
5342 register IndexPacket
5349 register PixelPacket
5352 if (status == MagickFalse)
5354 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5356 if (q == (PixelPacket *) NULL)
5361 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5363 id=GetOpenMPThreadId();
5364 for (x=0; x < (long) wave_image->columns; x++)
5366 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5367 sine_map[x]),&pixel);
5368 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5371 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5373 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5378 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5379 #pragma omp critical (MagickCore_WaveImage)
5381 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5382 if (proceed == MagickFalse)
5386 wave_view=DestroyCacheView(wave_view);
5387 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5388 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5389 if (status == MagickFalse)
5390 wave_image=DestroyImage(wave_image);