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: ",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 (ssize_t) 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",depth);
1170 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1176 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1178 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
1180 if (LocaleNCompare(symbol,"maxima",6) == 0)
1186 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1187 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
1189 if (LocaleNCompare(symbol,"mean",4) == 0)
1195 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1197 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
1199 if (LocaleNCompare(symbol,"minima",6) == 0)
1205 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1206 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
1208 if (LocaleNCompare(symbol,"skewness",8) == 0)
1214 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1216 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
1218 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1224 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1226 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
1227 standard_deviation);
1229 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1230 ConstantString(statistic));
1231 return(QuantumScale*StringToDouble(statistic));
1234 static MagickRealType
1235 FxEvaluateSubexpression(FxInfo *,const ChannelType,const ssize_t,const ssize_t,
1236 const char *,MagickRealType *,ExceptionInfo *);
1238 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1239 const ssize_t x,const ssize_t y,const char *expression,ExceptionInfo *exception)
1245 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1246 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1249 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1250 const ssize_t x,const ssize_t y,const char *expression,ExceptionInfo *exception)
1256 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1257 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1260 static inline const char *FxSubexpression(const char *expression,
1261 ExceptionInfo *exception)
1270 subexpression=expression;
1271 while ((*subexpression != '\0') &&
1272 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1274 if (strchr("(",(int) *subexpression) != (char *) NULL)
1277 if (strchr(")",(int) *subexpression) != (char *) NULL)
1281 if (*subexpression == '\0')
1282 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1283 "UnbalancedParenthesis","`%s'",expression);
1284 return(subexpression);
1287 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1288 const ssize_t x,const ssize_t y,const char *expression,ExceptionInfo *exception)
1292 subexpression[MaxTextExtent],
1293 symbol[MaxTextExtent];
1322 i=GetImageIndexInList(fx_info->images);
1326 if (isalpha((int) *(p+1)) == 0)
1328 if (strchr("suv",(int) *p) != (char *) NULL)
1335 i=GetImageIndexInList(fx_info->images);
1338 case 'u': i=0; break;
1339 case 'v': i=1; break;
1346 for (p++; *p != '\0'; )
1360 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1362 i=(ssize_t) (alpha+0.5);
1368 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1375 for (p++; *p != '\0'; )
1389 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1400 for (p++; *p != '\0'; )
1414 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1424 length=GetImageListLength(fx_info->images);
1426 i+=(ssize_t) length;
1428 image=GetImageFromList(fx_info->images,i);
1429 if (image == (Image *) NULL)
1431 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1432 "NoSuchImage","`%s'",expression);
1435 (void) ResamplePixelColor(fx_info->resample_filter[i],point.x,point.y,&pixel);
1436 if ((strlen(p) > 2) &&
1437 (LocaleCompare(p,"intensity") != 0) &&
1438 (LocaleCompare(p,"luminance") != 0) &&
1439 (LocaleCompare(p,"hue") != 0) &&
1440 (LocaleCompare(p,"saturation") != 0) &&
1441 (LocaleCompare(p,"lightness") != 0))
1444 name[MaxTextExtent];
1446 (void) CopyMagickString(name,p,MaxTextExtent);
1447 for (q=name+(strlen(name)-1); q > name; q--)
1457 if ((strlen(name) > 2) &&
1458 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1463 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1465 if (color != (MagickPixelPacket *) NULL)
1471 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1473 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1474 CloneMagickPixelPacket(&pixel));
1479 (void) CopyMagickString(symbol,p,MaxTextExtent);
1480 StripString(symbol);
1481 if (*symbol == '\0')
1485 case RedChannel: return(QuantumScale*pixel.red);
1486 case GreenChannel: return(QuantumScale*pixel.green);
1487 case BlueChannel: return(QuantumScale*pixel.blue);
1488 case OpacityChannel:
1490 if (pixel.matte == MagickFalse)
1492 fx_info->matte=MagickFalse;
1495 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1499 if (image->colorspace != CMYKColorspace)
1501 (void) ThrowMagickException(exception,GetMagickModule(),
1502 OptionError,"ColorSeparatedImageRequired","`%s'",
1506 return(QuantumScale*pixel.index);
1511 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1512 "UnableToParseExpression","`%s'",p);
1520 if (LocaleCompare(symbol,"a") == 0)
1521 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1527 if (LocaleCompare(symbol,"b") == 0)
1528 return(QuantumScale*pixel.blue);
1534 if (LocaleNCompare(symbol,"channel",7) == 0)
1542 flags=ParseGeometry(symbol+7,&channel_info);
1543 if (image->colorspace == CMYKColorspace)
1548 if ((flags & RhoValue) == 0)
1550 return(channel_info.rho);
1552 case MagentaChannel:
1554 if ((flags & SigmaValue) == 0)
1556 return(channel_info.sigma);
1560 if ((flags & XiValue) == 0)
1562 return(channel_info.xi);
1566 if ((flags & PsiValue) == 0)
1568 return(channel_info.psi);
1570 case OpacityChannel:
1572 if ((flags & ChiValue) == 0)
1574 return(channel_info.chi);
1583 if ((flags & RhoValue) == 0)
1585 return(channel_info.rho);
1589 if ((flags & SigmaValue) == 0)
1591 return(channel_info.sigma);
1595 if ((flags & XiValue) == 0)
1597 return(channel_info.xi);
1599 case OpacityChannel:
1601 if ((flags & PsiValue) == 0)
1603 return(channel_info.psi);
1607 if ((flags & ChiValue) == 0)
1609 return(channel_info.chi);
1616 if (LocaleCompare(symbol,"c") == 0)
1617 return(QuantumScale*pixel.red);
1623 if (LocaleNCompare(symbol,"depth",5) == 0)
1624 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1630 if (LocaleCompare(symbol,"g") == 0)
1631 return(QuantumScale*pixel.green);
1637 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1638 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1639 if (LocaleCompare(symbol,"k") == 0)
1641 if (image->colorspace != CMYKColorspace)
1643 (void) ThrowMagickException(exception,GetMagickModule(),
1644 OptionError,"ColorSeparatedImageRequired","`%s'",
1648 return(QuantumScale*pixel.index);
1655 if (LocaleCompare(symbol,"h") == 0)
1656 return((MagickRealType) image->rows);
1657 if (LocaleCompare(symbol,"hue") == 0)
1664 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1665 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1673 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1674 (LocaleCompare(symbol,"image.minima") == 0) ||
1675 (LocaleCompare(symbol,"image.maxima") == 0) ||
1676 (LocaleCompare(symbol,"image.mean") == 0) ||
1677 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1678 (LocaleCompare(symbol,"image.skewness") == 0) ||
1679 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1680 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1681 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1682 return(image->x_resolution);
1683 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1684 return(image->y_resolution);
1685 if (LocaleCompare(symbol,"intensity") == 0)
1686 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1687 if (LocaleCompare(symbol,"i") == 0)
1688 return((MagickRealType) x);
1694 if (LocaleCompare(symbol,"j") == 0)
1695 return((MagickRealType) y);
1701 if (LocaleCompare(symbol,"lightness") == 0)
1708 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1709 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1712 if (LocaleCompare(symbol,"luminance") == 0)
1717 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1718 return(QuantumScale*luminence);
1725 if (LocaleNCompare(symbol,"maxima",6) == 0)
1726 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1727 if (LocaleNCompare(symbol,"mean",4) == 0)
1728 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1729 if (LocaleNCompare(symbol,"minima",6) == 0)
1730 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1731 if (LocaleCompare(symbol,"m") == 0)
1732 return(QuantumScale*pixel.blue);
1738 if (LocaleCompare(symbol,"n") == 0)
1739 return((MagickRealType) GetImageListLength(fx_info->images));
1745 if (LocaleCompare(symbol,"o") == 0)
1746 return(QuantumScale*pixel.opacity);
1752 if (LocaleCompare(symbol,"page.height") == 0)
1753 return((MagickRealType) image->page.height);
1754 if (LocaleCompare(symbol,"page.width") == 0)
1755 return((MagickRealType) image->page.width);
1756 if (LocaleCompare(symbol,"page.x") == 0)
1757 return((MagickRealType) image->page.x);
1758 if (LocaleCompare(symbol,"page.y") == 0)
1759 return((MagickRealType) image->page.y);
1765 if (LocaleCompare(symbol,"resolution.x") == 0)
1766 return(image->x_resolution);
1767 if (LocaleCompare(symbol,"resolution.y") == 0)
1768 return(image->y_resolution);
1769 if (LocaleCompare(symbol,"r") == 0)
1770 return(QuantumScale*pixel.red);
1776 if (LocaleCompare(symbol,"saturation") == 0)
1783 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1784 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1787 if (LocaleNCompare(symbol,"skewness",8) == 0)
1788 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1789 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1790 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1796 if (LocaleCompare(symbol,"t") == 0)
1797 return((MagickRealType) fx_info->images->scene);
1803 if (LocaleCompare(symbol,"w") == 0)
1804 return((MagickRealType) image->columns);
1810 if (LocaleCompare(symbol,"y") == 0)
1811 return(QuantumScale*pixel.green);
1817 if (LocaleCompare(symbol,"z") == 0)
1822 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1823 fx_info->exception);
1831 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1832 if (value != (const char *) NULL)
1833 return((MagickRealType) StringToDouble(value));
1834 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1835 "UnableToParseExpression","`%s'",symbol);
1839 static const char *FxOperatorPrecedence(const char *expression,
1840 ExceptionInfo *exception)
1844 UndefinedPrecedence,
1846 BitwiseComplementPrecedence,
1851 RelationalPrecedence,
1852 EquivalencyPrecedence,
1853 BitwiseAndPrecedence,
1854 BitwiseOrPrecedence,
1855 LogicalAndPrecedence,
1856 LogicalOrPrecedence,
1858 AssignmentPrecedence,
1878 subexpression=(const char *) NULL;
1879 target=NullPrecedence;
1880 while (*expression != '\0')
1882 precedence=UndefinedPrecedence;
1883 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1888 switch (*expression)
1893 if (LocaleNCompare(expression,"atan2",5) == 0)
1903 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1904 (LocaleNCompare(expression,"j1",2) == 0))
1914 if ((c == (int) '{') || (c == (int) '['))
1917 if ((c == (int) '}') || (c == (int) ']'))
1920 switch ((unsigned char) *expression)
1925 precedence=BitwiseComplementPrecedence;
1930 precedence=ExponentPrecedence;
1935 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1936 (strchr(")",c) != (char *) NULL))) &&
1937 (((islower((int) ((char) *expression)) != 0) ||
1938 (strchr("(",(int) *expression) != (char *) NULL)) ||
1939 ((isdigit((int) ((char) c)) == 0) &&
1940 (isdigit((int) ((char) *expression)) != 0))) &&
1941 (strchr("xy",(int) *expression) == (char *) NULL))
1942 precedence=MultiplyPrecedence;
1949 precedence=MultiplyPrecedence;
1955 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1957 precedence=AdditionPrecedence;
1960 case LeftShiftOperator:
1961 case RightShiftOperator:
1963 precedence=ShiftPrecedence;
1967 case LessThanEqualOperator:
1968 case GreaterThanEqualOperator:
1971 precedence=RelationalPrecedence;
1975 case NotEqualOperator:
1977 precedence=EquivalencyPrecedence;
1982 precedence=BitwiseAndPrecedence;
1987 precedence=BitwiseOrPrecedence;
1990 case LogicalAndOperator:
1992 precedence=LogicalAndPrecedence;
1995 case LogicalOrOperator:
1997 precedence=LogicalOrPrecedence;
2003 precedence=TernaryPrecedence;
2008 precedence=AssignmentPrecedence;
2013 precedence=CommaPrecedence;
2018 precedence=SeparatorPrecedence;
2022 if ((precedence == BitwiseComplementPrecedence) ||
2023 (precedence == TernaryPrecedence) ||
2024 (precedence == AssignmentPrecedence))
2026 if (precedence > target)
2029 Right-to-left associativity.
2032 subexpression=expression;
2036 if (precedence >= target)
2039 Left-to-right associativity.
2042 subexpression=expression;
2044 if (strchr("(",(int) *expression) != (char *) NULL)
2045 expression=FxSubexpression(expression,exception);
2046 c=(int) (*expression++);
2048 return(subexpression);
2051 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2052 const ChannelType channel,const ssize_t x,const ssize_t y,const char *expression,
2053 MagickRealType *beta,ExceptionInfo *exception)
2057 subexpression[MaxTextExtent];
2067 if (exception->severity != UndefinedException)
2069 while (isspace((int) *expression) != 0)
2071 if (*expression == '\0')
2073 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2074 "MissingExpression","`%s'",expression);
2077 *subexpression='\0';
2078 p=FxOperatorPrecedence(expression,exception);
2079 if (p != (const char *) NULL)
2081 (void) CopyMagickString(subexpression,expression,(size_t)
2083 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2085 switch ((unsigned char) *p)
2089 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2090 *beta=(MagickRealType) (~(size_t) *beta);
2095 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2096 return(*beta == 0.0 ? 1.0 : 0.0);
2100 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2101 channel,x,y,++p,beta,exception));
2106 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2107 return(alpha*(*beta));
2111 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2114 if (exception->severity == UndefinedException)
2115 (void) ThrowMagickException(exception,GetMagickModule(),
2116 OptionError,"DivideByZero","`%s'",expression);
2119 return(alpha/(*beta));
2123 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2124 *beta=fabs(floor(((double) *beta)+0.5));
2127 (void) ThrowMagickException(exception,GetMagickModule(),
2128 OptionError,"DivideByZero","`%s'",expression);
2131 return(fmod((double) alpha,(double) *beta));
2135 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2136 return(alpha+(*beta));
2140 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2141 return(alpha-(*beta));
2143 case LeftShiftOperator:
2145 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2146 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2150 case RightShiftOperator:
2152 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2153 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2159 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2160 return(alpha < *beta ? 1.0 : 0.0);
2162 case LessThanEqualOperator:
2164 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2165 return(alpha <= *beta ? 1.0 : 0.0);
2169 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2170 return(alpha > *beta ? 1.0 : 0.0);
2172 case GreaterThanEqualOperator:
2174 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2175 return(alpha >= *beta ? 1.0 : 0.0);
2179 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2180 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2182 case NotEqualOperator:
2184 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2185 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2189 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2190 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2196 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2197 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2201 case LogicalAndOperator:
2203 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2204 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2207 case LogicalOrOperator:
2209 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2210 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2218 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2220 p=StringToken(":",&q);
2221 if (q == (char *) NULL)
2223 (void) ThrowMagickException(exception,GetMagickModule(),
2224 OptionError,"UnableToParseExpression","`%s'",subexpression);
2227 if (fabs((double) alpha) > MagickEpsilon)
2228 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2230 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2236 numeric[MaxTextExtent];
2239 while (isalpha((int) ((unsigned char) *q)) != 0)
2243 (void) ThrowMagickException(exception,GetMagickModule(),
2244 OptionError,"UnableToParseExpression","`%s'",subexpression);
2247 ClearMagickException(exception);
2248 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2249 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2251 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2252 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2253 subexpression),ConstantString(numeric));
2258 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2263 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2268 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2274 if (strchr("(",(int) *expression) != (char *) NULL)
2276 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2277 subexpression[strlen(subexpression)-1]='\0';
2278 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2282 switch (*expression)
2286 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2292 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2298 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2300 return((MagickRealType) (~(size_t) (gamma+0.5)));
2305 if (LocaleNCompare(expression,"abs",3) == 0)
2307 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2309 return((MagickRealType) fabs((double) alpha));
2311 if (LocaleNCompare(expression,"acos",4) == 0)
2313 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2315 return((MagickRealType) acos((double) alpha));
2317 #if defined(MAGICKCORE_HAVE_J1)
2318 if (LocaleNCompare(expression,"airy",4) == 0)
2320 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2324 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2325 return(gamma*gamma);
2328 if (LocaleNCompare(expression,"asin",4) == 0)
2330 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2332 return((MagickRealType) asin((double) alpha));
2334 if (LocaleNCompare(expression,"alt",3) == 0)
2336 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2338 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2340 if (LocaleNCompare(expression,"atan2",5) == 0)
2342 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2344 return((MagickRealType) atan2((double) alpha,(double) *beta));
2346 if (LocaleNCompare(expression,"atan",4) == 0)
2348 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2350 return((MagickRealType) atan((double) alpha));
2352 if (LocaleCompare(expression,"a") == 0)
2353 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2359 if (LocaleCompare(expression,"b") == 0)
2360 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2366 if (LocaleNCompare(expression,"ceil",4) == 0)
2368 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2370 return((MagickRealType) ceil((double) alpha));
2372 if (LocaleNCompare(expression,"cosh",4) == 0)
2374 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2376 return((MagickRealType) cosh((double) alpha));
2378 if (LocaleNCompare(expression,"cos",3) == 0)
2380 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2382 return((MagickRealType) cos((double) alpha));
2384 if (LocaleCompare(expression,"c") == 0)
2385 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2391 if (LocaleNCompare(expression,"debug",5) == 0)
2396 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2398 if (fx_info->images->colorspace == CMYKColorspace)
2401 case CyanChannel: type="cyan"; break;
2402 case MagentaChannel: type="magenta"; break;
2403 case YellowChannel: type="yellow"; break;
2404 case OpacityChannel: type="opacity"; break;
2405 case BlackChannel: type="black"; break;
2406 default: type="unknown"; break;
2411 case RedChannel: type="red"; break;
2412 case GreenChannel: type="green"; break;
2413 case BlueChannel: type="blue"; break;
2414 case OpacityChannel: type="opacity"; break;
2415 default: type="unknown"; break;
2417 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2418 if (strlen(subexpression) > 1)
2419 subexpression[strlen(subexpression)-1]='\0';
2420 if (fx_info->file != (FILE *) NULL)
2421 (void) fprintf(fx_info->file,"%s[%ld,%ld].%s: %s=%.*g\n",
2422 fx_info->images->filename,(long) x,(long) y,type,subexpression,
2423 GetMagickPrecision(),(double) alpha);
2431 if (LocaleCompare(expression,"epsilon") == 0)
2432 return((MagickRealType) MagickEpsilon);
2433 if (LocaleNCompare(expression,"exp",3) == 0)
2435 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2437 return((MagickRealType) exp((double) alpha));
2439 if (LocaleCompare(expression,"e") == 0)
2440 return((MagickRealType) 2.7182818284590452354);
2446 if (LocaleNCompare(expression,"floor",5) == 0)
2448 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2450 return((MagickRealType) floor((double) alpha));
2457 if (LocaleCompare(expression,"g") == 0)
2458 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2464 if (LocaleCompare(expression,"h") == 0)
2465 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2466 if (LocaleCompare(expression,"hue") == 0)
2467 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2468 if (LocaleNCompare(expression,"hypot",5) == 0)
2470 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2472 return((MagickRealType) hypot((double) alpha,(double) *beta));
2479 if (LocaleCompare(expression,"k") == 0)
2480 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2486 if (LocaleCompare(expression,"intensity") == 0)
2487 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2488 if (LocaleNCompare(expression,"int",3) == 0)
2490 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2492 return((MagickRealType) floor(alpha+0.5));
2494 if (LocaleCompare(expression,"i") == 0)
2495 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2501 if (LocaleCompare(expression,"j") == 0)
2502 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2503 #if defined(MAGICKCORE_HAVE_J0)
2504 if (LocaleNCompare(expression,"j0",2) == 0)
2506 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2508 return((MagickRealType) j0((double) alpha));
2511 #if defined(MAGICKCORE_HAVE_J1)
2512 if (LocaleNCompare(expression,"j1",2) == 0)
2514 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2516 return((MagickRealType) j1((double) alpha));
2519 #if defined(MAGICKCORE_HAVE_J1)
2520 if (LocaleNCompare(expression,"jinc",4) == 0)
2522 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2526 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2536 if (LocaleNCompare(expression,"ln",2) == 0)
2538 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2540 return((MagickRealType) log((double) alpha));
2542 if (LocaleNCompare(expression,"logtwo",4) == 0)
2544 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2546 return((MagickRealType) log10((double) alpha))/log10(2.0);
2548 if (LocaleNCompare(expression,"log",3) == 0)
2550 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2552 return((MagickRealType) log10((double) alpha));
2554 if (LocaleCompare(expression,"lightness") == 0)
2555 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2561 if (LocaleCompare(expression,"MaxRGB") == 0)
2562 return((MagickRealType) QuantumRange);
2563 if (LocaleNCompare(expression,"maxima",6) == 0)
2565 if (LocaleNCompare(expression,"max",3) == 0)
2566 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2567 if (LocaleNCompare(expression,"minima",6) == 0)
2569 if (LocaleNCompare(expression,"min",3) == 0)
2570 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2571 if (LocaleNCompare(expression,"mod",3) == 0)
2573 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2575 return((MagickRealType) fmod((double) alpha,(double) *beta));
2577 if (LocaleCompare(expression,"m") == 0)
2578 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2584 if (LocaleCompare(expression,"n") == 0)
2585 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2591 if (LocaleCompare(expression,"Opaque") == 0)
2593 if (LocaleCompare(expression,"o") == 0)
2594 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2600 if (LocaleCompare(expression,"pi") == 0)
2601 return((MagickRealType) MagickPI);
2602 if (LocaleNCompare(expression,"pow",3) == 0)
2604 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2606 return((MagickRealType) pow((double) alpha,(double) *beta));
2608 if (LocaleCompare(expression,"p") == 0)
2609 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2615 if (LocaleCompare(expression,"QuantumRange") == 0)
2616 return((MagickRealType) QuantumRange);
2617 if (LocaleCompare(expression,"QuantumScale") == 0)
2618 return((MagickRealType) QuantumScale);
2624 if (LocaleNCompare(expression,"rand",4) == 0)
2625 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2626 if (LocaleNCompare(expression,"round",5) == 0)
2628 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2631 return((MagickRealType) floor((double) alpha+0.5));
2632 return((MagickRealType) ceil((double) alpha-0.5));
2634 if (LocaleCompare(expression,"r") == 0)
2635 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2641 if (LocaleCompare(expression,"saturation") == 0)
2642 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2643 if (LocaleNCompare(expression,"sign",4) == 0)
2645 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2647 return(alpha < 0.0 ? -1.0 : 1.0);
2649 if (LocaleNCompare(expression,"sinc",4) == 0)
2651 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2655 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2659 if (LocaleNCompare(expression,"sinh",4) == 0)
2661 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2663 return((MagickRealType) sinh((double) alpha));
2665 if (LocaleNCompare(expression,"sin",3) == 0)
2667 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2669 return((MagickRealType) sin((double) alpha));
2671 if (LocaleNCompare(expression,"sqrt",4) == 0)
2673 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2675 return((MagickRealType) sqrt((double) alpha));
2677 if (LocaleCompare(expression,"s") == 0)
2678 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2684 if (LocaleNCompare(expression,"tanh",4) == 0)
2686 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2688 return((MagickRealType) tanh((double) alpha));
2690 if (LocaleNCompare(expression,"tan",3) == 0)
2692 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2694 return((MagickRealType) tan((double) alpha));
2696 if (LocaleCompare(expression,"Transparent") == 0)
2698 if (LocaleCompare(expression,"t") == 0)
2699 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2705 if (LocaleCompare(expression,"u") == 0)
2706 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2712 if (LocaleCompare(expression,"v") == 0)
2713 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2719 if (LocaleCompare(expression,"w") == 0)
2720 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2726 if (LocaleCompare(expression,"y") == 0)
2727 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2733 if (LocaleCompare(expression,"z") == 0)
2734 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2740 q=(char *) expression;
2741 alpha=strtod(expression,&q);
2742 if (q == expression)
2743 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2747 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2748 MagickRealType *alpha,ExceptionInfo *exception)
2753 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2757 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2758 MagickRealType *alpha,ExceptionInfo *exception)
2767 fx_info->file=(FILE *) NULL;
2768 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2773 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2774 const ChannelType channel,const ssize_t x,const ssize_t y,MagickRealType *alpha,
2775 ExceptionInfo *exception)
2781 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2783 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2797 % FxImage() applies a mathematical expression to the specified image.
2799 % The format of the FxImage method is:
2801 % Image *FxImage(const Image *image,const char *expression,
2802 % ExceptionInfo *exception)
2803 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2804 % const char *expression,ExceptionInfo *exception)
2806 % A description of each parameter follows:
2808 % o image: the image.
2810 % o channel: the channel.
2812 % o expression: A mathematical expression.
2814 % o exception: return any errors or warnings in this structure.
2818 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2823 assert(fx_info != (FxInfo **) NULL);
2824 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2825 if (fx_info[i] != (FxInfo *) NULL)
2826 fx_info[i]=DestroyFxInfo(fx_info[i]);
2827 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2831 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2832 ExceptionInfo *exception)
2849 number_threads=GetOpenMPMaximumThreads();
2850 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2851 if (fx_info == (FxInfo **) NULL)
2852 return((FxInfo **) NULL);
2853 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2854 if (*expression != '@')
2855 fx_expression=ConstantString(expression);
2857 fx_expression=FileToString(expression+1,~0,exception);
2858 for (i=0; i < (ssize_t) number_threads; i++)
2860 fx_info[i]=AcquireFxInfo(image,fx_expression);
2861 if (fx_info[i] == (FxInfo *) NULL)
2862 return(DestroyFxThreadSet(fx_info));
2863 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2865 fx_expression=DestroyString(fx_expression);
2869 MagickExport Image *FxImage(const Image *image,const char *expression,
2870 ExceptionInfo *exception)
2875 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2879 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2880 const char *expression,ExceptionInfo *exception)
2882 #define FxImageTag "Fx/Image"
2905 assert(image != (Image *) NULL);
2906 assert(image->signature == MagickSignature);
2907 if (image->debug != MagickFalse)
2908 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2909 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2910 if (fx_image == (Image *) NULL)
2911 return((Image *) NULL);
2912 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2914 InheritException(exception,&fx_image->exception);
2915 fx_image=DestroyImage(fx_image);
2916 return((Image *) NULL);
2918 fx_info=AcquireFxThreadSet(image,expression,exception);
2919 if (fx_info == (FxInfo **) NULL)
2921 fx_image=DestroyImage(fx_image);
2922 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2924 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2925 if (status == MagickFalse)
2927 fx_image=DestroyImage(fx_image);
2928 fx_info=DestroyFxThreadSet(fx_info);
2929 return((Image *) NULL);
2936 fx_view=AcquireCacheView(fx_image);
2937 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2938 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2940 for (y=0; y < (ssize_t) fx_image->rows; y++)
2945 register IndexPacket
2946 *restrict fx_indexes;
2952 register PixelPacket
2955 if (status == MagickFalse)
2957 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2958 if (q == (PixelPacket *) NULL)
2963 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2964 id=GetOpenMPThreadId();
2966 for (x=0; x < (ssize_t) fx_image->columns; x++)
2968 if ((channel & RedChannel) != 0)
2970 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
2972 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2974 if ((channel & GreenChannel) != 0)
2976 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
2978 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2980 if ((channel & BlueChannel) != 0)
2982 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
2984 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2986 if ((channel & OpacityChannel) != 0)
2988 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
2990 if (image->matte == MagickFalse)
2991 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
2993 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
2994 QuantumRange*alpha));
2996 if (((channel & IndexChannel) != 0) &&
2997 (fx_image->colorspace == CMYKColorspace))
2999 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
3001 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
3002 QuantumRange*alpha);
3006 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3008 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3013 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3014 #pragma omp critical (MagickCore_FxImageChannel)
3016 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3017 if (proceed == MagickFalse)
3021 fx_image->matte=fx_info[0]->matte;
3022 fx_view=DestroyCacheView(fx_view);
3023 fx_info=DestroyFxThreadSet(fx_info);
3024 if (status == MagickFalse)
3025 fx_image=DestroyImage(fx_image);
3030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3034 % I m p l o d e I m a g e %
3038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3040 % ImplodeImage() creates a new image that is a copy of an existing
3041 % one with the image pixels "implode" by the specified percentage. It
3042 % allocates the memory necessary for the new Image structure and returns a
3043 % pointer to the new image.
3045 % The format of the ImplodeImage method is:
3047 % Image *ImplodeImage(const Image *image,const double amount,
3048 % ExceptionInfo *exception)
3050 % A description of each parameter follows:
3052 % o implode_image: Method ImplodeImage returns a pointer to the image
3053 % after it is implode. A null image is returned if there is a memory
3056 % o image: the image.
3058 % o amount: Define the extent of the implosion.
3060 % o exception: return any errors or warnings in this structure.
3063 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3064 ExceptionInfo *exception)
3066 #define ImplodeImageTag "Implode/Image"
3092 **restrict resample_filter;
3098 Initialize implode image attributes.
3100 assert(image != (Image *) NULL);
3101 assert(image->signature == MagickSignature);
3102 if (image->debug != MagickFalse)
3103 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3104 assert(exception != (ExceptionInfo *) NULL);
3105 assert(exception->signature == MagickSignature);
3106 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3107 if (implode_image == (Image *) NULL)
3108 return((Image *) NULL);
3109 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3111 InheritException(exception,&implode_image->exception);
3112 implode_image=DestroyImage(implode_image);
3113 return((Image *) NULL);
3115 if (implode_image->background_color.opacity != OpaqueOpacity)
3116 implode_image->matte=MagickTrue;
3118 Compute scaling factor.
3122 center.x=0.5*image->columns;
3123 center.y=0.5*image->rows;
3125 if (image->columns > image->rows)
3126 scale.y=(double) image->columns/(double) image->rows;
3128 if (image->columns < image->rows)
3130 scale.x=(double) image->rows/(double) image->columns;
3138 GetMagickPixelPacket(implode_image,&zero);
3139 resample_filter=AcquireResampleFilterThreadSet(image,
3140 UndefinedVirtualPixelMethod,MagickTrue,exception);
3141 image_view=AcquireCacheView(image);
3142 implode_view=AcquireCacheView(implode_image);
3143 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3144 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3146 for (y=0; y < (ssize_t) image->rows; y++)
3157 register IndexPacket
3158 *restrict implode_indexes;
3164 register PixelPacket
3167 if (status == MagickFalse)
3169 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3171 if (q == (PixelPacket *) NULL)
3176 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
3177 delta.y=scale.y*(double) (y-center.y);
3179 id=GetOpenMPThreadId();
3180 for (x=0; x < (ssize_t) image->columns; x++)
3183 Determine if the pixel is within an ellipse.
3185 delta.x=scale.x*(double) (x-center.x);
3186 distance=delta.x*delta.x+delta.y*delta.y;
3187 if (distance < (radius*radius))
3197 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3198 radius/2)),-amount);
3199 (void) ResamplePixelColor(resample_filter[id],(double)
3200 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3201 scale.y+center.y),&pixel);
3202 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
3206 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3208 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3213 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3214 #pragma omp critical (MagickCore_ImplodeImage)
3216 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3217 if (proceed == MagickFalse)
3221 implode_view=DestroyCacheView(implode_view);
3222 image_view=DestroyCacheView(image_view);
3223 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
3224 if (status == MagickFalse)
3225 implode_image=DestroyImage(implode_image);
3226 return(implode_image);
3230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3234 % M o r p h I m a g e s %
3238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3240 % The MorphImages() method requires a minimum of two images. The first
3241 % image is transformed into the second by a number of intervening images
3242 % as specified by frames.
3244 % The format of the MorphImage method is:
3246 % Image *MorphImages(const Image *image,const size_t number_frames,
3247 % ExceptionInfo *exception)
3249 % A description of each parameter follows:
3251 % o image: the image.
3253 % o number_frames: Define the number of in-between image to generate.
3254 % The more in-between frames, the smoother the morph.
3256 % o exception: return any errors or warnings in this structure.
3259 MagickExport Image *MorphImages(const Image *image,
3260 const size_t number_frames,ExceptionInfo *exception)
3262 #define MorphImageTag "Morph/Image"
3278 register const Image
3288 Clone first frame in sequence.
3290 assert(image != (Image *) NULL);
3291 assert(image->signature == MagickSignature);
3292 if (image->debug != MagickFalse)
3293 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3294 assert(exception != (ExceptionInfo *) NULL);
3295 assert(exception->signature == MagickSignature);
3296 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3297 if (morph_images == (Image *) NULL)
3298 return((Image *) NULL);
3299 if (GetNextImageInList(image) == (Image *) NULL)
3304 for (i=1; i < (ssize_t) number_frames; i++)
3306 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3307 if (morph_image == (Image *) NULL)
3309 morph_images=DestroyImageList(morph_images);
3310 return((Image *) NULL);
3312 AppendImageToList(&morph_images,morph_image);
3313 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3318 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3320 if (proceed == MagickFalse)
3324 return(GetFirstImageInList(morph_images));
3327 Morph image sequence.
3332 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3334 for (i=0; i < (ssize_t) number_frames; i++)
3340 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3342 morph_image=ZoomImage(next,(size_t) (alpha*next->columns+beta*
3343 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3344 next->rows+beta*GetNextImageInList(next)->rows+0.5),exception);
3345 if (morph_image == (Image *) NULL)
3347 morph_images=DestroyImageList(morph_images);
3348 return((Image *) NULL);
3350 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3352 InheritException(exception,&morph_image->exception);
3353 morph_image=DestroyImage(morph_image);
3354 return((Image *) NULL);
3356 AppendImageToList(&morph_images,morph_image);
3357 morph_images=GetLastImageInList(morph_images);
3358 morph_image=ZoomImage(GetNextImageInList(next),morph_images->columns,
3359 morph_images->rows,exception);
3360 if (morph_image == (Image *) NULL)
3362 morph_images=DestroyImageList(morph_images);
3363 return((Image *) NULL);
3365 image_view=AcquireCacheView(morph_image);
3366 morph_view=AcquireCacheView(morph_images);
3367 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3368 #pragma omp parallel for schedule(dynamic,4) shared(status)
3370 for (y=0; y < (ssize_t) morph_images->rows; y++)
3375 register const PixelPacket
3381 register PixelPacket
3384 if (status == MagickFalse)
3386 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3388 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3390 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3395 for (x=0; x < (ssize_t) morph_images->columns; x++)
3397 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3398 q->green=ClampToQuantum(alpha*q->green+beta*
3399 GetGreenPixelComponent(p));
3400 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3401 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3402 GetOpacityPixelComponent(p));
3406 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3407 if (sync == MagickFalse)
3410 morph_view=DestroyCacheView(morph_view);
3411 image_view=DestroyCacheView(image_view);
3412 morph_image=DestroyImage(morph_image);
3414 if (i < (ssize_t) number_frames)
3417 Clone last frame in sequence.
3419 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3420 if (morph_image == (Image *) NULL)
3422 morph_images=DestroyImageList(morph_images);
3423 return((Image *) NULL);
3425 AppendImageToList(&morph_images,morph_image);
3426 morph_images=GetLastImageInList(morph_images);
3427 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3432 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3433 #pragma omp critical (MagickCore_MorphImages)
3435 proceed=SetImageProgress(image,MorphImageTag,scene,
3436 GetImageListLength(image));
3437 if (proceed == MagickFalse)
3442 if (GetNextImageInList(next) != (Image *) NULL)
3444 morph_images=DestroyImageList(morph_images);
3445 return((Image *) NULL);
3447 return(GetFirstImageInList(morph_images));
3451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3455 % P l a s m a I m a g e %
3459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3461 % PlasmaImage() initializes an image with plasma fractal values. The image
3462 % must be initialized with a base color and the random number generator
3463 % seeded before this method is called.
3465 % The format of the PlasmaImage method is:
3467 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3468 % size_t attenuate,size_t depth)
3470 % A description of each parameter follows:
3472 % o image: the image.
3474 % o segment: Define the region to apply plasma fractals values.
3476 % o attenuate: Define the plasmattenuation factor.
3478 % o depth: Limit the plasma recursion depth.
3482 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3483 const MagickRealType pixel,const MagickRealType noise)
3488 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3493 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3494 RandomInfo *random_info,const SegmentInfo *segment,size_t attenuate,
3513 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3521 Divide the area into quadrants and recurse.
3525 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3526 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3527 local_info=(*segment);
3528 local_info.x2=(double) x_mid;
3529 local_info.y2=(double) y_mid;
3530 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3531 local_info=(*segment);
3532 local_info.y1=(double) y_mid;
3533 local_info.x2=(double) x_mid;
3534 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3535 local_info=(*segment);
3536 local_info.x1=(double) x_mid;
3537 local_info.y2=(double) y_mid;
3538 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3539 local_info=(*segment);
3540 local_info.x1=(double) x_mid;
3541 local_info.y1=(double) y_mid;
3542 return(PlasmaImageProxy(image,random_info,&local_info,attenuate,depth));
3544 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3545 return(MagickFalse);
3546 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3547 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3548 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3549 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3550 return(MagickFalse);
3552 Average pixels and apply plasma.
3554 exception=(&image->exception);
3555 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3556 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3558 register PixelPacket
3564 x=(ssize_t) ceil(segment->x1-0.5);
3565 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y1-0.5),&u,
3567 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y2-0.5),&v,
3569 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3570 if (q == (PixelPacket *) NULL)
3572 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3574 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3576 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3578 (void) SyncAuthenticPixels(image,exception);
3579 if (segment->x1 != segment->x2)
3584 x=(ssize_t) ceil(segment->x2-0.5);
3585 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y1-0.5),&u,
3587 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y2-0.5),&v,
3589 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3590 if (q == (PixelPacket *) NULL)
3592 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3594 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3596 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3598 (void) SyncAuthenticPixels(image,exception);
3601 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3603 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3605 register PixelPacket
3611 y=(ssize_t) ceil(segment->y2-0.5);
3612 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x1-0.5),y,&u,
3614 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x2-0.5),y,&v,
3616 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3617 if (q == (PixelPacket *) NULL)
3619 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3621 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3623 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3625 (void) SyncAuthenticPixels(image,exception);
3627 if (segment->y1 != segment->y2)
3629 register PixelPacket
3635 y=(ssize_t) ceil(segment->y1-0.5);
3636 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x1-0.5),y,&u,
3638 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x2-0.5),y,&v,
3640 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3641 if (q == (PixelPacket *) NULL)
3643 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3645 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3647 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3649 (void) SyncAuthenticPixels(image,exception);
3652 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3654 register PixelPacket
3660 x=(ssize_t) ceil(segment->x1-0.5);
3661 y=(ssize_t) ceil(segment->y1-0.5);
3662 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3663 x=(ssize_t) ceil(segment->x2-0.5);
3664 y=(ssize_t) ceil(segment->y2-0.5);
3665 (void) GetOneVirtualPixel(image,x,y,&v,exception);
3666 q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception);
3667 if (q == (PixelPacket *) NULL)
3669 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3671 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3673 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3675 (void) SyncAuthenticPixels(image,exception);
3677 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3679 return(MagickFalse);
3682 MagickExport MagickBooleanType PlasmaImage(Image *image,
3683 const SegmentInfo *segment,size_t attenuate,size_t depth)
3691 if (image->debug != MagickFalse)
3692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3693 assert(image != (Image *) NULL);
3694 assert(image->signature == MagickSignature);
3695 if (image->debug != MagickFalse)
3696 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3697 random_info=AcquireRandomInfo();
3698 status=PlasmaImageProxy(image,random_info,segment,attenuate,depth);
3699 random_info=DestroyRandomInfo(random_info);
3704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3708 % P o l a r o i d I m a g e %
3712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3714 % PolaroidImage() simulates a Polaroid picture.
3716 % The format of the AnnotateImage method is:
3718 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3719 % const double angle,ExceptionInfo exception)
3721 % A description of each parameter follows:
3723 % o image: the image.
3725 % o draw_info: the draw info.
3727 % o angle: Apply the effect assize_t this angle.
3729 % o exception: return any errors or warnings in this structure.
3732 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3733 const double angle,ExceptionInfo *exception)
3754 Simulate a Polaroid picture.
3756 assert(image != (Image *) NULL);
3757 assert(image->signature == MagickSignature);
3758 if (image->debug != MagickFalse)
3759 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3760 assert(exception != (ExceptionInfo *) NULL);
3761 assert(exception->signature == MagickSignature);
3762 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3763 image->rows)/25.0,10.0);
3764 height=image->rows+2*quantum;
3765 caption_image=(Image *) NULL;
3766 value=GetImageProperty(image,"Caption");
3767 if (value != (const char *) NULL)
3771 geometry[MaxTextExtent];
3786 Generate caption image.
3788 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3789 if (caption_image == (Image *) NULL)
3790 return((Image *) NULL);
3791 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3792 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3794 (void) CloneString(&annotate_info->text,caption);
3795 count=FormatMagickCaption(caption_image,annotate_info,&metrics,&caption);
3796 status=SetImageExtent(caption_image,image->columns,(size_t)
3797 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3798 if (status == MagickFalse)
3799 caption_image=DestroyImage(caption_image);
3802 caption_image->background_color=image->border_color;
3803 (void) SetImageBackgroundColor(caption_image);
3804 (void) CloneString(&annotate_info->text,caption);
3805 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3807 if (annotate_info->gravity == UndefinedGravity)
3808 (void) CloneString(&annotate_info->geometry,AcquireString(
3810 (void) AnnotateImage(caption_image,annotate_info);
3811 height+=caption_image->rows;
3813 annotate_info=DestroyDrawInfo(annotate_info);
3814 caption=DestroyString(caption);
3816 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3818 if (picture_image == (Image *) NULL)
3820 if (caption_image != (Image *) NULL)
3821 caption_image=DestroyImage(caption_image);
3822 return((Image *) NULL);
3824 picture_image->background_color=image->border_color;
3825 (void) SetImageBackgroundColor(picture_image);
3826 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3827 if (caption_image != (Image *) NULL)
3829 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3830 quantum,(ssize_t) (image->rows+3*quantum/2));
3831 caption_image=DestroyImage(caption_image);
3833 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3834 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3835 rotate_image=RotateImage(picture_image,90.0,exception);
3836 picture_image=DestroyImage(picture_image);
3837 if (rotate_image == (Image *) NULL)
3838 return((Image *) NULL);
3839 picture_image=rotate_image;
3840 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3841 picture_image->columns,exception);
3842 picture_image=DestroyImage(picture_image);
3843 if (bend_image == (Image *) NULL)
3844 return((Image *) NULL);
3845 InheritException(&bend_image->exception,exception);
3846 picture_image=bend_image;
3847 rotate_image=RotateImage(picture_image,-90.0,exception);
3848 picture_image=DestroyImage(picture_image);
3849 if (rotate_image == (Image *) NULL)
3850 return((Image *) NULL);
3851 picture_image=rotate_image;
3852 picture_image->background_color=image->background_color;
3853 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3855 if (polaroid_image == (Image *) NULL)
3857 picture_image=DestroyImage(picture_image);
3858 return(picture_image);
3860 flop_image=FlopImage(polaroid_image,exception);
3861 polaroid_image=DestroyImage(polaroid_image);
3862 if (flop_image == (Image *) NULL)
3864 picture_image=DestroyImage(picture_image);
3865 return(picture_image);
3867 polaroid_image=flop_image;
3868 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3869 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3870 picture_image=DestroyImage(picture_image);
3871 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3872 rotate_image=RotateImage(polaroid_image,angle,exception);
3873 polaroid_image=DestroyImage(polaroid_image);
3874 if (rotate_image == (Image *) NULL)
3875 return((Image *) NULL);
3876 polaroid_image=rotate_image;
3877 trim_image=TrimImage(polaroid_image,exception);
3878 polaroid_image=DestroyImage(polaroid_image);
3879 if (trim_image == (Image *) NULL)
3880 return((Image *) NULL);
3881 polaroid_image=trim_image;
3882 return(polaroid_image);
3886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3890 % S e p i a T o n e I m a g e %
3894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3896 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3897 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3898 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3899 % threshold of 80% is a good starting point for a reasonable tone.
3901 % The format of the SepiaToneImage method is:
3903 % Image *SepiaToneImage(const Image *image,const double threshold,
3904 % ExceptionInfo *exception)
3906 % A description of each parameter follows:
3908 % o image: the image.
3910 % o threshold: the tone threshold.
3912 % o exception: return any errors or warnings in this structure.
3915 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3916 ExceptionInfo *exception)
3918 #define SepiaToneImageTag "SepiaTone/Image"
3937 Initialize sepia-toned image attributes.
3939 assert(image != (const Image *) NULL);
3940 assert(image->signature == MagickSignature);
3941 if (image->debug != MagickFalse)
3942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3943 assert(exception != (ExceptionInfo *) NULL);
3944 assert(exception->signature == MagickSignature);
3945 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3946 if (sepia_image == (Image *) NULL)
3947 return((Image *) NULL);
3948 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3950 InheritException(exception,&sepia_image->exception);
3951 sepia_image=DestroyImage(sepia_image);
3952 return((Image *) NULL);
3955 Tone each row of the image.
3959 image_view=AcquireCacheView(image);
3960 sepia_view=AcquireCacheView(sepia_image);
3961 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3962 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3964 for (y=0; y < (ssize_t) image->rows; y++)
3966 register const PixelPacket
3972 register PixelPacket
3975 if (status == MagickFalse)
3977 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3978 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
3980 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3985 for (x=0; x < (ssize_t) image->columns; x++)
3991 intensity=(MagickRealType) PixelIntensityToQuantum(p);
3992 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
3993 (MagickRealType) QuantumRange-threshold;
3994 q->red=ClampToQuantum(tone);
3995 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
3996 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
3997 q->green=ClampToQuantum(tone);
3998 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
3999 q->blue=ClampToQuantum(tone);
4001 if ((MagickRealType) q->green < tone)
4002 q->green=ClampToQuantum(tone);
4003 if ((MagickRealType) q->blue < tone)
4004 q->blue=ClampToQuantum(tone);
4008 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4010 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4015 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4016 #pragma omp critical (MagickCore_SepiaToneImage)
4018 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4020 if (proceed == MagickFalse)
4024 sepia_view=DestroyCacheView(sepia_view);
4025 image_view=DestroyCacheView(image_view);
4026 (void) NormalizeImage(sepia_image);
4027 (void) ContrastImage(sepia_image,MagickTrue);
4028 if (status == MagickFalse)
4029 sepia_image=DestroyImage(sepia_image);
4030 return(sepia_image);
4034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4038 % S h a d o w I m a g e %
4042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4044 % ShadowImage() simulates a shadow from the specified image and returns it.
4046 % The format of the ShadowImage method is:
4048 % Image *ShadowImage(const Image *image,const double opacity,
4049 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4050 % ExceptionInfo *exception)
4052 % A description of each parameter follows:
4054 % o image: the image.
4056 % o opacity: percentage transparency.
4058 % o sigma: the standard deviation of the Gaussian, in pixels.
4060 % o x_offset: the shadow x-offset.
4062 % o y_offset: the shadow y-offset.
4064 % o exception: return any errors or warnings in this structure.
4067 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4068 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4069 ExceptionInfo *exception)
4071 #define ShadowImageTag "Shadow/Image"
4093 assert(image != (Image *) NULL);
4094 assert(image->signature == MagickSignature);
4095 if (image->debug != MagickFalse)
4096 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4097 assert(exception != (ExceptionInfo *) NULL);
4098 assert(exception->signature == MagickSignature);
4099 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4100 if (clone_image == (Image *) NULL)
4101 return((Image *) NULL);
4102 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4103 clone_image->compose=OverCompositeOp;
4104 border_info.width=(size_t) floor(2.0*sigma+0.5);
4105 border_info.height=(size_t) floor(2.0*sigma+0.5);
4108 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4109 border_image=BorderImage(clone_image,&border_info,exception);
4110 clone_image=DestroyImage(clone_image);
4111 if (border_image == (Image *) NULL)
4112 return((Image *) NULL);
4113 if (border_image->matte == MagickFalse)
4114 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4120 image_view=AcquireCacheView(border_image);
4121 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4122 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4124 for (y=0; y < (ssize_t) border_image->rows; y++)
4129 register PixelPacket
4132 if (status == MagickFalse)
4134 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4136 if (q == (PixelPacket *) NULL)
4141 for (x=0; x < (ssize_t) border_image->columns; x++)
4143 q->red=border_image->background_color.red;
4144 q->green=border_image->background_color.green;
4145 q->blue=border_image->background_color.blue;
4146 if (border_image->matte == MagickFalse)
4147 q->opacity=border_image->background_color.opacity;
4149 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4150 GetAlphaPixelComponent(q)*opacity/100.0));
4153 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4155 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4160 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4161 #pragma omp critical (MagickCore_ShadowImage)
4163 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4164 border_image->rows);
4165 if (proceed == MagickFalse)
4169 image_view=DestroyCacheView(image_view);
4170 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4171 border_image=DestroyImage(border_image);
4172 if (shadow_image == (Image *) NULL)
4173 return((Image *) NULL);
4174 if (shadow_image->page.width == 0)
4175 shadow_image->page.width=shadow_image->columns;
4176 if (shadow_image->page.height == 0)
4177 shadow_image->page.height=shadow_image->rows;
4178 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4179 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4180 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4181 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4182 return(shadow_image);
4186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4190 % S k e t c h I m a g e %
4194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4196 % SketchImage() simulates a pencil sketch. We convolve the image with a
4197 % Gaussian operator of the given radius and standard deviation (sigma). For
4198 % reasonable results, radius should be larger than sigma. Use a radius of 0
4199 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4202 % The format of the SketchImage method is:
4204 % Image *SketchImage(const Image *image,const double radius,
4205 % const double sigma,const double angle,ExceptionInfo *exception)
4207 % A description of each parameter follows:
4209 % o image: the image.
4211 % o radius: the radius of the Gaussian, in pixels, not counting
4214 % o sigma: the standard deviation of the Gaussian, in pixels.
4216 % o angle: Apply the effect assize_t this angle.
4218 % o exception: return any errors or warnings in this structure.
4221 MagickExport Image *SketchImage(const Image *image,const double radius,
4222 const double sigma,const double angle,ExceptionInfo *exception)
4244 **restrict random_info;
4249 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4250 MagickTrue,exception);
4251 if (random_image == (Image *) NULL)
4252 return((Image *) NULL);
4254 GetMagickPixelPacket(random_image,&zero);
4255 random_info=AcquireRandomInfoThreadSet();
4256 random_view=AcquireCacheView(random_image);
4257 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4258 #pragma omp parallel for schedule(dynamic,4) shared(status)
4260 for (y=0; y < (ssize_t) random_image->rows; y++)
4265 register IndexPacket
4272 register PixelPacket
4275 if (status == MagickFalse)
4277 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4279 if (q == (PixelPacket *) NULL)
4284 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4286 id=GetOpenMPThreadId();
4287 for (x=0; x < (ssize_t) random_image->columns; x++)
4289 pixel.red=(MagickRealType) (QuantumRange*
4290 GetPseudoRandomValue(random_info[id]));
4291 pixel.green=pixel.red;
4292 pixel.blue=pixel.red;
4293 if (image->colorspace == CMYKColorspace)
4294 pixel.index=pixel.red;
4295 SetPixelPacket(random_image,&pixel,q,indexes+x);
4298 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4301 random_view=DestroyCacheView(random_view);
4302 random_info=DestroyRandomInfoThreadSet(random_info);
4303 if (status == MagickFalse)
4305 random_image=DestroyImage(random_image);
4306 return(random_image);
4308 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4309 random_image=DestroyImage(random_image);
4310 if (blur_image == (Image *) NULL)
4311 return((Image *) NULL);
4312 dodge_image=EdgeImage(blur_image,radius,exception);
4313 blur_image=DestroyImage(blur_image);
4314 if (dodge_image == (Image *) NULL)
4315 return((Image *) NULL);
4316 (void) NormalizeImage(dodge_image);
4317 (void) NegateImage(dodge_image,MagickFalse);
4318 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4319 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4320 if (sketch_image == (Image *) NULL)
4322 dodge_image=DestroyImage(dodge_image);
4323 return((Image *) NULL);
4325 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4326 dodge_image=DestroyImage(dodge_image);
4327 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4328 if (blend_image == (Image *) NULL)
4330 sketch_image=DestroyImage(sketch_image);
4331 return((Image *) NULL);
4333 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4334 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4335 blend_image=DestroyImage(blend_image);
4336 return(sketch_image);
4340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4344 % S o l a r i z e I m a g e %
4348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4350 % SolarizeImage() applies a special effect to the image, similar to the effect
4351 % achieved in a photo darkroom by selectively exposing areas of photo
4352 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4353 % measure of the extent of the solarization.
4355 % The format of the SolarizeImage method is:
4357 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4359 % A description of each parameter follows:
4361 % o image: the image.
4363 % o threshold: Define the extent of the solarization.
4366 MagickExport MagickBooleanType SolarizeImage(Image *image,
4367 const double threshold)
4369 #define SolarizeImageTag "Solarize/Image"
4386 assert(image != (Image *) NULL);
4387 assert(image->signature == MagickSignature);
4388 if (image->debug != MagickFalse)
4389 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4390 if (image->storage_class == PseudoClass)
4398 for (i=0; i < (ssize_t) image->colors; i++)
4400 if ((MagickRealType) image->colormap[i].red > threshold)
4401 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4402 if ((MagickRealType) image->colormap[i].green > threshold)
4403 image->colormap[i].green=(Quantum) QuantumRange-
4404 image->colormap[i].green;
4405 if ((MagickRealType) image->colormap[i].blue > threshold)
4406 image->colormap[i].blue=(Quantum) QuantumRange-
4407 image->colormap[i].blue;
4415 exception=(&image->exception);
4416 image_view=AcquireCacheView(image);
4417 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4418 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4420 for (y=0; y < (ssize_t) image->rows; y++)
4425 register PixelPacket
4428 if (status == MagickFalse)
4430 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4432 if (q == (PixelPacket *) NULL)
4437 for (x=0; x < (ssize_t) image->columns; x++)
4439 if ((MagickRealType) q->red > threshold)
4440 q->red=(Quantum) QuantumRange-q->red;
4441 if ((MagickRealType) q->green > threshold)
4442 q->green=(Quantum) QuantumRange-q->green;
4443 if ((MagickRealType) q->blue > threshold)
4444 q->blue=(Quantum) QuantumRange-q->blue;
4447 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4449 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4454 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4455 #pragma omp critical (MagickCore_SolarizeImage)
4457 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4458 if (proceed == MagickFalse)
4462 image_view=DestroyCacheView(image_view);
4467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4471 % S t e g a n o I m a g e %
4475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4477 % SteganoImage() hides a digital watermark within the image. Recover
4478 % the hidden watermark later to prove that the authenticity of an image.
4479 % Offset defines the start position within the image to hide the watermark.
4481 % The format of the SteganoImage method is:
4483 % Image *SteganoImage(const Image *image,Image *watermark,
4484 % ExceptionInfo *exception)
4486 % A description of each parameter follows:
4488 % o image: the image.
4490 % o watermark: the watermark image.
4492 % o exception: return any errors or warnings in this structure.
4495 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4496 ExceptionInfo *exception)
4498 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) \
4500 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) ? (size_t) (alpha) \
4501 | (1UL << (size_t) (i)) : (size_t) (alpha) & \
4502 ~(1UL << (size_t) (i)))
4503 #define SteganoImageTag "Stegano/Image"
4526 register PixelPacket
4533 Initialize steganographic image attributes.
4535 assert(image != (const Image *) NULL);
4536 assert(image->signature == MagickSignature);
4537 if (image->debug != MagickFalse)
4538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4539 assert(watermark != (const Image *) NULL);
4540 assert(watermark->signature == MagickSignature);
4541 assert(exception != (ExceptionInfo *) NULL);
4542 assert(exception->signature == MagickSignature);
4543 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4544 if (stegano_image == (Image *) NULL)
4545 return((Image *) NULL);
4546 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4548 InheritException(exception,&stegano_image->exception);
4549 stegano_image=DestroyImage(stegano_image);
4550 return((Image *) NULL);
4552 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4554 Hide watermark in low-order bits of image.
4559 depth=stegano_image->depth;
4561 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4563 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4565 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4567 (void) GetOneVirtualPixel(watermark,x,y,&pixel,exception);
4568 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4570 q=GetAuthenticPixels(stegano_image,k % (ssize_t) stegano_image->columns,
4571 k/(ssize_t) stegano_image->columns,1,1,exception);
4572 if (q == (PixelPacket *) NULL)
4578 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4583 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4588 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4592 if (SyncAuthenticPixels(stegano_image,exception) == MagickFalse)
4598 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4600 if (k == image->offset)
4604 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4609 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4611 if (proceed == MagickFalse)
4615 if (stegano_image->storage_class == PseudoClass)
4616 (void) SyncImage(stegano_image);
4617 return(stegano_image);
4621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4625 % S t e r e o A n a g l y p h I m a g e %
4629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4631 % StereoAnaglyphImage() combines two images and produces a single image that
4632 % is the composite of a left and right image of a stereo pair. Special
4633 % red-green stereo glasses are required to view this effect.
4635 % The format of the StereoAnaglyphImage method is:
4637 % Image *StereoImage(const Image *left_image,const Image *right_image,
4638 % ExceptionInfo *exception)
4639 % Image *StereoAnaglyphImage(const Image *left_image,
4640 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4641 % ExceptionInfo *exception)
4643 % A description of each parameter follows:
4645 % o left_image: the left image.
4647 % o right_image: the right image.
4649 % o exception: return any errors or warnings in this structure.
4651 % o x_offset: amount, in pixels, by which the left image is offset to the
4652 % right of the right image.
4654 % o y_offset: amount, in pixels, by which the left image is offset to the
4655 % bottom of the right image.
4659 MagickExport Image *StereoImage(const Image *left_image,
4660 const Image *right_image,ExceptionInfo *exception)
4662 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4665 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4666 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4667 ExceptionInfo *exception)
4669 #define StereoImageTag "Stereo/Image"
4683 assert(left_image != (const Image *) NULL);
4684 assert(left_image->signature == MagickSignature);
4685 if (left_image->debug != MagickFalse)
4686 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4687 left_image->filename);
4688 assert(right_image != (const Image *) NULL);
4689 assert(right_image->signature == MagickSignature);
4690 assert(exception != (ExceptionInfo *) NULL);
4691 assert(exception->signature == MagickSignature);
4692 assert(right_image != (const Image *) NULL);
4694 if ((left_image->columns != right_image->columns) ||
4695 (left_image->rows != right_image->rows))
4696 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4698 Initialize stereo image attributes.
4700 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4701 MagickTrue,exception);
4702 if (stereo_image == (Image *) NULL)
4703 return((Image *) NULL);
4704 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4706 InheritException(exception,&stereo_image->exception);
4707 stereo_image=DestroyImage(stereo_image);
4708 return((Image *) NULL);
4711 Copy left image to red channel and right image to blue channel.
4713 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4715 register const PixelPacket
4722 register PixelPacket
4725 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4727 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4728 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4729 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4730 (r == (PixelPacket *) NULL))
4732 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4734 r->red=GetRedPixelComponent(p);
4737 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4742 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4744 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4749 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4750 stereo_image->rows);
4751 if (proceed == MagickFalse)
4755 return(stereo_image);
4759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4763 % S w i r l I m a g e %
4767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4769 % SwirlImage() swirls the pixels about the center of the image, where
4770 % degrees indicates the sweep of the arc through which each pixel is moved.
4771 % You get a more dramatic effect as the degrees move from 1 to 360.
4773 % The format of the SwirlImage method is:
4775 % Image *SwirlImage(const Image *image,double degrees,
4776 % ExceptionInfo *exception)
4778 % A description of each parameter follows:
4780 % o image: the image.
4782 % o degrees: Define the tightness of the swirling effect.
4784 % o exception: return any errors or warnings in this structure.
4787 MagickExport Image *SwirlImage(const Image *image,double degrees,
4788 ExceptionInfo *exception)
4790 #define SwirlImageTag "Swirl/Image"
4816 **restrict resample_filter;
4822 Initialize swirl image attributes.
4824 assert(image != (const Image *) NULL);
4825 assert(image->signature == MagickSignature);
4826 if (image->debug != MagickFalse)
4827 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4828 assert(exception != (ExceptionInfo *) NULL);
4829 assert(exception->signature == MagickSignature);
4830 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4831 if (swirl_image == (Image *) NULL)
4832 return((Image *) NULL);
4833 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4835 InheritException(exception,&swirl_image->exception);
4836 swirl_image=DestroyImage(swirl_image);
4837 return((Image *) NULL);
4839 if (swirl_image->background_color.opacity != OpaqueOpacity)
4840 swirl_image->matte=MagickTrue;
4842 Compute scaling factor.
4844 center.x=(double) image->columns/2.0;
4845 center.y=(double) image->rows/2.0;
4846 radius=MagickMax(center.x,center.y);
4849 if (image->columns > image->rows)
4850 scale.y=(double) image->columns/(double) image->rows;
4852 if (image->columns < image->rows)
4853 scale.x=(double) image->rows/(double) image->columns;
4854 degrees=(double) DegreesToRadians(degrees);
4860 GetMagickPixelPacket(swirl_image,&zero);
4861 resample_filter=AcquireResampleFilterThreadSet(image,
4862 UndefinedVirtualPixelMethod,MagickTrue,exception);
4863 image_view=AcquireCacheView(image);
4864 swirl_view=AcquireCacheView(swirl_image);
4865 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4866 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4868 for (y=0; y < (ssize_t) image->rows; y++)
4879 register IndexPacket
4880 *restrict swirl_indexes;
4886 register PixelPacket
4889 if (status == MagickFalse)
4891 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4893 if (q == (PixelPacket *) NULL)
4898 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4899 delta.y=scale.y*(double) (y-center.y);
4901 id=GetOpenMPThreadId();
4902 for (x=0; x < (ssize_t) image->columns; x++)
4905 Determine if the pixel is within an ellipse.
4907 delta.x=scale.x*(double) (x-center.x);
4908 distance=delta.x*delta.x+delta.y*delta.y;
4909 if (distance < (radius*radius))
4919 factor=1.0-sqrt((double) distance)/radius;
4920 sine=sin((double) (degrees*factor*factor));
4921 cosine=cos((double) (degrees*factor*factor));
4922 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4923 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4924 cosine*delta.y)/scale.y+center.y),&pixel);
4925 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4929 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4931 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4936 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4937 #pragma omp critical (MagickCore_SwirlImage)
4939 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4940 if (proceed == MagickFalse)
4944 swirl_view=DestroyCacheView(swirl_view);
4945 image_view=DestroyCacheView(image_view);
4946 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
4947 if (status == MagickFalse)
4948 swirl_image=DestroyImage(swirl_image);
4949 return(swirl_image);
4953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4957 % T i n t I m a g e %
4961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4963 % TintImage() applies a color vector to each pixel in the image. The length
4964 % of the vector is 0 for black and white and at its maximum for the midtones.
4965 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
4967 % The format of the TintImage method is:
4969 % Image *TintImage(const Image *image,const char *opacity,
4970 % const PixelPacket tint,ExceptionInfo *exception)
4972 % A description of each parameter follows:
4974 % o image: the image.
4976 % o opacity: A color value used for tinting.
4978 % o tint: A color value used for tinting.
4980 % o exception: return any errors or warnings in this structure.
4983 MagickExport Image *TintImage(const Image *image,const char *opacity,
4984 const PixelPacket tint,ExceptionInfo *exception)
4986 #define TintImageTag "Tint/Image"
5015 Allocate tint image.
5017 assert(image != (const Image *) NULL);
5018 assert(image->signature == MagickSignature);
5019 if (image->debug != MagickFalse)
5020 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5021 assert(exception != (ExceptionInfo *) NULL);
5022 assert(exception->signature == MagickSignature);
5023 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5024 if (tint_image == (Image *) NULL)
5025 return((Image *) NULL);
5026 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5028 InheritException(exception,&tint_image->exception);
5029 tint_image=DestroyImage(tint_image);
5030 return((Image *) NULL);
5032 if (opacity == (const char *) NULL)
5035 Determine RGB values of the color.
5037 flags=ParseGeometry(opacity,&geometry_info);
5038 pixel.red=geometry_info.rho;
5039 if ((flags & SigmaValue) != 0)
5040 pixel.green=geometry_info.sigma;
5042 pixel.green=pixel.red;
5043 if ((flags & XiValue) != 0)
5044 pixel.blue=geometry_info.xi;
5046 pixel.blue=pixel.red;
5047 if ((flags & PsiValue) != 0)
5048 pixel.opacity=geometry_info.psi;
5050 pixel.opacity=(MagickRealType) OpaqueOpacity;
5051 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5052 PixelIntensity(&tint));
5053 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5054 PixelIntensity(&tint));
5055 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5056 PixelIntensity(&tint));
5062 image_view=AcquireCacheView(image);
5063 tint_view=AcquireCacheView(tint_image);
5064 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5065 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5067 for (y=0; y < (ssize_t) image->rows; y++)
5069 register const PixelPacket
5075 register PixelPacket
5078 if (status == MagickFalse)
5080 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5081 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5083 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5088 for (x=0; x < (ssize_t) image->columns; x++)
5096 weight=QuantumScale*p->red-0.5;
5097 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5099 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5100 weight=QuantumScale*p->green-0.5;
5101 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5103 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5104 weight=QuantumScale*p->blue-0.5;
5105 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5107 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5108 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5112 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5114 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5119 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5120 #pragma omp critical (MagickCore_TintImage)
5122 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5123 if (proceed == MagickFalse)
5127 tint_view=DestroyCacheView(tint_view);
5128 image_view=DestroyCacheView(image_view);
5129 if (status == MagickFalse)
5130 tint_image=DestroyImage(tint_image);
5135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5139 % V i g n e t t e I m a g e %
5143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5145 % VignetteImage() softens the edges of the image in vignette style.
5147 % The format of the VignetteImage method is:
5149 % Image *VignetteImage(const Image *image,const double radius,
5150 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5152 % A description of each parameter follows:
5154 % o image: the image.
5156 % o radius: the radius of the pixel neighborhood.
5158 % o sigma: the standard deviation of the Gaussian, in pixels.
5160 % o x, y: Define the x and y ellipse offset.
5162 % o exception: return any errors or warnings in this structure.
5165 MagickExport Image *VignetteImage(const Image *image,const double radius,
5166 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5169 ellipse[MaxTextExtent];
5180 assert(image != (Image *) NULL);
5181 assert(image->signature == MagickSignature);
5182 if (image->debug != MagickFalse)
5183 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5184 assert(exception != (ExceptionInfo *) NULL);
5185 assert(exception->signature == MagickSignature);
5186 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5187 if (canvas_image == (Image *) NULL)
5188 return((Image *) NULL);
5189 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5191 InheritException(exception,&canvas_image->exception);
5192 canvas_image=DestroyImage(canvas_image);
5193 return((Image *) NULL);
5195 canvas_image->matte=MagickTrue;
5196 oval_image=CloneImage(canvas_image,canvas_image->columns,
5197 canvas_image->rows,MagickTrue,exception);
5198 if (oval_image == (Image *) NULL)
5200 canvas_image=DestroyImage(canvas_image);
5201 return((Image *) NULL);
5203 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5204 (void) SetImageBackgroundColor(oval_image);
5205 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5206 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5207 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5208 (void) FormatMagickString(ellipse,MaxTextExtent,
5209 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5210 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5211 draw_info->primitive=AcquireString(ellipse);
5212 (void) DrawImage(oval_image,draw_info);
5213 draw_info=DestroyDrawInfo(draw_info);
5214 blur_image=BlurImage(oval_image,radius,sigma,exception);
5215 oval_image=DestroyImage(oval_image);
5216 if (blur_image == (Image *) NULL)
5218 canvas_image=DestroyImage(canvas_image);
5219 return((Image *) NULL);
5221 blur_image->matte=MagickFalse;
5222 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5223 blur_image=DestroyImage(blur_image);
5224 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5225 canvas_image=DestroyImage(canvas_image);
5226 return(vignette_image);
5230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5234 % W a v e I m a g e %
5238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5240 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5241 % vertically assize_t a sine wave whose amplitude and wavelength is specified
5242 % by the given parameters.
5244 % The format of the WaveImage method is:
5246 % Image *WaveImage(const Image *image,const double amplitude,
5247 % const double wave_length,ExceptionInfo *exception)
5249 % A description of each parameter follows:
5251 % o image: the image.
5253 % o amplitude, wave_length: Define the amplitude and wave length of the
5256 % o exception: return any errors or warnings in this structure.
5259 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5260 const double wave_length,ExceptionInfo *exception)
5262 #define WaveImageTag "Wave/Image"
5286 **restrict resample_filter;
5292 Initialize wave image attributes.
5294 assert(image != (Image *) NULL);
5295 assert(image->signature == MagickSignature);
5296 if (image->debug != MagickFalse)
5297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5298 assert(exception != (ExceptionInfo *) NULL);
5299 assert(exception->signature == MagickSignature);
5300 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5301 fabs(amplitude)),MagickTrue,exception);
5302 if (wave_image == (Image *) NULL)
5303 return((Image *) NULL);
5304 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5306 InheritException(exception,&wave_image->exception);
5307 wave_image=DestroyImage(wave_image);
5308 return((Image *) NULL);
5310 if (wave_image->background_color.opacity != OpaqueOpacity)
5311 wave_image->matte=MagickTrue;
5315 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5317 if (sine_map == (MagickRealType *) NULL)
5319 wave_image=DestroyImage(wave_image);
5320 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5322 for (i=0; i < (ssize_t) wave_image->columns; i++)
5323 sine_map[i]=fabs(amplitude)+amplitude*sin((2*MagickPI*i)/wave_length);
5329 GetMagickPixelPacket(wave_image,&zero);
5330 resample_filter=AcquireResampleFilterThreadSet(image,
5331 BackgroundVirtualPixelMethod,MagickTrue,exception);
5332 wave_view=AcquireCacheView(wave_image);
5333 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5334 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5336 for (y=0; y < (ssize_t) wave_image->rows; y++)
5341 register IndexPacket
5348 register PixelPacket
5351 if (status == MagickFalse)
5353 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5355 if (q == (PixelPacket *) NULL)
5360 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5362 id=GetOpenMPThreadId();
5363 for (x=0; x < (ssize_t) wave_image->columns; x++)
5365 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5366 sine_map[x]),&pixel);
5367 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5370 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5372 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5377 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5378 #pragma omp critical (MagickCore_WaveImage)
5380 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5381 if (proceed == MagickFalse)
5385 wave_view=DestroyCacheView(wave_view);
5386 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5387 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5388 if (status == MagickFalse)
5389 wave_image=DestroyImage(wave_image);