The answer is given by the definition of 'terms':
terms = (row < 4) ? row : 4;
In pratice, that means that
- with row<4 the loop is
for (i = 0; i <= row; i++) {
...
}
- with row>=4 the loop is
for (i = 0; i <= 4; i++) {
...
}
Alastair M. Robinson wrote:
> Hi,
>
> I may be missing something obvious here, but I'm trying to understand
> the workings of the Gaussian Blur plugin, since I need to implement
> something similar myself, and either there's something screwy here, or
> there's something obvious I'm missing.
>
> In gimp-2.4.4/plugins/common/gauss.c, the gauss_iir() function,
> at line 960 we have four pointers initialised - two to the beginning of
> their respective buffers, and two to one tuple before the end.
>
> sp_p = src;
> sp_m = src + (height - 1) * bytes;
> vp = val_p;
> vm = val_m + (height - 1) * bytes;
>
> But then the inner loop does this:
> for (b = 0; b < bytes; b++)
> {
> vpptr = vp + b; vmptr = vm + b;
> for (i = 0; i <= terms; i++)
> {
> *vpptr += n_p[i] * sp_p[(-i * bytes) + b] - d_p[i] * vp[(-i *
> bytes) + b];
> *vmptr += n_m[i] * sp_m[(i * bytes) + b] - d_m[i] * vm[(i *
> bytes) + b];
> }
> ...
>
> On the first run through, with b=0, the index [(-i * bytes) + b] will be
> negative for all but the first iteration, yet it's used with the sp_p
> and vp pointers, which point to the beginning of their buffers, thus
> accessing memory outside the buffer. Or am I missing something here?
>
> And while we're on the subject, can anyone point me to an explanation of
> the maths behind this IIR approximation of the Gaussian filter? I
> understand Gaussian blurring well enough to implement a
> convolution-based version, but I want to implement a
> local-contrast-stretch filter - basically a gentle large-radius
> unsharp-mask, which would require unfeasibly large convolution matrices
> to do it that way.
>
> All the best,
> --
> Alastair M. Robinson
>
>
> _______________________________________________
> Gimp-developer mailing list
> [email protected]
> https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
>
>
_______________________________________________
Gimp-developer mailing list
[email protected]
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer