50#include "MagickCore/studio.h"
51#include "MagickCore/accelerate-private.h"
52#include "MagickCore/annotate.h"
53#include "MagickCore/artifact.h"
54#include "MagickCore/attribute.h"
55#include "MagickCore/cache.h"
56#include "MagickCore/cache-private.h"
57#include "MagickCore/cache-view.h"
58#include "MagickCore/channel.h"
59#include "MagickCore/color.h"
60#include "MagickCore/color-private.h"
61#include "MagickCore/colorspace-private.h"
62#include "MagickCore/composite.h"
63#include "MagickCore/decorate.h"
64#include "MagickCore/distort.h"
65#include "MagickCore/draw.h"
66#include "MagickCore/effect.h"
67#include "MagickCore/enhance.h"
68#include "MagickCore/exception.h"
69#include "MagickCore/exception-private.h"
70#include "MagickCore/gem.h"
71#include "MagickCore/gem-private.h"
72#include "MagickCore/geometry.h"
73#include "MagickCore/layer.h"
74#include "MagickCore/list.h"
75#include "MagickCore/log.h"
76#include "MagickCore/image.h"
77#include "MagickCore/image-private.h"
78#include "MagickCore/magick.h"
79#include "MagickCore/memory_.h"
80#include "MagickCore/memory-private.h"
81#include "MagickCore/monitor.h"
82#include "MagickCore/monitor-private.h"
83#include "MagickCore/option.h"
84#include "MagickCore/pixel.h"
85#include "MagickCore/pixel-accessor.h"
86#include "MagickCore/property.h"
87#include "MagickCore/quantum.h"
88#include "MagickCore/quantum-private.h"
89#include "MagickCore/random_.h"
90#include "MagickCore/random-private.h"
91#include "MagickCore/resample.h"
92#include "MagickCore/resample-private.h"
93#include "MagickCore/resize.h"
94#include "MagickCore/resource_.h"
95#include "MagickCore/splay-tree.h"
96#include "MagickCore/statistic.h"
97#include "MagickCore/string_.h"
98#include "MagickCore/string-private.h"
99#include "MagickCore/thread-private.h"
100#include "MagickCore/threshold.h"
101#include "MagickCore/transform.h"
102#include "MagickCore/transform-private.h"
103#include "MagickCore/utility.h"
104#include "MagickCore/visual-effects.h"
138MagickExport
Image *AddNoiseImage(
const Image *image,
const NoiseType noise_type,
141#define AddNoiseImageTag "AddNoise/Image"
157 **magick_restrict random_info;
162#if defined(MAGICKCORE_OPENMP_SUPPORT)
170 assert(image != (
const Image *) NULL);
171 assert(image->signature == MagickCoreSignature);
173 assert(exception->signature == MagickCoreSignature);
174 if (IsEventLogging() != MagickFalse)
175 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
176 noise_image=CloneImage(image,0,0,MagickTrue,exception);
177 if (noise_image == (
Image *) NULL)
178 return((
Image *) NULL);
179 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
181 noise_image=DestroyImage(noise_image);
182 return((
Image *) NULL);
189 random_info=AcquireRandomInfoTLS();
190 image_view=AcquireVirtualCacheView(image,exception);
191 noise_view=AcquireAuthenticCacheView(noise_image,exception);
192#if defined(MAGICKCORE_OPENMP_SUPPORT)
193 key=GetRandomSecretKey(random_info[0]);
194 #pragma omp parallel for schedule(static) shared(progress,status) \
195 magick_number_threads(image,noise_image,image->rows,key == ~0UL ? 0 : 2)
197 for (y=0; y < (ssize_t) image->rows; y++)
200 id = GetOpenMPThreadId();
214 if (status == MagickFalse)
216 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
217 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
219 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
224 for (x=0; x < (ssize_t) image->columns; x++)
229 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
231 PixelChannel channel = GetPixelChannelChannel(image,i);
232 PixelTrait traits = GetPixelChannelTraits(image,channel);
233 PixelTrait noise_traits=GetPixelChannelTraits(noise_image,channel);
234 if ((traits == UndefinedPixelTrait) ||
235 (noise_traits == UndefinedPixelTrait))
237 if ((noise_traits & CopyPixelTrait) != 0)
239 SetPixelChannel(noise_image,channel,p[i],q);
242 SetPixelChannel(noise_image,channel,ClampToQuantum(
243 GenerateDifferentialNoise(random_info[
id],p[i],noise_type,attenuate)),
246 p+=(ptrdiff_t) GetPixelChannels(image);
247 q+=(ptrdiff_t) GetPixelChannels(noise_image);
249 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
250 if (sync == MagickFalse)
252 if (image->progress_monitor != (MagickProgressMonitor) NULL)
257#if defined(MAGICKCORE_OPENMP_SUPPORT)
261 proceed=SetImageProgress(image,AddNoiseImageTag,progress,image->rows);
262 if (proceed == MagickFalse)
266 noise_view=DestroyCacheView(noise_view);
267 image_view=DestroyCacheView(image_view);
268 random_info=DestroyRandomInfoTLS(random_info);
269 if (status == MagickFalse)
270 noise_image=DestroyImage(noise_image);
302MagickExport
Image *BlueShiftImage(
const Image *image,
const double factor,
305#define BlueShiftImageTag "BlueShift/Image"
326 assert(image != (
const Image *) NULL);
327 assert(image->signature == MagickCoreSignature);
329 assert(exception->signature == MagickCoreSignature);
330 if (IsEventLogging() != MagickFalse)
331 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
332 shift_image=CloneImage(image,0,0,MagickTrue,exception);
333 if (shift_image == (
Image *) NULL)
334 return((
Image *) NULL);
335 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
337 shift_image=DestroyImage(shift_image);
338 return((
Image *) NULL);
345 image_view=AcquireVirtualCacheView(image,exception);
346 shift_view=AcquireAuthenticCacheView(shift_image,exception);
347#if defined(MAGICKCORE_OPENMP_SUPPORT)
348 #pragma omp parallel for schedule(static) shared(progress,status) \
349 magick_number_threads(image,shift_image,image->rows,1)
351 for (y=0; y < (ssize_t) image->rows; y++)
371 if (status == MagickFalse)
373 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
374 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
376 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
381 for (x=0; x < (ssize_t) image->columns; x++)
383 quantum=GetPixelRed(image,p);
384 if (GetPixelGreen(image,p) < quantum)
385 quantum=GetPixelGreen(image,p);
386 if (GetPixelBlue(image,p) < quantum)
387 quantum=GetPixelBlue(image,p);
388 pixel.red=0.5*((double) GetPixelRed(image,p)+factor*(double) quantum);
389 pixel.green=0.5*((double) GetPixelGreen(image,p)+factor*(double) quantum);
390 pixel.blue=0.5*((double) GetPixelBlue(image,p)+factor*(double) quantum);
391 quantum=GetPixelRed(image,p);
392 if (GetPixelGreen(image,p) > quantum)
393 quantum=GetPixelGreen(image,p);
394 if (GetPixelBlue(image,p) > quantum)
395 quantum=GetPixelBlue(image,p);
396 pixel.red=0.5*(pixel.red+factor*(double) quantum);
397 pixel.green=0.5*(pixel.green+factor*(double) quantum);
398 pixel.blue=0.5*(pixel.blue+factor*(double) quantum);
399 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
400 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
401 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
402 p+=(ptrdiff_t) GetPixelChannels(image);
403 q+=(ptrdiff_t) GetPixelChannels(shift_image);
405 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
406 if (sync == MagickFalse)
408 if (image->progress_monitor != (MagickProgressMonitor) NULL)
413#if defined(MAGICKCORE_OPENMP_SUPPORT)
417 proceed=SetImageProgress(image,BlueShiftImageTag,progress,image->rows);
418 if (proceed == MagickFalse)
422 image_view=DestroyCacheView(image_view);
423 shift_view=DestroyCacheView(shift_view);
424 if (status == MagickFalse)
425 shift_image=DestroyImage(shift_image);
460MagickExport
Image *CharcoalImage(
const Image *image,
const double radius,
470 assert(image != (
Image *) NULL);
471 assert(image->signature == MagickCoreSignature);
473 assert(exception->signature == MagickCoreSignature);
474 if (IsEventLogging() != MagickFalse)
475 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
476 edge_image=EdgeImage(image,radius,exception);
477 if (edge_image == (
Image *) NULL)
478 return((
Image *) NULL);
479 edge_image->alpha_trait=UndefinedPixelTrait;
480 charcoal_image=(
Image *) NULL;
481 status=ClampImage(edge_image,exception);
482 if (status != MagickFalse)
483 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
484 edge_image=DestroyImage(edge_image);
485 if (charcoal_image == (
Image *) NULL)
486 return((
Image *) NULL);
487 status=NormalizeImage(charcoal_image,exception);
488 if (status != MagickFalse)
489 status=NegateImage(charcoal_image,MagickFalse,exception);
490 if (status != MagickFalse)
491 status=GrayscaleImage(charcoal_image,image->intensity,exception);
492 if (status == MagickFalse)
493 charcoal_image=DestroyImage(charcoal_image);
494 return(charcoal_image);
530MagickExport
Image *ColorizeImage(
const Image *image,
const char *blend,
533#define ColorizeImageTag "Colorize/Image"
534#define Colorize(pixel,blend_percentage,colorize) \
535 ((((double) pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0)
564 assert(image != (
const Image *) NULL);
565 assert(image->signature == MagickCoreSignature);
567 assert(exception->signature == MagickCoreSignature);
568 if (IsEventLogging() != MagickFalse)
569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
570 colorize_image=CloneImage(image,0,0,MagickTrue,exception);
571 if (colorize_image == (
Image *) NULL)
572 return((
Image *) NULL);
573 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
575 colorize_image=DestroyImage(colorize_image);
576 return((
Image *) NULL);
578 if ((IsGrayColorspace(colorize_image->colorspace) != MagickFalse) ||
579 (IsPixelInfoGray(colorize) != MagickFalse))
580 (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
581 if ((colorize_image->alpha_trait == UndefinedPixelTrait) &&
582 (colorize->alpha_trait != UndefinedPixelTrait))
583 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
584 if (blend == (
const char *) NULL)
585 return(colorize_image);
586 GetPixelInfo(colorize_image,&blend_percentage);
587 flags=ParseGeometry(blend,&geometry_info);
588 blend_percentage.red=geometry_info.rho;
589 blend_percentage.green=geometry_info.rho;
590 blend_percentage.blue=geometry_info.rho;
591 blend_percentage.black=geometry_info.rho;
592 blend_percentage.alpha=(MagickRealType) TransparentAlpha;
593 if ((flags & SigmaValue) != 0)
594 blend_percentage.green=geometry_info.sigma;
595 if ((flags & XiValue) != 0)
596 blend_percentage.blue=geometry_info.xi;
597 if ((flags & PsiValue) != 0)
598 blend_percentage.alpha=geometry_info.psi;
599 if (blend_percentage.colorspace == CMYKColorspace)
601 if ((flags & PsiValue) != 0)
602 blend_percentage.black=geometry_info.psi;
603 if ((flags & ChiValue) != 0)
604 blend_percentage.alpha=geometry_info.chi;
611 image_view=AcquireAuthenticCacheView(colorize_image,exception);
612#if defined(MAGICKCORE_OPENMP_SUPPORT)
613 #pragma omp parallel for schedule(static) shared(progress,status) \
614 magick_number_threads(colorize_image,colorize_image,colorize_image->rows,2)
616 for (y=0; y < (ssize_t) colorize_image->rows; y++)
627 if (status == MagickFalse)
629 q=GetCacheViewAuthenticPixels(image_view,0,y,colorize_image->columns,1,
631 if (q == (Quantum *) NULL)
636 for (x=0; x < (ssize_t) colorize_image->columns; x++)
641 for (i=0; i < (ssize_t) GetPixelChannels(colorize_image); i++)
643 PixelTrait traits = GetPixelChannelTraits(colorize_image,
645 if (traits == UndefinedPixelTrait)
647 if ((traits & CopyPixelTrait) != 0)
649 SetPixelChannel(colorize_image,(PixelChannel) i,ClampToQuantum(
650 Colorize(q[i],GetPixelInfoChannel(&blend_percentage,(PixelChannel) i),
651 GetPixelInfoChannel(colorize,(PixelChannel) i))),q);
653 q+=(ptrdiff_t) GetPixelChannels(colorize_image);
655 sync=SyncCacheViewAuthenticPixels(image_view,exception);
656 if (sync == MagickFalse)
658 if (image->progress_monitor != (MagickProgressMonitor) NULL)
663#if defined(MAGICKCORE_OPENMP_SUPPORT)
667 proceed=SetImageProgress(image,ColorizeImageTag,progress,
668 colorize_image->rows);
669 if (proceed == MagickFalse)
673 image_view=DestroyCacheView(image_view);
674 if (status == MagickFalse)
675 colorize_image=DestroyImage(colorize_image);
676 return(colorize_image);
717MagickExport
Image *ColorMatrixImage(
const Image *image,
720#define ColorMatrixImageTag "ColorMatrix/Image"
729 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
730 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
731 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
732 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
733 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
734 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
757 assert(image != (
Image *) NULL);
758 assert(image->signature == MagickCoreSignature);
760 assert(exception->signature == MagickCoreSignature);
761 if (IsEventLogging() != MagickFalse)
762 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
764 for (v=0; v < (ssize_t) color_matrix->height; v++)
765 for (u=0; u < (ssize_t) color_matrix->width; u++)
767 if ((v < 6) && (u < 6))
768 ColorMatrix[v][u]=color_matrix->values[i];
774 color_image=CloneImage(image,0,0,MagickTrue,exception);
775 if (color_image == (
Image *) NULL)
776 return((
Image *) NULL);
777 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
779 color_image=DestroyImage(color_image);
780 return((
Image *) NULL);
782 if (image->debug != MagickFalse)
785 format[MagickPathExtent],
788 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
789 " ColorMatrix image with color matrix:");
790 message=AcquireString(
"");
791 for (v=0; v < 6; v++)
794 (void) FormatLocaleString(format,MagickPathExtent,
"%.20g: ",(
double) v);
795 (void) ConcatenateString(&message,format);
796 for (u=0; u < 6; u++)
798 (void) FormatLocaleString(format,MagickPathExtent,
"%+f ",
800 (void) ConcatenateString(&message,format);
802 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
"%s",message);
804 message=DestroyString(message);
811 image_view=AcquireVirtualCacheView(image,exception);
812 color_view=AcquireAuthenticCacheView(color_image,exception);
813#if defined(MAGICKCORE_OPENMP_SUPPORT)
814 #pragma omp parallel for schedule(static) shared(progress,status) \
815 magick_number_threads(image,color_image,image->rows,1)
817 for (y=0; y < (ssize_t) image->rows; y++)
831 if (status == MagickFalse)
833 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
834 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
836 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
841 GetPixelInfo(image,&pixel);
842 for (x=0; x < (ssize_t) image->columns; x++)
850 GetPixelInfoPixel(image,p,&pixel);
851 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
852 for (h=0; h < (ssize_t) height; h++)
857 sum=ColorMatrix[h][0]*(double) GetPixelRed(image,p)+ColorMatrix[h][1]*
858 (double) GetPixelGreen(image,p)+ColorMatrix[h][2]*(double)
859 GetPixelBlue(image,p);
860 if (image->colorspace == CMYKColorspace)
861 sum+=ColorMatrix[h][3]*(double) GetPixelBlack(image,p);
862 if (image->alpha_trait != UndefinedPixelTrait)
863 sum+=ColorMatrix[h][4]*(double) GetPixelAlpha(image,p);
864 sum+=(double) QuantumRange*ColorMatrix[h][5];
867 case 0: pixel.red=sum;
break;
868 case 1: pixel.green=sum;
break;
869 case 2: pixel.blue=sum;
break;
870 case 3: pixel.black=sum;
break;
871 case 4: pixel.alpha=sum;
break;
875 SetPixelViaPixelInfo(color_image,&pixel,q);
876 p+=(ptrdiff_t) GetPixelChannels(image);
877 q+=(ptrdiff_t) GetPixelChannels(color_image);
879 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
881 if (image->progress_monitor != (MagickProgressMonitor) NULL)
886#if defined(MAGICKCORE_OPENMP_SUPPORT)
890 proceed=SetImageProgress(image,ColorMatrixImageTag,progress,
892 if (proceed == MagickFalse)
896 color_view=DestroyCacheView(color_view);
897 image_view=DestroyCacheView(image_view);
898 if (status == MagickFalse)
899 color_image=DestroyImage(color_image);
939MagickExport
Image *ImplodeImage(
const Image *image,
const double amount,
940 const PixelInterpolateMethod method,
ExceptionInfo *exception)
942#define ImplodeImageTag "Implode/Image"
972 assert(image != (
Image *) NULL);
973 assert(image->signature == MagickCoreSignature);
975 assert(exception->signature == MagickCoreSignature);
976 if (IsEventLogging() != MagickFalse)
977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
978 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
979 if (canvas_image == (
Image *) NULL)
980 return((
Image *) NULL);
981 if ((canvas_image->alpha_trait == UndefinedPixelTrait) &&
982 (canvas_image->background_color.alpha != (
double) OpaqueAlpha))
983 (void) SetImageAlphaChannel(canvas_image,OpaqueAlphaChannel,exception);
984 implode_image=CloneImage(canvas_image,0,0,MagickTrue,exception);
985 if (implode_image == (
Image *) NULL)
987 canvas_image=DestroyImage(canvas_image);
988 return((
Image *) NULL);
990 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
992 canvas_image=DestroyImage(canvas_image);
993 implode_image=DestroyImage(implode_image);
994 return((
Image *) NULL);
1001 center.x=0.5*canvas_image->columns;
1002 center.y=0.5*canvas_image->rows;
1004 if (canvas_image->columns > canvas_image->rows)
1005 scale.y=(double) canvas_image->columns*PerceptibleReciprocal((
double)
1006 canvas_image->rows);
1008 if (canvas_image->columns < canvas_image->rows)
1010 scale.x=(double) canvas_image->rows*PerceptibleReciprocal((
double)
1011 canvas_image->columns);
1019 canvas_view=AcquireVirtualCacheView(canvas_image,exception);
1020 interpolate_view=AcquireVirtualCacheView(canvas_image,exception);
1021 implode_view=AcquireAuthenticCacheView(implode_image,exception);
1022#if defined(MAGICKCORE_OPENMP_SUPPORT)
1023 #pragma omp parallel for schedule(static) shared(progress,status) \
1024 magick_number_threads(canvas_image,implode_image,canvas_image->rows,1)
1026 for (y=0; y < (ssize_t) canvas_image->rows; y++)
1043 if (status == MagickFalse)
1045 p=GetCacheViewVirtualPixels(canvas_view,0,y,canvas_image->columns,1,
1047 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
1049 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1054 delta.y=scale.y*((double) y-center.y);
1055 for (x=0; x < (ssize_t) canvas_image->columns; x++)
1063 delta.x=scale.x*((double) x-center.x);
1064 distance=delta.x*delta.x+delta.y*delta.y;
1065 if (distance >= (radius*radius))
1066 for (i=0; i < (ssize_t) GetPixelChannels(canvas_image); i++)
1068 PixelChannel channel = GetPixelChannelChannel(canvas_image,i);
1069 PixelTrait traits = GetPixelChannelTraits(canvas_image,channel);
1070 PixelTrait implode_traits = GetPixelChannelTraits(implode_image,
1072 if ((traits == UndefinedPixelTrait) ||
1073 (implode_traits == UndefinedPixelTrait))
1075 SetPixelChannel(implode_image,channel,p[i],q);
1090 factor=pow(sin(MagickPI*sqrt(distance)*
1091 PerceptibleReciprocal(radius)/2.0),-amount);
1092 offset.x=factor*delta.x*PerceptibleReciprocal(scale.x)+center.x;
1093 offset.y=factor*delta.y*PerceptibleReciprocal(scale.y)+center.y;
1094 if ((IsValidPixelOffset(offset.x,image->columns) != MagickFalse) &&
1095 (IsValidPixelOffset(offset.y,image->rows) != MagickFalse))
1096 status=InterpolatePixelChannels(canvas_image,interpolate_view,
1097 implode_image,method,offset.x,offset.y,q,exception);
1098 if (status == MagickFalse)
1101 p+=(ptrdiff_t) GetPixelChannels(canvas_image);
1102 q+=(ptrdiff_t) GetPixelChannels(implode_image);
1104 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
1106 if (canvas_image->progress_monitor != (MagickProgressMonitor) NULL)
1111#if defined(MAGICKCORE_OPENMP_SUPPORT)
1115 proceed=SetImageProgress(canvas_image,ImplodeImageTag,progress,
1116 canvas_image->rows);
1117 if (proceed == MagickFalse)
1121 implode_view=DestroyCacheView(implode_view);
1122 interpolate_view=DestroyCacheView(interpolate_view);
1123 canvas_view=DestroyCacheView(canvas_view);
1124 canvas_image=DestroyImage(canvas_image);
1125 if (status == MagickFalse)
1126 implode_image=DestroyImage(implode_image);
1127 return(implode_image);
1160MagickExport
Image *MorphImages(
const Image *image,
const size_t number_frames,
1163#define MorphImageTag "Morph/Image"
1191 assert(image != (
Image *) NULL);
1192 assert(image->signature == MagickCoreSignature);
1194 assert(exception->signature == MagickCoreSignature);
1195 if (IsEventLogging() != MagickFalse)
1196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1197 morph_images=CloneImage(image,0,0,MagickTrue,exception);
1198 if (morph_images == (
Image *) NULL)
1199 return((
Image *) NULL);
1200 if (GetNextImageInList(image) == (
Image *) NULL)
1205 for (n=1; n < (ssize_t) number_frames; n++)
1207 morph_image=CloneImage(image,0,0,MagickTrue,exception);
1208 if (morph_image == (
Image *) NULL)
1210 morph_images=DestroyImageList(morph_images);
1211 return((
Image *) NULL);
1213 AppendImageToList(&morph_images,morph_image);
1214 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1219 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) n,
1221 if (proceed == MagickFalse)
1225 return(GetFirstImageInList(morph_images));
1233 for ( ; GetNextImageInList(next) != (
Image *) NULL; next=GetNextImageInList(next))
1235 for (n=0; n < (ssize_t) number_frames; n++)
1241 beta=(double) (n+1.0)/(double) (number_frames+1.0);
1243 morph_image=ResizeImage(next,(
size_t) (alpha*next->columns+beta*
1244 GetNextImageInList(next)->columns+0.5),(
size_t) (alpha*next->rows+beta*
1245 GetNextImageInList(next)->rows+0.5),next->filter,exception);
1246 if (morph_image == (
Image *) NULL)
1248 morph_images=DestroyImageList(morph_images);
1249 return((
Image *) NULL);
1251 status=SetImageStorageClass(morph_image,DirectClass,exception);
1252 if (status == MagickFalse)
1254 morph_image=DestroyImage(morph_image);
1255 return((
Image *) NULL);
1257 AppendImageToList(&morph_images,morph_image);
1258 morph_images=GetLastImageInList(morph_images);
1259 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
1260 morph_images->rows,GetNextImageInList(next)->filter,exception);
1261 if (morph_image == (
Image *) NULL)
1263 morph_images=DestroyImageList(morph_images);
1264 return((
Image *) NULL);
1266 image_view=AcquireVirtualCacheView(morph_image,exception);
1267 morph_view=AcquireAuthenticCacheView(morph_images,exception);
1268#if defined(MAGICKCORE_OPENMP_SUPPORT)
1269 #pragma omp parallel for schedule(static) shared(status) \
1270 magick_number_threads(morph_image,morph_image,morph_image->rows,2)
1272 for (y=0; y < (ssize_t) morph_images->rows; y++)
1286 if (status == MagickFalse)
1288 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
1290 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
1292 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1297 for (x=0; x < (ssize_t) morph_images->columns; x++)
1302 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
1304 PixelChannel channel = GetPixelChannelChannel(morph_image,i);
1305 PixelTrait traits = GetPixelChannelTraits(morph_image,channel);
1306 PixelTrait morph_traits=GetPixelChannelTraits(morph_images,channel);
1307 if ((traits == UndefinedPixelTrait) ||
1308 (morph_traits == UndefinedPixelTrait))
1310 if ((morph_traits & CopyPixelTrait) != 0)
1312 SetPixelChannel(morph_image,channel,p[i],q);
1315 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*(
double)
1316 GetPixelChannel(morph_images,channel,q)+beta*(
double) p[i]),q);
1318 p+=(ptrdiff_t) GetPixelChannels(morph_image);
1319 q+=(ptrdiff_t) GetPixelChannels(morph_images);
1321 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
1322 if (sync == MagickFalse)
1325 morph_view=DestroyCacheView(morph_view);
1326 image_view=DestroyCacheView(image_view);
1327 morph_image=DestroyImage(morph_image);
1329 if (n < (ssize_t) number_frames)
1334 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
1335 if (morph_image == (
Image *) NULL)
1337 morph_images=DestroyImageList(morph_images);
1338 return((
Image *) NULL);
1340 AppendImageToList(&morph_images,morph_image);
1341 morph_images=GetLastImageInList(morph_images);
1342 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1347 proceed=SetImageProgress(image,MorphImageTag,scene,
1348 GetImageListLength(image));
1349 if (proceed == MagickFalse)
1354 if (GetNextImageInList(next) != (
Image *) NULL)
1356 morph_images=DestroyImageList(morph_images);
1357 return((
Image *) NULL);
1359 return(GetFirstImageInList(morph_images));
1396static inline Quantum PlasmaPixel(
RandomInfo *magick_restrict random_info,
1397 const double pixel,
const double noise)
1402 plasma=pixel+noise*GetPseudoRandomValue(random_info)-noise/2.0;
1403 return(ClampToQuantum(plasma));
1406static MagickBooleanType PlasmaImageProxy(
Image *image,
CacheView *image_view,
1408 const SegmentInfo *magick_restrict segment,
size_t attenuate,
size_t depth,
1433 if ((fabs(segment->x2-segment->x1) < MagickEpsilon) &&
1434 (fabs(segment->y2-segment->y1) < MagickEpsilon))
1446 x_mid=CastDoubleToLong(ceil((segment->x1+segment->x2)/2-0.5));
1447 y_mid=CastDoubleToLong(ceil((segment->y1+segment->y2)/2-0.5));
1448 local_info=(*segment);
1449 local_info.x2=(double) x_mid;
1450 local_info.y2=(double) y_mid;
1451 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
1452 &local_info,attenuate,depth,exception);
1453 local_info=(*segment);
1454 local_info.y1=(double) y_mid;
1455 local_info.x2=(double) x_mid;
1456 status&=(MagickStatusType) PlasmaImageProxy(image,image_view,u_view,
1457 v_view,random_info,&local_info,attenuate,depth,exception);
1458 local_info=(*segment);
1459 local_info.x1=(double) x_mid;
1460 local_info.y2=(double) y_mid;
1461 status&=(MagickStatusType) PlasmaImageProxy(image,image_view,u_view,
1462 v_view,random_info,&local_info,attenuate,depth,exception);
1463 local_info=(*segment);
1464 local_info.x1=(double) x_mid;
1465 local_info.y1=(double) y_mid;
1466 status&=(MagickStatusType) PlasmaImageProxy(image,image_view,u_view,
1467 v_view,random_info,&local_info,attenuate,depth,exception);
1468 return(status == 0 ? MagickFalse : MagickTrue);
1470 x_mid=CastDoubleToLong(ceil((segment->x1+segment->x2)/2-0.5));
1471 y_mid=CastDoubleToLong(ceil((segment->y1+segment->y2)/2-0.5));
1472 if ((fabs(segment->x1-x_mid) < MagickEpsilon) &&
1473 (fabs(segment->x2-x_mid) < MagickEpsilon) &&
1474 (fabs(segment->y1-y_mid) < MagickEpsilon) &&
1475 (fabs(segment->y2-y_mid) < MagickEpsilon))
1476 return(MagickFalse);
1481 plasma=(double) QuantumRange/(2.0*attenuate);
1482 if ((fabs(segment->x1-x_mid) >= MagickEpsilon) ||
1483 (fabs(segment->x2-x_mid) >= MagickEpsilon))
1488 x=CastDoubleToLong(ceil(segment->x1-0.5));
1489 u=GetCacheViewVirtualPixels(u_view,x,CastDoubleToLong(ceil(
1490 segment->y1-0.5)),1,1,exception);
1491 v=GetCacheViewVirtualPixels(v_view,x,CastDoubleToLong(ceil(
1492 segment->y2-0.5)),1,1,exception);
1493 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
1494 if ((u == (
const Quantum *) NULL) || (v == (
const Quantum *) NULL) ||
1495 (q == (Quantum *) NULL))
1497 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1499 PixelChannel channel = GetPixelChannelChannel(image,i);
1500 PixelTrait traits = GetPixelChannelTraits(image,channel);
1501 if (traits == UndefinedPixelTrait)
1503 q[i]=PlasmaPixel(random_info,((
double) u[i]+(
double) v[i])/2.0,plasma);
1505 status=SyncCacheViewAuthenticPixels(image_view,exception);
1506 if (fabs(segment->x1-segment->x2) >= MagickEpsilon)
1511 x=CastDoubleToLong(ceil(segment->x2-0.5));
1512 u=GetCacheViewVirtualPixels(u_view,x,CastDoubleToLong(ceil(
1513 segment->y1-0.5)),1,1,exception);
1514 v=GetCacheViewVirtualPixels(v_view,x,CastDoubleToLong(ceil(
1515 segment->y2-0.5)),1,1,exception);
1516 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
1517 if ((u == (
const Quantum *) NULL) || (v == (
const Quantum *) NULL) ||
1518 (q == (Quantum *) NULL))
1519 return(MagickFalse);
1520 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1522 PixelChannel channel = GetPixelChannelChannel(image,i);
1523 PixelTrait traits = GetPixelChannelTraits(image,channel);
1524 if (traits == UndefinedPixelTrait)
1526 q[i]=PlasmaPixel(random_info,((
double) u[i]+(
double) v[i])/2.0,
1529 status=SyncCacheViewAuthenticPixels(image_view,exception);
1532 if ((fabs(segment->y1-y_mid) >= MagickEpsilon) ||
1533 (fabs(segment->y2-y_mid) >= MagickEpsilon))
1535 if ((fabs(segment->x1-x_mid) >= MagickEpsilon) ||
1536 (fabs(segment->y2-y_mid) >= MagickEpsilon))
1541 y=CastDoubleToLong(ceil(segment->y2-0.5));
1542 u=GetCacheViewVirtualPixels(u_view,CastDoubleToLong(ceil(
1543 segment->x1-0.5)),y,1,1,exception);
1544 v=GetCacheViewVirtualPixels(v_view,CastDoubleToLong(ceil(
1545 segment->x2-0.5)),y,1,1,exception);
1546 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
1547 if ((u == (
const Quantum *) NULL) || (v == (
const Quantum *) NULL) ||
1548 (q == (Quantum *) NULL))
1550 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1552 PixelChannel channel = GetPixelChannelChannel(image,i);
1553 PixelTrait traits = GetPixelChannelTraits(image,channel);
1554 if (traits == UndefinedPixelTrait)
1556 q[i]=PlasmaPixel(random_info,((
double) u[i]+(
double) v[i])/2.0,
1559 status=SyncCacheViewAuthenticPixels(image_view,exception);
1561 if (fabs(segment->y1-segment->y2) >= MagickEpsilon)
1566 y=CastDoubleToLong(ceil(segment->y1-0.5));
1567 u=GetCacheViewVirtualPixels(u_view,CastDoubleToLong(ceil(
1568 segment->x1-0.5)),y,1,1,exception);
1569 v=GetCacheViewVirtualPixels(v_view,CastDoubleToLong(ceil(
1570 segment->x2-0.5)),y,1,1,exception);
1571 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
1572 if ((u == (
const Quantum *) NULL) || (v == (
const Quantum *) NULL) ||
1573 (q == (Quantum *) NULL))
1575 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1577 PixelChannel channel = GetPixelChannelChannel(image,i);
1578 PixelTrait traits = GetPixelChannelTraits(image,channel);
1579 if (traits == UndefinedPixelTrait)
1581 q[i]=PlasmaPixel(random_info,((
double) u[i]+(
double) v[i])/2.0,
1584 status=SyncCacheViewAuthenticPixels(image_view,exception);
1587 if ((fabs(segment->x1-segment->x2) >= MagickEpsilon) ||
1588 (fabs(segment->y1-segment->y2) >= MagickEpsilon))
1593 x=CastDoubleToLong(ceil(segment->x1-0.5));
1594 y=CastDoubleToLong(ceil(segment->y1-0.5));
1595 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
1596 x=CastDoubleToLong(ceil(segment->x2-0.5));
1597 y=CastDoubleToLong(ceil(segment->y2-0.5));
1598 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
1599 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
1600 if ((u == (
const Quantum *) NULL) || (v == (
const Quantum *) NULL) ||
1601 (q == (Quantum *) NULL))
1603 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1605 PixelChannel channel = GetPixelChannelChannel(image,i);
1606 PixelTrait traits = GetPixelChannelTraits(image,channel);
1607 if (traits == UndefinedPixelTrait)
1609 q[i]=PlasmaPixel(random_info,((
double) u[i]+(
double) v[i])/2.0,plasma);
1611 status=SyncCacheViewAuthenticPixels(image_view,exception);
1613 if ((fabs(segment->x2-segment->x1) < 3.0) &&
1614 (fabs(segment->y2-segment->y1) < 3.0))
1615 return(status == 0 ? MagickFalse : MagickTrue);
1616 return(MagickFalse);
1619MagickExport MagickBooleanType PlasmaImage(
Image *image,
1620 const SegmentInfo *segment,
size_t attenuate,
size_t depth,
1634 assert(image != (
Image *) NULL);
1635 assert(image->signature == MagickCoreSignature);
1636 if (IsEventLogging() != MagickFalse)
1637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1638 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1639 return(MagickFalse);
1640 image_view=AcquireAuthenticCacheView(image,exception);
1641 u_view=AcquireVirtualCacheView(image,exception);
1642 v_view=AcquireVirtualCacheView(image,exception);
1643 random_info=AcquireRandomInfo();
1644 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
1645 attenuate,depth,exception);
1646 random_info=DestroyRandomInfo(random_info);
1647 v_view=DestroyCacheView(v_view);
1648 u_view=DestroyCacheView(u_view);
1649 image_view=DestroyCacheView(image_view);
1688 const char *caption,
const double angle,
const PixelInterpolateMethod method,
1709 assert(image != (
Image *) NULL);
1710 assert(image->signature == MagickCoreSignature);
1712 assert(exception->signature == MagickCoreSignature);
1713 if (IsEventLogging() != MagickFalse)
1714 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1715 quantum=(ssize_t) MagickMax(MagickMax((
double) image->columns,(
double)
1716 image->rows)/25.0,10.0);
1717 height=(size_t) ((ssize_t) image->rows+2*quantum);
1718 caption_image=(
Image *) NULL;
1719 if (caption != (
const char *) NULL)
1727 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
1728 if (caption_image == (
Image *) NULL)
1729 return((
Image *) NULL);
1730 text=InterpretImageProperties((
ImageInfo *) NULL,(
Image *) image,caption,
1732 if (text != (
char *) NULL)
1735 geometry[MagickPathExtent];
1749 annotate_info=CloneDrawInfo((
const ImageInfo *) NULL,draw_info);
1750 (void) CloneString(&annotate_info->text,text);
1751 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,
1752 &metrics,&text,exception);
1753 status=SetImageExtent(caption_image,image->columns,(
size_t)
1754 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
1755 if (status == MagickFalse)
1756 caption_image=DestroyImage(caption_image);
1759 caption_image->background_color=image->border_color;
1760 (void) SetImageBackgroundColor(caption_image,exception);
1761 (void) CloneString(&annotate_info->text,text);
1762 (void) FormatLocaleString(geometry,MagickPathExtent,
"+0+%.20g",
1764 if (annotate_info->gravity == UndefinedGravity)
1765 (void) CloneString(&annotate_info->geometry,AcquireString(
1767 (void) AnnotateImage(caption_image,annotate_info,exception);
1768 height+=caption_image->rows;
1770 annotate_info=DestroyDrawInfo(annotate_info);
1771 text=DestroyString(text);
1774 picture_image=CloneImage(image,(
size_t) ((ssize_t) image->columns+2*quantum),
1775 height,MagickTrue,exception);
1776 if (picture_image == (
Image *) NULL)
1778 if (caption_image != (
Image *) NULL)
1779 caption_image=DestroyImage(caption_image);
1780 return((
Image *) NULL);
1782 picture_image->background_color=image->border_color;
1783 (void) SetImageBackgroundColor(picture_image,exception);
1784 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum,
1786 if (caption_image != (
Image *) NULL)
1788 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
1789 MagickTrue,quantum,((ssize_t) image->rows+3*quantum/2),exception);
1790 caption_image=DestroyImage(caption_image);
1792 (void) QueryColorCompliance(
"none",AllCompliance,
1793 &picture_image->background_color,exception);
1794 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
1795 rotate_image=RotateImage(picture_image,90.0,exception);
1796 picture_image=DestroyImage(picture_image);
1797 if (rotate_image == (
Image *) NULL)
1798 return((
Image *) NULL);
1799 picture_image=rotate_image;
1800 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
1801 picture_image->columns,method,exception);
1802 picture_image=DestroyImage(picture_image);
1803 if (bend_image == (
Image *) NULL)
1804 return((
Image *) NULL);
1805 picture_image=bend_image;
1806 rotate_image=RotateImage(picture_image,-90.0,exception);
1807 picture_image=DestroyImage(picture_image);
1808 if (rotate_image == (
Image *) NULL)
1809 return((
Image *) NULL);
1810 picture_image=rotate_image;
1811 picture_image->background_color=image->background_color;
1812 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
1814 if (polaroid_image == (
Image *) NULL)
1816 picture_image=DestroyImage(picture_image);
1817 return(picture_image);
1819 flop_image=FlopImage(polaroid_image,exception);
1820 polaroid_image=DestroyImage(polaroid_image);
1821 if (flop_image == (
Image *) NULL)
1823 picture_image=DestroyImage(picture_image);
1824 return(picture_image);
1826 polaroid_image=flop_image;
1827 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
1828 MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
1829 picture_image=DestroyImage(picture_image);
1830 (void) QueryColorCompliance(
"none",AllCompliance,
1831 &polaroid_image->background_color,exception);
1832 rotate_image=RotateImage(polaroid_image,angle,exception);
1833 polaroid_image=DestroyImage(polaroid_image);
1834 if (rotate_image == (
Image *) NULL)
1835 return((
Image *) NULL);
1836 polaroid_image=rotate_image;
1837 trim_image=TrimImage(polaroid_image,exception);
1838 polaroid_image=DestroyImage(polaroid_image);
1839 if (trim_image == (
Image *) NULL)
1840 return((
Image *) NULL);
1841 polaroid_image=trim_image;
1842 return(polaroid_image);
1875MagickExport
Image *SepiaToneImage(
const Image *image,
const double threshold,
1878#define SepiaToneImageTag "SepiaTone/Image"
1899 assert(image != (
const Image *) NULL);
1900 assert(image->signature == MagickCoreSignature);
1902 assert(exception->signature == MagickCoreSignature);
1903 if (IsEventLogging() != MagickFalse)
1904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1905 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
1906 if (sepia_image == (
Image *) NULL)
1907 return((
Image *) NULL);
1908 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
1910 sepia_image=DestroyImage(sepia_image);
1911 return((
Image *) NULL);
1918 image_view=AcquireVirtualCacheView(image,exception);
1919 sepia_view=AcquireAuthenticCacheView(sepia_image,exception);
1920#if defined(MAGICKCORE_OPENMP_SUPPORT)
1921 #pragma omp parallel for schedule(static) shared(progress,status) \
1922 magick_number_threads(image,sepia_image,image->rows,1)
1924 for (y=0; y < (ssize_t) image->rows; y++)
1935 if (status == MagickFalse)
1937 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1938 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
1940 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1945 for (x=0; x < (ssize_t) image->columns; x++)
1951 intensity=GetPixelIntensity(image,p);
1952 tone=intensity > threshold ? (double) QuantumRange : intensity+
1953 (double) QuantumRange-threshold;
1954 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
1955 tone=intensity > (7.0*threshold/6.0) ? (
double) QuantumRange :
1956 intensity+(double) QuantumRange-7.0*threshold/6.0;
1957 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
1958 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
1959 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
1961 if ((
double) GetPixelGreen(image,q) < tone)
1962 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
1963 if ((
double) GetPixelBlue(image,q) < tone)
1964 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
1965 SetPixelAlpha(sepia_image,GetPixelAlpha(image,p),q);
1966 p+=(ptrdiff_t) GetPixelChannels(image);
1967 q+=(ptrdiff_t) GetPixelChannels(sepia_image);
1969 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
1971 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1976#if defined(MAGICKCORE_OPENMP_SUPPORT)
1980 proceed=SetImageProgress(image,SepiaToneImageTag,progress,image->rows);
1981 if (proceed == MagickFalse)
1985 sepia_view=DestroyCacheView(sepia_view);
1986 image_view=DestroyCacheView(image_view);
1987 (void) NormalizeImage(sepia_image,exception);
1988 (void) ContrastImage(sepia_image,MagickTrue,exception);
1989 if (status == MagickFalse)
1990 sepia_image=DestroyImage(sepia_image);
1991 return(sepia_image);
2028MagickExport
Image *ShadowImage(
const Image *image,
const double alpha,
2029 const double sigma,
const ssize_t x_offset,
const ssize_t y_offset,
2032#define ShadowImageTag "Shadow/Image"
2057 assert(image != (
Image *) NULL);
2058 assert(image->signature == MagickCoreSignature);
2060 assert(exception->signature == MagickCoreSignature);
2061 if (IsEventLogging() != MagickFalse)
2062 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2063 clone_image=CloneImage(image,0,0,MagickTrue,exception);
2064 if (clone_image == (
Image *) NULL)
2065 return((
Image *) NULL);
2066 if (IsGrayColorspace(image->colorspace) != MagickFalse)
2067 (void) SetImageColorspace(clone_image,sRGBColorspace,exception);
2068 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod,
2070 border_info.width=CastDoubleToUnsigned(2.0*sigma+0.5);
2071 border_info.height=CastDoubleToUnsigned(2.0*sigma+0.5);
2074 (void) QueryColorCompliance(
"none",AllCompliance,&clone_image->border_color,
2076 clone_image->alpha_trait=BlendPixelTrait;
2077 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
2078 clone_image=DestroyImage(clone_image);
2079 if (border_image == (
Image *) NULL)
2080 return((
Image *) NULL);
2081 if (border_image->alpha_trait == UndefinedPixelTrait)
2082 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
2087 background_color=border_image->background_color;
2088 background_color.alpha_trait=BlendPixelTrait;
2089 image_view=AcquireAuthenticCacheView(border_image,exception);
2090 for (y=0; y < (ssize_t) border_image->rows; y++)
2098 if (status == MagickFalse)
2100 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
2102 if (q == (Quantum *) NULL)
2107 for (x=0; x < (ssize_t) border_image->columns; x++)
2109 if (border_image->alpha_trait != UndefinedPixelTrait)
2110 background_color.alpha=(double) GetPixelAlpha(border_image,q)*alpha/
2112 SetPixelViaPixelInfo(border_image,&background_color,q);
2113 q+=(ptrdiff_t) GetPixelChannels(border_image);
2115 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2118 image_view=DestroyCacheView(image_view);
2119 if (status == MagickFalse)
2121 border_image=DestroyImage(border_image);
2122 return((
Image *) NULL);
2124 channel_mask=SetImageChannelMask(border_image,AlphaChannel);
2125 shadow_image=BlurImage(border_image,0.0,sigma,exception);
2126 border_image=DestroyImage(border_image);
2127 if (shadow_image == (
Image *) NULL)
2128 return((
Image *) NULL);
2129 (void) SetPixelChannelMask(shadow_image,channel_mask);
2130 if (shadow_image->page.width == 0)
2131 shadow_image->page.width=shadow_image->columns;
2132 if (shadow_image->page.height == 0)
2133 shadow_image->page.height=shadow_image->rows;
2134 shadow_image->page.width=(size_t) ((ssize_t) shadow_image->page.width+
2135 x_offset-(ssize_t) border_info.width);
2136 shadow_image->page.height=(size_t) ((ssize_t) shadow_image->page.height+
2137 y_offset-(ssize_t) border_info.height);
2138 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
2139 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
2140 return(shadow_image);
2179MagickExport
Image *SketchImage(
const Image *image,
const double radius,
2180 const double sigma,
const double angle,
ExceptionInfo *exception)
2196 **magick_restrict random_info;
2201#if defined(MAGICKCORE_OPENMP_SUPPORT)
2209 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
2210 MagickTrue,exception);
2211 if (random_image == (
Image *) NULL)
2212 return((
Image *) NULL);
2214 random_info=AcquireRandomInfoTLS();
2215 random_view=AcquireAuthenticCacheView(random_image,exception);
2216#if defined(MAGICKCORE_OPENMP_SUPPORT)
2217 key=GetRandomSecretKey(random_info[0]);
2218 #pragma omp parallel for schedule(static) shared(status) \
2219 magick_number_threads(random_image,random_image,random_image->rows,key == ~0UL ? 0 : 2)
2221 for (y=0; y < (ssize_t) random_image->rows; y++)
2224 id = GetOpenMPThreadId();
2232 if (status == MagickFalse)
2234 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
2236 if (q == (Quantum *) NULL)
2241 for (x=0; x < (ssize_t) random_image->columns; x++)
2249 value=GetPseudoRandomValue(random_info[
id]);
2250 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
2252 PixelChannel channel = GetPixelChannelChannel(image,i);
2253 PixelTrait traits = GetPixelChannelTraits(image,channel);
2254 if (traits == UndefinedPixelTrait)
2256 q[i]=ClampToQuantum((
double) QuantumRange*value);
2258 q+=(ptrdiff_t) GetPixelChannels(random_image);
2260 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
2263 random_view=DestroyCacheView(random_view);
2264 random_info=DestroyRandomInfoTLS(random_info);
2265 if (status == MagickFalse)
2267 random_image=DestroyImage(random_image);
2268 return(random_image);
2270 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
2271 random_image=DestroyImage(random_image);
2272 if (blur_image == (
Image *) NULL)
2273 return((
Image *) NULL);
2274 dodge_image=EdgeImage(blur_image,radius,exception);
2275 blur_image=DestroyImage(blur_image);
2276 if (dodge_image == (
Image *) NULL)
2277 return((
Image *) NULL);
2278 status=ClampImage(dodge_image,exception);
2279 if (status != MagickFalse)
2280 status=NormalizeImage(dodge_image,exception);
2281 if (status != MagickFalse)
2282 status=NegateImage(dodge_image,MagickFalse,exception);
2283 if (status != MagickFalse)
2284 status=TransformImage(&dodge_image,(
char *) NULL,
"50%",exception);
2285 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
2286 if (sketch_image == (
Image *) NULL)
2288 dodge_image=DestroyImage(dodge_image);
2289 return((
Image *) NULL);
2291 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
2292 MagickTrue,0,0,exception);
2293 dodge_image=DestroyImage(dodge_image);
2294 blend_image=CloneImage(image,0,0,MagickTrue,exception);
2295 if (blend_image == (
Image *) NULL)
2297 sketch_image=DestroyImage(sketch_image);
2298 return((
Image *) NULL);
2300 if (blend_image->alpha_trait != BlendPixelTrait)
2301 (void) SetImageAlpha(blend_image,TransparentAlpha,exception);
2302 (void) SetImageArtifact(blend_image,
"compose:args",
"20x80");
2303 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue,
2305 blend_image=DestroyImage(blend_image);
2306 return(sketch_image);
2339MagickExport MagickBooleanType SolarizeImage(
Image *image,
2342#define SolarizeImageTag "Solarize/Image"
2356 assert(image != (
Image *) NULL);
2357 assert(image->signature == MagickCoreSignature);
2358 if (IsEventLogging() != MagickFalse)
2359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2360 if (IsGrayColorspace(image->colorspace) != MagickFalse)
2361 (void) SetImageColorspace(image,sRGBColorspace,exception);
2362 if (image->storage_class == PseudoClass)
2370 for (i=0; i < (ssize_t) image->colors; i++)
2372 if ((
double) image->colormap[i].red > threshold)
2373 image->colormap[i].red=(double) QuantumRange-image->colormap[i].red;
2374 if ((
double) image->colormap[i].green > threshold)
2375 image->colormap[i].green=(double) QuantumRange-
2376 image->colormap[i].green;
2377 if ((
double) image->colormap[i].blue > threshold)
2378 image->colormap[i].blue=(double) QuantumRange-image->colormap[i].blue;
2380 return(SyncImage(image,exception));
2387 image_view=AcquireAuthenticCacheView(image,exception);
2388#if defined(MAGICKCORE_OPENMP_SUPPORT)
2389 #pragma omp parallel for schedule(static) shared(progress,status) \
2390 magick_number_threads(image,image,image->rows,2)
2392 for (y=0; y < (ssize_t) image->rows; y++)
2400 if (status == MagickFalse)
2402 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2403 if (q == (Quantum *) NULL)
2408 for (x=0; x < (ssize_t) image->columns; x++)
2413 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2415 PixelChannel channel = GetPixelChannelChannel(image,i);
2416 PixelTrait traits = GetPixelChannelTraits(image,channel);
2417 if ((traits & UpdatePixelTrait) == 0)
2419 if ((
double) q[i] > threshold)
2420 q[i]=QuantumRange-q[i];
2422 q+=(ptrdiff_t) GetPixelChannels(image);
2424 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2426 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2431#if defined(MAGICKCORE_OPENMP_SUPPORT)
2435 proceed=SetImageProgress(image,SolarizeImageTag,progress,image->rows);
2436 if (proceed == MagickFalse)
2440 image_view=DestroyCacheView(image_view);
2473MagickExport
Image *SteganoImage(
const Image *image,
const Image *watermark,
2476#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
2477#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
2478 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
2479#define SteganoImageTag "Stegano/Image"
2516 assert(image != (
const Image *) NULL);
2517 assert(image->signature == MagickCoreSignature);
2518 assert(watermark != (
const Image *) NULL);
2519 assert(watermark->signature == MagickCoreSignature);
2521 assert(exception->signature == MagickCoreSignature);
2522 if (IsEventLogging() != MagickFalse)
2523 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2525 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
2526 if (stegano_image == (
Image *) NULL)
2527 return((
Image *) NULL);
2528 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
2529 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
2531 stegano_image=DestroyImage(stegano_image);
2532 return((
Image *) NULL);
2540 depth=stegano_image->depth;
2541 k=stegano_image->offset;
2543 watermark_view=AcquireVirtualCacheView(watermark,exception);
2544 stegano_view=AcquireAuthenticCacheView(stegano_image,exception);
2545 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
2547 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
2549 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
2554 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
2556 offset=k/(ssize_t) stegano_image->columns;
2557 if (offset >= (ssize_t) stegano_image->rows)
2559 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
2560 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
2562 if (q == (Quantum *) NULL)
2568 SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
2569 GetBit(GetPixelInfoIntensity(stegano_image,&pixel),i)),q);
2574 SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
2575 GetBit(GetPixelInfoIntensity(stegano_image,&pixel),i)),q);
2580 SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
2581 GetBit(GetPixelInfoIntensity(stegano_image,&pixel),i)),q);
2585 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
2591 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
2593 if (k == stegano_image->offset)
2597 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2602 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
2604 if (proceed == MagickFalse)
2608 stegano_view=DestroyCacheView(stegano_view);
2609 watermark_view=DestroyCacheView(watermark_view);
2610 if (status == MagickFalse)
2611 stegano_image=DestroyImage(stegano_image);
2612 return(stegano_image);
2654MagickExport
Image *StereoImage(
const Image *left_image,
2657 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
2660MagickExport
Image *StereoAnaglyphImage(
const Image *left_image,
2661 const Image *right_image,
const ssize_t x_offset,
const ssize_t y_offset,
2664#define StereoImageTag "Stereo/Image"
2678 assert(left_image != (
const Image *) NULL);
2679 assert(left_image->signature == MagickCoreSignature);
2680 assert(right_image != (
const Image *) NULL);
2681 assert(right_image->signature == MagickCoreSignature);
2683 assert(exception->signature == MagickCoreSignature);
2684 if (IsEventLogging() != MagickFalse)
2685 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2686 left_image->filename);
2688 if ((left_image->columns != right_image->columns) ||
2689 (left_image->rows != right_image->rows))
2690 ThrowImageException(ImageError,
"LeftAndRightImageSizesDiffer");
2694 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
2695 MagickTrue,exception);
2696 if (stereo_image == (
Image *) NULL)
2697 return((
Image *) NULL);
2698 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
2700 stereo_image=DestroyImage(stereo_image);
2701 return((
Image *) NULL);
2703 (void) SetImageColorspace(stereo_image,sRGBColorspace,exception);
2708 for (y=0; y < (ssize_t) stereo_image->rows; y++)
2720 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
2722 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
2723 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
2724 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL) ||
2725 (r == (Quantum *) NULL))
2727 for (x=0; x < (ssize_t) stereo_image->columns; x++)
2729 SetPixelRed(stereo_image,GetPixelRed(left_image,p),r);
2730 SetPixelGreen(stereo_image,GetPixelGreen(right_image,q),r);
2731 SetPixelBlue(stereo_image,GetPixelBlue(right_image,q),r);
2732 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
2733 SetPixelAlpha(stereo_image,(GetPixelAlpha(left_image,p)+
2734 GetPixelAlpha(right_image,q))/2,r);
2735 p+=(ptrdiff_t) GetPixelChannels(left_image);
2736 q+=(ptrdiff_t) GetPixelChannels(right_image);
2737 r+=(ptrdiff_t) GetPixelChannels(stereo_image);
2739 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
2741 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2746 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
2747 stereo_image->rows);
2748 if (proceed == MagickFalse)
2752 if (status == MagickFalse)
2753 stereo_image=DestroyImage(stereo_image);
2754 return(stereo_image);
2788MagickExport
Image *SwirlImage(
const Image *image,
double degrees,
2789 const PixelInterpolateMethod method,
ExceptionInfo *exception)
2791#define SwirlImageTag "Swirl/Image"
2821 assert(image != (
const Image *) NULL);
2822 assert(image->signature == MagickCoreSignature);
2824 assert(exception->signature == MagickCoreSignature);
2825 if (IsEventLogging() != MagickFalse)
2826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2827 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
2828 if (canvas_image == (
Image *) NULL)
2829 return((
Image *) NULL);
2830 swirl_image=CloneImage(canvas_image,0,0,MagickTrue,exception);
2831 if (swirl_image == (
Image *) NULL)
2833 canvas_image=DestroyImage(canvas_image);
2834 return((
Image *) NULL);
2836 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
2838 canvas_image=DestroyImage(canvas_image);
2839 swirl_image=DestroyImage(swirl_image);
2840 return((
Image *) NULL);
2842 if (swirl_image->background_color.alpha_trait != UndefinedPixelTrait)
2843 (void) SetImageAlphaChannel(swirl_image,OnAlphaChannel,exception);
2847 center.x=(double) canvas_image->columns/2.0;
2848 center.y=(double) canvas_image->rows/2.0;
2849 radius=MagickMax(center.x,center.y);
2852 if (canvas_image->columns > canvas_image->rows)
2853 scale.y=(double) canvas_image->columns/(
double) canvas_image->rows;
2855 if (canvas_image->columns < canvas_image->rows)
2856 scale.x=(double) canvas_image->rows/(
double) canvas_image->columns;
2857 degrees=(double) DegreesToRadians(degrees);
2863 canvas_view=AcquireVirtualCacheView(canvas_image,exception);
2864 interpolate_view=AcquireVirtualCacheView(image,exception);
2865 swirl_view=AcquireAuthenticCacheView(swirl_image,exception);
2866#if defined(MAGICKCORE_OPENMP_SUPPORT)
2867 #pragma omp parallel for schedule(static) shared(progress,status) \
2868 magick_number_threads(canvas_image,swirl_image,canvas_image->rows,1)
2870 for (y=0; y < (ssize_t) canvas_image->rows; y++)
2887 if (status == MagickFalse)
2889 p=GetCacheViewVirtualPixels(canvas_view,0,y,canvas_image->columns,1,
2891 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
2893 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
2898 delta.y=scale.y*(double) (y-center.y);
2899 for (x=0; x < (ssize_t) canvas_image->columns; x++)
2904 delta.x=scale.x*(double) (x-center.x);
2905 distance=delta.x*delta.x+delta.y*delta.y;
2906 if (distance >= (radius*radius))
2911 for (i=0; i < (ssize_t) GetPixelChannels(canvas_image); i++)
2913 PixelChannel channel = GetPixelChannelChannel(canvas_image,i);
2914 PixelTrait traits = GetPixelChannelTraits(canvas_image,channel);
2915 PixelTrait swirl_traits = GetPixelChannelTraits(swirl_image,
2917 if ((traits == UndefinedPixelTrait) ||
2918 (swirl_traits == UndefinedPixelTrait))
2920 SetPixelChannel(swirl_image,channel,p[i],q);
2933 factor=1.0-sqrt((
double) distance)/radius;
2934 sine=sin((
double) (degrees*factor*factor));
2935 cosine=cos((
double) (degrees*factor*factor));
2936 status=InterpolatePixelChannels(canvas_image,interpolate_view,
2937 swirl_image,method,((cosine*delta.x-sine*delta.y)/scale.x+center.x),
2938 (
double) ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,
2940 if (status == MagickFalse)
2943 p+=(ptrdiff_t) GetPixelChannels(canvas_image);
2944 q+=(ptrdiff_t) GetPixelChannels(swirl_image);
2946 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
2948 if (canvas_image->progress_monitor != (MagickProgressMonitor) NULL)
2953#if defined(MAGICKCORE_OPENMP_SUPPORT)
2957 proceed=SetImageProgress(canvas_image,SwirlImageTag,progress,
2958 canvas_image->rows);
2959 if (proceed == MagickFalse)
2963 swirl_view=DestroyCacheView(swirl_view);
2964 interpolate_view=DestroyCacheView(interpolate_view);
2965 canvas_view=DestroyCacheView(canvas_view);
2966 canvas_image=DestroyImage(canvas_image);
2967 if (status == MagickFalse)
2968 swirl_image=DestroyImage(swirl_image);
2969 return(swirl_image);
3003MagickExport
Image *TintImage(
const Image *image,
const char *blend,
3006#define TintImageTag "Tint/Image"
3039 assert(image != (
const Image *) NULL);
3040 assert(image->signature == MagickCoreSignature);
3042 assert(exception->signature == MagickCoreSignature);
3043 if (IsEventLogging() != MagickFalse)
3044 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3045 tint_image=CloneImage(image,0,0,MagickTrue,exception);
3046 if (tint_image == (
Image *) NULL)
3047 return((
Image *) NULL);
3048 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
3050 tint_image=DestroyImage(tint_image);
3051 return((
Image *) NULL);
3053 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
3054 (IsPixelInfoGray(tint) == MagickFalse))
3055 (void) SetImageColorspace(tint_image,sRGBColorspace,exception);
3056 if (blend == (
const char *) NULL)
3061 GetPixelInfo(image,&color_vector);
3062 flags=ParseGeometry(blend,&geometry_info);
3063 color_vector.red=geometry_info.rho;
3064 color_vector.green=geometry_info.rho;
3065 color_vector.blue=geometry_info.rho;
3066 color_vector.alpha=(MagickRealType) OpaqueAlpha;
3067 if ((flags & SigmaValue) != 0)
3068 color_vector.green=geometry_info.sigma;
3069 if ((flags & XiValue) != 0)
3070 color_vector.blue=geometry_info.xi;
3071 if ((flags & PsiValue) != 0)
3072 color_vector.alpha=geometry_info.psi;
3073 if (image->colorspace == CMYKColorspace)
3075 color_vector.black=geometry_info.rho;
3076 if ((flags & PsiValue) != 0)
3077 color_vector.black=geometry_info.psi;
3078 if ((flags & ChiValue) != 0)
3079 color_vector.alpha=geometry_info.chi;
3081 intensity=(double) GetPixelInfoIntensity((
const Image *) NULL,tint);
3082 color_vector.red=(double) (color_vector.red*tint->red/100.0-intensity);
3083 color_vector.green=(double) (color_vector.green*tint->green/100.0-intensity);
3084 color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-intensity);
3085 color_vector.black=(double) (color_vector.black*tint->black/100.0-intensity);
3086 color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-intensity);
3092 image_view=AcquireVirtualCacheView(image,exception);
3093 tint_view=AcquireAuthenticCacheView(tint_image,exception);
3094#if defined(MAGICKCORE_OPENMP_SUPPORT)
3095 #pragma omp parallel for schedule(static) shared(progress,status) \
3096 magick_number_threads(image,tint_image,image->rows,1)
3098 for (y=0; y < (ssize_t) image->rows; y++)
3109 if (status == MagickFalse)
3111 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3112 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
3114 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3119 for (x=0; x < (ssize_t) image->columns; x++)
3127 GetPixelInfo(image,&pixel);
3128 weight=QuantumScale*(double) GetPixelRed(image,p)-0.5;
3129 pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
3130 (1.0-(4.0*(weight*weight)));
3131 weight=QuantumScale*(double) GetPixelGreen(image,p)-0.5;
3132 pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
3133 (1.0-(4.0*(weight*weight)));
3134 weight=QuantumScale*(double) GetPixelBlue(image,p)-0.5;
3135 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
3136 (1.0-(4.0*(weight*weight)));
3137 weight=QuantumScale*(double) GetPixelBlack(image,p)-0.5;
3138 pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black*
3139 (1.0-(4.0*(weight*weight)));
3140 pixel.alpha=(MagickRealType) GetPixelAlpha(image,p);
3141 SetPixelViaPixelInfo(tint_image,&pixel,q);
3142 p+=(ptrdiff_t) GetPixelChannels(image);
3143 q+=(ptrdiff_t) GetPixelChannels(tint_image);
3145 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
3147 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3152#if defined(MAGICKCORE_OPENMP_SUPPORT)
3156 proceed=SetImageProgress(image,TintImageTag,progress,image->rows);
3157 if (proceed == MagickFalse)
3161 tint_view=DestroyCacheView(tint_view);
3162 image_view=DestroyCacheView(image_view);
3163 if (status == MagickFalse)
3164 tint_image=DestroyImage(tint_image);
3200MagickExport
Image *VignetteImage(
const Image *image,
const double radius,
3201 const double sigma,
const ssize_t x,
const ssize_t y,
ExceptionInfo *exception)
3204 ellipse[MagickPathExtent];
3215 assert(image != (
Image *) NULL);
3216 assert(image->signature == MagickCoreSignature);
3218 assert(exception->signature == MagickCoreSignature);
3219 if (IsEventLogging() != MagickFalse)
3220 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3221 canvas=CloneImage(image,0,0,MagickTrue,exception);
3222 if (canvas == (
Image *) NULL)
3223 return((
Image *) NULL);
3224 if (SetImageStorageClass(canvas,DirectClass,exception) == MagickFalse)
3226 canvas=DestroyImage(canvas);
3227 return((
Image *) NULL);
3229 canvas->alpha_trait=BlendPixelTrait;
3230 oval_image=CloneImage(canvas,canvas->columns,canvas->rows,MagickTrue,
3232 if (oval_image == (
Image *) NULL)
3234 canvas=DestroyImage(canvas);
3235 return((
Image *) NULL);
3237 (void) QueryColorCompliance(
"#000000",AllCompliance,
3238 &oval_image->background_color,exception);
3239 (void) SetImageBackgroundColor(oval_image,exception);
3241 (void) QueryColorCompliance(
"#ffffff",AllCompliance,&draw_info->fill,
3243 (void) QueryColorCompliance(
"#ffffff",AllCompliance,&draw_info->stroke,
3245 (void) FormatLocaleString(ellipse,MagickPathExtent,
"ellipse %g,%g,%g,%g,"
3246 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
3248 draw_info->primitive=AcquireString(ellipse);
3249 (void) DrawImage(oval_image,draw_info,exception);
3250 draw_info=DestroyDrawInfo(draw_info);
3251 blur_image=BlurImage(oval_image,radius,sigma,exception);
3252 oval_image=DestroyImage(oval_image);
3253 if (blur_image == (
Image *) NULL)
3255 canvas=DestroyImage(canvas);
3256 return((
Image *) NULL);
3258 blur_image->alpha_trait=UndefinedPixelTrait;
3259 (void) CompositeImage(canvas,blur_image,IntensityCompositeOp,MagickTrue,
3261 blur_image=DestroyImage(blur_image);
3262 vignette_image=MergeImageLayers(canvas,FlattenLayer,exception);
3263 canvas=DestroyImage(canvas);
3264 if (vignette_image != (
Image *) NULL)
3265 (void) TransformImageColorspace(vignette_image,image->colorspace,exception);
3266 return(vignette_image);
3302MagickExport
Image *WaveImage(
const Image *image,
const double amplitude,
3303 const double wave_length,
const PixelInterpolateMethod method,
3306#define WaveImageTag "Wave/Image"
3334 assert(image != (
Image *) NULL);
3335 assert(image->signature == MagickCoreSignature);
3337 assert(exception->signature == MagickCoreSignature);
3338 if (IsEventLogging() != MagickFalse)
3339 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3340 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
3341 if (canvas_image == (
Image *) NULL)
3342 return((
Image *) NULL);
3343 if ((canvas_image->alpha_trait == UndefinedPixelTrait) &&
3344 (canvas_image->background_color.alpha != (
double) OpaqueAlpha))
3345 (void) SetImageAlpha(canvas_image,OpaqueAlpha,exception);
3346 wave_image=CloneImage(canvas_image,canvas_image->columns,(
size_t)
3347 (canvas_image->rows+2.0*fabs(amplitude)),MagickTrue,exception);
3348 if (wave_image == (
Image *) NULL)
3350 canvas_image=DestroyImage(canvas_image);
3351 return((
Image *) NULL);
3353 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
3355 canvas_image=DestroyImage(canvas_image);
3356 wave_image=DestroyImage(wave_image);
3357 return((
Image *) NULL);
3362 sine_map=(
float *) AcquireQuantumMemory((
size_t) wave_image->columns,
3364 if (sine_map == (
float *) NULL)
3366 canvas_image=DestroyImage(canvas_image);
3367 wave_image=DestroyImage(wave_image);
3368 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
3370 for (i=0; i < (ssize_t) wave_image->columns; i++)
3371 sine_map[i]=(
float) (fabs(amplitude)+amplitude*sin((
double)
3372 ((2.0*MagickPI*i)*(
double) PerceptibleReciprocal(wave_length))));
3378 canvas_image_view=AcquireVirtualCacheView(canvas_image,exception);
3379 wave_view=AcquireAuthenticCacheView(wave_image,exception);
3380 (void) SetCacheViewVirtualPixelMethod(canvas_image_view,
3381 BackgroundVirtualPixelMethod);
3382#if defined(MAGICKCORE_OPENMP_SUPPORT)
3383 #pragma omp parallel for schedule(static) shared(progress,status) \
3384 magick_number_threads(canvas_image,wave_image,wave_image->rows,1)
3386 for (y=0; y < (ssize_t) wave_image->rows; y++)
3397 if (status == MagickFalse)
3399 p=GetCacheViewVirtualPixels(canvas_image_view,0,y,canvas_image->columns,1,
3401 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
3403 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3408 for (x=0; x < (ssize_t) wave_image->columns; x++)
3410 status=InterpolatePixelChannels(canvas_image,canvas_image_view,
3411 wave_image,method,(
double) x,(
double) (y-sine_map[x]),q,exception);
3412 if (status == MagickFalse)
3414 p+=(ptrdiff_t) GetPixelChannels(canvas_image);
3415 q+=(ptrdiff_t) GetPixelChannels(wave_image);
3417 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
3419 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3424#if defined(MAGICKCORE_OPENMP_SUPPORT)
3428 proceed=SetImageProgress(canvas_image,WaveImageTag,progress,
3429 canvas_image->rows);
3430 if (proceed == MagickFalse)
3434 wave_view=DestroyCacheView(wave_view);
3435 canvas_image_view=DestroyCacheView(canvas_image_view);
3436 canvas_image=DestroyImage(canvas_image);
3437 sine_map=(
float *) RelinquishMagickMemory(sine_map);
3438 if (status == MagickFalse)
3439 wave_image=DestroyImage(wave_image);
3478static inline void HatTransform(
const float *magick_restrict pixels,
3479 const size_t stride,
const size_t extent,
const size_t scale,
float *kernel)
3490 q=pixels+scale*stride;
3491 r=pixels+scale*stride;
3492 for (i=0; i < (ssize_t) scale; i++)
3494 kernel[i]=0.25f*(*p+(*p)+(*q)+(*r));
3495 p+=(ptrdiff_t) stride;
3497 r+=(ptrdiff_t) stride;
3499 for ( ; i < (ssize_t) (extent-scale); i++)
3501 kernel[i]=0.25f*(2.0f*(*p)+*(p-scale*stride)+*(p+scale*stride));
3502 p+=(ptrdiff_t) stride;
3505 r=pixels+stride*(extent-2);
3506 for ( ; i < (ssize_t) extent; i++)
3508 kernel[i]=0.25f*(*p+(*p)+(*q)+(*r));
3509 p+=(ptrdiff_t) stride;
3510 q+=(ptrdiff_t) stride;
3515MagickExport
Image *WaveletDenoiseImage(
const Image *image,
3516 const double threshold,
const double softness,
ExceptionInfo *exception)
3542 noise_levels[] = { 0.8002f, 0.2735f, 0.1202f, 0.0585f, 0.0291f, 0.0152f,
3548 assert(image != (
const Image *) NULL);
3549 assert(image->signature == MagickCoreSignature);
3551 assert(exception->signature == MagickCoreSignature);
3552 if (IsEventLogging() != MagickFalse)
3553 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3554#if defined(MAGICKCORE_OPENCL_SUPPORT)
3555 noise_image=AccelerateWaveletDenoiseImage(image,threshold,exception);
3556 if (noise_image != (
Image *) NULL)
3557 return(noise_image);
3559 noise_image=CloneImage(image,0,0,MagickTrue,exception);
3560 if (noise_image == (
Image *) NULL)
3561 return((
Image *) NULL);
3562 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
3564 noise_image=DestroyImage(noise_image);
3565 return((
Image *) NULL);
3567 if (AcquireMagickResource(WidthResource,4*image->columns) == MagickFalse)
3568 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
3569 pixels_info=AcquireVirtualMemory(3*image->columns,image->rows*
3571 kernel=(
float *) AcquireQuantumMemory(MagickMax(image->rows,image->columns)+1,
3572 GetOpenMPMaximumThreads()*
sizeof(*kernel));
3573 if ((pixels_info == (
MemoryInfo *) NULL) || (kernel == (
float *) NULL))
3575 if (kernel != (
float *) NULL)
3576 kernel=(
float *) RelinquishMagickMemory(kernel);
3578 pixels_info=RelinquishVirtualMemory(pixels_info);
3579 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
3581 pixels=(
float *) GetVirtualMemoryBlob(pixels_info);
3583 number_pixels=(MagickSizeType) image->columns*image->rows;
3584 image_view=AcquireAuthenticCacheView(image,exception);
3585 noise_view=AcquireAuthenticCacheView(noise_image,exception);
3586 for (channel=0; channel < (ssize_t) GetPixelChannels(image); channel++)
3605 if (status == MagickFalse)
3607 traits=GetPixelChannelTraits(image,(PixelChannel) channel);
3608 if (traits == UndefinedPixelTrait)
3610 pixel_channel=GetPixelChannelChannel(image,channel);
3611 if ((pixel_channel != RedPixelChannel) &&
3612 (pixel_channel != GreenPixelChannel) &&
3613 (pixel_channel != BluePixelChannel))
3619 for (y=0; y < (ssize_t) image->rows; y++)
3627 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3628 if (p == (
const Quantum *) NULL)
3633 for (x=0; x < (ssize_t) image->columns; x++)
3635 pixels[i++]=(float) p[channel];
3636 p+=(ptrdiff_t) GetPixelChannels(image);
3645 for (level=0; level < 5; level++)
3653 low_pass=(size_t) (number_pixels*((level & 0x01)+1));
3654#if defined(MAGICKCORE_OPENMP_SUPPORT)
3655 #pragma omp parallel for schedule(static,1) \
3656 magick_number_threads(image,image,image->rows,1)
3658 for (y=0; y < (ssize_t) image->rows; y++)
3661 id = GetOpenMPThreadId();
3670 p=kernel+
id*(ssize_t) image->columns;
3671 q=pixels+y*(ssize_t) image->columns;
3672 HatTransform(q+high_pass,1,image->columns,((
size_t) 1UL << level),p);
3673 q+=(ptrdiff_t) low_pass;
3674 for (c=0; c < (ssize_t) image->columns; c++)
3677#if defined(MAGICKCORE_OPENMP_SUPPORT)
3678 #pragma omp parallel for schedule(static,1) \
3679 magick_number_threads(image,image,image->columns,1)
3681 for (x=0; x < (ssize_t) image->columns; x++)
3684 id = GetOpenMPThreadId();
3693 p=kernel+
id*(ssize_t) image->rows;
3694 q=pixels+x+low_pass;
3695 HatTransform(q,image->columns,image->rows,((
size_t) 1UL << level),p);
3696 for (r=0; r < (ssize_t) image->rows; r++)
3699 q+=(ptrdiff_t) image->columns;
3706 magnitude=threshold*(double) noise_levels[level];
3707 for (i=0; i < (ssize_t) number_pixels; ++i)
3709 pixels[(ssize_t) high_pass+i]-=pixels[(ssize_t) low_pass+i];
3710 if ((
double) pixels[(ssize_t) high_pass+i] < -magnitude)
3711 pixels[(ssize_t) high_pass+i]+=(
float) (magnitude-softness*magnitude);
3713 if ((
double) pixels[(ssize_t) high_pass+i] > magnitude)
3714 pixels[(ssize_t) high_pass+i]-=(
float) (magnitude-softness*
3717 pixels[(ssize_t) high_pass+i]*=(
float) softness;
3719 pixels[i]+=pixels[(ssize_t) high_pass+i];
3727 for (y=0; y < (ssize_t) image->rows; y++)
3741 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
3743 if (q == (Quantum *) NULL)
3748 offset=GetPixelChannelOffset(noise_image,pixel_channel);
3749 for (x=0; x < (ssize_t) image->columns; x++)
3754 pixel=(MagickRealType) pixels[i]+(MagickRealType)
3755 pixels[(ssize_t) low_pass+i];
3756 q[offset]=ClampToQuantum(pixel);
3758 q+=(ptrdiff_t) GetPixelChannels(noise_image);
3760 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
3761 if (sync == MagickFalse)
3764 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3769 proceed=SetImageProgress(image,AddNoiseImageTag,(MagickOffsetType)
3770 channel,GetPixelChannels(image));
3771 if (proceed == MagickFalse)
3775 noise_view=DestroyCacheView(noise_view);
3776 image_view=DestroyCacheView(image_view);
3777 kernel=(
float *) RelinquishMagickMemory(kernel);
3778 pixels_info=RelinquishVirtualMemory(pixels_info);
3779 if (status == MagickFalse)
3780 noise_image=DestroyImage(noise_image);
3781 return(noise_image);