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
101 #define ExponentialNotation 0xfd
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 + A c q u i r e F x I n f o %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % AcquireFxInfo() allocates the FxInfo structure.
144 % The format of the AcquireFxInfo method is:
146 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
147 % A description of each parameter follows:
149 % o image: the image.
151 % o expression: the expression.
154 MagickExport FxInfo *AcquireFxInfo(const Image *image,const char *expression)
165 fx_info=(FxInfo *) AcquireAlignedMemory(1,sizeof(*fx_info));
166 if (fx_info == (FxInfo *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
169 fx_info->exception=AcquireExceptionInfo();
170 fx_info->images=image;
171 fx_info->matte=image->matte;
172 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
173 RelinquishMagickMemory);
174 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->resample_filter=(ResampleFilter **) AcquireQuantumMemory(
177 GetImageListLength(fx_info->images),sizeof(*fx_info->resample_filter));
178 if (fx_info->resample_filter == (ResampleFilter **) NULL)
179 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
180 for (i=0; i < (ssize_t) GetImageListLength(fx_info->images); i++)
182 fx_info->resample_filter[i]=AcquireResampleFilter(GetImageFromList(
183 fx_info->images,i),fx_info->exception);
184 SetResampleFilter(fx_info->resample_filter[i],PointFilter,1.0);
186 fx_info->random_info=AcquireRandomInfo();
187 fx_info->expression=ConstantString(expression);
188 fx_info->file=stderr;
189 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
190 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
191 (strstr(fx_info->expression,"e-") != (char *) NULL))
194 Convert scientific notation.
196 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
197 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
198 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
199 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
200 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
201 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
202 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
203 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
204 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
205 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
206 (void) SubstituteString(&fx_info->expression,"0e-","0**10^-");
207 (void) SubstituteString(&fx_info->expression,"1e-","1**10^-");
208 (void) SubstituteString(&fx_info->expression,"2e-","2**10^-");
209 (void) SubstituteString(&fx_info->expression,"3e-","3**10^-");
210 (void) SubstituteString(&fx_info->expression,"4e-","4**10^-");
211 (void) SubstituteString(&fx_info->expression,"5e-","5**10^-");
212 (void) SubstituteString(&fx_info->expression,"6e-","6**10^-");
213 (void) SubstituteString(&fx_info->expression,"7e-","7**10^-");
214 (void) SubstituteString(&fx_info->expression,"8e-","8**10^-");
215 (void) SubstituteString(&fx_info->expression,"9e-","9**10^-");
218 Convert complex to simple operators.
221 *fx_op=(char) LeftShiftOperator;
222 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
223 *fx_op=(char) RightShiftOperator;
224 (void) SubstituteString(&fx_info->expression,">>",fx_op);
225 *fx_op=(char) LessThanEqualOperator;
226 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
227 *fx_op=(char) GreaterThanEqualOperator;
228 (void) SubstituteString(&fx_info->expression,">=",fx_op);
229 *fx_op=(char) EqualOperator;
230 (void) SubstituteString(&fx_info->expression,"==",fx_op);
231 *fx_op=(char) NotEqualOperator;
232 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
233 *fx_op=(char) LogicalAndOperator;
234 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
235 *fx_op=(char) LogicalOrOperator;
236 (void) SubstituteString(&fx_info->expression,"||",fx_op);
237 *fx_op=(char) ExponentialNotation;
238 (void) SubstituteString(&fx_info->expression,"**",fx_op);
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % A d d N o i s e I m a g e %
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % AddNoiseImage() adds random noise to the image.
255 % The format of the AddNoiseImage method is:
257 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
258 % ExceptionInfo *exception)
259 % Image *AddNoiseImageChannel(const Image *image,const ChannelType channel,
260 % const NoiseType noise_type,ExceptionInfo *exception)
262 % A description of each parameter follows:
264 % o image: the image.
266 % o channel: the channel type.
268 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
269 % Impulse, Laplacian, or Poisson.
271 % o exception: return any errors or warnings in this structure.
274 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
275 ExceptionInfo *exception)
280 noise_image=AddNoiseImageChannel(image,DefaultChannels,noise_type,exception);
284 MagickExport Image *AddNoiseImageChannel(const Image *image,
285 const ChannelType channel,const NoiseType noise_type,ExceptionInfo *exception)
287 #define AddNoiseImageTag "AddNoise/Image"
309 **restrict random_info;
315 Initialize noise image attributes.
317 assert(image != (const Image *) NULL);
318 assert(image->signature == MagickSignature);
319 if (image->debug != MagickFalse)
320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
321 assert(exception != (ExceptionInfo *) NULL);
322 assert(exception->signature == MagickSignature);
323 noise_image=CloneImage(image,0,0,MagickTrue,exception);
324 if (noise_image == (Image *) NULL)
325 return((Image *) NULL);
326 if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
328 InheritException(exception,&noise_image->exception);
329 noise_image=DestroyImage(noise_image);
330 return((Image *) NULL);
333 Add noise in each row.
336 option=GetImageArtifact(image,"attenuate");
337 if (option != (char *) NULL)
338 attenuate=StringToDouble(option);
341 random_info=AcquireRandomInfoThreadSet();
342 image_view=AcquireCacheView(image);
343 noise_view=AcquireCacheView(noise_image);
344 #if defined(MAGICKCORE_OPENMP_SUPPORT)
345 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
347 for (y=0; y < (ssize_t) image->rows; y++)
355 register const IndexPacket
358 register const PixelPacket
362 *restrict noise_indexes;
370 if (status == MagickFalse)
372 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
373 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
375 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
380 indexes=GetCacheViewVirtualIndexQueue(image_view);
381 noise_indexes=GetCacheViewAuthenticIndexQueue(noise_view);
382 id=GetOpenMPThreadId();
383 for (x=0; x < (ssize_t) image->columns; x++)
385 if ((channel & RedChannel) != 0)
386 q->red=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
387 p->red,noise_type,attenuate));
388 if ((channel & GreenChannel) != 0)
389 q->green=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
390 p->green,noise_type,attenuate));
391 if ((channel & BlueChannel) != 0)
392 q->blue=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
393 p->blue,noise_type,attenuate));
394 if ((channel & OpacityChannel) != 0)
395 q->opacity=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
396 p->opacity,noise_type,attenuate));
397 if (((channel & IndexChannel) != 0) &&
398 (image->colorspace == CMYKColorspace))
399 noise_indexes[x]=(IndexPacket) ClampToQuantum(GenerateDifferentialNoise(
400 random_info[id],indexes[x],noise_type,attenuate));
404 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
405 if (sync == MagickFalse)
407 if (image->progress_monitor != (MagickProgressMonitor) NULL)
412 #if defined(MAGICKCORE_OPENMP_SUPPORT)
413 #pragma omp critical (MagickCore_AddNoiseImage)
415 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
417 if (proceed == MagickFalse)
421 noise_view=DestroyCacheView(noise_view);
422 image_view=DestroyCacheView(image_view);
423 random_info=DestroyRandomInfoThreadSet(random_info);
424 if (status == MagickFalse)
425 noise_image=DestroyImage(noise_image);
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 % B l u e S h i f t I m a g e %
438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 % BlueShiftImage() mutes the colors of the image to simulate a scene at
441 % nighttime in the moonlight.
443 % The format of the BlueShiftImage method is:
445 % Image *BlueShiftImage(const Image *image,const double factor,
446 % ExceptionInfo *exception)
448 % A description of each parameter follows:
450 % o image: the image.
452 % o factor: the shift factor.
454 % o exception: return any errors or warnings in this structure.
457 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
458 ExceptionInfo *exception)
460 #define BlueShiftImageTag "BlueShift/Image"
479 Allocate blue shift image.
481 assert(image != (const Image *) NULL);
482 assert(image->signature == MagickSignature);
483 if (image->debug != MagickFalse)
484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
485 assert(exception != (ExceptionInfo *) NULL);
486 assert(exception->signature == MagickSignature);
487 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
489 if (shift_image == (Image *) NULL)
490 return((Image *) NULL);
491 if (SetImageStorageClass(shift_image,DirectClass) == MagickFalse)
493 InheritException(exception,&shift_image->exception);
494 shift_image=DestroyImage(shift_image);
495 return((Image *) NULL);
498 Blue-shift DirectClass image.
502 image_view=AcquireCacheView(image);
503 shift_view=AcquireCacheView(shift_image);
504 #if defined(MAGICKCORE_OPENMP_SUPPORT)
505 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
507 for (y=0; y < (ssize_t) image->rows; y++)
518 register const PixelPacket
527 if (status == MagickFalse)
529 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
530 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
532 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
537 for (x=0; x < (ssize_t) image->columns; x++)
539 quantum=GetRedPixelComponent(p);
540 if (p->green < quantum)
541 quantum=GetGreenPixelComponent(p);
542 if (p->blue < quantum)
543 quantum=GetBluePixelComponent(p);
544 pixel.red=0.5*(p->red+factor*quantum);
545 pixel.green=0.5*(p->green+factor*quantum);
546 pixel.blue=0.5*(p->blue+factor*quantum);
547 quantum=GetRedPixelComponent(p);
548 if (p->green > quantum)
549 quantum=GetGreenPixelComponent(p);
550 if (p->blue > quantum)
551 quantum=GetBluePixelComponent(p);
552 pixel.red=0.5*(pixel.red+factor*quantum);
553 pixel.green=0.5*(pixel.green+factor*quantum);
554 pixel.blue=0.5*(pixel.blue+factor*quantum);
555 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
556 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
557 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
561 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
562 if (sync == MagickFalse)
564 if (image->progress_monitor != (MagickProgressMonitor) NULL)
569 #if defined(MAGICKCORE_OPENMP_SUPPORT)
570 #pragma omp critical (MagickCore_BlueShiftImage)
572 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
574 if (proceed == MagickFalse)
578 image_view=DestroyCacheView(image_view);
579 shift_view=DestroyCacheView(shift_view);
580 if (status == MagickFalse)
581 shift_image=DestroyImage(shift_image);
586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590 % C h a r c o a l I m a g e %
594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
596 % CharcoalImage() creates a new image that is a copy of an existing one with
597 % the edge highlighted. It allocates the memory necessary for the new Image
598 % structure and returns a pointer to the new image.
600 % The format of the CharcoalImage method is:
602 % Image *CharcoalImage(const Image *image,const double radius,
603 % const double sigma,ExceptionInfo *exception)
605 % A description of each parameter follows:
607 % o image: the image.
609 % o radius: the radius of the pixel neighborhood.
611 % o sigma: the standard deviation of the Gaussian, in pixels.
613 % o exception: return any errors or warnings in this structure.
616 MagickExport Image *CharcoalImage(const Image *image,const double radius,
617 const double sigma,ExceptionInfo *exception)
624 assert(image != (Image *) NULL);
625 assert(image->signature == MagickSignature);
626 if (image->debug != MagickFalse)
627 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
628 assert(exception != (ExceptionInfo *) NULL);
629 assert(exception->signature == MagickSignature);
630 clone_image=CloneImage(image,0,0,MagickTrue,exception);
631 if (clone_image == (Image *) NULL)
632 return((Image *) NULL);
633 (void) SetImageType(clone_image,GrayscaleType);
634 edge_image=EdgeImage(clone_image,radius,exception);
635 clone_image=DestroyImage(clone_image);
636 if (edge_image == (Image *) NULL)
637 return((Image *) NULL);
638 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
639 edge_image=DestroyImage(edge_image);
640 if (charcoal_image == (Image *) NULL)
641 return((Image *) NULL);
642 (void) NormalizeImage(charcoal_image);
643 (void) NegateImage(charcoal_image,MagickFalse);
644 (void) SetImageType(charcoal_image,GrayscaleType);
645 return(charcoal_image);
649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 % C o l o r i z e I m a g e %
657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 % ColorizeImage() blends the fill color with each pixel in the image.
660 % A percentage blend is specified with opacity. Control the application
661 % of different color components by specifying a different percentage for
662 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
664 % The format of the ColorizeImage method is:
666 % Image *ColorizeImage(const Image *image,const char *opacity,
667 % const PixelPacket colorize,ExceptionInfo *exception)
669 % A description of each parameter follows:
671 % o image: the image.
673 % o opacity: A character string indicating the level of opacity as a
676 % o colorize: A color value.
678 % o exception: return any errors or warnings in this structure.
681 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
682 const PixelPacket colorize,ExceptionInfo *exception)
684 #define ColorizeImageTag "Colorize/Image"
712 Allocate colorized image.
714 assert(image != (const Image *) NULL);
715 assert(image->signature == MagickSignature);
716 if (image->debug != MagickFalse)
717 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
718 assert(exception != (ExceptionInfo *) NULL);
719 assert(exception->signature == MagickSignature);
720 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
722 if (colorize_image == (Image *) NULL)
723 return((Image *) NULL);
724 if (SetImageStorageClass(colorize_image,DirectClass) == MagickFalse)
726 InheritException(exception,&colorize_image->exception);
727 colorize_image=DestroyImage(colorize_image);
728 return((Image *) NULL);
730 if (opacity == (const char *) NULL)
731 return(colorize_image);
733 Determine RGB values of the pen color.
735 flags=ParseGeometry(opacity,&geometry_info);
736 pixel.red=geometry_info.rho;
737 pixel.green=geometry_info.rho;
738 pixel.blue=geometry_info.rho;
739 pixel.opacity=(MagickRealType) OpaqueOpacity;
740 if ((flags & SigmaValue) != 0)
741 pixel.green=geometry_info.sigma;
742 if ((flags & XiValue) != 0)
743 pixel.blue=geometry_info.xi;
744 if ((flags & PsiValue) != 0)
745 pixel.opacity=geometry_info.psi;
747 Colorize DirectClass image.
751 image_view=AcquireCacheView(image);
752 colorize_view=AcquireCacheView(colorize_image);
753 #if defined(MAGICKCORE_OPENMP_SUPPORT)
754 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
756 for (y=0; y < (ssize_t) image->rows; y++)
761 register const PixelPacket
770 if (status == MagickFalse)
772 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
773 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
775 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
780 for (x=0; x < (ssize_t) image->columns; x++)
782 q->red=(Quantum) ((p->red*(100.0-pixel.red)+
783 colorize.red*pixel.red)/100.0);
784 q->green=(Quantum) ((p->green*(100.0-pixel.green)+
785 colorize.green*pixel.green)/100.0);
786 q->blue=(Quantum) ((p->blue*(100.0-pixel.blue)+
787 colorize.blue*pixel.blue)/100.0);
788 q->opacity=(Quantum) ((p->opacity*(100.0-pixel.opacity)+
789 colorize.opacity*pixel.opacity)/100.0);
793 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
794 if (sync == MagickFalse)
796 if (image->progress_monitor != (MagickProgressMonitor) NULL)
801 #if defined(MAGICKCORE_OPENMP_SUPPORT)
802 #pragma omp critical (MagickCore_ColorizeImage)
804 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
805 if (proceed == MagickFalse)
809 image_view=DestroyCacheView(image_view);
810 colorize_view=DestroyCacheView(colorize_view);
811 if (status == MagickFalse)
812 colorize_image=DestroyImage(colorize_image);
813 return(colorize_image);
817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 % C o l o r M a t r i x I m a g e %
825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
827 % ColorMatrixImage() applies color transformation to an image. This method
828 % permits saturation changes, hue rotation, luminance to alpha, and various
829 % other effects. Although variable-sized transformation matrices can be used,
830 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
831 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
832 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
833 % and offsets are normalized (divide Flash offset by 255).
835 % The format of the ColorMatrixImage method is:
837 % Image *ColorMatrixImage(const Image *image,
838 % const KernelInfo *color_matrix,ExceptionInfo *exception)
840 % A description of each parameter follows:
842 % o image: the image.
844 % o color_matrix: the color matrix.
846 % o exception: return any errors or warnings in this structure.
849 MagickExport Image *ColorMatrixImage(const Image *image,
850 const KernelInfo *color_matrix,ExceptionInfo *exception)
852 #define ColorMatrixImageTag "ColorMatrix/Image"
861 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
862 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
863 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
864 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
865 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
866 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
889 assert(image != (Image *) NULL);
890 assert(image->signature == MagickSignature);
891 if (image->debug != MagickFalse)
892 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
893 assert(exception != (ExceptionInfo *) NULL);
894 assert(exception->signature == MagickSignature);
896 for (v=0; v < (ssize_t) color_matrix->height; v++)
897 for (u=0; u < (ssize_t) color_matrix->width; u++)
899 if ((v < 6) && (u < 6))
900 ColorMatrix[v][u]=color_matrix->values[i];
904 Initialize color image.
906 color_image=CloneImage(image,0,0,MagickTrue,exception);
907 if (color_image == (Image *) NULL)
908 return((Image *) NULL);
909 if (SetImageStorageClass(color_image,DirectClass) == MagickFalse)
911 InheritException(exception,&color_image->exception);
912 color_image=DestroyImage(color_image);
913 return((Image *) NULL);
915 if (image->debug != MagickFalse)
918 format[MaxTextExtent],
921 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
922 " ColorMatrix image with color matrix:");
923 message=AcquireString("");
924 for (v=0; v < 6; v++)
927 (void) FormatMagickString(format,MaxTextExtent,"%.20g: ",(double) v);
928 (void) ConcatenateString(&message,format);
929 for (u=0; u < 6; u++)
931 (void) FormatMagickString(format,MaxTextExtent,"%+f ",
933 (void) ConcatenateString(&message,format);
935 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
937 message=DestroyString(message);
944 image_view=AcquireCacheView(image);
945 color_view=AcquireCacheView(color_image);
946 #if defined(MAGICKCORE_OPENMP_SUPPORT)
947 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
949 for (y=0; y < (ssize_t) image->rows; y++)
954 register const IndexPacket
957 register const PixelPacket
964 *restrict color_indexes;
969 if (status == MagickFalse)
971 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
972 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
974 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
979 indexes=GetCacheViewVirtualIndexQueue(image_view);
980 color_indexes=GetCacheViewAuthenticIndexQueue(color_view);
981 for (x=0; x < (ssize_t) image->columns; x++)
989 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
990 for (v=0; v < (ssize_t) height; v++)
992 pixel=ColorMatrix[v][0]*p->red+ColorMatrix[v][1]*p->green+
993 ColorMatrix[v][2]*p->blue;
994 if (image->matte != MagickFalse)
995 pixel+=ColorMatrix[v][3]*(QuantumRange-p->opacity);
996 if (image->colorspace == CMYKColorspace)
997 pixel+=ColorMatrix[v][4]*indexes[x];
998 pixel+=QuantumRange*ColorMatrix[v][5];
1001 case 0: q->red=ClampToQuantum(pixel); break;
1002 case 1: q->green=ClampToQuantum(pixel); break;
1003 case 2: q->blue=ClampToQuantum(pixel); break;
1006 if (image->matte != MagickFalse)
1007 q->opacity=ClampToQuantum(QuantumRange-pixel);
1012 if (image->colorspace == CMYKColorspace)
1013 color_indexes[x]=ClampToQuantum(pixel);
1021 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1023 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1028 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1029 #pragma omp critical (MagickCore_ColorMatrixImage)
1031 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1033 if (proceed == MagickFalse)
1037 color_view=DestroyCacheView(color_view);
1038 image_view=DestroyCacheView(image_view);
1039 if (status == MagickFalse)
1040 color_image=DestroyImage(color_image);
1041 return(color_image);
1045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049 + D e s t r o y F x I n f o %
1053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1055 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1057 % The format of the DestroyFxInfo method is:
1059 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1061 % A description of each parameter follows:
1063 % o fx_info: the fx info.
1066 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1071 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1072 fx_info->expression=DestroyString(fx_info->expression);
1073 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1074 fx_info->colors=DestroySplayTree(fx_info->colors);
1075 for (i=0; i < (ssize_t) GetImageListLength(fx_info->images); i++)
1076 fx_info->resample_filter[i]=DestroyResampleFilter(
1077 fx_info->resample_filter[i]);
1078 fx_info->resample_filter=(ResampleFilter **) RelinquishMagickMemory(
1079 fx_info->resample_filter);
1080 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1081 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090 + 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 %
1094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096 % FxEvaluateChannelExpression() evaluates an expression and returns the
1099 % The format of the FxEvaluateExpression method is:
1101 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1102 % const ChannelType channel,const ssize_t x,const ssize_t y,
1103 % MagickRealType *alpha,Exceptioninfo *exception)
1104 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1105 % MagickRealType *alpha,Exceptioninfo *exception)
1107 % A description of each parameter follows:
1109 % o fx_info: the fx info.
1111 % o channel: the channel.
1113 % o x,y: the pixel position.
1115 % o alpha: the result.
1117 % o exception: return any errors or warnings in this structure.
1121 static inline double MagickMax(const double x,const double y)
1128 static inline double MagickMin(const double x,const double y)
1135 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1136 ChannelType channel,const char *symbol,ExceptionInfo *exception)
1140 statistic[MaxTextExtent];
1148 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1150 switch (*++p) /* e.g. depth.r */
1152 case 'r': channel=RedChannel; break;
1153 case 'g': channel=GreenChannel; break;
1154 case 'b': channel=BlueChannel; break;
1155 case 'c': channel=CyanChannel; break;
1156 case 'm': channel=MagentaChannel; break;
1157 case 'y': channel=YellowChannel; break;
1158 case 'k': channel=BlackChannel; break;
1161 (void) FormatMagickString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1162 (double) channel,symbol);
1163 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1164 if (value != (const char *) NULL)
1165 return(QuantumScale*StringToDouble(value));
1166 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1167 if (LocaleNCompare(symbol,"depth",5) == 0)
1172 depth=GetImageChannelDepth(image,channel,exception);
1173 (void) FormatMagickString(statistic,MaxTextExtent,"%.20g",(double)
1176 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1182 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1184 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
1186 if (LocaleNCompare(symbol,"maxima",6) == 0)
1192 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1193 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
1195 if (LocaleNCompare(symbol,"mean",4) == 0)
1201 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1203 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
1205 if (LocaleNCompare(symbol,"minima",6) == 0)
1211 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1212 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
1214 if (LocaleNCompare(symbol,"skewness",8) == 0)
1220 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1222 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
1224 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1230 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1232 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
1233 standard_deviation);
1235 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1236 ConstantString(statistic));
1237 return(QuantumScale*StringToDouble(statistic));
1240 static MagickRealType
1241 FxEvaluateSubexpression(FxInfo *,const ChannelType,const ssize_t,
1242 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1244 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1245 const ssize_t x,const ssize_t y,const char *expression,
1246 ExceptionInfo *exception)
1252 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1253 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1256 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1257 const ssize_t x,const ssize_t y,const char *expression,
1258 ExceptionInfo *exception)
1264 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1265 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1268 static inline const char *FxSubexpression(const char *expression,
1269 ExceptionInfo *exception)
1278 subexpression=expression;
1279 while ((*subexpression != '\0') &&
1280 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1282 if (strchr("(",(int) *subexpression) != (char *) NULL)
1285 if (strchr(")",(int) *subexpression) != (char *) NULL)
1289 if (*subexpression == '\0')
1290 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1291 "UnbalancedParenthesis","`%s'",expression);
1292 return(subexpression);
1295 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1296 const ssize_t x,const ssize_t y,const char *expression,
1297 ExceptionInfo *exception)
1301 subexpression[MaxTextExtent],
1302 symbol[MaxTextExtent];
1331 i=GetImageIndexInList(fx_info->images);
1335 if (isalpha((int) *(p+1)) == 0)
1337 if (strchr("suv",(int) *p) != (char *) NULL)
1344 i=GetImageIndexInList(fx_info->images);
1347 case 'u': i=0; break;
1348 case 'v': i=1; break;
1355 for (p++; *p != '\0'; )
1369 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1371 i=(ssize_t) (alpha+0.5);
1377 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1384 for (p++; *p != '\0'; )
1398 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1409 for (p++; *p != '\0'; )
1423 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1433 length=GetImageListLength(fx_info->images);
1435 i+=(ssize_t) length;
1437 image=GetImageFromList(fx_info->images,i);
1438 if (image == (Image *) NULL)
1440 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1441 "NoSuchImage","`%s'",expression);
1444 (void) ResamplePixelColor(fx_info->resample_filter[i],point.x,point.y,&pixel);
1445 if ((strlen(p) > 2) &&
1446 (LocaleCompare(p,"intensity") != 0) &&
1447 (LocaleCompare(p,"luminance") != 0) &&
1448 (LocaleCompare(p,"hue") != 0) &&
1449 (LocaleCompare(p,"saturation") != 0) &&
1450 (LocaleCompare(p,"lightness") != 0))
1453 name[MaxTextExtent];
1455 (void) CopyMagickString(name,p,MaxTextExtent);
1456 for (q=name+(strlen(name)-1); q > name; q--)
1466 if ((strlen(name) > 2) &&
1467 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1472 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1474 if (color != (MagickPixelPacket *) NULL)
1480 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1482 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1483 CloneMagickPixelPacket(&pixel));
1488 (void) CopyMagickString(symbol,p,MaxTextExtent);
1489 StripString(symbol);
1490 if (*symbol == '\0')
1494 case RedChannel: return(QuantumScale*pixel.red);
1495 case GreenChannel: return(QuantumScale*pixel.green);
1496 case BlueChannel: return(QuantumScale*pixel.blue);
1497 case OpacityChannel:
1499 if (pixel.matte == MagickFalse)
1501 fx_info->matte=MagickFalse;
1504 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1508 if (image->colorspace != CMYKColorspace)
1510 (void) ThrowMagickException(exception,GetMagickModule(),
1511 OptionError,"ColorSeparatedImageRequired","`%s'",
1515 return(QuantumScale*pixel.index);
1520 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1521 "UnableToParseExpression","`%s'",p);
1529 if (LocaleCompare(symbol,"a") == 0)
1530 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1536 if (LocaleCompare(symbol,"b") == 0)
1537 return(QuantumScale*pixel.blue);
1543 if (LocaleNCompare(symbol,"channel",7) == 0)
1551 flags=ParseGeometry(symbol+7,&channel_info);
1552 if (image->colorspace == CMYKColorspace)
1557 if ((flags & RhoValue) == 0)
1559 return(channel_info.rho);
1561 case MagentaChannel:
1563 if ((flags & SigmaValue) == 0)
1565 return(channel_info.sigma);
1569 if ((flags & XiValue) == 0)
1571 return(channel_info.xi);
1575 if ((flags & PsiValue) == 0)
1577 return(channel_info.psi);
1579 case OpacityChannel:
1581 if ((flags & ChiValue) == 0)
1583 return(channel_info.chi);
1592 if ((flags & RhoValue) == 0)
1594 return(channel_info.rho);
1598 if ((flags & SigmaValue) == 0)
1600 return(channel_info.sigma);
1604 if ((flags & XiValue) == 0)
1606 return(channel_info.xi);
1608 case OpacityChannel:
1610 if ((flags & PsiValue) == 0)
1612 return(channel_info.psi);
1616 if ((flags & ChiValue) == 0)
1618 return(channel_info.chi);
1625 if (LocaleCompare(symbol,"c") == 0)
1626 return(QuantumScale*pixel.red);
1632 if (LocaleNCompare(symbol,"depth",5) == 0)
1633 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1639 if (LocaleCompare(symbol,"g") == 0)
1640 return(QuantumScale*pixel.green);
1646 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1647 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1648 if (LocaleCompare(symbol,"k") == 0)
1650 if (image->colorspace != CMYKColorspace)
1652 (void) ThrowMagickException(exception,GetMagickModule(),
1653 OptionError,"ColorSeparatedImageRequired","`%s'",
1657 return(QuantumScale*pixel.index);
1664 if (LocaleCompare(symbol,"h") == 0)
1665 return((MagickRealType) image->rows);
1666 if (LocaleCompare(symbol,"hue") == 0)
1673 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1674 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1682 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1683 (LocaleCompare(symbol,"image.minima") == 0) ||
1684 (LocaleCompare(symbol,"image.maxima") == 0) ||
1685 (LocaleCompare(symbol,"image.mean") == 0) ||
1686 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1687 (LocaleCompare(symbol,"image.skewness") == 0) ||
1688 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1689 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1690 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1691 return(image->x_resolution);
1692 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1693 return(image->y_resolution);
1694 if (LocaleCompare(symbol,"intensity") == 0)
1695 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1696 if (LocaleCompare(symbol,"i") == 0)
1697 return((MagickRealType) x);
1703 if (LocaleCompare(symbol,"j") == 0)
1704 return((MagickRealType) y);
1710 if (LocaleCompare(symbol,"lightness") == 0)
1717 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1718 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1721 if (LocaleCompare(symbol,"luminance") == 0)
1726 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1727 return(QuantumScale*luminence);
1734 if (LocaleNCompare(symbol,"maxima",6) == 0)
1735 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1736 if (LocaleNCompare(symbol,"mean",4) == 0)
1737 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1738 if (LocaleNCompare(symbol,"minima",6) == 0)
1739 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1740 if (LocaleCompare(symbol,"m") == 0)
1741 return(QuantumScale*pixel.blue);
1747 if (LocaleCompare(symbol,"n") == 0)
1748 return((MagickRealType) GetImageListLength(fx_info->images));
1754 if (LocaleCompare(symbol,"o") == 0)
1755 return(QuantumScale*pixel.opacity);
1761 if (LocaleCompare(symbol,"page.height") == 0)
1762 return((MagickRealType) image->page.height);
1763 if (LocaleCompare(symbol,"page.width") == 0)
1764 return((MagickRealType) image->page.width);
1765 if (LocaleCompare(symbol,"page.x") == 0)
1766 return((MagickRealType) image->page.x);
1767 if (LocaleCompare(symbol,"page.y") == 0)
1768 return((MagickRealType) image->page.y);
1774 if (LocaleCompare(symbol,"resolution.x") == 0)
1775 return(image->x_resolution);
1776 if (LocaleCompare(symbol,"resolution.y") == 0)
1777 return(image->y_resolution);
1778 if (LocaleCompare(symbol,"r") == 0)
1779 return(QuantumScale*pixel.red);
1785 if (LocaleCompare(symbol,"saturation") == 0)
1792 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1793 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1796 if (LocaleNCompare(symbol,"skewness",8) == 0)
1797 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1798 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1799 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1805 if (LocaleCompare(symbol,"t") == 0)
1806 return((MagickRealType) fx_info->images->scene);
1812 if (LocaleCompare(symbol,"w") == 0)
1813 return((MagickRealType) image->columns);
1819 if (LocaleCompare(symbol,"y") == 0)
1820 return(QuantumScale*pixel.green);
1826 if (LocaleCompare(symbol,"z") == 0)
1831 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1832 fx_info->exception);
1840 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1841 if (value != (const char *) NULL)
1842 return((MagickRealType) StringToDouble(value));
1843 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1844 "UnableToParseExpression","`%s'",symbol);
1848 static const char *FxOperatorPrecedence(const char *expression,
1849 ExceptionInfo *exception)
1853 UndefinedPrecedence,
1855 BitwiseComplementPrecedence,
1857 ExponentialNotationPrecedence,
1861 RelationalPrecedence,
1862 EquivalencyPrecedence,
1863 BitwiseAndPrecedence,
1864 BitwiseOrPrecedence,
1865 LogicalAndPrecedence,
1866 LogicalOrPrecedence,
1868 AssignmentPrecedence,
1888 subexpression=(const char *) NULL;
1889 target=NullPrecedence;
1890 while (*expression != '\0')
1892 precedence=UndefinedPrecedence;
1893 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1898 switch (*expression)
1903 if (LocaleNCompare(expression,"atan2",5) == 0)
1913 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1914 (LocaleNCompare(expression,"j1",2) == 0))
1923 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1930 if ((c == (int) '{') || (c == (int) '['))
1933 if ((c == (int) '}') || (c == (int) ']'))
1936 switch ((unsigned char) *expression)
1941 precedence=BitwiseComplementPrecedence;
1947 precedence=ExponentPrecedence;
1952 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1953 (strchr(")",c) != (char *) NULL))) &&
1954 (((islower((int) ((char) *expression)) != 0) ||
1955 (strchr("(",(int) *expression) != (char *) NULL)) ||
1956 ((isdigit((int) ((char) c)) == 0) &&
1957 (isdigit((int) ((char) *expression)) != 0))) &&
1958 (strchr("xy",(int) *expression) == (char *) NULL))
1959 precedence=MultiplyPrecedence;
1966 precedence=MultiplyPrecedence;
1972 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1974 precedence=AdditionPrecedence;
1977 case LeftShiftOperator:
1978 case RightShiftOperator:
1980 precedence=ShiftPrecedence;
1984 case LessThanEqualOperator:
1985 case GreaterThanEqualOperator:
1988 precedence=RelationalPrecedence;
1992 case NotEqualOperator:
1994 precedence=EquivalencyPrecedence;
1999 precedence=BitwiseAndPrecedence;
2004 precedence=BitwiseOrPrecedence;
2007 case LogicalAndOperator:
2009 precedence=LogicalAndPrecedence;
2012 case LogicalOrOperator:
2014 precedence=LogicalOrPrecedence;
2017 case ExponentialNotation:
2019 precedence=ExponentialNotationPrecedence;
2025 precedence=TernaryPrecedence;
2030 precedence=AssignmentPrecedence;
2035 precedence=CommaPrecedence;
2040 precedence=SeparatorPrecedence;
2044 if ((precedence == BitwiseComplementPrecedence) ||
2045 (precedence == TernaryPrecedence) ||
2046 (precedence == AssignmentPrecedence))
2048 if (precedence > target)
2051 Right-to-left associativity.
2054 subexpression=expression;
2058 if (precedence >= target)
2061 Left-to-right associativity.
2064 subexpression=expression;
2066 if (strchr("(",(int) *expression) != (char *) NULL)
2067 expression=FxSubexpression(expression,exception);
2068 c=(int) (*expression++);
2070 return(subexpression);
2073 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2074 const ChannelType channel,const ssize_t x,const ssize_t y,
2075 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2079 subexpression[MaxTextExtent];
2089 if (exception->severity != UndefinedException)
2091 while (isspace((int) *expression) != 0)
2093 if (*expression == '\0')
2095 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2096 "MissingExpression","`%s'",expression);
2099 *subexpression='\0';
2100 p=FxOperatorPrecedence(expression,exception);
2101 if (p != (const char *) NULL)
2103 (void) CopyMagickString(subexpression,expression,(size_t)
2105 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2107 switch ((unsigned char) *p)
2111 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2112 *beta=(MagickRealType) (~(size_t) *beta);
2117 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2118 return(*beta == 0.0 ? 1.0 : 0.0);
2122 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2123 channel,x,y,++p,beta,exception));
2127 case ExponentialNotation:
2129 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2130 return(alpha*(*beta));
2134 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2137 if (exception->severity == UndefinedException)
2138 (void) ThrowMagickException(exception,GetMagickModule(),
2139 OptionError,"DivideByZero","`%s'",expression);
2142 return(alpha/(*beta));
2146 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2147 *beta=fabs(floor(((double) *beta)+0.5));
2150 (void) ThrowMagickException(exception,GetMagickModule(),
2151 OptionError,"DivideByZero","`%s'",expression);
2154 return(fmod((double) alpha,(double) *beta));
2158 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2159 return(alpha+(*beta));
2163 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2164 return(alpha-(*beta));
2166 case LeftShiftOperator:
2168 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2169 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2173 case RightShiftOperator:
2175 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2176 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2182 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2183 return(alpha < *beta ? 1.0 : 0.0);
2185 case LessThanEqualOperator:
2187 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2188 return(alpha <= *beta ? 1.0 : 0.0);
2192 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2193 return(alpha > *beta ? 1.0 : 0.0);
2195 case GreaterThanEqualOperator:
2197 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2198 return(alpha >= *beta ? 1.0 : 0.0);
2202 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2203 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2205 case NotEqualOperator:
2207 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2208 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2212 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2213 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2219 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2220 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2224 case LogicalAndOperator:
2226 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2227 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2230 case LogicalOrOperator:
2232 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2233 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2241 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2243 p=StringToken(":",&q);
2244 if (q == (char *) NULL)
2246 (void) ThrowMagickException(exception,GetMagickModule(),
2247 OptionError,"UnableToParseExpression","`%s'",subexpression);
2250 if (fabs((double) alpha) > MagickEpsilon)
2251 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2253 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2259 numeric[MaxTextExtent];
2262 while (isalpha((int) ((unsigned char) *q)) != 0)
2266 (void) ThrowMagickException(exception,GetMagickModule(),
2267 OptionError,"UnableToParseExpression","`%s'",subexpression);
2270 ClearMagickException(exception);
2271 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2272 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2274 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2275 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2276 subexpression),ConstantString(numeric));
2281 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2286 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2291 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2297 if (strchr("(",(int) *expression) != (char *) NULL)
2299 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2300 subexpression[strlen(subexpression)-1]='\0';
2301 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2305 switch (*expression)
2309 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2315 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2321 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2323 return((MagickRealType) (~(size_t) (gamma+0.5)));
2328 if (LocaleNCompare(expression,"abs",3) == 0)
2330 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2332 return((MagickRealType) fabs((double) alpha));
2334 if (LocaleNCompare(expression,"acos",4) == 0)
2336 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2338 return((MagickRealType) acos((double) alpha));
2340 #if defined(MAGICKCORE_HAVE_J1)
2341 if (LocaleNCompare(expression,"airy",4) == 0)
2343 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2347 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2348 return(gamma*gamma);
2351 if (LocaleNCompare(expression,"asin",4) == 0)
2353 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2355 return((MagickRealType) asin((double) alpha));
2357 if (LocaleNCompare(expression,"alt",3) == 0)
2359 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2361 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2363 if (LocaleNCompare(expression,"atan2",5) == 0)
2365 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2367 return((MagickRealType) atan2((double) alpha,(double) *beta));
2369 if (LocaleNCompare(expression,"atan",4) == 0)
2371 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2373 return((MagickRealType) atan((double) alpha));
2375 if (LocaleCompare(expression,"a") == 0)
2376 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2382 if (LocaleCompare(expression,"b") == 0)
2383 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2389 if (LocaleNCompare(expression,"ceil",4) == 0)
2391 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2393 return((MagickRealType) ceil((double) alpha));
2395 if (LocaleNCompare(expression,"cosh",4) == 0)
2397 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2399 return((MagickRealType) cosh((double) alpha));
2401 if (LocaleNCompare(expression,"cos",3) == 0)
2403 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2405 return((MagickRealType) cos((double) alpha));
2407 if (LocaleCompare(expression,"c") == 0)
2408 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2414 if (LocaleNCompare(expression,"debug",5) == 0)
2419 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2421 if (fx_info->images->colorspace == CMYKColorspace)
2424 case CyanChannel: type="cyan"; break;
2425 case MagentaChannel: type="magenta"; break;
2426 case YellowChannel: type="yellow"; break;
2427 case OpacityChannel: type="opacity"; break;
2428 case BlackChannel: type="black"; break;
2429 default: type="unknown"; break;
2434 case RedChannel: type="red"; break;
2435 case GreenChannel: type="green"; break;
2436 case BlueChannel: type="blue"; break;
2437 case OpacityChannel: type="opacity"; break;
2438 default: type="unknown"; break;
2440 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2441 if (strlen(subexpression) > 1)
2442 subexpression[strlen(subexpression)-1]='\0';
2443 if (fx_info->file != (FILE *) NULL)
2444 (void) fprintf(fx_info->file,"%s[%.20g,%.20g].%s: %s=%.*g\n",
2445 fx_info->images->filename,(double) x,(double) y,type,
2446 subexpression,GetMagickPrecision(),(double) alpha);
2454 if (LocaleCompare(expression,"epsilon") == 0)
2455 return((MagickRealType) MagickEpsilon);
2456 if (LocaleNCompare(expression,"exp",3) == 0)
2458 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2460 return((MagickRealType) exp((double) alpha));
2462 if (LocaleCompare(expression,"e") == 0)
2463 return((MagickRealType) 2.7182818284590452354);
2469 if (LocaleNCompare(expression,"floor",5) == 0)
2471 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2473 return((MagickRealType) floor((double) alpha));
2480 if (LocaleCompare(expression,"g") == 0)
2481 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2487 if (LocaleCompare(expression,"h") == 0)
2488 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2489 if (LocaleCompare(expression,"hue") == 0)
2490 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2491 if (LocaleNCompare(expression,"hypot",5) == 0)
2493 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2495 return((MagickRealType) hypot((double) alpha,(double) *beta));
2502 if (LocaleCompare(expression,"k") == 0)
2503 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2509 if (LocaleCompare(expression,"intensity") == 0)
2510 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2511 if (LocaleNCompare(expression,"int",3) == 0)
2513 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2515 return((MagickRealType) floor(alpha));
2517 if (LocaleCompare(expression,"i") == 0)
2518 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2524 if (LocaleCompare(expression,"j") == 0)
2525 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2526 #if defined(MAGICKCORE_HAVE_J0)
2527 if (LocaleNCompare(expression,"j0",2) == 0)
2529 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2531 return((MagickRealType) j0((double) alpha));
2534 #if defined(MAGICKCORE_HAVE_J1)
2535 if (LocaleNCompare(expression,"j1",2) == 0)
2537 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2539 return((MagickRealType) j1((double) alpha));
2542 #if defined(MAGICKCORE_HAVE_J1)
2543 if (LocaleNCompare(expression,"jinc",4) == 0)
2545 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2549 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2559 if (LocaleNCompare(expression,"ln",2) == 0)
2561 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2563 return((MagickRealType) log((double) alpha));
2565 if (LocaleNCompare(expression,"logtwo",6) == 0)
2567 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2569 return((MagickRealType) log10((double) alpha))/log10(2.0);
2571 if (LocaleNCompare(expression,"log",3) == 0)
2573 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2575 return((MagickRealType) log10((double) alpha));
2577 if (LocaleCompare(expression,"lightness") == 0)
2578 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2584 if (LocaleCompare(expression,"MaxRGB") == 0)
2585 return((MagickRealType) QuantumRange);
2586 if (LocaleNCompare(expression,"maxima",6) == 0)
2588 if (LocaleNCompare(expression,"max",3) == 0)
2589 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2590 if (LocaleNCompare(expression,"minima",6) == 0)
2592 if (LocaleNCompare(expression,"min",3) == 0)
2593 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2594 if (LocaleNCompare(expression,"mod",3) == 0)
2596 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2598 return((MagickRealType) fmod((double) alpha,(double) *beta));
2600 if (LocaleCompare(expression,"m") == 0)
2601 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2607 if (LocaleCompare(expression,"n") == 0)
2608 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2614 if (LocaleCompare(expression,"Opaque") == 0)
2616 if (LocaleCompare(expression,"o") == 0)
2617 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2623 if (LocaleCompare(expression,"pi") == 0)
2624 return((MagickRealType) MagickPI);
2625 if (LocaleNCompare(expression,"pow",3) == 0)
2627 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2629 return((MagickRealType) pow((double) alpha,(double) *beta));
2631 if (LocaleCompare(expression,"p") == 0)
2632 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2638 if (LocaleCompare(expression,"QuantumRange") == 0)
2639 return((MagickRealType) QuantumRange);
2640 if (LocaleCompare(expression,"QuantumScale") == 0)
2641 return((MagickRealType) QuantumScale);
2647 if (LocaleNCompare(expression,"rand",4) == 0)
2648 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2649 if (LocaleNCompare(expression,"round",5) == 0)
2651 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2653 return((MagickRealType) floor((double) alpha+0.5));
2655 if (LocaleCompare(expression,"r") == 0)
2656 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2662 if (LocaleCompare(expression,"saturation") == 0)
2663 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2664 if (LocaleNCompare(expression,"sign",4) == 0)
2666 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2668 return(alpha < 0.0 ? -1.0 : 1.0);
2670 if (LocaleNCompare(expression,"sinc",4) == 0)
2672 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2676 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2680 if (LocaleNCompare(expression,"sinh",4) == 0)
2682 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2684 return((MagickRealType) sinh((double) alpha));
2686 if (LocaleNCompare(expression,"sin",3) == 0)
2688 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2690 return((MagickRealType) sin((double) alpha));
2692 if (LocaleNCompare(expression,"sqrt",4) == 0)
2694 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2696 return((MagickRealType) sqrt((double) alpha));
2698 if (LocaleCompare(expression,"s") == 0)
2699 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2705 if (LocaleNCompare(expression,"tanh",4) == 0)
2707 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2709 return((MagickRealType) tanh((double) alpha));
2711 if (LocaleNCompare(expression,"tan",3) == 0)
2713 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2715 return((MagickRealType) tan((double) alpha));
2717 if (LocaleCompare(expression,"Transparent") == 0)
2719 if (LocaleNCompare(expression,"trunc",5) == 0)
2721 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2724 return((MagickRealType) floor((double) alpha));
2725 return((MagickRealType) ceil((double) alpha));
2727 if (LocaleCompare(expression,"t") == 0)
2728 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2734 if (LocaleCompare(expression,"u") == 0)
2735 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2741 if (LocaleCompare(expression,"v") == 0)
2742 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2748 if (LocaleCompare(expression,"w") == 0)
2749 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2755 if (LocaleCompare(expression,"y") == 0)
2756 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2762 if (LocaleCompare(expression,"z") == 0)
2763 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2769 q=(char *) expression;
2770 alpha=strtod(expression,&q);
2771 if (q == expression)
2772 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2776 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2777 MagickRealType *alpha,ExceptionInfo *exception)
2782 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2786 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2787 MagickRealType *alpha,ExceptionInfo *exception)
2796 fx_info->file=(FILE *) NULL;
2797 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2802 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2803 const ChannelType channel,const ssize_t x,const ssize_t y,
2804 MagickRealType *alpha,ExceptionInfo *exception)
2810 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2812 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2826 % FxImage() applies a mathematical expression to the specified image.
2828 % The format of the FxImage method is:
2830 % Image *FxImage(const Image *image,const char *expression,
2831 % ExceptionInfo *exception)
2832 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2833 % const char *expression,ExceptionInfo *exception)
2835 % A description of each parameter follows:
2837 % o image: the image.
2839 % o channel: the channel.
2841 % o expression: A mathematical expression.
2843 % o exception: return any errors or warnings in this structure.
2847 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2852 assert(fx_info != (FxInfo **) NULL);
2853 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2854 if (fx_info[i] != (FxInfo *) NULL)
2855 fx_info[i]=DestroyFxInfo(fx_info[i]);
2856 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2860 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2861 ExceptionInfo *exception)
2878 number_threads=GetOpenMPMaximumThreads();
2879 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2880 if (fx_info == (FxInfo **) NULL)
2881 return((FxInfo **) NULL);
2882 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2883 if (*expression != '@')
2884 fx_expression=ConstantString(expression);
2886 fx_expression=FileToString(expression+1,~0,exception);
2887 for (i=0; i < (ssize_t) number_threads; i++)
2889 fx_info[i]=AcquireFxInfo(image,fx_expression);
2890 if (fx_info[i] == (FxInfo *) NULL)
2891 return(DestroyFxThreadSet(fx_info));
2892 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2894 fx_expression=DestroyString(fx_expression);
2898 MagickExport Image *FxImage(const Image *image,const char *expression,
2899 ExceptionInfo *exception)
2904 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2908 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2909 const char *expression,ExceptionInfo *exception)
2911 #define FxImageTag "Fx/Image"
2934 assert(image != (Image *) NULL);
2935 assert(image->signature == MagickSignature);
2936 if (image->debug != MagickFalse)
2937 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2938 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2939 if (fx_image == (Image *) NULL)
2940 return((Image *) NULL);
2941 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2943 InheritException(exception,&fx_image->exception);
2944 fx_image=DestroyImage(fx_image);
2945 return((Image *) NULL);
2947 fx_info=AcquireFxThreadSet(image,expression,exception);
2948 if (fx_info == (FxInfo **) NULL)
2950 fx_image=DestroyImage(fx_image);
2951 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2953 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2954 if (status == MagickFalse)
2956 fx_image=DestroyImage(fx_image);
2957 fx_info=DestroyFxThreadSet(fx_info);
2958 return((Image *) NULL);
2965 fx_view=AcquireCacheView(fx_image);
2966 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2967 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2969 for (y=0; y < (ssize_t) fx_image->rows; y++)
2977 register IndexPacket
2978 *restrict fx_indexes;
2983 register PixelPacket
2986 if (status == MagickFalse)
2988 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2989 if (q == (PixelPacket *) NULL)
2994 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2995 id=GetOpenMPThreadId();
2997 for (x=0; x < (ssize_t) fx_image->columns; x++)
2999 if ((channel & RedChannel) != 0)
3001 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
3003 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3005 if ((channel & GreenChannel) != 0)
3007 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
3009 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3011 if ((channel & BlueChannel) != 0)
3013 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
3015 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3017 if ((channel & OpacityChannel) != 0)
3019 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
3021 if (image->matte == MagickFalse)
3022 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3024 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
3025 QuantumRange*alpha));
3027 if (((channel & IndexChannel) != 0) &&
3028 (fx_image->colorspace == CMYKColorspace))
3030 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
3032 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
3033 QuantumRange*alpha);
3037 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3039 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3044 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3045 #pragma omp critical (MagickCore_FxImageChannel)
3047 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3048 if (proceed == MagickFalse)
3052 fx_image->matte=fx_info[0]->matte;
3053 fx_view=DestroyCacheView(fx_view);
3054 fx_info=DestroyFxThreadSet(fx_info);
3055 if (status == MagickFalse)
3056 fx_image=DestroyImage(fx_image);
3061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3065 % I m p l o d e I m a g e %
3069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3071 % ImplodeImage() creates a new image that is a copy of an existing
3072 % one with the image pixels "implode" by the specified percentage. It
3073 % allocates the memory necessary for the new Image structure and returns a
3074 % pointer to the new image.
3076 % The format of the ImplodeImage method is:
3078 % Image *ImplodeImage(const Image *image,const double amount,
3079 % ExceptionInfo *exception)
3081 % A description of each parameter follows:
3083 % o implode_image: Method ImplodeImage returns a pointer to the image
3084 % after it is implode. A null image is returned if there is a memory
3087 % o image: the image.
3089 % o amount: Define the extent of the implosion.
3091 % o exception: return any errors or warnings in this structure.
3094 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3095 ExceptionInfo *exception)
3097 #define ImplodeImageTag "Implode/Image"
3123 **restrict resample_filter;
3129 Initialize implode image attributes.
3131 assert(image != (Image *) NULL);
3132 assert(image->signature == MagickSignature);
3133 if (image->debug != MagickFalse)
3134 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3135 assert(exception != (ExceptionInfo *) NULL);
3136 assert(exception->signature == MagickSignature);
3137 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3138 if (implode_image == (Image *) NULL)
3139 return((Image *) NULL);
3140 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3142 InheritException(exception,&implode_image->exception);
3143 implode_image=DestroyImage(implode_image);
3144 return((Image *) NULL);
3146 if (implode_image->background_color.opacity != OpaqueOpacity)
3147 implode_image->matte=MagickTrue;
3149 Compute scaling factor.
3153 center.x=0.5*image->columns;
3154 center.y=0.5*image->rows;
3156 if (image->columns > image->rows)
3157 scale.y=(double) image->columns/(double) image->rows;
3159 if (image->columns < image->rows)
3161 scale.x=(double) image->rows/(double) image->columns;
3169 GetMagickPixelPacket(implode_image,&zero);
3170 resample_filter=AcquireResampleFilterThreadSet(image,
3171 UndefinedVirtualPixelMethod,MagickTrue,exception);
3172 image_view=AcquireCacheView(image);
3173 implode_view=AcquireCacheView(implode_image);
3174 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3175 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3177 for (y=0; y < (ssize_t) image->rows; y++)
3191 register IndexPacket
3192 *restrict implode_indexes;
3197 register PixelPacket
3200 if (status == MagickFalse)
3202 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3204 if (q == (PixelPacket *) NULL)
3209 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
3210 delta.y=scale.y*(double) (y-center.y);
3212 id=GetOpenMPThreadId();
3213 for (x=0; x < (ssize_t) image->columns; x++)
3216 Determine if the pixel is within an ellipse.
3218 delta.x=scale.x*(double) (x-center.x);
3219 distance=delta.x*delta.x+delta.y*delta.y;
3220 if (distance < (radius*radius))
3230 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3231 radius/2)),-amount);
3232 (void) ResamplePixelColor(resample_filter[id],(double)
3233 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3234 scale.y+center.y),&pixel);
3235 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
3239 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3241 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3246 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3247 #pragma omp critical (MagickCore_ImplodeImage)
3249 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3250 if (proceed == MagickFalse)
3254 implode_view=DestroyCacheView(implode_view);
3255 image_view=DestroyCacheView(image_view);
3256 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
3257 if (status == MagickFalse)
3258 implode_image=DestroyImage(implode_image);
3259 return(implode_image);
3263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3267 % M o r p h I m a g e s %
3271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3273 % The MorphImages() method requires a minimum of two images. The first
3274 % image is transformed into the second by a number of intervening images
3275 % as specified by frames.
3277 % The format of the MorphImage method is:
3279 % Image *MorphImages(const Image *image,const size_t number_frames,
3280 % ExceptionInfo *exception)
3282 % A description of each parameter follows:
3284 % o image: the image.
3286 % o number_frames: Define the number of in-between image to generate.
3287 % The more in-between frames, the smoother the morph.
3289 % o exception: return any errors or warnings in this structure.
3292 MagickExport Image *MorphImages(const Image *image,
3293 const size_t number_frames,ExceptionInfo *exception)
3295 #define MorphImageTag "Morph/Image"
3311 register const Image
3321 Clone first frame in sequence.
3323 assert(image != (Image *) NULL);
3324 assert(image->signature == MagickSignature);
3325 if (image->debug != MagickFalse)
3326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3327 assert(exception != (ExceptionInfo *) NULL);
3328 assert(exception->signature == MagickSignature);
3329 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3330 if (morph_images == (Image *) NULL)
3331 return((Image *) NULL);
3332 if (GetNextImageInList(image) == (Image *) NULL)
3337 for (i=1; i < (ssize_t) number_frames; i++)
3339 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3340 if (morph_image == (Image *) NULL)
3342 morph_images=DestroyImageList(morph_images);
3343 return((Image *) NULL);
3345 AppendImageToList(&morph_images,morph_image);
3346 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3351 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3353 if (proceed == MagickFalse)
3357 return(GetFirstImageInList(morph_images));
3360 Morph image sequence.
3365 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3367 for (i=0; i < (ssize_t) number_frames; i++)
3373 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3375 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3376 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3377 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3378 next->filter,next->blur,exception);
3379 if (morph_image == (Image *) NULL)
3381 morph_images=DestroyImageList(morph_images);
3382 return((Image *) NULL);
3384 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3386 InheritException(exception,&morph_image->exception);
3387 morph_image=DestroyImage(morph_image);
3388 return((Image *) NULL);
3390 AppendImageToList(&morph_images,morph_image);
3391 morph_images=GetLastImageInList(morph_images);
3392 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3393 morph_images->rows,GetNextImageInList(next)->filter,
3394 GetNextImageInList(next)->blur,exception);
3395 if (morph_image == (Image *) NULL)
3397 morph_images=DestroyImageList(morph_images);
3398 return((Image *) NULL);
3400 image_view=AcquireCacheView(morph_image);
3401 morph_view=AcquireCacheView(morph_images);
3402 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3403 #pragma omp parallel for schedule(dynamic,4) shared(status)
3405 for (y=0; y < (ssize_t) morph_images->rows; y++)
3410 register const PixelPacket
3416 register PixelPacket
3419 if (status == MagickFalse)
3421 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3423 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3425 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3430 for (x=0; x < (ssize_t) morph_images->columns; x++)
3432 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3433 q->green=ClampToQuantum(alpha*q->green+beta*
3434 GetGreenPixelComponent(p));
3435 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3436 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3437 GetOpacityPixelComponent(p));
3441 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3442 if (sync == MagickFalse)
3445 morph_view=DestroyCacheView(morph_view);
3446 image_view=DestroyCacheView(image_view);
3447 morph_image=DestroyImage(morph_image);
3449 if (i < (ssize_t) number_frames)
3452 Clone last frame in sequence.
3454 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3455 if (morph_image == (Image *) NULL)
3457 morph_images=DestroyImageList(morph_images);
3458 return((Image *) NULL);
3460 AppendImageToList(&morph_images,morph_image);
3461 morph_images=GetLastImageInList(morph_images);
3462 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3467 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3468 #pragma omp critical (MagickCore_MorphImages)
3470 proceed=SetImageProgress(image,MorphImageTag,scene,
3471 GetImageListLength(image));
3472 if (proceed == MagickFalse)
3477 if (GetNextImageInList(next) != (Image *) NULL)
3479 morph_images=DestroyImageList(morph_images);
3480 return((Image *) NULL);
3482 return(GetFirstImageInList(morph_images));
3486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3490 % P l a s m a I m a g e %
3494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3496 % PlasmaImage() initializes an image with plasma fractal values. The image
3497 % must be initialized with a base color and the random number generator
3498 % seeded before this method is called.
3500 % The format of the PlasmaImage method is:
3502 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3503 % size_t attenuate,size_t depth)
3505 % A description of each parameter follows:
3507 % o image: the image.
3509 % o segment: Define the region to apply plasma fractals values.
3511 % o attenuate: Define the plasma attenuation factor.
3513 % o depth: Limit the plasma recursion depth.
3517 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3518 const MagickRealType pixel,const MagickRealType noise)
3523 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3528 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3529 RandomInfo *random_info,const SegmentInfo *segment,size_t attenuate,
3548 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3556 Divide the area into quadrants and recurse.
3560 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3561 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3562 local_info=(*segment);
3563 local_info.x2=(double) x_mid;
3564 local_info.y2=(double) y_mid;
3565 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3566 local_info=(*segment);
3567 local_info.y1=(double) y_mid;
3568 local_info.x2=(double) x_mid;
3569 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3570 local_info=(*segment);
3571 local_info.x1=(double) x_mid;
3572 local_info.y2=(double) y_mid;
3573 (void) PlasmaImageProxy(image,random_info,&local_info,attenuate,depth);
3574 local_info=(*segment);
3575 local_info.x1=(double) x_mid;
3576 local_info.y1=(double) y_mid;
3577 return(PlasmaImageProxy(image,random_info,&local_info,attenuate,depth));
3579 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3580 return(MagickFalse);
3581 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3582 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3583 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3584 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3585 return(MagickFalse);
3587 Average pixels and apply plasma.
3589 exception=(&image->exception);
3590 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3591 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3593 register PixelPacket
3599 x=(ssize_t) ceil(segment->x1-0.5);
3600 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y1-0.5),&u,
3602 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y2-0.5),&v,
3604 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3605 if (q == (PixelPacket *) NULL)
3607 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3609 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3611 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3613 (void) SyncAuthenticPixels(image,exception);
3614 if (segment->x1 != segment->x2)
3619 x=(ssize_t) ceil(segment->x2-0.5);
3620 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y1-0.5),&u,
3622 (void) GetOneVirtualPixel(image,x,(ssize_t) ceil(segment->y2-0.5),&v,
3624 q=QueueAuthenticPixels(image,x,y_mid,1,1,exception);
3625 if (q == (PixelPacket *) NULL)
3627 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3629 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3631 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3633 (void) SyncAuthenticPixels(image,exception);
3636 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3638 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3640 register PixelPacket
3646 y=(ssize_t) ceil(segment->y2-0.5);
3647 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x1-0.5),y,&u,
3649 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x2-0.5),y,&v,
3651 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3652 if (q == (PixelPacket *) NULL)
3654 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3656 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3658 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3660 (void) SyncAuthenticPixels(image,exception);
3662 if (segment->y1 != segment->y2)
3664 register PixelPacket
3670 y=(ssize_t) ceil(segment->y1-0.5);
3671 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x1-0.5),y,&u,
3673 (void) GetOneVirtualPixel(image,(ssize_t) ceil(segment->x2-0.5),y,&v,
3675 q=QueueAuthenticPixels(image,x_mid,y,1,1,exception);
3676 if (q == (PixelPacket *) NULL)
3678 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3680 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3682 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3684 (void) SyncAuthenticPixels(image,exception);
3687 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3689 register PixelPacket
3695 x=(ssize_t) ceil(segment->x1-0.5);
3696 y=(ssize_t) ceil(segment->y1-0.5);
3697 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3698 x=(ssize_t) ceil(segment->x2-0.5);
3699 y=(ssize_t) ceil(segment->y2-0.5);
3700 (void) GetOneVirtualPixel(image,x,y,&v,exception);
3701 q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception);
3702 if (q == (PixelPacket *) NULL)
3704 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3706 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3708 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3710 (void) SyncAuthenticPixels(image,exception);
3712 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3714 return(MagickFalse);
3717 MagickExport MagickBooleanType PlasmaImage(Image *image,
3718 const SegmentInfo *segment,size_t attenuate,size_t depth)
3726 if (image->debug != MagickFalse)
3727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3728 assert(image != (Image *) NULL);
3729 assert(image->signature == MagickSignature);
3730 if (image->debug != MagickFalse)
3731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3732 random_info=AcquireRandomInfo();
3733 status=PlasmaImageProxy(image,random_info,segment,attenuate,depth);
3734 random_info=DestroyRandomInfo(random_info);
3739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3743 % P o l a r o i d I m a g e %
3747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3749 % PolaroidImage() simulates a Polaroid picture.
3751 % The format of the AnnotateImage method is:
3753 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3754 % const double angle,ExceptionInfo exception)
3756 % A description of each parameter follows:
3758 % o image: the image.
3760 % o draw_info: the draw info.
3762 % o angle: Apply the effect along this angle.
3764 % o exception: return any errors or warnings in this structure.
3767 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3768 const double angle,ExceptionInfo *exception)
3789 Simulate a Polaroid picture.
3791 assert(image != (Image *) NULL);
3792 assert(image->signature == MagickSignature);
3793 if (image->debug != MagickFalse)
3794 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3795 assert(exception != (ExceptionInfo *) NULL);
3796 assert(exception->signature == MagickSignature);
3797 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3798 image->rows)/25.0,10.0);
3799 height=image->rows+2*quantum;
3800 caption_image=(Image *) NULL;
3801 value=GetImageProperty(image,"Caption");
3802 if (value != (const char *) NULL)
3806 geometry[MaxTextExtent];
3821 Generate caption image.
3823 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3824 if (caption_image == (Image *) NULL)
3825 return((Image *) NULL);
3826 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3827 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3829 (void) CloneString(&annotate_info->text,caption);
3830 count=FormatMagickCaption(caption_image,annotate_info,&metrics,&caption);
3831 status=SetImageExtent(caption_image,image->columns,(size_t)
3832 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3833 if (status == MagickFalse)
3834 caption_image=DestroyImage(caption_image);
3837 caption_image->background_color=image->border_color;
3838 (void) SetImageBackgroundColor(caption_image);
3839 (void) CloneString(&annotate_info->text,caption);
3840 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3842 if (annotate_info->gravity == UndefinedGravity)
3843 (void) CloneString(&annotate_info->geometry,AcquireString(
3845 (void) AnnotateImage(caption_image,annotate_info);
3846 height+=caption_image->rows;
3848 annotate_info=DestroyDrawInfo(annotate_info);
3849 caption=DestroyString(caption);
3851 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3853 if (picture_image == (Image *) NULL)
3855 if (caption_image != (Image *) NULL)
3856 caption_image=DestroyImage(caption_image);
3857 return((Image *) NULL);
3859 picture_image->background_color=image->border_color;
3860 (void) SetImageBackgroundColor(picture_image);
3861 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3862 if (caption_image != (Image *) NULL)
3864 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3865 quantum,(ssize_t) (image->rows+3*quantum/2));
3866 caption_image=DestroyImage(caption_image);
3868 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3869 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3870 rotate_image=RotateImage(picture_image,90.0,exception);
3871 picture_image=DestroyImage(picture_image);
3872 if (rotate_image == (Image *) NULL)
3873 return((Image *) NULL);
3874 picture_image=rotate_image;
3875 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3876 picture_image->columns,exception);
3877 picture_image=DestroyImage(picture_image);
3878 if (bend_image == (Image *) NULL)
3879 return((Image *) NULL);
3880 InheritException(&bend_image->exception,exception);
3881 picture_image=bend_image;
3882 rotate_image=RotateImage(picture_image,-90.0,exception);
3883 picture_image=DestroyImage(picture_image);
3884 if (rotate_image == (Image *) NULL)
3885 return((Image *) NULL);
3886 picture_image=rotate_image;
3887 picture_image->background_color=image->background_color;
3888 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3890 if (polaroid_image == (Image *) NULL)
3892 picture_image=DestroyImage(picture_image);
3893 return(picture_image);
3895 flop_image=FlopImage(polaroid_image,exception);
3896 polaroid_image=DestroyImage(polaroid_image);
3897 if (flop_image == (Image *) NULL)
3899 picture_image=DestroyImage(picture_image);
3900 return(picture_image);
3902 polaroid_image=flop_image;
3903 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3904 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3905 picture_image=DestroyImage(picture_image);
3906 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3907 rotate_image=RotateImage(polaroid_image,angle,exception);
3908 polaroid_image=DestroyImage(polaroid_image);
3909 if (rotate_image == (Image *) NULL)
3910 return((Image *) NULL);
3911 polaroid_image=rotate_image;
3912 trim_image=TrimImage(polaroid_image,exception);
3913 polaroid_image=DestroyImage(polaroid_image);
3914 if (trim_image == (Image *) NULL)
3915 return((Image *) NULL);
3916 polaroid_image=trim_image;
3917 return(polaroid_image);
3921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3925 % S e p i a T o n e I m a g e %
3929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3931 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3932 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3933 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3934 % threshold of 80% is a good starting point for a reasonable tone.
3936 % The format of the SepiaToneImage method is:
3938 % Image *SepiaToneImage(const Image *image,const double threshold,
3939 % ExceptionInfo *exception)
3941 % A description of each parameter follows:
3943 % o image: the image.
3945 % o threshold: the tone threshold.
3947 % o exception: return any errors or warnings in this structure.
3950 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3951 ExceptionInfo *exception)
3953 #define SepiaToneImageTag "SepiaTone/Image"
3972 Initialize sepia-toned image attributes.
3974 assert(image != (const Image *) NULL);
3975 assert(image->signature == MagickSignature);
3976 if (image->debug != MagickFalse)
3977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3978 assert(exception != (ExceptionInfo *) NULL);
3979 assert(exception->signature == MagickSignature);
3980 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3981 if (sepia_image == (Image *) NULL)
3982 return((Image *) NULL);
3983 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3985 InheritException(exception,&sepia_image->exception);
3986 sepia_image=DestroyImage(sepia_image);
3987 return((Image *) NULL);
3990 Tone each row of the image.
3994 image_view=AcquireCacheView(image);
3995 sepia_view=AcquireCacheView(sepia_image);
3996 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3997 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3999 for (y=0; y < (ssize_t) image->rows; y++)
4001 register const PixelPacket
4007 register PixelPacket
4010 if (status == MagickFalse)
4012 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4013 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4015 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4020 for (x=0; x < (ssize_t) image->columns; x++)
4026 intensity=(MagickRealType) PixelIntensityToQuantum(p);
4027 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4028 (MagickRealType) QuantumRange-threshold;
4029 q->red=ClampToQuantum(tone);
4030 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4031 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4032 q->green=ClampToQuantum(tone);
4033 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4034 q->blue=ClampToQuantum(tone);
4036 if ((MagickRealType) q->green < tone)
4037 q->green=ClampToQuantum(tone);
4038 if ((MagickRealType) q->blue < tone)
4039 q->blue=ClampToQuantum(tone);
4043 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4045 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4050 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4051 #pragma omp critical (MagickCore_SepiaToneImage)
4053 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4055 if (proceed == MagickFalse)
4059 sepia_view=DestroyCacheView(sepia_view);
4060 image_view=DestroyCacheView(image_view);
4061 (void) NormalizeImage(sepia_image);
4062 (void) ContrastImage(sepia_image,MagickTrue);
4063 if (status == MagickFalse)
4064 sepia_image=DestroyImage(sepia_image);
4065 return(sepia_image);
4069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4073 % S h a d o w I m a g e %
4077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4079 % ShadowImage() simulates a shadow from the specified image and returns it.
4081 % The format of the ShadowImage method is:
4083 % Image *ShadowImage(const Image *image,const double opacity,
4084 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4085 % ExceptionInfo *exception)
4087 % A description of each parameter follows:
4089 % o image: the image.
4091 % o opacity: percentage transparency.
4093 % o sigma: the standard deviation of the Gaussian, in pixels.
4095 % o x_offset: the shadow x-offset.
4097 % o y_offset: the shadow y-offset.
4099 % o exception: return any errors or warnings in this structure.
4102 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4103 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4104 ExceptionInfo *exception)
4106 #define ShadowImageTag "Shadow/Image"
4128 assert(image != (Image *) NULL);
4129 assert(image->signature == MagickSignature);
4130 if (image->debug != MagickFalse)
4131 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4132 assert(exception != (ExceptionInfo *) NULL);
4133 assert(exception->signature == MagickSignature);
4134 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4135 if (clone_image == (Image *) NULL)
4136 return((Image *) NULL);
4137 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4138 clone_image->compose=OverCompositeOp;
4139 border_info.width=(size_t) floor(2.0*sigma+0.5);
4140 border_info.height=(size_t) floor(2.0*sigma+0.5);
4143 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4144 border_image=BorderImage(clone_image,&border_info,exception);
4145 clone_image=DestroyImage(clone_image);
4146 if (border_image == (Image *) NULL)
4147 return((Image *) NULL);
4148 if (border_image->matte == MagickFalse)
4149 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4155 image_view=AcquireCacheView(border_image);
4156 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4157 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4159 for (y=0; y < (ssize_t) border_image->rows; y++)
4164 register PixelPacket
4167 if (status == MagickFalse)
4169 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4171 if (q == (PixelPacket *) NULL)
4176 for (x=0; x < (ssize_t) border_image->columns; x++)
4178 q->red=border_image->background_color.red;
4179 q->green=border_image->background_color.green;
4180 q->blue=border_image->background_color.blue;
4181 if (border_image->matte == MagickFalse)
4182 q->opacity=border_image->background_color.opacity;
4184 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4185 GetAlphaPixelComponent(q)*opacity/100.0));
4188 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4190 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4195 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4196 #pragma omp critical (MagickCore_ShadowImage)
4198 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4199 border_image->rows);
4200 if (proceed == MagickFalse)
4204 image_view=DestroyCacheView(image_view);
4205 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4206 border_image=DestroyImage(border_image);
4207 if (shadow_image == (Image *) NULL)
4208 return((Image *) NULL);
4209 if (shadow_image->page.width == 0)
4210 shadow_image->page.width=shadow_image->columns;
4211 if (shadow_image->page.height == 0)
4212 shadow_image->page.height=shadow_image->rows;
4213 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4214 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4215 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4216 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4217 return(shadow_image);
4221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4225 % S k e t c h I m a g e %
4229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4231 % SketchImage() simulates a pencil sketch. We convolve the image with a
4232 % Gaussian operator of the given radius and standard deviation (sigma). For
4233 % reasonable results, radius should be larger than sigma. Use a radius of 0
4234 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4237 % The format of the SketchImage method is:
4239 % Image *SketchImage(const Image *image,const double radius,
4240 % const double sigma,const double angle,ExceptionInfo *exception)
4242 % A description of each parameter follows:
4244 % o image: the image.
4246 % o radius: the radius of the Gaussian, in pixels, not counting
4249 % o sigma: the standard deviation of the Gaussian, in pixels.
4251 % o angle: Apply the effect along this angle.
4253 % o exception: return any errors or warnings in this structure.
4256 MagickExport Image *SketchImage(const Image *image,const double radius,
4257 const double sigma,const double angle,ExceptionInfo *exception)
4279 **restrict random_info;
4284 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4285 MagickTrue,exception);
4286 if (random_image == (Image *) NULL)
4287 return((Image *) NULL);
4289 GetMagickPixelPacket(random_image,&zero);
4290 random_info=AcquireRandomInfoThreadSet();
4291 random_view=AcquireCacheView(random_image);
4292 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4293 #pragma omp parallel for schedule(dynamic,4) shared(status)
4295 for (y=0; y < (ssize_t) random_image->rows; y++)
4303 register IndexPacket
4309 register PixelPacket
4312 if (status == MagickFalse)
4314 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4316 if (q == (PixelPacket *) NULL)
4321 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4323 id=GetOpenMPThreadId();
4324 for (x=0; x < (ssize_t) random_image->columns; x++)
4326 pixel.red=(MagickRealType) (QuantumRange*
4327 GetPseudoRandomValue(random_info[id]));
4328 pixel.green=pixel.red;
4329 pixel.blue=pixel.red;
4330 if (image->colorspace == CMYKColorspace)
4331 pixel.index=pixel.red;
4332 SetPixelPacket(random_image,&pixel,q,indexes+x);
4335 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4338 random_view=DestroyCacheView(random_view);
4339 random_info=DestroyRandomInfoThreadSet(random_info);
4340 if (status == MagickFalse)
4342 random_image=DestroyImage(random_image);
4343 return(random_image);
4345 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4346 random_image=DestroyImage(random_image);
4347 if (blur_image == (Image *) NULL)
4348 return((Image *) NULL);
4349 dodge_image=EdgeImage(blur_image,radius,exception);
4350 blur_image=DestroyImage(blur_image);
4351 if (dodge_image == (Image *) NULL)
4352 return((Image *) NULL);
4353 (void) NormalizeImage(dodge_image);
4354 (void) NegateImage(dodge_image,MagickFalse);
4355 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4356 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4357 if (sketch_image == (Image *) NULL)
4359 dodge_image=DestroyImage(dodge_image);
4360 return((Image *) NULL);
4362 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4363 dodge_image=DestroyImage(dodge_image);
4364 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4365 if (blend_image == (Image *) NULL)
4367 sketch_image=DestroyImage(sketch_image);
4368 return((Image *) NULL);
4370 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4371 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4372 blend_image=DestroyImage(blend_image);
4373 return(sketch_image);
4377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4381 % S o l a r i z e I m a g e %
4385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4387 % SolarizeImage() applies a special effect to the image, similar to the effect
4388 % achieved in a photo darkroom by selectively exposing areas of photo
4389 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4390 % measure of the extent of the solarization.
4392 % The format of the SolarizeImage method is:
4394 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4396 % A description of each parameter follows:
4398 % o image: the image.
4400 % o threshold: Define the extent of the solarization.
4403 MagickExport MagickBooleanType SolarizeImage(Image *image,
4404 const double threshold)
4406 #define SolarizeImageTag "Solarize/Image"
4423 assert(image != (Image *) NULL);
4424 assert(image->signature == MagickSignature);
4425 if (image->debug != MagickFalse)
4426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4427 if (image->storage_class == PseudoClass)
4435 for (i=0; i < (ssize_t) image->colors; i++)
4437 if ((MagickRealType) image->colormap[i].red > threshold)
4438 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4439 if ((MagickRealType) image->colormap[i].green > threshold)
4440 image->colormap[i].green=(Quantum) QuantumRange-
4441 image->colormap[i].green;
4442 if ((MagickRealType) image->colormap[i].blue > threshold)
4443 image->colormap[i].blue=(Quantum) QuantumRange-
4444 image->colormap[i].blue;
4452 exception=(&image->exception);
4453 image_view=AcquireCacheView(image);
4454 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4455 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4457 for (y=0; y < (ssize_t) image->rows; y++)
4462 register PixelPacket
4465 if (status == MagickFalse)
4467 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4469 if (q == (PixelPacket *) NULL)
4474 for (x=0; x < (ssize_t) image->columns; x++)
4476 if ((MagickRealType) q->red > threshold)
4477 q->red=(Quantum) QuantumRange-q->red;
4478 if ((MagickRealType) q->green > threshold)
4479 q->green=(Quantum) QuantumRange-q->green;
4480 if ((MagickRealType) q->blue > threshold)
4481 q->blue=(Quantum) QuantumRange-q->blue;
4484 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4486 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4491 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4492 #pragma omp critical (MagickCore_SolarizeImage)
4494 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4495 if (proceed == MagickFalse)
4499 image_view=DestroyCacheView(image_view);
4504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4508 % S t e g a n o I m a g e %
4512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4514 % SteganoImage() hides a digital watermark within the image. Recover
4515 % the hidden watermark later to prove that the authenticity of an image.
4516 % Offset defines the start position within the image to hide the watermark.
4518 % The format of the SteganoImage method is:
4520 % Image *SteganoImage(const Image *image,Image *watermark,
4521 % ExceptionInfo *exception)
4523 % A description of each parameter follows:
4525 % o image: the image.
4527 % o watermark: the watermark image.
4529 % o exception: return any errors or warnings in this structure.
4532 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4533 ExceptionInfo *exception)
4535 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) \
4537 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) != 0 ? (size_t) (alpha) \
4538 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4539 #define SteganoImageTag "Stegano/Image"
4562 register PixelPacket
4570 Initialize steganographic image attributes.
4572 assert(image != (const Image *) NULL);
4573 assert(image->signature == MagickSignature);
4574 if (image->debug != MagickFalse)
4575 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4576 assert(watermark != (const Image *) NULL);
4577 assert(watermark->signature == MagickSignature);
4578 assert(exception != (ExceptionInfo *) NULL);
4579 assert(exception->signature == MagickSignature);
4581 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4582 if (stegano_image == (Image *) NULL)
4583 return((Image *) NULL);
4584 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4586 InheritException(exception,&stegano_image->exception);
4587 stegano_image=DestroyImage(stegano_image);
4588 return((Image *) NULL);
4590 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4592 Hide watermark in low-order bits of image.
4597 depth=stegano_image->depth;
4599 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4601 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4603 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4605 (void) GetOneVirtualPixel(watermark,x,y,&pixel,exception);
4606 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4608 q=GetAuthenticPixels(stegano_image,k % (ssize_t) stegano_image->columns,
4609 k/(ssize_t) stegano_image->columns,1,1,exception);
4610 if (q == (PixelPacket *) NULL)
4616 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4621 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4626 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4630 if (SyncAuthenticPixels(stegano_image,exception) == MagickFalse)
4636 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4638 if (k == image->offset)
4642 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4647 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4649 if (proceed == MagickFalse)
4653 if (stegano_image->storage_class == PseudoClass)
4654 (void) SyncImage(stegano_image);
4655 return(stegano_image);
4659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4663 % S t e r e o A n a g l y p h I m a g e %
4667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4669 % StereoAnaglyphImage() combines two images and produces a single image that
4670 % is the composite of a left and right image of a stereo pair. Special
4671 % red-green stereo glasses are required to view this effect.
4673 % The format of the StereoAnaglyphImage method is:
4675 % Image *StereoImage(const Image *left_image,const Image *right_image,
4676 % ExceptionInfo *exception)
4677 % Image *StereoAnaglyphImage(const Image *left_image,
4678 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4679 % ExceptionInfo *exception)
4681 % A description of each parameter follows:
4683 % o left_image: the left image.
4685 % o right_image: the right image.
4687 % o exception: return any errors or warnings in this structure.
4689 % o x_offset: amount, in pixels, by which the left image is offset to the
4690 % right of the right image.
4692 % o y_offset: amount, in pixels, by which the left image is offset to the
4693 % bottom of the right image.
4697 MagickExport Image *StereoImage(const Image *left_image,
4698 const Image *right_image,ExceptionInfo *exception)
4700 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4703 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4704 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4705 ExceptionInfo *exception)
4707 #define StereoImageTag "Stereo/Image"
4721 assert(left_image != (const Image *) NULL);
4722 assert(left_image->signature == MagickSignature);
4723 if (left_image->debug != MagickFalse)
4724 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4725 left_image->filename);
4726 assert(right_image != (const Image *) NULL);
4727 assert(right_image->signature == MagickSignature);
4728 assert(exception != (ExceptionInfo *) NULL);
4729 assert(exception->signature == MagickSignature);
4730 assert(right_image != (const Image *) NULL);
4732 if ((left_image->columns != right_image->columns) ||
4733 (left_image->rows != right_image->rows))
4734 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4736 Initialize stereo image attributes.
4738 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4739 MagickTrue,exception);
4740 if (stereo_image == (Image *) NULL)
4741 return((Image *) NULL);
4742 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4744 InheritException(exception,&stereo_image->exception);
4745 stereo_image=DestroyImage(stereo_image);
4746 return((Image *) NULL);
4749 Copy left image to red channel and right image to blue channel.
4751 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4753 register const PixelPacket
4760 register PixelPacket
4763 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4765 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4766 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4767 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4768 (r == (PixelPacket *) NULL))
4770 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4772 r->red=GetRedPixelComponent(p);
4775 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4780 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4782 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4787 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4788 stereo_image->rows);
4789 if (proceed == MagickFalse)
4793 return(stereo_image);
4797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4801 % S w i r l I m a g e %
4805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4807 % SwirlImage() swirls the pixels about the center of the image, where
4808 % degrees indicates the sweep of the arc through which each pixel is moved.
4809 % You get a more dramatic effect as the degrees move from 1 to 360.
4811 % The format of the SwirlImage method is:
4813 % Image *SwirlImage(const Image *image,double degrees,
4814 % ExceptionInfo *exception)
4816 % A description of each parameter follows:
4818 % o image: the image.
4820 % o degrees: Define the tightness of the swirling effect.
4822 % o exception: return any errors or warnings in this structure.
4825 MagickExport Image *SwirlImage(const Image *image,double degrees,
4826 ExceptionInfo *exception)
4828 #define SwirlImageTag "Swirl/Image"
4854 **restrict resample_filter;
4860 Initialize swirl image attributes.
4862 assert(image != (const Image *) NULL);
4863 assert(image->signature == MagickSignature);
4864 if (image->debug != MagickFalse)
4865 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4866 assert(exception != (ExceptionInfo *) NULL);
4867 assert(exception->signature == MagickSignature);
4868 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4869 if (swirl_image == (Image *) NULL)
4870 return((Image *) NULL);
4871 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4873 InheritException(exception,&swirl_image->exception);
4874 swirl_image=DestroyImage(swirl_image);
4875 return((Image *) NULL);
4877 if (swirl_image->background_color.opacity != OpaqueOpacity)
4878 swirl_image->matte=MagickTrue;
4880 Compute scaling factor.
4882 center.x=(double) image->columns/2.0;
4883 center.y=(double) image->rows/2.0;
4884 radius=MagickMax(center.x,center.y);
4887 if (image->columns > image->rows)
4888 scale.y=(double) image->columns/(double) image->rows;
4890 if (image->columns < image->rows)
4891 scale.x=(double) image->rows/(double) image->columns;
4892 degrees=(double) DegreesToRadians(degrees);
4898 GetMagickPixelPacket(swirl_image,&zero);
4899 resample_filter=AcquireResampleFilterThreadSet(image,
4900 UndefinedVirtualPixelMethod,MagickTrue,exception);
4901 image_view=AcquireCacheView(image);
4902 swirl_view=AcquireCacheView(swirl_image);
4903 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4904 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4906 for (y=0; y < (ssize_t) image->rows; y++)
4920 register IndexPacket
4921 *restrict swirl_indexes;
4926 register PixelPacket
4929 if (status == MagickFalse)
4931 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4933 if (q == (PixelPacket *) NULL)
4938 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4939 delta.y=scale.y*(double) (y-center.y);
4941 id=GetOpenMPThreadId();
4942 for (x=0; x < (ssize_t) image->columns; x++)
4945 Determine if the pixel is within an ellipse.
4947 delta.x=scale.x*(double) (x-center.x);
4948 distance=delta.x*delta.x+delta.y*delta.y;
4949 if (distance < (radius*radius))
4959 factor=1.0-sqrt((double) distance)/radius;
4960 sine=sin((double) (degrees*factor*factor));
4961 cosine=cos((double) (degrees*factor*factor));
4962 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4963 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4964 cosine*delta.y)/scale.y+center.y),&pixel);
4965 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4969 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4971 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4976 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4977 #pragma omp critical (MagickCore_SwirlImage)
4979 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4980 if (proceed == MagickFalse)
4984 swirl_view=DestroyCacheView(swirl_view);
4985 image_view=DestroyCacheView(image_view);
4986 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
4987 if (status == MagickFalse)
4988 swirl_image=DestroyImage(swirl_image);
4989 return(swirl_image);
4993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4997 % T i n t I m a g e %
5001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5003 % TintImage() applies a color vector to each pixel in the image. The length
5004 % of the vector is 0 for black and white and at its maximum for the midtones.
5005 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5007 % The format of the TintImage method is:
5009 % Image *TintImage(const Image *image,const char *opacity,
5010 % const PixelPacket tint,ExceptionInfo *exception)
5012 % A description of each parameter follows:
5014 % o image: the image.
5016 % o opacity: A color value used for tinting.
5018 % o tint: A color value used for tinting.
5020 % o exception: return any errors or warnings in this structure.
5023 MagickExport Image *TintImage(const Image *image,const char *opacity,
5024 const PixelPacket tint,ExceptionInfo *exception)
5026 #define TintImageTag "Tint/Image"
5055 Allocate tint image.
5057 assert(image != (const Image *) NULL);
5058 assert(image->signature == MagickSignature);
5059 if (image->debug != MagickFalse)
5060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5061 assert(exception != (ExceptionInfo *) NULL);
5062 assert(exception->signature == MagickSignature);
5063 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5064 if (tint_image == (Image *) NULL)
5065 return((Image *) NULL);
5066 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5068 InheritException(exception,&tint_image->exception);
5069 tint_image=DestroyImage(tint_image);
5070 return((Image *) NULL);
5072 if (opacity == (const char *) NULL)
5075 Determine RGB values of the color.
5077 flags=ParseGeometry(opacity,&geometry_info);
5078 pixel.red=geometry_info.rho;
5079 if ((flags & SigmaValue) != 0)
5080 pixel.green=geometry_info.sigma;
5082 pixel.green=pixel.red;
5083 if ((flags & XiValue) != 0)
5084 pixel.blue=geometry_info.xi;
5086 pixel.blue=pixel.red;
5087 if ((flags & PsiValue) != 0)
5088 pixel.opacity=geometry_info.psi;
5090 pixel.opacity=(MagickRealType) OpaqueOpacity;
5091 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5092 PixelIntensity(&tint));
5093 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5094 PixelIntensity(&tint));
5095 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5096 PixelIntensity(&tint));
5102 image_view=AcquireCacheView(image);
5103 tint_view=AcquireCacheView(tint_image);
5104 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5105 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5107 for (y=0; y < (ssize_t) image->rows; y++)
5109 register const PixelPacket
5115 register PixelPacket
5118 if (status == MagickFalse)
5120 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5121 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5123 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5128 for (x=0; x < (ssize_t) image->columns; x++)
5136 weight=QuantumScale*p->red-0.5;
5137 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5139 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5140 weight=QuantumScale*p->green-0.5;
5141 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5143 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5144 weight=QuantumScale*p->blue-0.5;
5145 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5147 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5148 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5152 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5154 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5159 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5160 #pragma omp critical (MagickCore_TintImage)
5162 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5163 if (proceed == MagickFalse)
5167 tint_view=DestroyCacheView(tint_view);
5168 image_view=DestroyCacheView(image_view);
5169 if (status == MagickFalse)
5170 tint_image=DestroyImage(tint_image);
5175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5179 % V i g n e t t e I m a g e %
5183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5185 % VignetteImage() softens the edges of the image in vignette style.
5187 % The format of the VignetteImage method is:
5189 % Image *VignetteImage(const Image *image,const double radius,
5190 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5192 % A description of each parameter follows:
5194 % o image: the image.
5196 % o radius: the radius of the pixel neighborhood.
5198 % o sigma: the standard deviation of the Gaussian, in pixels.
5200 % o x, y: Define the x and y ellipse offset.
5202 % o exception: return any errors or warnings in this structure.
5205 MagickExport Image *VignetteImage(const Image *image,const double radius,
5206 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5209 ellipse[MaxTextExtent];
5220 assert(image != (Image *) NULL);
5221 assert(image->signature == MagickSignature);
5222 if (image->debug != MagickFalse)
5223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5224 assert(exception != (ExceptionInfo *) NULL);
5225 assert(exception->signature == MagickSignature);
5226 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5227 if (canvas_image == (Image *) NULL)
5228 return((Image *) NULL);
5229 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5231 InheritException(exception,&canvas_image->exception);
5232 canvas_image=DestroyImage(canvas_image);
5233 return((Image *) NULL);
5235 canvas_image->matte=MagickTrue;
5236 oval_image=CloneImage(canvas_image,canvas_image->columns,
5237 canvas_image->rows,MagickTrue,exception);
5238 if (oval_image == (Image *) NULL)
5240 canvas_image=DestroyImage(canvas_image);
5241 return((Image *) NULL);
5243 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5244 (void) SetImageBackgroundColor(oval_image);
5245 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5246 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5247 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5248 (void) FormatMagickString(ellipse,MaxTextExtent,
5249 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5250 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5251 draw_info->primitive=AcquireString(ellipse);
5252 (void) DrawImage(oval_image,draw_info);
5253 draw_info=DestroyDrawInfo(draw_info);
5254 blur_image=BlurImage(oval_image,radius,sigma,exception);
5255 oval_image=DestroyImage(oval_image);
5256 if (blur_image == (Image *) NULL)
5258 canvas_image=DestroyImage(canvas_image);
5259 return((Image *) NULL);
5261 blur_image->matte=MagickFalse;
5262 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5263 blur_image=DestroyImage(blur_image);
5264 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5265 canvas_image=DestroyImage(canvas_image);
5266 return(vignette_image);
5270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5274 % W a v e I m a g e %
5278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5280 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5281 % vertically along a sine wave whose amplitude and wavelength is specified
5282 % by the given parameters.
5284 % The format of the WaveImage method is:
5286 % Image *WaveImage(const Image *image,const double amplitude,
5287 % const double wave_length,ExceptionInfo *exception)
5289 % A description of each parameter follows:
5291 % o image: the image.
5293 % o amplitude, wave_length: Define the amplitude and wave length of the
5296 % o exception: return any errors or warnings in this structure.
5299 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5300 const double wave_length,ExceptionInfo *exception)
5302 #define WaveImageTag "Wave/Image"
5326 **restrict resample_filter;
5332 Initialize wave image attributes.
5334 assert(image != (Image *) NULL);
5335 assert(image->signature == MagickSignature);
5336 if (image->debug != MagickFalse)
5337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5338 assert(exception != (ExceptionInfo *) NULL);
5339 assert(exception->signature == MagickSignature);
5340 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5341 fabs(amplitude)),MagickTrue,exception);
5342 if (wave_image == (Image *) NULL)
5343 return((Image *) NULL);
5344 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5346 InheritException(exception,&wave_image->exception);
5347 wave_image=DestroyImage(wave_image);
5348 return((Image *) NULL);
5350 if (wave_image->background_color.opacity != OpaqueOpacity)
5351 wave_image->matte=MagickTrue;
5355 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5357 if (sine_map == (MagickRealType *) NULL)
5359 wave_image=DestroyImage(wave_image);
5360 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5362 for (i=0; i < (ssize_t) wave_image->columns; i++)
5363 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5370 GetMagickPixelPacket(wave_image,&zero);
5371 resample_filter=AcquireResampleFilterThreadSet(image,
5372 BackgroundVirtualPixelMethod,MagickTrue,exception);
5373 wave_view=AcquireCacheView(wave_image);
5374 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5375 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5377 for (y=0; y < (ssize_t) wave_image->rows; y++)
5385 register IndexPacket
5391 register PixelPacket
5394 if (status == MagickFalse)
5396 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5398 if (q == (PixelPacket *) NULL)
5403 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5405 id=GetOpenMPThreadId();
5406 for (x=0; x < (ssize_t) wave_image->columns; x++)
5408 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5409 sine_map[x]),&pixel);
5410 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5413 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5415 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5420 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5421 #pragma omp critical (MagickCore_WaveImage)
5423 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5424 if (proceed == MagickFalse)
5428 wave_view=DestroyCacheView(wave_view);
5429 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5430 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5431 if (status == MagickFalse)
5432 wave_image=DestroyImage(wave_image);