2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % MagickCore Image Special Effects Methods %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "magick/studio.h"
44 #include "magick/annotate.h"
45 #include "magick/artifact.h"
46 #include "magick/attribute.h"
47 #include "magick/cache.h"
48 #include "magick/cache-view.h"
49 #include "magick/color.h"
50 #include "magick/color-private.h"
51 #include "magick/composite.h"
52 #include "magick/decorate.h"
53 #include "magick/draw.h"
54 #include "magick/effect.h"
55 #include "magick/enhance.h"
56 #include "magick/exception.h"
57 #include "magick/exception-private.h"
58 #include "magick/fx.h"
59 #include "magick/fx-private.h"
60 #include "magick/gem.h"
61 #include "magick/geometry.h"
62 #include "magick/layer.h"
63 #include "magick/list.h"
64 #include "magick/log.h"
65 #include "magick/image.h"
66 #include "magick/image-private.h"
67 #include "magick/magick.h"
68 #include "magick/memory_.h"
69 #include "magick/monitor.h"
70 #include "magick/monitor-private.h"
71 #include "magick/option.h"
72 #include "magick/pixel-private.h"
73 #include "magick/property.h"
74 #include "magick/quantum.h"
75 #include "magick/quantum-private.h"
76 #include "magick/random_.h"
77 #include "magick/random-private.h"
78 #include "magick/resample.h"
79 #include "magick/resample-private.h"
80 #include "magick/resize.h"
81 #include "magick/shear.h"
82 #include "magick/splay-tree.h"
83 #include "magick/statistic.h"
84 #include "magick/string_.h"
85 #include "magick/string-private.h"
86 #include "magick/thread-private.h"
87 #include "magick/transform.h"
88 #include "magick/utility.h"
93 #define LeftShiftOperator 0xf5
94 #define RightShiftOperator 0xf6
95 #define LessThanEqualOperator 0xf7
96 #define GreaterThanEqualOperator 0xf8
97 #define EqualOperator 0xf9
98 #define NotEqualOperator 0xfa
99 #define LogicalAndOperator 0xfb
100 #define LogicalOrOperator 0xfc
101 #define ExponentialNotation 0xfd
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 + A c q u i r e F x I n f o %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % AcquireFxInfo() allocates the FxInfo structure.
144 % The format of the AcquireFxInfo method is:
146 % FxInfo *AcquireFxInfo(Image *image,const char *expression)
147 % A description of each parameter follows:
149 % o image: the image.
151 % o expression: the expression.
154 MagickExport FxInfo *AcquireFxInfo(const Image *image,const char *expression)
165 fx_info=(FxInfo *) AcquireAlignedMemory(1,sizeof(*fx_info));
166 if (fx_info == (FxInfo *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
169 fx_info->exception=AcquireExceptionInfo();
170 fx_info->images=image;
171 fx_info->matte=image->matte;
172 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
173 RelinquishMagickMemory);
174 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->resample_filter=(ResampleFilter **) AcquireQuantumMemory(
177 GetImageListLength(fx_info->images),sizeof(*fx_info->resample_filter));
178 if (fx_info->resample_filter == (ResampleFilter **) NULL)
179 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
180 for (i=0; i < (ssize_t) GetImageListLength(fx_info->images); i++)
182 fx_info->resample_filter[i]=AcquireResampleFilter(GetImageFromList(
183 fx_info->images,i),fx_info->exception);
184 SetResampleFilter(fx_info->resample_filter[i],PointFilter,1.0);
186 fx_info->random_info=AcquireRandomInfo();
187 fx_info->expression=ConstantString(expression);
188 fx_info->file=stderr;
189 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
190 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
191 (strstr(fx_info->expression,"e-") != (char *) NULL))
194 Convert scientific notation.
196 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
197 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
198 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
199 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
200 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
201 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
202 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
203 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
204 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
205 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
206 (void) SubstituteString(&fx_info->expression,"0e-","0**10^-");
207 (void) SubstituteString(&fx_info->expression,"1e-","1**10^-");
208 (void) SubstituteString(&fx_info->expression,"2e-","2**10^-");
209 (void) SubstituteString(&fx_info->expression,"3e-","3**10^-");
210 (void) SubstituteString(&fx_info->expression,"4e-","4**10^-");
211 (void) SubstituteString(&fx_info->expression,"5e-","5**10^-");
212 (void) SubstituteString(&fx_info->expression,"6e-","6**10^-");
213 (void) SubstituteString(&fx_info->expression,"7e-","7**10^-");
214 (void) SubstituteString(&fx_info->expression,"8e-","8**10^-");
215 (void) SubstituteString(&fx_info->expression,"9e-","9**10^-");
218 Convert complex to simple operators.
221 *fx_op=(char) LeftShiftOperator;
222 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
223 *fx_op=(char) RightShiftOperator;
224 (void) SubstituteString(&fx_info->expression,">>",fx_op);
225 *fx_op=(char) LessThanEqualOperator;
226 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
227 *fx_op=(char) GreaterThanEqualOperator;
228 (void) SubstituteString(&fx_info->expression,">=",fx_op);
229 *fx_op=(char) EqualOperator;
230 (void) SubstituteString(&fx_info->expression,"==",fx_op);
231 *fx_op=(char) NotEqualOperator;
232 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
233 *fx_op=(char) LogicalAndOperator;
234 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
235 *fx_op=(char) LogicalOrOperator;
236 (void) SubstituteString(&fx_info->expression,"||",fx_op);
237 *fx_op=(char) ExponentialNotation;
238 (void) SubstituteString(&fx_info->expression,"**",fx_op);
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % A d d N o i s e I m a g e %
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % AddNoiseImage() adds random noise to the image.
255 % The format of the AddNoiseImage method is:
257 % Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
258 % ExceptionInfo *exception)
259 % Image *AddNoiseImageChannel(const Image *image,const ChannelType channel,
260 % const NoiseType noise_type,ExceptionInfo *exception)
262 % A description of each parameter follows:
264 % o image: the image.
266 % o channel: the channel type.
268 % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
269 % Impulse, Laplacian, or Poisson.
271 % o exception: return any errors or warnings in this structure.
274 MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
275 ExceptionInfo *exception)
280 noise_image=AddNoiseImageChannel(image,DefaultChannels,noise_type,exception);
284 MagickExport Image *AddNoiseImageChannel(const Image *image,
285 const ChannelType channel,const NoiseType noise_type,ExceptionInfo *exception)
287 #define AddNoiseImageTag "AddNoise/Image"
309 **restrict random_info;
315 Initialize noise image attributes.
317 assert(image != (const Image *) NULL);
318 assert(image->signature == MagickSignature);
319 if (image->debug != MagickFalse)
320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
321 assert(exception != (ExceptionInfo *) NULL);
322 assert(exception->signature == MagickSignature);
323 noise_image=CloneImage(image,0,0,MagickTrue,exception);
324 if (noise_image == (Image *) NULL)
325 return((Image *) NULL);
326 if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
328 InheritException(exception,&noise_image->exception);
329 noise_image=DestroyImage(noise_image);
330 return((Image *) NULL);
333 Add noise in each row.
336 option=GetImageArtifact(image,"attenuate");
337 if (option != (char *) NULL)
338 attenuate=StringToDouble(option);
341 random_info=AcquireRandomInfoThreadSet();
342 image_view=AcquireCacheView(image);
343 noise_view=AcquireCacheView(noise_image);
344 #if defined(MAGICKCORE_OPENMP_SUPPORT)
345 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
347 for (y=0; y < (ssize_t) image->rows; y++)
350 id = GetOpenMPThreadId();
355 register const IndexPacket
358 register const PixelPacket
362 *restrict noise_indexes;
370 if (status == MagickFalse)
372 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
373 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
375 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
380 indexes=GetCacheViewVirtualIndexQueue(image_view);
381 noise_indexes=GetCacheViewAuthenticIndexQueue(noise_view);
382 for (x=0; x < (ssize_t) image->columns; x++)
384 if ((channel & RedChannel) != 0)
385 q->red=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
386 p->red,noise_type,attenuate));
387 if ((channel & GreenChannel) != 0)
388 q->green=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
389 p->green,noise_type,attenuate));
390 if ((channel & BlueChannel) != 0)
391 q->blue=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
392 p->blue,noise_type,attenuate));
393 if ((channel & OpacityChannel) != 0)
394 q->opacity=ClampToQuantum(GenerateDifferentialNoise(random_info[id],
395 p->opacity,noise_type,attenuate));
396 if (((channel & IndexChannel) != 0) &&
397 (image->colorspace == CMYKColorspace))
398 noise_indexes[x]=(IndexPacket) ClampToQuantum(GenerateDifferentialNoise(
399 random_info[id],indexes[x],noise_type,attenuate));
403 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
404 if (sync == MagickFalse)
406 if (image->progress_monitor != (MagickProgressMonitor) NULL)
411 #if defined(MAGICKCORE_OPENMP_SUPPORT)
412 #pragma omp critical (MagickCore_AddNoiseImage)
414 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
416 if (proceed == MagickFalse)
420 noise_view=DestroyCacheView(noise_view);
421 image_view=DestroyCacheView(image_view);
422 random_info=DestroyRandomInfoThreadSet(random_info);
423 if (status == MagickFalse)
424 noise_image=DestroyImage(noise_image);
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 % B l u e S h i f t I m a g e %
437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439 % BlueShiftImage() mutes the colors of the image to simulate a scene at
440 % nighttime in the moonlight.
442 % The format of the BlueShiftImage method is:
444 % Image *BlueShiftImage(const Image *image,const double factor,
445 % ExceptionInfo *exception)
447 % A description of each parameter follows:
449 % o image: the image.
451 % o factor: the shift factor.
453 % o exception: return any errors or warnings in this structure.
456 MagickExport Image *BlueShiftImage(const Image *image,const double factor,
457 ExceptionInfo *exception)
459 #define BlueShiftImageTag "BlueShift/Image"
478 Allocate blue shift image.
480 assert(image != (const Image *) NULL);
481 assert(image->signature == MagickSignature);
482 if (image->debug != MagickFalse)
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
484 assert(exception != (ExceptionInfo *) NULL);
485 assert(exception->signature == MagickSignature);
486 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
488 if (shift_image == (Image *) NULL)
489 return((Image *) NULL);
490 if (SetImageStorageClass(shift_image,DirectClass) == MagickFalse)
492 InheritException(exception,&shift_image->exception);
493 shift_image=DestroyImage(shift_image);
494 return((Image *) NULL);
497 Blue-shift DirectClass image.
501 image_view=AcquireCacheView(image);
502 shift_view=AcquireCacheView(shift_image);
503 #if defined(MAGICKCORE_OPENMP_SUPPORT)
504 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
506 for (y=0; y < (ssize_t) image->rows; y++)
517 register const PixelPacket
526 if (status == MagickFalse)
528 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
529 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
531 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
536 for (x=0; x < (ssize_t) image->columns; x++)
538 quantum=GetRedPixelComponent(p);
539 if (p->green < quantum)
540 quantum=GetGreenPixelComponent(p);
541 if (p->blue < quantum)
542 quantum=GetBluePixelComponent(p);
543 pixel.red=0.5*(p->red+factor*quantum);
544 pixel.green=0.5*(p->green+factor*quantum);
545 pixel.blue=0.5*(p->blue+factor*quantum);
546 quantum=GetRedPixelComponent(p);
547 if (p->green > quantum)
548 quantum=GetGreenPixelComponent(p);
549 if (p->blue > quantum)
550 quantum=GetBluePixelComponent(p);
551 pixel.red=0.5*(pixel.red+factor*quantum);
552 pixel.green=0.5*(pixel.green+factor*quantum);
553 pixel.blue=0.5*(pixel.blue+factor*quantum);
554 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
555 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
556 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
560 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
561 if (sync == MagickFalse)
563 if (image->progress_monitor != (MagickProgressMonitor) NULL)
568 #if defined(MAGICKCORE_OPENMP_SUPPORT)
569 #pragma omp critical (MagickCore_BlueShiftImage)
571 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
573 if (proceed == MagickFalse)
577 image_view=DestroyCacheView(image_view);
578 shift_view=DestroyCacheView(shift_view);
579 if (status == MagickFalse)
580 shift_image=DestroyImage(shift_image);
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589 % C h a r c o a l I m a g e %
593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595 % CharcoalImage() creates a new image that is a copy of an existing one with
596 % the edge highlighted. It allocates the memory necessary for the new Image
597 % structure and returns a pointer to the new image.
599 % The format of the CharcoalImage method is:
601 % Image *CharcoalImage(const Image *image,const double radius,
602 % const double sigma,ExceptionInfo *exception)
604 % A description of each parameter follows:
606 % o image: the image.
608 % o radius: the radius of the pixel neighborhood.
610 % o sigma: the standard deviation of the Gaussian, in pixels.
612 % o exception: return any errors or warnings in this structure.
615 MagickExport Image *CharcoalImage(const Image *image,const double radius,
616 const double sigma,ExceptionInfo *exception)
623 assert(image != (Image *) NULL);
624 assert(image->signature == MagickSignature);
625 if (image->debug != MagickFalse)
626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
627 assert(exception != (ExceptionInfo *) NULL);
628 assert(exception->signature == MagickSignature);
629 clone_image=CloneImage(image,0,0,MagickTrue,exception);
630 if (clone_image == (Image *) NULL)
631 return((Image *) NULL);
632 (void) SetImageType(clone_image,GrayscaleType);
633 edge_image=EdgeImage(clone_image,radius,exception);
634 clone_image=DestroyImage(clone_image);
635 if (edge_image == (Image *) NULL)
636 return((Image *) NULL);
637 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
638 edge_image=DestroyImage(edge_image);
639 if (charcoal_image == (Image *) NULL)
640 return((Image *) NULL);
641 (void) NormalizeImage(charcoal_image);
642 (void) NegateImage(charcoal_image,MagickFalse);
643 (void) SetImageType(charcoal_image,GrayscaleType);
644 return(charcoal_image);
648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 % C o l o r i z e I m a g e %
656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658 % ColorizeImage() blends the fill color with each pixel in the image.
659 % A percentage blend is specified with opacity. Control the application
660 % of different color components by specifying a different percentage for
661 % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
663 % The format of the ColorizeImage method is:
665 % Image *ColorizeImage(const Image *image,const char *opacity,
666 % const PixelPacket colorize,ExceptionInfo *exception)
668 % A description of each parameter follows:
670 % o image: the image.
672 % o opacity: A character string indicating the level of opacity as a
675 % o colorize: A color value.
677 % o exception: return any errors or warnings in this structure.
680 MagickExport Image *ColorizeImage(const Image *image,const char *opacity,
681 const PixelPacket colorize,ExceptionInfo *exception)
683 #define ColorizeImageTag "Colorize/Image"
711 Allocate colorized image.
713 assert(image != (const Image *) NULL);
714 assert(image->signature == MagickSignature);
715 if (image->debug != MagickFalse)
716 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
717 assert(exception != (ExceptionInfo *) NULL);
718 assert(exception->signature == MagickSignature);
719 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
721 if (colorize_image == (Image *) NULL)
722 return((Image *) NULL);
723 if (SetImageStorageClass(colorize_image,DirectClass) == MagickFalse)
725 InheritException(exception,&colorize_image->exception);
726 colorize_image=DestroyImage(colorize_image);
727 return((Image *) NULL);
729 if (opacity == (const char *) NULL)
730 return(colorize_image);
732 Determine RGB values of the pen color.
734 flags=ParseGeometry(opacity,&geometry_info);
735 pixel.red=geometry_info.rho;
736 pixel.green=geometry_info.rho;
737 pixel.blue=geometry_info.rho;
738 pixel.opacity=(MagickRealType) OpaqueOpacity;
739 if ((flags & SigmaValue) != 0)
740 pixel.green=geometry_info.sigma;
741 if ((flags & XiValue) != 0)
742 pixel.blue=geometry_info.xi;
743 if ((flags & PsiValue) != 0)
744 pixel.opacity=geometry_info.psi;
746 Colorize DirectClass image.
750 image_view=AcquireCacheView(image);
751 colorize_view=AcquireCacheView(colorize_image);
752 #if defined(MAGICKCORE_OPENMP_SUPPORT)
753 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
755 for (y=0; y < (ssize_t) image->rows; y++)
760 register const PixelPacket
769 if (status == MagickFalse)
771 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
772 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
774 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
779 for (x=0; x < (ssize_t) image->columns; x++)
781 q->red=(Quantum) ((p->red*(100.0-pixel.red)+
782 colorize.red*pixel.red)/100.0);
783 q->green=(Quantum) ((p->green*(100.0-pixel.green)+
784 colorize.green*pixel.green)/100.0);
785 q->blue=(Quantum) ((p->blue*(100.0-pixel.blue)+
786 colorize.blue*pixel.blue)/100.0);
787 q->opacity=(Quantum) ((p->opacity*(100.0-pixel.opacity)+
788 colorize.opacity*pixel.opacity)/100.0);
792 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
793 if (sync == MagickFalse)
795 if (image->progress_monitor != (MagickProgressMonitor) NULL)
800 #if defined(MAGICKCORE_OPENMP_SUPPORT)
801 #pragma omp critical (MagickCore_ColorizeImage)
803 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
804 if (proceed == MagickFalse)
808 image_view=DestroyCacheView(image_view);
809 colorize_view=DestroyCacheView(colorize_view);
810 if (status == MagickFalse)
811 colorize_image=DestroyImage(colorize_image);
812 return(colorize_image);
816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820 % C o l o r M a t r i x I m a g e %
824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
826 % ColorMatrixImage() applies color transformation to an image. This method
827 % permits saturation changes, hue rotation, luminance to alpha, and various
828 % other effects. Although variable-sized transformation matrices can be used,
829 % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
830 % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
831 % except offsets are in column 6 rather than 5 (in support of CMYKA images)
832 % and offsets are normalized (divide Flash offset by 255).
834 % The format of the ColorMatrixImage method is:
836 % Image *ColorMatrixImage(const Image *image,
837 % const KernelInfo *color_matrix,ExceptionInfo *exception)
839 % A description of each parameter follows:
841 % o image: the image.
843 % o color_matrix: the color matrix.
845 % o exception: return any errors or warnings in this structure.
848 MagickExport Image *ColorMatrixImage(const Image *image,
849 const KernelInfo *color_matrix,ExceptionInfo *exception)
851 #define ColorMatrixImageTag "ColorMatrix/Image"
860 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
861 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
862 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
863 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
864 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
865 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
888 assert(image != (Image *) NULL);
889 assert(image->signature == MagickSignature);
890 if (image->debug != MagickFalse)
891 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
892 assert(exception != (ExceptionInfo *) NULL);
893 assert(exception->signature == MagickSignature);
895 for (v=0; v < (ssize_t) color_matrix->height; v++)
896 for (u=0; u < (ssize_t) color_matrix->width; u++)
898 if ((v < 6) && (u < 6))
899 ColorMatrix[v][u]=color_matrix->values[i];
903 Initialize color image.
905 color_image=CloneImage(image,0,0,MagickTrue,exception);
906 if (color_image == (Image *) NULL)
907 return((Image *) NULL);
908 if (SetImageStorageClass(color_image,DirectClass) == MagickFalse)
910 InheritException(exception,&color_image->exception);
911 color_image=DestroyImage(color_image);
912 return((Image *) NULL);
914 if (image->debug != MagickFalse)
917 format[MaxTextExtent],
920 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
921 " ColorMatrix image with color matrix:");
922 message=AcquireString("");
923 for (v=0; v < 6; v++)
926 (void) FormatMagickString(format,MaxTextExtent,"%.20g: ",(double) v);
927 (void) ConcatenateString(&message,format);
928 for (u=0; u < 6; u++)
930 (void) FormatMagickString(format,MaxTextExtent,"%+f ",
932 (void) ConcatenateString(&message,format);
934 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
936 message=DestroyString(message);
943 image_view=AcquireCacheView(image);
944 color_view=AcquireCacheView(color_image);
945 #if defined(MAGICKCORE_OPENMP_SUPPORT)
946 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
948 for (y=0; y < (ssize_t) image->rows; y++)
953 register const IndexPacket
956 register const PixelPacket
963 *restrict color_indexes;
968 if (status == MagickFalse)
970 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
971 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
973 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
978 indexes=GetCacheViewVirtualIndexQueue(image_view);
979 color_indexes=GetCacheViewAuthenticIndexQueue(color_view);
980 for (x=0; x < (ssize_t) image->columns; x++)
988 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
989 for (v=0; v < (ssize_t) height; v++)
991 pixel=ColorMatrix[v][0]*p->red+ColorMatrix[v][1]*p->green+
992 ColorMatrix[v][2]*p->blue;
993 if (image->matte != MagickFalse)
994 pixel+=ColorMatrix[v][3]*(QuantumRange-p->opacity);
995 if (image->colorspace == CMYKColorspace)
996 pixel+=ColorMatrix[v][4]*indexes[x];
997 pixel+=QuantumRange*ColorMatrix[v][5];
1000 case 0: q->red=ClampToQuantum(pixel); break;
1001 case 1: q->green=ClampToQuantum(pixel); break;
1002 case 2: q->blue=ClampToQuantum(pixel); break;
1005 if (image->matte != MagickFalse)
1006 q->opacity=ClampToQuantum(QuantumRange-pixel);
1011 if (image->colorspace == CMYKColorspace)
1012 color_indexes[x]=ClampToQuantum(pixel);
1020 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1022 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1027 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1028 #pragma omp critical (MagickCore_ColorMatrixImage)
1030 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1032 if (proceed == MagickFalse)
1036 color_view=DestroyCacheView(color_view);
1037 image_view=DestroyCacheView(image_view);
1038 if (status == MagickFalse)
1039 color_image=DestroyImage(color_image);
1040 return(color_image);
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 + D e s t r o y F x I n f o %
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054 % DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1056 % The format of the DestroyFxInfo method is:
1058 % ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1060 % A description of each parameter follows:
1062 % o fx_info: the fx info.
1065 MagickExport FxInfo *DestroyFxInfo(FxInfo *fx_info)
1070 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1071 fx_info->expression=DestroyString(fx_info->expression);
1072 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1073 fx_info->colors=DestroySplayTree(fx_info->colors);
1074 for (i=0; i < (ssize_t) GetImageListLength(fx_info->images); i++)
1075 fx_info->resample_filter[i]=DestroyResampleFilter(
1076 fx_info->resample_filter[i]);
1077 fx_info->resample_filter=(ResampleFilter **) RelinquishMagickMemory(
1078 fx_info->resample_filter);
1079 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1080 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1089 + 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 %
1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1095 % FxEvaluateChannelExpression() evaluates an expression and returns the
1098 % The format of the FxEvaluateExpression method is:
1100 % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
1101 % const ChannelType channel,const ssize_t x,const ssize_t y,
1102 % MagickRealType *alpha,Exceptioninfo *exception)
1103 % MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1104 % MagickRealType *alpha,Exceptioninfo *exception)
1106 % A description of each parameter follows:
1108 % o fx_info: the fx info.
1110 % o channel: the channel.
1112 % o x,y: the pixel position.
1114 % o alpha: the result.
1116 % o exception: return any errors or warnings in this structure.
1120 static inline double MagickMax(const double x,const double y)
1127 static inline double MagickMin(const double x,const double y)
1134 static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
1135 ChannelType channel,const char *symbol,ExceptionInfo *exception)
1139 statistic[MaxTextExtent];
1147 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1149 switch (*++p) /* e.g. depth.r */
1151 case 'r': channel=RedChannel; break;
1152 case 'g': channel=GreenChannel; break;
1153 case 'b': channel=BlueChannel; break;
1154 case 'c': channel=CyanChannel; break;
1155 case 'm': channel=MagentaChannel; break;
1156 case 'y': channel=YellowChannel; break;
1157 case 'k': channel=BlackChannel; break;
1160 (void) FormatMagickString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
1161 (double) channel,symbol);
1162 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1163 if (value != (const char *) NULL)
1164 return(QuantumScale*StringToDouble(value));
1165 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1166 if (LocaleNCompare(symbol,"depth",5) == 0)
1171 depth=GetImageChannelDepth(image,channel,exception);
1172 (void) FormatMagickString(statistic,MaxTextExtent,"%.20g",(double)
1175 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1181 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1183 (void) FormatMagickString(statistic,MaxTextExtent,"%g",kurtosis);
1185 if (LocaleNCompare(symbol,"maxima",6) == 0)
1191 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1192 (void) FormatMagickString(statistic,MaxTextExtent,"%g",maxima);
1194 if (LocaleNCompare(symbol,"mean",4) == 0)
1200 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1202 (void) FormatMagickString(statistic,MaxTextExtent,"%g",mean);
1204 if (LocaleNCompare(symbol,"minima",6) == 0)
1210 (void) GetImageChannelRange(image,channel,&minima,&maxima,exception);
1211 (void) FormatMagickString(statistic,MaxTextExtent,"%g",minima);
1213 if (LocaleNCompare(symbol,"skewness",8) == 0)
1219 (void) GetImageChannelKurtosis(image,channel,&kurtosis,&skewness,
1221 (void) FormatMagickString(statistic,MaxTextExtent,"%g",skewness);
1223 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1229 (void) GetImageChannelMean(image,channel,&mean,&standard_deviation,
1231 (void) FormatMagickString(statistic,MaxTextExtent,"%g",
1232 standard_deviation);
1234 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1235 ConstantString(statistic));
1236 return(QuantumScale*StringToDouble(statistic));
1239 static MagickRealType
1240 FxEvaluateSubexpression(FxInfo *,const ChannelType,const ssize_t,
1241 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
1243 static inline MagickRealType FxMax(FxInfo *fx_info,const ChannelType channel,
1244 const ssize_t x,const ssize_t y,const char *expression,
1245 ExceptionInfo *exception)
1251 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1252 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1255 static inline MagickRealType FxMin(FxInfo *fx_info,ChannelType channel,
1256 const ssize_t x,const ssize_t y,const char *expression,
1257 ExceptionInfo *exception)
1263 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1264 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1267 static inline const char *FxSubexpression(const char *expression,
1268 ExceptionInfo *exception)
1277 subexpression=expression;
1278 while ((*subexpression != '\0') &&
1279 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1281 if (strchr("(",(int) *subexpression) != (char *) NULL)
1284 if (strchr(")",(int) *subexpression) != (char *) NULL)
1288 if (*subexpression == '\0')
1289 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1290 "UnbalancedParenthesis","`%s'",expression);
1291 return(subexpression);
1294 static MagickRealType FxGetSymbol(FxInfo *fx_info,const ChannelType channel,
1295 const ssize_t x,const ssize_t y,const char *expression,
1296 ExceptionInfo *exception)
1300 subexpression[MaxTextExtent],
1301 symbol[MaxTextExtent];
1330 i=GetImageIndexInList(fx_info->images);
1334 if (isalpha((int) *(p+1)) == 0)
1336 if (strchr("suv",(int) *p) != (char *) NULL)
1343 i=GetImageIndexInList(fx_info->images);
1346 case 'u': i=0; break;
1347 case 'v': i=1; break;
1354 for (p++; *p != '\0'; )
1368 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1370 i=(ssize_t) (alpha+0.5);
1376 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1383 for (p++; *p != '\0'; )
1397 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1408 for (p++; *p != '\0'; )
1422 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1432 length=GetImageListLength(fx_info->images);
1434 i+=(ssize_t) length;
1436 image=GetImageFromList(fx_info->images,i);
1437 if (image == (Image *) NULL)
1439 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1440 "NoSuchImage","`%s'",expression);
1443 (void) ResamplePixelColor(fx_info->resample_filter[i],point.x,point.y,&pixel);
1444 if ((strlen(p) > 2) &&
1445 (LocaleCompare(p,"intensity") != 0) &&
1446 (LocaleCompare(p,"luminance") != 0) &&
1447 (LocaleCompare(p,"hue") != 0) &&
1448 (LocaleCompare(p,"saturation") != 0) &&
1449 (LocaleCompare(p,"lightness") != 0))
1452 name[MaxTextExtent];
1454 (void) CopyMagickString(name,p,MaxTextExtent);
1455 for (q=name+(strlen(name)-1); q > name; q--)
1465 if ((strlen(name) > 2) &&
1466 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1471 color=(MagickPixelPacket *) GetValueFromSplayTree(fx_info->colors,
1473 if (color != (MagickPixelPacket *) NULL)
1479 if (QueryMagickColor(name,&pixel,fx_info->exception) != MagickFalse)
1481 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
1482 CloneMagickPixelPacket(&pixel));
1487 (void) CopyMagickString(symbol,p,MaxTextExtent);
1488 StripString(symbol);
1489 if (*symbol == '\0')
1493 case RedChannel: return(QuantumScale*pixel.red);
1494 case GreenChannel: return(QuantumScale*pixel.green);
1495 case BlueChannel: return(QuantumScale*pixel.blue);
1496 case OpacityChannel:
1498 if (pixel.matte == MagickFalse)
1500 fx_info->matte=MagickFalse;
1503 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1507 if (image->colorspace != CMYKColorspace)
1509 (void) ThrowMagickException(exception,GetMagickModule(),
1510 OptionError,"ColorSeparatedImageRequired","`%s'",
1514 return(QuantumScale*pixel.index);
1519 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1520 "UnableToParseExpression","`%s'",p);
1528 if (LocaleCompare(symbol,"a") == 0)
1529 return((MagickRealType) (QuantumScale*GetAlphaPixelComponent(&pixel)));
1535 if (LocaleCompare(symbol,"b") == 0)
1536 return(QuantumScale*pixel.blue);
1542 if (LocaleNCompare(symbol,"channel",7) == 0)
1550 flags=ParseGeometry(symbol+7,&channel_info);
1551 if (image->colorspace == CMYKColorspace)
1556 if ((flags & RhoValue) == 0)
1558 return(channel_info.rho);
1560 case MagentaChannel:
1562 if ((flags & SigmaValue) == 0)
1564 return(channel_info.sigma);
1568 if ((flags & XiValue) == 0)
1570 return(channel_info.xi);
1574 if ((flags & PsiValue) == 0)
1576 return(channel_info.psi);
1578 case OpacityChannel:
1580 if ((flags & ChiValue) == 0)
1582 return(channel_info.chi);
1591 if ((flags & RhoValue) == 0)
1593 return(channel_info.rho);
1597 if ((flags & SigmaValue) == 0)
1599 return(channel_info.sigma);
1603 if ((flags & XiValue) == 0)
1605 return(channel_info.xi);
1607 case OpacityChannel:
1609 if ((flags & PsiValue) == 0)
1611 return(channel_info.psi);
1615 if ((flags & ChiValue) == 0)
1617 return(channel_info.chi);
1624 if (LocaleCompare(symbol,"c") == 0)
1625 return(QuantumScale*pixel.red);
1631 if (LocaleNCompare(symbol,"depth",5) == 0)
1632 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1638 if (LocaleCompare(symbol,"g") == 0)
1639 return(QuantumScale*pixel.green);
1645 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1646 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1647 if (LocaleCompare(symbol,"k") == 0)
1649 if (image->colorspace != CMYKColorspace)
1651 (void) ThrowMagickException(exception,GetMagickModule(),
1652 OptionError,"ColorSeparatedImageRequired","`%s'",
1656 return(QuantumScale*pixel.index);
1663 if (LocaleCompare(symbol,"h") == 0)
1664 return((MagickRealType) image->rows);
1665 if (LocaleCompare(symbol,"hue") == 0)
1672 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1673 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1681 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1682 (LocaleCompare(symbol,"image.minima") == 0) ||
1683 (LocaleCompare(symbol,"image.maxima") == 0) ||
1684 (LocaleCompare(symbol,"image.mean") == 0) ||
1685 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1686 (LocaleCompare(symbol,"image.skewness") == 0) ||
1687 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1688 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1689 if (LocaleCompare(symbol,"image.resolution.x") == 0)
1690 return(image->x_resolution);
1691 if (LocaleCompare(symbol,"image.resolution.y") == 0)
1692 return(image->y_resolution);
1693 if (LocaleCompare(symbol,"intensity") == 0)
1694 return(QuantumScale*MagickPixelIntensityToQuantum(&pixel));
1695 if (LocaleCompare(symbol,"i") == 0)
1696 return((MagickRealType) x);
1702 if (LocaleCompare(symbol,"j") == 0)
1703 return((MagickRealType) y);
1709 if (LocaleCompare(symbol,"lightness") == 0)
1716 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1717 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1720 if (LocaleCompare(symbol,"luminance") == 0)
1725 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1726 return(QuantumScale*luminence);
1733 if (LocaleNCompare(symbol,"maxima",6) == 0)
1734 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1735 if (LocaleNCompare(symbol,"mean",4) == 0)
1736 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1737 if (LocaleNCompare(symbol,"minima",6) == 0)
1738 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1739 if (LocaleCompare(symbol,"m") == 0)
1740 return(QuantumScale*pixel.blue);
1746 if (LocaleCompare(symbol,"n") == 0)
1747 return((MagickRealType) GetImageListLength(fx_info->images));
1753 if (LocaleCompare(symbol,"o") == 0)
1754 return(QuantumScale*pixel.opacity);
1760 if (LocaleCompare(symbol,"page.height") == 0)
1761 return((MagickRealType) image->page.height);
1762 if (LocaleCompare(symbol,"page.width") == 0)
1763 return((MagickRealType) image->page.width);
1764 if (LocaleCompare(symbol,"page.x") == 0)
1765 return((MagickRealType) image->page.x);
1766 if (LocaleCompare(symbol,"page.y") == 0)
1767 return((MagickRealType) image->page.y);
1773 if (LocaleCompare(symbol,"resolution.x") == 0)
1774 return(image->x_resolution);
1775 if (LocaleCompare(symbol,"resolution.y") == 0)
1776 return(image->y_resolution);
1777 if (LocaleCompare(symbol,"r") == 0)
1778 return(QuantumScale*pixel.red);
1784 if (LocaleCompare(symbol,"saturation") == 0)
1791 ConvertRGBToHSL(ClampToQuantum(pixel.red),ClampToQuantum(pixel.green),
1792 ClampToQuantum(pixel.blue),&hue,&saturation,&lightness);
1795 if (LocaleNCompare(symbol,"skewness",8) == 0)
1796 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1797 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1798 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1804 if (LocaleCompare(symbol,"t") == 0)
1805 return((MagickRealType) fx_info->images->scene);
1811 if (LocaleCompare(symbol,"w") == 0)
1812 return((MagickRealType) image->columns);
1818 if (LocaleCompare(symbol,"y") == 0)
1819 return(QuantumScale*pixel.green);
1825 if (LocaleCompare(symbol,"z") == 0)
1830 depth=(MagickRealType) GetImageChannelDepth(image,channel,
1831 fx_info->exception);
1839 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1840 if (value != (const char *) NULL)
1841 return((MagickRealType) StringToDouble(value));
1842 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1843 "UnableToParseExpression","`%s'",symbol);
1847 static const char *FxOperatorPrecedence(const char *expression,
1848 ExceptionInfo *exception)
1852 UndefinedPrecedence,
1854 BitwiseComplementPrecedence,
1856 ExponentialNotationPrecedence,
1860 RelationalPrecedence,
1861 EquivalencyPrecedence,
1862 BitwiseAndPrecedence,
1863 BitwiseOrPrecedence,
1864 LogicalAndPrecedence,
1865 LogicalOrPrecedence,
1867 AssignmentPrecedence,
1887 subexpression=(const char *) NULL;
1888 target=NullPrecedence;
1889 while (*expression != '\0')
1891 precedence=UndefinedPrecedence;
1892 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1897 switch (*expression)
1902 if (LocaleNCompare(expression,"atan2",5) == 0)
1912 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1913 (LocaleNCompare(expression,"j1",2) == 0))
1922 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1929 if ((c == (int) '{') || (c == (int) '['))
1932 if ((c == (int) '}') || (c == (int) ']'))
1935 switch ((unsigned char) *expression)
1940 precedence=BitwiseComplementPrecedence;
1946 precedence=ExponentPrecedence;
1951 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1952 (strchr(")",c) != (char *) NULL))) &&
1953 (((islower((int) ((char) *expression)) != 0) ||
1954 (strchr("(",(int) *expression) != (char *) NULL)) ||
1955 ((isdigit((int) ((char) c)) == 0) &&
1956 (isdigit((int) ((char) *expression)) != 0))) &&
1957 (strchr("xy",(int) *expression) == (char *) NULL))
1958 precedence=MultiplyPrecedence;
1965 precedence=MultiplyPrecedence;
1971 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1973 precedence=AdditionPrecedence;
1976 case LeftShiftOperator:
1977 case RightShiftOperator:
1979 precedence=ShiftPrecedence;
1983 case LessThanEqualOperator:
1984 case GreaterThanEqualOperator:
1987 precedence=RelationalPrecedence;
1991 case NotEqualOperator:
1993 precedence=EquivalencyPrecedence;
1998 precedence=BitwiseAndPrecedence;
2003 precedence=BitwiseOrPrecedence;
2006 case LogicalAndOperator:
2008 precedence=LogicalAndPrecedence;
2011 case LogicalOrOperator:
2013 precedence=LogicalOrPrecedence;
2016 case ExponentialNotation:
2018 precedence=ExponentialNotationPrecedence;
2024 precedence=TernaryPrecedence;
2029 precedence=AssignmentPrecedence;
2034 precedence=CommaPrecedence;
2039 precedence=SeparatorPrecedence;
2043 if ((precedence == BitwiseComplementPrecedence) ||
2044 (precedence == TernaryPrecedence) ||
2045 (precedence == AssignmentPrecedence))
2047 if (precedence > target)
2050 Right-to-left associativity.
2053 subexpression=expression;
2057 if (precedence >= target)
2060 Left-to-right associativity.
2063 subexpression=expression;
2065 if (strchr("(",(int) *expression) != (char *) NULL)
2066 expression=FxSubexpression(expression,exception);
2067 c=(int) (*expression++);
2069 return(subexpression);
2072 static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
2073 const ChannelType channel,const ssize_t x,const ssize_t y,
2074 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
2078 subexpression[MaxTextExtent];
2088 if (exception->severity != UndefinedException)
2090 while (isspace((int) *expression) != 0)
2092 if (*expression == '\0')
2094 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2095 "MissingExpression","`%s'",expression);
2098 *subexpression='\0';
2099 p=FxOperatorPrecedence(expression,exception);
2100 if (p != (const char *) NULL)
2102 (void) CopyMagickString(subexpression,expression,(size_t)
2104 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2106 switch ((unsigned char) *p)
2110 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2111 *beta=(MagickRealType) (~(size_t) *beta);
2116 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2117 return(*beta == 0.0 ? 1.0 : 0.0);
2121 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2122 channel,x,y,++p,beta,exception));
2126 case ExponentialNotation:
2128 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2129 return(alpha*(*beta));
2133 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2136 if (exception->severity == UndefinedException)
2137 (void) ThrowMagickException(exception,GetMagickModule(),
2138 OptionError,"DivideByZero","`%s'",expression);
2141 return(alpha/(*beta));
2145 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2146 *beta=fabs(floor(((double) *beta)+0.5));
2149 (void) ThrowMagickException(exception,GetMagickModule(),
2150 OptionError,"DivideByZero","`%s'",expression);
2153 return(fmod((double) alpha,(double) *beta));
2157 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2158 return(alpha+(*beta));
2162 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2163 return(alpha-(*beta));
2165 case LeftShiftOperator:
2167 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2168 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
2172 case RightShiftOperator:
2174 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2175 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
2181 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2182 return(alpha < *beta ? 1.0 : 0.0);
2184 case LessThanEqualOperator:
2186 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2187 return(alpha <= *beta ? 1.0 : 0.0);
2191 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2192 return(alpha > *beta ? 1.0 : 0.0);
2194 case GreaterThanEqualOperator:
2196 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2197 return(alpha >= *beta ? 1.0 : 0.0);
2201 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2202 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2204 case NotEqualOperator:
2206 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2207 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2211 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2212 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
2218 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2219 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
2223 case LogicalAndOperator:
2225 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2226 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2229 case LogicalOrOperator:
2231 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2232 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2240 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2242 p=StringToken(":",&q);
2243 if (q == (char *) NULL)
2245 (void) ThrowMagickException(exception,GetMagickModule(),
2246 OptionError,"UnableToParseExpression","`%s'",subexpression);
2249 if (fabs((double) alpha) > MagickEpsilon)
2250 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2252 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2258 numeric[MaxTextExtent];
2261 while (isalpha((int) ((unsigned char) *q)) != 0)
2265 (void) ThrowMagickException(exception,GetMagickModule(),
2266 OptionError,"UnableToParseExpression","`%s'",subexpression);
2269 ClearMagickException(exception);
2270 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2271 (void) FormatMagickString(numeric,MaxTextExtent,"%g",(double)
2273 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2274 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2275 subexpression),ConstantString(numeric));
2280 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2285 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2290 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2296 if (strchr("(",(int) *expression) != (char *) NULL)
2298 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2299 subexpression[strlen(subexpression)-1]='\0';
2300 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2304 switch (*expression)
2308 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2314 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2320 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2322 return((MagickRealType) (~(size_t) (gamma+0.5)));
2327 if (LocaleNCompare(expression,"abs",3) == 0)
2329 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2331 return((MagickRealType) fabs((double) alpha));
2333 if (LocaleNCompare(expression,"acos",4) == 0)
2335 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2337 return((MagickRealType) acos((double) alpha));
2339 #if defined(MAGICKCORE_HAVE_J1)
2340 if (LocaleNCompare(expression,"airy",4) == 0)
2342 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2346 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
2347 return(gamma*gamma);
2350 if (LocaleNCompare(expression,"asin",4) == 0)
2352 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2354 return((MagickRealType) asin((double) alpha));
2356 if (LocaleNCompare(expression,"alt",3) == 0)
2358 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2360 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
2362 if (LocaleNCompare(expression,"atan2",5) == 0)
2364 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2366 return((MagickRealType) atan2((double) alpha,(double) *beta));
2368 if (LocaleNCompare(expression,"atan",4) == 0)
2370 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2372 return((MagickRealType) atan((double) alpha));
2374 if (LocaleCompare(expression,"a") == 0)
2375 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2381 if (LocaleCompare(expression,"b") == 0)
2382 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2388 if (LocaleNCompare(expression,"ceil",4) == 0)
2390 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2392 return((MagickRealType) ceil((double) alpha));
2394 if (LocaleNCompare(expression,"cosh",4) == 0)
2396 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2398 return((MagickRealType) cosh((double) alpha));
2400 if (LocaleNCompare(expression,"cos",3) == 0)
2402 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2404 return((MagickRealType) cos((double) alpha));
2406 if (LocaleCompare(expression,"c") == 0)
2407 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2413 if (LocaleNCompare(expression,"debug",5) == 0)
2418 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2420 if (fx_info->images->colorspace == CMYKColorspace)
2423 case CyanChannel: type="cyan"; break;
2424 case MagentaChannel: type="magenta"; break;
2425 case YellowChannel: type="yellow"; break;
2426 case OpacityChannel: type="opacity"; break;
2427 case BlackChannel: type="black"; break;
2428 default: type="unknown"; break;
2433 case RedChannel: type="red"; break;
2434 case GreenChannel: type="green"; break;
2435 case BlueChannel: type="blue"; break;
2436 case OpacityChannel: type="opacity"; break;
2437 default: type="unknown"; break;
2439 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2440 if (strlen(subexpression) > 1)
2441 subexpression[strlen(subexpression)-1]='\0';
2442 if (fx_info->file != (FILE *) NULL)
2443 (void) fprintf(fx_info->file,"%s[%.20g,%.20g].%s: %s=%.*g\n",
2444 fx_info->images->filename,(double) x,(double) y,type,
2445 subexpression,GetMagickPrecision(),(double) alpha);
2453 if (LocaleCompare(expression,"epsilon") == 0)
2454 return((MagickRealType) MagickEpsilon);
2455 if (LocaleNCompare(expression,"exp",3) == 0)
2457 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2459 return((MagickRealType) exp((double) alpha));
2461 if (LocaleCompare(expression,"e") == 0)
2462 return((MagickRealType) 2.7182818284590452354);
2468 if (LocaleNCompare(expression,"floor",5) == 0)
2470 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2472 return((MagickRealType) floor((double) alpha));
2479 if (LocaleCompare(expression,"g") == 0)
2480 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2486 if (LocaleCompare(expression,"h") == 0)
2487 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2488 if (LocaleCompare(expression,"hue") == 0)
2489 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2490 if (LocaleNCompare(expression,"hypot",5) == 0)
2492 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2494 return((MagickRealType) hypot((double) alpha,(double) *beta));
2501 if (LocaleCompare(expression,"k") == 0)
2502 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2508 if (LocaleCompare(expression,"intensity") == 0)
2509 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2510 if (LocaleNCompare(expression,"int",3) == 0)
2512 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2514 return((MagickRealType) floor(alpha));
2516 if (LocaleCompare(expression,"i") == 0)
2517 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2523 if (LocaleCompare(expression,"j") == 0)
2524 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2525 #if defined(MAGICKCORE_HAVE_J0)
2526 if (LocaleNCompare(expression,"j0",2) == 0)
2528 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2530 return((MagickRealType) j0((double) alpha));
2533 #if defined(MAGICKCORE_HAVE_J1)
2534 if (LocaleNCompare(expression,"j1",2) == 0)
2536 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2538 return((MagickRealType) j1((double) alpha));
2541 #if defined(MAGICKCORE_HAVE_J1)
2542 if (LocaleNCompare(expression,"jinc",4) == 0)
2544 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2548 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
2558 if (LocaleNCompare(expression,"ln",2) == 0)
2560 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2562 return((MagickRealType) log((double) alpha));
2564 if (LocaleNCompare(expression,"logtwo",6) == 0)
2566 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2568 return((MagickRealType) log10((double) alpha))/log10(2.0);
2570 if (LocaleNCompare(expression,"log",3) == 0)
2572 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2574 return((MagickRealType) log10((double) alpha));
2576 if (LocaleCompare(expression,"lightness") == 0)
2577 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2583 if (LocaleCompare(expression,"MaxRGB") == 0)
2584 return((MagickRealType) QuantumRange);
2585 if (LocaleNCompare(expression,"maxima",6) == 0)
2587 if (LocaleNCompare(expression,"max",3) == 0)
2588 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2589 if (LocaleNCompare(expression,"minima",6) == 0)
2591 if (LocaleNCompare(expression,"min",3) == 0)
2592 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2593 if (LocaleNCompare(expression,"mod",3) == 0)
2595 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2597 return((MagickRealType) fmod((double) alpha,(double) *beta));
2599 if (LocaleCompare(expression,"m") == 0)
2600 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2606 if (LocaleCompare(expression,"n") == 0)
2607 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2613 if (LocaleCompare(expression,"Opaque") == 0)
2615 if (LocaleCompare(expression,"o") == 0)
2616 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2622 if (LocaleCompare(expression,"pi") == 0)
2623 return((MagickRealType) MagickPI);
2624 if (LocaleNCompare(expression,"pow",3) == 0)
2626 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2628 return((MagickRealType) pow((double) alpha,(double) *beta));
2630 if (LocaleCompare(expression,"p") == 0)
2631 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2637 if (LocaleCompare(expression,"QuantumRange") == 0)
2638 return((MagickRealType) QuantumRange);
2639 if (LocaleCompare(expression,"QuantumScale") == 0)
2640 return((MagickRealType) QuantumScale);
2646 if (LocaleNCompare(expression,"rand",4) == 0)
2647 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2648 if (LocaleNCompare(expression,"round",5) == 0)
2650 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2652 return((MagickRealType) floor((double) alpha+0.5));
2654 if (LocaleCompare(expression,"r") == 0)
2655 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2661 if (LocaleCompare(expression,"saturation") == 0)
2662 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2663 if (LocaleNCompare(expression,"sign",4) == 0)
2665 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2667 return(alpha < 0.0 ? -1.0 : 1.0);
2669 if (LocaleNCompare(expression,"sinc",4) == 0)
2671 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2675 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2679 if (LocaleNCompare(expression,"sinh",4) == 0)
2681 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2683 return((MagickRealType) sinh((double) alpha));
2685 if (LocaleNCompare(expression,"sin",3) == 0)
2687 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2689 return((MagickRealType) sin((double) alpha));
2691 if (LocaleNCompare(expression,"sqrt",4) == 0)
2693 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2695 return((MagickRealType) sqrt((double) alpha));
2697 if (LocaleCompare(expression,"s") == 0)
2698 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2704 if (LocaleNCompare(expression,"tanh",4) == 0)
2706 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2708 return((MagickRealType) tanh((double) alpha));
2710 if (LocaleNCompare(expression,"tan",3) == 0)
2712 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2714 return((MagickRealType) tan((double) alpha));
2716 if (LocaleCompare(expression,"Transparent") == 0)
2718 if (LocaleNCompare(expression,"trunc",5) == 0)
2720 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2723 return((MagickRealType) floor((double) alpha));
2724 return((MagickRealType) ceil((double) alpha));
2726 if (LocaleCompare(expression,"t") == 0)
2727 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2733 if (LocaleCompare(expression,"u") == 0)
2734 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2740 if (LocaleCompare(expression,"v") == 0)
2741 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2747 if (LocaleCompare(expression,"w") == 0)
2748 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2754 if (LocaleCompare(expression,"y") == 0)
2755 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2761 if (LocaleCompare(expression,"z") == 0)
2762 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2768 q=(char *) expression;
2769 alpha=strtod(expression,&q);
2770 if (q == expression)
2771 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2775 MagickExport MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
2776 MagickRealType *alpha,ExceptionInfo *exception)
2781 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2785 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2786 MagickRealType *alpha,ExceptionInfo *exception)
2795 fx_info->file=(FILE *) NULL;
2796 status=FxEvaluateChannelExpression(fx_info,GrayChannel,0,0,alpha,exception);
2801 MagickExport MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
2802 const ChannelType channel,const ssize_t x,const ssize_t y,
2803 MagickRealType *alpha,ExceptionInfo *exception)
2809 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2811 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2823 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2825 % FxImage() applies a mathematical expression to the specified image.
2827 % The format of the FxImage method is:
2829 % Image *FxImage(const Image *image,const char *expression,
2830 % ExceptionInfo *exception)
2831 % Image *FxImageChannel(const Image *image,const ChannelType channel,
2832 % const char *expression,ExceptionInfo *exception)
2834 % A description of each parameter follows:
2836 % o image: the image.
2838 % o channel: the channel.
2840 % o expression: A mathematical expression.
2842 % o exception: return any errors or warnings in this structure.
2846 static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2851 assert(fx_info != (FxInfo **) NULL);
2852 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
2853 if (fx_info[i] != (FxInfo *) NULL)
2854 fx_info[i]=DestroyFxInfo(fx_info[i]);
2855 fx_info=(FxInfo **) RelinquishAlignedMemory(fx_info);
2859 static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2860 ExceptionInfo *exception)
2877 number_threads=GetOpenMPMaximumThreads();
2878 fx_info=(FxInfo **) AcquireAlignedMemory(number_threads,sizeof(*fx_info));
2879 if (fx_info == (FxInfo **) NULL)
2880 return((FxInfo **) NULL);
2881 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2882 if (*expression != '@')
2883 fx_expression=ConstantString(expression);
2885 fx_expression=FileToString(expression+1,~0,exception);
2886 for (i=0; i < (ssize_t) number_threads; i++)
2888 fx_info[i]=AcquireFxInfo(image,fx_expression);
2889 if (fx_info[i] == (FxInfo *) NULL)
2890 return(DestroyFxThreadSet(fx_info));
2891 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
2893 fx_expression=DestroyString(fx_expression);
2897 MagickExport Image *FxImage(const Image *image,const char *expression,
2898 ExceptionInfo *exception)
2903 fx_image=FxImageChannel(image,GrayChannel,expression,exception);
2907 MagickExport Image *FxImageChannel(const Image *image,const ChannelType channel,
2908 const char *expression,ExceptionInfo *exception)
2910 #define FxImageTag "Fx/Image"
2933 assert(image != (Image *) NULL);
2934 assert(image->signature == MagickSignature);
2935 if (image->debug != MagickFalse)
2936 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2937 fx_image=CloneImage(image,0,0,MagickTrue,exception);
2938 if (fx_image == (Image *) NULL)
2939 return((Image *) NULL);
2940 if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse)
2942 InheritException(exception,&fx_image->exception);
2943 fx_image=DestroyImage(fx_image);
2944 return((Image *) NULL);
2946 fx_info=AcquireFxThreadSet(image,expression,exception);
2947 if (fx_info == (FxInfo **) NULL)
2949 fx_image=DestroyImage(fx_image);
2950 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
2952 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
2953 if (status == MagickFalse)
2955 fx_image=DestroyImage(fx_image);
2956 fx_info=DestroyFxThreadSet(fx_info);
2957 return((Image *) NULL);
2964 fx_view=AcquireCacheView(fx_image);
2965 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2966 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2968 for (y=0; y < (ssize_t) fx_image->rows; y++)
2971 id = GetOpenMPThreadId();
2976 register IndexPacket
2977 *restrict fx_indexes;
2982 register PixelPacket
2985 if (status == MagickFalse)
2987 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
2988 if (q == (PixelPacket *) NULL)
2993 fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);
2995 for (x=0; x < (ssize_t) fx_image->columns; x++)
2997 if ((channel & RedChannel) != 0)
2999 (void) FxEvaluateChannelExpression(fx_info[id],RedChannel,x,y,
3001 q->red=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3003 if ((channel & GreenChannel) != 0)
3005 (void) FxEvaluateChannelExpression(fx_info[id],GreenChannel,x,y,
3007 q->green=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3009 if ((channel & BlueChannel) != 0)
3011 (void) FxEvaluateChannelExpression(fx_info[id],BlueChannel,x,y,
3013 q->blue=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3015 if ((channel & OpacityChannel) != 0)
3017 (void) FxEvaluateChannelExpression(fx_info[id],OpacityChannel,x,y,
3019 if (image->matte == MagickFalse)
3020 q->opacity=ClampToQuantum((MagickRealType) QuantumRange*alpha);
3022 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
3023 QuantumRange*alpha));
3025 if (((channel & IndexChannel) != 0) &&
3026 (fx_image->colorspace == CMYKColorspace))
3028 (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y,
3030 fx_indexes[x]=(IndexPacket) ClampToQuantum((MagickRealType)
3031 QuantumRange*alpha);
3035 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3037 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3042 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3043 #pragma omp critical (MagickCore_FxImageChannel)
3045 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3046 if (proceed == MagickFalse)
3050 fx_image->matte=fx_info[0]->matte;
3051 fx_view=DestroyCacheView(fx_view);
3052 fx_info=DestroyFxThreadSet(fx_info);
3053 if (status == MagickFalse)
3054 fx_image=DestroyImage(fx_image);
3059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3063 % I m p l o d e I m a g e %
3067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3069 % ImplodeImage() creates a new image that is a copy of an existing
3070 % one with the image pixels "implode" by the specified percentage. It
3071 % allocates the memory necessary for the new Image structure and returns a
3072 % pointer to the new image.
3074 % The format of the ImplodeImage method is:
3076 % Image *ImplodeImage(const Image *image,const double amount,
3077 % ExceptionInfo *exception)
3079 % A description of each parameter follows:
3081 % o implode_image: Method ImplodeImage returns a pointer to the image
3082 % after it is implode. A null image is returned if there is a memory
3085 % o image: the image.
3087 % o amount: Define the extent of the implosion.
3089 % o exception: return any errors or warnings in this structure.
3092 MagickExport Image *ImplodeImage(const Image *image,const double amount,
3093 ExceptionInfo *exception)
3095 #define ImplodeImageTag "Implode/Image"
3121 **restrict resample_filter;
3127 Initialize implode image attributes.
3129 assert(image != (Image *) NULL);
3130 assert(image->signature == MagickSignature);
3131 if (image->debug != MagickFalse)
3132 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3133 assert(exception != (ExceptionInfo *) NULL);
3134 assert(exception->signature == MagickSignature);
3135 implode_image=CloneImage(image,0,0,MagickTrue,exception);
3136 if (implode_image == (Image *) NULL)
3137 return((Image *) NULL);
3138 if (SetImageStorageClass(implode_image,DirectClass) == MagickFalse)
3140 InheritException(exception,&implode_image->exception);
3141 implode_image=DestroyImage(implode_image);
3142 return((Image *) NULL);
3144 if (implode_image->background_color.opacity != OpaqueOpacity)
3145 implode_image->matte=MagickTrue;
3147 Compute scaling factor.
3151 center.x=0.5*image->columns;
3152 center.y=0.5*image->rows;
3154 if (image->columns > image->rows)
3155 scale.y=(double) image->columns/(double) image->rows;
3157 if (image->columns < image->rows)
3159 scale.x=(double) image->rows/(double) image->columns;
3167 GetMagickPixelPacket(implode_image,&zero);
3168 resample_filter=AcquireResampleFilterThreadSet(image,
3169 UndefinedVirtualPixelMethod,MagickTrue,exception);
3170 image_view=AcquireCacheView(image);
3171 implode_view=AcquireCacheView(implode_image);
3172 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3173 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
3175 for (y=0; y < (ssize_t) image->rows; y++)
3178 id = GetOpenMPThreadId();
3189 register IndexPacket
3190 *restrict implode_indexes;
3195 register PixelPacket
3198 if (status == MagickFalse)
3200 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3202 if (q == (PixelPacket *) NULL)
3207 implode_indexes=GetCacheViewAuthenticIndexQueue(implode_view);
3208 delta.y=scale.y*(double) (y-center.y);
3210 for (x=0; x < (ssize_t) image->columns; x++)
3213 Determine if the pixel is within an ellipse.
3215 delta.x=scale.x*(double) (x-center.x);
3216 distance=delta.x*delta.x+delta.y*delta.y;
3217 if (distance < (radius*radius))
3227 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3228 radius/2)),-amount);
3229 (void) ResamplePixelColor(resample_filter[id],(double)
3230 (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3231 scale.y+center.y),&pixel);
3232 SetPixelPacket(implode_image,&pixel,q,implode_indexes+x);
3236 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3238 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3243 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3244 #pragma omp critical (MagickCore_ImplodeImage)
3246 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3247 if (proceed == MagickFalse)
3251 implode_view=DestroyCacheView(implode_view);
3252 image_view=DestroyCacheView(image_view);
3253 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
3254 if (status == MagickFalse)
3255 implode_image=DestroyImage(implode_image);
3256 return(implode_image);
3260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3264 % M o r p h I m a g e s %
3268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3270 % The MorphImages() method requires a minimum of two images. The first
3271 % image is transformed into the second by a number of intervening images
3272 % as specified by frames.
3274 % The format of the MorphImage method is:
3276 % Image *MorphImages(const Image *image,const size_t number_frames,
3277 % ExceptionInfo *exception)
3279 % A description of each parameter follows:
3281 % o image: the image.
3283 % o number_frames: Define the number of in-between image to generate.
3284 % The more in-between frames, the smoother the morph.
3286 % o exception: return any errors or warnings in this structure.
3289 MagickExport Image *MorphImages(const Image *image,
3290 const size_t number_frames,ExceptionInfo *exception)
3292 #define MorphImageTag "Morph/Image"
3308 register const Image
3318 Clone first frame in sequence.
3320 assert(image != (Image *) NULL);
3321 assert(image->signature == MagickSignature);
3322 if (image->debug != MagickFalse)
3323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3324 assert(exception != (ExceptionInfo *) NULL);
3325 assert(exception->signature == MagickSignature);
3326 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3327 if (morph_images == (Image *) NULL)
3328 return((Image *) NULL);
3329 if (GetNextImageInList(image) == (Image *) NULL)
3334 for (i=1; i < (ssize_t) number_frames; i++)
3336 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3337 if (morph_image == (Image *) NULL)
3339 morph_images=DestroyImageList(morph_images);
3340 return((Image *) NULL);
3342 AppendImageToList(&morph_images,morph_image);
3343 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3348 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3350 if (proceed == MagickFalse)
3354 return(GetFirstImageInList(morph_images));
3357 Morph image sequence.
3362 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3364 for (i=0; i < (ssize_t) number_frames; i++)
3370 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3372 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
3373 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
3374 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3375 next->filter,next->blur,exception);
3376 if (morph_image == (Image *) NULL)
3378 morph_images=DestroyImageList(morph_images);
3379 return((Image *) NULL);
3381 if (SetImageStorageClass(morph_image,DirectClass) == MagickFalse)
3383 InheritException(exception,&morph_image->exception);
3384 morph_image=DestroyImage(morph_image);
3385 return((Image *) NULL);
3387 AppendImageToList(&morph_images,morph_image);
3388 morph_images=GetLastImageInList(morph_images);
3389 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3390 morph_images->rows,GetNextImageInList(next)->filter,
3391 GetNextImageInList(next)->blur,exception);
3392 if (morph_image == (Image *) NULL)
3394 morph_images=DestroyImageList(morph_images);
3395 return((Image *) NULL);
3397 image_view=AcquireCacheView(morph_image);
3398 morph_view=AcquireCacheView(morph_images);
3399 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3400 #pragma omp parallel for schedule(dynamic,4) shared(status)
3402 for (y=0; y < (ssize_t) morph_images->rows; y++)
3407 register const PixelPacket
3413 register PixelPacket
3416 if (status == MagickFalse)
3418 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3420 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3422 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
3427 for (x=0; x < (ssize_t) morph_images->columns; x++)
3429 q->red=ClampToQuantum(alpha*q->red+beta*GetRedPixelComponent(p));
3430 q->green=ClampToQuantum(alpha*q->green+beta*
3431 GetGreenPixelComponent(p));
3432 q->blue=ClampToQuantum(alpha*q->blue+beta*GetBluePixelComponent(p));
3433 q->opacity=ClampToQuantum(alpha*q->opacity+beta*
3434 GetOpacityPixelComponent(p));
3438 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3439 if (sync == MagickFalse)
3442 morph_view=DestroyCacheView(morph_view);
3443 image_view=DestroyCacheView(image_view);
3444 morph_image=DestroyImage(morph_image);
3446 if (i < (ssize_t) number_frames)
3449 Clone last frame in sequence.
3451 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3452 if (morph_image == (Image *) NULL)
3454 morph_images=DestroyImageList(morph_images);
3455 return((Image *) NULL);
3457 AppendImageToList(&morph_images,morph_image);
3458 morph_images=GetLastImageInList(morph_images);
3459 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3464 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3465 #pragma omp critical (MagickCore_MorphImages)
3467 proceed=SetImageProgress(image,MorphImageTag,scene,
3468 GetImageListLength(image));
3469 if (proceed == MagickFalse)
3474 if (GetNextImageInList(next) != (Image *) NULL)
3476 morph_images=DestroyImageList(morph_images);
3477 return((Image *) NULL);
3479 return(GetFirstImageInList(morph_images));
3483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3487 % P l a s m a I m a g e %
3491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3493 % PlasmaImage() initializes an image with plasma fractal values. The image
3494 % must be initialized with a base color and the random number generator
3495 % seeded before this method is called.
3497 % The format of the PlasmaImage method is:
3499 % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
3500 % size_t attenuate,size_t depth)
3502 % A description of each parameter follows:
3504 % o image: the image.
3506 % o segment: Define the region to apply plasma fractals values.
3508 % o attenuate: Define the plasma attenuation factor.
3510 % o depth: Limit the plasma recursion depth.
3514 static inline Quantum PlasmaPixel(RandomInfo *random_info,
3515 const MagickRealType pixel,const MagickRealType noise)
3520 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
3525 MagickExport MagickBooleanType PlasmaImageProxy(Image *image,
3526 CacheView *image_view,RandomInfo *random_info,const SegmentInfo *segment,
3527 size_t attenuate,size_t depth)
3545 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3553 Divide the area into quadrants and recurse.
3557 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3558 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3559 local_info=(*segment);
3560 local_info.x2=(double) x_mid;
3561 local_info.y2=(double) y_mid;
3562 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3564 local_info=(*segment);
3565 local_info.y1=(double) y_mid;
3566 local_info.x2=(double) x_mid;
3567 (void) PlasmaImageProxy(image,image_view,random_info,&local_info,
3569 local_info=(*segment);
3570 local_info.x1=(double) x_mid;
3571 local_info.y2=(double) y_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.y1=(double) y_mid;
3577 return(PlasmaImageProxy(image,image_view,random_info,&local_info,
3580 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3581 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
3582 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3583 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3584 return(MagickFalse);
3586 Average pixels and apply plasma.
3588 exception=(&image->exception);
3589 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3590 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3592 register PixelPacket
3598 x=(ssize_t) ceil(segment->x1-0.5);
3599 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3600 ceil(segment->y1-0.5),&u,exception);
3601 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3602 ceil(segment->y2-0.5),&v,exception);
3603 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3604 if (q == (PixelPacket *) NULL)
3606 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3608 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3610 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3612 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3613 if (segment->x1 != segment->x2)
3618 x=(ssize_t) ceil(segment->x2-0.5);
3619 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3620 ceil(segment->y1-0.5),&u,exception);
3621 (void) GetOneCacheViewVirtualPixel(image_view,x,(ssize_t)
3622 ceil(segment->y2-0.5),&v,exception);
3623 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
3624 if (q == (PixelPacket *) NULL)
3626 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3628 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3630 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3632 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3635 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3637 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3639 register PixelPacket
3645 y=(ssize_t) ceil(segment->y2-0.5);
3646 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3647 ceil(segment->x1-0.5),y,&u,exception);
3648 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3649 ceil(segment->x2-0.5),y,&v,exception);
3650 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3651 if (q == (PixelPacket *) NULL)
3653 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3655 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3657 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3659 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3661 if (segment->y1 != segment->y2)
3663 register PixelPacket
3669 y=(ssize_t) ceil(segment->y1-0.5);
3670 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3671 ceil(segment->x1-0.5),y,&u,exception);
3672 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t)
3673 ceil(segment->x2-0.5),y,&v,exception);
3674 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
3675 if (q == (PixelPacket *) NULL)
3677 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3679 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/
3681 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3683 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3686 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3688 register PixelPacket
3694 x=(ssize_t) ceil(segment->x1-0.5);
3695 y=(ssize_t) ceil(segment->y1-0.5);
3696 (void) GetOneVirtualPixel(image,x,y,&u,exception);
3697 x=(ssize_t) ceil(segment->x2-0.5);
3698 y=(ssize_t) ceil(segment->y2-0.5);
3699 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&v,exception);
3700 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
3701 if (q == (PixelPacket *) NULL)
3703 q->red=PlasmaPixel(random_info,(MagickRealType) (u.red+v.red)/2.0,
3705 q->green=PlasmaPixel(random_info,(MagickRealType) (u.green+v.green)/2.0,
3707 q->blue=PlasmaPixel(random_info,(MagickRealType) (u.blue+v.blue)/2.0,
3709 (void) SyncCacheViewAuthenticPixels(image_view,exception);
3711 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3713 return(MagickFalse);
3716 MagickExport MagickBooleanType PlasmaImage(Image *image,
3717 const SegmentInfo *segment,size_t attenuate,size_t depth)
3728 if (image->debug != MagickFalse)
3729 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3730 assert(image != (Image *) NULL);
3731 assert(image->signature == MagickSignature);
3732 if (image->debug != MagickFalse)
3733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3734 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3735 return(MagickFalse);
3736 image_view=AcquireCacheView(image);
3737 random_info=AcquireRandomInfo();
3738 status=PlasmaImageProxy(image,image_view,random_info,segment,attenuate,depth);
3739 random_info=DestroyRandomInfo(random_info);
3740 image_view=DestroyCacheView(image_view);
3745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3749 % P o l a r o i d I m a g e %
3753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3755 % PolaroidImage() simulates a Polaroid picture.
3757 % The format of the AnnotateImage method is:
3759 % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3760 % const double angle,ExceptionInfo exception)
3762 % A description of each parameter follows:
3764 % o image: the image.
3766 % o draw_info: the draw info.
3768 % o angle: Apply the effect along this angle.
3770 % o exception: return any errors or warnings in this structure.
3773 MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
3774 const double angle,ExceptionInfo *exception)
3795 Simulate a Polaroid picture.
3797 assert(image != (Image *) NULL);
3798 assert(image->signature == MagickSignature);
3799 if (image->debug != MagickFalse)
3800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3801 assert(exception != (ExceptionInfo *) NULL);
3802 assert(exception->signature == MagickSignature);
3803 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
3804 image->rows)/25.0,10.0);
3805 height=image->rows+2*quantum;
3806 caption_image=(Image *) NULL;
3807 value=GetImageProperty(image,"Caption");
3808 if (value != (const char *) NULL)
3812 geometry[MaxTextExtent];
3827 Generate caption image.
3829 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3830 if (caption_image == (Image *) NULL)
3831 return((Image *) NULL);
3832 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3833 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
3835 (void) CloneString(&annotate_info->text,caption);
3836 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
3838 status=SetImageExtent(caption_image,image->columns,(size_t)
3839 ((count+1)*(metrics.ascent-metrics.descent)+0.5));
3840 if (status == MagickFalse)
3841 caption_image=DestroyImage(caption_image);
3844 caption_image->background_color=image->border_color;
3845 (void) SetImageBackgroundColor(caption_image);
3846 (void) CloneString(&annotate_info->text,caption);
3847 (void) FormatMagickString(geometry,MaxTextExtent,"+0+%g",
3849 if (annotate_info->gravity == UndefinedGravity)
3850 (void) CloneString(&annotate_info->geometry,AcquireString(
3852 (void) AnnotateImage(caption_image,annotate_info);
3853 height+=caption_image->rows;
3855 annotate_info=DestroyDrawInfo(annotate_info);
3856 caption=DestroyString(caption);
3858 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3860 if (picture_image == (Image *) NULL)
3862 if (caption_image != (Image *) NULL)
3863 caption_image=DestroyImage(caption_image);
3864 return((Image *) NULL);
3866 picture_image->background_color=image->border_color;
3867 (void) SetImageBackgroundColor(picture_image);
3868 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum);
3869 if (caption_image != (Image *) NULL)
3871 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
3872 quantum,(ssize_t) (image->rows+3*quantum/2));
3873 caption_image=DestroyImage(caption_image);
3875 (void) QueryColorDatabase("none",&picture_image->background_color,exception);
3876 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel);
3877 rotate_image=RotateImage(picture_image,90.0,exception);
3878 picture_image=DestroyImage(picture_image);
3879 if (rotate_image == (Image *) NULL)
3880 return((Image *) NULL);
3881 picture_image=rotate_image;
3882 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
3883 picture_image->columns,exception);
3884 picture_image=DestroyImage(picture_image);
3885 if (bend_image == (Image *) NULL)
3886 return((Image *) NULL);
3887 InheritException(&bend_image->exception,exception);
3888 picture_image=bend_image;
3889 rotate_image=RotateImage(picture_image,-90.0,exception);
3890 picture_image=DestroyImage(picture_image);
3891 if (rotate_image == (Image *) NULL)
3892 return((Image *) NULL);
3893 picture_image=rotate_image;
3894 picture_image->background_color=image->background_color;
3895 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
3897 if (polaroid_image == (Image *) NULL)
3899 picture_image=DestroyImage(picture_image);
3900 return(picture_image);
3902 flop_image=FlopImage(polaroid_image,exception);
3903 polaroid_image=DestroyImage(polaroid_image);
3904 if (flop_image == (Image *) NULL)
3906 picture_image=DestroyImage(picture_image);
3907 return(picture_image);
3909 polaroid_image=flop_image;
3910 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
3911 (ssize_t) (-0.01*picture_image->columns/2.0),0L);
3912 picture_image=DestroyImage(picture_image);
3913 (void) QueryColorDatabase("none",&polaroid_image->background_color,exception);
3914 rotate_image=RotateImage(polaroid_image,angle,exception);
3915 polaroid_image=DestroyImage(polaroid_image);
3916 if (rotate_image == (Image *) NULL)
3917 return((Image *) NULL);
3918 polaroid_image=rotate_image;
3919 trim_image=TrimImage(polaroid_image,exception);
3920 polaroid_image=DestroyImage(polaroid_image);
3921 if (trim_image == (Image *) NULL)
3922 return((Image *) NULL);
3923 polaroid_image=trim_image;
3924 return(polaroid_image);
3928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3932 % S e p i a T o n e I m a g e %
3936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3938 % MagickSepiaToneImage() applies a special effect to the image, similar to the
3939 % effect achieved in a photo darkroom by sepia toning. Threshold ranges from
3940 % 0 to QuantumRange and is a measure of the extent of the sepia toning. A
3941 % threshold of 80% is a good starting point for a reasonable tone.
3943 % The format of the SepiaToneImage method is:
3945 % Image *SepiaToneImage(const Image *image,const double threshold,
3946 % ExceptionInfo *exception)
3948 % A description of each parameter follows:
3950 % o image: the image.
3952 % o threshold: the tone threshold.
3954 % o exception: return any errors or warnings in this structure.
3957 MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
3958 ExceptionInfo *exception)
3960 #define SepiaToneImageTag "SepiaTone/Image"
3979 Initialize sepia-toned image attributes.
3981 assert(image != (const Image *) NULL);
3982 assert(image->signature == MagickSignature);
3983 if (image->debug != MagickFalse)
3984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3985 assert(exception != (ExceptionInfo *) NULL);
3986 assert(exception->signature == MagickSignature);
3987 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3988 if (sepia_image == (Image *) NULL)
3989 return((Image *) NULL);
3990 if (SetImageStorageClass(sepia_image,DirectClass) == MagickFalse)
3992 InheritException(exception,&sepia_image->exception);
3993 sepia_image=DestroyImage(sepia_image);
3994 return((Image *) NULL);
3997 Tone each row of the image.
4001 image_view=AcquireCacheView(image);
4002 sepia_view=AcquireCacheView(sepia_image);
4003 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4004 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4006 for (y=0; y < (ssize_t) image->rows; y++)
4008 register const PixelPacket
4014 register PixelPacket
4017 if (status == MagickFalse)
4019 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4020 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4022 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4027 for (x=0; x < (ssize_t) image->columns; x++)
4033 intensity=(MagickRealType) PixelIntensityToQuantum(p);
4034 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4035 (MagickRealType) QuantumRange-threshold;
4036 q->red=ClampToQuantum(tone);
4037 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4038 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
4039 q->green=ClampToQuantum(tone);
4040 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
4041 q->blue=ClampToQuantum(tone);
4043 if ((MagickRealType) q->green < tone)
4044 q->green=ClampToQuantum(tone);
4045 if ((MagickRealType) q->blue < tone)
4046 q->blue=ClampToQuantum(tone);
4050 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4052 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4057 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4058 #pragma omp critical (MagickCore_SepiaToneImage)
4060 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4062 if (proceed == MagickFalse)
4066 sepia_view=DestroyCacheView(sepia_view);
4067 image_view=DestroyCacheView(image_view);
4068 (void) NormalizeImage(sepia_image);
4069 (void) ContrastImage(sepia_image,MagickTrue);
4070 if (status == MagickFalse)
4071 sepia_image=DestroyImage(sepia_image);
4072 return(sepia_image);
4076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4080 % S h a d o w I m a g e %
4084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4086 % ShadowImage() simulates a shadow from the specified image and returns it.
4088 % The format of the ShadowImage method is:
4090 % Image *ShadowImage(const Image *image,const double opacity,
4091 % const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4092 % ExceptionInfo *exception)
4094 % A description of each parameter follows:
4096 % o image: the image.
4098 % o opacity: percentage transparency.
4100 % o sigma: the standard deviation of the Gaussian, in pixels.
4102 % o x_offset: the shadow x-offset.
4104 % o y_offset: the shadow y-offset.
4106 % o exception: return any errors or warnings in this structure.
4109 MagickExport Image *ShadowImage(const Image *image,const double opacity,
4110 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4111 ExceptionInfo *exception)
4113 #define ShadowImageTag "Shadow/Image"
4135 assert(image != (Image *) NULL);
4136 assert(image->signature == MagickSignature);
4137 if (image->debug != MagickFalse)
4138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4139 assert(exception != (ExceptionInfo *) NULL);
4140 assert(exception->signature == MagickSignature);
4141 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4142 if (clone_image == (Image *) NULL)
4143 return((Image *) NULL);
4144 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4145 clone_image->compose=OverCompositeOp;
4146 border_info.width=(size_t) floor(2.0*sigma+0.5);
4147 border_info.height=(size_t) floor(2.0*sigma+0.5);
4150 (void) QueryColorDatabase("none",&clone_image->border_color,exception);
4151 border_image=BorderImage(clone_image,&border_info,exception);
4152 clone_image=DestroyImage(clone_image);
4153 if (border_image == (Image *) NULL)
4154 return((Image *) NULL);
4155 if (border_image->matte == MagickFalse)
4156 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel);
4162 image_view=AcquireCacheView(border_image);
4163 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4164 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4166 for (y=0; y < (ssize_t) border_image->rows; y++)
4171 register PixelPacket
4174 if (status == MagickFalse)
4176 q=GetCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4178 if (q == (PixelPacket *) NULL)
4183 for (x=0; x < (ssize_t) border_image->columns; x++)
4185 q->red=border_image->background_color.red;
4186 q->green=border_image->background_color.green;
4187 q->blue=border_image->background_color.blue;
4188 if (border_image->matte == MagickFalse)
4189 q->opacity=border_image->background_color.opacity;
4191 q->opacity=ClampToQuantum((MagickRealType) (QuantumRange-
4192 GetAlphaPixelComponent(q)*opacity/100.0));
4195 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4197 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4202 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4203 #pragma omp critical (MagickCore_ShadowImage)
4205 proceed=SetImageProgress(image,ShadowImageTag,progress++,
4206 border_image->rows);
4207 if (proceed == MagickFalse)
4211 image_view=DestroyCacheView(image_view);
4212 shadow_image=BlurImageChannel(border_image,AlphaChannel,0.0,sigma,exception);
4213 border_image=DestroyImage(border_image);
4214 if (shadow_image == (Image *) NULL)
4215 return((Image *) NULL);
4216 if (shadow_image->page.width == 0)
4217 shadow_image->page.width=shadow_image->columns;
4218 if (shadow_image->page.height == 0)
4219 shadow_image->page.height=shadow_image->rows;
4220 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4221 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4222 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4223 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
4224 return(shadow_image);
4228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4232 % S k e t c h I m a g e %
4236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4238 % SketchImage() simulates a pencil sketch. We convolve the image with a
4239 % Gaussian operator of the given radius and standard deviation (sigma). For
4240 % reasonable results, radius should be larger than sigma. Use a radius of 0
4241 % and SketchImage() selects a suitable radius for you. Angle gives the angle
4244 % The format of the SketchImage method is:
4246 % Image *SketchImage(const Image *image,const double radius,
4247 % const double sigma,const double angle,ExceptionInfo *exception)
4249 % A description of each parameter follows:
4251 % o image: the image.
4253 % o radius: the radius of the Gaussian, in pixels, not counting
4256 % o sigma: the standard deviation of the Gaussian, in pixels.
4258 % o angle: Apply the effect along this angle.
4260 % o exception: return any errors or warnings in this structure.
4263 MagickExport Image *SketchImage(const Image *image,const double radius,
4264 const double sigma,const double angle,ExceptionInfo *exception)
4286 **restrict random_info;
4291 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4292 MagickTrue,exception);
4293 if (random_image == (Image *) NULL)
4294 return((Image *) NULL);
4296 GetMagickPixelPacket(random_image,&zero);
4297 random_info=AcquireRandomInfoThreadSet();
4298 random_view=AcquireCacheView(random_image);
4299 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4300 #pragma omp parallel for schedule(dynamic,4) shared(status)
4302 for (y=0; y < (ssize_t) random_image->rows; y++)
4305 id = GetOpenMPThreadId();
4310 register IndexPacket
4316 register PixelPacket
4319 if (status == MagickFalse)
4321 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4323 if (q == (PixelPacket *) NULL)
4328 indexes=GetCacheViewAuthenticIndexQueue(random_view);
4330 for (x=0; x < (ssize_t) random_image->columns; x++)
4332 pixel.red=(MagickRealType) (QuantumRange*
4333 GetPseudoRandomValue(random_info[id]));
4334 pixel.green=pixel.red;
4335 pixel.blue=pixel.red;
4336 if (image->colorspace == CMYKColorspace)
4337 pixel.index=pixel.red;
4338 SetPixelPacket(random_image,&pixel,q,indexes+x);
4341 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4344 random_view=DestroyCacheView(random_view);
4345 random_info=DestroyRandomInfoThreadSet(random_info);
4346 if (status == MagickFalse)
4348 random_image=DestroyImage(random_image);
4349 return(random_image);
4351 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
4352 random_image=DestroyImage(random_image);
4353 if (blur_image == (Image *) NULL)
4354 return((Image *) NULL);
4355 dodge_image=EdgeImage(blur_image,radius,exception);
4356 blur_image=DestroyImage(blur_image);
4357 if (dodge_image == (Image *) NULL)
4358 return((Image *) NULL);
4359 (void) NormalizeImage(dodge_image);
4360 (void) NegateImage(dodge_image,MagickFalse);
4361 (void) TransformImage(&dodge_image,(char *) NULL,"50%");
4362 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4363 if (sketch_image == (Image *) NULL)
4365 dodge_image=DestroyImage(dodge_image);
4366 return((Image *) NULL);
4368 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0);
4369 dodge_image=DestroyImage(dodge_image);
4370 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4371 if (blend_image == (Image *) NULL)
4373 sketch_image=DestroyImage(sketch_image);
4374 return((Image *) NULL);
4376 (void) SetImageArtifact(blend_image,"compose:args","20x80");
4377 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0);
4378 blend_image=DestroyImage(blend_image);
4379 return(sketch_image);
4383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4387 % S o l a r i z e I m a g e %
4391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4393 % SolarizeImage() applies a special effect to the image, similar to the effect
4394 % achieved in a photo darkroom by selectively exposing areas of photo
4395 % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4396 % measure of the extent of the solarization.
4398 % The format of the SolarizeImage method is:
4400 % MagickBooleanType SolarizeImage(Image *image,const double threshold)
4402 % A description of each parameter follows:
4404 % o image: the image.
4406 % o threshold: Define the extent of the solarization.
4409 MagickExport MagickBooleanType SolarizeImage(Image *image,
4410 const double threshold)
4412 #define SolarizeImageTag "Solarize/Image"
4429 assert(image != (Image *) NULL);
4430 assert(image->signature == MagickSignature);
4431 if (image->debug != MagickFalse)
4432 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4433 if (image->storage_class == PseudoClass)
4441 for (i=0; i < (ssize_t) image->colors; i++)
4443 if ((MagickRealType) image->colormap[i].red > threshold)
4444 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4445 if ((MagickRealType) image->colormap[i].green > threshold)
4446 image->colormap[i].green=(Quantum) QuantumRange-
4447 image->colormap[i].green;
4448 if ((MagickRealType) image->colormap[i].blue > threshold)
4449 image->colormap[i].blue=(Quantum) QuantumRange-
4450 image->colormap[i].blue;
4458 exception=(&image->exception);
4459 image_view=AcquireCacheView(image);
4460 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4461 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4463 for (y=0; y < (ssize_t) image->rows; y++)
4468 register PixelPacket
4471 if (status == MagickFalse)
4473 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4475 if (q == (PixelPacket *) NULL)
4480 for (x=0; x < (ssize_t) image->columns; x++)
4482 if ((MagickRealType) q->red > threshold)
4483 q->red=(Quantum) QuantumRange-q->red;
4484 if ((MagickRealType) q->green > threshold)
4485 q->green=(Quantum) QuantumRange-q->green;
4486 if ((MagickRealType) q->blue > threshold)
4487 q->blue=(Quantum) QuantumRange-q->blue;
4490 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4492 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4497 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4498 #pragma omp critical (MagickCore_SolarizeImage)
4500 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4501 if (proceed == MagickFalse)
4505 image_view=DestroyCacheView(image_view);
4510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4514 % S t e g a n o I m a g e %
4518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4520 % SteganoImage() hides a digital watermark within the image. Recover
4521 % the hidden watermark later to prove that the authenticity of an image.
4522 % Offset defines the start position within the image to hide the watermark.
4524 % The format of the SteganoImage method is:
4526 % Image *SteganoImage(const Image *image,Image *watermark,
4527 % ExceptionInfo *exception)
4529 % A description of each parameter follows:
4531 % o image: the image.
4533 % o watermark: the watermark image.
4535 % o exception: return any errors or warnings in this structure.
4538 MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4539 ExceptionInfo *exception)
4541 #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
4542 #define SetBit(alpha,i,set) (alpha)=(Quantum) ((set) != 0 ? (size_t) (alpha) \
4543 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
4544 #define SteganoImageTag "Stegano/Image"
4562 register PixelPacket
4579 Initialize steganographic image attributes.
4581 assert(image != (const Image *) NULL);
4582 assert(image->signature == MagickSignature);
4583 if (image->debug != MagickFalse)
4584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4585 assert(watermark != (const Image *) NULL);
4586 assert(watermark->signature == MagickSignature);
4587 assert(exception != (ExceptionInfo *) NULL);
4588 assert(exception->signature == MagickSignature);
4590 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4591 if (stegano_image == (Image *) NULL)
4592 return((Image *) NULL);
4593 if (SetImageStorageClass(stegano_image,DirectClass) == MagickFalse)
4595 InheritException(exception,&stegano_image->exception);
4596 stegano_image=DestroyImage(stegano_image);
4597 return((Image *) NULL);
4599 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4601 Hide watermark in low-order bits of image.
4606 depth=stegano_image->depth;
4608 watermark_view=AcquireCacheView(watermark);
4609 stegano_view=AcquireCacheView(stegano_image);
4610 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
4612 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
4614 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
4616 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,&pixel,exception);
4617 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
4619 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4620 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4622 if (q == (PixelPacket *) NULL)
4628 SetBit(q->red,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4633 SetBit(q->green,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4638 SetBit(q->blue,j,GetBit(PixelIntensityToQuantum(&pixel),i));
4642 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
4648 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
4650 if (k == image->offset)
4654 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4659 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4661 if (proceed == MagickFalse)
4665 stegano_view=DestroyCacheView(stegano_view);
4666 watermark_view=DestroyCacheView(watermark_view);
4667 if (stegano_image->storage_class == PseudoClass)
4668 (void) SyncImage(stegano_image);
4669 return(stegano_image);
4673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4677 % S t e r e o A n a g l y p h I m a g e %
4681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4683 % StereoAnaglyphImage() combines two images and produces a single image that
4684 % is the composite of a left and right image of a stereo pair. Special
4685 % red-green stereo glasses are required to view this effect.
4687 % The format of the StereoAnaglyphImage method is:
4689 % Image *StereoImage(const Image *left_image,const Image *right_image,
4690 % ExceptionInfo *exception)
4691 % Image *StereoAnaglyphImage(const Image *left_image,
4692 % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4693 % ExceptionInfo *exception)
4695 % A description of each parameter follows:
4697 % o left_image: the left image.
4699 % o right_image: the right image.
4701 % o exception: return any errors or warnings in this structure.
4703 % o x_offset: amount, in pixels, by which the left image is offset to the
4704 % right of the right image.
4706 % o y_offset: amount, in pixels, by which the left image is offset to the
4707 % bottom of the right image.
4711 MagickExport Image *StereoImage(const Image *left_image,
4712 const Image *right_image,ExceptionInfo *exception)
4714 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4717 MagickExport Image *StereoAnaglyphImage(const Image *left_image,
4718 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
4719 ExceptionInfo *exception)
4721 #define StereoImageTag "Stereo/Image"
4735 assert(left_image != (const Image *) NULL);
4736 assert(left_image->signature == MagickSignature);
4737 if (left_image->debug != MagickFalse)
4738 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4739 left_image->filename);
4740 assert(right_image != (const Image *) NULL);
4741 assert(right_image->signature == MagickSignature);
4742 assert(exception != (ExceptionInfo *) NULL);
4743 assert(exception->signature == MagickSignature);
4744 assert(right_image != (const Image *) NULL);
4746 if ((left_image->columns != right_image->columns) ||
4747 (left_image->rows != right_image->rows))
4748 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4750 Initialize stereo image attributes.
4752 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4753 MagickTrue,exception);
4754 if (stereo_image == (Image *) NULL)
4755 return((Image *) NULL);
4756 if (SetImageStorageClass(stereo_image,DirectClass) == MagickFalse)
4758 InheritException(exception,&stereo_image->exception);
4759 stereo_image=DestroyImage(stereo_image);
4760 return((Image *) NULL);
4763 Copy left image to red channel and right image to blue channel.
4765 for (y=0; y < (ssize_t) stereo_image->rows; y++)
4767 register const PixelPacket
4774 register PixelPacket
4777 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4779 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4780 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
4781 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL) ||
4782 (r == (PixelPacket *) NULL))
4784 for (x=0; x < (ssize_t) stereo_image->columns; x++)
4786 r->red=GetRedPixelComponent(p);
4789 r->opacity=(Quantum) ((p->opacity+q->opacity)/2);
4794 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4796 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4801 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4802 stereo_image->rows);
4803 if (proceed == MagickFalse)
4807 return(stereo_image);
4811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4815 % S w i r l I m a g e %
4819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4821 % SwirlImage() swirls the pixels about the center of the image, where
4822 % degrees indicates the sweep of the arc through which each pixel is moved.
4823 % You get a more dramatic effect as the degrees move from 1 to 360.
4825 % The format of the SwirlImage method is:
4827 % Image *SwirlImage(const Image *image,double degrees,
4828 % ExceptionInfo *exception)
4830 % A description of each parameter follows:
4832 % o image: the image.
4834 % o degrees: Define the tightness of the swirling effect.
4836 % o exception: return any errors or warnings in this structure.
4839 MagickExport Image *SwirlImage(const Image *image,double degrees,
4840 ExceptionInfo *exception)
4842 #define SwirlImageTag "Swirl/Image"
4868 **restrict resample_filter;
4874 Initialize swirl image attributes.
4876 assert(image != (const Image *) NULL);
4877 assert(image->signature == MagickSignature);
4878 if (image->debug != MagickFalse)
4879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4880 assert(exception != (ExceptionInfo *) NULL);
4881 assert(exception->signature == MagickSignature);
4882 swirl_image=CloneImage(image,0,0,MagickTrue,exception);
4883 if (swirl_image == (Image *) NULL)
4884 return((Image *) NULL);
4885 if (SetImageStorageClass(swirl_image,DirectClass) == MagickFalse)
4887 InheritException(exception,&swirl_image->exception);
4888 swirl_image=DestroyImage(swirl_image);
4889 return((Image *) NULL);
4891 if (swirl_image->background_color.opacity != OpaqueOpacity)
4892 swirl_image->matte=MagickTrue;
4894 Compute scaling factor.
4896 center.x=(double) image->columns/2.0;
4897 center.y=(double) image->rows/2.0;
4898 radius=MagickMax(center.x,center.y);
4901 if (image->columns > image->rows)
4902 scale.y=(double) image->columns/(double) image->rows;
4904 if (image->columns < image->rows)
4905 scale.x=(double) image->rows/(double) image->columns;
4906 degrees=(double) DegreesToRadians(degrees);
4912 GetMagickPixelPacket(swirl_image,&zero);
4913 resample_filter=AcquireResampleFilterThreadSet(image,
4914 UndefinedVirtualPixelMethod,MagickTrue,exception);
4915 image_view=AcquireCacheView(image);
4916 swirl_view=AcquireCacheView(swirl_image);
4917 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4918 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
4920 for (y=0; y < (ssize_t) image->rows; y++)
4923 id = GetOpenMPThreadId();
4934 register IndexPacket
4935 *restrict swirl_indexes;
4940 register PixelPacket
4943 if (status == MagickFalse)
4945 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
4947 if (q == (PixelPacket *) NULL)
4952 swirl_indexes=GetCacheViewAuthenticIndexQueue(swirl_view);
4953 delta.y=scale.y*(double) (y-center.y);
4955 for (x=0; x < (ssize_t) image->columns; x++)
4958 Determine if the pixel is within an ellipse.
4960 delta.x=scale.x*(double) (x-center.x);
4961 distance=delta.x*delta.x+delta.y*delta.y;
4962 if (distance < (radius*radius))
4972 factor=1.0-sqrt((double) distance)/radius;
4973 sine=sin((double) (degrees*factor*factor));
4974 cosine=cos((double) (degrees*factor*factor));
4975 (void) ResamplePixelColor(resample_filter[id],(double) ((cosine*
4976 delta.x-sine*delta.y)/scale.x+center.x),(double) ((sine*delta.x+
4977 cosine*delta.y)/scale.y+center.y),&pixel);
4978 SetPixelPacket(swirl_image,&pixel,q,swirl_indexes+x);
4982 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
4984 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4989 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4990 #pragma omp critical (MagickCore_SwirlImage)
4992 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
4993 if (proceed == MagickFalse)
4997 swirl_view=DestroyCacheView(swirl_view);
4998 image_view=DestroyCacheView(image_view);
4999 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5000 if (status == MagickFalse)
5001 swirl_image=DestroyImage(swirl_image);
5002 return(swirl_image);
5006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5010 % T i n t I m a g e %
5014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5016 % TintImage() applies a color vector to each pixel in the image. The length
5017 % of the vector is 0 for black and white and at its maximum for the midtones.
5018 % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5020 % The format of the TintImage method is:
5022 % Image *TintImage(const Image *image,const char *opacity,
5023 % const PixelPacket tint,ExceptionInfo *exception)
5025 % A description of each parameter follows:
5027 % o image: the image.
5029 % o opacity: A color value used for tinting.
5031 % o tint: A color value used for tinting.
5033 % o exception: return any errors or warnings in this structure.
5036 MagickExport Image *TintImage(const Image *image,const char *opacity,
5037 const PixelPacket tint,ExceptionInfo *exception)
5039 #define TintImageTag "Tint/Image"
5068 Allocate tint image.
5070 assert(image != (const Image *) NULL);
5071 assert(image->signature == MagickSignature);
5072 if (image->debug != MagickFalse)
5073 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5074 assert(exception != (ExceptionInfo *) NULL);
5075 assert(exception->signature == MagickSignature);
5076 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5077 if (tint_image == (Image *) NULL)
5078 return((Image *) NULL);
5079 if (SetImageStorageClass(tint_image,DirectClass) == MagickFalse)
5081 InheritException(exception,&tint_image->exception);
5082 tint_image=DestroyImage(tint_image);
5083 return((Image *) NULL);
5085 if (opacity == (const char *) NULL)
5088 Determine RGB values of the color.
5090 flags=ParseGeometry(opacity,&geometry_info);
5091 pixel.red=geometry_info.rho;
5092 if ((flags & SigmaValue) != 0)
5093 pixel.green=geometry_info.sigma;
5095 pixel.green=pixel.red;
5096 if ((flags & XiValue) != 0)
5097 pixel.blue=geometry_info.xi;
5099 pixel.blue=pixel.red;
5100 if ((flags & PsiValue) != 0)
5101 pixel.opacity=geometry_info.psi;
5103 pixel.opacity=(MagickRealType) OpaqueOpacity;
5104 color_vector.red=(MagickRealType) (pixel.red*tint.red/100.0-
5105 PixelIntensity(&tint));
5106 color_vector.green=(MagickRealType) (pixel.green*tint.green/100.0-
5107 PixelIntensity(&tint));
5108 color_vector.blue=(MagickRealType) (pixel.blue*tint.blue/100.0-
5109 PixelIntensity(&tint));
5115 image_view=AcquireCacheView(image);
5116 tint_view=AcquireCacheView(tint_image);
5117 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5118 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5120 for (y=0; y < (ssize_t) image->rows; y++)
5122 register const PixelPacket
5128 register PixelPacket
5131 if (status == MagickFalse)
5133 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5134 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5136 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
5141 for (x=0; x < (ssize_t) image->columns; x++)
5149 weight=QuantumScale*p->red-0.5;
5150 pixel.red=(MagickRealType) p->red+color_vector.red*(1.0-(4.0*
5152 SetRedPixelComponent(q,ClampRedPixelComponent(&pixel));
5153 weight=QuantumScale*p->green-0.5;
5154 pixel.green=(MagickRealType) p->green+color_vector.green*(1.0-(4.0*
5156 SetGreenPixelComponent(q,ClampGreenPixelComponent(&pixel));
5157 weight=QuantumScale*p->blue-0.5;
5158 pixel.blue=(MagickRealType) p->blue+color_vector.blue*(1.0-(4.0*
5160 SetBluePixelComponent(q,ClampBluePixelComponent(&pixel));
5161 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
5165 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5167 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5172 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5173 #pragma omp critical (MagickCore_TintImage)
5175 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5176 if (proceed == MagickFalse)
5180 tint_view=DestroyCacheView(tint_view);
5181 image_view=DestroyCacheView(image_view);
5182 if (status == MagickFalse)
5183 tint_image=DestroyImage(tint_image);
5188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5192 % V i g n e t t e I m a g e %
5196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5198 % VignetteImage() softens the edges of the image in vignette style.
5200 % The format of the VignetteImage method is:
5202 % Image *VignetteImage(const Image *image,const double radius,
5203 % const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5205 % A description of each parameter follows:
5207 % o image: the image.
5209 % o radius: the radius of the pixel neighborhood.
5211 % o sigma: the standard deviation of the Gaussian, in pixels.
5213 % o x, y: Define the x and y ellipse offset.
5215 % o exception: return any errors or warnings in this structure.
5218 MagickExport Image *VignetteImage(const Image *image,const double radius,
5219 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
5222 ellipse[MaxTextExtent];
5233 assert(image != (Image *) NULL);
5234 assert(image->signature == MagickSignature);
5235 if (image->debug != MagickFalse)
5236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5237 assert(exception != (ExceptionInfo *) NULL);
5238 assert(exception->signature == MagickSignature);
5239 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5240 if (canvas_image == (Image *) NULL)
5241 return((Image *) NULL);
5242 if (SetImageStorageClass(canvas_image,DirectClass) == MagickFalse)
5244 InheritException(exception,&canvas_image->exception);
5245 canvas_image=DestroyImage(canvas_image);
5246 return((Image *) NULL);
5248 canvas_image->matte=MagickTrue;
5249 oval_image=CloneImage(canvas_image,canvas_image->columns,
5250 canvas_image->rows,MagickTrue,exception);
5251 if (oval_image == (Image *) NULL)
5253 canvas_image=DestroyImage(canvas_image);
5254 return((Image *) NULL);
5256 (void) QueryColorDatabase("#000000",&oval_image->background_color,exception);
5257 (void) SetImageBackgroundColor(oval_image);
5258 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
5259 (void) QueryColorDatabase("#ffffff",&draw_info->fill,exception);
5260 (void) QueryColorDatabase("#ffffff",&draw_info->stroke,exception);
5261 (void) FormatMagickString(ellipse,MaxTextExtent,
5262 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
5263 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
5264 draw_info->primitive=AcquireString(ellipse);
5265 (void) DrawImage(oval_image,draw_info);
5266 draw_info=DestroyDrawInfo(draw_info);
5267 blur_image=BlurImage(oval_image,radius,sigma,exception);
5268 oval_image=DestroyImage(oval_image);
5269 if (blur_image == (Image *) NULL)
5271 canvas_image=DestroyImage(canvas_image);
5272 return((Image *) NULL);
5274 blur_image->matte=MagickFalse;
5275 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0);
5276 blur_image=DestroyImage(blur_image);
5277 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5278 canvas_image=DestroyImage(canvas_image);
5279 return(vignette_image);
5283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5287 % W a v e I m a g e %
5291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5293 % WaveImage() creates a "ripple" effect in the image by shifting the pixels
5294 % vertically along a sine wave whose amplitude and wavelength is specified
5295 % by the given parameters.
5297 % The format of the WaveImage method is:
5299 % Image *WaveImage(const Image *image,const double amplitude,
5300 % const double wave_length,ExceptionInfo *exception)
5302 % A description of each parameter follows:
5304 % o image: the image.
5306 % o amplitude, wave_length: Define the amplitude and wave length of the
5309 % o exception: return any errors or warnings in this structure.
5312 MagickExport Image *WaveImage(const Image *image,const double amplitude,
5313 const double wave_length,ExceptionInfo *exception)
5315 #define WaveImageTag "Wave/Image"
5339 **restrict resample_filter;
5345 Initialize wave image attributes.
5347 assert(image != (Image *) NULL);
5348 assert(image->signature == MagickSignature);
5349 if (image->debug != MagickFalse)
5350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5351 assert(exception != (ExceptionInfo *) NULL);
5352 assert(exception->signature == MagickSignature);
5353 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
5354 fabs(amplitude)),MagickTrue,exception);
5355 if (wave_image == (Image *) NULL)
5356 return((Image *) NULL);
5357 if (SetImageStorageClass(wave_image,DirectClass) == MagickFalse)
5359 InheritException(exception,&wave_image->exception);
5360 wave_image=DestroyImage(wave_image);
5361 return((Image *) NULL);
5363 if (wave_image->background_color.opacity != OpaqueOpacity)
5364 wave_image->matte=MagickTrue;
5368 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5370 if (sine_map == (MagickRealType *) NULL)
5372 wave_image=DestroyImage(wave_image);
5373 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5375 for (i=0; i < (ssize_t) wave_image->columns; i++)
5376 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5383 GetMagickPixelPacket(wave_image,&zero);
5384 resample_filter=AcquireResampleFilterThreadSet(image,
5385 BackgroundVirtualPixelMethod,MagickTrue,exception);
5386 wave_view=AcquireCacheView(wave_image);
5387 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5388 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
5390 for (y=0; y < (ssize_t) wave_image->rows; y++)
5393 id = GetOpenMPThreadId();
5398 register IndexPacket
5404 register PixelPacket
5407 if (status == MagickFalse)
5409 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5411 if (q == (PixelPacket *) NULL)
5416 indexes=GetCacheViewAuthenticIndexQueue(wave_view);
5418 for (x=0; x < (ssize_t) wave_image->columns; x++)
5420 (void) ResamplePixelColor(resample_filter[id],(double) x,(double) (y-
5421 sine_map[x]),&pixel);
5422 SetPixelPacket(wave_image,&pixel,q,indexes+x);
5425 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5427 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5432 #if defined(MAGICKCORE_OPENMP_SUPPORT)
5433 #pragma omp critical (MagickCore_WaveImage)
5435 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5436 if (proceed == MagickFalse)
5440 wave_view=DestroyCacheView(wave_view);
5441 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
5442 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5443 if (status == MagickFalse)
5444 wave_image=DestroyImage(wave_image);