Correct an off-by-one in the reflection of the convolution index.

Currently the convolution code uses the formula 2*(N-1)-n to reflect the index
n when n is greater than or equal to N.
This is wrong as n=N -> 2*(N-1)-N = N-2 instead of N-1.

Furthermore when the image is small, e.g. at the highest levels of the
pyramid, this causes the code to index before the start of the array and
causes valgrind to issue a warning.
This commit is contained in:
Chris Wilson 2007-03-11 21:55:19 +00:00 committed by Carl Worth
parent 789aada06b
commit 14cab8b020

View file

@ -46,8 +46,8 @@ convolve (lpyramid_t *pyramid, float *a, float *b)
ny=y+j;
if (nx<0) nx=-nx;
if (ny<0) ny=-ny;
if (nx>=width) nx=2*(width-1)-nx;
if (ny>=height) ny=2*(height-1)-ny;
if (nx>=width) nx=2*width - nx - 1;
if (ny>=height) ny=2*height - ny - 1;
a[index] += Kernel[i+2] * Kernel[j+2] * b[ny * width + nx];
}
}