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 % C o l o r M a t r i x I m a g e %
814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 % ColorMatrixImage() applies color transformation to an image. This method
817 % permits saturation changes, hue rotation, luminance to alpha, and various
818 % other effects. Although variable-sized transformation matrices can be used,
819 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
820 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
821 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
822 % and offsets are normalized (divide Flash offset by 255).
824 % The format of the ColorMatrixImage method is:
826 % Image *ColorMatrixImage(const Image *image,
827 % const KernelInfo *color_matrix,ExceptionInfo *exception)
829 % A description of each parameter follows:
831 % o image: the image.
833 % o color_matrix: the color matrix.
835 % o exception: return any errors or warnings in this structure.
838 MagickExport Image *ColorMatrixImage(const Image *image,
839 const KernelInfo *color_matrix,ExceptionInfo *exception)
841 #define ColorMatrixImageTag "ColorMatrix/Image"
850 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
851 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
852 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
853 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
854 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
855 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
876 assert(image != (Image *) NULL);
877 assert(image->signature == MagickSignature);
878 if (image->debug != MagickFalse)
879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
880 assert(exception != (ExceptionInfo *) NULL);
881 assert(exception->signature == MagickSignature);
883 for (v=0; v < (long) color_matrix->height; v++)
884 for (u=0; u < (long) color_matrix->width; u++)
886 if ((v < 6) && (u < 6))
887 ColorMatrix[v][u]=color_matrix->values[i];
891 Initialize color image.
893 color_image=CloneImage(image,0,0,MagickTrue,exception);
894 if (color_image == (Image *) NULL)
895 return((Image *) NULL);
896 if (SetImageStorageClass(color_image,DirectClass) == MagickFalse)
898 InheritException(exception,&color_image->exception);
899 color_image=DestroyImage(color_image);
900 return((Image *) NULL);
902 if (image->debug != MagickFalse)
905 format[MaxTextExtent],
908 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
909 " ColorMatrix image with color matrix:");
910 message=AcquireString("");
911 for (v=0; v < 6; v++)
914 (void) FormatMagickString(format,MaxTextExtent,"%ld: ",v);
915 (void) ConcatenateString(&message,format);
916 for (u=0; u < 6; u++)
918 (void) FormatMagickString(format,MaxTextExtent,"%+f ",
920 (void) ConcatenateString(&message,format);
922 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
924 message=DestroyString(message);
931 image_view=AcquireCacheView(image);
932 color_view=AcquireCacheView(color_image);
933 #if defined(MAGICKCORE_OPENMP_SUPPORT)
934 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
936 for (y=0; y < (long) image->rows; y++)
941 register const IndexPacket
944 register const PixelPacket
951 *restrict color_indexes;
956 if (status == MagickFalse)
958 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
959 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
961 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
966 indexes=GetCacheViewVirtualIndexQueue(image_view);
967 color_indexes=GetCacheViewAuthenticIndexQueue(color_view);
968 for (x=0; x < (long) image->columns; x++)
976 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
977 for (v=0; v < (long) height; v++)
979 pixel=ColorMatrix[v][0]*p->red+ColorMatrix[v][1]*p->green+
980 ColorMatrix[v][2]*p->blue;
981 if (image->matte != MagickFalse)
982 pixel+=ColorMatrix[v][3]*(QuantumRange-p->opacity);
983 if (image->colorspace == CMYKColorspace)
984 pixel+=ColorMatrix[v][4]*indexes[x];
985 pixel+=QuantumRange*ColorMatrix[v][5];
988 case 0: q->red=ClampToQuantum(pixel); break;
989 case 1: q->green=ClampToQuantum(pixel); break;
990 case 2: q->blue=ClampToQuantum(pixel); break;
993 if (image->matte != MagickFalse)
994 q->opacity=ClampToQuantum(QuantumRange-pixel);
999 if (image->colorspace == CMYKColorspace)
1000 color_indexes[x]=ClampToQuantum(pixel);
1008 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1010 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1015 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1016 #pragma omp critical (MagickCore_ColorMatrixImage)
1018 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1020 if (proceed == MagickFalse)
1024 color_view=DestroyCacheView(color_view);
1025 image_view=DestroyCacheView(image_view);
1026 if (status == MagickFalse)
1027 color_image=DestroyImage(color_image);
1028 return(color_image);
1032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1036 + D e s t r o y F x I n f o %
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1044 % The format of the DestroyFxInfo method is:
1046 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1048 % A description of each parameter follows:
1050 % o fx_info: the fx info.
1053 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1058 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1059 fx_info->expression=DestroyString(fx_info->expression);
1060 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1061 fx_info->colors=DestroySplayTree(fx_info->colors);
1062 for (i=0; i < (long) GetImageListLength(fx_info->images); i++)
1063 fx_info->resample_filter[i]=DestroyResampleFilter(
1064 fx_info->resample_filter[i]);
1065 fx_info->resample_filter=(ResampleFilter **) RelinquishMagickMemory(
1066 fx_info->resample_filter);
1067 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1068 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077 + 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 %
1081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1083 % FxEvaluateChannelExpression() evaluates an expression and returns the
1086 % The format of the FxEvaluateExpression method is:
1088 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1089 % const ChannelType channel,const long x,const long y,
1090 % MagickRealType *alpha,Exceptioninfo *exception)
1091 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1092 % MagickRealType *alpha,Exceptioninfo *exception)
1094 % A description of each parameter follows:
1096 % o fx_info: the fx info.
1098 % o channel: the channel.
1100 % o x,y: the pixel position.
1102 % o alpha: the result.
1104 % o exception: return any errors or warnings in this structure.
1108 static inline double MagickMax(const double x,const double y)
1115 static inline double MagickMin(const double x,const double y)
1122 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1123 ChannelType channel,const char *symbol,ExceptionInfo *exception)
1127 statistic[MaxTextExtent];
1135 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1137 switch (*++p) /* e.g. depth.r */
1139 case 'r': channel=RedChannel; break;
1140 case 'g': channel=GreenChannel; break;
1141 case 'b': channel=BlueChannel; break;
1142 case 'c': channel=CyanChannel; break;
1143 case 'm': channel=MagentaChannel; break;
1144 case 'y': channel=YellowChannel; break;
1145 case 'k': channel=BlackChannel; break;
1148 (void) FormatMagickString(key,MaxTextExtent,"%p.%ld.%s",(void *) image,
1149 (long) channel,symbol);
1150 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1151 if (value != (const char *) NULL)
1152 return(QuantumScale*StringToDouble(value));
1153 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1154 if (LocaleNCompare(symbol,"depth",5) == 0)
1159 depth=GetImageChannelDepth(image,channel,exception);
1160 (void) FormatMagickString(statistic,MaxTextExtent,"%lu",depth);
1162 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1168 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1170 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
1172 if (LocaleNCompare(symbol,"maxima",6) == 0)
1178 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1179 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
1181 if (LocaleNCompare(symbol,"mean",4) == 0)
1187 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1189 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
1191 if (LocaleNCompare(symbol,"minima",6) == 0)
1197 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1198 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
1200 if (LocaleNCompare(symbol,"skewness",8) == 0)
1206 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1208 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
1210 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1216 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1218 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
1219 standard_deviation);
1221 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1222 ConstantString(statistic));
1223 return(QuantumScale*StringToDouble(statistic));
1226 static MagickRealType
1227 FxEvaluateSubexpression(FxInfo *,const ChannelType,const long,const long,
1228 const char *,MagickRealType *,ExceptionInfo *);
1230 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1231 const long x,const long y,const char *expression,ExceptionInfo *exception)
1237 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1238 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1241 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1242 const long x,const long y,const char *expression,ExceptionInfo *exception)
1248 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1249 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1252 static inline const char *FxSubexpression(const char *expression,
1253 ExceptionInfo *exception)
1262 subexpression=expression;
1263 while ((*subexpression != '\0') &&
1264 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1266 if (strchr("(",(int) *subexpression) != (char *) NULL)
1269 if (strchr(")",(int) *subexpression) != (char *) NULL)
1273 if (*subexpression == '\0')
1274 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1275 "UnbalancedParenthesis","`%s'",expression);
1276 return(subexpression);
1279 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1280 const long x,const long y,const char *expression,ExceptionInfo *exception)
1284 subexpression[MaxTextExtent],
1285 symbol[MaxTextExtent];
1314 i=GetImageIndexInList(fx_info->images);
1318 if (isalpha((int) *(p+1)) == 0)
1320 if (strchr("suv",(int) *p) != (char *) NULL)
1327 i=GetImageIndexInList(fx_info->images);
1330 case 'u': i=0; break;
1331 case 'v': i=1; break;
1338 for (p++; *p != '\0'; )
1352 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1354 i=(long) (alpha+0.5);
1360 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1367 for (p++; *p != '\0'; )
1381 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1392 for (p++; *p != '\0'; )
1406 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1416 length=GetImageListLength(fx_info->images);
1420 image=GetImageFromList(fx_info->images,i);
1421 if (image == (Image *) NULL)
1423 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1424 "NoSuchImage","`%s'",expression);
1427 (void) ResamplePixelColor(fx_info->resample_filter[i],point.x,point.y,&pixel);
1428 if ((strlen(p) > 2) &&
1429 (LocaleCompare(p,"intensity") != 0) &&
1430 (LocaleCompare(p,"luminance") != 0) &&
1431 (LocaleCompare(p,"hue") != 0) &&
1432 (LocaleCompare(p,"saturation") != 0) &&
1433 (LocaleCompare(p,"lightness") != 0))
1436 name[MaxTextExtent];
1438 (void) CopyMagickString(name,p,MaxTextExtent);
1439 for (q=name+(strlen(name)-1); q > name; q--)
1449 if ((strlen(name) > 2) &&
1450 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1455 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1457 if (color != (MagickPixelPacket *) NULL)
1463 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1465 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1466 CloneMagickPixelPacket(&pixel));
1471 (void) CopyMagickString(symbol,p,MaxTextExtent);
1472 StripString(symbol);
1473 if (*symbol == '\0')
1477 case RedChannel: return(QuantumScale*pixel.red);
1478 case GreenChannel: return(QuantumScale*pixel.green);
1479 case BlueChannel: return(QuantumScale*pixel.blue);
1480 case OpacityChannel:
1482 if (pixel.matte == MagickFalse)
1484 fx_info->matte=MagickFalse;
1487 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1491 if (image->colorspace != CMYKColorspace)
1493 (void) ThrowMagickException(exception,GetMagickModule(),
1494 OptionError,"ColorSeparatedImageRequired","`%s'",
1498 return(QuantumScale*pixel.index);
1503 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1504 "UnableToParseExpression","`%s'",p);
1512 if (LocaleCompare(symbol,"a") == 0)
1513 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1519 if (LocaleCompare(symbol,"b") == 0)
1520 return(QuantumScale*pixel.blue);
1526 if (LocaleNCompare(symbol,"channel",7) == 0)
1534 flags=ParseGeometry(symbol+7,&channel_info);
1535 if (image->colorspace == CMYKColorspace)
1540 if ((flags & RhoValue) == 0)
1542 return(channel_info.rho);
1544 case MagentaChannel:
1546 if ((flags & SigmaValue) == 0)
1548 return(channel_info.sigma);
1552 if ((flags & XiValue) == 0)
1554 return(channel_info.xi);
1558 if ((flags & PsiValue) == 0)
1560 return(channel_info.psi);
1562 case OpacityChannel:
1564 if ((flags & ChiValue) == 0)
1566 return(channel_info.chi);
1575 if ((flags & RhoValue) == 0)
1577 return(channel_info.rho);
1581 if ((flags & SigmaValue) == 0)
1583 return(channel_info.sigma);
1587 if ((flags & XiValue) == 0)
1589 return(channel_info.xi);
1591 case OpacityChannel:
1593 if ((flags & PsiValue) == 0)
1595 return(channel_info.psi);
1599 if ((flags & ChiValue) == 0)
1601 return(channel_info.chi);
1608 if (LocaleCompare(symbol,"c") == 0)
1609 return(QuantumScale*pixel.red);
1615 if (LocaleNCompare(symbol,"depth",5) == 0)
1616 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1622 if (LocaleCompare(symbol,"g") == 0)
1623 return(QuantumScale*pixel.green);
1629 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1630 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1631 if (LocaleCompare(symbol,"k") == 0)
1633 if (image->colorspace != CMYKColorspace)
1635 (void) ThrowMagickException(exception,GetMagickModule(),
1636 OptionError,"ColorSeparatedImageRequired","`%s'",
1640 return(QuantumScale*pixel.index);
1647 if (LocaleCompare(symbol,"h") == 0)
1648 return((MagickRealType) image->rows);
1649 if (LocaleCompare(symbol,"hue") == 0)
1656 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1657 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1665 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1666 (LocaleCompare(symbol,"image.minima") == 0) ||
1667 (LocaleCompare(symbol,"image.maxima") == 0) ||
1668 (LocaleCompare(symbol,"image.mean") == 0) ||
1669 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1670 (LocaleCompare(symbol,"image.skewness") == 0) ||
1671 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1672 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1673 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1674 return(image->x_resolution);
1675 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1676 return(image->y_resolution);
1677 if (LocaleCompare(symbol,"intensity") == 0)
1678 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1679 if (LocaleCompare(symbol,"i") == 0)
1680 return((MagickRealType) x);
1686 if (LocaleCompare(symbol,"j") == 0)
1687 return((MagickRealType) y);
1693 if (LocaleCompare(symbol,"lightness") == 0)
1700 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1701 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1704 if (LocaleCompare(symbol,"luminance") == 0)
1709 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1710 return(QuantumScale*luminence);
1717 if (LocaleNCompare(symbol,"maxima",6) == 0)
1718 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1719 if (LocaleNCompare(symbol,"mean",4) == 0)
1720 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1721 if (LocaleNCompare(symbol,"minima",6) == 0)
1722 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1723 if (LocaleCompare(symbol,"m") == 0)
1724 return(QuantumScale*pixel.blue);
1730 if (LocaleCompare(symbol,"n") == 0)
1731 return((MagickRealType) GetImageListLength(fx_info->images));
1737 if (LocaleCompare(symbol,"o") == 0)
1738 return(QuantumScale*pixel.opacity);
1744 if (LocaleCompare(symbol,"page.height") == 0)
1745 return((MagickRealType) image->page.height);
1746 if (LocaleCompare(symbol,"page.width") == 0)
1747 return((MagickRealType) image->page.width);
1748 if (LocaleCompare(symbol,"page.x") == 0)
1749 return((MagickRealType) image->page.x);
1750 if (LocaleCompare(symbol,"page.y") == 0)
1751 return((MagickRealType) image->page.y);
1757 if (LocaleCompare(symbol,"resolution.x") == 0)
1758 return(image->x_resolution);
1759 if (LocaleCompare(symbol,"resolution.y") == 0)
1760 return(image->y_resolution);
1761 if (LocaleCompare(symbol,"r") == 0)
1762 return(QuantumScale*pixel.red);
1768 if (LocaleCompare(symbol,"saturation") == 0)
1775 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1776 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1779 if (LocaleNCompare(symbol,"skewness",8) == 0)
1780 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1781 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1782 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1788 if (LocaleCompare(symbol,"t") == 0)
1789 return((MagickRealType) fx_info->images->scene);
1795 if (LocaleCompare(symbol,"w") == 0)
1796 return((MagickRealType) image->columns);
1802 if (LocaleCompare(symbol,"y") == 0)
1803 return(QuantumScale*pixel.green);
1809 if (LocaleCompare(symbol,"z") == 0)
1814 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1815 fx_info->exception);
1823 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1824 if (value != (const char *) NULL)
1825 return((MagickRealType) StringToDouble(value));
1826 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1827 "UnableToParseExpression","`%s'",symbol);
1831 static const char *FxOperatorPrecedence(const char *expression,
1832 ExceptionInfo *exception)
1836 UndefinedPrecedence,
1838 BitwiseComplementPrecedence,
1843 RelationalPrecedence,
1844 EquivalencyPrecedence,
1845 BitwiseAndPrecedence,
1846 BitwiseOrPrecedence,
1847 LogicalAndPrecedence,
1848 LogicalOrPrecedence,
1850 AssignmentPrecedence,
1870 subexpression=(const char *) NULL;
1871 target=NullPrecedence;
1872 while (*expression != '\0')
1874 precedence=UndefinedPrecedence;
1875 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1880 switch (*expression)
1885 if (LocaleNCompare(expression,"atan2",5) == 0)
1895 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1896 (LocaleNCompare(expression,"j1",2) == 0))
1906 if ((c == (int) '{') || (c == (int) '['))
1909 if ((c == (int) '}') || (c == (int) ']'))
1912 switch ((unsigned char) *expression)
1917 precedence=BitwiseComplementPrecedence;
1922 precedence=ExponentPrecedence;
1927 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1928 (strchr(")",c) != (char *) NULL))) &&
1929 (((islower((int) ((char) *expression)) != 0) ||
1930 (strchr("(",(int) *expression) != (char *) NULL)) ||
1931 ((isdigit((int) ((char) c)) == 0) &&
1932 (isdigit((int) ((char) *expression)) != 0))) &&
1933 (strchr("xy",(int) *expression) == (char *) NULL))
1934 precedence=MultiplyPrecedence;
1941 precedence=MultiplyPrecedence;
1947 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1949 precedence=AdditionPrecedence;
1952 case LeftShiftOperator:
1953 case RightShiftOperator:
1955 precedence=ShiftPrecedence;
1959 case LessThanEqualOperator:
1960 case GreaterThanEqualOperator:
1963 precedence=RelationalPrecedence;
1967 case NotEqualOperator:
1969 precedence=EquivalencyPrecedence;
1974 precedence=BitwiseAndPrecedence;
1979 precedence=BitwiseOrPrecedence;
1982 case LogicalAndOperator:
1984 precedence=LogicalAndPrecedence;
1987 case LogicalOrOperator:
1989 precedence=LogicalOrPrecedence;
1995 precedence=TernaryPrecedence;
2000 precedence=AssignmentPrecedence;
2005 precedence=CommaPrecedence;
2010 precedence=SeparatorPrecedence;
2014 if ((precedence == BitwiseComplementPrecedence) ||
2015 (precedence == TernaryPrecedence) ||
2016 (precedence == AssignmentPrecedence))
2018 if (precedence > target)
2021 Right-to-left associativity.
2024 subexpression=expression;
2028 if (precedence >= target)
2031 Left-to-right associativity.
2034 subexpression=expression;
2036 if (strchr("(",(int) *expression) != (char *) NULL)
2037 expression=FxSubexpression(expression,exception);
2038 c=(int) (*expression++);
2040 return(subexpression);
2043 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2044 const ChannelType channel,const long x,const long y,const char *expression,
2045 MagickRealType *beta,ExceptionInfo *exception)
2049 subexpression[MaxTextExtent];
2059 if (exception->severity != UndefinedException)
2061 while (isspace((int) *expression) != 0)
2063 if (*expression == '\0')
2065 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2066 "MissingExpression","`%s'",expression);
2069 p=FxOperatorPrecedence(expression,exception);
2070 if (p != (const char *) NULL)
2072 (void) CopyMagickString(subexpression,expression,(size_t)
2074 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2076 switch ((unsigned char) *p)
2080 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2081 *beta=(MagickRealType) (~(unsigned long) *beta);
2086 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2087 return(*beta == 0.0 ? 1.0 : 0.0);
2091 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2092 channel,x,y,++p,beta,exception));
2097 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2098 return(alpha*(*beta));
2102 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2105 if (exception->severity == UndefinedException)
2106 (void) ThrowMagickException(exception,GetMagickModule(),
2107 OptionError,"DivideByZero","`%s'",expression);
2110 return(alpha/(*beta));
2114 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2115 *beta=fabs(floor(((double) *beta)+0.5));
2118 (void) ThrowMagickException(exception,GetMagickModule(),
2119 OptionError,"DivideByZero","`%s'",expression);
2122 return(fmod((double) alpha,(double) *beta));
2126 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2127 return(alpha+(*beta));
2131 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2132 return(alpha-(*beta));
2134 case LeftShiftOperator:
2136 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2137 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) << (unsigned long)
2141 case RightShiftOperator:
2143 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2144 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) >> (unsigned long)
2150 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2151 return(alpha < *beta ? 1.0 : 0.0);
2153 case LessThanEqualOperator:
2155 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2156 return(alpha <= *beta ? 1.0 : 0.0);
2160 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2161 return(alpha > *beta ? 1.0 : 0.0);
2163 case GreaterThanEqualOperator:
2165 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2166 return(alpha >= *beta ? 1.0 : 0.0);
2170 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2171 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2173 case NotEqualOperator:
2175 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2176 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2180 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2181 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) & (unsigned long)
2187 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2188 *beta=(MagickRealType) ((unsigned long) (alpha+0.5) | (unsigned long)
2192 case LogicalAndOperator:
2194 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2195 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2198 case LogicalOrOperator:
2200 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2201 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2209 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2211 p=StringToken(":",&q);
2212 if (q == (char *) NULL)
2214 (void) ThrowMagickException(exception,GetMagickModule(),
2215 OptionError,"UnableToParseExpression","`%s'",subexpression);
2218 if (fabs((double) alpha) > MagickEpsilon)
2219 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2221 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2227 numeric[MaxTextExtent];
2230 while (isalpha((int) ((unsigned char) *q)) != 0)
2234 (void) ThrowMagickException(exception,GetMagickModule(),
2235 OptionError,"UnableToParseExpression","`%s'",subexpression);
2238 ClearMagickException(exception);
2239 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2240 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2242 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2243 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2244 subexpression),ConstantString(numeric));
2249 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2254 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2259 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2265 if (strchr("(",(int) *expression) != (char *) NULL)
2267 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2268 subexpression[strlen(subexpression)-1]='\0';
2269 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2273 switch (*expression)
2277 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2283 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2289 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2291 return((MagickRealType) (~(unsigned long) (gamma+0.5)));
2296 if (LocaleNCompare(expression,"abs",3) == 0)
2298 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2300 return((MagickRealType) fabs((double) alpha));
2302 if (LocaleNCompare(expression,"acos",4) == 0)
2304 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2306 return((MagickRealType) acos((double) alpha));
2308 #if defined(MAGICKCORE_HAVE_J1)
2309 if (LocaleNCompare(expression,"airy",4) == 0)
2311 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2315 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2316 return(gamma*gamma);
2319 if (LocaleNCompare(expression,"asin",4) == 0)
2321 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2323 return((MagickRealType) asin((double) alpha));
2325 if (LocaleNCompare(expression,"alt",3) == 0)
2327 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2329 return(((long) alpha) & 0x01 ? -1.0 : 1.0);
2331 if (LocaleNCompare(expression,"atan2",5) == 0)
2333 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2335 return((MagickRealType) atan2((double) alpha,(double) *beta));
2337 if (LocaleNCompare(expression,"atan",4) == 0)
2339 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2341 return((MagickRealType) atan((double) alpha));
2343 if (LocaleCompare(expression,"a") == 0)
2344 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2350 if (LocaleCompare(expression,"b") == 0)
2351 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2357 if (LocaleNCompare(expression,"ceil",4) == 0)
2359 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2361 return((MagickRealType) ceil((double) alpha));
2363 if (LocaleNCompare(expression,"cosh",4) == 0)
2365 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2367 return((MagickRealType) cosh((double) alpha));
2369 if (LocaleNCompare(expression,"cos",3) == 0)
2371 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2373 return((MagickRealType) cos((double) alpha));
2375 if (LocaleCompare(expression,"c") == 0)
2376 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2382 if (LocaleNCompare(expression,"debug",5) == 0)
2387 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2389 if (fx_info->images->colorspace == CMYKColorspace)
2392 case CyanChannel: type="cyan"; break;
2393 case MagentaChannel: type="magenta"; break;
2394 case YellowChannel: type="yellow"; break;
2395 case OpacityChannel: type="opacity"; break;
2396 case BlackChannel: type="black"; break;
2397 default: type="unknown"; break;
2402 case RedChannel: type="red"; break;
2403 case GreenChannel: type="green"; break;
2404 case BlueChannel: type="blue"; break;
2405 case OpacityChannel: type="opacity"; break;
2406 default: type="unknown"; break;
2408 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2409 if (strlen(subexpression) > 1)
2410 subexpression[strlen(subexpression)-1]='\0';
2411 if (fx_info->file != (FILE *) NULL)
2412 (void) fprintf(fx_info->file,"%s[%ld,%ld].%s: %s=%.*g\n",
2413 fx_info->images->filename,x,y,type,subexpression,
2414 GetMagickPrecision(),(double) alpha);
2422 if (LocaleCompare(expression,"epsilon") == 0)
2423 return((MagickRealType) MagickEpsilon);
2424 if (LocaleNCompare(expression,"exp",3) == 0)
2426 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2428 return((MagickRealType) exp((double) alpha));
2430 if (LocaleCompare(expression,"e") == 0)
2431 return((MagickRealType) 2.7182818284590452354);
2437 if (LocaleNCompare(expression,"floor",5) == 0)
2439 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2441 return((MagickRealType) floor((double) alpha));
2448 if (LocaleCompare(expression,"g") == 0)
2449 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2455 if (LocaleCompare(expression,"h") == 0)
2456 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2457 if (LocaleCompare(expression,"hue") == 0)
2458 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2459 if (LocaleNCompare(expression,"hypot",5) == 0)
2461 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2463 return((MagickRealType) hypot((double) alpha,(double) *beta));
2470 if (LocaleCompare(expression,"k") == 0)
2471 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2477 if (LocaleCompare(expression,"intensity") == 0)
2478 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2479 if (LocaleNCompare(expression,"int",3) == 0)
2481 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2483 return((MagickRealType) floor(alpha+0.5));
2485 if (LocaleCompare(expression,"i") == 0)
2486 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2492 if (LocaleCompare(expression,"j") == 0)
2493 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2494 #if defined(MAGICKCORE_HAVE_J0)
2495 if (LocaleNCompare(expression,"j0",2) == 0)
2497 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2499 return((MagickRealType) j0((double) alpha));
2502 #if defined(MAGICKCORE_HAVE_J1)
2503 if (LocaleNCompare(expression,"j1",2) == 0)
2505 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2507 return((MagickRealType) j1((double) alpha));
2510 #if defined(MAGICKCORE_HAVE_J1)
2511 if (LocaleNCompare(expression,"jinc",4) == 0)
2513 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2517 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2527 if (LocaleNCompare(expression,"ln",2) == 0)
2529 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2531 return((MagickRealType) log((double) alpha));
2533 if (LocaleNCompare(expression,"logtwo",4) == 0)
2535 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2537 return((MagickRealType) log10((double) alpha))/log10(2.0);
2539 if (LocaleNCompare(expression,"log",3) == 0)
2541 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2543 return((MagickRealType) log10((double) alpha));
2545 if (LocaleCompare(expression,"lightness") == 0)
2546 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2552 if (LocaleCompare(expression,"MaxRGB") == 0)
2553 return((MagickRealType) QuantumRange);
2554 if (LocaleNCompare(expression,"maxima",6) == 0)
2556 if (LocaleNCompare(expression,"max",3) == 0)
2557 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2558 if (LocaleNCompare(expression,"minima",6) == 0)
2560 if (LocaleNCompare(expression,"min",3) == 0)
2561 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2562 if (LocaleNCompare(expression,"mod",3) == 0)
2564 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2566 return((MagickRealType) fmod((double) alpha,(double) *beta));
2568 if (LocaleCompare(expression,"m") == 0)
2569 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2575 if (LocaleCompare(expression,"n") == 0)
2576 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2582 if (LocaleCompare(expression,"Opaque") == 0)
2584 if (LocaleCompare(expression,"o") == 0)
2585 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2591 if (LocaleCompare(expression,"pi") == 0)
2592 return((MagickRealType) MagickPI);
2593 if (LocaleNCompare(expression,"pow",3) == 0)
2595 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2597 return((MagickRealType) pow((double) alpha,(double) *beta));
2599 if (LocaleCompare(expression,"p") == 0)
2600 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2606 if (LocaleCompare(expression,"QuantumRange") == 0)
2607 return((MagickRealType) QuantumRange);
2608 if (LocaleCompare(expression,"QuantumScale") == 0)
2609 return((MagickRealType) QuantumScale);
2615 if (LocaleNCompare(expression,"rand",4) == 0)
2616 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2617 if (LocaleNCompare(expression,"round",5) == 0)
2619 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2622 return((MagickRealType) floor((double) alpha+0.5));
2623 return((MagickRealType) ceil((double) alpha-0.5));
2625 if (LocaleCompare(expression,"r") == 0)
2626 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2632 if (LocaleCompare(expression,"saturation") == 0)
2633 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2634 if (LocaleNCompare(expression,"sign",4) == 0)
2636 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2638 return(alpha < 0.0 ? -1.0 : 1.0);
2640 if (LocaleNCompare(expression,"sinc",4) == 0)
2642 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2646 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2650 if (LocaleNCompare(expression,"sinh",4) == 0)
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2654 return((MagickRealType) sinh((double) alpha));
2656 if (LocaleNCompare(expression,"sin",3) == 0)
2658 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2660 return((MagickRealType) sin((double) alpha));
2662 if (LocaleNCompare(expression,"sqrt",4) == 0)
2664 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2666 return((MagickRealType) sqrt((double) alpha));
2668 if (LocaleCompare(expression,"s") == 0)
2669 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2675 if (LocaleNCompare(expression,"tanh",4) == 0)
2677 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2679 return((MagickRealType) tanh((double) alpha));
2681 if (LocaleNCompare(expression,"tan",3) == 0)
2683 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2685 return((MagickRealType) tan((double) alpha));
2687 if (LocaleCompare(expression,"Transparent") == 0)
2689 if (LocaleCompare(expression,"t") == 0)
2690 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2696 if (LocaleCompare(expression,"u") == 0)
2697 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2703 if (LocaleCompare(expression,"v") == 0)
2704 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2710 if (LocaleCompare(expression,"w") == 0)
2711 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2717 if (LocaleCompare(expression,"y") == 0)
2718 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2724 if (LocaleCompare(expression,"z") == 0)
2725 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2731 q=(char *) expression;
2732 alpha=strtod(expression,&q);
2733 if (q == expression)
2734 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2738 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2739 MagickRealType *alpha,ExceptionInfo *exception)
2744 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2748 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2749 MagickRealType *alpha,ExceptionInfo *exception)
2758 fx_info->file=(FILE *) NULL;
2759 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2764 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2765 const ChannelType channel,const long x,const long y,MagickRealType *alpha,
2766 ExceptionInfo *exception)
2772 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2774 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2788 % FxImage() applies a mathematical expression to the specified image.
2790 % The format of the FxImage method is:
2792 % Image *FxImage(const Image *image,const char *expression,
2793 % ExceptionInfo *exception)
2794 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2795 % const char *expression,ExceptionInfo *exception)
2797 % A description of each parameter follows:
2799 % o image: the image.
2801 % o channel: the channel.
2803 % o expression: A mathematical expression.
2805 % o exception: return any errors or warnings in this structure.
2809 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2814 assert(fx_info != (FxInfo **) NULL);
2815 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
2816 if (fx_info[i] != (FxInfo *) NULL)
2817 fx_info[i]=DestroyFxInfo(fx_info[i]);
2818 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2822 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2823 ExceptionInfo *exception)
2840 number_threads=GetOpenMPMaximumThreads();
2841 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2842 if (fx_info == (FxInfo **) NULL)
2843 return((FxInfo **) NULL);
2844 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2845 if (*expression != '@')
2846 fx_expression=ConstantString(expression);
2848 fx_expression=FileToString(expression+1,~0,exception);
2849 for (i=0; i < (long) number_threads; i++)
2851 fx_info[i]=AcquireFxInfo(image,fx_expression);
2852 if (fx_info[i] == (FxInfo *) NULL)
2853 return(DestroyFxThreadSet(fx_info));
2854 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2856 fx_expression=DestroyString(fx_expression);
2860 MagickExport Image *FxImage(const Image *image,const char *expression,
2861 ExceptionInfo *exception)
2866 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2870 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2871 const char *expression,ExceptionInfo *exception)
2873 #define FxImageTag "Fx/Image"
2894 assert(image != (Image *) NULL);
2895 assert(image->signature == MagickSignature);
2896 if (image->debug != MagickFalse)
2897 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2898 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2899 if (fx_image == (Image *) NULL)
2900 return((Image *) NULL);
2901 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2903 InheritException(exception,&fx_image->exception);
2904 fx_image=DestroyImage(fx_image);
2905 return((Image *) NULL);
2907 fx_info=AcquireFxThreadSet(image,expression,exception);
2908 if (fx_info == (FxInfo **) NULL)
2910 fx_image=DestroyImage(fx_image);
2911 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2913 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2914 if (status == MagickFalse)
2916 fx_image=DestroyImage(fx_image);
2917 fx_info=DestroyFxThreadSet(fx_info);
2918 return((Image *) NULL);
2925 fx_view=AcquireCacheView(fx_image);
2926 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2927 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2929 for (y=0; y < (long) fx_image->rows; y++)
2934 register IndexPacket
2935 *restrict fx_indexes;
2941 register PixelPacket
2944 if (status == MagickFalse)
2946 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2947 if (q == (PixelPacket *) NULL)
2952 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2953 id=GetOpenMPThreadId();
2955 for (x=0; x < (long) fx_image->columns; x++)
2957 if ((channel & RedChannel) != 0)
2959 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
2961 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2963 if ((channel & GreenChannel) != 0)
2965 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
2967 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2969 if ((channel & BlueChannel) != 0)
2971 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
2973 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2975 if ((channel & OpacityChannel) != 0)
2977 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
2979 if (image->matte == MagickFalse)
2980 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2982 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
2983 QuantumRange*alpha));
2985 if (((channel & IndexChannel) != 0) &&
2986 (fx_image->colorspace == CMYKColorspace))
2988 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
2990 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
2991 QuantumRange*alpha);
2995 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
2997 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3002 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3003 #pragma omp critical (MagickCore_FxImageChannel)
3005 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3006 if (proceed == MagickFalse)
3010 fx_image->matte=fx_info[0]->matte;
3011 fx_view=DestroyCacheView(fx_view);
3012 fx_info=DestroyFxThreadSet(fx_info);
3013 if (status == MagickFalse)
3014 fx_image=DestroyImage(fx_image);
3019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3023 % I m p l o d e I m a g e %
3027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3029 % ImplodeImage() creates a new image that is a copy of an existing
3030 % one with the image pixels "implode" by the specified percentage. It
3031 % allocates the memory necessary for the new Image structure and returns a
3032 % pointer to the new image.
3034 % The format of the ImplodeImage method is:
3036 % Image *ImplodeImage(const Image *image,const double amount,
3037 % ExceptionInfo *exception)
3039 % A description of each parameter follows:
3041 % o implode_image: Method ImplodeImage returns a pointer to the image
3042 % after it is implode. A null image is returned if there is a memory
3045 % o image: the image.
3047 % o amount: Define the extent of the implosion.
3049 % o exception: return any errors or warnings in this structure.
3052 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3053 ExceptionInfo *exception)
3055 #define ImplodeImageTag "Implode/Image"
3082 **restrict resample_filter;
3085 Initialize implode image attributes.
3087 assert(image != (Image *) NULL);
3088 assert(image->signature == MagickSignature);
3089 if (image->debug != MagickFalse)
3090 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3091 assert(exception != (ExceptionInfo *) NULL);
3092 assert(exception->signature == MagickSignature);
3093 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3094 if (implode_image == (Image *) NULL)
3095 return((Image *) NULL);
3096 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3098 InheritException(exception,&implode_image->exception);
3099 implode_image=DestroyImage(implode_image);
3100 return((Image *) NULL);
3102 if (implode_image->background_color.opacity != OpaqueOpacity)
3103 implode_image->matte=MagickTrue;
3105 Compute scaling factor.
3109 center.x=0.5*image->columns;
3110 center.y=0.5*image->rows;
3112 if (image->columns > image->rows)
3113 scale.y=(double) image->columns/(double) image->rows;
3115 if (image->columns < image->rows)
3117 scale.x=(double) image->rows/(double) image->columns;
3125 GetMagickPixelPacket(implode_image,&zero);
3126 resample_filter=AcquireResampleFilterThreadSet(image,
3127 UndefinedVirtualPixelMethod,MagickTrue,exception);
3128 image_view=AcquireCacheView(image);
3129 implode_view=AcquireCacheView(implode_image);
3130 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3131 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3133 for (y=0; y < (long) image->rows; y++)
3144 register IndexPacket
3145 *restrict implode_indexes;
3151 register PixelPacket
3154 if (status == MagickFalse)
3156 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3158 if (q == (PixelPacket *) NULL)
3163 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
3164 delta.y=scale.y*(double) (y-center.y);
3166 id=GetOpenMPThreadId();
3167 for (x=0; x < (long) image->columns; x++)
3170 Determine if the pixel is within an ellipse.
3172 delta.x=scale.x*(double) (x-center.x);
3173 distance=delta.x*delta.x+delta.y*delta.y;
3174 if (distance < (radius*radius))
3184 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3185 radius/2)),-amount);
3186 (void) ResamplePixelColor(resample_filter[id],(double)
3187 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3188 scale.y+center.y),&pixel);
3189 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
3193 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3195 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3200 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3201 #pragma omp critical (MagickCore_ImplodeImage)
3203 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3204 if (proceed == MagickFalse)
3208 implode_view=DestroyCacheView(implode_view);
3209 image_view=DestroyCacheView(image_view);
3210 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
3211 if (status == MagickFalse)
3212 implode_image=DestroyImage(implode_image);
3213 return(implode_image);
3217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3221 % M o r p h I m a g e s %
3225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3227 % The MorphImages() method requires a minimum of two images. The first
3228 % image is transformed into the second by a number of intervening images
3229 % as specified by frames.
3231 % The format of the MorphImage method is:
3233 % Image *MorphImages(const Image *image,const unsigned long number_frames,
3234 % ExceptionInfo *exception)
3236 % A description of each parameter follows:
3238 % o image: the image.
3240 % o number_frames: Define the number of in-between image to generate.
3241 % The more in-between frames, the smoother the morph.
3243 % o exception: return any errors or warnings in this structure.
3246 MagickExport Image *MorphImages(const Image *image,
3247 const unsigned long number_frames,ExceptionInfo *exception)
3249 #define MorphImageTag "Morph/Image"
3265 register const Image
3275 Clone first frame in sequence.
3277 assert(image != (Image *) NULL);
3278 assert(image->signature == MagickSignature);
3279 if (image->debug != MagickFalse)
3280 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3281 assert(exception != (ExceptionInfo *) NULL);
3282 assert(exception->signature == MagickSignature);
3283 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3284 if (morph_images == (Image *) NULL)
3285 return((Image *) NULL);
3286 if (GetNextImageInList(image) == (Image *) NULL)
3291 for (i=1; i < (long) number_frames; i++)
3293 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3294 if (morph_image == (Image *) NULL)
3296 morph_images=DestroyImageList(morph_images);
3297 return((Image *) NULL);
3299 AppendImageToList(&morph_images,morph_image);
3300 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3305 proceed=SetImageProgress(image,MorphImageTag,i,number_frames);
3306 if (proceed == MagickFalse)
3310 return(GetFirstImageInList(morph_images));
3313 Morph image sequence.
3318 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3320 for (i=0; i < (long) number_frames; i++)
3326 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3328 morph_image=ZoomImage(next,(unsigned long) (alpha*next->columns+beta*
3329 GetNextImageInList(next)->columns+0.5),(unsigned long) (alpha*
3330 next->rows+beta*GetNextImageInList(next)->rows+0.5),exception);
3331 if (morph_image == (Image *) NULL)
3333 morph_images=DestroyImageList(morph_images);
3334 return((Image *) NULL);
3336 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3338 InheritException(exception,&morph_image->exception);
3339 morph_image=DestroyImage(morph_image);
3340 return((Image *) NULL);
3342 AppendImageToList(&morph_images,morph_image);
3343 morph_images=GetLastImageInList(morph_images);
3344 morph_image=ZoomImage(GetNextImageInList(next),morph_images->columns,
3345 morph_images->rows,exception);
3346 if (morph_image == (Image *) NULL)
3348 morph_images=DestroyImageList(morph_images);
3349 return((Image *) NULL);
3351 image_view=AcquireCacheView(morph_image);
3352 morph_view=AcquireCacheView(morph_images);
3353 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3354 #pragma omp parallel for schedule(dynamic,4) shared(status)
3356 for (y=0; y < (long) morph_images->rows; y++)
3361 register const PixelPacket
3367 register PixelPacket
3370 if (status == MagickFalse)
3372 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3374 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3376 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3381 for (x=0; x < (long) morph_images->columns; x++)
3383 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3384 q->green=ClampToQuantum(alpha*q->green+beta*
3385 GetGreenPixelComponent(p));
3386 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3387 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3388 GetOpacityPixelComponent(p));
3392 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3393 if (sync == MagickFalse)
3396 morph_view=DestroyCacheView(morph_view);
3397 image_view=DestroyCacheView(image_view);
3398 morph_image=DestroyImage(morph_image);
3400 if (i < (long) number_frames)
3403 Clone last frame in sequence.
3405 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3406 if (morph_image == (Image *) NULL)
3408 morph_images=DestroyImageList(morph_images);
3409 return((Image *) NULL);
3411 AppendImageToList(&morph_images,morph_image);
3412 morph_images=GetLastImageInList(morph_images);
3413 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3418 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3419 #pragma omp critical (MagickCore_MorphImages)
3421 proceed=SetImageProgress(image,MorphImageTag,scene,
3422 GetImageListLength(image));
3423 if (proceed == MagickFalse)
3428 if (GetNextImageInList(next) != (Image *) NULL)
3430 morph_images=DestroyImageList(morph_images);
3431 return((Image *) NULL);
3433 return(GetFirstImageInList(morph_images));
3437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3441 % P l a s m a I m a g e %
3445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3447 % PlasmaImage() initializes an image with plasma fractal values. The image
3448 % must be initialized with a base color and the random number generator
3449 % seeded before this method is called.
3451 % The format of the PlasmaImage method is:
3453 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3454 % unsigned long attenuate,unsigned long depth)
3456 % A description of each parameter follows:
3458 % o image: the image.
3460 % o segment: Define the region to apply plasma fractals values.
3462 % o attenuate: Define the plasmattenuation factor.
3464 % o depth: Limit the plasma recursion depth.
3468 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3469 const MagickRealType pixel,const MagickRealType noise)
3474 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3479 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3480 RandomInfo *random_info,const SegmentInfo *segment,unsigned long attenuate,
3481 unsigned long depth)
3499 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3507 Divide the area into quadrants and recurse.
3511 x_mid=(long) ceil((segment->x1+segment->x2)/2-0.5);
3512 y_mid=(long) ceil((segment->y1+segment->y2)/2-0.5);
3513 local_info=(*segment);
3514 local_info.x2=(double) x_mid;
3515 local_info.y2=(double) y_mid;
3516 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3517 local_info=(*segment);
3518 local_info.y1=(double) y_mid;
3519 local_info.x2=(double) x_mid;
3520 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3521 local_info=(*segment);
3522 local_info.x1=(double) x_mid;
3523 local_info.y2=(double) y_mid;
3524 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3525 local_info=(*segment);
3526 local_info.x1=(double) x_mid;
3527 local_info.y1=(double) y_mid;
3528 return(PlasmaImageProxy(image,random_info,&local_info,attenuate,depth));
3530 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3531 return(MagickFalse);
3532 x_mid=(long) ceil((segment->x1+segment->x2)/2-0.5);
3533 y_mid=(long) ceil((segment->y1+segment->y2)/2-0.5);
3534 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3535 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3536 return(MagickFalse);
3538 Average pixels and apply plasma.
3540 exception=(&image->exception);
3541 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3542 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3544 register PixelPacket
3550 x=(long) ceil(segment->x1-0.5);
3551 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y1-0.5),&u,
3553 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y2-0.5),&v,
3555 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3556 if (q == (PixelPacket *) NULL)
3558 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3560 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3562 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3564 (void) SyncAuthenticPixels(image,exception);
3565 if (segment->x1 != segment->x2)
3570 x=(long) ceil(segment->x2-0.5);
3571 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y1-0.5),&u,
3573 (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y2-0.5),&v,
3575 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3576 if (q == (PixelPacket *) NULL)
3578 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3580 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3582 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3584 (void) SyncAuthenticPixels(image,exception);
3587 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3589 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3591 register PixelPacket
3597 y=(long) ceil(segment->y2-0.5);
3598 (void) GetOneVirtualPixel(image,(long) ceil(segment->x1-0.5),y,&u,
3600 (void) GetOneVirtualPixel(image,(long) ceil(segment->x2-0.5),y,&v,
3602 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3603 if (q == (PixelPacket *) NULL)
3605 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3607 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3609 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3611 (void) SyncAuthenticPixels(image,exception);
3613 if (segment->y1 != segment->y2)
3615 register PixelPacket
3621 y=(long) ceil(segment->y1-0.5);
3622 (void) GetOneVirtualPixel(image,(long) ceil(segment->x1-0.5),y,&u,
3624 (void) GetOneVirtualPixel(image,(long) ceil(segment->x2-0.5),y,&v,
3626 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3627 if (q == (PixelPacket *) NULL)
3629 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3631 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3633 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3635 (void) SyncAuthenticPixels(image,exception);
3638 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3640 register PixelPacket
3646 x=(long) ceil(segment->x1-0.5);
3647 y=(long) ceil(segment->y1-0.5);
3648 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3649 x=(long) ceil(segment->x2-0.5);
3650 y=(long) ceil(segment->y2-0.5);
3651 (void) GetOneVirtualPixel(image,x,y,&v,exception);
3652 q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception);
3653 if (q == (PixelPacket *) NULL)
3655 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3657 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3659 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3661 (void) SyncAuthenticPixels(image,exception);
3663 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3665 return(MagickFalse);
3668 MagickExport MagickBooleanType PlasmaImage(Image *image,
3669 const SegmentInfo *segment,unsigned long attenuate,unsigned long depth)
3677 if (image->debug != MagickFalse)
3678 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3679 assert(image != (Image *) NULL);
3680 assert(image->signature == MagickSignature);
3681 if (image->debug != MagickFalse)
3682 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3683 random_info=AcquireRandomInfo();
3684 status=PlasmaImageProxy(image,random_info,segment,attenuate,depth);
3685 random_info=DestroyRandomInfo(random_info);
3690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3694 % P o l a r o i d I m a g e %
3698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3700 % PolaroidImage() simulates a Polaroid picture.
3702 % The format of the AnnotateImage method is:
3704 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3705 % const double angle,ExceptionInfo exception)
3707 % A description of each parameter follows:
3709 % o image: the image.
3711 % o draw_info: the draw info.
3713 % o angle: Apply the effect along this angle.
3715 % o exception: return any errors or warnings in this structure.
3718 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3719 const double angle,ExceptionInfo *exception)
3740 Simulate a Polaroid picture.
3742 assert(image != (Image *) NULL);
3743 assert(image->signature == MagickSignature);
3744 if (image->debug != MagickFalse)
3745 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3746 assert(exception != (ExceptionInfo *) NULL);
3747 assert(exception->signature == MagickSignature);
3748 quantum=(long) MagickMax(MagickMax((double) image->columns,(double)
3749 image->rows)/25.0,10.0);
3750 height=image->rows+2*quantum;
3751 caption_image=(Image *) NULL;
3752 value=GetImageProperty(image,"Caption");
3753 if (value != (const char *) NULL)
3757 geometry[MaxTextExtent];
3772 Generate caption image.
3774 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3775 if (caption_image == (Image *) NULL)
3776 return((Image *) NULL);
3777 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3778 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3780 (void) CloneString(&annotate_info->text,caption);
3781 count=FormatMagickCaption(caption_image,annotate_info,&metrics,&caption);
3782 status=SetImageExtent(caption_image,image->columns,(unsigned long)
3783 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3784 if (status == MagickFalse)
3785 caption_image=DestroyImage(caption_image);
3788 caption_image->background_color=image->border_color;
3789 (void) SetImageBackgroundColor(caption_image);
3790 (void) CloneString(&annotate_info->text,caption);
3791 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3793 if (annotate_info->gravity == UndefinedGravity)
3794 (void) CloneString(&annotate_info->geometry,AcquireString(
3796 (void) AnnotateImage(caption_image,annotate_info);
3797 height+=caption_image->rows;
3799 annotate_info=DestroyDrawInfo(annotate_info);
3800 caption=DestroyString(caption);
3802 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3804 if (picture_image == (Image *) NULL)
3806 if (caption_image != (Image *) NULL)
3807 caption_image=DestroyImage(caption_image);
3808 return((Image *) NULL);
3810 picture_image->background_color=image->border_color;
3811 (void) SetImageBackgroundColor(picture_image);
3812 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3813 if (caption_image != (Image *) NULL)
3815 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3816 quantum,(long) (image->rows+3*quantum/2));
3817 caption_image=DestroyImage(caption_image);
3819 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3820 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3821 rotate_image=RotateImage(picture_image,90.0,exception);
3822 picture_image=DestroyImage(picture_image);
3823 if (rotate_image == (Image *) NULL)
3824 return((Image *) NULL);
3825 picture_image=rotate_image;
3826 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3827 picture_image->columns,exception);
3828 picture_image=DestroyImage(picture_image);
3829 if (bend_image == (Image *) NULL)
3830 return((Image *) NULL);
3831 InheritException(&bend_image->exception,exception);
3832 picture_image=bend_image;
3833 rotate_image=RotateImage(picture_image,-90.0,exception);
3834 picture_image=DestroyImage(picture_image);
3835 if (rotate_image == (Image *) NULL)
3836 return((Image *) NULL);
3837 picture_image=rotate_image;
3838 picture_image->background_color=image->background_color;
3839 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3841 if (polaroid_image == (Image *) NULL)
3843 picture_image=DestroyImage(picture_image);
3844 return(picture_image);
3846 flop_image=FlopImage(polaroid_image,exception);
3847 polaroid_image=DestroyImage(polaroid_image);
3848 if (flop_image == (Image *) NULL)
3850 picture_image=DestroyImage(picture_image);
3851 return(picture_image);
3853 polaroid_image=flop_image;
3854 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3855 (long) (-0.01*picture_image->columns/2.0),0L);
3856 picture_image=DestroyImage(picture_image);
3857 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3858 rotate_image=RotateImage(polaroid_image,angle,exception);
3859 polaroid_image=DestroyImage(polaroid_image);
3860 if (rotate_image == (Image *) NULL)
3861 return((Image *) NULL);
3862 polaroid_image=rotate_image;
3863 trim_image=TrimImage(polaroid_image,exception);
3864 polaroid_image=DestroyImage(polaroid_image);
3865 if (trim_image == (Image *) NULL)
3866 return((Image *) NULL);
3867 polaroid_image=trim_image;
3868 return(polaroid_image);
3872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3876 % S e p i a T o n e I m a g e %
3880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3882 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3883 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3884 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3885 % threshold of 80% is a good starting point for a reasonable tone.
3887 % The format of the SepiaToneImage method is:
3889 % Image *SepiaToneImage(const Image *image,const double threshold,
3890 % ExceptionInfo *exception)
3892 % A description of each parameter follows:
3894 % o image: the image.
3896 % o threshold: the tone threshold.
3898 % o exception: return any errors or warnings in this structure.
3901 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3902 ExceptionInfo *exception)
3904 #define SepiaToneImageTag "SepiaTone/Image"
3921 Initialize sepia-toned image attributes.
3923 assert(image != (const Image *) NULL);
3924 assert(image->signature == MagickSignature);
3925 if (image->debug != MagickFalse)
3926 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3927 assert(exception != (ExceptionInfo *) NULL);
3928 assert(exception->signature == MagickSignature);
3929 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3930 if (sepia_image == (Image *) NULL)
3931 return((Image *) NULL);
3932 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3934 InheritException(exception,&sepia_image->exception);
3935 sepia_image=DestroyImage(sepia_image);
3936 return((Image *) NULL);
3939 Tone each row of the image.
3943 image_view=AcquireCacheView(image);
3944 sepia_view=AcquireCacheView(sepia_image);
3945 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3946 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3948 for (y=0; y < (long) image->rows; y++)
3950 register const PixelPacket
3956 register PixelPacket
3959 if (status == MagickFalse)
3961 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3962 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
3964 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3969 for (x=0; x < (long) image->columns; x++)
3975 intensity=(MagickRealType) PixelIntensityToQuantum(p);
3976 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
3977 (MagickRealType) QuantumRange-threshold;
3978 q->red=ClampToQuantum(tone);
3979 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
3980 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
3981 q->green=ClampToQuantum(tone);
3982 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
3983 q->blue=ClampToQuantum(tone);
3985 if ((MagickRealType) q->green < tone)
3986 q->green=ClampToQuantum(tone);
3987 if ((MagickRealType) q->blue < tone)
3988 q->blue=ClampToQuantum(tone);
3992 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
3994 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3999 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4000 #pragma omp critical (MagickCore_SepiaToneImage)
4002 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4004 if (proceed == MagickFalse)
4008 sepia_view=DestroyCacheView(sepia_view);
4009 image_view=DestroyCacheView(image_view);
4010 (void) NormalizeImage(sepia_image);
4011 (void) ContrastImage(sepia_image,MagickTrue);
4012 if (status == MagickFalse)
4013 sepia_image=DestroyImage(sepia_image);
4014 return(sepia_image);
4018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4022 % S h a d o w I m a g e %
4026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4028 % ShadowImage() simulates a shadow from the specified image and returns it.
4030 % The format of the ShadowImage method is:
4032 % Image *ShadowImage(const Image *image,const double opacity,
4033 % const double sigma,const long x_offset,const long y_offset,
4034 % ExceptionInfo *exception)
4036 % A description of each parameter follows:
4038 % o image: the image.
4040 % o opacity: percentage transparency.
4042 % o sigma: the standard deviation of the Gaussian, in pixels.
4044 % o x_offset: the shadow x-offset.
4046 % o y_offset: the shadow y-offset.
4048 % o exception: return any errors or warnings in this structure.
4051 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4052 const double sigma,const long x_offset,const long y_offset,
4053 ExceptionInfo *exception)
4055 #define ShadowImageTag "Shadow/Image"
4075 assert(image != (Image *) NULL);
4076 assert(image->signature == MagickSignature);
4077 if (image->debug != MagickFalse)
4078 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4079 assert(exception != (ExceptionInfo *) NULL);
4080 assert(exception->signature == MagickSignature);
4081 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4082 if (clone_image == (Image *) NULL)
4083 return((Image *) NULL);
4084 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4085 clone_image->compose=OverCompositeOp;
4086 border_info.width=(unsigned long) floor(2.0*sigma+0.5);
4087 border_info.height=(unsigned long) floor(2.0*sigma+0.5);
4090 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4091 border_image=BorderImage(clone_image,&border_info,exception);
4092 clone_image=DestroyImage(clone_image);
4093 if (border_image == (Image *) NULL)
4094 return((Image *) NULL);
4095 if (border_image->matte == MagickFalse)
4096 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4102 image_view=AcquireCacheView(border_image);
4103 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4104 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4106 for (y=0; y < (long) border_image->rows; y++)
4111 register PixelPacket
4114 if (status == MagickFalse)
4116 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4118 if (q == (PixelPacket *) NULL)
4123 for (x=0; x < (long) border_image->columns; x++)
4125 q->red=border_image->background_color.red;
4126 q->green=border_image->background_color.green;
4127 q->blue=border_image->background_color.blue;
4128 if (border_image->matte == MagickFalse)
4129 q->opacity=border_image->background_color.opacity;
4131 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4132 GetAlphaPixelComponent(q)*opacity/100.0));
4135 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4137 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4142 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4143 #pragma omp critical (MagickCore_ShadowImage)
4145 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4146 border_image->rows);
4147 if (proceed == MagickFalse)
4151 image_view=DestroyCacheView(image_view);
4152 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4153 border_image=DestroyImage(border_image);
4154 if (shadow_image == (Image *) NULL)
4155 return((Image *) NULL);
4156 if (shadow_image->page.width == 0)
4157 shadow_image->page.width=shadow_image->columns;
4158 if (shadow_image->page.height == 0)
4159 shadow_image->page.height=shadow_image->rows;
4160 shadow_image->page.width+=x_offset-(long) border_info.width;
4161 shadow_image->page.height+=y_offset-(long) border_info.height;
4162 shadow_image->page.x+=x_offset-(long) border_info.width;
4163 shadow_image->page.y+=y_offset-(long) border_info.height;
4164 return(shadow_image);
4168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4172 % S k e t c h I m a g e %
4176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4178 % SketchImage() simulates a pencil sketch. We convolve the image with a
4179 % Gaussian operator of the given radius and standard deviation (sigma). For
4180 % reasonable results, radius should be larger than sigma. Use a radius of 0
4181 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4184 % The format of the SketchImage method is:
4186 % Image *SketchImage(const Image *image,const double radius,
4187 % const double sigma,const double angle,ExceptionInfo *exception)
4189 % A description of each parameter follows:
4191 % o image: the image.
4193 % o radius: the radius of the Gaussian, in pixels, not counting
4196 % o sigma: the standard deviation of the Gaussian, in pixels.
4198 % o angle: Apply the effect along this angle.
4200 % o exception: return any errors or warnings in this structure.
4203 MagickExport Image *SketchImage(const Image *image,const double radius,
4204 const double sigma,const double angle,ExceptionInfo *exception)
4226 **restrict random_info;
4231 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4232 MagickTrue,exception);
4233 if (random_image == (Image *) NULL)
4234 return((Image *) NULL);
4236 GetMagickPixelPacket(random_image,&zero);
4237 random_info=AcquireRandomInfoThreadSet();
4238 random_view=AcquireCacheView(random_image);
4239 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4240 #pragma omp parallel for schedule(dynamic,4) shared(status)
4242 for (y=0; y < (long) random_image->rows; y++)
4247 register IndexPacket
4254 register PixelPacket
4257 if (status == MagickFalse)
4259 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4261 if (q == (PixelPacket *) NULL)
4266 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4268 id=GetOpenMPThreadId();
4269 for (x=0; x < (long) random_image->columns; x++)
4271 pixel.red=(MagickRealType) (QuantumRange*
4272 GetPseudoRandomValue(random_info[id]));
4273 pixel.green=pixel.red;
4274 pixel.blue=pixel.red;
4275 if (image->colorspace == CMYKColorspace)
4276 pixel.index=pixel.red;
4277 SetPixelPacket(random_image,&pixel,q,indexes+x);
4280 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4283 random_view=DestroyCacheView(random_view);
4284 random_info=DestroyRandomInfoThreadSet(random_info);
4285 if (status == MagickFalse)
4287 random_image=DestroyImage(random_image);
4288 return(random_image);
4290 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4291 random_image=DestroyImage(random_image);
4292 if (blur_image == (Image *) NULL)
4293 return((Image *) NULL);
4294 dodge_image=EdgeImage(blur_image,radius,exception);
4295 blur_image=DestroyImage(blur_image);
4296 if (dodge_image == (Image *) NULL)
4297 return((Image *) NULL);
4298 (void) NormalizeImage(dodge_image);
4299 (void) NegateImage(dodge_image,MagickFalse);
4300 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4301 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4302 if (sketch_image == (Image *) NULL)
4304 dodge_image=DestroyImage(dodge_image);
4305 return((Image *) NULL);
4307 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4308 dodge_image=DestroyImage(dodge_image);
4309 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4310 if (blend_image == (Image *) NULL)
4312 sketch_image=DestroyImage(sketch_image);
4313 return((Image *) NULL);
4315 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4316 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4317 blend_image=DestroyImage(blend_image);
4318 return(sketch_image);
4322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4326 % S o l a r i z e I m a g e %
4330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4332 % SolarizeImage() applies a special effect to the image, similar to the effect
4333 % achieved in a photo darkroom by selectively exposing areas of photo
4334 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4335 % measure of the extent of the solarization.
4337 % The format of the SolarizeImage method is:
4339 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4341 % A description of each parameter follows:
4343 % o image: the image.
4345 % o threshold: Define the extent of the solarization.
4348 MagickExport MagickBooleanType SolarizeImage(Image *image,
4349 const double threshold)
4351 #define SolarizeImageTag "Solarize/Image"
4366 assert(image != (Image *) NULL);
4367 assert(image->signature == MagickSignature);
4368 if (image->debug != MagickFalse)
4369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4370 if (image->storage_class == PseudoClass)
4378 for (i=0; i < (long) image->colors; i++)
4380 if ((MagickRealType) image->colormap[i].red > threshold)
4381 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4382 if ((MagickRealType) image->colormap[i].green > threshold)
4383 image->colormap[i].green=(Quantum) QuantumRange-
4384 image->colormap[i].green;
4385 if ((MagickRealType) image->colormap[i].blue > threshold)
4386 image->colormap[i].blue=(Quantum) QuantumRange-
4387 image->colormap[i].blue;
4395 exception=(&image->exception);
4396 image_view=AcquireCacheView(image);
4397 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4398 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4400 for (y=0; y < (long) image->rows; y++)
4405 register PixelPacket
4408 if (status == MagickFalse)
4410 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4412 if (q == (PixelPacket *) NULL)
4417 for (x=0; x < (long) image->columns; x++)
4419 if ((MagickRealType) q->red > threshold)
4420 q->red=(Quantum) QuantumRange-q->red;
4421 if ((MagickRealType) q->green > threshold)
4422 q->green=(Quantum) QuantumRange-q->green;
4423 if ((MagickRealType) q->blue > threshold)
4424 q->blue=(Quantum) QuantumRange-q->blue;
4427 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4429 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4434 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4435 #pragma omp critical (MagickCore_SolarizeImage)
4437 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4438 if (proceed == MagickFalse)
4442 image_view=DestroyCacheView(image_view);
4447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4451 % S t e g a n o I m a g e %
4455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4457 % SteganoImage() hides a digital watermark within the image. Recover
4458 % the hidden watermark later to prove that the authenticity of an image.
4459 % Offset defines the start position within the image to hide the watermark.
4461 % The format of the SteganoImage method is:
4463 % Image *SteganoImage(const Image *image,Image *watermark,
4464 % ExceptionInfo *exception)
4466 % A description of each parameter follows:
4468 % o image: the image.
4470 % o watermark: the watermark image.
4472 % o exception: return any errors or warnings in this structure.
4475 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4476 ExceptionInfo *exception)
4478 #define GetBit(alpha,i) ((((unsigned long) (alpha) >> (unsigned long) \
4480 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) ? (unsigned long) (alpha) \
4481 | (1UL << (unsigned long) (i)) : (unsigned long) (alpha) & \
4482 ~(1UL << (unsigned long) (i)))
4483 #define SteganoImageTag "Stegano/Image"
4506 register PixelPacket
4513 Initialize steganographic image attributes.
4515 assert(image != (const Image *) NULL);
4516 assert(image->signature == MagickSignature);
4517 if (image->debug != MagickFalse)
4518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4519 assert(watermark != (const Image *) NULL);
4520 assert(watermark->signature == MagickSignature);
4521 assert(exception != (ExceptionInfo *) NULL);
4522 assert(exception->signature == MagickSignature);
4523 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4524 if (stegano_image == (Image *) NULL)
4525 return((Image *) NULL);
4526 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4528 InheritException(exception,&stegano_image->exception);
4529 stegano_image=DestroyImage(stegano_image);
4530 return((Image *) NULL);
4532 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4534 Hide watermark in low-order bits of image.
4539 depth=stegano_image->depth;
4541 for (i=(long) depth-1; (i >= 0) && (j < (long) depth); i--)
4543 for (y=0; (y < (long) watermark->rows) && (j < (long) depth); y++)
4545 for (x=0; (x < (long) watermark->columns) && (j < (long) depth); x++)
4547 (void) GetOneVirtualPixel(watermark,x,y,&pixel,exception);
4548 if ((k/(long) stegano_image->columns) >= (long) stegano_image->rows)
4550 q=GetAuthenticPixels(stegano_image,k % (long) stegano_image->columns,
4551 k/(long) stegano_image->columns,1,1,exception);
4552 if (q == (PixelPacket *) NULL)
4558 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4563 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4568 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4572 if (SyncAuthenticPixels(stegano_image,exception) == MagickFalse)
4578 if (k == (long) (stegano_image->columns*stegano_image->columns))
4580 if (k == image->offset)
4584 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4589 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4591 if (proceed == MagickFalse)
4595 if (stegano_image->storage_class == PseudoClass)
4596 (void) SyncImage(stegano_image);
4597 return(stegano_image);
4601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4605 % S t e r e o A n a g l y p h I m a g e %
4609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4611 % StereoAnaglyphImage() combines two images and produces a single image that
4612 % is the composite of a left and right image of a stereo pair. Special
4613 % red-green stereo glasses are required to view this effect.
4615 % The format of the StereoAnaglyphImage method is:
4617 % Image *StereoImage(const Image *left_image,const Image *right_image,
4618 % ExceptionInfo *exception)
4619 % Image *StereoAnaglyphImage(const Image *left_image,
4620 % const Image *right_image,const long x_offset,const long y_offset,
4621 % ExceptionInfo *exception)
4623 % A description of each parameter follows:
4625 % o left_image: the left image.
4627 % o right_image: the right image.
4629 % o exception: return any errors or warnings in this structure.
4631 % o x_offset: amount, in pixels, by which the left image is offset to the
4632 % right of the right image.
4634 % o y_offset: amount, in pixels, by which the left image is offset to the
4635 % bottom of the right image.
4639 MagickExport Image *StereoImage(const Image *left_image,
4640 const Image *right_image,ExceptionInfo *exception)
4642 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4645 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4646 const Image *right_image,const long x_offset,const long y_offset,
4647 ExceptionInfo *exception)
4649 #define StereoImageTag "Stereo/Image"
4663 assert(left_image != (const Image *) NULL);
4664 assert(left_image->signature == MagickSignature);
4665 if (left_image->debug != MagickFalse)
4666 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4667 left_image->filename);
4668 assert(right_image != (const Image *) NULL);
4669 assert(right_image->signature == MagickSignature);
4670 assert(exception != (ExceptionInfo *) NULL);
4671 assert(exception->signature == MagickSignature);
4672 assert(right_image != (const Image *) NULL);
4674 if ((left_image->columns != right_image->columns) ||
4675 (left_image->rows != right_image->rows))
4676 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4678 Initialize stereo image attributes.
4680 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4681 MagickTrue,exception);
4682 if (stereo_image == (Image *) NULL)
4683 return((Image *) NULL);
4684 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4686 InheritException(exception,&stereo_image->exception);
4687 stereo_image=DestroyImage(stereo_image);
4688 return((Image *) NULL);
4691 Copy left image to red channel and right image to blue channel.
4693 for (y=0; y < (long) stereo_image->rows; y++)
4695 register const PixelPacket
4702 register PixelPacket
4705 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4707 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4708 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4709 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4710 (r == (PixelPacket *) NULL))
4712 for (x=0; x < (long) stereo_image->columns; x++)
4714 r->red=GetRedPixelComponent(p);
4717 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4722 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4724 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4729 proceed=SetImageProgress(image,StereoImageTag,y,stereo_image->rows);
4730 if (proceed == MagickFalse)
4734 return(stereo_image);
4738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4742 % S w i r l I m a g e %
4746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4748 % SwirlImage() swirls the pixels about the center of the image, where
4749 % degrees indicates the sweep of the arc through which each pixel is moved.
4750 % You get a more dramatic effect as the degrees move from 1 to 360.
4752 % The format of the SwirlImage method is:
4754 % Image *SwirlImage(const Image *image,double degrees,
4755 % ExceptionInfo *exception)
4757 % A description of each parameter follows:
4759 % o image: the image.
4761 % o degrees: Define the tightness of the swirling effect.
4763 % o exception: return any errors or warnings in this structure.
4766 MagickExport Image *SwirlImage(const Image *image,double degrees,
4767 ExceptionInfo *exception)
4769 #define SwirlImageTag "Swirl/Image"
4796 **restrict resample_filter;
4799 Initialize swirl image attributes.
4801 assert(image != (const Image *) NULL);
4802 assert(image->signature == MagickSignature);
4803 if (image->debug != MagickFalse)
4804 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4805 assert(exception != (ExceptionInfo *) NULL);
4806 assert(exception->signature == MagickSignature);
4807 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4808 if (swirl_image == (Image *) NULL)
4809 return((Image *) NULL);
4810 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4812 InheritException(exception,&swirl_image->exception);
4813 swirl_image=DestroyImage(swirl_image);
4814 return((Image *) NULL);
4816 if (swirl_image->background_color.opacity != OpaqueOpacity)
4817 swirl_image->matte=MagickTrue;
4819 Compute scaling factor.
4821 center.x=(double) image->columns/2.0;
4822 center.y=(double) image->rows/2.0;
4823 radius=MagickMax(center.x,center.y);
4826 if (image->columns > image->rows)
4827 scale.y=(double) image->columns/(double) image->rows;
4829 if (image->columns < image->rows)
4830 scale.x=(double) image->rows/(double) image->columns;
4831 degrees=(double) DegreesToRadians(degrees);
4837 GetMagickPixelPacket(swirl_image,&zero);
4838 resample_filter=AcquireResampleFilterThreadSet(image,
4839 UndefinedVirtualPixelMethod,MagickTrue,exception);
4840 image_view=AcquireCacheView(image);
4841 swirl_view=AcquireCacheView(swirl_image);
4842 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4843 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4845 for (y=0; y < (long) image->rows; y++)
4856 register IndexPacket
4857 *restrict swirl_indexes;
4863 register PixelPacket
4866 if (status == MagickFalse)
4868 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4870 if (q == (PixelPacket *) NULL)
4875 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4876 delta.y=scale.y*(double) (y-center.y);
4878 id=GetOpenMPThreadId();
4879 for (x=0; x < (long) image->columns; x++)
4882 Determine if the pixel is within an ellipse.
4884 delta.x=scale.x*(double) (x-center.x);
4885 distance=delta.x*delta.x+delta.y*delta.y;
4886 if (distance < (radius*radius))
4896 factor=1.0-sqrt((double) distance)/radius;
4897 sine=sin((double) (degrees*factor*factor));
4898 cosine=cos((double) (degrees*factor*factor));
4899 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4900 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4901 cosine*delta.y)/scale.y+center.y),&pixel);
4902 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4906 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4908 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4913 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4914 #pragma omp critical (MagickCore_SwirlImage)
4916 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4917 if (proceed == MagickFalse)
4921 swirl_view=DestroyCacheView(swirl_view);
4922 image_view=DestroyCacheView(image_view);
4923 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
4924 if (status == MagickFalse)
4925 swirl_image=DestroyImage(swirl_image);
4926 return(swirl_image);
4930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4934 % T i n t I m a g e %
4938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4940 % TintImage() applies a color vector to each pixel in the image. The length
4941 % of the vector is 0 for black and white and at its maximum for the midtones.
4942 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
4944 % The format of the TintImage method is:
4946 % Image *TintImage(const Image *image,const char *opacity,
4947 % const PixelPacket tint,ExceptionInfo *exception)
4949 % A description of each parameter follows:
4951 % o image: the image.
4953 % o opacity: A color value used for tinting.
4955 % o tint: A color value used for tinting.
4957 % o exception: return any errors or warnings in this structure.
4960 MagickExport Image *TintImage(const Image *image,const char *opacity,
4961 const PixelPacket tint,ExceptionInfo *exception)
4963 #define TintImageTag "Tint/Image"
4990 Allocate tint image.
4992 assert(image != (const Image *) NULL);
4993 assert(image->signature == MagickSignature);
4994 if (image->debug != MagickFalse)
4995 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4996 assert(exception != (ExceptionInfo *) NULL);
4997 assert(exception->signature == MagickSignature);
4998 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4999 if (tint_image == (Image *) NULL)
5000 return((Image *) NULL);
5001 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5003 InheritException(exception,&tint_image->exception);
5004 tint_image=DestroyImage(tint_image);
5005 return((Image *) NULL);
5007 if (opacity == (const char *) NULL)
5010 Determine RGB values of the color.
5012 flags=ParseGeometry(opacity,&geometry_info);
5013 pixel.red=geometry_info.rho;
5014 if ((flags & SigmaValue) != 0)
5015 pixel.green=geometry_info.sigma;
5017 pixel.green=pixel.red;
5018 if ((flags & XiValue) != 0)
5019 pixel.blue=geometry_info.xi;
5021 pixel.blue=pixel.red;
5022 if ((flags & PsiValue) != 0)
5023 pixel.opacity=geometry_info.psi;
5025 pixel.opacity=(MagickRealType) OpaqueOpacity;
5026 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5027 PixelIntensity(&tint));
5028 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5029 PixelIntensity(&tint));
5030 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5031 PixelIntensity(&tint));
5037 image_view=AcquireCacheView(image);
5038 tint_view=AcquireCacheView(tint_image);
5039 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5040 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5042 for (y=0; y < (long) image->rows; y++)
5044 register const PixelPacket
5050 register PixelPacket
5053 if (status == MagickFalse)
5055 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5056 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5058 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5063 for (x=0; x < (long) image->columns; x++)
5071 weight=QuantumScale*p->red-0.5;
5072 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5074 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5075 weight=QuantumScale*p->green-0.5;
5076 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5078 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5079 weight=QuantumScale*p->blue-0.5;
5080 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5082 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5083 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5087 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5089 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5094 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5095 #pragma omp critical (MagickCore_TintImage)
5097 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5098 if (proceed == MagickFalse)
5102 tint_view=DestroyCacheView(tint_view);
5103 image_view=DestroyCacheView(image_view);
5104 if (status == MagickFalse)
5105 tint_image=DestroyImage(tint_image);
5110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5114 % V i g n e t t e I m a g e %
5118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5120 % VignetteImage() softens the edges of the image in vignette style.
5122 % The format of the VignetteImage method is:
5124 % Image *VignetteImage(const Image *image,const double radius,
5125 % const double sigma,const long x,const long y,ExceptionInfo *exception)
5127 % A description of each parameter follows:
5129 % o image: the image.
5131 % o radius: the radius of the pixel neighborhood.
5133 % o sigma: the standard deviation of the Gaussian, in pixels.
5135 % o x, y: Define the x and y ellipse offset.
5137 % o exception: return any errors or warnings in this structure.
5140 MagickExport Image *VignetteImage(const Image *image,const double radius,
5141 const double sigma,const long x,const long y,ExceptionInfo *exception)
5144 ellipse[MaxTextExtent];
5155 assert(image != (Image *) NULL);
5156 assert(image->signature == MagickSignature);
5157 if (image->debug != MagickFalse)
5158 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5159 assert(exception != (ExceptionInfo *) NULL);
5160 assert(exception->signature == MagickSignature);
5161 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5162 if (canvas_image == (Image *) NULL)
5163 return((Image *) NULL);
5164 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5166 InheritException(exception,&canvas_image->exception);
5167 canvas_image=DestroyImage(canvas_image);
5168 return((Image *) NULL);
5170 canvas_image->matte=MagickTrue;
5171 oval_image=CloneImage(canvas_image,canvas_image->columns,
5172 canvas_image->rows,MagickTrue,exception);
5173 if (oval_image == (Image *) NULL)
5175 canvas_image=DestroyImage(canvas_image);
5176 return((Image *) NULL);
5178 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5179 (void) SetImageBackgroundColor(oval_image);
5180 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5181 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5182 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5183 (void) FormatMagickString(ellipse,MaxTextExtent,
5184 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5185 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5186 draw_info->primitive=AcquireString(ellipse);
5187 (void) DrawImage(oval_image,draw_info);
5188 draw_info=DestroyDrawInfo(draw_info);
5189 blur_image=BlurImage(oval_image,radius,sigma,exception);
5190 oval_image=DestroyImage(oval_image);
5191 if (blur_image == (Image *) NULL)
5193 canvas_image=DestroyImage(canvas_image);
5194 return((Image *) NULL);
5196 blur_image->matte=MagickFalse;
5197 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5198 blur_image=DestroyImage(blur_image);
5199 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5200 canvas_image=DestroyImage(canvas_image);
5201 return(vignette_image);
5205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5209 % W a v e I m a g e %
5213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5215 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5216 % vertically along a sine wave whose amplitude and wavelength is specified
5217 % by the given parameters.
5219 % The format of the WaveImage method is:
5221 % Image *WaveImage(const Image *image,const double amplitude,
5222 % const double wave_length,ExceptionInfo *exception)
5224 % A description of each parameter follows:
5226 % o image: the image.
5228 % o amplitude, wave_length: Define the amplitude and wave length of the
5231 % o exception: return any errors or warnings in this structure.
5234 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5235 const double wave_length,ExceptionInfo *exception)
5237 #define WaveImageTag "Wave/Image"
5262 **restrict resample_filter;
5265 Initialize wave image attributes.
5267 assert(image != (Image *) NULL);
5268 assert(image->signature == MagickSignature);
5269 if (image->debug != MagickFalse)
5270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5271 assert(exception != (ExceptionInfo *) NULL);
5272 assert(exception->signature == MagickSignature);
5273 wave_image=CloneImage(image,image->columns,(unsigned long) (image->rows+2.0*
5274 fabs(amplitude)),MagickTrue,exception);
5275 if (wave_image == (Image *) NULL)
5276 return((Image *) NULL);
5277 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5279 InheritException(exception,&wave_image->exception);
5280 wave_image=DestroyImage(wave_image);
5281 return((Image *) NULL);
5283 if (wave_image->background_color.opacity != OpaqueOpacity)
5284 wave_image->matte=MagickTrue;
5288 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5290 if (sine_map == (MagickRealType *) NULL)
5292 wave_image=DestroyImage(wave_image);
5293 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5295 for (i=0; i < (long) wave_image->columns; i++)
5296 sine_map[i]=fabs(amplitude)+amplitude*sin((2*MagickPI*i)/wave_length);
5302 GetMagickPixelPacket(wave_image,&zero);
5303 resample_filter=AcquireResampleFilterThreadSet(image,
5304 BackgroundVirtualPixelMethod,MagickTrue,exception);
5305 wave_view=AcquireCacheView(wave_image);
5306 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5307 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5309 for (y=0; y < (long) wave_image->rows; y++)
5314 register IndexPacket
5321 register PixelPacket
5324 if (status == MagickFalse)
5326 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5328 if (q == (PixelPacket *) NULL)
5333 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5335 id=GetOpenMPThreadId();
5336 for (x=0; x < (long) wave_image->columns; x++)
5338 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5339 sine_map[x]),&pixel);
5340 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5343 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5345 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5350 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5351 #pragma omp critical (MagickCore_WaveImage)
5353 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5354 if (proceed == MagickFalse)
5358 wave_view=DestroyCacheView(wave_view);
5359 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5360 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5361 if (status == MagickFalse)
5362 wave_image=DestroyImage(wave_image);