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 < (ssize_t) 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"
306 **restrict random_info;
312 Initialize noise image attributes.
314 assert(image != (const Image *) NULL);
315 assert(image->signature == MagickSignature);
316 if (image->debug != MagickFalse)
317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
318 assert(exception != (ExceptionInfo *) NULL);
319 assert(exception->signature == MagickSignature);
320 noise_image=CloneImage(image,0,0,MagickTrue,exception);
321 if (noise_image == (Image *) NULL)
322 return((Image *) NULL);
323 if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
325 InheritException(exception,&noise_image->exception);
326 noise_image=DestroyImage(noise_image);
327 return((Image *) NULL);
330 Add noise in each row.
333 option=GetImageArtifact(image,"attenuate");
334 if (option != (char *) NULL)
335 attenuate=StringToDouble(option);
338 random_info=AcquireRandomInfoThreadSet();
339 image_view=AcquireCacheView(image);
340 noise_view=AcquireCacheView(noise_image);
341 #if defined(MAGICKCORE_OPENMP_SUPPORT)
342 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
344 for (y=0; y < (ssize_t) image->rows; y++)
349 register const IndexPacket
352 register const PixelPacket
356 *restrict noise_indexes;
365 if (status == MagickFalse)
367 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
368 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
370 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
375 indexes=GetCacheViewVirtualIndexQueue(image_view);
376 noise_indexes=GetCacheViewAuthenticIndexQueue(noise_view);
377 id=GetOpenMPThreadId();
378 for (x=0; x < (ssize_t) image->columns; x++)
380 if ((channel & RedChannel) != 0)
381 q->red=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
382 p->red,noise_type,attenuate));
383 if ((channel & GreenChannel) != 0)
384 q->green=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
385 p->green,noise_type,attenuate));
386 if ((channel & BlueChannel) != 0)
387 q->blue=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
388 p->blue,noise_type,attenuate));
389 if ((channel & OpacityChannel) != 0)
390 q->opacity=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
391 p->opacity,noise_type,attenuate));
392 if (((channel & IndexChannel) != 0) &&
393 (image->colorspace == CMYKColorspace))
394 noise_indexes[x]=(IndexPacket) ClampToQuantum(GenerateDifferentialNoise(
395 random_info[id],indexes[x],noise_type,attenuate));
399 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
400 if (sync == MagickFalse)
402 if (image->progress_monitor != (MagickProgressMonitor) NULL)
407 #if defined(MAGICKCORE_OPENMP_SUPPORT)
408 #pragma omp critical (MagickCore_AddNoiseImage)
410 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
412 if (proceed == MagickFalse)
416 noise_view=DestroyCacheView(noise_view);
417 image_view=DestroyCacheView(image_view);
418 random_info=DestroyRandomInfoThreadSet(random_info);
419 if (status == MagickFalse)
420 noise_image=DestroyImage(noise_image);
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % B l u e S h i f t I m a g e %
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % BlueShiftImage() mutes the colors of the image to simulate a scene at
436 % nighttime in the moonlight.
438 % The format of the BlueShiftImage method is:
440 % Image *BlueShiftImage(const Image *image,const double factor,
441 % ExceptionInfo *exception)
443 % A description of each parameter follows:
445 % o image: the image.
447 % o factor: the shift factor.
449 % o exception: return any errors or warnings in this structure.
452 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
453 ExceptionInfo *exception)
455 #define BlueShiftImageTag "BlueShift/Image"
474 Allocate blue shift image.
476 assert(image != (const Image *) NULL);
477 assert(image->signature == MagickSignature);
478 if (image->debug != MagickFalse)
479 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
480 assert(exception != (ExceptionInfo *) NULL);
481 assert(exception->signature == MagickSignature);
482 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
484 if (shift_image == (Image *) NULL)
485 return((Image *) NULL);
486 if (SetImageStorageClass(shift_image,DirectClass) == MagickFalse)
488 InheritException(exception,&shift_image->exception);
489 shift_image=DestroyImage(shift_image);
490 return((Image *) NULL);
493 Blue-shift DirectClass image.
497 image_view=AcquireCacheView(image);
498 shift_view=AcquireCacheView(shift_image);
499 #if defined(MAGICKCORE_OPENMP_SUPPORT)
500 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
502 for (y=0; y < (ssize_t) image->rows; y++)
513 register const PixelPacket
522 if (status == MagickFalse)
524 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
525 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
527 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
532 for (x=0; x < (ssize_t) image->columns; x++)
534 quantum=GetRedPixelComponent(p);
535 if (p->green < quantum)
536 quantum=GetGreenPixelComponent(p);
537 if (p->blue < quantum)
538 quantum=GetBluePixelComponent(p);
539 pixel.red=0.5*(p->red+factor*quantum);
540 pixel.green=0.5*(p->green+factor*quantum);
541 pixel.blue=0.5*(p->blue+factor*quantum);
542 quantum=GetRedPixelComponent(p);
543 if (p->green > quantum)
544 quantum=GetGreenPixelComponent(p);
545 if (p->blue > quantum)
546 quantum=GetBluePixelComponent(p);
547 pixel.red=0.5*(pixel.red+factor*quantum);
548 pixel.green=0.5*(pixel.green+factor*quantum);
549 pixel.blue=0.5*(pixel.blue+factor*quantum);
550 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
551 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
552 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
556 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
557 if (sync == MagickFalse)
559 if (image->progress_monitor != (MagickProgressMonitor) NULL)
564 #if defined(MAGICKCORE_OPENMP_SUPPORT)
565 #pragma omp critical (MagickCore_BlueShiftImage)
567 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
569 if (proceed == MagickFalse)
573 image_view=DestroyCacheView(image_view);
574 shift_view=DestroyCacheView(shift_view);
575 if (status == MagickFalse)
576 shift_image=DestroyImage(shift_image);
581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
585 % C h a r c o a l I m a g e %
589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591 % CharcoalImage() creates a new image that is a copy of an existing one with
592 % the edge highlighted. It allocates the memory necessary for the new Image
593 % structure and returns a pointer to the new image.
595 % The format of the CharcoalImage method is:
597 % Image *CharcoalImage(const Image *image,const double radius,
598 % const double sigma,ExceptionInfo *exception)
600 % A description of each parameter follows:
602 % o image: the image.
604 % o radius: the radius of the pixel neighborhood.
606 % o sigma: the standard deviation of the Gaussian, in pixels.
608 % o exception: return any errors or warnings in this structure.
611 MagickExport Image *CharcoalImage(const Image *image,const double radius,
612 const double sigma,ExceptionInfo *exception)
619 assert(image != (Image *) NULL);
620 assert(image->signature == MagickSignature);
621 if (image->debug != MagickFalse)
622 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
623 assert(exception != (ExceptionInfo *) NULL);
624 assert(exception->signature == MagickSignature);
625 clone_image=CloneImage(image,0,0,MagickTrue,exception);
626 if (clone_image == (Image *) NULL)
627 return((Image *) NULL);
628 (void) SetImageType(clone_image,GrayscaleType);
629 edge_image=EdgeImage(clone_image,radius,exception);
630 clone_image=DestroyImage(clone_image);
631 if (edge_image == (Image *) NULL)
632 return((Image *) NULL);
633 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
634 edge_image=DestroyImage(edge_image);
635 if (charcoal_image == (Image *) NULL)
636 return((Image *) NULL);
637 (void) NormalizeImage(charcoal_image);
638 (void) NegateImage(charcoal_image,MagickFalse);
639 (void) SetImageType(charcoal_image,GrayscaleType);
640 return(charcoal_image);
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 % C o l o r i z e I m a g e %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % ColorizeImage() blends the fill color with each pixel in the image.
655 % A percentage blend is specified with opacity. Control the application
656 % of different color components by specifying a different percentage for
657 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
659 % The format of the ColorizeImage method is:
661 % Image *ColorizeImage(const Image *image,const char *opacity,
662 % const PixelPacket colorize,ExceptionInfo *exception)
664 % A description of each parameter follows:
666 % o image: the image.
668 % o opacity: A character string indicating the level of opacity as a
671 % o colorize: A color value.
673 % o exception: return any errors or warnings in this structure.
676 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
677 const PixelPacket colorize,ExceptionInfo *exception)
679 #define ColorizeImageTag "Colorize/Image"
707 Allocate colorized image.
709 assert(image != (const Image *) NULL);
710 assert(image->signature == MagickSignature);
711 if (image->debug != MagickFalse)
712 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
713 assert(exception != (ExceptionInfo *) NULL);
714 assert(exception->signature == MagickSignature);
715 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
717 if (colorize_image == (Image *) NULL)
718 return((Image *) NULL);
719 if (SetImageStorageClass(colorize_image,DirectClass) == MagickFalse)
721 InheritException(exception,&colorize_image->exception);
722 colorize_image=DestroyImage(colorize_image);
723 return((Image *) NULL);
725 if (opacity == (const char *) NULL)
726 return(colorize_image);
728 Determine RGB values of the pen color.
730 flags=ParseGeometry(opacity,&geometry_info);
731 pixel.red=geometry_info.rho;
732 pixel.green=geometry_info.rho;
733 pixel.blue=geometry_info.rho;
734 pixel.opacity=(MagickRealType) OpaqueOpacity;
735 if ((flags & SigmaValue) != 0)
736 pixel.green=geometry_info.sigma;
737 if ((flags & XiValue) != 0)
738 pixel.blue=geometry_info.xi;
739 if ((flags & PsiValue) != 0)
740 pixel.opacity=geometry_info.psi;
742 Colorize DirectClass image.
746 image_view=AcquireCacheView(image);
747 colorize_view=AcquireCacheView(colorize_image);
748 #if defined(MAGICKCORE_OPENMP_SUPPORT)
749 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
751 for (y=0; y < (ssize_t) image->rows; y++)
756 register const PixelPacket
765 if (status == MagickFalse)
767 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
768 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
770 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
775 for (x=0; x < (ssize_t) image->columns; x++)
777 q->red=(Quantum) ((p->red*(100.0-pixel.red)+
778 colorize.red*pixel.red)/100.0);
779 q->green=(Quantum) ((p->green*(100.0-pixel.green)+
780 colorize.green*pixel.green)/100.0);
781 q->blue=(Quantum) ((p->blue*(100.0-pixel.blue)+
782 colorize.blue*pixel.blue)/100.0);
783 q->opacity=(Quantum) ((p->opacity*(100.0-pixel.opacity)+
784 colorize.opacity*pixel.opacity)/100.0);
788 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
789 if (sync == MagickFalse)
791 if (image->progress_monitor != (MagickProgressMonitor) NULL)
796 #if defined(MAGICKCORE_OPENMP_SUPPORT)
797 #pragma omp critical (MagickCore_ColorizeImage)
799 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
800 if (proceed == MagickFalse)
804 image_view=DestroyCacheView(image_view);
805 colorize_view=DestroyCacheView(colorize_view);
806 if (status == MagickFalse)
807 colorize_image=DestroyImage(colorize_image);
808 return(colorize_image);
812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 % C o l o r M a t r i x I m a g e %
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 % ColorMatrixImage() applies color transformation to an image. This method
823 % permits saturation changes, hue rotation, luminance to alpha, and various
824 % other effects. Although variable-sized transformation matrices can be used,
825 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
826 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
827 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
828 % and offsets are normalized (divide Flash offset by 255).
830 % The format of the ColorMatrixImage method is:
832 % Image *ColorMatrixImage(const Image *image,
833 % const KernelInfo *color_matrix,ExceptionInfo *exception)
835 % A description of each parameter follows:
837 % o image: the image.
839 % o color_matrix: the color matrix.
841 % o exception: return any errors or warnings in this structure.
844 MagickExport Image *ColorMatrixImage(const Image *image,
845 const KernelInfo *color_matrix,ExceptionInfo *exception)
847 #define ColorMatrixImageTag "ColorMatrix/Image"
856 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
857 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
858 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
859 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
860 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
861 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
884 assert(image != (Image *) NULL);
885 assert(image->signature == MagickSignature);
886 if (image->debug != MagickFalse)
887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
888 assert(exception != (ExceptionInfo *) NULL);
889 assert(exception->signature == MagickSignature);
891 for (v=0; v < (ssize_t) color_matrix->height; v++)
892 for (u=0; u < (ssize_t) color_matrix->width; u++)
894 if ((v < 6) && (u < 6))
895 ColorMatrix[v][u]=color_matrix->values[i];
899 Initialize color image.
901 color_image=CloneImage(image,0,0,MagickTrue,exception);
902 if (color_image == (Image *) NULL)
903 return((Image *) NULL);
904 if (SetImageStorageClass(color_image,DirectClass) == MagickFalse)
906 InheritException(exception,&color_image->exception);
907 color_image=DestroyImage(color_image);
908 return((Image *) NULL);
910 if (image->debug != MagickFalse)
913 format[MaxTextExtent],
916 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
917 " ColorMatrix image with color matrix:");
918 message=AcquireString("");
919 for (v=0; v < 6; v++)
922 (void) FormatMagickString(format,MaxTextExtent,"%ld: ",(long) v);
923 (void) ConcatenateString(&message,format);
924 for (u=0; u < 6; u++)
926 (void) FormatMagickString(format,MaxTextExtent,"%+f ",
928 (void) ConcatenateString(&message,format);
930 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
932 message=DestroyString(message);
939 image_view=AcquireCacheView(image);
940 color_view=AcquireCacheView(color_image);
941 #if defined(MAGICKCORE_OPENMP_SUPPORT)
942 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
944 for (y=0; y < (ssize_t) image->rows; y++)
949 register const IndexPacket
952 register const PixelPacket
959 *restrict color_indexes;
964 if (status == MagickFalse)
966 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
967 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
969 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
974 indexes=GetCacheViewVirtualIndexQueue(image_view);
975 color_indexes=GetCacheViewAuthenticIndexQueue(color_view);
976 for (x=0; x < (ssize_t) image->columns; x++)
984 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
985 for (v=0; v < (ssize_t) height; v++)
987 pixel=ColorMatrix[v][0]*p->red+ColorMatrix[v][1]*p->green+
988 ColorMatrix[v][2]*p->blue;
989 if (image->matte != MagickFalse)
990 pixel+=ColorMatrix[v][3]*(QuantumRange-p->opacity);
991 if (image->colorspace == CMYKColorspace)
992 pixel+=ColorMatrix[v][4]*indexes[x];
993 pixel+=QuantumRange*ColorMatrix[v][5];
996 case 0: q->red=ClampToQuantum(pixel); break;
997 case 1: q->green=ClampToQuantum(pixel); break;
998 case 2: q->blue=ClampToQuantum(pixel); break;
1001 if (image->matte != MagickFalse)
1002 q->opacity=ClampToQuantum(QuantumRange-pixel);
1007 if (image->colorspace == CMYKColorspace)
1008 color_indexes[x]=ClampToQuantum(pixel);
1016 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1018 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1023 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1024 #pragma omp critical (MagickCore_ColorMatrixImage)
1026 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1028 if (proceed == MagickFalse)
1032 color_view=DestroyCacheView(color_view);
1033 image_view=DestroyCacheView(image_view);
1034 if (status == MagickFalse)
1035 color_image=DestroyImage(color_image);
1036 return(color_image);
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 + D e s t r o y F x I n f o %
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1052 % The format of the DestroyFxInfo method is:
1054 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1056 % A description of each parameter follows:
1058 % o fx_info: the fx info.
1061 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1066 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1067 fx_info->expression=DestroyString(fx_info->expression);
1068 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1069 fx_info->colors=DestroySplayTree(fx_info->colors);
1070 for (i=0; i < (ssize_t) GetImageListLength(fx_info->images); i++)
1071 fx_info->resample_filter[i]=DestroyResampleFilter(
1072 fx_info->resample_filter[i]);
1073 fx_info->resample_filter=(ResampleFilter **) RelinquishMagickMemory(
1074 fx_info->resample_filter);
1075 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1076 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1085 + 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 %
1089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091 % FxEvaluateChannelExpression() evaluates an expression and returns the
1094 % The format of the FxEvaluateExpression method is:
1096 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1097 % const ChannelType channel,const ssize_t x,const ssize_t y,
1098 % MagickRealType *alpha,Exceptioninfo *exception)
1099 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1100 % MagickRealType *alpha,Exceptioninfo *exception)
1102 % A description of each parameter follows:
1104 % o fx_info: the fx info.
1106 % o channel: the channel.
1108 % o x,y: the pixel position.
1110 % o alpha: the result.
1112 % o exception: return any errors or warnings in this structure.
1116 static inline double MagickMax(const double x,const double y)
1123 static inline double MagickMin(const double x,const double y)
1130 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1131 ChannelType channel,const char *symbol,ExceptionInfo *exception)
1135 statistic[MaxTextExtent];
1143 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1145 switch (*++p) /* e.g. depth.r */
1147 case 'r': channel=RedChannel; break;
1148 case 'g': channel=GreenChannel; break;
1149 case 'b': channel=BlueChannel; break;
1150 case 'c': channel=CyanChannel; break;
1151 case 'm': channel=MagentaChannel; break;
1152 case 'y': channel=YellowChannel; break;
1153 case 'k': channel=BlackChannel; break;
1156 (void) FormatMagickString(key,MaxTextExtent,"%p.%ld.%s",(void *) image,
1157 (long) channel,symbol);
1158 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1159 if (value != (const char *) NULL)
1160 return(QuantumScale*StringToDouble(value));
1161 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1162 if (LocaleNCompare(symbol,"depth",5) == 0)
1167 depth=GetImageChannelDepth(image,channel,exception);
1168 (void) FormatMagickString(statistic,MaxTextExtent,"%lu",
1169 (unsigned long) depth);
1171 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1177 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1179 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
1181 if (LocaleNCompare(symbol,"maxima",6) == 0)
1187 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1188 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
1190 if (LocaleNCompare(symbol,"mean",4) == 0)
1196 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1198 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
1200 if (LocaleNCompare(symbol,"minima",6) == 0)
1206 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1207 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
1209 if (LocaleNCompare(symbol,"skewness",8) == 0)
1215 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1217 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
1219 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1225 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1227 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
1228 standard_deviation);
1230 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1231 ConstantString(statistic));
1232 return(QuantumScale*StringToDouble(statistic));
1235 static MagickRealType
1236 FxEvaluateSubexpression(FxInfo *,const ChannelType,const ssize_t,const ssize_t,
1237 const char *,MagickRealType *,ExceptionInfo *);
1239 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1240 const ssize_t x,const ssize_t y,const char *expression,ExceptionInfo *exception)
1246 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1247 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1250 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1251 const ssize_t x,const ssize_t y,const char *expression,ExceptionInfo *exception)
1257 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1258 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1261 static inline const char *FxSubexpression(const char *expression,
1262 ExceptionInfo *exception)
1271 subexpression=expression;
1272 while ((*subexpression != '\0') &&
1273 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1275 if (strchr("(",(int) *subexpression) != (char *) NULL)
1278 if (strchr(")",(int) *subexpression) != (char *) NULL)
1282 if (*subexpression == '\0')
1283 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1284 "UnbalancedParenthesis","`%s'",expression);
1285 return(subexpression);
1288 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1289 const ssize_t x,const ssize_t y,const char *expression,ExceptionInfo *exception)
1293 subexpression[MaxTextExtent],
1294 symbol[MaxTextExtent];
1323 i=GetImageIndexInList(fx_info->images);
1327 if (isalpha((int) *(p+1)) == 0)
1329 if (strchr("suv",(int) *p) != (char *) NULL)
1336 i=GetImageIndexInList(fx_info->images);
1339 case 'u': i=0; break;
1340 case 'v': i=1; break;
1347 for (p++; *p != '\0'; )
1361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1363 i=(ssize_t) (alpha+0.5);
1369 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1376 for (p++; *p != '\0'; )
1390 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1401 for (p++; *p != '\0'; )
1415 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1425 length=GetImageListLength(fx_info->images);
1427 i+=(ssize_t) length;
1429 image=GetImageFromList(fx_info->images,i);
1430 if (image == (Image *) NULL)
1432 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1433 "NoSuchImage","`%s'",expression);
1436 (void) ResamplePixelColor(fx_info->resample_filter[i],point.x,point.y,&pixel);
1437 if ((strlen(p) > 2) &&
1438 (LocaleCompare(p,"intensity") != 0) &&
1439 (LocaleCompare(p,"luminance") != 0) &&
1440 (LocaleCompare(p,"hue") != 0) &&
1441 (LocaleCompare(p,"saturation") != 0) &&
1442 (LocaleCompare(p,"lightness") != 0))
1445 name[MaxTextExtent];
1447 (void) CopyMagickString(name,p,MaxTextExtent);
1448 for (q=name+(strlen(name)-1); q > name; q--)
1458 if ((strlen(name) > 2) &&
1459 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1464 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1466 if (color != (MagickPixelPacket *) NULL)
1472 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1474 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1475 CloneMagickPixelPacket(&pixel));
1480 (void) CopyMagickString(symbol,p,MaxTextExtent);
1481 StripString(symbol);
1482 if (*symbol == '\0')
1486 case RedChannel: return(QuantumScale*pixel.red);
1487 case GreenChannel: return(QuantumScale*pixel.green);
1488 case BlueChannel: return(QuantumScale*pixel.blue);
1489 case OpacityChannel:
1491 if (pixel.matte == MagickFalse)
1493 fx_info->matte=MagickFalse;
1496 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1500 if (image->colorspace != CMYKColorspace)
1502 (void) ThrowMagickException(exception,GetMagickModule(),
1503 OptionError,"ColorSeparatedImageRequired","`%s'",
1507 return(QuantumScale*pixel.index);
1512 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1513 "UnableToParseExpression","`%s'",p);
1521 if (LocaleCompare(symbol,"a") == 0)
1522 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1528 if (LocaleCompare(symbol,"b") == 0)
1529 return(QuantumScale*pixel.blue);
1535 if (LocaleNCompare(symbol,"channel",7) == 0)
1543 flags=ParseGeometry(symbol+7,&channel_info);
1544 if (image->colorspace == CMYKColorspace)
1549 if ((flags & RhoValue) == 0)
1551 return(channel_info.rho);
1553 case MagentaChannel:
1555 if ((flags & SigmaValue) == 0)
1557 return(channel_info.sigma);
1561 if ((flags & XiValue) == 0)
1563 return(channel_info.xi);
1567 if ((flags & PsiValue) == 0)
1569 return(channel_info.psi);
1571 case OpacityChannel:
1573 if ((flags & ChiValue) == 0)
1575 return(channel_info.chi);
1584 if ((flags & RhoValue) == 0)
1586 return(channel_info.rho);
1590 if ((flags & SigmaValue) == 0)
1592 return(channel_info.sigma);
1596 if ((flags & XiValue) == 0)
1598 return(channel_info.xi);
1600 case OpacityChannel:
1602 if ((flags & PsiValue) == 0)
1604 return(channel_info.psi);
1608 if ((flags & ChiValue) == 0)
1610 return(channel_info.chi);
1617 if (LocaleCompare(symbol,"c") == 0)
1618 return(QuantumScale*pixel.red);
1624 if (LocaleNCompare(symbol,"depth",5) == 0)
1625 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1631 if (LocaleCompare(symbol,"g") == 0)
1632 return(QuantumScale*pixel.green);
1638 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1639 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1640 if (LocaleCompare(symbol,"k") == 0)
1642 if (image->colorspace != CMYKColorspace)
1644 (void) ThrowMagickException(exception,GetMagickModule(),
1645 OptionError,"ColorSeparatedImageRequired","`%s'",
1649 return(QuantumScale*pixel.index);
1656 if (LocaleCompare(symbol,"h") == 0)
1657 return((MagickRealType) image->rows);
1658 if (LocaleCompare(symbol,"hue") == 0)
1665 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1666 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1674 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1675 (LocaleCompare(symbol,"image.minima") == 0) ||
1676 (LocaleCompare(symbol,"image.maxima") == 0) ||
1677 (LocaleCompare(symbol,"image.mean") == 0) ||
1678 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1679 (LocaleCompare(symbol,"image.skewness") == 0) ||
1680 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1681 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1682 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1683 return(image->x_resolution);
1684 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1685 return(image->y_resolution);
1686 if (LocaleCompare(symbol,"intensity") == 0)
1687 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1688 if (LocaleCompare(symbol,"i") == 0)
1689 return((MagickRealType) x);
1695 if (LocaleCompare(symbol,"j") == 0)
1696 return((MagickRealType) y);
1702 if (LocaleCompare(symbol,"lightness") == 0)
1709 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1710 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1713 if (LocaleCompare(symbol,"luminance") == 0)
1718 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1719 return(QuantumScale*luminence);
1726 if (LocaleNCompare(symbol,"maxima",6) == 0)
1727 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1728 if (LocaleNCompare(symbol,"mean",4) == 0)
1729 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1730 if (LocaleNCompare(symbol,"minima",6) == 0)
1731 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1732 if (LocaleCompare(symbol,"m") == 0)
1733 return(QuantumScale*pixel.blue);
1739 if (LocaleCompare(symbol,"n") == 0)
1740 return((MagickRealType) GetImageListLength(fx_info->images));
1746 if (LocaleCompare(symbol,"o") == 0)
1747 return(QuantumScale*pixel.opacity);
1753 if (LocaleCompare(symbol,"page.height") == 0)
1754 return((MagickRealType) image->page.height);
1755 if (LocaleCompare(symbol,"page.width") == 0)
1756 return((MagickRealType) image->page.width);
1757 if (LocaleCompare(symbol,"page.x") == 0)
1758 return((MagickRealType) image->page.x);
1759 if (LocaleCompare(symbol,"page.y") == 0)
1760 return((MagickRealType) image->page.y);
1766 if (LocaleCompare(symbol,"resolution.x") == 0)
1767 return(image->x_resolution);
1768 if (LocaleCompare(symbol,"resolution.y") == 0)
1769 return(image->y_resolution);
1770 if (LocaleCompare(symbol,"r") == 0)
1771 return(QuantumScale*pixel.red);
1777 if (LocaleCompare(symbol,"saturation") == 0)
1784 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1785 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1788 if (LocaleNCompare(symbol,"skewness",8) == 0)
1789 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1790 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1791 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1797 if (LocaleCompare(symbol,"t") == 0)
1798 return((MagickRealType) fx_info->images->scene);
1804 if (LocaleCompare(symbol,"w") == 0)
1805 return((MagickRealType) image->columns);
1811 if (LocaleCompare(symbol,"y") == 0)
1812 return(QuantumScale*pixel.green);
1818 if (LocaleCompare(symbol,"z") == 0)
1823 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1824 fx_info->exception);
1832 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1833 if (value != (const char *) NULL)
1834 return((MagickRealType) StringToDouble(value));
1835 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1836 "UnableToParseExpression","`%s'",symbol);
1840 static const char *FxOperatorPrecedence(const char *expression,
1841 ExceptionInfo *exception)
1845 UndefinedPrecedence,
1847 BitwiseComplementPrecedence,
1852 RelationalPrecedence,
1853 EquivalencyPrecedence,
1854 BitwiseAndPrecedence,
1855 BitwiseOrPrecedence,
1856 LogicalAndPrecedence,
1857 LogicalOrPrecedence,
1859 AssignmentPrecedence,
1879 subexpression=(const char *) NULL;
1880 target=NullPrecedence;
1881 while (*expression != '\0')
1883 precedence=UndefinedPrecedence;
1884 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1889 switch (*expression)
1894 if (LocaleNCompare(expression,"atan2",5) == 0)
1904 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1905 (LocaleNCompare(expression,"j1",2) == 0))
1915 if ((c == (int) '{') || (c == (int) '['))
1918 if ((c == (int) '}') || (c == (int) ']'))
1921 switch ((unsigned char) *expression)
1926 precedence=BitwiseComplementPrecedence;
1931 precedence=ExponentPrecedence;
1936 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1937 (strchr(")",c) != (char *) NULL))) &&
1938 (((islower((int) ((char) *expression)) != 0) ||
1939 (strchr("(",(int) *expression) != (char *) NULL)) ||
1940 ((isdigit((int) ((char) c)) == 0) &&
1941 (isdigit((int) ((char) *expression)) != 0))) &&
1942 (strchr("xy",(int) *expression) == (char *) NULL))
1943 precedence=MultiplyPrecedence;
1950 precedence=MultiplyPrecedence;
1956 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1958 precedence=AdditionPrecedence;
1961 case LeftShiftOperator:
1962 case RightShiftOperator:
1964 precedence=ShiftPrecedence;
1968 case LessThanEqualOperator:
1969 case GreaterThanEqualOperator:
1972 precedence=RelationalPrecedence;
1976 case NotEqualOperator:
1978 precedence=EquivalencyPrecedence;
1983 precedence=BitwiseAndPrecedence;
1988 precedence=BitwiseOrPrecedence;
1991 case LogicalAndOperator:
1993 precedence=LogicalAndPrecedence;
1996 case LogicalOrOperator:
1998 precedence=LogicalOrPrecedence;
2004 precedence=TernaryPrecedence;
2009 precedence=AssignmentPrecedence;
2014 precedence=CommaPrecedence;
2019 precedence=SeparatorPrecedence;
2023 if ((precedence == BitwiseComplementPrecedence) ||
2024 (precedence == TernaryPrecedence) ||
2025 (precedence == AssignmentPrecedence))
2027 if (precedence > target)
2030 Right-to-left associativity.
2033 subexpression=expression;
2037 if (precedence >= target)
2040 Left-to-right associativity.
2043 subexpression=expression;
2045 if (strchr("(",(int) *expression) != (char *) NULL)
2046 expression=FxSubexpression(expression,exception);
2047 c=(int) (*expression++);
2049 return(subexpression);
2052 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2053 const ChannelType channel,const ssize_t x,const ssize_t y,const char *expression,
2054 MagickRealType *beta,ExceptionInfo *exception)
2058 subexpression[MaxTextExtent];
2068 if (exception->severity != UndefinedException)
2070 while (isspace((int) *expression) != 0)
2072 if (*expression == '\0')
2074 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2075 "MissingExpression","`%s'",expression);
2078 *subexpression='\0';
2079 p=FxOperatorPrecedence(expression,exception);
2080 if (p != (const char *) NULL)
2082 (void) CopyMagickString(subexpression,expression,(size_t)
2084 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2086 switch ((unsigned char) *p)
2090 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2091 *beta=(MagickRealType) (~(size_t) *beta);
2096 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2097 return(*beta == 0.0 ? 1.0 : 0.0);
2101 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2102 channel,x,y,++p,beta,exception));
2107 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2108 return(alpha*(*beta));
2112 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2115 if (exception->severity == UndefinedException)
2116 (void) ThrowMagickException(exception,GetMagickModule(),
2117 OptionError,"DivideByZero","`%s'",expression);
2120 return(alpha/(*beta));
2124 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2125 *beta=fabs(floor(((double) *beta)+0.5));
2128 (void) ThrowMagickException(exception,GetMagickModule(),
2129 OptionError,"DivideByZero","`%s'",expression);
2132 return(fmod((double) alpha,(double) *beta));
2136 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2137 return(alpha+(*beta));
2141 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2142 return(alpha-(*beta));
2144 case LeftShiftOperator:
2146 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2147 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2151 case RightShiftOperator:
2153 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2154 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2160 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2161 return(alpha < *beta ? 1.0 : 0.0);
2163 case LessThanEqualOperator:
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(alpha > *beta ? 1.0 : 0.0);
2173 case GreaterThanEqualOperator:
2175 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2176 return(alpha >= *beta ? 1.0 : 0.0);
2180 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2181 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2183 case NotEqualOperator:
2185 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2186 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2190 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2191 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2197 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2198 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2202 case LogicalAndOperator:
2204 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2205 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2208 case LogicalOrOperator:
2210 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2211 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2219 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2221 p=StringToken(":",&q);
2222 if (q == (char *) NULL)
2224 (void) ThrowMagickException(exception,GetMagickModule(),
2225 OptionError,"UnableToParseExpression","`%s'",subexpression);
2228 if (fabs((double) alpha) > MagickEpsilon)
2229 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2231 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2237 numeric[MaxTextExtent];
2240 while (isalpha((int) ((unsigned char) *q)) != 0)
2244 (void) ThrowMagickException(exception,GetMagickModule(),
2245 OptionError,"UnableToParseExpression","`%s'",subexpression);
2248 ClearMagickException(exception);
2249 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2250 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2252 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2253 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2254 subexpression),ConstantString(numeric));
2259 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2264 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2269 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2275 if (strchr("(",(int) *expression) != (char *) NULL)
2277 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2278 subexpression[strlen(subexpression)-1]='\0';
2279 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2283 switch (*expression)
2287 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2293 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2299 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2301 return((MagickRealType) (~(size_t) (gamma+0.5)));
2306 if (LocaleNCompare(expression,"abs",3) == 0)
2308 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2310 return((MagickRealType) fabs((double) alpha));
2312 if (LocaleNCompare(expression,"acos",4) == 0)
2314 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2316 return((MagickRealType) acos((double) alpha));
2318 #if defined(MAGICKCORE_HAVE_J1)
2319 if (LocaleNCompare(expression,"airy",4) == 0)
2321 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2325 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2326 return(gamma*gamma);
2329 if (LocaleNCompare(expression,"asin",4) == 0)
2331 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2333 return((MagickRealType) asin((double) alpha));
2335 if (LocaleNCompare(expression,"alt",3) == 0)
2337 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2339 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2341 if (LocaleNCompare(expression,"atan2",5) == 0)
2343 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2345 return((MagickRealType) atan2((double) alpha,(double) *beta));
2347 if (LocaleNCompare(expression,"atan",4) == 0)
2349 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2351 return((MagickRealType) atan((double) alpha));
2353 if (LocaleCompare(expression,"a") == 0)
2354 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2360 if (LocaleCompare(expression,"b") == 0)
2361 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2367 if (LocaleNCompare(expression,"ceil",4) == 0)
2369 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2371 return((MagickRealType) ceil((double) alpha));
2373 if (LocaleNCompare(expression,"cosh",4) == 0)
2375 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2377 return((MagickRealType) cosh((double) alpha));
2379 if (LocaleNCompare(expression,"cos",3) == 0)
2381 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2383 return((MagickRealType) cos((double) alpha));
2385 if (LocaleCompare(expression,"c") == 0)
2386 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2392 if (LocaleNCompare(expression,"debug",5) == 0)
2397 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2399 if (fx_info->images->colorspace == CMYKColorspace)
2402 case CyanChannel: type="cyan"; break;
2403 case MagentaChannel: type="magenta"; break;
2404 case YellowChannel: type="yellow"; break;
2405 case OpacityChannel: type="opacity"; break;
2406 case BlackChannel: type="black"; break;
2407 default: type="unknown"; break;
2412 case RedChannel: type="red"; break;
2413 case GreenChannel: type="green"; break;
2414 case BlueChannel: type="blue"; break;
2415 case OpacityChannel: type="opacity"; break;
2416 default: type="unknown"; break;
2418 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2419 if (strlen(subexpression) > 1)
2420 subexpression[strlen(subexpression)-1]='\0';
2421 if (fx_info->file != (FILE *) NULL)
2422 (void) fprintf(fx_info->file,"%s[%ld,%ld].%s: %s=%.*g\n",
2423 fx_info->images->filename,(long) x,(long) y,type,subexpression,
2424 GetMagickPrecision(),(double) alpha);
2432 if (LocaleCompare(expression,"epsilon") == 0)
2433 return((MagickRealType) MagickEpsilon);
2434 if (LocaleNCompare(expression,"exp",3) == 0)
2436 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2438 return((MagickRealType) exp((double) alpha));
2440 if (LocaleCompare(expression,"e") == 0)
2441 return((MagickRealType) 2.7182818284590452354);
2447 if (LocaleNCompare(expression,"floor",5) == 0)
2449 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2451 return((MagickRealType) floor((double) alpha));
2458 if (LocaleCompare(expression,"g") == 0)
2459 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2465 if (LocaleCompare(expression,"h") == 0)
2466 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2467 if (LocaleCompare(expression,"hue") == 0)
2468 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2469 if (LocaleNCompare(expression,"hypot",5) == 0)
2471 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2473 return((MagickRealType) hypot((double) alpha,(double) *beta));
2480 if (LocaleCompare(expression,"k") == 0)
2481 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2487 if (LocaleCompare(expression,"intensity") == 0)
2488 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2489 if (LocaleNCompare(expression,"int",3) == 0)
2491 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2493 return((MagickRealType) floor(alpha+0.5));
2495 if (LocaleCompare(expression,"i") == 0)
2496 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2502 if (LocaleCompare(expression,"j") == 0)
2503 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2504 #if defined(MAGICKCORE_HAVE_J0)
2505 if (LocaleNCompare(expression,"j0",2) == 0)
2507 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2509 return((MagickRealType) j0((double) alpha));
2512 #if defined(MAGICKCORE_HAVE_J1)
2513 if (LocaleNCompare(expression,"j1",2) == 0)
2515 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2517 return((MagickRealType) j1((double) alpha));
2520 #if defined(MAGICKCORE_HAVE_J1)
2521 if (LocaleNCompare(expression,"jinc",4) == 0)
2523 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2527 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2537 if (LocaleNCompare(expression,"ln",2) == 0)
2539 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2541 return((MagickRealType) log((double) alpha));
2543 if (LocaleNCompare(expression,"logtwo",4) == 0)
2545 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2547 return((MagickRealType) log10((double) alpha))/log10(2.0);
2549 if (LocaleNCompare(expression,"log",3) == 0)
2551 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2553 return((MagickRealType) log10((double) alpha));
2555 if (LocaleCompare(expression,"lightness") == 0)
2556 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2562 if (LocaleCompare(expression,"MaxRGB") == 0)
2563 return((MagickRealType) QuantumRange);
2564 if (LocaleNCompare(expression,"maxima",6) == 0)
2566 if (LocaleNCompare(expression,"max",3) == 0)
2567 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2568 if (LocaleNCompare(expression,"minima",6) == 0)
2570 if (LocaleNCompare(expression,"min",3) == 0)
2571 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2572 if (LocaleNCompare(expression,"mod",3) == 0)
2574 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2576 return((MagickRealType) fmod((double) alpha,(double) *beta));
2578 if (LocaleCompare(expression,"m") == 0)
2579 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2585 if (LocaleCompare(expression,"n") == 0)
2586 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2592 if (LocaleCompare(expression,"Opaque") == 0)
2594 if (LocaleCompare(expression,"o") == 0)
2595 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2601 if (LocaleCompare(expression,"pi") == 0)
2602 return((MagickRealType) MagickPI);
2603 if (LocaleNCompare(expression,"pow",3) == 0)
2605 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2607 return((MagickRealType) pow((double) alpha,(double) *beta));
2609 if (LocaleCompare(expression,"p") == 0)
2610 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2616 if (LocaleCompare(expression,"QuantumRange") == 0)
2617 return((MagickRealType) QuantumRange);
2618 if (LocaleCompare(expression,"QuantumScale") == 0)
2619 return((MagickRealType) QuantumScale);
2625 if (LocaleNCompare(expression,"rand",4) == 0)
2626 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2627 if (LocaleNCompare(expression,"round",5) == 0)
2629 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2632 return((MagickRealType) floor((double) alpha+0.5));
2633 return((MagickRealType) ceil((double) alpha-0.5));
2635 if (LocaleCompare(expression,"r") == 0)
2636 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2642 if (LocaleCompare(expression,"saturation") == 0)
2643 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2644 if (LocaleNCompare(expression,"sign",4) == 0)
2646 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2648 return(alpha < 0.0 ? -1.0 : 1.0);
2650 if (LocaleNCompare(expression,"sinc",4) == 0)
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2656 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2660 if (LocaleNCompare(expression,"sinh",4) == 0)
2662 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2664 return((MagickRealType) sinh((double) alpha));
2666 if (LocaleNCompare(expression,"sin",3) == 0)
2668 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2670 return((MagickRealType) sin((double) alpha));
2672 if (LocaleNCompare(expression,"sqrt",4) == 0)
2674 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2676 return((MagickRealType) sqrt((double) alpha));
2678 if (LocaleCompare(expression,"s") == 0)
2679 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2685 if (LocaleNCompare(expression,"tanh",4) == 0)
2687 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2689 return((MagickRealType) tanh((double) alpha));
2691 if (LocaleNCompare(expression,"tan",3) == 0)
2693 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2695 return((MagickRealType) tan((double) alpha));
2697 if (LocaleCompare(expression,"Transparent") == 0)
2699 if (LocaleCompare(expression,"t") == 0)
2700 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2706 if (LocaleCompare(expression,"u") == 0)
2707 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2713 if (LocaleCompare(expression,"v") == 0)
2714 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2720 if (LocaleCompare(expression,"w") == 0)
2721 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2727 if (LocaleCompare(expression,"y") == 0)
2728 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2734 if (LocaleCompare(expression,"z") == 0)
2735 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2741 q=(char *) expression;
2742 alpha=strtod(expression,&q);
2743 if (q == expression)
2744 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2748 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2749 MagickRealType *alpha,ExceptionInfo *exception)
2754 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2758 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2759 MagickRealType *alpha,ExceptionInfo *exception)
2768 fx_info->file=(FILE *) NULL;
2769 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2774 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2775 const ChannelType channel,const ssize_t x,const ssize_t y,MagickRealType *alpha,
2776 ExceptionInfo *exception)
2782 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2784 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2798 % FxImage() applies a mathematical expression to the specified image.
2800 % The format of the FxImage method is:
2802 % Image *FxImage(const Image *image,const char *expression,
2803 % ExceptionInfo *exception)
2804 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2805 % const char *expression,ExceptionInfo *exception)
2807 % A description of each parameter follows:
2809 % o image: the image.
2811 % o channel: the channel.
2813 % o expression: A mathematical expression.
2815 % o exception: return any errors or warnings in this structure.
2819 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2824 assert(fx_info != (FxInfo **) NULL);
2825 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2826 if (fx_info[i] != (FxInfo *) NULL)
2827 fx_info[i]=DestroyFxInfo(fx_info[i]);
2828 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2832 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2833 ExceptionInfo *exception)
2850 number_threads=GetOpenMPMaximumThreads();
2851 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2852 if (fx_info == (FxInfo **) NULL)
2853 return((FxInfo **) NULL);
2854 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2855 if (*expression != '@')
2856 fx_expression=ConstantString(expression);
2858 fx_expression=FileToString(expression+1,~0,exception);
2859 for (i=0; i < (ssize_t) number_threads; i++)
2861 fx_info[i]=AcquireFxInfo(image,fx_expression);
2862 if (fx_info[i] == (FxInfo *) NULL)
2863 return(DestroyFxThreadSet(fx_info));
2864 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2866 fx_expression=DestroyString(fx_expression);
2870 MagickExport Image *FxImage(const Image *image,const char *expression,
2871 ExceptionInfo *exception)
2876 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2880 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2881 const char *expression,ExceptionInfo *exception)
2883 #define FxImageTag "Fx/Image"
2906 assert(image != (Image *) NULL);
2907 assert(image->signature == MagickSignature);
2908 if (image->debug != MagickFalse)
2909 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2910 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2911 if (fx_image == (Image *) NULL)
2912 return((Image *) NULL);
2913 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2915 InheritException(exception,&fx_image->exception);
2916 fx_image=DestroyImage(fx_image);
2917 return((Image *) NULL);
2919 fx_info=AcquireFxThreadSet(image,expression,exception);
2920 if (fx_info == (FxInfo **) NULL)
2922 fx_image=DestroyImage(fx_image);
2923 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2925 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2926 if (status == MagickFalse)
2928 fx_image=DestroyImage(fx_image);
2929 fx_info=DestroyFxThreadSet(fx_info);
2930 return((Image *) NULL);
2937 fx_view=AcquireCacheView(fx_image);
2938 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2939 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2941 for (y=0; y < (ssize_t) fx_image->rows; y++)
2946 register IndexPacket
2947 *restrict fx_indexes;
2953 register PixelPacket
2956 if (status == MagickFalse)
2958 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2959 if (q == (PixelPacket *) NULL)
2964 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2965 id=GetOpenMPThreadId();
2967 for (x=0; x < (ssize_t) fx_image->columns; x++)
2969 if ((channel & RedChannel) != 0)
2971 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
2973 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2975 if ((channel & GreenChannel) != 0)
2977 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
2979 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2981 if ((channel & BlueChannel) != 0)
2983 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
2985 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2987 if ((channel & OpacityChannel) != 0)
2989 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
2991 if (image->matte == MagickFalse)
2992 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2994 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
2995 QuantumRange*alpha));
2997 if (((channel & IndexChannel) != 0) &&
2998 (fx_image->colorspace == CMYKColorspace))
3000 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
3002 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
3003 QuantumRange*alpha);
3007 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3009 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3014 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3015 #pragma omp critical (MagickCore_FxImageChannel)
3017 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3018 if (proceed == MagickFalse)
3022 fx_image->matte=fx_info[0]->matte;
3023 fx_view=DestroyCacheView(fx_view);
3024 fx_info=DestroyFxThreadSet(fx_info);
3025 if (status == MagickFalse)
3026 fx_image=DestroyImage(fx_image);
3031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3035 % I m p l o d e I m a g e %
3039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3041 % ImplodeImage() creates a new image that is a copy of an existing
3042 % one with the image pixels "implode" by the specified percentage. It
3043 % allocates the memory necessary for the new Image structure and returns a
3044 % pointer to the new image.
3046 % The format of the ImplodeImage method is:
3048 % Image *ImplodeImage(const Image *image,const double amount,
3049 % ExceptionInfo *exception)
3051 % A description of each parameter follows:
3053 % o implode_image: Method ImplodeImage returns a pointer to the image
3054 % after it is implode. A null image is returned if there is a memory
3057 % o image: the image.
3059 % o amount: Define the extent of the implosion.
3061 % o exception: return any errors or warnings in this structure.
3064 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3065 ExceptionInfo *exception)
3067 #define ImplodeImageTag "Implode/Image"
3093 **restrict resample_filter;
3099 Initialize implode image attributes.
3101 assert(image != (Image *) NULL);
3102 assert(image->signature == MagickSignature);
3103 if (image->debug != MagickFalse)
3104 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3105 assert(exception != (ExceptionInfo *) NULL);
3106 assert(exception->signature == MagickSignature);
3107 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3108 if (implode_image == (Image *) NULL)
3109 return((Image *) NULL);
3110 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3112 InheritException(exception,&implode_image->exception);
3113 implode_image=DestroyImage(implode_image);
3114 return((Image *) NULL);
3116 if (implode_image->background_color.opacity != OpaqueOpacity)
3117 implode_image->matte=MagickTrue;
3119 Compute scaling factor.
3123 center.x=0.5*image->columns;
3124 center.y=0.5*image->rows;
3126 if (image->columns > image->rows)
3127 scale.y=(double) image->columns/(double) image->rows;
3129 if (image->columns < image->rows)
3131 scale.x=(double) image->rows/(double) image->columns;
3139 GetMagickPixelPacket(implode_image,&zero);
3140 resample_filter=AcquireResampleFilterThreadSet(image,
3141 UndefinedVirtualPixelMethod,MagickTrue,exception);
3142 image_view=AcquireCacheView(image);
3143 implode_view=AcquireCacheView(implode_image);
3144 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3145 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3147 for (y=0; y < (ssize_t) image->rows; y++)
3158 register IndexPacket
3159 *restrict implode_indexes;
3165 register PixelPacket
3168 if (status == MagickFalse)
3170 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3172 if (q == (PixelPacket *) NULL)
3177 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
3178 delta.y=scale.y*(double) (y-center.y);
3180 id=GetOpenMPThreadId();
3181 for (x=0; x < (ssize_t) image->columns; x++)
3184 Determine if the pixel is within an ellipse.
3186 delta.x=scale.x*(double) (x-center.x);
3187 distance=delta.x*delta.x+delta.y*delta.y;
3188 if (distance < (radius*radius))
3198 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3199 radius/2)),-amount);
3200 (void) ResamplePixelColor(resample_filter[id],(double)
3201 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3202 scale.y+center.y),&pixel);
3203 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
3207 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3209 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3214 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3215 #pragma omp critical (MagickCore_ImplodeImage)
3217 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3218 if (proceed == MagickFalse)
3222 implode_view=DestroyCacheView(implode_view);
3223 image_view=DestroyCacheView(image_view);
3224 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
3225 if (status == MagickFalse)
3226 implode_image=DestroyImage(implode_image);
3227 return(implode_image);
3231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3235 % M o r p h I m a g e s %
3239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3241 % The MorphImages() method requires a minimum of two images. The first
3242 % image is transformed into the second by a number of intervening images
3243 % as specified by frames.
3245 % The format of the MorphImage method is:
3247 % Image *MorphImages(const Image *image,const size_t number_frames,
3248 % ExceptionInfo *exception)
3250 % A description of each parameter follows:
3252 % o image: the image.
3254 % o number_frames: Define the number of in-between image to generate.
3255 % The more in-between frames, the smoother the morph.
3257 % o exception: return any errors or warnings in this structure.
3260 MagickExport Image *MorphImages(const Image *image,
3261 const size_t number_frames,ExceptionInfo *exception)
3263 #define MorphImageTag "Morph/Image"
3279 register const Image
3289 Clone first frame in sequence.
3291 assert(image != (Image *) NULL);
3292 assert(image->signature == MagickSignature);
3293 if (image->debug != MagickFalse)
3294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3295 assert(exception != (ExceptionInfo *) NULL);
3296 assert(exception->signature == MagickSignature);
3297 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3298 if (morph_images == (Image *) NULL)
3299 return((Image *) NULL);
3300 if (GetNextImageInList(image) == (Image *) NULL)
3305 for (i=1; i < (ssize_t) number_frames; i++)
3307 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3308 if (morph_image == (Image *) NULL)
3310 morph_images=DestroyImageList(morph_images);
3311 return((Image *) NULL);
3313 AppendImageToList(&morph_images,morph_image);
3314 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3319 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3321 if (proceed == MagickFalse)
3325 return(GetFirstImageInList(morph_images));
3328 Morph image sequence.
3333 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3335 for (i=0; i < (ssize_t) number_frames; i++)
3341 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3343 morph_image=ZoomImage(next,(size_t) (alpha*next->columns+beta*
3344 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3345 next->rows+beta*GetNextImageInList(next)->rows+0.5),exception);
3346 if (morph_image == (Image *) NULL)
3348 morph_images=DestroyImageList(morph_images);
3349 return((Image *) NULL);
3351 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3353 InheritException(exception,&morph_image->exception);
3354 morph_image=DestroyImage(morph_image);
3355 return((Image *) NULL);
3357 AppendImageToList(&morph_images,morph_image);
3358 morph_images=GetLastImageInList(morph_images);
3359 morph_image=ZoomImage(GetNextImageInList(next),morph_images->columns,
3360 morph_images->rows,exception);
3361 if (morph_image == (Image *) NULL)
3363 morph_images=DestroyImageList(morph_images);
3364 return((Image *) NULL);
3366 image_view=AcquireCacheView(morph_image);
3367 morph_view=AcquireCacheView(morph_images);
3368 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3369 #pragma omp parallel for schedule(dynamic,4) shared(status)
3371 for (y=0; y < (ssize_t) morph_images->rows; y++)
3376 register const PixelPacket
3382 register PixelPacket
3385 if (status == MagickFalse)
3387 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3389 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3391 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3396 for (x=0; x < (ssize_t) morph_images->columns; x++)
3398 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3399 q->green=ClampToQuantum(alpha*q->green+beta*
3400 GetGreenPixelComponent(p));
3401 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3402 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3403 GetOpacityPixelComponent(p));
3407 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3408 if (sync == MagickFalse)
3411 morph_view=DestroyCacheView(morph_view);
3412 image_view=DestroyCacheView(image_view);
3413 morph_image=DestroyImage(morph_image);
3415 if (i < (ssize_t) number_frames)
3418 Clone last frame in sequence.
3420 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3421 if (morph_image == (Image *) NULL)
3423 morph_images=DestroyImageList(morph_images);
3424 return((Image *) NULL);
3426 AppendImageToList(&morph_images,morph_image);
3427 morph_images=GetLastImageInList(morph_images);
3428 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3433 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3434 #pragma omp critical (MagickCore_MorphImages)
3436 proceed=SetImageProgress(image,MorphImageTag,scene,
3437 GetImageListLength(image));
3438 if (proceed == MagickFalse)
3443 if (GetNextImageInList(next) != (Image *) NULL)
3445 morph_images=DestroyImageList(morph_images);
3446 return((Image *) NULL);
3448 return(GetFirstImageInList(morph_images));
3452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3456 % P l a s m a I m a g e %
3460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3462 % PlasmaImage() initializes an image with plasma fractal values. The image
3463 % must be initialized with a base color and the random number generator
3464 % seeded before this method is called.
3466 % The format of the PlasmaImage method is:
3468 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3469 % size_t attenuate,size_t depth)
3471 % A description of each parameter follows:
3473 % o image: the image.
3475 % o segment: Define the region to apply plasma fractals values.
3477 % o attenuate: Define the plasmattenuation factor.
3479 % o depth: Limit the plasma recursion depth.
3483 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3484 const MagickRealType pixel,const MagickRealType noise)
3489 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3494 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3495 RandomInfo *random_info,const SegmentInfo *segment,size_t attenuate,
3514 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3522 Divide the area into quadrants and recurse.
3526 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3527 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3528 local_info=(*segment);
3529 local_info.x2=(double) x_mid;
3530 local_info.y2=(double) y_mid;
3531 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3532 local_info=(*segment);
3533 local_info.y1=(double) y_mid;
3534 local_info.x2=(double) x_mid;
3535 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3536 local_info=(*segment);
3537 local_info.x1=(double) x_mid;
3538 local_info.y2=(double) y_mid;
3539 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3540 local_info=(*segment);
3541 local_info.x1=(double) x_mid;
3542 local_info.y1=(double) y_mid;
3543 return(PlasmaImageProxy(image,random_info,&local_info,attenuate,depth));
3545 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3546 return(MagickFalse);
3547 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3548 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3549 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3550 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3551 return(MagickFalse);
3553 Average pixels and apply plasma.
3555 exception=(&image->exception);
3556 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3557 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3559 register PixelPacket
3565 x=(ssize_t) ceil(segment->x1-0.5);
3566 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y1-0.5),&u,
3568 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y2-0.5),&v,
3570 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3571 if (q == (PixelPacket *) NULL)
3573 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3575 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3577 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3579 (void) SyncAuthenticPixels(image,exception);
3580 if (segment->x1 != segment->x2)
3585 x=(ssize_t) ceil(segment->x2-0.5);
3586 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y1-0.5),&u,
3588 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y2-0.5),&v,
3590 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3591 if (q == (PixelPacket *) NULL)
3593 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3595 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3597 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3599 (void) SyncAuthenticPixels(image,exception);
3602 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3604 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3606 register PixelPacket
3612 y=(ssize_t) ceil(segment->y2-0.5);
3613 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x1-0.5),y,&u,
3615 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x2-0.5),y,&v,
3617 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3618 if (q == (PixelPacket *) NULL)
3620 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3622 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3624 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3626 (void) SyncAuthenticPixels(image,exception);
3628 if (segment->y1 != segment->y2)
3630 register PixelPacket
3636 y=(ssize_t) ceil(segment->y1-0.5);
3637 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x1-0.5),y,&u,
3639 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x2-0.5),y,&v,
3641 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3642 if (q == (PixelPacket *) NULL)
3644 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3646 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3648 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3650 (void) SyncAuthenticPixels(image,exception);
3653 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3655 register PixelPacket
3661 x=(ssize_t) ceil(segment->x1-0.5);
3662 y=(ssize_t) ceil(segment->y1-0.5);
3663 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3664 x=(ssize_t) ceil(segment->x2-0.5);
3665 y=(ssize_t) ceil(segment->y2-0.5);
3666 (void) GetOneVirtualPixel(image,x,y,&v,exception);
3667 q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception);
3668 if (q == (PixelPacket *) NULL)
3670 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3672 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3674 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3676 (void) SyncAuthenticPixels(image,exception);
3678 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3680 return(MagickFalse);
3683 MagickExport MagickBooleanType PlasmaImage(Image *image,
3684 const SegmentInfo *segment,size_t attenuate,size_t depth)
3692 if (image->debug != MagickFalse)
3693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3694 assert(image != (Image *) NULL);
3695 assert(image->signature == MagickSignature);
3696 if (image->debug != MagickFalse)
3697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3698 random_info=AcquireRandomInfo();
3699 status=PlasmaImageProxy(image,random_info,segment,attenuate,depth);
3700 random_info=DestroyRandomInfo(random_info);
3705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3709 % P o l a r o i d I m a g e %
3713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3715 % PolaroidImage() simulates a Polaroid picture.
3717 % The format of the AnnotateImage method is:
3719 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3720 % const double angle,ExceptionInfo exception)
3722 % A description of each parameter follows:
3724 % o image: the image.
3726 % o draw_info: the draw info.
3728 % o angle: Apply the effect along this angle.
3730 % o exception: return any errors or warnings in this structure.
3733 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3734 const double angle,ExceptionInfo *exception)
3755 Simulate a Polaroid picture.
3757 assert(image != (Image *) NULL);
3758 assert(image->signature == MagickSignature);
3759 if (image->debug != MagickFalse)
3760 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3761 assert(exception != (ExceptionInfo *) NULL);
3762 assert(exception->signature == MagickSignature);
3763 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3764 image->rows)/25.0,10.0);
3765 height=image->rows+2*quantum;
3766 caption_image=(Image *) NULL;
3767 value=GetImageProperty(image,"Caption");
3768 if (value != (const char *) NULL)
3772 geometry[MaxTextExtent];
3787 Generate caption image.
3789 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3790 if (caption_image == (Image *) NULL)
3791 return((Image *) NULL);
3792 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3793 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3795 (void) CloneString(&annotate_info->text,caption);
3796 count=FormatMagickCaption(caption_image,annotate_info,&metrics,&caption);
3797 status=SetImageExtent(caption_image,image->columns,(size_t)
3798 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3799 if (status == MagickFalse)
3800 caption_image=DestroyImage(caption_image);
3803 caption_image->background_color=image->border_color;
3804 (void) SetImageBackgroundColor(caption_image);
3805 (void) CloneString(&annotate_info->text,caption);
3806 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3808 if (annotate_info->gravity == UndefinedGravity)
3809 (void) CloneString(&annotate_info->geometry,AcquireString(
3811 (void) AnnotateImage(caption_image,annotate_info);
3812 height+=caption_image->rows;
3814 annotate_info=DestroyDrawInfo(annotate_info);
3815 caption=DestroyString(caption);
3817 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3819 if (picture_image == (Image *) NULL)
3821 if (caption_image != (Image *) NULL)
3822 caption_image=DestroyImage(caption_image);
3823 return((Image *) NULL);
3825 picture_image->background_color=image->border_color;
3826 (void) SetImageBackgroundColor(picture_image);
3827 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3828 if (caption_image != (Image *) NULL)
3830 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3831 quantum,(ssize_t) (image->rows+3*quantum/2));
3832 caption_image=DestroyImage(caption_image);
3834 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3835 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3836 rotate_image=RotateImage(picture_image,90.0,exception);
3837 picture_image=DestroyImage(picture_image);
3838 if (rotate_image == (Image *) NULL)
3839 return((Image *) NULL);
3840 picture_image=rotate_image;
3841 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3842 picture_image->columns,exception);
3843 picture_image=DestroyImage(picture_image);
3844 if (bend_image == (Image *) NULL)
3845 return((Image *) NULL);
3846 InheritException(&bend_image->exception,exception);
3847 picture_image=bend_image;
3848 rotate_image=RotateImage(picture_image,-90.0,exception);
3849 picture_image=DestroyImage(picture_image);
3850 if (rotate_image == (Image *) NULL)
3851 return((Image *) NULL);
3852 picture_image=rotate_image;
3853 picture_image->background_color=image->background_color;
3854 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3856 if (polaroid_image == (Image *) NULL)
3858 picture_image=DestroyImage(picture_image);
3859 return(picture_image);
3861 flop_image=FlopImage(polaroid_image,exception);
3862 polaroid_image=DestroyImage(polaroid_image);
3863 if (flop_image == (Image *) NULL)
3865 picture_image=DestroyImage(picture_image);
3866 return(picture_image);
3868 polaroid_image=flop_image;
3869 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3870 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3871 picture_image=DestroyImage(picture_image);
3872 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3873 rotate_image=RotateImage(polaroid_image,angle,exception);
3874 polaroid_image=DestroyImage(polaroid_image);
3875 if (rotate_image == (Image *) NULL)
3876 return((Image *) NULL);
3877 polaroid_image=rotate_image;
3878 trim_image=TrimImage(polaroid_image,exception);
3879 polaroid_image=DestroyImage(polaroid_image);
3880 if (trim_image == (Image *) NULL)
3881 return((Image *) NULL);
3882 polaroid_image=trim_image;
3883 return(polaroid_image);
3887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3891 % S e p i a T o n e I m a g e %
3895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3897 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3898 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3899 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3900 % threshold of 80% is a good starting point for a reasonable tone.
3902 % The format of the SepiaToneImage method is:
3904 % Image *SepiaToneImage(const Image *image,const double threshold,
3905 % ExceptionInfo *exception)
3907 % A description of each parameter follows:
3909 % o image: the image.
3911 % o threshold: the tone threshold.
3913 % o exception: return any errors or warnings in this structure.
3916 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3917 ExceptionInfo *exception)
3919 #define SepiaToneImageTag "SepiaTone/Image"
3938 Initialize sepia-toned image attributes.
3940 assert(image != (const Image *) NULL);
3941 assert(image->signature == MagickSignature);
3942 if (image->debug != MagickFalse)
3943 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3944 assert(exception != (ExceptionInfo *) NULL);
3945 assert(exception->signature == MagickSignature);
3946 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3947 if (sepia_image == (Image *) NULL)
3948 return((Image *) NULL);
3949 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3951 InheritException(exception,&sepia_image->exception);
3952 sepia_image=DestroyImage(sepia_image);
3953 return((Image *) NULL);
3956 Tone each row of the image.
3960 image_view=AcquireCacheView(image);
3961 sepia_view=AcquireCacheView(sepia_image);
3962 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3963 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3965 for (y=0; y < (ssize_t) image->rows; y++)
3967 register const PixelPacket
3973 register PixelPacket
3976 if (status == MagickFalse)
3978 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3979 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
3981 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3986 for (x=0; x < (ssize_t) image->columns; x++)
3992 intensity=(MagickRealType) PixelIntensityToQuantum(p);
3993 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
3994 (MagickRealType) QuantumRange-threshold;
3995 q->red=ClampToQuantum(tone);
3996 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
3997 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
3998 q->green=ClampToQuantum(tone);
3999 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4000 q->blue=ClampToQuantum(tone);
4002 if ((MagickRealType) q->green < tone)
4003 q->green=ClampToQuantum(tone);
4004 if ((MagickRealType) q->blue < tone)
4005 q->blue=ClampToQuantum(tone);
4009 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4011 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4016 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4017 #pragma omp critical (MagickCore_SepiaToneImage)
4019 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4021 if (proceed == MagickFalse)
4025 sepia_view=DestroyCacheView(sepia_view);
4026 image_view=DestroyCacheView(image_view);
4027 (void) NormalizeImage(sepia_image);
4028 (void) ContrastImage(sepia_image,MagickTrue);
4029 if (status == MagickFalse)
4030 sepia_image=DestroyImage(sepia_image);
4031 return(sepia_image);
4035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4039 % S h a d o w I m a g e %
4043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4045 % ShadowImage() simulates a shadow from the specified image and returns it.
4047 % The format of the ShadowImage method is:
4049 % Image *ShadowImage(const Image *image,const double opacity,
4050 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4051 % ExceptionInfo *exception)
4053 % A description of each parameter follows:
4055 % o image: the image.
4057 % o opacity: percentage transparency.
4059 % o sigma: the standard deviation of the Gaussian, in pixels.
4061 % o x_offset: the shadow x-offset.
4063 % o y_offset: the shadow y-offset.
4065 % o exception: return any errors or warnings in this structure.
4068 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4069 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4070 ExceptionInfo *exception)
4072 #define ShadowImageTag "Shadow/Image"
4094 assert(image != (Image *) NULL);
4095 assert(image->signature == MagickSignature);
4096 if (image->debug != MagickFalse)
4097 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4098 assert(exception != (ExceptionInfo *) NULL);
4099 assert(exception->signature == MagickSignature);
4100 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4101 if (clone_image == (Image *) NULL)
4102 return((Image *) NULL);
4103 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4104 clone_image->compose=OverCompositeOp;
4105 border_info.width=(size_t) floor(2.0*sigma+0.5);
4106 border_info.height=(size_t) floor(2.0*sigma+0.5);
4109 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4110 border_image=BorderImage(clone_image,&border_info,exception);
4111 clone_image=DestroyImage(clone_image);
4112 if (border_image == (Image *) NULL)
4113 return((Image *) NULL);
4114 if (border_image->matte == MagickFalse)
4115 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4121 image_view=AcquireCacheView(border_image);
4122 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4123 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4125 for (y=0; y < (ssize_t) border_image->rows; y++)
4130 register PixelPacket
4133 if (status == MagickFalse)
4135 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4137 if (q == (PixelPacket *) NULL)
4142 for (x=0; x < (ssize_t) border_image->columns; x++)
4144 q->red=border_image->background_color.red;
4145 q->green=border_image->background_color.green;
4146 q->blue=border_image->background_color.blue;
4147 if (border_image->matte == MagickFalse)
4148 q->opacity=border_image->background_color.opacity;
4150 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4151 GetAlphaPixelComponent(q)*opacity/100.0));
4154 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4156 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4161 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4162 #pragma omp critical (MagickCore_ShadowImage)
4164 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4165 border_image->rows);
4166 if (proceed == MagickFalse)
4170 image_view=DestroyCacheView(image_view);
4171 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4172 border_image=DestroyImage(border_image);
4173 if (shadow_image == (Image *) NULL)
4174 return((Image *) NULL);
4175 if (shadow_image->page.width == 0)
4176 shadow_image->page.width=shadow_image->columns;
4177 if (shadow_image->page.height == 0)
4178 shadow_image->page.height=shadow_image->rows;
4179 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4180 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4181 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4182 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4183 return(shadow_image);
4187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4191 % S k e t c h I m a g e %
4195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4197 % SketchImage() simulates a pencil sketch. We convolve the image with a
4198 % Gaussian operator of the given radius and standard deviation (sigma). For
4199 % reasonable results, radius should be larger than sigma. Use a radius of 0
4200 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4203 % The format of the SketchImage method is:
4205 % Image *SketchImage(const Image *image,const double radius,
4206 % const double sigma,const double angle,ExceptionInfo *exception)
4208 % A description of each parameter follows:
4210 % o image: the image.
4212 % o radius: the radius of the Gaussian, in pixels, not counting
4215 % o sigma: the standard deviation of the Gaussian, in pixels.
4217 % o angle: Apply the effect along this angle.
4219 % o exception: return any errors or warnings in this structure.
4222 MagickExport Image *SketchImage(const Image *image,const double radius,
4223 const double sigma,const double angle,ExceptionInfo *exception)
4245 **restrict random_info;
4250 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4251 MagickTrue,exception);
4252 if (random_image == (Image *) NULL)
4253 return((Image *) NULL);
4255 GetMagickPixelPacket(random_image,&zero);
4256 random_info=AcquireRandomInfoThreadSet();
4257 random_view=AcquireCacheView(random_image);
4258 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4259 #pragma omp parallel for schedule(dynamic,4) shared(status)
4261 for (y=0; y < (ssize_t) random_image->rows; y++)
4266 register IndexPacket
4273 register PixelPacket
4276 if (status == MagickFalse)
4278 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4280 if (q == (PixelPacket *) NULL)
4285 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4287 id=GetOpenMPThreadId();
4288 for (x=0; x < (ssize_t) random_image->columns; x++)
4290 pixel.red=(MagickRealType) (QuantumRange*
4291 GetPseudoRandomValue(random_info[id]));
4292 pixel.green=pixel.red;
4293 pixel.blue=pixel.red;
4294 if (image->colorspace == CMYKColorspace)
4295 pixel.index=pixel.red;
4296 SetPixelPacket(random_image,&pixel,q,indexes+x);
4299 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4302 random_view=DestroyCacheView(random_view);
4303 random_info=DestroyRandomInfoThreadSet(random_info);
4304 if (status == MagickFalse)
4306 random_image=DestroyImage(random_image);
4307 return(random_image);
4309 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4310 random_image=DestroyImage(random_image);
4311 if (blur_image == (Image *) NULL)
4312 return((Image *) NULL);
4313 dodge_image=EdgeImage(blur_image,radius,exception);
4314 blur_image=DestroyImage(blur_image);
4315 if (dodge_image == (Image *) NULL)
4316 return((Image *) NULL);
4317 (void) NormalizeImage(dodge_image);
4318 (void) NegateImage(dodge_image,MagickFalse);
4319 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4320 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4321 if (sketch_image == (Image *) NULL)
4323 dodge_image=DestroyImage(dodge_image);
4324 return((Image *) NULL);
4326 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4327 dodge_image=DestroyImage(dodge_image);
4328 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4329 if (blend_image == (Image *) NULL)
4331 sketch_image=DestroyImage(sketch_image);
4332 return((Image *) NULL);
4334 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4335 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4336 blend_image=DestroyImage(blend_image);
4337 return(sketch_image);
4341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4345 % S o l a r i z e I m a g e %
4349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4351 % SolarizeImage() applies a special effect to the image, similar to the effect
4352 % achieved in a photo darkroom by selectively exposing areas of photo
4353 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4354 % measure of the extent of the solarization.
4356 % The format of the SolarizeImage method is:
4358 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4360 % A description of each parameter follows:
4362 % o image: the image.
4364 % o threshold: Define the extent of the solarization.
4367 MagickExport MagickBooleanType SolarizeImage(Image *image,
4368 const double threshold)
4370 #define SolarizeImageTag "Solarize/Image"
4387 assert(image != (Image *) NULL);
4388 assert(image->signature == MagickSignature);
4389 if (image->debug != MagickFalse)
4390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4391 if (image->storage_class == PseudoClass)
4399 for (i=0; i < (ssize_t) image->colors; i++)
4401 if ((MagickRealType) image->colormap[i].red > threshold)
4402 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4403 if ((MagickRealType) image->colormap[i].green > threshold)
4404 image->colormap[i].green=(Quantum) QuantumRange-
4405 image->colormap[i].green;
4406 if ((MagickRealType) image->colormap[i].blue > threshold)
4407 image->colormap[i].blue=(Quantum) QuantumRange-
4408 image->colormap[i].blue;
4416 exception=(&image->exception);
4417 image_view=AcquireCacheView(image);
4418 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4419 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4421 for (y=0; y < (ssize_t) image->rows; y++)
4426 register PixelPacket
4429 if (status == MagickFalse)
4431 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4433 if (q == (PixelPacket *) NULL)
4438 for (x=0; x < (ssize_t) image->columns; x++)
4440 if ((MagickRealType) q->red > threshold)
4441 q->red=(Quantum) QuantumRange-q->red;
4442 if ((MagickRealType) q->green > threshold)
4443 q->green=(Quantum) QuantumRange-q->green;
4444 if ((MagickRealType) q->blue > threshold)
4445 q->blue=(Quantum) QuantumRange-q->blue;
4448 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4450 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4455 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4456 #pragma omp critical (MagickCore_SolarizeImage)
4458 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4459 if (proceed == MagickFalse)
4463 image_view=DestroyCacheView(image_view);
4468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4472 % S t e g a n o I m a g e %
4476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4478 % SteganoImage() hides a digital watermark within the image. Recover
4479 % the hidden watermark later to prove that the authenticity of an image.
4480 % Offset defines the start position within the image to hide the watermark.
4482 % The format of the SteganoImage method is:
4484 % Image *SteganoImage(const Image *image,Image *watermark,
4485 % ExceptionInfo *exception)
4487 % A description of each parameter follows:
4489 % o image: the image.
4491 % o watermark: the watermark image.
4493 % o exception: return any errors or warnings in this structure.
4496 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4497 ExceptionInfo *exception)
4499 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) \
4501 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) != 0 ? (size_t) (alpha) \
4502 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4503 #define SteganoImageTag "Stegano/Image"
4526 register PixelPacket
4534 Initialize steganographic image attributes.
4536 assert(image != (const Image *) NULL);
4537 assert(image->signature == MagickSignature);
4538 if (image->debug != MagickFalse)
4539 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4540 assert(watermark != (const Image *) NULL);
4541 assert(watermark->signature == MagickSignature);
4542 assert(exception != (ExceptionInfo *) NULL);
4543 assert(exception->signature == MagickSignature);
4545 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4546 if (stegano_image == (Image *) NULL)
4547 return((Image *) NULL);
4548 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4550 InheritException(exception,&stegano_image->exception);
4551 stegano_image=DestroyImage(stegano_image);
4552 return((Image *) NULL);
4554 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4556 Hide watermark in low-order bits of image.
4561 depth=stegano_image->depth;
4563 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4565 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4567 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4569 (void) GetOneVirtualPixel(watermark,x,y,&pixel,exception);
4570 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4572 q=GetAuthenticPixels(stegano_image,k % (ssize_t) stegano_image->columns,
4573 k/(ssize_t) stegano_image->columns,1,1,exception);
4574 if (q == (PixelPacket *) NULL)
4580 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4585 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4590 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4594 if (SyncAuthenticPixels(stegano_image,exception) == MagickFalse)
4600 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4602 if (k == image->offset)
4606 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4611 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4613 if (proceed == MagickFalse)
4617 if (stegano_image->storage_class == PseudoClass)
4618 (void) SyncImage(stegano_image);
4619 return(stegano_image);
4623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4627 % S t e r e o A n a g l y p h I m a g e %
4631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4633 % StereoAnaglyphImage() combines two images and produces a single image that
4634 % is the composite of a left and right image of a stereo pair. Special
4635 % red-green stereo glasses are required to view this effect.
4637 % The format of the StereoAnaglyphImage method is:
4639 % Image *StereoImage(const Image *left_image,const Image *right_image,
4640 % ExceptionInfo *exception)
4641 % Image *StereoAnaglyphImage(const Image *left_image,
4642 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4643 % ExceptionInfo *exception)
4645 % A description of each parameter follows:
4647 % o left_image: the left image.
4649 % o right_image: the right image.
4651 % o exception: return any errors or warnings in this structure.
4653 % o x_offset: amount, in pixels, by which the left image is offset to the
4654 % right of the right image.
4656 % o y_offset: amount, in pixels, by which the left image is offset to the
4657 % bottom of the right image.
4661 MagickExport Image *StereoImage(const Image *left_image,
4662 const Image *right_image,ExceptionInfo *exception)
4664 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4667 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4668 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4669 ExceptionInfo *exception)
4671 #define StereoImageTag "Stereo/Image"
4685 assert(left_image != (const Image *) NULL);
4686 assert(left_image->signature == MagickSignature);
4687 if (left_image->debug != MagickFalse)
4688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4689 left_image->filename);
4690 assert(right_image != (const Image *) NULL);
4691 assert(right_image->signature == MagickSignature);
4692 assert(exception != (ExceptionInfo *) NULL);
4693 assert(exception->signature == MagickSignature);
4694 assert(right_image != (const Image *) NULL);
4696 if ((left_image->columns != right_image->columns) ||
4697 (left_image->rows != right_image->rows))
4698 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4700 Initialize stereo image attributes.
4702 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4703 MagickTrue,exception);
4704 if (stereo_image == (Image *) NULL)
4705 return((Image *) NULL);
4706 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4708 InheritException(exception,&stereo_image->exception);
4709 stereo_image=DestroyImage(stereo_image);
4710 return((Image *) NULL);
4713 Copy left image to red channel and right image to blue channel.
4715 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4717 register const PixelPacket
4724 register PixelPacket
4727 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4729 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4730 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4731 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4732 (r == (PixelPacket *) NULL))
4734 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4736 r->red=GetRedPixelComponent(p);
4739 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4744 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4746 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4751 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4752 stereo_image->rows);
4753 if (proceed == MagickFalse)
4757 return(stereo_image);
4761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4765 % S w i r l I m a g e %
4769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4771 % SwirlImage() swirls the pixels about the center of the image, where
4772 % degrees indicates the sweep of the arc through which each pixel is moved.
4773 % You get a more dramatic effect as the degrees move from 1 to 360.
4775 % The format of the SwirlImage method is:
4777 % Image *SwirlImage(const Image *image,double degrees,
4778 % ExceptionInfo *exception)
4780 % A description of each parameter follows:
4782 % o image: the image.
4784 % o degrees: Define the tightness of the swirling effect.
4786 % o exception: return any errors or warnings in this structure.
4789 MagickExport Image *SwirlImage(const Image *image,double degrees,
4790 ExceptionInfo *exception)
4792 #define SwirlImageTag "Swirl/Image"
4818 **restrict resample_filter;
4824 Initialize swirl image attributes.
4826 assert(image != (const Image *) NULL);
4827 assert(image->signature == MagickSignature);
4828 if (image->debug != MagickFalse)
4829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4830 assert(exception != (ExceptionInfo *) NULL);
4831 assert(exception->signature == MagickSignature);
4832 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4833 if (swirl_image == (Image *) NULL)
4834 return((Image *) NULL);
4835 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4837 InheritException(exception,&swirl_image->exception);
4838 swirl_image=DestroyImage(swirl_image);
4839 return((Image *) NULL);
4841 if (swirl_image->background_color.opacity != OpaqueOpacity)
4842 swirl_image->matte=MagickTrue;
4844 Compute scaling factor.
4846 center.x=(double) image->columns/2.0;
4847 center.y=(double) image->rows/2.0;
4848 radius=MagickMax(center.x,center.y);
4851 if (image->columns > image->rows)
4852 scale.y=(double) image->columns/(double) image->rows;
4854 if (image->columns < image->rows)
4855 scale.x=(double) image->rows/(double) image->columns;
4856 degrees=(double) DegreesToRadians(degrees);
4862 GetMagickPixelPacket(swirl_image,&zero);
4863 resample_filter=AcquireResampleFilterThreadSet(image,
4864 UndefinedVirtualPixelMethod,MagickTrue,exception);
4865 image_view=AcquireCacheView(image);
4866 swirl_view=AcquireCacheView(swirl_image);
4867 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4868 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4870 for (y=0; y < (ssize_t) image->rows; y++)
4881 register IndexPacket
4882 *restrict swirl_indexes;
4888 register PixelPacket
4891 if (status == MagickFalse)
4893 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4895 if (q == (PixelPacket *) NULL)
4900 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4901 delta.y=scale.y*(double) (y-center.y);
4903 id=GetOpenMPThreadId();
4904 for (x=0; x < (ssize_t) image->columns; x++)
4907 Determine if the pixel is within an ellipse.
4909 delta.x=scale.x*(double) (x-center.x);
4910 distance=delta.x*delta.x+delta.y*delta.y;
4911 if (distance < (radius*radius))
4921 factor=1.0-sqrt((double) distance)/radius;
4922 sine=sin((double) (degrees*factor*factor));
4923 cosine=cos((double) (degrees*factor*factor));
4924 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4925 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4926 cosine*delta.y)/scale.y+center.y),&pixel);
4927 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4931 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4933 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4938 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4939 #pragma omp critical (MagickCore_SwirlImage)
4941 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4942 if (proceed == MagickFalse)
4946 swirl_view=DestroyCacheView(swirl_view);
4947 image_view=DestroyCacheView(image_view);
4948 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
4949 if (status == MagickFalse)
4950 swirl_image=DestroyImage(swirl_image);
4951 return(swirl_image);
4955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4959 % T i n t I m a g e %
4963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4965 % TintImage() applies a color vector to each pixel in the image. The length
4966 % of the vector is 0 for black and white and at its maximum for the midtones.
4967 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
4969 % The format of the TintImage method is:
4971 % Image *TintImage(const Image *image,const char *opacity,
4972 % const PixelPacket tint,ExceptionInfo *exception)
4974 % A description of each parameter follows:
4976 % o image: the image.
4978 % o opacity: A color value used for tinting.
4980 % o tint: A color value used for tinting.
4982 % o exception: return any errors or warnings in this structure.
4985 MagickExport Image *TintImage(const Image *image,const char *opacity,
4986 const PixelPacket tint,ExceptionInfo *exception)
4988 #define TintImageTag "Tint/Image"
5017 Allocate tint image.
5019 assert(image != (const Image *) NULL);
5020 assert(image->signature == MagickSignature);
5021 if (image->debug != MagickFalse)
5022 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5023 assert(exception != (ExceptionInfo *) NULL);
5024 assert(exception->signature == MagickSignature);
5025 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5026 if (tint_image == (Image *) NULL)
5027 return((Image *) NULL);
5028 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5030 InheritException(exception,&tint_image->exception);
5031 tint_image=DestroyImage(tint_image);
5032 return((Image *) NULL);
5034 if (opacity == (const char *) NULL)
5037 Determine RGB values of the color.
5039 flags=ParseGeometry(opacity,&geometry_info);
5040 pixel.red=geometry_info.rho;
5041 if ((flags & SigmaValue) != 0)
5042 pixel.green=geometry_info.sigma;
5044 pixel.green=pixel.red;
5045 if ((flags & XiValue) != 0)
5046 pixel.blue=geometry_info.xi;
5048 pixel.blue=pixel.red;
5049 if ((flags & PsiValue) != 0)
5050 pixel.opacity=geometry_info.psi;
5052 pixel.opacity=(MagickRealType) OpaqueOpacity;
5053 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5054 PixelIntensity(&tint));
5055 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5056 PixelIntensity(&tint));
5057 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5058 PixelIntensity(&tint));
5064 image_view=AcquireCacheView(image);
5065 tint_view=AcquireCacheView(tint_image);
5066 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5067 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5069 for (y=0; y < (ssize_t) image->rows; y++)
5071 register const PixelPacket
5077 register PixelPacket
5080 if (status == MagickFalse)
5082 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5083 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5085 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5090 for (x=0; x < (ssize_t) image->columns; x++)
5098 weight=QuantumScale*p->red-0.5;
5099 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5101 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5102 weight=QuantumScale*p->green-0.5;
5103 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5105 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5106 weight=QuantumScale*p->blue-0.5;
5107 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5109 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5110 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5114 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5116 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5121 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5122 #pragma omp critical (MagickCore_TintImage)
5124 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5125 if (proceed == MagickFalse)
5129 tint_view=DestroyCacheView(tint_view);
5130 image_view=DestroyCacheView(image_view);
5131 if (status == MagickFalse)
5132 tint_image=DestroyImage(tint_image);
5137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5141 % V i g n e t t e I m a g e %
5145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5147 % VignetteImage() softens the edges of the image in vignette style.
5149 % The format of the VignetteImage method is:
5151 % Image *VignetteImage(const Image *image,const double radius,
5152 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5154 % A description of each parameter follows:
5156 % o image: the image.
5158 % o radius: the radius of the pixel neighborhood.
5160 % o sigma: the standard deviation of the Gaussian, in pixels.
5162 % o x, y: Define the x and y ellipse offset.
5164 % o exception: return any errors or warnings in this structure.
5167 MagickExport Image *VignetteImage(const Image *image,const double radius,
5168 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5171 ellipse[MaxTextExtent];
5182 assert(image != (Image *) NULL);
5183 assert(image->signature == MagickSignature);
5184 if (image->debug != MagickFalse)
5185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5186 assert(exception != (ExceptionInfo *) NULL);
5187 assert(exception->signature == MagickSignature);
5188 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5189 if (canvas_image == (Image *) NULL)
5190 return((Image *) NULL);
5191 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5193 InheritException(exception,&canvas_image->exception);
5194 canvas_image=DestroyImage(canvas_image);
5195 return((Image *) NULL);
5197 canvas_image->matte=MagickTrue;
5198 oval_image=CloneImage(canvas_image,canvas_image->columns,
5199 canvas_image->rows,MagickTrue,exception);
5200 if (oval_image == (Image *) NULL)
5202 canvas_image=DestroyImage(canvas_image);
5203 return((Image *) NULL);
5205 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5206 (void) SetImageBackgroundColor(oval_image);
5207 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5208 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5209 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5210 (void) FormatMagickString(ellipse,MaxTextExtent,
5211 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5212 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5213 draw_info->primitive=AcquireString(ellipse);
5214 (void) DrawImage(oval_image,draw_info);
5215 draw_info=DestroyDrawInfo(draw_info);
5216 blur_image=BlurImage(oval_image,radius,sigma,exception);
5217 oval_image=DestroyImage(oval_image);
5218 if (blur_image == (Image *) NULL)
5220 canvas_image=DestroyImage(canvas_image);
5221 return((Image *) NULL);
5223 blur_image->matte=MagickFalse;
5224 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5225 blur_image=DestroyImage(blur_image);
5226 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5227 canvas_image=DestroyImage(canvas_image);
5228 return(vignette_image);
5232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5236 % W a v e I m a g e %
5240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5242 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5243 % vertically along a sine wave whose amplitude and wavelength is specified
5244 % by the given parameters.
5246 % The format of the WaveImage method is:
5248 % Image *WaveImage(const Image *image,const double amplitude,
5249 % const double wave_length,ExceptionInfo *exception)
5251 % A description of each parameter follows:
5253 % o image: the image.
5255 % o amplitude, wave_length: Define the amplitude and wave length of the
5258 % o exception: return any errors or warnings in this structure.
5261 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5262 const double wave_length,ExceptionInfo *exception)
5264 #define WaveImageTag "Wave/Image"
5288 **restrict resample_filter;
5294 Initialize wave image attributes.
5296 assert(image != (Image *) NULL);
5297 assert(image->signature == MagickSignature);
5298 if (image->debug != MagickFalse)
5299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5300 assert(exception != (ExceptionInfo *) NULL);
5301 assert(exception->signature == MagickSignature);
5302 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5303 fabs(amplitude)),MagickTrue,exception);
5304 if (wave_image == (Image *) NULL)
5305 return((Image *) NULL);
5306 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5308 InheritException(exception,&wave_image->exception);
5309 wave_image=DestroyImage(wave_image);
5310 return((Image *) NULL);
5312 if (wave_image->background_color.opacity != OpaqueOpacity)
5313 wave_image->matte=MagickTrue;
5317 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5319 if (sine_map == (MagickRealType *) NULL)
5321 wave_image=DestroyImage(wave_image);
5322 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5324 for (i=0; i < (ssize_t) wave_image->columns; i++)
5325 sine_map[i]=fabs(amplitude)+amplitude*sin((2*MagickPI*i)/wave_length);
5331 GetMagickPixelPacket(wave_image,&zero);
5332 resample_filter=AcquireResampleFilterThreadSet(image,
5333 BackgroundVirtualPixelMethod,MagickTrue,exception);
5334 wave_view=AcquireCacheView(wave_image);
5335 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5336 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5338 for (y=0; y < (ssize_t) wave_image->rows; y++)
5343 register IndexPacket
5350 register PixelPacket
5353 if (status == MagickFalse)
5355 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5357 if (q == (PixelPacket *) NULL)
5362 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5364 id=GetOpenMPThreadId();
5365 for (x=0; x < (ssize_t) wave_image->columns; x++)
5367 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5368 sine_map[x]),&pixel);
5369 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5372 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5374 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5379 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5380 #pragma omp critical (MagickCore_WaveImage)
5382 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5383 if (proceed == MagickFalse)
5387 wave_view=DestroyCacheView(wave_view);
5388 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5389 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5390 if (status == MagickFalse)
5391 wave_image=DestroyImage(wave_image);