2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects Methods %
20 % Copyright 1999-2011 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
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 + A c q u i r e F x I n f o %
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % AcquireFxInfo() allocates the FxInfo structure.
141 % The format of the AcquireFxInfo method is:
143 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
145 % A description of each parameter follows:
147 % o image: the image.
149 % o expression: the expression.
152 MagickExport FxInfo *AcquireFxInfo(const Image *image,const char *expression)
166 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
167 if (fx_info == (FxInfo *) NULL)
168 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
169 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
170 fx_info->exception=AcquireExceptionInfo();
171 fx_info->images=image;
172 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
173 RelinquishMagickMemory);
174 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
177 fx_info->images),sizeof(*fx_info->view));
178 if (fx_info->view == (CacheView **) NULL)
179 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
181 next=GetFirstImageInList(fx_info->images);
182 for ( ; next != (Image *) NULL; next=next->next)
184 fx_info->view[i]=AcquireCacheView(next);
187 fx_info->random_info=AcquireRandomInfo();
188 fx_info->expression=ConstantString(expression);
189 fx_info->file=stderr;
190 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
191 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
192 (strstr(fx_info->expression,"e-") != (char *) NULL))
195 Convert scientific notation.
197 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
198 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
199 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
200 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
201 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
202 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
203 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
204 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
205 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
206 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
207 (void) SubstituteString(&fx_info->expression,"0e-","0**10^-");
208 (void) SubstituteString(&fx_info->expression,"1e-","1**10^-");
209 (void) SubstituteString(&fx_info->expression,"2e-","2**10^-");
210 (void) SubstituteString(&fx_info->expression,"3e-","3**10^-");
211 (void) SubstituteString(&fx_info->expression,"4e-","4**10^-");
212 (void) SubstituteString(&fx_info->expression,"5e-","5**10^-");
213 (void) SubstituteString(&fx_info->expression,"6e-","6**10^-");
214 (void) SubstituteString(&fx_info->expression,"7e-","7**10^-");
215 (void) SubstituteString(&fx_info->expression,"8e-","8**10^-");
216 (void) SubstituteString(&fx_info->expression,"9e-","9**10^-");
219 Force right-to-left associativity for unary negation.
221 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
223 Convert complex to simple operators.
226 *fx_op=(char) LeftShiftOperator;
227 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
228 *fx_op=(char) RightShiftOperator;
229 (void) SubstituteString(&fx_info->expression,">>",fx_op);
230 *fx_op=(char) LessThanEqualOperator;
231 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
232 *fx_op=(char) GreaterThanEqualOperator;
233 (void) SubstituteString(&fx_info->expression,">=",fx_op);
234 *fx_op=(char) EqualOperator;
235 (void) SubstituteString(&fx_info->expression,"==",fx_op);
236 *fx_op=(char) NotEqualOperator;
237 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
238 *fx_op=(char) LogicalAndOperator;
239 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
240 *fx_op=(char) LogicalOrOperator;
241 (void) SubstituteString(&fx_info->expression,"||",fx_op);
242 *fx_op=(char) ExponentialNotation;
243 (void) SubstituteString(&fx_info->expression,"**",fx_op);
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % A d d N o i s e I m a g e %
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % AddNoiseImage() adds random noise to the image.
260 % The format of the AddNoiseImage method is:
262 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
263 % ExceptionInfo *exception)
264 % Image *AddNoiseImageChannel(const Image *image,const ChannelType channel,
265 % const NoiseType noise_type,ExceptionInfo *exception)
267 % A description of each parameter follows:
269 % o image: the image.
271 % o channel: the channel type.
273 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
274 % Impulse, Laplacian, or Poisson.
276 % o exception: return any errors or warnings in this structure.
279 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
280 ExceptionInfo *exception)
285 noise_image=AddNoiseImageChannel(image,DefaultChannels,noise_type,exception);
289 MagickExport Image *AddNoiseImageChannel(const Image *image,
290 const ChannelType channel,const NoiseType noise_type,ExceptionInfo *exception)
292 #define AddNoiseImageTag "AddNoise/Image"
314 **restrict random_info;
320 Initialize noise image attributes.
322 assert(image != (const Image *) NULL);
323 assert(image->signature == MagickSignature);
324 if (image->debug != MagickFalse)
325 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
326 assert(exception != (ExceptionInfo *) NULL);
327 assert(exception->signature == MagickSignature);
328 noise_image=CloneImage(image,0,0,MagickTrue,exception);
329 if (noise_image == (Image *) NULL)
330 return((Image *) NULL);
331 if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
333 InheritException(exception,&noise_image->exception);
334 noise_image=DestroyImage(noise_image);
335 return((Image *) NULL);
338 Add noise in each row.
341 option=GetImageArtifact(image,"attenuate");
342 if (option != (char *) NULL)
343 attenuate=StringToDouble(option);
346 random_info=AcquireRandomInfoThreadSet();
347 image_view=AcquireCacheView(image);
348 noise_view=AcquireCacheView(noise_image);
349 #if defined(MAGICKCORE_OPENMP_SUPPORT)
350 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
352 for (y=0; y < (ssize_t) image->rows; y++)
355 id = GetOpenMPThreadId();
360 register const IndexPacket
363 register const PixelPacket
367 *restrict noise_indexes;
375 if (status == MagickFalse)
377 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
378 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
380 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
385 indexes=GetCacheViewVirtualIndexQueue(image_view);
386 noise_indexes=GetCacheViewAuthenticIndexQueue(noise_view);
387 for (x=0; x < (ssize_t) image->columns; x++)
389 if ((channel & RedChannel) != 0)
390 q->red=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
391 p->red,noise_type,attenuate));
392 if ((channel & GreenChannel) != 0)
393 q->green=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
394 p->green,noise_type,attenuate));
395 if ((channel & BlueChannel) != 0)
396 q->blue=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
397 p->blue,noise_type,attenuate));
398 if ((channel & OpacityChannel) != 0)
399 q->opacity=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
400 p->opacity,noise_type,attenuate));
401 if (((channel & IndexChannel) != 0) &&
402 (image->colorspace == CMYKColorspace))
403 noise_indexes[x]=(IndexPacket) ClampToQuantum(GenerateDifferentialNoise(
404 random_info[id],indexes[x],noise_type,attenuate));
408 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
409 if (sync == MagickFalse)
411 if (image->progress_monitor != (MagickProgressMonitor) NULL)
416 #if defined(MAGICKCORE_OPENMP_SUPPORT)
417 #pragma omp critical (MagickCore_AddNoiseImage)
419 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
421 if (proceed == MagickFalse)
425 noise_view=DestroyCacheView(noise_view);
426 image_view=DestroyCacheView(image_view);
427 random_info=DestroyRandomInfoThreadSet(random_info);
428 if (status == MagickFalse)
429 noise_image=DestroyImage(noise_image);
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 % B l u e S h i f t I m a g e %
442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 % BlueShiftImage() mutes the colors of the image to simulate a scene at
445 % nighttime in the moonlight.
447 % The format of the BlueShiftImage method is:
449 % Image *BlueShiftImage(const Image *image,const double factor,
450 % ExceptionInfo *exception)
452 % A description of each parameter follows:
454 % o image: the image.
456 % o factor: the shift factor.
458 % o exception: return any errors or warnings in this structure.
461 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
462 ExceptionInfo *exception)
464 #define BlueShiftImageTag "BlueShift/Image"
483 Allocate blue shift image.
485 assert(image != (const Image *) NULL);
486 assert(image->signature == MagickSignature);
487 if (image->debug != MagickFalse)
488 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
489 assert(exception != (ExceptionInfo *) NULL);
490 assert(exception->signature == MagickSignature);
491 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
493 if (shift_image == (Image *) NULL)
494 return((Image *) NULL);
495 if (SetImageStorageClass(shift_image,DirectClass) == MagickFalse)
497 InheritException(exception,&shift_image->exception);
498 shift_image=DestroyImage(shift_image);
499 return((Image *) NULL);
502 Blue-shift DirectClass image.
506 image_view=AcquireCacheView(image);
507 shift_view=AcquireCacheView(shift_image);
508 #if defined(MAGICKCORE_OPENMP_SUPPORT)
509 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
511 for (y=0; y < (ssize_t) image->rows; y++)
522 register const PixelPacket
531 if (status == MagickFalse)
533 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
534 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
536 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
541 for (x=0; x < (ssize_t) image->columns; x++)
543 quantum=GetRedPixelComponent(p);
544 if (p->green < quantum)
545 quantum=GetGreenPixelComponent(p);
546 if (p->blue < quantum)
547 quantum=GetBluePixelComponent(p);
548 pixel.red=0.5*(p->red+factor*quantum);
549 pixel.green=0.5*(p->green+factor*quantum);
550 pixel.blue=0.5*(p->blue+factor*quantum);
551 quantum=GetRedPixelComponent(p);
552 if (p->green > quantum)
553 quantum=GetGreenPixelComponent(p);
554 if (p->blue > quantum)
555 quantum=GetBluePixelComponent(p);
556 pixel.red=0.5*(pixel.red+factor*quantum);
557 pixel.green=0.5*(pixel.green+factor*quantum);
558 pixel.blue=0.5*(pixel.blue+factor*quantum);
559 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
560 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
561 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
565 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
566 if (sync == MagickFalse)
568 if (image->progress_monitor != (MagickProgressMonitor) NULL)
573 #if defined(MAGICKCORE_OPENMP_SUPPORT)
574 #pragma omp critical (MagickCore_BlueShiftImage)
576 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
578 if (proceed == MagickFalse)
582 image_view=DestroyCacheView(image_view);
583 shift_view=DestroyCacheView(shift_view);
584 if (status == MagickFalse)
585 shift_image=DestroyImage(shift_image);
590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
594 % C h a r c o a l I m a g e %
598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600 % CharcoalImage() creates a new image that is a copy of an existing one with
601 % the edge highlighted. It allocates the memory necessary for the new Image
602 % structure and returns a pointer to the new image.
604 % The format of the CharcoalImage method is:
606 % Image *CharcoalImage(const Image *image,const double radius,
607 % const double sigma,ExceptionInfo *exception)
609 % A description of each parameter follows:
611 % o image: the image.
613 % o radius: the radius of the pixel neighborhood.
615 % o sigma: the standard deviation of the Gaussian, in pixels.
617 % o exception: return any errors or warnings in this structure.
620 MagickExport Image *CharcoalImage(const Image *image,const double radius,
621 const double sigma,ExceptionInfo *exception)
628 assert(image != (Image *) NULL);
629 assert(image->signature == MagickSignature);
630 if (image->debug != MagickFalse)
631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
632 assert(exception != (ExceptionInfo *) NULL);
633 assert(exception->signature == MagickSignature);
634 clone_image=CloneImage(image,0,0,MagickTrue,exception);
635 if (clone_image == (Image *) NULL)
636 return((Image *) NULL);
637 (void) SetImageType(clone_image,GrayscaleType);
638 edge_image=EdgeImage(clone_image,radius,exception);
639 clone_image=DestroyImage(clone_image);
640 if (edge_image == (Image *) NULL)
641 return((Image *) NULL);
642 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
643 edge_image=DestroyImage(edge_image);
644 if (charcoal_image == (Image *) NULL)
645 return((Image *) NULL);
646 (void) NormalizeImage(charcoal_image);
647 (void) NegateImage(charcoal_image,MagickFalse);
648 (void) SetImageType(charcoal_image,GrayscaleType);
649 return(charcoal_image);
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 % C o l o r i z e I m a g e %
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 % ColorizeImage() blends the fill color with each pixel in the image.
664 % A percentage blend is specified with opacity. Control the application
665 % of different color components by specifying a different percentage for
666 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
668 % The format of the ColorizeImage method is:
670 % Image *ColorizeImage(const Image *image,const char *opacity,
671 % const PixelPacket colorize,ExceptionInfo *exception)
673 % A description of each parameter follows:
675 % o image: the image.
677 % o opacity: A character string indicating the level of opacity as a
680 % o colorize: A color value.
682 % o exception: return any errors or warnings in this structure.
685 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
686 const PixelPacket colorize,ExceptionInfo *exception)
688 #define ColorizeImageTag "Colorize/Image"
716 Allocate colorized image.
718 assert(image != (const Image *) NULL);
719 assert(image->signature == MagickSignature);
720 if (image->debug != MagickFalse)
721 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
722 assert(exception != (ExceptionInfo *) NULL);
723 assert(exception->signature == MagickSignature);
724 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
726 if (colorize_image == (Image *) NULL)
727 return((Image *) NULL);
728 if (SetImageStorageClass(colorize_image,DirectClass) == MagickFalse)
730 InheritException(exception,&colorize_image->exception);
731 colorize_image=DestroyImage(colorize_image);
732 return((Image *) NULL);
734 if (opacity == (const char *) NULL)
735 return(colorize_image);
737 Determine RGB values of the pen color.
739 flags=ParseGeometry(opacity,&geometry_info);
740 pixel.red=geometry_info.rho;
741 pixel.green=geometry_info.rho;
742 pixel.blue=geometry_info.rho;
743 pixel.opacity=(MagickRealType) OpaqueOpacity;
744 if ((flags & SigmaValue) != 0)
745 pixel.green=geometry_info.sigma;
746 if ((flags & XiValue) != 0)
747 pixel.blue=geometry_info.xi;
748 if ((flags & PsiValue) != 0)
749 pixel.opacity=geometry_info.psi;
751 Colorize DirectClass image.
755 image_view=AcquireCacheView(image);
756 colorize_view=AcquireCacheView(colorize_image);
757 #if defined(MAGICKCORE_OPENMP_SUPPORT)
758 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
760 for (y=0; y < (ssize_t) image->rows; y++)
765 register const PixelPacket
774 if (status == MagickFalse)
776 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
777 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
779 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
784 for (x=0; x < (ssize_t) image->columns; x++)
786 q->red=(Quantum) ((p->red*(100.0-pixel.red)+
787 colorize.red*pixel.red)/100.0);
788 q->green=(Quantum) ((p->green*(100.0-pixel.green)+
789 colorize.green*pixel.green)/100.0);
790 q->blue=(Quantum) ((p->blue*(100.0-pixel.blue)+
791 colorize.blue*pixel.blue)/100.0);
792 q->opacity=(Quantum) ((p->opacity*(100.0-pixel.opacity)+
793 colorize.opacity*pixel.opacity)/100.0);
797 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
798 if (sync == MagickFalse)
800 if (image->progress_monitor != (MagickProgressMonitor) NULL)
805 #if defined(MAGICKCORE_OPENMP_SUPPORT)
806 #pragma omp critical (MagickCore_ColorizeImage)
808 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
809 if (proceed == MagickFalse)
813 image_view=DestroyCacheView(image_view);
814 colorize_view=DestroyCacheView(colorize_view);
815 if (status == MagickFalse)
816 colorize_image=DestroyImage(colorize_image);
817 return(colorize_image);
821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825 % C o l o r M a t r i x I m a g e %
829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
831 % ColorMatrixImage() applies color transformation to an image. This method
832 % permits saturation changes, hue rotation, luminance to alpha, and various
833 % other effects. Although variable-sized transformation matrices can be used,
834 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
835 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
836 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
837 % and offsets are normalized (divide Flash offset by 255).
839 % The format of the ColorMatrixImage method is:
841 % Image *ColorMatrixImage(const Image *image,
842 % const KernelInfo *color_matrix,ExceptionInfo *exception)
844 % A description of each parameter follows:
846 % o image: the image.
848 % o color_matrix: the color matrix.
850 % o exception: return any errors or warnings in this structure.
853 MagickExport Image *ColorMatrixImage(const Image *image,
854 const KernelInfo *color_matrix,ExceptionInfo *exception)
856 #define ColorMatrixImageTag "ColorMatrix/Image"
865 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
866 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
867 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
868 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
869 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
870 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
893 assert(image != (Image *) NULL);
894 assert(image->signature == MagickSignature);
895 if (image->debug != MagickFalse)
896 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
897 assert(exception != (ExceptionInfo *) NULL);
898 assert(exception->signature == MagickSignature);
900 for (v=0; v < (ssize_t) color_matrix->height; v++)
901 for (u=0; u < (ssize_t) color_matrix->width; u++)
903 if ((v < 6) && (u < 6))
904 ColorMatrix[v][u]=color_matrix->values[i];
908 Initialize color image.
910 color_image=CloneImage(image,0,0,MagickTrue,exception);
911 if (color_image == (Image *) NULL)
912 return((Image *) NULL);
913 if (SetImageStorageClass(color_image,DirectClass) == MagickFalse)
915 InheritException(exception,&color_image->exception);
916 color_image=DestroyImage(color_image);
917 return((Image *) NULL);
919 if (image->debug != MagickFalse)
922 format[MaxTextExtent],
925 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
926 " ColorMatrix image with color matrix:");
927 message=AcquireString("");
928 for (v=0; v < 6; v++)
931 (void) FormatMagickString(format,MaxTextExtent,"%.20g: ",(double) v);
932 (void) ConcatenateString(&message,format);
933 for (u=0; u < 6; u++)
935 (void) FormatMagickString(format,MaxTextExtent,"%+f ",
937 (void) ConcatenateString(&message,format);
939 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
941 message=DestroyString(message);
948 image_view=AcquireCacheView(image);
949 color_view=AcquireCacheView(color_image);
950 #if defined(MAGICKCORE_OPENMP_SUPPORT)
951 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
953 for (y=0; y < (ssize_t) image->rows; y++)
958 register const IndexPacket
961 register const PixelPacket
968 *restrict color_indexes;
973 if (status == MagickFalse)
975 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
976 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
978 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
983 indexes=GetCacheViewVirtualIndexQueue(image_view);
984 color_indexes=GetCacheViewAuthenticIndexQueue(color_view);
985 for (x=0; x < (ssize_t) image->columns; x++)
993 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
994 for (v=0; v < (ssize_t) height; v++)
996 pixel=ColorMatrix[v][0]*p->red+ColorMatrix[v][1]*p->green+
997 ColorMatrix[v][2]*p->blue;
998 if (image->matte != MagickFalse)
999 pixel+=ColorMatrix[v][3]*(QuantumRange-p->opacity);
1000 if (image->colorspace == CMYKColorspace)
1001 pixel+=ColorMatrix[v][4]*indexes[x];
1002 pixel+=QuantumRange*ColorMatrix[v][5];
1005 case 0: q->red=ClampToQuantum(pixel); break;
1006 case 1: q->green=ClampToQuantum(pixel); break;
1007 case 2: q->blue=ClampToQuantum(pixel); break;
1010 if (image->matte != MagickFalse)
1011 q->opacity=ClampToQuantum(QuantumRange-pixel);
1016 if (image->colorspace == CMYKColorspace)
1017 color_indexes[x]=ClampToQuantum(pixel);
1025 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1027 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1032 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1033 #pragma omp critical (MagickCore_ColorMatrixImage)
1035 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1037 if (proceed == MagickFalse)
1041 color_view=DestroyCacheView(color_view);
1042 image_view=DestroyCacheView(image_view);
1043 if (status == MagickFalse)
1044 color_image=DestroyImage(color_image);
1045 return(color_image);
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1053 + D e s t r o y F x I n f o %
1057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1061 % The format of the DestroyFxInfo method is:
1063 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1065 % A description of each parameter follows:
1067 % o fx_info: the fx info.
1070 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1075 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1076 fx_info->expression=DestroyString(fx_info->expression);
1077 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1078 fx_info->colors=DestroySplayTree(fx_info->colors);
1079 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
1080 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1081 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
1082 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1083 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1092 + 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 %
1096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1098 % FxEvaluateChannelExpression() evaluates an expression and returns the
1101 % The format of the FxEvaluateExpression method is:
1103 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1104 % const ChannelType channel,const ssize_t x,const ssize_t y,
1105 % MagickRealType *alpha,Exceptioninfo *exception)
1106 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1107 % MagickRealType *alpha,Exceptioninfo *exception)
1109 % A description of each parameter follows:
1111 % o fx_info: the fx info.
1113 % o channel: the channel.
1115 % o x,y: the pixel position.
1117 % o alpha: the result.
1119 % o exception: return any errors or warnings in this structure.
1123 static inline double MagickMax(const double x,const double y)
1130 static inline double MagickMin(const double x,const double y)
1137 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1138 ChannelType channel,const char *symbol,ExceptionInfo *exception)
1142 statistic[MaxTextExtent];
1150 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1152 switch (*++p) /* e.g. depth.r */
1154 case 'r': channel=RedChannel; break;
1155 case 'g': channel=GreenChannel; break;
1156 case 'b': channel=BlueChannel; break;
1157 case 'c': channel=CyanChannel; break;
1158 case 'm': channel=MagentaChannel; break;
1159 case 'y': channel=YellowChannel; break;
1160 case 'k': channel=BlackChannel; break;
1163 (void) FormatMagickString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1164 (double) channel,symbol);
1165 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1166 if (value != (const char *) NULL)
1167 return(QuantumScale*StringToDouble(value));
1168 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1169 if (LocaleNCompare(symbol,"depth",5) == 0)
1174 depth=GetImageChannelDepth(image,channel,exception);
1175 (void) FormatMagickString(statistic,MaxTextExtent,"%.20g",(double)
1178 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1184 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1186 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
1188 if (LocaleNCompare(symbol,"maxima",6) == 0)
1194 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1195 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
1197 if (LocaleNCompare(symbol,"mean",4) == 0)
1203 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1205 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
1207 if (LocaleNCompare(symbol,"minima",6) == 0)
1213 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1214 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
1216 if (LocaleNCompare(symbol,"skewness",8) == 0)
1222 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1224 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
1226 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1232 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1234 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
1235 standard_deviation);
1237 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1238 ConstantString(statistic));
1239 return(QuantumScale*StringToDouble(statistic));
1242 static MagickRealType
1243 FxEvaluateSubexpression(FxInfo *,const ChannelType,const ssize_t,
1244 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1246 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1247 const ssize_t x,const ssize_t y,const char *expression,
1248 ExceptionInfo *exception)
1254 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1255 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1258 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1259 const ssize_t x,const ssize_t y,const char *expression,
1260 ExceptionInfo *exception)
1266 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1267 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1270 static inline const char *FxSubexpression(const char *expression,
1271 ExceptionInfo *exception)
1280 subexpression=expression;
1281 while ((*subexpression != '\0') &&
1282 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1284 if (strchr("(",(int) *subexpression) != (char *) NULL)
1287 if (strchr(")",(int) *subexpression) != (char *) NULL)
1291 if (*subexpression == '\0')
1292 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1293 "UnbalancedParenthesis","`%s'",expression);
1294 return(subexpression);
1297 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1298 const ssize_t x,const ssize_t y,const char *expression,
1299 ExceptionInfo *exception)
1303 subexpression[MaxTextExtent],
1304 symbol[MaxTextExtent];
1313 InterpolatePixelMethod
1336 i=GetImageIndexInList(fx_info->images);
1340 if (isalpha((int) *(p+1)) == 0)
1342 if (strchr("suv",(int) *p) != (char *) NULL)
1349 i=GetImageIndexInList(fx_info->images);
1352 case 'u': i=0; break;
1353 case 'v': i=1; break;
1360 for (p++; *p != '\0'; )
1374 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1376 i=(ssize_t) (alpha+0.5);
1382 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1389 for (p++; *p != '\0'; )
1403 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1414 for (p++; *p != '\0'; )
1428 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1438 length=GetImageListLength(fx_info->images);
1440 i+=(ssize_t) length;
1442 image=GetImageFromList(fx_info->images,i);
1443 if (image == (Image *) NULL)
1445 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1446 "NoSuchImage","`%s'",expression);
1449 interpolate_method=image->interpolate == UndefinedInterpolatePixel ?
1450 NearestNeighborInterpolatePixel : image->interpolate;
1451 (void) InterpolateMagickPixelPacket(image,fx_info->view[i],interpolate_method,
1452 point.x,point.y,&pixel,exception);
1453 if ((strlen(p) > 2) &&
1454 (LocaleCompare(p,"intensity") != 0) &&
1455 (LocaleCompare(p,"luminance") != 0) &&
1456 (LocaleCompare(p,"hue") != 0) &&
1457 (LocaleCompare(p,"saturation") != 0) &&
1458 (LocaleCompare(p,"lightness") != 0))
1461 name[MaxTextExtent];
1463 (void) CopyMagickString(name,p,MaxTextExtent);
1464 for (q=name+(strlen(name)-1); q > name; q--)
1474 if ((strlen(name) > 2) &&
1475 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1480 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1482 if (color != (MagickPixelPacket *) NULL)
1488 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1490 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1491 CloneMagickPixelPacket(&pixel));
1496 (void) CopyMagickString(symbol,p,MaxTextExtent);
1497 StripString(symbol);
1498 if (*symbol == '\0')
1502 case RedChannel: return(QuantumScale*pixel.red);
1503 case GreenChannel: return(QuantumScale*pixel.green);
1504 case BlueChannel: return(QuantumScale*pixel.blue);
1505 case OpacityChannel:
1510 if (pixel.matte == MagickFalse)
1512 alpha=(MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel));
1517 if (image->colorspace != CMYKColorspace)
1519 (void) ThrowMagickException(exception,GetMagickModule(),
1520 OptionError,"ColorSeparatedImageRequired","`%s'",
1524 return(QuantumScale*pixel.index);
1526 case DefaultChannels:
1528 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1533 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1534 "UnableToParseExpression","`%s'",p);
1542 if (LocaleCompare(symbol,"a") == 0)
1543 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1549 if (LocaleCompare(symbol,"b") == 0)
1550 return(QuantumScale*pixel.blue);
1556 if (LocaleNCompare(symbol,"channel",7) == 0)
1564 flags=ParseGeometry(symbol+7,&channel_info);
1565 if (image->colorspace == CMYKColorspace)
1570 if ((flags & RhoValue) == 0)
1572 return(channel_info.rho);
1574 case MagentaChannel:
1576 if ((flags & SigmaValue) == 0)
1578 return(channel_info.sigma);
1582 if ((flags & XiValue) == 0)
1584 return(channel_info.xi);
1588 if ((flags & PsiValue) == 0)
1590 return(channel_info.psi);
1592 case OpacityChannel:
1594 if ((flags & ChiValue) == 0)
1596 return(channel_info.chi);
1605 if ((flags & RhoValue) == 0)
1607 return(channel_info.rho);
1611 if ((flags & SigmaValue) == 0)
1613 return(channel_info.sigma);
1617 if ((flags & XiValue) == 0)
1619 return(channel_info.xi);
1621 case OpacityChannel:
1623 if ((flags & PsiValue) == 0)
1625 return(channel_info.psi);
1629 if ((flags & ChiValue) == 0)
1631 return(channel_info.chi);
1638 if (LocaleCompare(symbol,"c") == 0)
1639 return(QuantumScale*pixel.red);
1645 if (LocaleNCompare(symbol,"depth",5) == 0)
1646 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1652 if (LocaleCompare(symbol,"g") == 0)
1653 return(QuantumScale*pixel.green);
1659 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1660 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1661 if (LocaleCompare(symbol,"k") == 0)
1663 if (image->colorspace != CMYKColorspace)
1665 (void) ThrowMagickException(exception,GetMagickModule(),
1666 OptionError,"ColorSeparatedImageRequired","`%s'",
1670 return(QuantumScale*pixel.index);
1677 if (LocaleCompare(symbol,"h") == 0)
1678 return((MagickRealType) image->rows);
1679 if (LocaleCompare(symbol,"hue") == 0)
1686 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1687 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1695 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1696 (LocaleCompare(symbol,"image.minima") == 0) ||
1697 (LocaleCompare(symbol,"image.maxima") == 0) ||
1698 (LocaleCompare(symbol,"image.mean") == 0) ||
1699 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1700 (LocaleCompare(symbol,"image.skewness") == 0) ||
1701 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1702 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1703 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1704 return(image->x_resolution);
1705 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1706 return(image->y_resolution);
1707 if (LocaleCompare(symbol,"intensity") == 0)
1708 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1709 if (LocaleCompare(symbol,"i") == 0)
1710 return((MagickRealType) x);
1716 if (LocaleCompare(symbol,"j") == 0)
1717 return((MagickRealType) y);
1723 if (LocaleCompare(symbol,"lightness") == 0)
1730 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1731 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1734 if (LocaleCompare(symbol,"luminance") == 0)
1739 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1740 return(QuantumScale*luminence);
1747 if (LocaleNCompare(symbol,"maxima",6) == 0)
1748 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1749 if (LocaleNCompare(symbol,"mean",4) == 0)
1750 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1751 if (LocaleNCompare(symbol,"minima",6) == 0)
1752 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1753 if (LocaleCompare(symbol,"m") == 0)
1754 return(QuantumScale*pixel.blue);
1760 if (LocaleCompare(symbol,"n") == 0)
1761 return((MagickRealType) GetImageListLength(fx_info->images));
1767 if (LocaleCompare(symbol,"o") == 0)
1768 return(QuantumScale*pixel.opacity);
1774 if (LocaleCompare(symbol,"page.height") == 0)
1775 return((MagickRealType) image->page.height);
1776 if (LocaleCompare(symbol,"page.width") == 0)
1777 return((MagickRealType) image->page.width);
1778 if (LocaleCompare(symbol,"page.x") == 0)
1779 return((MagickRealType) image->page.x);
1780 if (LocaleCompare(symbol,"page.y") == 0)
1781 return((MagickRealType) image->page.y);
1787 if (LocaleCompare(symbol,"resolution.x") == 0)
1788 return(image->x_resolution);
1789 if (LocaleCompare(symbol,"resolution.y") == 0)
1790 return(image->y_resolution);
1791 if (LocaleCompare(symbol,"r") == 0)
1792 return(QuantumScale*pixel.red);
1798 if (LocaleCompare(symbol,"saturation") == 0)
1805 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1806 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1809 if (LocaleNCompare(symbol,"skewness",8) == 0)
1810 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1811 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1812 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1818 if (LocaleCompare(symbol,"t") == 0)
1819 return((MagickRealType) GetImageIndexInList(fx_info->images));
1825 if (LocaleCompare(symbol,"w") == 0)
1826 return((MagickRealType) image->columns);
1832 if (LocaleCompare(symbol,"y") == 0)
1833 return(QuantumScale*pixel.green);
1839 if (LocaleCompare(symbol,"z") == 0)
1844 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1845 fx_info->exception);
1853 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1854 if (value != (const char *) NULL)
1855 return((MagickRealType) StringToDouble(value));
1856 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1857 "UnableToParseExpression","`%s'",symbol);
1861 static const char *FxOperatorPrecedence(const char *expression,
1862 ExceptionInfo *exception)
1866 UndefinedPrecedence,
1868 BitwiseComplementPrecedence,
1870 ExponentialNotationPrecedence,
1874 RelationalPrecedence,
1875 EquivalencyPrecedence,
1876 BitwiseAndPrecedence,
1877 BitwiseOrPrecedence,
1878 LogicalAndPrecedence,
1879 LogicalOrPrecedence,
1881 AssignmentPrecedence,
1901 subexpression=(const char *) NULL;
1902 target=NullPrecedence;
1903 while (*expression != '\0')
1905 precedence=UndefinedPrecedence;
1906 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1911 switch (*expression)
1916 if (LocaleNCompare(expression,"atan2",5) == 0)
1926 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1927 (LocaleNCompare(expression,"j1",2) == 0))
1936 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1943 if ((c == (int) '{') || (c == (int) '['))
1946 if ((c == (int) '}') || (c == (int) ']'))
1949 switch ((unsigned char) *expression)
1954 precedence=BitwiseComplementPrecedence;
1960 precedence=ExponentPrecedence;
1965 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1966 (strchr(")",c) != (char *) NULL))) &&
1967 (((islower((int) ((char) *expression)) != 0) ||
1968 (strchr("(",(int) *expression) != (char *) NULL)) ||
1969 ((isdigit((int) ((char) c)) == 0) &&
1970 (isdigit((int) ((char) *expression)) != 0))) &&
1971 (strchr("xy",(int) *expression) == (char *) NULL))
1972 precedence=MultiplyPrecedence;
1979 precedence=MultiplyPrecedence;
1985 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1987 precedence=AdditionPrecedence;
1990 case LeftShiftOperator:
1991 case RightShiftOperator:
1993 precedence=ShiftPrecedence;
1997 case LessThanEqualOperator:
1998 case GreaterThanEqualOperator:
2001 precedence=RelationalPrecedence;
2005 case NotEqualOperator:
2007 precedence=EquivalencyPrecedence;
2012 precedence=BitwiseAndPrecedence;
2017 precedence=BitwiseOrPrecedence;
2020 case LogicalAndOperator:
2022 precedence=LogicalAndPrecedence;
2025 case LogicalOrOperator:
2027 precedence=LogicalOrPrecedence;
2030 case ExponentialNotation:
2032 precedence=ExponentialNotationPrecedence;
2038 precedence=TernaryPrecedence;
2043 precedence=AssignmentPrecedence;
2048 precedence=CommaPrecedence;
2053 precedence=SeparatorPrecedence;
2057 if ((precedence == BitwiseComplementPrecedence) ||
2058 (precedence == TernaryPrecedence) ||
2059 (precedence == AssignmentPrecedence))
2061 if (precedence > target)
2064 Right-to-left associativity.
2067 subexpression=expression;
2071 if (precedence >= target)
2074 Left-to-right associativity.
2077 subexpression=expression;
2079 if (strchr("(",(int) *expression) != (char *) NULL)
2080 expression=FxSubexpression(expression,exception);
2081 c=(int) (*expression++);
2083 return(subexpression);
2086 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2087 const ChannelType channel,const ssize_t x,const ssize_t y,
2088 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2092 subexpression[MaxTextExtent];
2102 if (exception->severity != UndefinedException)
2104 while (isspace((int) *expression) != 0)
2106 if (*expression == '\0')
2108 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2109 "MissingExpression","`%s'",expression);
2112 *subexpression='\0';
2113 p=FxOperatorPrecedence(expression,exception);
2114 if (p != (const char *) NULL)
2116 (void) CopyMagickString(subexpression,expression,(size_t)
2118 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2120 switch ((unsigned char) *p)
2124 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2125 *beta=(MagickRealType) (~(size_t) *beta);
2130 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2131 return(*beta == 0.0 ? 1.0 : 0.0);
2135 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2136 channel,x,y,++p,beta,exception));
2140 case ExponentialNotation:
2142 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2143 return(alpha*(*beta));
2147 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2150 if (exception->severity == UndefinedException)
2151 (void) ThrowMagickException(exception,GetMagickModule(),
2152 OptionError,"DivideByZero","`%s'",expression);
2155 return(alpha/(*beta));
2159 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2160 *beta=fabs(floor(((double) *beta)+0.5));
2163 (void) ThrowMagickException(exception,GetMagickModule(),
2164 OptionError,"DivideByZero","`%s'",expression);
2167 return(fmod((double) alpha,(double) *beta));
2171 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2172 return(alpha+(*beta));
2176 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2177 return(alpha-(*beta));
2179 case LeftShiftOperator:
2181 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2182 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2186 case RightShiftOperator:
2188 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2189 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2195 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2196 return(alpha < *beta ? 1.0 : 0.0);
2198 case LessThanEqualOperator:
2200 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2201 return(alpha <= *beta ? 1.0 : 0.0);
2205 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2206 return(alpha > *beta ? 1.0 : 0.0);
2208 case GreaterThanEqualOperator:
2210 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2211 return(alpha >= *beta ? 1.0 : 0.0);
2215 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2216 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2218 case NotEqualOperator:
2220 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2221 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2225 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2226 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2232 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2233 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2237 case LogicalAndOperator:
2239 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2240 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2243 case LogicalOrOperator:
2245 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2246 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2254 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2256 p=StringToken(":",&q);
2257 if (q == (char *) NULL)
2259 (void) ThrowMagickException(exception,GetMagickModule(),
2260 OptionError,"UnableToParseExpression","`%s'",subexpression);
2263 if (fabs((double) alpha) > MagickEpsilon)
2264 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2266 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2272 numeric[MaxTextExtent];
2275 while (isalpha((int) ((unsigned char) *q)) != 0)
2279 (void) ThrowMagickException(exception,GetMagickModule(),
2280 OptionError,"UnableToParseExpression","`%s'",subexpression);
2283 ClearMagickException(exception);
2284 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2285 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2287 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2288 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2289 subexpression),ConstantString(numeric));
2294 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2299 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2304 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2310 if (strchr("(",(int) *expression) != (char *) NULL)
2312 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2313 subexpression[strlen(subexpression)-1]='\0';
2314 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2318 switch (*expression)
2322 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2328 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2334 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2336 return((MagickRealType) (~(size_t) (gamma+0.5)));
2341 if (LocaleNCompare(expression,"abs",3) == 0)
2343 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2345 return((MagickRealType) fabs((double) alpha));
2347 if (LocaleNCompare(expression,"acos",4) == 0)
2349 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2351 return((MagickRealType) acos((double) alpha));
2353 #if defined(MAGICKCORE_HAVE_J1)
2354 if (LocaleNCompare(expression,"airy",4) == 0)
2356 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2360 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2361 return(gamma*gamma);
2364 if (LocaleNCompare(expression,"asin",4) == 0)
2366 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2368 return((MagickRealType) asin((double) alpha));
2370 if (LocaleNCompare(expression,"alt",3) == 0)
2372 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2374 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2376 if (LocaleNCompare(expression,"atan2",5) == 0)
2378 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2380 return((MagickRealType) atan2((double) alpha,(double) *beta));
2382 if (LocaleNCompare(expression,"atan",4) == 0)
2384 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2386 return((MagickRealType) atan((double) alpha));
2388 if (LocaleCompare(expression,"a") == 0)
2389 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2395 if (LocaleCompare(expression,"b") == 0)
2396 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2402 if (LocaleNCompare(expression,"ceil",4) == 0)
2404 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2406 return((MagickRealType) ceil((double) alpha));
2408 if (LocaleNCompare(expression,"cosh",4) == 0)
2410 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2412 return((MagickRealType) cosh((double) alpha));
2414 if (LocaleNCompare(expression,"cos",3) == 0)
2416 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2418 return((MagickRealType) cos((double) alpha));
2420 if (LocaleCompare(expression,"c") == 0)
2421 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2427 if (LocaleNCompare(expression,"debug",5) == 0)
2432 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2434 if (fx_info->images->colorspace == CMYKColorspace)
2437 case CyanChannel: type="cyan"; break;
2438 case MagentaChannel: type="magenta"; break;
2439 case YellowChannel: type="yellow"; break;
2440 case OpacityChannel: type="opacity"; break;
2441 case BlackChannel: type="black"; break;
2442 default: type="unknown"; break;
2447 case RedChannel: type="red"; break;
2448 case GreenChannel: type="green"; break;
2449 case BlueChannel: type="blue"; break;
2450 case OpacityChannel: type="opacity"; break;
2451 default: type="unknown"; break;
2453 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2454 if (strlen(subexpression) > 1)
2455 subexpression[strlen(subexpression)-1]='\0';
2456 if (fx_info->file != (FILE *) NULL)
2457 (void) fprintf(fx_info->file,"%s[%.20g,%.20g].%s: %s=%.*g\n",
2458 fx_info->images->filename,(double) x,(double) y,type,
2459 subexpression,GetMagickPrecision(),(double) alpha);
2467 if (LocaleCompare(expression,"epsilon") == 0)
2468 return((MagickRealType) MagickEpsilon);
2469 if (LocaleNCompare(expression,"exp",3) == 0)
2471 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2473 return((MagickRealType) exp((double) alpha));
2475 if (LocaleCompare(expression,"e") == 0)
2476 return((MagickRealType) 2.7182818284590452354);
2482 if (LocaleNCompare(expression,"floor",5) == 0)
2484 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2486 return((MagickRealType) floor((double) alpha));
2493 if (LocaleCompare(expression,"g") == 0)
2494 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2500 if (LocaleCompare(expression,"h") == 0)
2501 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2502 if (LocaleCompare(expression,"hue") == 0)
2503 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2504 if (LocaleNCompare(expression,"hypot",5) == 0)
2506 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2508 return((MagickRealType) hypot((double) alpha,(double) *beta));
2515 if (LocaleCompare(expression,"k") == 0)
2516 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2522 if (LocaleCompare(expression,"intensity") == 0)
2523 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2524 if (LocaleNCompare(expression,"int",3) == 0)
2526 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2528 return((MagickRealType) floor(alpha));
2530 if (LocaleCompare(expression,"i") == 0)
2531 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2537 if (LocaleCompare(expression,"j") == 0)
2538 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2539 #if defined(MAGICKCORE_HAVE_J0)
2540 if (LocaleNCompare(expression,"j0",2) == 0)
2542 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2544 return((MagickRealType) j0((double) alpha));
2547 #if defined(MAGICKCORE_HAVE_J1)
2548 if (LocaleNCompare(expression,"j1",2) == 0)
2550 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2552 return((MagickRealType) j1((double) alpha));
2555 #if defined(MAGICKCORE_HAVE_J1)
2556 if (LocaleNCompare(expression,"jinc",4) == 0)
2558 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2562 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2572 if (LocaleNCompare(expression,"ln",2) == 0)
2574 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2576 return((MagickRealType) log((double) alpha));
2578 if (LocaleNCompare(expression,"logtwo",6) == 0)
2580 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2582 return((MagickRealType) log10((double) alpha))/log10(2.0);
2584 if (LocaleNCompare(expression,"log",3) == 0)
2586 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2588 return((MagickRealType) log10((double) alpha));
2590 if (LocaleCompare(expression,"lightness") == 0)
2591 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2597 if (LocaleCompare(expression,"MaxRGB") == 0)
2598 return((MagickRealType) QuantumRange);
2599 if (LocaleNCompare(expression,"maxima",6) == 0)
2601 if (LocaleNCompare(expression,"max",3) == 0)
2602 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2603 if (LocaleNCompare(expression,"minima",6) == 0)
2605 if (LocaleNCompare(expression,"min",3) == 0)
2606 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2607 if (LocaleNCompare(expression,"mod",3) == 0)
2609 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2611 return((MagickRealType) fmod((double) alpha,(double) *beta));
2613 if (LocaleCompare(expression,"m") == 0)
2614 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2620 if (LocaleCompare(expression,"n") == 0)
2621 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2627 if (LocaleCompare(expression,"Opaque") == 0)
2629 if (LocaleCompare(expression,"o") == 0)
2630 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2636 if (LocaleCompare(expression,"pi") == 0)
2637 return((MagickRealType) MagickPI);
2638 if (LocaleNCompare(expression,"pow",3) == 0)
2640 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2642 return((MagickRealType) pow((double) alpha,(double) *beta));
2644 if (LocaleCompare(expression,"p") == 0)
2645 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2651 if (LocaleCompare(expression,"QuantumRange") == 0)
2652 return((MagickRealType) QuantumRange);
2653 if (LocaleCompare(expression,"QuantumScale") == 0)
2654 return((MagickRealType) QuantumScale);
2660 if (LocaleNCompare(expression,"rand",4) == 0)
2661 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2662 if (LocaleNCompare(expression,"round",5) == 0)
2664 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2666 return((MagickRealType) floor((double) alpha+0.5));
2668 if (LocaleCompare(expression,"r") == 0)
2669 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2675 if (LocaleCompare(expression,"saturation") == 0)
2676 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2677 if (LocaleNCompare(expression,"sign",4) == 0)
2679 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2681 return(alpha < 0.0 ? -1.0 : 1.0);
2683 if (LocaleNCompare(expression,"sinc",4) == 0)
2685 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2689 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2693 if (LocaleNCompare(expression,"sinh",4) == 0)
2695 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2697 return((MagickRealType) sinh((double) alpha));
2699 if (LocaleNCompare(expression,"sin",3) == 0)
2701 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2703 return((MagickRealType) sin((double) alpha));
2705 if (LocaleNCompare(expression,"sqrt",4) == 0)
2707 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2709 return((MagickRealType) sqrt((double) alpha));
2711 if (LocaleCompare(expression,"s") == 0)
2712 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2718 if (LocaleNCompare(expression,"tanh",4) == 0)
2720 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2722 return((MagickRealType) tanh((double) alpha));
2724 if (LocaleNCompare(expression,"tan",3) == 0)
2726 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2728 return((MagickRealType) tan((double) alpha));
2730 if (LocaleCompare(expression,"Transparent") == 0)
2732 if (LocaleNCompare(expression,"trunc",5) == 0)
2734 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2737 return((MagickRealType) floor((double) alpha));
2738 return((MagickRealType) ceil((double) alpha));
2740 if (LocaleCompare(expression,"t") == 0)
2741 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2747 if (LocaleCompare(expression,"u") == 0)
2748 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2754 if (LocaleCompare(expression,"v") == 0)
2755 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2761 if (LocaleCompare(expression,"w") == 0)
2762 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2768 if (LocaleCompare(expression,"y") == 0)
2769 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2775 if (LocaleCompare(expression,"z") == 0)
2776 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2782 q=(char *) expression;
2783 alpha=strtod(expression,&q);
2784 if (q == expression)
2785 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2789 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2790 MagickRealType *alpha,ExceptionInfo *exception)
2795 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2799 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2800 MagickRealType *alpha,ExceptionInfo *exception)
2809 fx_info->file=(FILE *) NULL;
2810 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2815 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2816 const ChannelType channel,const ssize_t x,const ssize_t y,
2817 MagickRealType *alpha,ExceptionInfo *exception)
2823 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2825 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2839 % FxImage() applies a mathematical expression to the specified image.
2841 % The format of the FxImage method is:
2843 % Image *FxImage(const Image *image,const char *expression,
2844 % ExceptionInfo *exception)
2845 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2846 % const char *expression,ExceptionInfo *exception)
2848 % A description of each parameter follows:
2850 % o image: the image.
2852 % o channel: the channel.
2854 % o expression: A mathematical expression.
2856 % o exception: return any errors or warnings in this structure.
2860 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2865 assert(fx_info != (FxInfo **) NULL);
2866 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2867 if (fx_info[i] != (FxInfo *) NULL)
2868 fx_info[i]=DestroyFxInfo(fx_info[i]);
2869 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
2873 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2874 ExceptionInfo *exception)
2891 number_threads=GetOpenMPMaximumThreads();
2892 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
2893 if (fx_info == (FxInfo **) NULL)
2894 return((FxInfo **) NULL);
2895 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2896 if (*expression != '@')
2897 fx_expression=ConstantString(expression);
2899 fx_expression=FileToString(expression+1,~0,exception);
2900 for (i=0; i < (ssize_t) number_threads; i++)
2902 fx_info[i]=AcquireFxInfo(image,fx_expression);
2903 if (fx_info[i] == (FxInfo *) NULL)
2904 return(DestroyFxThreadSet(fx_info));
2905 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2907 fx_expression=DestroyString(fx_expression);
2911 MagickExport Image *FxImage(const Image *image,const char *expression,
2912 ExceptionInfo *exception)
2917 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2921 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2922 const char *expression,ExceptionInfo *exception)
2924 #define FxImageTag "Fx/Image"
2947 assert(image != (Image *) NULL);
2948 assert(image->signature == MagickSignature);
2949 if (image->debug != MagickFalse)
2950 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2951 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2952 if (fx_image == (Image *) NULL)
2953 return((Image *) NULL);
2954 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2956 InheritException(exception,&fx_image->exception);
2957 fx_image=DestroyImage(fx_image);
2958 return((Image *) NULL);
2960 fx_info=AcquireFxThreadSet(image,expression,exception);
2961 if (fx_info == (FxInfo **) NULL)
2963 fx_image=DestroyImage(fx_image);
2964 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2966 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2967 if (status == MagickFalse)
2969 fx_image=DestroyImage(fx_image);
2970 fx_info=DestroyFxThreadSet(fx_info);
2971 return((Image *) NULL);
2978 fx_view=AcquireCacheView(fx_image);
2979 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2980 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2982 for (y=0; y < (ssize_t) fx_image->rows; y++)
2985 id = GetOpenMPThreadId();
2990 register IndexPacket
2991 *restrict fx_indexes;
2996 register PixelPacket
2999 if (status == MagickFalse)
3001 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
3002 if (q == (PixelPacket *) NULL)
3007 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
3009 for (x=0; x < (ssize_t) fx_image->columns; x++)
3011 if ((channel & RedChannel) != 0)
3013 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
3015 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3017 if ((channel & GreenChannel) != 0)
3019 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
3021 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3023 if ((channel & BlueChannel) != 0)
3025 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
3027 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3029 if ((channel & OpacityChannel) != 0)
3031 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
3033 if (image->matte == MagickFalse)
3034 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3036 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
3037 QuantumRange*alpha));
3039 if (((channel & IndexChannel) != 0) &&
3040 (fx_image->colorspace == CMYKColorspace))
3042 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
3044 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
3045 QuantumRange*alpha);
3049 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3051 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3056 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3057 #pragma omp critical (MagickCore_FxImageChannel)
3059 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3060 if (proceed == MagickFalse)
3064 fx_view=DestroyCacheView(fx_view);
3065 fx_info=DestroyFxThreadSet(fx_info);
3066 if (status == MagickFalse)
3067 fx_image=DestroyImage(fx_image);
3072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3076 % I m p l o d e I m a g e %
3080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3082 % ImplodeImage() creates a new image that is a copy of an existing
3083 % one with the image pixels "implode" by the specified percentage. It
3084 % allocates the memory necessary for the new Image structure and returns a
3085 % pointer to the new image.
3087 % The format of the ImplodeImage method is:
3089 % Image *ImplodeImage(const Image *image,const double amount,
3090 % ExceptionInfo *exception)
3092 % A description of each parameter follows:
3094 % o implode_image: Method ImplodeImage returns a pointer to the image
3095 % after it is implode. A null image is returned if there is a memory
3098 % o image: the image.
3100 % o amount: Define the extent of the implosion.
3102 % o exception: return any errors or warnings in this structure.
3105 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3106 ExceptionInfo *exception)
3108 #define ImplodeImageTag "Implode/Image"
3137 Initialize implode image attributes.
3139 assert(image != (Image *) NULL);
3140 assert(image->signature == MagickSignature);
3141 if (image->debug != MagickFalse)
3142 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3143 assert(exception != (ExceptionInfo *) NULL);
3144 assert(exception->signature == MagickSignature);
3145 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3146 if (implode_image == (Image *) NULL)
3147 return((Image *) NULL);
3148 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3150 InheritException(exception,&implode_image->exception);
3151 implode_image=DestroyImage(implode_image);
3152 return((Image *) NULL);
3154 if (implode_image->background_color.opacity != OpaqueOpacity)
3155 implode_image->matte=MagickTrue;
3157 Compute scaling factor.
3161 center.x=0.5*image->columns;
3162 center.y=0.5*image->rows;
3164 if (image->columns > image->rows)
3165 scale.y=(double) image->columns/(double) image->rows;
3167 if (image->columns < image->rows)
3169 scale.x=(double) image->rows/(double) image->columns;
3177 GetMagickPixelPacket(implode_image,&zero);
3178 image_view=AcquireCacheView(image);
3179 implode_view=AcquireCacheView(implode_image);
3180 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3181 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3183 for (y=0; y < (ssize_t) image->rows; y++)
3194 register IndexPacket
3195 *restrict implode_indexes;
3200 register PixelPacket
3203 if (status == MagickFalse)
3205 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3207 if (q == (PixelPacket *) NULL)
3212 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
3213 delta.y=scale.y*(double) (y-center.y);
3215 for (x=0; x < (ssize_t) image->columns; x++)
3218 Determine if the pixel is within an ellipse.
3220 delta.x=scale.x*(double) (x-center.x);
3221 distance=delta.x*delta.x+delta.y*delta.y;
3222 if (distance < (radius*radius))
3232 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3233 radius/2)),-amount);
3234 (void) InterpolateMagickPixelPacket(image,image_view,
3235 UndefinedInterpolatePixel,(double) (factor*delta.x/scale.x+
3236 center.x),(double) (factor*delta.y/scale.y+center.y),&pixel,
3238 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
3242 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3244 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3249 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3250 #pragma omp critical (MagickCore_ImplodeImage)
3252 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3253 if (proceed == MagickFalse)
3257 implode_view=DestroyCacheView(implode_view);
3258 image_view=DestroyCacheView(image_view);
3259 if (status == MagickFalse)
3260 implode_image=DestroyImage(implode_image);
3261 return(implode_image);
3265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3269 % M o r p h I m a g e s %
3273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3275 % The MorphImages() method requires a minimum of two images. The first
3276 % image is transformed into the second by a number of intervening images
3277 % as specified by frames.
3279 % The format of the MorphImage method is:
3281 % Image *MorphImages(const Image *image,const size_t number_frames,
3282 % ExceptionInfo *exception)
3284 % A description of each parameter follows:
3286 % o image: the image.
3288 % o number_frames: Define the number of in-between image to generate.
3289 % The more in-between frames, the smoother the morph.
3291 % o exception: return any errors or warnings in this structure.
3294 MagickExport Image *MorphImages(const Image *image,
3295 const size_t number_frames,ExceptionInfo *exception)
3297 #define MorphImageTag "Morph/Image"
3313 register const Image
3323 Clone first frame in sequence.
3325 assert(image != (Image *) NULL);
3326 assert(image->signature == MagickSignature);
3327 if (image->debug != MagickFalse)
3328 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3329 assert(exception != (ExceptionInfo *) NULL);
3330 assert(exception->signature == MagickSignature);
3331 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3332 if (morph_images == (Image *) NULL)
3333 return((Image *) NULL);
3334 if (GetNextImageInList(image) == (Image *) NULL)
3339 for (i=1; i < (ssize_t) number_frames; i++)
3341 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3342 if (morph_image == (Image *) NULL)
3344 morph_images=DestroyImageList(morph_images);
3345 return((Image *) NULL);
3347 AppendImageToList(&morph_images,morph_image);
3348 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3353 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3355 if (proceed == MagickFalse)
3359 return(GetFirstImageInList(morph_images));
3362 Morph image sequence.
3367 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3369 for (i=0; i < (ssize_t) number_frames; i++)
3375 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3377 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3378 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3379 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3380 next->filter,next->blur,exception);
3381 if (morph_image == (Image *) NULL)
3383 morph_images=DestroyImageList(morph_images);
3384 return((Image *) NULL);
3386 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3388 InheritException(exception,&morph_image->exception);
3389 morph_image=DestroyImage(morph_image);
3390 return((Image *) NULL);
3392 AppendImageToList(&morph_images,morph_image);
3393 morph_images=GetLastImageInList(morph_images);
3394 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3395 morph_images->rows,GetNextImageInList(next)->filter,
3396 GetNextImageInList(next)->blur,exception);
3397 if (morph_image == (Image *) NULL)
3399 morph_images=DestroyImageList(morph_images);
3400 return((Image *) NULL);
3402 image_view=AcquireCacheView(morph_image);
3403 morph_view=AcquireCacheView(morph_images);
3404 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3405 #pragma omp parallel for schedule(dynamic,4) shared(status)
3407 for (y=0; y < (ssize_t) morph_images->rows; y++)
3412 register const PixelPacket
3418 register PixelPacket
3421 if (status == MagickFalse)
3423 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3425 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3427 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3432 for (x=0; x < (ssize_t) morph_images->columns; x++)
3434 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3435 q->green=ClampToQuantum(alpha*q->green+beta*
3436 GetGreenPixelComponent(p));
3437 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3438 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3439 GetOpacityPixelComponent(p));
3443 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3444 if (sync == MagickFalse)
3447 morph_view=DestroyCacheView(morph_view);
3448 image_view=DestroyCacheView(image_view);
3449 morph_image=DestroyImage(morph_image);
3451 if (i < (ssize_t) number_frames)
3454 Clone last frame in sequence.
3456 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3457 if (morph_image == (Image *) NULL)
3459 morph_images=DestroyImageList(morph_images);
3460 return((Image *) NULL);
3462 AppendImageToList(&morph_images,morph_image);
3463 morph_images=GetLastImageInList(morph_images);
3464 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3469 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3470 #pragma omp critical (MagickCore_MorphImages)
3472 proceed=SetImageProgress(image,MorphImageTag,scene,
3473 GetImageListLength(image));
3474 if (proceed == MagickFalse)
3479 if (GetNextImageInList(next) != (Image *) NULL)
3481 morph_images=DestroyImageList(morph_images);
3482 return((Image *) NULL);
3484 return(GetFirstImageInList(morph_images));
3488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3492 % P l a s m a I m a g e %
3496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3498 % PlasmaImage() initializes an image with plasma fractal values. The image
3499 % must be initialized with a base color and the random number generator
3500 % seeded before this method is called.
3502 % The format of the PlasmaImage method is:
3504 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3505 % size_t attenuate,size_t depth)
3507 % A description of each parameter follows:
3509 % o image: the image.
3511 % o segment: Define the region to apply plasma fractals values.
3513 % o attenuate: Define the plasma attenuation factor.
3515 % o depth: Limit the plasma recursion depth.
3519 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3520 const MagickRealType pixel,const MagickRealType noise)
3525 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3530 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3531 CacheView *image_view,RandomInfo *random_info,const SegmentInfo *segment,
3532 size_t attenuate,size_t depth)
3550 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3558 Divide the area into quadrants and recurse.
3562 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3563 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3564 local_info=(*segment);
3565 local_info.x2=(double) x_mid;
3566 local_info.y2=(double) y_mid;
3567 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3569 local_info=(*segment);
3570 local_info.y1=(double) y_mid;
3571 local_info.x2=(double) x_mid;
3572 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3574 local_info=(*segment);
3575 local_info.x1=(double) x_mid;
3576 local_info.y2=(double) y_mid;
3577 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3579 local_info=(*segment);
3580 local_info.x1=(double) x_mid;
3581 local_info.y1=(double) y_mid;
3582 return(PlasmaImageProxy(image,image_view,random_info,&local_info,
3585 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3586 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3587 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3588 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3589 return(MagickFalse);
3591 Average pixels and apply plasma.
3593 exception=(&image->exception);
3594 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3595 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3597 register PixelPacket
3603 x=(ssize_t) ceil(segment->x1-0.5);
3604 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3605 ceil(segment->y1-0.5),&u,exception);
3606 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3607 ceil(segment->y2-0.5),&v,exception);
3608 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3609 if (q == (PixelPacket *) NULL)
3611 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3613 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3615 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3617 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3618 if (segment->x1 != segment->x2)
3623 x=(ssize_t) ceil(segment->x2-0.5);
3624 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3625 ceil(segment->y1-0.5),&u,exception);
3626 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3627 ceil(segment->y2-0.5),&v,exception);
3628 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3629 if (q == (PixelPacket *) NULL)
3631 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3633 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3635 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3637 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3640 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3642 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3644 register PixelPacket
3650 y=(ssize_t) ceil(segment->y2-0.5);
3651 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3652 ceil(segment->x1-0.5),y,&u,exception);
3653 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3654 ceil(segment->x2-0.5),y,&v,exception);
3655 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3656 if (q == (PixelPacket *) NULL)
3658 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3660 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3662 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3664 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3666 if (segment->y1 != segment->y2)
3668 register PixelPacket
3674 y=(ssize_t) ceil(segment->y1-0.5);
3675 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3676 ceil(segment->x1-0.5),y,&u,exception);
3677 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3678 ceil(segment->x2-0.5),y,&v,exception);
3679 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3680 if (q == (PixelPacket *) NULL)
3682 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3684 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3686 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3688 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3691 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3693 register PixelPacket
3699 x=(ssize_t) ceil(segment->x1-0.5);
3700 y=(ssize_t) ceil(segment->y1-0.5);
3701 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3702 x=(ssize_t) ceil(segment->x2-0.5);
3703 y=(ssize_t) ceil(segment->y2-0.5);
3704 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&v,exception);
3705 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3706 if (q == (PixelPacket *) NULL)
3708 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3710 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3712 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3714 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3716 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3718 return(MagickFalse);
3721 MagickExport MagickBooleanType PlasmaImage(Image *image,
3722 const SegmentInfo *segment,size_t attenuate,size_t depth)
3733 if (image->debug != MagickFalse)
3734 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3735 assert(image != (Image *) NULL);
3736 assert(image->signature == MagickSignature);
3737 if (image->debug != MagickFalse)
3738 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3739 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3740 return(MagickFalse);
3741 image_view=AcquireCacheView(image);
3742 random_info=AcquireRandomInfo();
3743 status=PlasmaImageProxy(image,image_view,random_info,segment,attenuate,depth);
3744 random_info=DestroyRandomInfo(random_info);
3745 image_view=DestroyCacheView(image_view);
3750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3754 % P o l a r o i d I m a g e %
3758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3760 % PolaroidImage() simulates a Polaroid picture.
3762 % The format of the AnnotateImage method is:
3764 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3765 % const double angle,ExceptionInfo exception)
3767 % A description of each parameter follows:
3769 % o image: the image.
3771 % o draw_info: the draw info.
3773 % o angle: Apply the effect along this angle.
3775 % o exception: return any errors or warnings in this structure.
3778 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3779 const double angle,ExceptionInfo *exception)
3800 Simulate a Polaroid picture.
3802 assert(image != (Image *) NULL);
3803 assert(image->signature == MagickSignature);
3804 if (image->debug != MagickFalse)
3805 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3806 assert(exception != (ExceptionInfo *) NULL);
3807 assert(exception->signature == MagickSignature);
3808 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3809 image->rows)/25.0,10.0);
3810 height=image->rows+2*quantum;
3811 caption_image=(Image *) NULL;
3812 value=GetImageProperty(image,"Caption");
3813 if (value != (const char *) NULL)
3817 geometry[MaxTextExtent];
3832 Generate caption image.
3834 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3835 if (caption_image == (Image *) NULL)
3836 return((Image *) NULL);
3837 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3838 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3840 (void) CloneString(&annotate_info->text,caption);
3841 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3843 status=SetImageExtent(caption_image,image->columns,(size_t)
3844 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3845 if (status == MagickFalse)
3846 caption_image=DestroyImage(caption_image);
3849 caption_image->background_color=image->border_color;
3850 (void) SetImageBackgroundColor(caption_image);
3851 (void) CloneString(&annotate_info->text,caption);
3852 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3854 if (annotate_info->gravity == UndefinedGravity)
3855 (void) CloneString(&annotate_info->geometry,AcquireString(
3857 (void) AnnotateImage(caption_image,annotate_info);
3858 height+=caption_image->rows;
3860 annotate_info=DestroyDrawInfo(annotate_info);
3861 caption=DestroyString(caption);
3863 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3865 if (picture_image == (Image *) NULL)
3867 if (caption_image != (Image *) NULL)
3868 caption_image=DestroyImage(caption_image);
3869 return((Image *) NULL);
3871 picture_image->background_color=image->border_color;
3872 (void) SetImageBackgroundColor(picture_image);
3873 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3874 if (caption_image != (Image *) NULL)
3876 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3877 quantum,(ssize_t) (image->rows+3*quantum/2));
3878 caption_image=DestroyImage(caption_image);
3880 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3881 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
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 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3888 picture_image->columns,exception);
3889 picture_image=DestroyImage(picture_image);
3890 if (bend_image == (Image *) NULL)
3891 return((Image *) NULL);
3892 InheritException(&bend_image->exception,exception);
3893 picture_image=bend_image;
3894 rotate_image=RotateImage(picture_image,-90.0,exception);
3895 picture_image=DestroyImage(picture_image);
3896 if (rotate_image == (Image *) NULL)
3897 return((Image *) NULL);
3898 picture_image=rotate_image;
3899 picture_image->background_color=image->background_color;
3900 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3902 if (polaroid_image == (Image *) NULL)
3904 picture_image=DestroyImage(picture_image);
3905 return(picture_image);
3907 flop_image=FlopImage(polaroid_image,exception);
3908 polaroid_image=DestroyImage(polaroid_image);
3909 if (flop_image == (Image *) NULL)
3911 picture_image=DestroyImage(picture_image);
3912 return(picture_image);
3914 polaroid_image=flop_image;
3915 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3916 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3917 picture_image=DestroyImage(picture_image);
3918 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3919 rotate_image=RotateImage(polaroid_image,angle,exception);
3920 polaroid_image=DestroyImage(polaroid_image);
3921 if (rotate_image == (Image *) NULL)
3922 return((Image *) NULL);
3923 polaroid_image=rotate_image;
3924 trim_image=TrimImage(polaroid_image,exception);
3925 polaroid_image=DestroyImage(polaroid_image);
3926 if (trim_image == (Image *) NULL)
3927 return((Image *) NULL);
3928 polaroid_image=trim_image;
3929 return(polaroid_image);
3933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3937 % S e p i a T o n e I m a g e %
3941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3943 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3944 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3945 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3946 % threshold of 80% is a good starting point for a reasonable tone.
3948 % The format of the SepiaToneImage method is:
3950 % Image *SepiaToneImage(const Image *image,const double threshold,
3951 % ExceptionInfo *exception)
3953 % A description of each parameter follows:
3955 % o image: the image.
3957 % o threshold: the tone threshold.
3959 % o exception: return any errors or warnings in this structure.
3962 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3963 ExceptionInfo *exception)
3965 #define SepiaToneImageTag "SepiaTone/Image"
3984 Initialize sepia-toned image attributes.
3986 assert(image != (const Image *) NULL);
3987 assert(image->signature == MagickSignature);
3988 if (image->debug != MagickFalse)
3989 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3990 assert(exception != (ExceptionInfo *) NULL);
3991 assert(exception->signature == MagickSignature);
3992 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3993 if (sepia_image == (Image *) NULL)
3994 return((Image *) NULL);
3995 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3997 InheritException(exception,&sepia_image->exception);
3998 sepia_image=DestroyImage(sepia_image);
3999 return((Image *) NULL);
4002 Tone each row of the image.
4006 image_view=AcquireCacheView(image);
4007 sepia_view=AcquireCacheView(sepia_image);
4008 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4009 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4011 for (y=0; y < (ssize_t) image->rows; y++)
4013 register const PixelPacket
4019 register PixelPacket
4022 if (status == MagickFalse)
4024 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4025 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4027 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4032 for (x=0; x < (ssize_t) image->columns; x++)
4038 intensity=(MagickRealType) PixelIntensityToQuantum(p);
4039 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4040 (MagickRealType) QuantumRange-threshold;
4041 q->red=ClampToQuantum(tone);
4042 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4043 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4044 q->green=ClampToQuantum(tone);
4045 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4046 q->blue=ClampToQuantum(tone);
4048 if ((MagickRealType) q->green < tone)
4049 q->green=ClampToQuantum(tone);
4050 if ((MagickRealType) q->blue < tone)
4051 q->blue=ClampToQuantum(tone);
4055 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4057 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4062 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4063 #pragma omp critical (MagickCore_SepiaToneImage)
4065 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4067 if (proceed == MagickFalse)
4071 sepia_view=DestroyCacheView(sepia_view);
4072 image_view=DestroyCacheView(image_view);
4073 (void) NormalizeImage(sepia_image);
4074 (void) ContrastImage(sepia_image,MagickTrue);
4075 if (status == MagickFalse)
4076 sepia_image=DestroyImage(sepia_image);
4077 return(sepia_image);
4081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4085 % S h a d o w I m a g e %
4089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4091 % ShadowImage() simulates a shadow from the specified image and returns it.
4093 % The format of the ShadowImage method is:
4095 % Image *ShadowImage(const Image *image,const double opacity,
4096 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4097 % ExceptionInfo *exception)
4099 % A description of each parameter follows:
4101 % o image: the image.
4103 % o opacity: percentage transparency.
4105 % o sigma: the standard deviation of the Gaussian, in pixels.
4107 % o x_offset: the shadow x-offset.
4109 % o y_offset: the shadow y-offset.
4111 % o exception: return any errors or warnings in this structure.
4114 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4115 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4116 ExceptionInfo *exception)
4118 #define ShadowImageTag "Shadow/Image"
4140 assert(image != (Image *) NULL);
4141 assert(image->signature == MagickSignature);
4142 if (image->debug != MagickFalse)
4143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4144 assert(exception != (ExceptionInfo *) NULL);
4145 assert(exception->signature == MagickSignature);
4146 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4147 if (clone_image == (Image *) NULL)
4148 return((Image *) NULL);
4149 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4150 clone_image->compose=OverCompositeOp;
4151 border_info.width=(size_t) floor(2.0*sigma+0.5);
4152 border_info.height=(size_t) floor(2.0*sigma+0.5);
4155 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4156 border_image=BorderImage(clone_image,&border_info,exception);
4157 clone_image=DestroyImage(clone_image);
4158 if (border_image == (Image *) NULL)
4159 return((Image *) NULL);
4160 if (border_image->matte == MagickFalse)
4161 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4167 image_view=AcquireCacheView(border_image);
4168 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4169 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4171 for (y=0; y < (ssize_t) border_image->rows; y++)
4176 register PixelPacket
4179 if (status == MagickFalse)
4181 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4183 if (q == (PixelPacket *) NULL)
4188 for (x=0; x < (ssize_t) border_image->columns; x++)
4190 q->red=border_image->background_color.red;
4191 q->green=border_image->background_color.green;
4192 q->blue=border_image->background_color.blue;
4193 if (border_image->matte == MagickFalse)
4194 q->opacity=border_image->background_color.opacity;
4196 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4197 GetAlphaPixelComponent(q)*opacity/100.0));
4200 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4202 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4207 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4208 #pragma omp critical (MagickCore_ShadowImage)
4210 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4211 border_image->rows);
4212 if (proceed == MagickFalse)
4216 image_view=DestroyCacheView(image_view);
4217 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4218 border_image=DestroyImage(border_image);
4219 if (shadow_image == (Image *) NULL)
4220 return((Image *) NULL);
4221 if (shadow_image->page.width == 0)
4222 shadow_image->page.width=shadow_image->columns;
4223 if (shadow_image->page.height == 0)
4224 shadow_image->page.height=shadow_image->rows;
4225 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4226 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4227 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4228 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4229 return(shadow_image);
4233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4237 % S k e t c h I m a g e %
4241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4243 % SketchImage() simulates a pencil sketch. We convolve the image with a
4244 % Gaussian operator of the given radius and standard deviation (sigma). For
4245 % reasonable results, radius should be larger than sigma. Use a radius of 0
4246 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4249 % The format of the SketchImage method is:
4251 % Image *SketchImage(const Image *image,const double radius,
4252 % const double sigma,const double angle,ExceptionInfo *exception)
4254 % A description of each parameter follows:
4256 % o image: the image.
4258 % o radius: the radius of the Gaussian, in pixels, not counting
4261 % o sigma: the standard deviation of the Gaussian, in pixels.
4263 % o angle: Apply the effect along this angle.
4265 % o exception: return any errors or warnings in this structure.
4268 MagickExport Image *SketchImage(const Image *image,const double radius,
4269 const double sigma,const double angle,ExceptionInfo *exception)
4288 **restrict random_info;
4296 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4297 MagickTrue,exception);
4298 if (random_image == (Image *) NULL)
4299 return((Image *) NULL);
4301 GetMagickPixelPacket(random_image,&zero);
4302 random_info=AcquireRandomInfoThreadSet();
4303 random_view=AcquireCacheView(random_image);
4304 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4305 #pragma omp parallel for schedule(dynamic,4) shared(status)
4307 for (y=0; y < (ssize_t) random_image->rows; y++)
4310 id = GetOpenMPThreadId();
4315 register IndexPacket
4321 register PixelPacket
4324 if (status == MagickFalse)
4326 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4328 if (q == (PixelPacket *) NULL)
4333 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4335 for (x=0; x < (ssize_t) random_image->columns; x++)
4337 pixel.red=(MagickRealType) (QuantumRange*
4338 GetPseudoRandomValue(random_info[id]));
4339 pixel.green=pixel.red;
4340 pixel.blue=pixel.red;
4341 if (image->colorspace == CMYKColorspace)
4342 pixel.index=pixel.red;
4343 SetPixelPacket(random_image,&pixel,q,indexes+x);
4346 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4349 random_view=DestroyCacheView(random_view);
4350 random_info=DestroyRandomInfoThreadSet(random_info);
4351 if (status == MagickFalse)
4353 random_image=DestroyImage(random_image);
4354 return(random_image);
4356 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4357 random_image=DestroyImage(random_image);
4358 if (blur_image == (Image *) NULL)
4359 return((Image *) NULL);
4360 dodge_image=EdgeImage(blur_image,radius,exception);
4361 blur_image=DestroyImage(blur_image);
4362 if (dodge_image == (Image *) NULL)
4363 return((Image *) NULL);
4364 (void) NormalizeImage(dodge_image);
4365 (void) NegateImage(dodge_image,MagickFalse);
4366 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4367 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4368 if (sketch_image == (Image *) NULL)
4370 dodge_image=DestroyImage(dodge_image);
4371 return((Image *) NULL);
4373 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4374 dodge_image=DestroyImage(dodge_image);
4375 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4376 if (blend_image == (Image *) NULL)
4378 sketch_image=DestroyImage(sketch_image);
4379 return((Image *) NULL);
4381 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4382 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4383 blend_image=DestroyImage(blend_image);
4384 return(sketch_image);
4388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4392 % S o l a r i z e I m a g e %
4396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4398 % SolarizeImage() applies a special effect to the image, similar to the effect
4399 % achieved in a photo darkroom by selectively exposing areas of photo
4400 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4401 % measure of the extent of the solarization.
4403 % The format of the SolarizeImage method is:
4405 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4407 % A description of each parameter follows:
4409 % o image: the image.
4411 % o threshold: Define the extent of the solarization.
4414 MagickExport MagickBooleanType SolarizeImage(Image *image,
4415 const double threshold)
4417 #define SolarizeImageTag "Solarize/Image"
4434 assert(image != (Image *) NULL);
4435 assert(image->signature == MagickSignature);
4436 if (image->debug != MagickFalse)
4437 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4438 if (image->storage_class == PseudoClass)
4446 for (i=0; i < (ssize_t) image->colors; i++)
4448 if ((MagickRealType) image->colormap[i].red > threshold)
4449 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4450 if ((MagickRealType) image->colormap[i].green > threshold)
4451 image->colormap[i].green=(Quantum) QuantumRange-
4452 image->colormap[i].green;
4453 if ((MagickRealType) image->colormap[i].blue > threshold)
4454 image->colormap[i].blue=(Quantum) QuantumRange-
4455 image->colormap[i].blue;
4463 exception=(&image->exception);
4464 image_view=AcquireCacheView(image);
4465 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4466 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4468 for (y=0; y < (ssize_t) image->rows; y++)
4473 register PixelPacket
4476 if (status == MagickFalse)
4478 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4480 if (q == (PixelPacket *) NULL)
4485 for (x=0; x < (ssize_t) image->columns; x++)
4487 if ((MagickRealType) q->red > threshold)
4488 q->red=(Quantum) QuantumRange-q->red;
4489 if ((MagickRealType) q->green > threshold)
4490 q->green=(Quantum) QuantumRange-q->green;
4491 if ((MagickRealType) q->blue > threshold)
4492 q->blue=(Quantum) QuantumRange-q->blue;
4495 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4497 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4502 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4503 #pragma omp critical (MagickCore_SolarizeImage)
4505 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4506 if (proceed == MagickFalse)
4510 image_view=DestroyCacheView(image_view);
4515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4519 % S t e g a n o I m a g e %
4523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4525 % SteganoImage() hides a digital watermark within the image. Recover
4526 % the hidden watermark later to prove that the authenticity of an image.
4527 % Offset defines the start position within the image to hide the watermark.
4529 % The format of the SteganoImage method is:
4531 % Image *SteganoImage(const Image *image,Image *watermark,
4532 % ExceptionInfo *exception)
4534 % A description of each parameter follows:
4536 % o image: the image.
4538 % o watermark: the watermark image.
4540 % o exception: return any errors or warnings in this structure.
4543 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4544 ExceptionInfo *exception)
4546 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4547 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) != 0 ? (size_t) (alpha) \
4548 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4549 #define SteganoImageTag "Stegano/Image"
4567 register PixelPacket
4584 Initialize steganographic image attributes.
4586 assert(image != (const Image *) NULL);
4587 assert(image->signature == MagickSignature);
4588 if (image->debug != MagickFalse)
4589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4590 assert(watermark != (const Image *) NULL);
4591 assert(watermark->signature == MagickSignature);
4592 assert(exception != (ExceptionInfo *) NULL);
4593 assert(exception->signature == MagickSignature);
4595 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4596 if (stegano_image == (Image *) NULL)
4597 return((Image *) NULL);
4598 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4600 InheritException(exception,&stegano_image->exception);
4601 stegano_image=DestroyImage(stegano_image);
4602 return((Image *) NULL);
4604 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4606 Hide watermark in low-order bits of image.
4611 depth=stegano_image->depth;
4614 watermark_view=AcquireCacheView(watermark);
4615 stegano_view=AcquireCacheView(stegano_image);
4616 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4618 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4620 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4622 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,&pixel,exception);
4623 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4625 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4626 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4628 if (q == (PixelPacket *) NULL)
4634 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4639 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4644 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4648 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4654 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4656 if (k == image->offset)
4660 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4665 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4667 if (proceed == MagickFalse)
4671 stegano_view=DestroyCacheView(stegano_view);
4672 watermark_view=DestroyCacheView(watermark_view);
4673 if (stegano_image->storage_class == PseudoClass)
4674 (void) SyncImage(stegano_image);
4675 if (status == MagickFalse)
4677 stegano_image=DestroyImage(stegano_image);
4678 return((Image *) NULL);
4680 return(stegano_image);
4684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4688 % S t e r e o A n a g l y p h I m a g e %
4692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4694 % StereoAnaglyphImage() combines two images and produces a single image that
4695 % is the composite of a left and right image of a stereo pair. Special
4696 % red-green stereo glasses are required to view this effect.
4698 % The format of the StereoAnaglyphImage method is:
4700 % Image *StereoImage(const Image *left_image,const Image *right_image,
4701 % ExceptionInfo *exception)
4702 % Image *StereoAnaglyphImage(const Image *left_image,
4703 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4704 % ExceptionInfo *exception)
4706 % A description of each parameter follows:
4708 % o left_image: the left image.
4710 % o right_image: the right image.
4712 % o exception: return any errors or warnings in this structure.
4714 % o x_offset: amount, in pixels, by which the left image is offset to the
4715 % right of the right image.
4717 % o y_offset: amount, in pixels, by which the left image is offset to the
4718 % bottom of the right image.
4722 MagickExport Image *StereoImage(const Image *left_image,
4723 const Image *right_image,ExceptionInfo *exception)
4725 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4728 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4729 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4730 ExceptionInfo *exception)
4732 #define StereoImageTag "Stereo/Image"
4746 assert(left_image != (const Image *) NULL);
4747 assert(left_image->signature == MagickSignature);
4748 if (left_image->debug != MagickFalse)
4749 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4750 left_image->filename);
4751 assert(right_image != (const Image *) NULL);
4752 assert(right_image->signature == MagickSignature);
4753 assert(exception != (ExceptionInfo *) NULL);
4754 assert(exception->signature == MagickSignature);
4755 assert(right_image != (const Image *) NULL);
4757 if ((left_image->columns != right_image->columns) ||
4758 (left_image->rows != right_image->rows))
4759 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4761 Initialize stereo image attributes.
4763 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4764 MagickTrue,exception);
4765 if (stereo_image == (Image *) NULL)
4766 return((Image *) NULL);
4767 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4769 InheritException(exception,&stereo_image->exception);
4770 stereo_image=DestroyImage(stereo_image);
4771 return((Image *) NULL);
4774 Copy left image to red channel and right image to blue channel.
4777 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4779 register const PixelPacket
4786 register PixelPacket
4789 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4791 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4792 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4793 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4794 (r == (PixelPacket *) NULL))
4796 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4798 r->red=GetRedPixelComponent(p);
4801 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4806 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4808 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4813 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4814 stereo_image->rows);
4815 if (proceed == MagickFalse)
4819 if (status == MagickFalse)
4821 stereo_image=DestroyImage(stereo_image);
4822 return((Image *) NULL);
4824 return(stereo_image);
4828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4832 % S w i r l I m a g e %
4836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4838 % SwirlImage() swirls the pixels about the center of the image, where
4839 % degrees indicates the sweep of the arc through which each pixel is moved.
4840 % You get a more dramatic effect as the degrees move from 1 to 360.
4842 % The format of the SwirlImage method is:
4844 % Image *SwirlImage(const Image *image,double degrees,
4845 % ExceptionInfo *exception)
4847 % A description of each parameter follows:
4849 % o image: the image.
4851 % o degrees: Define the tightness of the swirling effect.
4853 % o exception: return any errors or warnings in this structure.
4856 MagickExport Image *SwirlImage(const Image *image,double degrees,
4857 ExceptionInfo *exception)
4859 #define SwirlImageTag "Swirl/Image"
4888 Initialize swirl image attributes.
4890 assert(image != (const Image *) NULL);
4891 assert(image->signature == MagickSignature);
4892 if (image->debug != MagickFalse)
4893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4894 assert(exception != (ExceptionInfo *) NULL);
4895 assert(exception->signature == MagickSignature);
4896 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4897 if (swirl_image == (Image *) NULL)
4898 return((Image *) NULL);
4899 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4901 InheritException(exception,&swirl_image->exception);
4902 swirl_image=DestroyImage(swirl_image);
4903 return((Image *) NULL);
4905 if (swirl_image->background_color.opacity != OpaqueOpacity)
4906 swirl_image->matte=MagickTrue;
4908 Compute scaling factor.
4910 center.x=(double) image->columns/2.0;
4911 center.y=(double) image->rows/2.0;
4912 radius=MagickMax(center.x,center.y);
4915 if (image->columns > image->rows)
4916 scale.y=(double) image->columns/(double) image->rows;
4918 if (image->columns < image->rows)
4919 scale.x=(double) image->rows/(double) image->columns;
4920 degrees=(double) DegreesToRadians(degrees);
4926 GetMagickPixelPacket(swirl_image,&zero);
4927 image_view=AcquireCacheView(image);
4928 swirl_view=AcquireCacheView(swirl_image);
4929 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4930 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4932 for (y=0; y < (ssize_t) image->rows; y++)
4943 register IndexPacket
4944 *restrict swirl_indexes;
4949 register PixelPacket
4952 if (status == MagickFalse)
4954 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4956 if (q == (PixelPacket *) NULL)
4961 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4962 delta.y=scale.y*(double) (y-center.y);
4964 for (x=0; x < (ssize_t) image->columns; x++)
4967 Determine if the pixel is within an ellipse.
4969 delta.x=scale.x*(double) (x-center.x);
4970 distance=delta.x*delta.x+delta.y*delta.y;
4971 if (distance < (radius*radius))
4981 factor=1.0-sqrt((double) distance)/radius;
4982 sine=sin((double) (degrees*factor*factor));
4983 cosine=cos((double) (degrees*factor*factor));
4984 (void) InterpolateMagickPixelPacket(image,image_view,
4985 UndefinedInterpolatePixel,(double) ((cosine*delta.x-sine*delta.y)/
4986 scale.x+center.x),(double) ((sine*delta.x+cosine*delta.y)/scale.y+
4987 center.y),&pixel,exception);
4988 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4992 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4994 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4999 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5000 #pragma omp critical (MagickCore_SwirlImage)
5002 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5003 if (proceed == MagickFalse)
5007 swirl_view=DestroyCacheView(swirl_view);
5008 image_view=DestroyCacheView(image_view);
5009 if (status == MagickFalse)
5010 swirl_image=DestroyImage(swirl_image);
5011 return(swirl_image);
5015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5019 % T i n t I m a g e %
5023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5025 % TintImage() applies a color vector to each pixel in the image. The length
5026 % of the vector is 0 for black and white and at its maximum for the midtones.
5027 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5029 % The format of the TintImage method is:
5031 % Image *TintImage(const Image *image,const char *opacity,
5032 % const PixelPacket tint,ExceptionInfo *exception)
5034 % A description of each parameter follows:
5036 % o image: the image.
5038 % o opacity: A color value used for tinting.
5040 % o tint: A color value used for tinting.
5042 % o exception: return any errors or warnings in this structure.
5045 MagickExport Image *TintImage(const Image *image,const char *opacity,
5046 const PixelPacket tint,ExceptionInfo *exception)
5048 #define TintImageTag "Tint/Image"
5077 Allocate tint image.
5079 assert(image != (const Image *) NULL);
5080 assert(image->signature == MagickSignature);
5081 if (image->debug != MagickFalse)
5082 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5083 assert(exception != (ExceptionInfo *) NULL);
5084 assert(exception->signature == MagickSignature);
5085 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5086 if (tint_image == (Image *) NULL)
5087 return((Image *) NULL);
5088 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5090 InheritException(exception,&tint_image->exception);
5091 tint_image=DestroyImage(tint_image);
5092 return((Image *) NULL);
5094 if (opacity == (const char *) NULL)
5097 Determine RGB values of the color.
5099 flags=ParseGeometry(opacity,&geometry_info);
5100 pixel.red=geometry_info.rho;
5101 if ((flags & SigmaValue) != 0)
5102 pixel.green=geometry_info.sigma;
5104 pixel.green=pixel.red;
5105 if ((flags & XiValue) != 0)
5106 pixel.blue=geometry_info.xi;
5108 pixel.blue=pixel.red;
5109 if ((flags & PsiValue) != 0)
5110 pixel.opacity=geometry_info.psi;
5112 pixel.opacity=(MagickRealType) OpaqueOpacity;
5113 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5114 PixelIntensity(&tint));
5115 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5116 PixelIntensity(&tint));
5117 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5118 PixelIntensity(&tint));
5124 image_view=AcquireCacheView(image);
5125 tint_view=AcquireCacheView(tint_image);
5126 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5127 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5129 for (y=0; y < (ssize_t) image->rows; y++)
5131 register const PixelPacket
5137 register PixelPacket
5140 if (status == MagickFalse)
5142 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5143 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5145 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5150 for (x=0; x < (ssize_t) image->columns; x++)
5158 weight=QuantumScale*p->red-0.5;
5159 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5161 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5162 weight=QuantumScale*p->green-0.5;
5163 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5165 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5166 weight=QuantumScale*p->blue-0.5;
5167 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5169 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5170 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5174 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5176 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5181 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5182 #pragma omp critical (MagickCore_TintImage)
5184 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5185 if (proceed == MagickFalse)
5189 tint_view=DestroyCacheView(tint_view);
5190 image_view=DestroyCacheView(image_view);
5191 if (status == MagickFalse)
5192 tint_image=DestroyImage(tint_image);
5197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5201 % V i g n e t t e I m a g e %
5205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5207 % VignetteImage() softens the edges of the image in vignette style.
5209 % The format of the VignetteImage method is:
5211 % Image *VignetteImage(const Image *image,const double radius,
5212 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5214 % A description of each parameter follows:
5216 % o image: the image.
5218 % o radius: the radius of the pixel neighborhood.
5220 % o sigma: the standard deviation of the Gaussian, in pixels.
5222 % o x, y: Define the x and y ellipse offset.
5224 % o exception: return any errors or warnings in this structure.
5227 MagickExport Image *VignetteImage(const Image *image,const double radius,
5228 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5231 ellipse[MaxTextExtent];
5242 assert(image != (Image *) NULL);
5243 assert(image->signature == MagickSignature);
5244 if (image->debug != MagickFalse)
5245 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5246 assert(exception != (ExceptionInfo *) NULL);
5247 assert(exception->signature == MagickSignature);
5248 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5249 if (canvas_image == (Image *) NULL)
5250 return((Image *) NULL);
5251 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5253 InheritException(exception,&canvas_image->exception);
5254 canvas_image=DestroyImage(canvas_image);
5255 return((Image *) NULL);
5257 canvas_image->matte=MagickTrue;
5258 oval_image=CloneImage(canvas_image,canvas_image->columns,
5259 canvas_image->rows,MagickTrue,exception);
5260 if (oval_image == (Image *) NULL)
5262 canvas_image=DestroyImage(canvas_image);
5263 return((Image *) NULL);
5265 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5266 (void) SetImageBackgroundColor(oval_image);
5267 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5268 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5269 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5270 (void) FormatMagickString(ellipse,MaxTextExtent,
5271 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5272 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5273 draw_info->primitive=AcquireString(ellipse);
5274 (void) DrawImage(oval_image,draw_info);
5275 draw_info=DestroyDrawInfo(draw_info);
5276 blur_image=BlurImage(oval_image,radius,sigma,exception);
5277 oval_image=DestroyImage(oval_image);
5278 if (blur_image == (Image *) NULL)
5280 canvas_image=DestroyImage(canvas_image);
5281 return((Image *) NULL);
5283 blur_image->matte=MagickFalse;
5284 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5285 blur_image=DestroyImage(blur_image);
5286 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5287 canvas_image=DestroyImage(canvas_image);
5288 return(vignette_image);
5292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5296 % W a v e I m a g e %
5300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5302 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5303 % vertically along a sine wave whose amplitude and wavelength is specified
5304 % by the given parameters.
5306 % The format of the WaveImage method is:
5308 % Image *WaveImage(const Image *image,const double amplitude,
5309 % const double wave_length,ExceptionInfo *exception)
5311 % A description of each parameter follows:
5313 % o image: the image.
5315 % o amplitude, wave_length: Define the amplitude and wave length of the
5318 % o exception: return any errors or warnings in this structure.
5321 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5322 const double wave_length,ExceptionInfo *exception)
5324 #define WaveImageTag "Wave/Image"
5352 Initialize wave image attributes.
5354 assert(image != (Image *) NULL);
5355 assert(image->signature == MagickSignature);
5356 if (image->debug != MagickFalse)
5357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5358 assert(exception != (ExceptionInfo *) NULL);
5359 assert(exception->signature == MagickSignature);
5360 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5361 fabs(amplitude)),MagickTrue,exception);
5362 if (wave_image == (Image *) NULL)
5363 return((Image *) NULL);
5364 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5366 InheritException(exception,&wave_image->exception);
5367 wave_image=DestroyImage(wave_image);
5368 return((Image *) NULL);
5370 if (wave_image->background_color.opacity != OpaqueOpacity)
5371 wave_image->matte=MagickTrue;
5375 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5377 if (sine_map == (MagickRealType *) NULL)
5379 wave_image=DestroyImage(wave_image);
5380 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5382 for (i=0; i < (ssize_t) wave_image->columns; i++)
5383 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5390 GetMagickPixelPacket(wave_image,&zero);
5391 image_view=AcquireCacheView(image);
5392 wave_view=AcquireCacheView(wave_image);
5393 (void) SetCacheViewVirtualPixelMethod(image_view,
5394 BackgroundVirtualPixelMethod);
5395 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5396 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5398 for (y=0; y < (ssize_t) wave_image->rows; y++)
5403 register IndexPacket
5406 register PixelPacket
5412 if (status == MagickFalse)
5414 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5416 if (q == (PixelPacket *) NULL)
5421 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5423 for (x=0; x < (ssize_t) wave_image->columns; x++)
5425 (void) InterpolateMagickPixelPacket(image,image_view,
5426 UndefinedInterpolatePixel,(double) x,(double) (y-sine_map[x]),&pixel,
5428 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5431 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5433 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5438 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5439 #pragma omp critical (MagickCore_WaveImage)
5441 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5442 if (proceed == MagickFalse)
5446 wave_view=DestroyCacheView(wave_view);
5447 image_view=DestroyCacheView(image_view);
5448 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5449 if (status == MagickFalse)
5450 wave_image=DestroyImage(wave_image);