From 36826ab1d629d39df5a82c479371d516838e9e64 Mon Sep 17 00:00:00 2001 From: cristy Date: Sat, 6 Mar 2010 01:29:30 +0000 Subject: [PATCH] --- magick/effect.c | 67 +++++++++++++++++++++---------------------------- wand/mogrify.c | 12 +++++++++ 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/magick/effect.c b/magick/effect.c index 6bd0f57be..49ac136e4 100644 --- a/magick/effect.c +++ b/magick/effect.c @@ -2166,9 +2166,6 @@ MagickExport Image *FilterImageChannel(const Image *image, *filter_view, *image_view; - KernelInfo - *normal_kernel; - Image *filter_image; @@ -2233,14 +2230,7 @@ MagickExport Image *FilterImageChannel(const Image *image, } message=DestroyString(message); } - normal_kernel=CloneKernelInfo(kernel); - if (normal_kernel == (KernelInfo *) NULL) - { - filter_image=DestroyImage(filter_image); - ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); - } - ScaleKernelInfo(normal_kernel,1.0,NormalizeValue); - status=AccelerateConvolveImage(image,normal_kernel,filter_image,exception); + status=AccelerateConvolveImage(image,kernel,filter_image,exception); if (status == MagickTrue) return(filter_image); /* @@ -2277,9 +2267,9 @@ MagickExport Image *FilterImageChannel(const Image *image, if (status == MagickFalse) continue; - p=GetCacheViewVirtualPixels(image_view,-((long) normal_kernel->width/2L), - y-(long) (normal_kernel->height/2L),image->columns+normal_kernel->width, - normal_kernel->height,exception); + p=GetCacheViewVirtualPixels(image_view,-((long) kernel->width/2L), + y-(long) (kernel->height/2L),image->columns+kernel->width,kernel->height, + exception); q=GetCacheViewAuthenticPixels(filter_view,0,y,filter_image->columns,1, exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) @@ -2307,20 +2297,20 @@ MagickExport Image *FilterImageChannel(const Image *image, u; pixel=bias; - k=normal_kernel->values; + k=kernel->values; kernel_pixels=p; if (((channel & OpacityChannel) == 0) || (image->matte == MagickFalse)) { - for (v=0; v < (long) normal_kernel->width; v++) + for (v=0; v < (long) kernel->width; v++) { - for (u=0; u < (long) normal_kernel->height; u++) + for (u=0; u < (long) kernel->height; u++) { pixel.red+=(*k)*kernel_pixels[u].red; pixel.green+=(*k)*kernel_pixels[u].green; pixel.blue+=(*k)*kernel_pixels[u].blue; k++; } - kernel_pixels+=image->columns+normal_kernel->width; + kernel_pixels+=image->columns+kernel->width; } if ((channel & RedChannel) != 0) SetRedPixelComponent(q,ClampRedPixelComponent(&pixel)); @@ -2330,16 +2320,16 @@ MagickExport Image *FilterImageChannel(const Image *image, SetBluePixelComponent(q,ClampBluePixelComponent(&pixel)); if ((channel & OpacityChannel) != 0) { - k=normal_kernel->values; + k=kernel->values; kernel_pixels=p; - for (v=0; v < (long) normal_kernel->width; v++) + for (v=0; v < (long) kernel->width; v++) { - for (u=0; u < (long) normal_kernel->height; u++) + for (u=0; u < (long) kernel->height; u++) { pixel.opacity+=(*k)*kernel_pixels[u].opacity; k++; } - kernel_pixels+=image->columns+normal_kernel->width; + kernel_pixels+=image->columns+kernel->width; } SetOpacityPixelComponent(q,ClampOpacityPixelComponent(&pixel)); } @@ -2349,16 +2339,16 @@ MagickExport Image *FilterImageChannel(const Image *image, register const IndexPacket *restrict kernel_indexes; - k=normal_kernel->values; + k=kernel->values; kernel_indexes=indexes; - for (v=0; v < (long) normal_kernel->width; v++) + for (v=0; v < (long) kernel->width; v++) { - for (u=0; u < (long) normal_kernel->height; u++) + for (u=0; u < (long) kernel->height; u++) { pixel.index+=(*k)*kernel_indexes[u]; k++; } - kernel_indexes+=image->columns+normal_kernel->width; + kernel_indexes+=image->columns+kernel->width; } filter_indexes[x]=ClampToQuantum(pixel.index); } @@ -2370,9 +2360,9 @@ MagickExport Image *FilterImageChannel(const Image *image, gamma; gamma=0.0; - for (v=0; v < (long) normal_kernel->width; v++) + for (v=0; v < (long) kernel->width; v++) { - for (u=0; u < (long) normal_kernel->height; u++) + for (u=0; u < (long) kernel->height; u++) { alpha=(MagickRealType) (QuantumScale*(QuantumRange- kernel_pixels[u].opacity)); @@ -2382,7 +2372,7 @@ MagickExport Image *FilterImageChannel(const Image *image, gamma+=(*k)*alpha; k++; } - kernel_pixels+=image->columns+normal_kernel->width; + kernel_pixels+=image->columns+kernel->width; } gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); if ((channel & RedChannel) != 0) @@ -2393,16 +2383,16 @@ MagickExport Image *FilterImageChannel(const Image *image, q->blue=ClampToQuantum(gamma*GetBluePixelComponent(&pixel)); if ((channel & OpacityChannel) != 0) { - k=normal_kernel->values; + k=kernel->values; kernel_pixels=p; - for (v=0; v < (long) normal_kernel->width; v++) + for (v=0; v < (long) kernel->width; v++) { - for (u=0; u < (long) normal_kernel->height; u++) + for (u=0; u < (long) kernel->height; u++) { pixel.opacity+=(*k)*kernel_pixels[u].opacity; k++; } - kernel_pixels+=image->columns+normal_kernel->width; + kernel_pixels+=image->columns+kernel->width; } SetOpacityPixelComponent(q,ClampOpacityPixelComponent(&pixel)); } @@ -2412,20 +2402,20 @@ MagickExport Image *FilterImageChannel(const Image *image, register const IndexPacket *restrict kernel_indexes; - k=normal_kernel->values; + k=kernel->values; kernel_pixels=p; kernel_indexes=indexes; - for (v=0; v < (long) normal_kernel->width; v++) + for (v=0; v < (long) kernel->width; v++) { - for (u=0; u < (long) normal_kernel->height; u++) + for (u=0; u < (long) kernel->height; u++) { alpha=(MagickRealType) (QuantumScale*(QuantumRange- kernel_pixels[u].opacity)); pixel.index+=(*k)*alpha*kernel_indexes[u]; k++; } - kernel_pixels+=image->columns+normal_kernel->width; - kernel_indexes+=image->columns+normal_kernel->width; + kernel_pixels+=image->columns+kernel->width; + kernel_indexes+=image->columns+kernel->width; } filter_indexes[x]=ClampToQuantum(gamma* GetIndexPixelComponent(&pixel)); @@ -2453,7 +2443,6 @@ MagickExport Image *FilterImageChannel(const Image *image, filter_image->type=image->type; filter_view=DestroyCacheView(filter_view); image_view=DestroyCacheView(image_view); - normal_kernel=DestroyKernelInfo(normal_kernel); if (status == MagickFalse) filter_image=DestroyImage(filter_image); return(filter_image); diff --git a/wand/mogrify.c b/wand/mogrify.c index 87580f8cd..73c588b49 100644 --- a/wand/mogrify.c +++ b/wand/mogrify.c @@ -1223,15 +1223,27 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, } if (LocaleCompare("convolve",option+1) == 0) { + double + gamma; + Image *convolve_image; KernelInfo *kernel; + register long + j; + kernel=AcquireKernelInfo(argv[i+1]); if (kernel == (KernelInfo *) NULL) break; + gamma=0.0; + for (j=0; j < (long) (kernel->width*kernel->height); j++) + gamma+=kernel->values[j]; + gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); + for (j=0; j < (long) (kernel->width*kernel->width); j++) + kernel->values[j]*=gamma; convolve_image=FilterImageChannel(*image,channel,kernel,exception); kernel=DestroyKernelInfo(kernel); if (convolve_image == (Image *) NULL) -- 2.40.0