Page 1 of 1

Bug in GetOptimalKernelWidth2D

Posted: 2007-06-09T09:54:41-07:00
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

Re: Bug in GetOptimalKernelWidth2D

Posted: 2007-06-09T10:17:45-07:00
by magick
An easy fix is to use ceil(). Thanks for the problem report.