43#include "MagickCore/studio.h"
44#include "MagickCore/accelerate-private.h"
45#include "MagickCore/blob.h"
46#include "MagickCore/cache-view.h"
47#include "MagickCore/color.h"
48#include "MagickCore/color-private.h"
49#include "MagickCore/colorspace.h"
50#include "MagickCore/constitute.h"
51#include "MagickCore/decorate.h"
52#include "MagickCore/distort.h"
53#include "MagickCore/draw.h"
54#include "MagickCore/enhance.h"
55#include "MagickCore/exception.h"
56#include "MagickCore/exception-private.h"
57#include "MagickCore/effect.h"
58#include "MagickCore/fx.h"
59#include "MagickCore/gem.h"
60#include "MagickCore/gem-private.h"
61#include "MagickCore/geometry.h"
62#include "MagickCore/image-private.h"
63#include "MagickCore/list.h"
64#include "MagickCore/log.h"
65#include "MagickCore/matrix.h"
66#include "MagickCore/memory_.h"
67#include "MagickCore/memory-private.h"
68#include "MagickCore/monitor.h"
69#include "MagickCore/monitor-private.h"
70#include "MagickCore/montage.h"
71#include "MagickCore/morphology.h"
72#include "MagickCore/morphology-private.h"
73#include "MagickCore/paint.h"
74#include "MagickCore/pixel-accessor.h"
75#include "MagickCore/property.h"
76#include "MagickCore/quantize.h"
77#include "MagickCore/quantum.h"
78#include "MagickCore/quantum-private.h"
79#include "MagickCore/random_.h"
80#include "MagickCore/random-private.h"
81#include "MagickCore/resample.h"
82#include "MagickCore/resample-private.h"
83#include "MagickCore/resize.h"
84#include "MagickCore/resource_.h"
85#include "MagickCore/segment.h"
86#include "MagickCore/shear.h"
87#include "MagickCore/signature-private.h"
88#include "MagickCore/statistic.h"
89#include "MagickCore/string_.h"
90#include "MagickCore/thread-private.h"
91#include "MagickCore/transform.h"
92#include "MagickCore/threshold.h"
128MagickExport
Image *AdaptiveBlurImage(
const Image *image,
const double radius,
131#define AdaptiveBlurImageTag "Convolve/Image"
132#define MagickSigma (fabs(sigma) < MagickEpsilon ? MagickEpsilon : sigma)
161 assert(image != (
const Image *) NULL);
162 assert(image->signature == MagickCoreSignature);
164 assert(exception->signature == MagickCoreSignature);
165 if (IsEventLogging() != MagickFalse)
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
167 blur_image=CloneImage(image,0,0,MagickTrue,exception);
168 if (blur_image == (
Image *) NULL)
169 return((
Image *) NULL);
170 if (fabs(sigma) < MagickEpsilon)
172 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
174 blur_image=DestroyImage(blur_image);
175 return((
Image *) NULL);
180 edge_image=EdgeImage(image,radius,exception);
181 if (edge_image == (
Image *) NULL)
183 blur_image=DestroyImage(blur_image);
184 return((
Image *) NULL);
186 (void) AutoLevelImage(edge_image,exception);
187 gaussian_image=BlurImage(edge_image,radius,sigma,exception);
188 if (gaussian_image != (
Image *) NULL)
190 edge_image=DestroyImage(edge_image);
191 edge_image=gaussian_image;
193 (void) AutoLevelImage(edge_image,exception);
197 width=GetOptimalKernelWidth2D(radius,sigma);
198 kernel=(
double **) MagickAssumeAligned(AcquireAlignedMemory((
size_t) width,
200 if (kernel == (
double **) NULL)
202 edge_image=DestroyImage(edge_image);
203 blur_image=DestroyImage(blur_image);
204 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
206 (void) memset(kernel,0,(
size_t) width*
sizeof(*kernel));
207 for (w=0; w < (ssize_t) width; w+=2)
215 kernel[w]=(
double *) MagickAssumeAligned(AcquireAlignedMemory(
216 (width-(
size_t) w),(width-(
size_t) w)*
sizeof(**kernel)));
217 if (kernel[w] == (
double *) NULL)
220 j=((ssize_t) width-w-1)/2;
222 for (v=(-j); v <= j; v++)
224 for (u=(-j); u <= j; u++)
226 kernel[w][k]=(double) (exp(-((
double) u*u+v*v)/(2.0*MagickSigma*
227 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
228 normalize+=kernel[w][k];
232 kernel[w][(k-1)/2]+=(
double) (1.0-normalize);
233 if (sigma < MagickEpsilon)
234 kernel[w][(k-1)/2]=1.0;
236 if (w < (ssize_t) width)
238 for (w-=2; w >= 0; w-=2)
239 kernel[w]=(
double *) RelinquishAlignedMemory(kernel[w]);
240 kernel=(
double **) RelinquishAlignedMemory(kernel);
241 edge_image=DestroyImage(edge_image);
242 blur_image=DestroyImage(blur_image);
243 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
250 image_view=AcquireVirtualCacheView(image,exception);
251 edge_view=AcquireVirtualCacheView(edge_image,exception);
252 blur_view=AcquireAuthenticCacheView(blur_image,exception);
253#if defined(MAGICKCORE_OPENMP_SUPPORT)
254 #pragma omp parallel for schedule(static) shared(progress,status) \
255 magick_number_threads(image,blur_image,blur_image->rows,1)
257 for (y=0; y < (ssize_t) blur_image->rows; y++)
268 if (status == MagickFalse)
270 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
271 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
273 if ((r == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
278 for (x=0; x < (ssize_t) blur_image->columns; x++)
290 j=CastDoubleToLong(ceil((
double) width*(1.0-QuantumScale*
291 GetPixelIntensity(edge_image,r))-0.5));
295 if (j > (ssize_t) width)
299 p=GetCacheViewVirtualPixels(image_view,x-((ssize_t) width-j)/2L,y-
300 ((ssize_t) width-j)/2L,width-(
size_t) j,width-(
size_t) j,exception);
301 if (p == (
const Quantum *) NULL)
303 center=(ssize_t) (GetPixelChannels(image)*(width-(
size_t) j)*
304 ((width-(
size_t) j)/2L)+GetPixelChannels(image)*((width-(
size_t) j)/2));
305 for (i=0; i < (ssize_t) GetPixelChannels(blur_image); i++)
311 *magick_restrict pixels;
329 channel=GetPixelChannelChannel(image,i);
330 traits=GetPixelChannelTraits(image,channel);
331 blur_traits=GetPixelChannelTraits(blur_image,channel);
332 if ((traits == UndefinedPixelTrait) ||
333 (blur_traits == UndefinedPixelTrait))
335 if ((blur_traits & CopyPixelTrait) != 0)
337 SetPixelChannel(blur_image,channel,p[center+i],q);
344 if ((blur_traits & BlendPixelTrait) == 0)
349 for (v=0; v < ((ssize_t) width-j); v++)
351 for (u=0; u < ((ssize_t) width-j); u++)
353 pixel+=(*k)*(double) pixels[i];
356 pixels+=(ptrdiff_t) GetPixelChannels(image);
359 gamma=PerceptibleReciprocal(gamma);
360 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
366 for (v=0; v < ((ssize_t) width-j); v++)
368 for (u=0; u < ((ssize_t) width-j); u++)
370 alpha=(double) (QuantumScale*(
double) GetPixelAlpha(image,pixels));
371 pixel+=(*k)*alpha*(double) pixels[i];
374 pixels+=(ptrdiff_t) GetPixelChannels(image);
377 gamma=PerceptibleReciprocal(gamma);
378 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
380 q+=(ptrdiff_t) GetPixelChannels(blur_image);
381 r+=(ptrdiff_t) GetPixelChannels(edge_image);
383 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
385 if (image->progress_monitor != (MagickProgressMonitor) NULL)
390#if defined(MAGICKCORE_OPENMP_SUPPORT)
394 proceed=SetImageProgress(image,AdaptiveBlurImageTag,progress,
396 if (proceed == MagickFalse)
400 blur_image->type=image->type;
401 blur_view=DestroyCacheView(blur_view);
402 edge_view=DestroyCacheView(edge_view);
403 image_view=DestroyCacheView(image_view);
404 edge_image=DestroyImage(edge_image);
405 for (w=0; w < (ssize_t) width; w+=2)
406 kernel[w]=(
double *) RelinquishAlignedMemory(kernel[w]);
407 kernel=(
double **) RelinquishAlignedMemory(kernel);
408 if (status == MagickFalse)
409 blur_image=DestroyImage(blur_image);
447MagickExport
Image *AdaptiveSharpenImage(
const Image *image,
const double radius,
450#define AdaptiveSharpenImageTag "Convolve/Image"
451#define MagickSigma (fabs(sigma) < MagickEpsilon ? MagickEpsilon : sigma)
480 assert(image != (
const Image *) NULL);
481 assert(image->signature == MagickCoreSignature);
483 assert(exception->signature == MagickCoreSignature);
484 if (IsEventLogging() != MagickFalse)
485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
486 sharp_image=CloneImage(image,0,0,MagickTrue,exception);
487 if (sharp_image == (
Image *) NULL)
488 return((
Image *) NULL);
489 if (fabs(sigma) < MagickEpsilon)
491 if (SetImageStorageClass(sharp_image,DirectClass,exception) == MagickFalse)
493 sharp_image=DestroyImage(sharp_image);
494 return((
Image *) NULL);
499 edge_image=EdgeImage(image,radius,exception);
500 if (edge_image == (
Image *) NULL)
502 sharp_image=DestroyImage(sharp_image);
503 return((
Image *) NULL);
505 (void) AutoLevelImage(edge_image,exception);
506 gaussian_image=BlurImage(edge_image,radius,sigma,exception);
507 if (gaussian_image != (
Image *) NULL)
509 edge_image=DestroyImage(edge_image);
510 edge_image=gaussian_image;
512 (void) AutoLevelImage(edge_image,exception);
516 width=GetOptimalKernelWidth2D(radius,sigma);
517 kernel=(
double **) MagickAssumeAligned(AcquireAlignedMemory((
size_t)
518 width,
sizeof(*kernel)));
519 if (kernel == (
double **) NULL)
521 edge_image=DestroyImage(edge_image);
522 sharp_image=DestroyImage(sharp_image);
523 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
525 (void) memset(kernel,0,(
size_t) width*
sizeof(*kernel));
526 for (w=0; w < (ssize_t) width; w+=2)
534 kernel[w]=(
double *) MagickAssumeAligned(AcquireAlignedMemory((
size_t)
535 (width-(
size_t) w),(width-(
size_t) w)*
sizeof(**kernel)));
536 if (kernel[w] == (
double *) NULL)
539 j=((ssize_t) width-w-1)/2;
541 for (v=(-j); v <= j; v++)
543 for (u=(-j); u <= j; u++)
545 kernel[w][k]=(double) (-exp(-((
double) u*u+v*v)/(2.0*MagickSigma*
546 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
547 normalize+=kernel[w][k];
551 kernel[w][(k-1)/2]=(
double) ((-2.0)*normalize);
552 if (sigma < MagickEpsilon)
553 kernel[w][(k-1)/2]=1.0;
555 if (w < (ssize_t) width)
557 for (w-=2; w >= 0; w-=2)
558 kernel[w]=(
double *) RelinquishAlignedMemory(kernel[w]);
559 kernel=(
double **) RelinquishAlignedMemory(kernel);
560 edge_image=DestroyImage(edge_image);
561 sharp_image=DestroyImage(sharp_image);
562 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
569 image_view=AcquireVirtualCacheView(image,exception);
570 edge_view=AcquireVirtualCacheView(edge_image,exception);
571 sharp_view=AcquireAuthenticCacheView(sharp_image,exception);
572#if defined(MAGICKCORE_OPENMP_SUPPORT)
573 #pragma omp parallel for schedule(static) shared(progress,status) \
574 magick_number_threads(image,sharp_image,sharp_image->rows,1)
576 for (y=0; y < (ssize_t) sharp_image->rows; y++)
587 if (status == MagickFalse)
589 r=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns,1,exception);
590 q=QueueCacheViewAuthenticPixels(sharp_view,0,y,sharp_image->columns,1,
592 if ((r == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
597 for (x=0; x < (ssize_t) sharp_image->columns; x++)
609 j=CastDoubleToLong(ceil((
double) width*(1.0-QuantumScale*
610 GetPixelIntensity(edge_image,r))-0.5));
614 if (j > (ssize_t) width)
618 p=GetCacheViewVirtualPixels(image_view,x-(((ssize_t) width-j)/2L),y-
619 (((ssize_t) width-j)/2L),width-(
size_t) j,width-(
size_t) j,exception);
620 if (p == (
const Quantum *) NULL)
622 center=(ssize_t) (GetPixelChannels(image)*(width-(
size_t) j)*
623 ((width-(
size_t) j)/2L)+GetPixelChannels(image)*((width-(
size_t) j)/2));
624 for (i=0; i < (ssize_t) GetPixelChannels(sharp_image); i++)
630 *magick_restrict pixels;
648 channel=GetPixelChannelChannel(image,i);
649 traits=GetPixelChannelTraits(image,channel);
650 sharp_traits=GetPixelChannelTraits(sharp_image,channel);
651 if ((traits == UndefinedPixelTrait) ||
652 (sharp_traits == UndefinedPixelTrait))
654 if ((sharp_traits & CopyPixelTrait) != 0)
656 SetPixelChannel(sharp_image,channel,p[center+i],q);
663 if ((sharp_traits & BlendPixelTrait) == 0)
668 for (v=0; v < ((ssize_t) width-j); v++)
670 for (u=0; u < ((ssize_t) width-j); u++)
672 pixel+=(*k)*(double) pixels[i];
675 pixels+=(ptrdiff_t) GetPixelChannels(image);
678 gamma=PerceptibleReciprocal(gamma);
679 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
685 for (v=0; v < ((ssize_t) width-j); v++)
687 for (u=0; u < ((ssize_t) width-j); u++)
689 alpha=(double) (QuantumScale*(
double) GetPixelAlpha(image,pixels));
690 pixel+=(*k)*alpha*(double) pixels[i];
693 pixels+=(ptrdiff_t) GetPixelChannels(image);
696 gamma=PerceptibleReciprocal(gamma);
697 SetPixelChannel(sharp_image,channel,ClampToQuantum(gamma*pixel),q);
699 q+=(ptrdiff_t) GetPixelChannels(sharp_image);
700 r+=(ptrdiff_t) GetPixelChannels(edge_image);
702 if (SyncCacheViewAuthenticPixels(sharp_view,exception) == MagickFalse)
704 if (image->progress_monitor != (MagickProgressMonitor) NULL)
709#if defined(MAGICKCORE_OPENMP_SUPPORT)
713 proceed=SetImageProgress(image,AdaptiveSharpenImageTag,progress,
715 if (proceed == MagickFalse)
719 sharp_image->type=image->type;
720 sharp_view=DestroyCacheView(sharp_view);
721 edge_view=DestroyCacheView(edge_view);
722 image_view=DestroyCacheView(image_view);
723 edge_image=DestroyImage(edge_image);
724 for (w=0; w < (ssize_t) width; w+=2)
725 kernel[w]=(
double *) RelinquishAlignedMemory(kernel[w]);
726 kernel=(
double **) RelinquishAlignedMemory(kernel);
727 if (status == MagickFalse)
728 sharp_image=DestroyImage(sharp_image);
765MagickExport
Image *BlurImage(
const Image *image,
const double radius,
769 geometry[MagickPathExtent];
777 assert(image != (
const Image *) NULL);
778 assert(image->signature == MagickCoreSignature);
780 assert(exception->signature == MagickCoreSignature);
781 if (IsEventLogging() != MagickFalse)
782 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
783#if defined(MAGICKCORE_OPENCL_SUPPORT)
784 blur_image=AccelerateBlurImage(image,radius,sigma,exception);
785 if (blur_image != (
Image *) NULL)
788 (void) FormatLocaleString(geometry,MagickPathExtent,
789 "blur:%.20gx%.20g;blur:%.20gx%.20g+90",radius,sigma,radius,sigma);
790 kernel_info=AcquireKernelInfo(geometry,exception);
792 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
793 blur_image=ConvolveImage(image,kernel_info,exception);
794 kernel_info=DestroyKernelInfo(kernel_info);
846static inline double BlurDistance(
const ssize_t x,
const ssize_t y,
847 const ssize_t u,
const ssize_t v)
849 return(sqrt(((
double) x-u)*((
double) x-u)+((
double) y-v)*((
double) y-v)));
852static inline double BlurGaussian(
const double x,
const double sigma)
854 return(exp(-((
double) x*x)*PerceptibleReciprocal(2.0*sigma*sigma))*
855 PerceptibleReciprocal(Magick2PI*sigma*sigma));
858static double **DestroyBilateralTLS(
const size_t number_threads,
864 assert(weights != (
double **) NULL);
865 for (i=0; i <= (ssize_t) number_threads; i++)
866 if (weights[i] != (
double *) NULL)
867 weights[i]=(
double *) RelinquishMagickMemory(weights[i]);
868 weights=(
double **) RelinquishMagickMemory(weights);
872static double **AcquireBilateralTLS(
const size_t number_threads,
873 const size_t width,
const size_t height)
881 weights=(
double **) AcquireQuantumMemory(number_threads+1,
sizeof(*weights));
882 if (weights == (
double **) NULL)
883 return((
double **) NULL);
884 (void) memset(weights,0,number_threads*
sizeof(*weights));
885 for (i=0; i <= (ssize_t) number_threads; i++)
887 weights[i]=(
double *) AcquireQuantumMemory(width,height*
sizeof(**weights));
888 if (weights[i] == (
double *) NULL)
889 return(DestroyBilateralTLS(number_threads,weights));
894MagickExport
Image *BilateralBlurImage(
const Image *image,
const size_t width,
895 const size_t height,
const double intensity_sigma,
const double spatial_sigma,
898#define MaxIntensity (255)
899#define BilateralBlurImageTag "Blur/Image"
906 intensity_gaussian[2*(MaxIntensity+1)],
929 assert(image != (
const Image *) NULL);
930 assert(image->signature == MagickCoreSignature);
932 assert(exception->signature == MagickCoreSignature);
933 if (IsEventLogging() != MagickFalse)
934 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
935 blur_image=CloneImage(image,0,0,MagickTrue,exception);
936 if (blur_image == (
Image *) NULL)
937 return((
Image *) NULL);
938 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
940 blur_image=DestroyImage(blur_image);
941 return((
Image *) NULL);
943 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
944 weights=AcquireBilateralTLS(number_threads,MagickMax(width,1),
945 MagickMax(height,1));
946 if (weights == (
double **) NULL)
948 blur_image=DestroyImage(blur_image);
949 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
951 for (w=(-MaxIntensity); w < MaxIntensity; w++)
952 intensity_gaussian[w+MaxIntensity]=BlurGaussian((
double) w,intensity_sigma);
953 spatial_gaussian=weights[number_threads];
960 mid.x=(ssize_t) (MagickMax(width,1)/2L);
961 mid.y=(ssize_t) (MagickMax(height,1)/2L);
962 for (v=0; v < (ssize_t) MagickMax(height,1); v++)
967 for (u=0; u < (ssize_t) MagickMax(width,1); u++)
968 spatial_gaussian[n++]=BlurGaussian(BlurDistance(0,0,u-mid.x,v-mid.y),
977 image_view=AcquireVirtualCacheView(image,exception);
978 blur_view=AcquireAuthenticCacheView(blur_image,exception);
979#if defined(MAGICKCORE_OPENMP_SUPPORT)
980 #pragma omp parallel for schedule(static) shared(progress,status) \
981 magick_number_threads(image,blur_image,blur_image->rows,1)
983 for (y=0; y < (ssize_t) blur_image->rows; y++)
986 id = GetOpenMPThreadId();
994 if (status == MagickFalse)
996 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
998 if (q == (Quantum *) NULL)
1003 for (x=0; x < (ssize_t) blur_image->columns; x++)
1022 p=GetCacheViewVirtualPixels(image_view,x-mid.x,y-mid.y,MagickMax(width,1),
1023 MagickMax(height,1),exception);
1024 if (p == (
const Quantum *) NULL)
1026 p+=(ptrdiff_t) (GetPixelChannels(image)*MagickMax(width,1)*(
size_t) mid.y+
1027 GetPixelChannels(image)*(
size_t) mid.x);
1029 for (v=0; v < (ssize_t) MagickMax(height,1); v++)
1031 for (u=0; u < (ssize_t) MagickMax(width,1); u++)
1036 r=p+(ssize_t) (GetPixelChannels(image)*MagickMax(width,1)*
1037 (
size_t) (mid.y-v)+GetPixelChannels(image)*(
size_t) (mid.x-u));
1038 intensity=ScaleQuantumToChar(GetPixelIntensity(image,r))-
1039 (double) ScaleQuantumToChar(GetPixelIntensity(image,p));
1040 if ((intensity >= -MaxIntensity) && (intensity <= MaxIntensity))
1041 weights[id][n]=intensity_gaussian[(ssize_t) intensity+MaxIntensity]*
1042 spatial_gaussian[n];
1044 weights[id][n]=BlurGaussian(intensity,intensity_sigma)*
1045 BlurGaussian(BlurDistance(x,y,x+u-mid.x,y+v-mid.y),spatial_sigma);
1049 for (i=0; i < (ssize_t) GetPixelChannels(blur_image); i++)
1058 channel=GetPixelChannelChannel(image,i);
1059 traits=GetPixelChannelTraits(image,channel);
1060 blur_traits=GetPixelChannelTraits(blur_image,channel);
1061 if ((traits == UndefinedPixelTrait) ||
1062 (blur_traits == UndefinedPixelTrait))
1064 if ((blur_traits & CopyPixelTrait) != 0)
1066 SetPixelChannel(blur_image,channel,p[i],q);
1072 if ((blur_traits & BlendPixelTrait) == 0)
1077 for (v=0; v < (ssize_t) MagickMax(height,1); v++)
1079 for (u=0; u < (ssize_t) MagickMax(width,1); u++)
1081 r=p+GetPixelChannels(image)*MagickMax(width,1)*(size_t)
1082 (mid.y-v)+GetPixelChannels(image)*(size_t) (mid.x-u);
1083 pixel+=weights[id][n]*(double) r[i];
1084 gamma+=weights[id][n];
1088 SetPixelChannel(blur_image,channel,ClampToQuantum(
1089 PerceptibleReciprocal(gamma)*pixel),q);
1095 for (v=0; v < (ssize_t) MagickMax(height,1); v++)
1097 for (u=0; u < (ssize_t) MagickMax(width,1); u++)
1103 r=p+GetPixelChannels(image)*MagickMax(width,1)*(size_t) (mid.y-v)+
1104 GetPixelChannels(image)*(size_t) (mid.x-u);
1105 alpha=(double) (QuantumScale*(
double) GetPixelAlpha(image,p));
1106 beta=(double) (QuantumScale*(
double) GetPixelAlpha(image,r));
1107 pixel+=weights[id][n]*(double) r[i];
1108 gamma+=weights[id][n]*alpha*beta;
1112 SetPixelChannel(blur_image,channel,ClampToQuantum(
1113 PerceptibleReciprocal(gamma)*pixel),q);
1115 q+=(ptrdiff_t) GetPixelChannels(blur_image);
1117 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
1119 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1124#if defined(MAGICKCORE_OPENMP_SUPPORT)
1128 proceed=SetImageProgress(image,BilateralBlurImageTag,progress,
1130 if (proceed == MagickFalse)
1134 blur_image->type=image->type;
1135 blur_view=DestroyCacheView(blur_view);
1136 image_view=DestroyCacheView(image_view);
1137 weights=DestroyBilateralTLS(number_threads,weights);
1138 if (status == MagickFalse)
1139 blur_image=DestroyImage(blur_image);
1170MagickExport
Image *ConvolveImage(
const Image *image,
1176 convolve_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
1178 return(convolve_image);
1211static void Hull(
const Image *image,
const ssize_t x_offset,
1212 const ssize_t y_offset,
const size_t columns,
const size_t rows,
1213 const int polarity,Quantum *magick_restrict f,Quantum *magick_restrict g)
1224 assert(image != (
const Image *) NULL);
1225 assert(image->signature == MagickCoreSignature);
1226 assert(f != (Quantum *) NULL);
1227 assert(g != (Quantum *) NULL);
1228 assert(columns <= (MAGICK_SSIZE_MAX-2));
1229 if (IsEventLogging() != MagickFalse)
1230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1231 p=f+(ptrdiff_t) (columns+2);
1232 q=g+(ptrdiff_t) (columns+2);
1233 r=p+(ptrdiff_t) (y_offset*((ssize_t) columns+2)+x_offset);
1234#if defined(MAGICKCORE_OPENMP_SUPPORT)
1235 #pragma omp parallel for schedule(static) \
1236 magick_number_threads(image,image,rows,2)
1238 for (y=0; y < (ssize_t) rows; y++)
1247 i=(2*y+1)+y*(ssize_t) columns;
1249 for (x=0; x < (ssize_t) columns; x++)
1251 v=(MagickRealType) p[i];
1252 if ((MagickRealType) r[i] >= (v+(
double) ScaleCharToQuantum(2)))
1253 v+=(double) ScaleCharToQuantum(1);
1258 for (x=0; x < (ssize_t) columns; x++)
1260 v=(MagickRealType) p[i];
1261 if ((MagickRealType) r[i] <= (v-(
double) ScaleCharToQuantum(2)))
1262 v-=(double) ScaleCharToQuantum(1);
1267 p=f+(ptrdiff_t) (columns+2);
1268 q=g+(ptrdiff_t) (columns+2);
1269 r=q+(ptrdiff_t) (y_offset*((ssize_t) columns+2)+x_offset);
1270 s=q-(ptrdiff_t) (y_offset*((ssize_t) columns+2)+x_offset);
1271#if defined(MAGICKCORE_OPENMP_SUPPORT)
1272 #pragma omp parallel for schedule(static) \
1273 magick_number_threads(image,image,rows,2)
1275 for (y=0; y < (ssize_t) rows; y++)
1284 i=(2*y+1)+y*(ssize_t) columns;
1286 for (x=0; x < (ssize_t) columns; x++)
1288 v=(MagickRealType) q[i];
1289 if (((MagickRealType) s[i] >= (v+(
double) ScaleCharToQuantum(2))) &&
1290 ((MagickRealType) r[i] > v))
1291 v+=(double) ScaleCharToQuantum(1);
1296 for (x=0; x < (ssize_t) columns; x++)
1298 v=(MagickRealType) q[i];
1299 if (((MagickRealType) s[i] <= (v-(
double) ScaleCharToQuantum(2))) &&
1300 ((MagickRealType) r[i] < v))
1301 v-=(double) ScaleCharToQuantum(1);
1310#define DespeckleImageTag "Despeckle/Image"
1327 *magick_restrict buffer,
1328 *magick_restrict pixels;
1336 static const ssize_t
1337 X[4] = {0, 1, 1,-1},
1338 Y[4] = {1, 0, 1, 1};
1343 assert(image != (
const Image *) NULL);
1344 assert(image->signature == MagickCoreSignature);
1346 assert(exception->signature == MagickCoreSignature);
1347 if (IsEventLogging() != MagickFalse)
1348 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1349#if defined(MAGICKCORE_OPENCL_SUPPORT)
1350 despeckle_image=AccelerateDespeckleImage(image,exception);
1351 if (despeckle_image != (
Image *) NULL)
1352 return(despeckle_image);
1354 despeckle_image=CloneImage(image,0,0,MagickTrue,exception);
1355 if (despeckle_image == (
Image *) NULL)
1356 return((
Image *) NULL);
1357 status=SetImageStorageClass(despeckle_image,DirectClass,exception);
1358 if (status == MagickFalse)
1360 despeckle_image=DestroyImage(despeckle_image);
1361 return((
Image *) NULL);
1366 length=(size_t) ((image->columns+2)*(image->rows+2));
1367 pixel_info=AcquireVirtualMemory(length,
sizeof(*pixels));
1368 buffer_info=AcquireVirtualMemory(length,
sizeof(*buffer));
1373 buffer_info=RelinquishVirtualMemory(buffer_info);
1375 pixel_info=RelinquishVirtualMemory(pixel_info);
1376 despeckle_image=DestroyImage(despeckle_image);
1377 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
1379 pixels=(Quantum *) GetVirtualMemoryBlob(pixel_info);
1380 buffer=(Quantum *) GetVirtualMemoryBlob(buffer_info);
1385 image_view=AcquireVirtualCacheView(image,exception);
1386 despeckle_view=AcquireAuthenticCacheView(despeckle_image,exception);
1387 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1404 if (status == MagickFalse)
1406 channel=GetPixelChannelChannel(image,i);
1407 traits=GetPixelChannelTraits(image,channel);
1408 despeckle_traits=GetPixelChannelTraits(despeckle_image,channel);
1409 if ((traits == UndefinedPixelTrait) ||
1410 (despeckle_traits == UndefinedPixelTrait))
1412 if ((despeckle_traits & CopyPixelTrait) != 0)
1414 (void) memset(pixels,0,length*
sizeof(*pixels));
1415 j=(ssize_t) image->columns+2;
1416 for (y=0; y < (ssize_t) image->rows; y++)
1421 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1422 if (p == (
const Quantum *) NULL)
1428 for (x=0; x < (ssize_t) image->columns; x++)
1431 p+=(ptrdiff_t) GetPixelChannels(image);
1435 (void) memset(buffer,0,length*
sizeof(*buffer));
1436 for (k=0; k < 4; k++)
1438 Hull(image,X[k],Y[k],image->columns,image->rows,1,pixels,buffer);
1439 Hull(image,-X[k],-Y[k],image->columns,image->rows,1,pixels,buffer);
1440 Hull(image,-X[k],-Y[k],image->columns,image->rows,-1,pixels,buffer);
1441 Hull(image,X[k],Y[k],image->columns,image->rows,-1,pixels,buffer);
1443 j=(ssize_t) image->columns+2;
1444 for (y=0; y < (ssize_t) image->rows; y++)
1452 q=GetCacheViewAuthenticPixels(despeckle_view,0,y,despeckle_image->columns,
1454 if (q == (Quantum *) NULL)
1460 for (x=0; x < (ssize_t) image->columns; x++)
1462 SetPixelChannel(despeckle_image,channel,pixels[j++],q);
1463 q+=(ptrdiff_t) GetPixelChannels(despeckle_image);
1465 sync=SyncCacheViewAuthenticPixels(despeckle_view,exception);
1466 if (sync == MagickFalse)
1470 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1475 proceed=SetImageProgress(image,DespeckleImageTag,(MagickOffsetType) i,
1476 GetPixelChannels(image));
1477 if (proceed == MagickFalse)
1481 despeckle_view=DestroyCacheView(despeckle_view);
1482 image_view=DestroyCacheView(image_view);
1483 buffer_info=RelinquishVirtualMemory(buffer_info);
1484 pixel_info=RelinquishVirtualMemory(pixel_info);
1485 despeckle_image->type=image->type;
1486 if (status == MagickFalse)
1487 despeckle_image=DestroyImage(despeckle_image);
1488 return(despeckle_image);
1520MagickExport
Image *EdgeImage(
const Image *image,
const double radius,
1535 assert(image != (
const Image *) NULL);
1536 assert(image->signature == MagickCoreSignature);
1538 assert(exception->signature == MagickCoreSignature);
1539 if (IsEventLogging() != MagickFalse)
1540 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1541 width=GetOptimalKernelWidth1D(radius,0.5);
1542 kernel_info=AcquireKernelInfo((
const char *) NULL,exception);
1544 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
1545 (void) memset(kernel_info,0,
sizeof(*kernel_info));
1546 kernel_info->width=width;
1547 kernel_info->height=width;
1548 kernel_info->x=(ssize_t) (kernel_info->width-1)/2;
1549 kernel_info->y=(ssize_t) (kernel_info->height-1)/2;
1550 kernel_info->signature=MagickCoreSignature;
1551 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
1552 AcquireAlignedMemory(kernel_info->width,kernel_info->height*
1553 sizeof(*kernel_info->values)));
1554 if (kernel_info->values == (MagickRealType *) NULL)
1556 kernel_info=DestroyKernelInfo(kernel_info);
1557 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
1559 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
1560 kernel_info->values[i]=(-1.0);
1561 kernel_info->values[i/2]=(double) kernel_info->width*kernel_info->height-1.0;
1562 edge_image=ConvolveImage(image,kernel_info,exception);
1563 kernel_info=DestroyKernelInfo(kernel_info);
1600MagickExport
Image *EmbossImage(
const Image *image,
const double radius,
1625 assert(image != (
const Image *) NULL);
1626 assert(image->signature == MagickCoreSignature);
1628 assert(exception->signature == MagickCoreSignature);
1629 if (IsEventLogging() != MagickFalse)
1630 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1631 width=GetOptimalKernelWidth1D(radius,sigma);
1632 kernel_info=AcquireKernelInfo((
const char *) NULL,exception);
1634 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
1635 kernel_info->width=width;
1636 kernel_info->height=width;
1637 kernel_info->x=(ssize_t) (width-1)/2;
1638 kernel_info->y=(ssize_t) (width-1)/2;
1639 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
1640 AcquireAlignedMemory(kernel_info->width,kernel_info->width*
1641 sizeof(*kernel_info->values)));
1642 if (kernel_info->values == (MagickRealType *) NULL)
1644 kernel_info=DestroyKernelInfo(kernel_info);
1645 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
1647 j=(ssize_t) (kernel_info->width-1)/2;
1650 for (v=(-j); v <= j; v++)
1652 for (u=(-j); u <= j; u++)
1654 kernel_info->values[i]=(MagickRealType) (((u < 0) || (v < 0) ? -8.0 :
1655 8.0)*exp(-((
double) u*u+v*v)/(2.0*MagickSigma*MagickSigma))/
1656 (2.0*MagickPI*MagickSigma*MagickSigma));
1658 kernel_info->values[i]=0.0;
1664 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
1665 normalize+=kernel_info->values[i];
1666 gamma=PerceptibleReciprocal(normalize);
1667 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
1668 kernel_info->values[i]*=gamma;
1669 emboss_image=ConvolveImage(image,kernel_info,exception);
1670 kernel_info=DestroyKernelInfo(kernel_info);
1671 if (emboss_image != (
Image *) NULL)
1672 (void) EqualizeImage(emboss_image,exception);
1673 return(emboss_image);
1709MagickExport
Image *GaussianBlurImage(
const Image *image,
const double radius,
1713 geometry[MagickPathExtent];
1721 assert(image != (
const Image *) NULL);
1722 assert(image->signature == MagickCoreSignature);
1724 assert(exception->signature == MagickCoreSignature);
1725 if (IsEventLogging() != MagickFalse)
1726 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1727 (void) FormatLocaleString(geometry,MagickPathExtent,
"gaussian:%.20gx%.20g",
1729 kernel_info=AcquireKernelInfo(geometry,exception);
1731 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
1732 blur_image=ConvolveImage(image,kernel_info,exception);
1733 kernel_info=DestroyKernelInfo(kernel_info);
1767static inline MagickRealType GetMeanLuma(
const Image *magick_restrict image,
1768 const double *magick_restrict pixel)
1770 return(0.212656*pixel[image->channel_map[RedPixelChannel].offset]+
1771 0.715158*pixel[image->channel_map[GreenPixelChannel].offset]+
1772 0.072186*pixel[image->channel_map[BluePixelChannel].offset]);
1775MagickExport
Image *KuwaharaImage(
const Image *image,
const double radius,
1778#define KuwaharaImageTag "Kuwahara/Image"
1803 assert(image != (
Image *) NULL);
1804 assert(image->signature == MagickCoreSignature);
1806 assert(exception->signature == MagickCoreSignature);
1807 if (IsEventLogging() != MagickFalse)
1808 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1809 width=(size_t) radius+1;
1810 gaussian_image=BlurImage(image,radius,sigma,exception);
1811 if (gaussian_image == (
Image *) NULL)
1812 return((
Image *) NULL);
1813 kuwahara_image=CloneImage(image,0,0,MagickTrue,exception);
1814 if (kuwahara_image == (
Image *) NULL)
1816 gaussian_image=DestroyImage(gaussian_image);
1817 return((
Image *) NULL);
1819 if (SetImageStorageClass(kuwahara_image,DirectClass,exception) == MagickFalse)
1821 gaussian_image=DestroyImage(gaussian_image);
1822 kuwahara_image=DestroyImage(kuwahara_image);
1823 return((
Image *) NULL);
1830 image_view=AcquireVirtualCacheView(gaussian_image,exception);
1831 kuwahara_view=AcquireAuthenticCacheView(kuwahara_image,exception);
1832#if defined(MAGICKCORE_OPENMP_SUPPORT)
1833 #pragma omp parallel for schedule(static) shared(progress,status) \
1834 magick_number_threads(image,kuwahara_image,gaussian_image->rows,1)
1836 for (y=0; y < (ssize_t) gaussian_image->rows; y++)
1844 if (status == MagickFalse)
1846 q=QueueCacheViewAuthenticPixels(kuwahara_view,0,y,kuwahara_image->columns,1,
1848 if (q == (Quantum *) NULL)
1853 for (x=0; x < (ssize_t) gaussian_image->columns; x++)
1868 min_variance=MagickMaximumValue;
1869 SetGeometry(gaussian_image,&target);
1870 quadrant.width=width;
1871 quadrant.height=width;
1872 for (i=0; i < 4; i++)
1878 mean[MaxPixelChannels],
1893 quadrant.x=x-(ssize_t) (width-1);
1894 quadrant.y=y-(ssize_t) (width-1);
1899 quadrant.y=y-(ssize_t) (width-1);
1904 quadrant.x=x-(ssize_t) (width-1);
1911 p=GetCacheViewVirtualPixels(image_view,quadrant.x,quadrant.y,
1912 quadrant.width,quadrant.height,exception);
1913 if (p == (
const Quantum *) NULL)
1915 for (j=0; j < (ssize_t) GetPixelChannels(gaussian_image); j++)
1918 for (n=0; n < (ssize_t) (width*width); n++)
1920 for (j=0; j < (ssize_t) GetPixelChannels(gaussian_image); j++)
1921 mean[j]+=(
double) k[j];
1922 k+=(ptrdiff_t) GetPixelChannels(gaussian_image);
1924 for (j=0; j < (ssize_t) GetPixelChannels(gaussian_image); j++)
1925 mean[j]/=(
double) (width*width);
1928 for (n=0; n < (ssize_t) (width*width); n++)
1933 luma=GetPixelLuma(gaussian_image,k);
1934 variance+=(luma-GetMeanLuma(gaussian_image,mean))*
1935 (luma-GetMeanLuma(gaussian_image,mean));
1936 k+=(ptrdiff_t) GetPixelChannels(gaussian_image);
1938 if (variance < min_variance)
1940 min_variance=variance;
1949 status=InterpolatePixelChannels(gaussian_image,image_view,kuwahara_image,
1950 UndefinedInterpolatePixel,(
double) target.x+target.width/2.0,(
double)
1951 target.y+target.height/2.0,q,exception);
1952 if (status == MagickFalse)
1954 q+=(ptrdiff_t) GetPixelChannels(kuwahara_image);
1956 if (SyncCacheViewAuthenticPixels(kuwahara_view,exception) == MagickFalse)
1958 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1963#if defined(MAGICKCORE_OPENMP_SUPPORT)
1967 proceed=SetImageProgress(image,KuwaharaImageTag,progress,image->rows);
1968 if (proceed == MagickFalse)
1972 kuwahara_view=DestroyCacheView(kuwahara_view);
1973 image_view=DestroyCacheView(image_view);
1974 gaussian_image=DestroyImage(gaussian_image);
1975 if (status == MagickFalse)
1976 kuwahara_image=DestroyImage(kuwahara_image);
1977 return(kuwahara_image);
2013MagickExport
Image *LocalContrastImage(
const Image *image,
const double radius,
2016#define LocalContrastImageTag "LocalContrast/Image"
2046 assert(image != (
const Image *) NULL);
2047 assert(image->signature == MagickCoreSignature);
2049 assert(exception->signature == MagickCoreSignature);
2050 if (IsEventLogging() != MagickFalse)
2051 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2052#if defined(MAGICKCORE_OPENCL_SUPPORT)
2053 contrast_image=AccelerateLocalContrastImage(image,radius,strength,exception);
2054 if (contrast_image != (
Image *) NULL)
2055 return(contrast_image);
2057 contrast_image=CloneImage(image,0,0,MagickTrue,exception);
2058 if (contrast_image == (
Image *) NULL)
2059 return((
Image *) NULL);
2060 if (SetImageStorageClass(contrast_image,DirectClass,exception) == MagickFalse)
2062 contrast_image=DestroyImage(contrast_image);
2063 return((
Image *) NULL);
2065 image_view=AcquireVirtualCacheView(image,exception);
2066 contrast_view=AcquireAuthenticCacheView(contrast_image,exception);
2067 scanLineSize=(ssize_t) MagickMax(image->columns,image->rows);
2068 width=(ssize_t) scanLineSize*0.002*fabs(radius);
2069 scanLineSize+=(2*width);
2070 scanline_info=AcquireVirtualMemory(GetOpenMPMaximumThreads()*
2071 (
size_t) scanLineSize,
sizeof(*scanline));
2074 contrast_view=DestroyCacheView(contrast_view);
2075 image_view=DestroyCacheView(image_view);
2076 contrast_image=DestroyImage(contrast_image);
2077 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
2079 scanline=(
float *) GetVirtualMemoryBlob(scanline_info);
2083 interImage_info=AcquireVirtualMemory(image->rows*(image->columns+(
size_t)
2084 (2*width)),
sizeof(*interImage));
2087 scanline_info=RelinquishVirtualMemory(scanline_info);
2088 contrast_view=DestroyCacheView(contrast_view);
2089 image_view=DestroyCacheView(image_view);
2090 contrast_image=DestroyImage(contrast_image);
2091 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
2093 interImage=(
float *) GetVirtualMemoryBlob(interImage_info);
2094 totalWeight=(float) ((width+1)*(width+1));
2103#if defined(MAGICKCORE_OPENMP_SUPPORT)
2104#pragma omp parallel for schedule(static) \
2105 magick_number_threads(image,image,image->columns,1)
2107 for (x=0; x < (ssize_t) image->columns; x++)
2110 id = GetOpenMPThreadId();
2126 if (status == MagickFalse)
2129 pixels+=
id*scanLineSize;
2131 p=GetCacheViewVirtualPixels(image_view,x,-(ssize_t) width,1,
2132 image->rows+(
size_t) (2*width),exception);
2133 if (p == (
const Quantum *) NULL)
2138 for (y=0; y < (ssize_t) image->rows+(2*width); y++)
2140 *pix++=(float)GetPixelLuma(image,p);
2141 p+=(ptrdiff_t) image->number_channels;
2143 out=interImage+x+width;
2144 for (y=0; y < (ssize_t) image->rows; y++)
2153 for (i=0; i < width; i++)
2155 sum+=weight*((double) *pix++);
2158 for (i=width+1; i < (2*width); i++)
2160 sum+=weight*((double) *pix++);
2164 *out=sum/totalWeight;
2166 if ((x <= width) && (x != 0))
2168 if ((x > (ssize_t) image->columns-width-2) &&
2169 (x != (ssize_t) image->columns-1))
2170 *(out+((image->columns-(size_t) x-1)*2))=*out;
2171 out+=image->columns+(size_t) (width*2);
2182#if defined(MAGICKCORE_OPENMP_SUPPORT)
2183#pragma omp parallel for schedule(static) \
2184 magick_number_threads(image,image,image->rows,1)
2186 for (y=0; y < (ssize_t) image->rows; y++)
2189 id = GetOpenMPThreadId();
2205 if (status == MagickFalse)
2208 pixels+=
id*scanLineSize;
2209 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2210 q=GetCacheViewAuthenticPixels(contrast_view,0,y,image->columns,1,
2212 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
2217 memcpy(pixels,interImage+((
size_t) y*(image->columns+(
size_t) (2*width))),
2218 (image->columns+(
size_t) (2*width))*
sizeof(
float));
2219 for (x=0; x < (ssize_t) image->columns; x++)
2233 for (i=0; i < width; i++)
2235 sum+=weight*((double) *pix++);
2238 for (i=width+1; i < (2*width); i++)
2240 sum+=weight*((double) *pix++);
2246 srcVal=(float) GetPixelLuma(image,p);
2247 mult=(srcVal-(sum/totalWeight))*(strength/100.0);
2248 mult=(srcVal+mult)/srcVal;
2249 traits=GetPixelChannelTraits(image,RedPixelChannel);
2250 if ((traits & UpdatePixelTrait) != 0)
2251 SetPixelRed(contrast_image,ClampToQuantum((MagickRealType)
2252 GetPixelRed(image,p)*mult),q);
2253 traits=GetPixelChannelTraits(image,GreenPixelChannel);
2254 if ((traits & UpdatePixelTrait) != 0)
2255 SetPixelGreen(contrast_image,ClampToQuantum((MagickRealType)
2256 GetPixelGreen(image,p)*mult),q);
2257 traits=GetPixelChannelTraits(image,BluePixelChannel);
2258 if ((traits & UpdatePixelTrait) != 0)
2259 SetPixelBlue(contrast_image,ClampToQuantum((MagickRealType)
2260 GetPixelBlue(image,p)*mult),q);
2261 p+=(ptrdiff_t) image->number_channels;
2262 q+=(ptrdiff_t) contrast_image->number_channels;
2264 if (SyncCacheViewAuthenticPixels(contrast_view,exception) == MagickFalse)
2268 scanline_info=RelinquishVirtualMemory(scanline_info);
2269 interImage_info=RelinquishVirtualMemory(interImage_info);
2270 contrast_view=DestroyCacheView(contrast_view);
2271 image_view=DestroyCacheView(image_view);
2272 if (status == MagickFalse)
2273 contrast_image=DestroyImage(contrast_image);
2274 return(contrast_image);
2316static MagickRealType *GetMotionBlurKernel(
const size_t width,
2329 if (IsEventLogging() != MagickFalse)
2330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2331 kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((
size_t)
2332 width,
sizeof(*kernel)));
2333 if (kernel == (MagickRealType *) NULL)
2336 for (i=0; i < (ssize_t) width; i++)
2338 kernel[i]=(MagickRealType) (exp((-((
double) i*i)/(
double) (2.0*MagickSigma*
2339 MagickSigma)))/(MagickSQ2PI*MagickSigma));
2340 normalize+=kernel[i];
2342 for (i=0; i < (ssize_t) width; i++)
2343 kernel[i]/=normalize;
2347MagickExport
Image *MotionBlurImage(
const Image *image,
const double radius,
2348 const double sigma,
const double angle,
ExceptionInfo *exception)
2350#define BlurImageTag "Blur/Image"
2382 assert(image != (
Image *) NULL);
2383 assert(image->signature == MagickCoreSignature);
2385 assert(exception->signature == MagickCoreSignature);
2386 if (IsEventLogging() != MagickFalse)
2387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2388 width=GetOptimalKernelWidth1D(radius,sigma);
2389 kernel=GetMotionBlurKernel(width,sigma);
2390 if (kernel == (MagickRealType *) NULL)
2391 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
2392 offset=(
OffsetInfo *) AcquireQuantumMemory(width,
sizeof(*offset));
2395 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2396 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
2398 point.x=(double) width*sin(DegreesToRadians(angle));
2399 point.y=(double) width*cos(DegreesToRadians(angle));
2400 for (w=0; w < (ssize_t) width; w++)
2402 offset[w].x=CastDoubleToLong(ceil((
double) (w*point.y)/
2403 hypot(point.x,point.y)-0.5));
2404 offset[w].y=CastDoubleToLong(ceil((
double) (w*point.x)/
2405 hypot(point.x,point.y)-0.5));
2410#if defined(MAGICKCORE_OPENCL_SUPPORT)
2411 blur_image=AccelerateMotionBlurImage(image,kernel,width,offset,exception);
2412 if (blur_image != (
Image *) NULL)
2414 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2415 offset=(
OffsetInfo *) RelinquishMagickMemory(offset);
2419 blur_image=CloneImage(image,0,0,MagickTrue,exception);
2420 if (blur_image == (
Image *) NULL)
2422 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2423 offset=(
OffsetInfo *) RelinquishMagickMemory(offset);
2424 return((
Image *) NULL);
2426 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
2428 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2429 offset=(
OffsetInfo *) RelinquishMagickMemory(offset);
2430 blur_image=DestroyImage(blur_image);
2431 return((
Image *) NULL);
2435 image_view=AcquireVirtualCacheView(image,exception);
2436 motion_view=AcquireVirtualCacheView(image,exception);
2437 blur_view=AcquireAuthenticCacheView(blur_image,exception);
2438#if defined(MAGICKCORE_OPENMP_SUPPORT)
2439 #pragma omp parallel for schedule(static) shared(progress,status) \
2440 magick_number_threads(image,blur_image,image->rows,1)
2442 for (y=0; y < (ssize_t) image->rows; y++)
2453 if (status == MagickFalse)
2455 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2456 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
2458 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
2463 for (x=0; x < (ssize_t) image->columns; x++)
2468 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2491 channel=GetPixelChannelChannel(image,i);
2492 traits=GetPixelChannelTraits(image,channel);
2493 blur_traits=GetPixelChannelTraits(blur_image,channel);
2494 if ((traits == UndefinedPixelTrait) ||
2495 (blur_traits == UndefinedPixelTrait))
2497 if ((blur_traits & CopyPixelTrait) != 0)
2499 SetPixelChannel(blur_image,channel,p[i],q);
2504 if ((blur_traits & BlendPixelTrait) == 0)
2506 for (j=0; j < (ssize_t) width; j++)
2508 r=GetCacheViewVirtualPixels(motion_view,x+offset[j].x,y+
2509 offset[j].y,1,1,exception);
2510 if (r == (
const Quantum *) NULL)
2515 pixel+=(*k)*(double) r[i];
2518 SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
2521 for (j=0; j < (ssize_t) width; j++)
2523 r=GetCacheViewVirtualPixels(motion_view,x+offset[j].x,y+offset[j].y,1,
2525 if (r == (
const Quantum *) NULL)
2530 alpha=QuantumScale*(double) GetPixelAlpha(image,r);
2531 pixel+=(*k)*alpha*(double) r[i];
2535 gamma=PerceptibleReciprocal(gamma);
2536 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
2538 p+=(ptrdiff_t) GetPixelChannels(image);
2539 q+=(ptrdiff_t) GetPixelChannels(blur_image);
2541 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
2543 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2548#if defined(MAGICKCORE_OPENMP_SUPPORT)
2552 proceed=SetImageProgress(image,BlurImageTag,progress,image->rows);
2553 if (proceed == MagickFalse)
2557 blur_view=DestroyCacheView(blur_view);
2558 motion_view=DestroyCacheView(motion_view);
2559 image_view=DestroyCacheView(image_view);
2560 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
2561 offset=(
OffsetInfo *) RelinquishMagickMemory(offset);
2562 if (status == MagickFalse)
2563 blur_image=DestroyImage(blur_image);
2597MagickExport
Image *PreviewImage(
const Image *image,
const PreviewType preview,
2600#define NumberTiles 9
2601#define PreviewImageTag "Preview/Image"
2602#define DefaultPreviewGeometry "204x204+10+10"
2605 factor[MagickPathExtent],
2606 label[MagickPathExtent];
2648 assert(image != (
Image *) NULL);
2649 assert(image->signature == MagickCoreSignature);
2650 if (IsEventLogging() != MagickFalse)
2651 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2655 preview_info=AcquireImageInfo();
2656 SetGeometry(image,&geometry);
2657 (void) ParseMetaGeometry(DefaultPreviewGeometry,&geometry.x,&geometry.y,
2658 &geometry.width,&geometry.height);
2659 images=NewImageList();
2661 GetQuantizeInfo(&quantize_info);
2665 for (i=0; i < NumberTiles; i++)
2667 thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
2668 if (thumbnail == (
Image *) NULL)
2670 (void) SetImageProgressMonitor(thumbnail,(MagickProgressMonitor) NULL,
2672 (void) SetImageProperty(thumbnail,
"label",DefaultTileLabel,exception);
2673 if (i == (NumberTiles/2))
2675 (void) QueryColorCompliance(
"#dfdfdf",AllCompliance,
2676 &thumbnail->matte_color,exception);
2677 AppendImageToList(&images,thumbnail);
2685 preview_image=RotateImage(thumbnail,degrees,exception);
2686 (void) FormatLocaleString(label,MagickPathExtent,
"rotate %g",degrees);
2692 preview_image=ShearImage(thumbnail,degrees,degrees,exception);
2693 (void) FormatLocaleString(label,MagickPathExtent,
"shear %gx%g",degrees,
2699 x=((i+1)*(ssize_t) thumbnail->columns)/NumberTiles;
2700 y=((i+1)*(ssize_t) thumbnail->rows)/NumberTiles;
2701 preview_image=RollImage(thumbnail,x,y,exception);
2702 (void) FormatLocaleString(label,MagickPathExtent,
"roll %+.20gx%+.20g",
2703 (
double) x,(
double) y);
2708 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2709 if (preview_image == (
Image *) NULL)
2711 (void) FormatLocaleString(factor,MagickPathExtent,
"100,100,%g",2.0*
2713 (void) ModulateImage(preview_image,factor,exception);
2714 (void) FormatLocaleString(label,MagickPathExtent,
"modulate %s",factor);
2717 case SaturationPreview:
2719 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2720 if (preview_image == (
Image *) NULL)
2722 (void) FormatLocaleString(factor,MagickPathExtent,
"100,%g",2.0*
2724 (void) ModulateImage(preview_image,factor,exception);
2725 (void) FormatLocaleString(label,MagickPathExtent,
"modulate %s",factor);
2728 case BrightnessPreview:
2730 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2731 if (preview_image == (
Image *) NULL)
2733 (void) FormatLocaleString(factor,MagickPathExtent,
"%g",2.0*percentage);
2734 (void) ModulateImage(preview_image,factor,exception);
2735 (void) FormatLocaleString(label,MagickPathExtent,
"modulate %s",factor);
2741 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2742 if (preview_image == (
Image *) NULL)
2745 (void) GammaImage(preview_image,gamma,exception);
2746 (void) FormatLocaleString(label,MagickPathExtent,
"gamma %g",gamma);
2751 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2752 if (preview_image != (
Image *) NULL)
2753 for (x=0; x < i; x++)
2754 (
void) ContrastImage(preview_image,MagickTrue,exception);
2755 (void) FormatLocaleString(label,MagickPathExtent,
"contrast (%.20g)",
2761 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2762 if (preview_image == (
Image *) NULL)
2764 for (x=0; x < i; x++)
2765 (
void) ContrastImage(preview_image,MagickFalse,exception);
2766 (void) FormatLocaleString(label,MagickPathExtent,
"+contrast (%.20g)",
2770 case GrayscalePreview:
2772 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2773 if (preview_image == (
Image *) NULL)
2776 quantize_info.number_colors=colors;
2777 quantize_info.colorspace=GRAYColorspace;
2778 (void) QuantizeImage(&quantize_info,preview_image,exception);
2779 (void) FormatLocaleString(label,MagickPathExtent,
2780 "-colorspace gray -colors %.20g",(
double) colors);
2783 case QuantizePreview:
2785 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2786 if (preview_image == (
Image *) NULL)
2789 quantize_info.number_colors=colors;
2790 (void) QuantizeImage(&quantize_info,preview_image,exception);
2791 (void) FormatLocaleString(label,MagickPathExtent,
"colors %.20g",
2795 case DespecklePreview:
2797 for (x=0; x < (i-1); x++)
2799 preview_image=DespeckleImage(thumbnail,exception);
2800 if (preview_image == (
Image *) NULL)
2802 thumbnail=DestroyImage(thumbnail);
2803 thumbnail=preview_image;
2805 preview_image=DespeckleImage(thumbnail,exception);
2806 if (preview_image == (
Image *) NULL)
2808 (void) FormatLocaleString(label,MagickPathExtent,
"despeckle (%.20g)",
2812 case ReduceNoisePreview:
2814 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(
size_t)
2815 radius,(
size_t) radius,exception);
2816 (void) FormatLocaleString(label,MagickPathExtent,
"noise %g",radius);
2819 case AddNoisePreview:
2825 (void) CopyMagickString(factor,
"uniform",MagickPathExtent);
2830 (void) CopyMagickString(factor,
"gaussian",MagickPathExtent);
2835 (void) CopyMagickString(factor,
"multiplicative",MagickPathExtent);
2840 (void) CopyMagickString(factor,
"impulse",MagickPathExtent);
2845 (void) CopyMagickString(factor,
"laplacian",MagickPathExtent);
2850 (void) CopyMagickString(factor,
"Poisson",MagickPathExtent);
2855 (void) CopyMagickString(thumbnail->magick,
"NULL",MagickPathExtent);
2859 preview_image=StatisticImage(thumbnail,NonpeakStatistic,(
size_t) i,
2860 (
size_t) i,exception);
2861 (void) FormatLocaleString(label,MagickPathExtent,
"+noise %s",factor);
2864 case SharpenPreview:
2866 preview_image=SharpenImage(thumbnail,radius,sigma,exception);
2867 (void) FormatLocaleString(label,MagickPathExtent,
"sharpen %gx%g",
2873 preview_image=BlurImage(thumbnail,radius,sigma,exception);
2874 (void) FormatLocaleString(label,MagickPathExtent,
"blur %gx%g",radius,
2878 case ThresholdPreview:
2880 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2881 if (preview_image == (
Image *) NULL)
2883 (void) BilevelImage(thumbnail,(
double) (percentage*((
double)
2884 QuantumRange+1.0))/100.0,exception);
2885 (void) FormatLocaleString(label,MagickPathExtent,
"threshold %g",
2886 (
double) (percentage*((
double) QuantumRange+1.0))/100.0);
2889 case EdgeDetectPreview:
2891 preview_image=EdgeImage(thumbnail,radius,exception);
2892 (void) FormatLocaleString(label,MagickPathExtent,
"edge %g",radius);
2897 preview_image=SpreadImage(thumbnail,image->interpolate,radius,
2899 (void) FormatLocaleString(label,MagickPathExtent,
"spread %g",
2903 case SolarizePreview:
2905 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2906 if (preview_image == (
Image *) NULL)
2908 (void) SolarizeImage(preview_image,(
double) QuantumRange*percentage/
2910 (void) FormatLocaleString(label,MagickPathExtent,
"solarize %g",
2911 ((
double) QuantumRange*percentage)/100.0);
2917 preview_image=ShadeImage(thumbnail,MagickTrue,degrees,degrees,
2919 (void) FormatLocaleString(label,MagickPathExtent,
"shade %gx%g",degrees,
2928 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2929 if (preview_image == (
Image *) NULL)
2931 raise.width=(size_t) (2*i+2);
2932 raise.height=(size_t) (2*i+2);
2935 (void) RaiseImage(preview_image,&raise,MagickTrue,exception);
2936 (void) FormatLocaleString(label,MagickPathExtent,
2937 "raise %.20gx%.20g%+.20g%+.20g",(
double) raise.width,(
double)
2938 raise.height,(
double) raise.x,(
double) raise.y);
2941 case SegmentPreview:
2943 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
2944 if (preview_image == (
Image *) NULL)
2947 (void) SegmentImage(preview_image,sRGBColorspace,MagickFalse,threshold,
2948 threshold,exception);
2949 (void) FormatLocaleString(label,MagickPathExtent,
"segment %gx%g",
2950 threshold,threshold);
2955 preview_image=SwirlImage(thumbnail,degrees,image->interpolate,
2957 (void) FormatLocaleString(label,MagickPathExtent,
"swirl %g",degrees);
2961 case ImplodePreview:
2964 preview_image=ImplodeImage(thumbnail,degrees,image->interpolate,
2966 (void) FormatLocaleString(label,MagickPathExtent,
"implode %g",degrees);
2972 preview_image=WaveImage(thumbnail,0.5*degrees,2.0*degrees,
2973 image->interpolate,exception);
2974 (void) FormatLocaleString(label,MagickPathExtent,
"wave %gx%g",0.5*
2975 degrees,2.0*degrees);
2978 case OilPaintPreview:
2980 preview_image=OilPaintImage(thumbnail,(
double) radius,(
double) sigma,
2982 (void) FormatLocaleString(label,MagickPathExtent,
"charcoal %gx%g",
2986 case CharcoalDrawingPreview:
2988 preview_image=CharcoalImage(thumbnail,(
double) radius,(
double) sigma,
2990 (void) FormatLocaleString(label,MagickPathExtent,
"charcoal %gx%g",
2997 filename[MagickPathExtent];
3005 preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
3006 if (preview_image == (
Image *) NULL)
3008 preview_info->quality=(size_t) percentage;
3009 (void) FormatLocaleString(factor,MagickPathExtent,
"%.20g",(
double)
3010 preview_info->quality);
3011 file=AcquireUniqueFileResource(filename);
3014 (void) FormatLocaleString(preview_image->filename,MagickPathExtent,
3015 "jpeg:%s",filename);
3016 status=WriteImage(preview_info,preview_image,exception);
3017 if (status != MagickFalse)
3022 (void) CopyMagickString(preview_info->filename,
3023 preview_image->filename,MagickPathExtent);
3024 quality_image=ReadImage(preview_info,exception);
3025 if (quality_image != (
Image *) NULL)
3027 preview_image=DestroyImage(preview_image);
3028 preview_image=quality_image;
3031 (void) RelinquishUniqueFileResource(preview_image->filename);
3032 if ((GetBlobSize(preview_image)/1024) >= 1024)
3033 (void) FormatLocaleString(label,MagickPathExtent,
"quality %s\n%gmb ",
3034 factor,(
double) ((MagickOffsetType) GetBlobSize(preview_image))/
3037 if (GetBlobSize(preview_image) >= 1024)
3038 (void) FormatLocaleString(label,MagickPathExtent,
3039 "quality %s\n%gkb ",factor,(
double) ((MagickOffsetType)
3040 GetBlobSize(preview_image))/1024.0);
3042 (
void) FormatLocaleString(label,MagickPathExtent,
3043 "quality %s\n%.20gb ",factor,(
double) ((MagickOffsetType)
3044 GetBlobSize(thumbnail)));
3048 thumbnail=DestroyImage(thumbnail);
3052 if (preview_image == (
Image *) NULL)
3054 preview_image->alpha_trait=UndefinedPixelTrait;
3055 (void) DeleteImageProperty(preview_image,
"label");
3056 (void) SetImageProperty(preview_image,
"label",label,exception);
3057 AppendImageToList(&images,preview_image);
3058 proceed=SetImageProgress(image,PreviewImageTag,(MagickOffsetType) i,
3060 if (proceed == MagickFalse)
3063 if (images == (
Image *) NULL)
3065 preview_info=DestroyImageInfo(preview_info);
3066 return((
Image *) NULL);
3071 montage_info=CloneMontageInfo(preview_info,(
MontageInfo *) NULL);
3072 (void) CopyMagickString(montage_info->filename,image->filename,
3074 montage_info->shadow=MagickTrue;
3075 (void) CloneString(&montage_info->tile,
"3x3");
3076 (void) CloneString(&montage_info->geometry,DefaultPreviewGeometry);
3077 (void) CloneString(&montage_info->frame,DefaultTileFrame);
3078 montage_image=MontageImages(images,montage_info,exception);
3079 montage_info=DestroyMontageInfo(montage_info);
3080 images=DestroyImageList(images);
3081 if (montage_image == (
Image *) NULL)
3082 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
3083 if (montage_image->montage != (
char *) NULL)
3088 montage_image->montage=(
char *) RelinquishMagickMemory(
3089 montage_image->montage);
3090 if (image->directory != (
char *) NULL)
3091 montage_image->directory=(
char *) RelinquishMagickMemory(
3092 montage_image->directory);
3094 preview_info=DestroyImageInfo(preview_info);
3095 return(montage_image);
3129MagickExport
Image *RotationalBlurImage(
const Image *image,
const double angle,
3166 assert(image != (
Image *) NULL);
3167 assert(image->signature == MagickCoreSignature);
3169 assert(exception->signature == MagickCoreSignature);
3170 if (IsEventLogging() != MagickFalse)
3171 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3172#if defined(MAGICKCORE_OPENCL_SUPPORT)
3173 blur_image=AccelerateRotationalBlurImage(image,angle,exception);
3174 if (blur_image != (
Image *) NULL)
3177 blur_image=CloneImage(image,0,0,MagickTrue,exception);
3178 if (blur_image == (
Image *) NULL)
3179 return((
Image *) NULL);
3180 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
3182 blur_image=DestroyImage(blur_image);
3183 return((
Image *) NULL);
3185 blur_center.x=(double) (image->columns-1)/2.0;
3186 blur_center.y=(double) (image->rows-1)/2.0;
3187 blur_radius=hypot(blur_center.x,blur_center.y);
3188 n=(size_t) fabs(4.0*DegreesToRadians(angle)*sqrt((
double) blur_radius)+2UL);
3189 theta=DegreesToRadians(angle)/(double) (n-1);
3190 cos_theta=(
double *) AcquireQuantumMemory((
size_t) n,
sizeof(*cos_theta));
3191 sin_theta=(
double *) AcquireQuantumMemory((
size_t) n,
sizeof(*sin_theta));
3192 if ((cos_theta == (
double *) NULL) || (sin_theta == (
double *) NULL))
3194 if (cos_theta != (
double *) NULL)
3195 cos_theta=(
double *) RelinquishMagickMemory(cos_theta);
3196 if (sin_theta != (
double *) NULL)
3197 sin_theta=(
double *) RelinquishMagickMemory(sin_theta);
3198 blur_image=DestroyImage(blur_image);
3199 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
3201 offset=theta*(double) (n-1)/2.0;
3202 for (w=0; w < (ssize_t) n; w++)
3204 cos_theta[w]=cos((
double) (theta*w-offset));
3205 sin_theta[w]=sin((
double) (theta*w-offset));
3212 image_view=AcquireVirtualCacheView(image,exception);
3213 radial_view=AcquireVirtualCacheView(image,exception);
3214 blur_view=AcquireAuthenticCacheView(blur_image,exception);
3215#if defined(MAGICKCORE_OPENMP_SUPPORT)
3216 #pragma omp parallel for schedule(static) shared(progress,status) \
3217 magick_number_threads(image,blur_image,image->rows,1)
3219 for (y=0; y < (ssize_t) image->rows; y++)
3230 if (status == MagickFalse)
3232 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
3233 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
3235 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3240 for (x=0; x < (ssize_t) image->columns; x++)
3254 center.x=(double) x-blur_center.x;
3255 center.y=(double) y-blur_center.y;
3256 radius=hypot((
double) center.x,center.y);
3261 step=(size_t) (blur_radius/radius);
3268 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3287 channel=GetPixelChannelChannel(image,i);
3288 traits=GetPixelChannelTraits(image,channel);
3289 blur_traits=GetPixelChannelTraits(blur_image,channel);
3290 if ((traits == UndefinedPixelTrait) ||
3291 (blur_traits == UndefinedPixelTrait))
3293 if ((blur_traits & CopyPixelTrait) != 0)
3295 SetPixelChannel(blur_image,channel,p[i],q);
3300 if ((GetPixelChannelTraits(image,AlphaPixelChannel) == UndefinedPixelTrait) ||
3301 (channel == AlphaPixelChannel))
3303 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
3305 r=GetCacheViewVirtualPixels(radial_view, (ssize_t) (blur_center.x+
3306 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
3307 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
3309 if (r == (
const Quantum *) NULL)
3314 pixel+=(double) r[i];
3317 gamma=PerceptibleReciprocal(gamma);
3318 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3321 for (j=0; j < (ssize_t) n; j+=(ssize_t) step)
3326 r=GetCacheViewVirtualPixels(radial_view, (ssize_t) (blur_center.x+
3327 center.x*cos_theta[j]-center.y*sin_theta[j]+0.5),(ssize_t)
3328 (blur_center.y+center.x*sin_theta[j]+center.y*cos_theta[j]+0.5),
3330 if (r == (
const Quantum *) NULL)
3335 alpha=QuantumScale*(double) GetPixelAlpha(image,r);
3336 pixel+=alpha*(double) r[i];
3339 gamma=PerceptibleReciprocal(gamma);
3340 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3342 p+=(ptrdiff_t) GetPixelChannels(image);
3343 q+=(ptrdiff_t) GetPixelChannels(blur_image);
3345 if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
3347 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3352#if defined(MAGICKCORE_OPENMP_SUPPORT)
3356 proceed=SetImageProgress(image,BlurImageTag,progress,image->rows);
3357 if (proceed == MagickFalse)
3361 blur_view=DestroyCacheView(blur_view);
3362 radial_view=DestroyCacheView(radial_view);
3363 image_view=DestroyCacheView(image_view);
3364 cos_theta=(
double *) RelinquishMagickMemory(cos_theta);
3365 sin_theta=(
double *) RelinquishMagickMemory(sin_theta);
3366 if (status == MagickFalse)
3367 blur_image=DestroyImage(blur_image);
3406MagickExport
Image *SelectiveBlurImage(
const Image *image,
const double radius,
3407 const double sigma,
const double threshold,
ExceptionInfo *exception)
3409#define SelectiveBlurImageTag "SelectiveBlur/Image"
3439 assert(image != (
Image *) NULL);
3440 assert(image->signature == MagickCoreSignature);
3442 assert(exception->signature == MagickCoreSignature);
3443 if (IsEventLogging() != MagickFalse)
3444 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3445 width=GetOptimalKernelWidth1D(radius,sigma);
3446 kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((
size_t)
3447 width,width*
sizeof(*kernel)));
3448 if (kernel == (MagickRealType *) NULL)
3449 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
3456 j=(ssize_t) (width-1)/2;
3458 for (v=(-j); v <= j; v++)
3463 for (u=(-j); u <= j; u++)
3464 kernel[i++]=(MagickRealType) (exp(-((
double) u*u+v*v)/(2.0*MagickSigma*
3465 MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
3468 if (image->debug != MagickFalse)
3471 format[MagickPathExtent],
3474 const MagickRealType
3481 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
3482 " SelectiveBlurImage with %.20gx%.20g kernel:",(
double) width,(
double)
3484 message=AcquireString(
"");
3486 for (v=0; v < (ssize_t) width; v++)
3489 (void) FormatLocaleString(format,MagickPathExtent,
"%.20g: ",(
double) v);
3490 (void) ConcatenateString(&message,format);
3491 for (u=0; u < (ssize_t) width; u++)
3493 (void) FormatLocaleString(format,MagickPathExtent,
"%+f ",(
double)
3495 (void) ConcatenateString(&message,format);
3497 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
"%s",message);
3499 message=DestroyString(message);
3501 blur_image=CloneImage(image,0,0,MagickTrue,exception);
3502 if (blur_image == (
Image *) NULL)
3503 return((
Image *) NULL);
3504 if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
3506 blur_image=DestroyImage(blur_image);
3507 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
3508 return((
Image *) NULL);
3510 luminance_image=CloneImage(image,0,0,MagickTrue,exception);
3511 if (luminance_image == (
Image *) NULL)
3513 blur_image=DestroyImage(blur_image);
3514 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
3515 return((
Image *) NULL);
3517 status=TransformImageColorspace(luminance_image,GRAYColorspace,exception);
3518 if (status == MagickFalse)
3520 luminance_image=DestroyImage(luminance_image);
3521 blur_image=DestroyImage(blur_image);
3522 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
3523 return((
Image *) NULL);
3530 center=(ssize_t) (GetPixelChannels(image)*(image->columns+width)*
3531 ((width-1)/2L)+GetPixelChannels(image)*((width-1)/2L));
3532 image_view=AcquireVirtualCacheView(image,exception);
3533 luminance_view=AcquireVirtualCacheView(luminance_image,exception);
3534 blur_view=AcquireAuthenticCacheView(blur_image,exception);
3535#if defined(MAGICKCORE_OPENMP_SUPPORT)
3536 #pragma omp parallel for schedule(static) shared(progress,status) \
3537 magick_number_threads(image,blur_image,image->rows,1)
3539 for (y=0; y < (ssize_t) image->rows; y++)
3557 if (status == MagickFalse)
3559 p=GetCacheViewVirtualPixels(image_view,-((ssize_t) (width-1)/2L),y-(ssize_t)
3560 ((width-1)/2L),image->columns+width,width,exception);
3561 l=GetCacheViewVirtualPixels(luminance_view,-((ssize_t) (width-1)/2L),y-
3562 (ssize_t) ((width-1)/2L),luminance_image->columns+width,width,exception);
3563 q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
3565 if ((p == (
const Quantum *) NULL) || (l == (
const Quantum *) NULL) ||
3566 (q == (Quantum *) NULL))
3571 for (x=0; x < (ssize_t) image->columns; x++)
3579 intensity=GetPixelIntensity(image,p+center);
3580 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3594 const MagickRealType
3598 *magick_restrict luminance_pixels,
3599 *magick_restrict pixels;
3607 channel=GetPixelChannelChannel(image,i);
3608 traits=GetPixelChannelTraits(image,channel);
3609 blur_traits=GetPixelChannelTraits(blur_image,channel);
3610 if ((traits == UndefinedPixelTrait) ||
3611 (blur_traits == UndefinedPixelTrait))
3613 if ((blur_traits & CopyPixelTrait) != 0)
3615 SetPixelChannel(blur_image,channel,p[center+i],q);
3623 if ((blur_traits & BlendPixelTrait) == 0)
3625 for (v=0; v < (ssize_t) width; v++)
3627 for (u=0; u < (ssize_t) width; u++)
3629 contrast=GetPixelIntensity(luminance_image,luminance_pixels)-
3631 if (fabs(contrast) < threshold)
3633 pixel+=(*k)*(double) pixels[i];
3637 pixels+=(ptrdiff_t) GetPixelChannels(image);
3638 luminance_pixels+=(ptrdiff_t) GetPixelChannels(luminance_image);
3640 pixels+=(ptrdiff_t) GetPixelChannels(image)*image->columns;
3641 luminance_pixels+=(ptrdiff_t) GetPixelChannels(luminance_image)*
3642 luminance_image->columns;
3644 if (fabs((
double) gamma) < MagickEpsilon)
3646 SetPixelChannel(blur_image,channel,p[center+i],q);
3649 gamma=PerceptibleReciprocal(gamma);
3650 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3653 for (v=0; v < (ssize_t) width; v++)
3655 for (u=0; u < (ssize_t) width; u++)
3657 contrast=GetPixelIntensity(image,pixels)-intensity;
3658 if (fabs(contrast) < threshold)
3660 alpha=QuantumScale*(double) GetPixelAlpha(image,pixels);
3661 pixel+=(*k)*alpha*(double) pixels[i];
3665 pixels+=(ptrdiff_t) GetPixelChannels(image);
3666 luminance_pixels+=(ptrdiff_t) GetPixelChannels(luminance_image);
3668 pixels+=(ptrdiff_t) GetPixelChannels(image)*image->columns;
3669 luminance_pixels+=(ptrdiff_t) GetPixelChannels(luminance_image)*
3670 luminance_image->columns;
3672 if (fabs((
double) gamma) < MagickEpsilon)
3674 SetPixelChannel(blur_image,channel,p[center+i],q);
3677 gamma=PerceptibleReciprocal(gamma);
3678 SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
3680 p+=(ptrdiff_t) GetPixelChannels(image);
3681 l+=(ptrdiff_t) GetPixelChannels(luminance_image);
3682 q+=(ptrdiff_t) GetPixelChannels(blur_image);
3684 sync=SyncCacheViewAuthenticPixels(blur_view,exception);
3685 if (sync == MagickFalse)
3687 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3692#if defined(MAGICKCORE_OPENMP_SUPPORT)
3696 proceed=SetImageProgress(image,SelectiveBlurImageTag,progress,
3698 if (proceed == MagickFalse)
3702 blur_image->type=image->type;
3703 blur_view=DestroyCacheView(blur_view);
3704 luminance_view=DestroyCacheView(luminance_view);
3705 image_view=DestroyCacheView(image_view);
3706 luminance_image=DestroyImage(luminance_image);
3707 kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
3708 if (status == MagickFalse)
3709 blur_image=DestroyImage(blur_image);
3745MagickExport
Image *ShadeImage(
const Image *image,
const MagickBooleanType gray,
3746 const double azimuth,
const double elevation,
ExceptionInfo *exception)
3748#define GetShadeIntensity(image,pixel) \
3749 ClampPixel(GetPixelIntensity((image),(pixel)))
3750#define ShadeImageTag "Shade/Image"
3775 assert(image != (
const Image *) NULL);
3776 assert(image->signature == MagickCoreSignature);
3778 assert(exception->signature == MagickCoreSignature);
3779 if (IsEventLogging() != MagickFalse)
3780 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3781 linear_image=CloneImage(image,0,0,MagickTrue,exception);
3782 shade_image=CloneImage(image,0,0,MagickTrue,exception);
3783 if ((linear_image == (
Image *) NULL) || (shade_image == (
Image *) NULL))
3785 if (linear_image != (
Image *) NULL)
3786 linear_image=DestroyImage(linear_image);
3787 if (shade_image != (
Image *) NULL)
3788 shade_image=DestroyImage(shade_image);
3789 return((
Image *) NULL);
3791 if (SetImageStorageClass(shade_image,DirectClass,exception) == MagickFalse)
3793 linear_image=DestroyImage(linear_image);
3794 shade_image=DestroyImage(shade_image);
3795 return((
Image *) NULL);
3800 light.x=(double) QuantumRange*cos(DegreesToRadians(azimuth))*
3801 cos(DegreesToRadians(elevation));
3802 light.y=(double) QuantumRange*sin(DegreesToRadians(azimuth))*
3803 cos(DegreesToRadians(elevation));
3804 light.z=(double) QuantumRange*sin(DegreesToRadians(elevation));
3810 image_view=AcquireVirtualCacheView(linear_image,exception);
3811 shade_view=AcquireAuthenticCacheView(shade_image,exception);
3812#if defined(MAGICKCORE_OPENMP_SUPPORT)
3813 #pragma omp parallel for schedule(static) shared(progress,status) \
3814 magick_number_threads(linear_image,shade_image,linear_image->rows,1)
3816 for (y=0; y < (ssize_t) linear_image->rows; y++)
3827 *magick_restrict center,
3829 *magick_restrict post,
3830 *magick_restrict pre;
3838 if (status == MagickFalse)
3840 p=GetCacheViewVirtualPixels(image_view,-1,y-1,linear_image->columns+2,3,
3842 q=QueueCacheViewAuthenticPixels(shade_view,0,y,shade_image->columns,1,
3844 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3852 normal.z=2.0*(double) QuantumRange;
3853 for (x=0; x < (ssize_t) linear_image->columns; x++)
3861 pre=p+GetPixelChannels(linear_image);
3862 center=pre+(linear_image->columns+2)*GetPixelChannels(linear_image);
3863 post=center+(linear_image->columns+2)*GetPixelChannels(linear_image);
3865 GetShadeIntensity(linear_image,pre-GetPixelChannels(linear_image))+
3866 GetShadeIntensity(linear_image,center-GetPixelChannels(linear_image))+
3867 GetShadeIntensity(linear_image,post-GetPixelChannels(linear_image))-
3868 GetShadeIntensity(linear_image,pre+GetPixelChannels(linear_image))-
3869 GetShadeIntensity(linear_image,center+GetPixelChannels(linear_image))-
3870 GetShadeIntensity(linear_image,post+GetPixelChannels(linear_image)));
3872 GetShadeIntensity(linear_image,post-GetPixelChannels(linear_image))+
3873 GetShadeIntensity(linear_image,post)+
3874 GetShadeIntensity(linear_image,post+GetPixelChannels(linear_image))-
3875 GetShadeIntensity(linear_image,pre-GetPixelChannels(linear_image))-
3876 GetShadeIntensity(linear_image,pre)-
3877 GetShadeIntensity(linear_image,pre+GetPixelChannels(linear_image)));
3878 if ((fabs(normal.x) <= MagickEpsilon) &&
3879 (fabs(normal.y) <= MagickEpsilon))
3884 distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
3885 if (distance > MagickEpsilon)
3887 normal_distance=normal.x*normal.x+normal.y*normal.y+
3889 if (normal_distance > (MagickEpsilon*MagickEpsilon))
3890 shade=distance/sqrt((
double) normal_distance);
3893 for (i=0; i < (ssize_t) GetPixelChannels(linear_image); i++)
3902 channel=GetPixelChannelChannel(linear_image,i);
3903 traits=GetPixelChannelTraits(linear_image,channel);
3904 shade_traits=GetPixelChannelTraits(shade_image,channel);
3905 if ((traits == UndefinedPixelTrait) ||
3906 (shade_traits == UndefinedPixelTrait))
3908 if ((shade_traits & CopyPixelTrait) != 0)
3910 SetPixelChannel(shade_image,channel,center[i],q);
3913 if ((traits & UpdatePixelTrait) == 0)
3915 SetPixelChannel(shade_image,channel,center[i],q);
3918 if (gray != MagickFalse)
3920 SetPixelChannel(shade_image,channel,ClampToQuantum(shade),q);
3923 SetPixelChannel(shade_image,channel,ClampToQuantum(QuantumScale*
3924 shade*(
double) center[i]),q);
3926 p+=(ptrdiff_t) GetPixelChannels(linear_image);
3927 q+=(ptrdiff_t) GetPixelChannels(shade_image);
3929 if (SyncCacheViewAuthenticPixels(shade_view,exception) == MagickFalse)
3931 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3936#if defined(MAGICKCORE_OPENMP_SUPPORT)
3940 proceed=SetImageProgress(image,ShadeImageTag,progress,image->rows);
3941 if (proceed == MagickFalse)
3945 shade_view=DestroyCacheView(shade_view);
3946 image_view=DestroyCacheView(image_view);
3947 linear_image=DestroyImage(linear_image);
3948 if (status == MagickFalse)
3949 shade_image=DestroyImage(shade_image);
3950 return(shade_image);
3991MagickExport
Image *SharpenImage(
const Image *image,
const double radius,
4015 assert(image != (
const Image *) NULL);
4016 assert(image->signature == MagickCoreSignature);
4018 assert(exception->signature == MagickCoreSignature);
4019 if (IsEventLogging() != MagickFalse)
4020 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4021 width=GetOptimalKernelWidth2D(radius,sigma);
4022 kernel_info=AcquireKernelInfo((
const char *) NULL,exception);
4024 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
4025 (void) memset(kernel_info,0,
sizeof(*kernel_info));
4026 kernel_info->width=width;
4027 kernel_info->height=width;
4028 kernel_info->x=(ssize_t) (width-1)/2;
4029 kernel_info->y=(ssize_t) (width-1)/2;
4030 kernel_info->signature=MagickCoreSignature;
4031 kernel_info->values=(MagickRealType *) MagickAssumeAligned(
4032 AcquireAlignedMemory(kernel_info->width,kernel_info->height*
4033 sizeof(*kernel_info->values)));
4034 if (kernel_info->values == (MagickRealType *) NULL)
4036 kernel_info=DestroyKernelInfo(kernel_info);
4037 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
4040 j=(ssize_t) (kernel_info->width-1)/2;
4042 for (v=(-j); v <= j; v++)
4044 for (u=(-j); u <= j; u++)
4046 kernel_info->values[i]=(MagickRealType) (-exp(-((
double) u*u+v*v)/(2.0*
4047 MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
4048 normalize+=kernel_info->values[i];
4052 kernel_info->values[i/2]=(double) ((-2.0)*normalize);
4054 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
4055 normalize+=kernel_info->values[i];
4056 gamma=PerceptibleReciprocal(normalize);
4057 for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
4058 kernel_info->values[i]*=gamma;
4059 sharp_image=ConvolveImage(image,kernel_info,exception);
4060 kernel_info=DestroyKernelInfo(kernel_info);
4061 return(sharp_image);
4095MagickExport
Image *SpreadImage(
const Image *image,
4096 const PixelInterpolateMethod method,
const double radius,
4099#define SpreadImageTag "Spread/Image"
4115 **magick_restrict random_info;
4123#if defined(MAGICKCORE_OPENMP_SUPPORT)
4131 assert(image != (
Image *) NULL);
4132 assert(image->signature == MagickCoreSignature);
4134 assert(exception->signature == MagickCoreSignature);
4135 if (IsEventLogging() != MagickFalse)
4136 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4137 spread_image=CloneImage(image,0,0,MagickTrue,exception);
4138 if (spread_image == (
Image *) NULL)
4139 return((
Image *) NULL);
4140 if (SetImageStorageClass(spread_image,DirectClass,exception) == MagickFalse)
4142 spread_image=DestroyImage(spread_image);
4143 return((
Image *) NULL);
4150 width=GetOptimalKernelWidth1D(radius,0.5);
4151 random_info=AcquireRandomInfoTLS();
4152 image_view=AcquireVirtualCacheView(image,exception);
4153 spread_view=AcquireAuthenticCacheView(spread_image,exception);
4154#if defined(MAGICKCORE_OPENMP_SUPPORT)
4155 key=GetRandomSecretKey(random_info[0]);
4156 #pragma omp parallel for schedule(static) shared(progress,status) \
4157 magick_number_threads(image,spread_image,image->rows,key == ~0UL)
4159 for (y=0; y < (ssize_t) image->rows; y++)
4162 id = GetOpenMPThreadId();
4170 if (status == MagickFalse)
4172 q=QueueCacheViewAuthenticPixels(spread_view,0,y,spread_image->columns,1,
4174 if (q == (Quantum *) NULL)
4179 for (x=0; x < (ssize_t) image->columns; x++)
4184 point.x=GetPseudoRandomValue(random_info[
id]);
4185 point.y=GetPseudoRandomValue(random_info[
id]);
4186 status=InterpolatePixelChannels(image,image_view,spread_image,method,
4187 (
double) x+width*(point.x-0.5),(
double) y+width*(point.y-0.5),q,
4189 if (status == MagickFalse)
4191 q+=(ptrdiff_t) GetPixelChannels(spread_image);
4193 if (SyncCacheViewAuthenticPixels(spread_view,exception) == MagickFalse)
4195 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4200#if defined(MAGICKCORE_OPENMP_SUPPORT)
4204 proceed=SetImageProgress(image,SpreadImageTag,progress,image->rows);
4205 if (proceed == MagickFalse)
4209 spread_view=DestroyCacheView(spread_view);
4210 image_view=DestroyCacheView(image_view);
4211 random_info=DestroyRandomInfoTLS(random_info);
4212 if (status == MagickFalse)
4213 spread_image=DestroyImage(spread_image);
4214 return(spread_image);
4256MagickExport
Image *UnsharpMaskImage(
const Image *image,
const double radius,
4257 const double sigma,
const double gain,
const double threshold,
4260#define SharpenImageTag "Sharpen/Image"
4281 assert(image != (
const Image *) NULL);
4282 assert(image->signature == MagickCoreSignature);
4284 assert(exception->signature == MagickCoreSignature);
4285 if (IsEventLogging() != MagickFalse)
4286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4295 unsharp_image=BlurImage(image,radius,sigma,exception);
4296 if (unsharp_image == (
Image *) NULL)
4297 return((
Image *) NULL);
4298 quantum_threshold=(double) QuantumRange*threshold;
4304 image_view=AcquireVirtualCacheView(image,exception);
4305 unsharp_view=AcquireAuthenticCacheView(unsharp_image,exception);
4306#if defined(MAGICKCORE_OPENMP_SUPPORT)
4307 #pragma omp parallel for schedule(static) shared(progress,status) \
4308 magick_number_threads(image,unsharp_image,image->rows,1)
4310 for (y=0; y < (ssize_t) image->rows; y++)
4321 if (status == MagickFalse)
4323 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4324 q=GetCacheViewAuthenticPixels(unsharp_view,0,y,unsharp_image->columns,1,
4326 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
4331 for (x=0; x < (ssize_t) image->columns; x++)
4336 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4348 channel=GetPixelChannelChannel(image,i);
4349 traits=GetPixelChannelTraits(image,channel);
4350 unsharp_traits=GetPixelChannelTraits(unsharp_image,channel);
4351 if ((traits == UndefinedPixelTrait) ||
4352 (unsharp_traits == UndefinedPixelTrait))
4354 if ((unsharp_traits & CopyPixelTrait) != 0)
4356 SetPixelChannel(unsharp_image,channel,p[i],q);
4359 pixel=(double) p[i]-(
double) GetPixelChannel(unsharp_image,channel,q);
4360 if (fabs(2.0*pixel) < quantum_threshold)
4361 pixel=(double) p[i];
4363 pixel=(double) p[i]+gain*pixel;
4364 SetPixelChannel(unsharp_image,channel,ClampToQuantum(pixel),q);
4366 p+=(ptrdiff_t) GetPixelChannels(image);
4367 q+=(ptrdiff_t) GetPixelChannels(unsharp_image);
4369 if (SyncCacheViewAuthenticPixels(unsharp_view,exception) == MagickFalse)
4371 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4376#if defined(MAGICKCORE_OPENMP_SUPPORT)
4380 proceed=SetImageProgress(image,SharpenImageTag,progress,image->rows);
4381 if (proceed == MagickFalse)
4385 unsharp_image->type=image->type;
4386 unsharp_view=DestroyCacheView(unsharp_view);
4387 image_view=DestroyCacheView(image_view);
4388 if (status == MagickFalse)
4389 unsharp_image=DestroyImage(unsharp_image);
4390 return(unsharp_image);