Bug in GetOptimalKernelWidth2D

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
ForgotOldAdd

Bug in GetOptimalKernelWidth2D

Post by ForgotOldAdd »

When calling blur or gaussian blur (via Magick++), some radii cause problems because GetOptimalKernelWidth2D might not return a valid kernel width:

GetOptimalKernelWidth2D - gem.c line 239

Code: Select all

	return((unsigned long) (MagickMax(2.0*radius+1.0,3.0)+0.5));
It can return an even number, but
fx.c line 491

Code: Select all

	if ((width % 2) == 0) ThrowImageException(OptionError,"KernelWidthMustBeAnOddNumber");
requires an odd number

Possible solution:
In gem.c:

Code: Select all

{
	double d_Radius = radius;

	if ( (unsigned long) (d_Radius * 2.0 + 1.5) % 2 == 0 )
		d_Radius += 0.5;
	if ( (unsigned long) (d_Radius * 2.0 + 1.5) % 2 == 0 )
		d_Radius -= 0.25;
	return((unsigned long) (MagickMax(2.0*d_Radius+1.0,3.0)+0.5));
}
The second "if" is needed in case the first one overshoot into another region whose image is even.

--Hector C
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Bug in GetOptimalKernelWidth2D

Post by magick »

An easy fix is to use ceil(). Thanks for the problem report.
Post Reply