in matlab/strred/matlabPyrTools/MEX/convolve.c [51:173]
int internal_reduce(image, x_dim, y_dim, filt, temp, x_fdim, y_fdim,
x_start, x_step, x_stop, y_start, y_step, y_stop,
result, edges)
register image_type *image, *temp;
register int x_fdim, x_dim;
register image_type *result;
register int x_step, y_step;
int x_start, y_start;
int x_stop, y_stop;
image_type *filt;
int y_dim, y_fdim;
char *edges;
{
register double sum;
register int filt_pos, im_pos, x_filt_stop;
register int x_pos, filt_size = x_fdim*y_fdim;
register int y_pos, res_pos;
register int y_ctr_stop = y_dim - ((y_fdim==1)?0:y_fdim);
register int x_ctr_stop = x_dim - ((x_fdim==1)?0:x_fdim);
register int x_res_dim = (x_stop-x_start+x_step-1)/x_step;
int x_ctr_start = ((x_fdim==1)?0:1);
int y_ctr_start = ((y_fdim==1)?0:1);
int x_fmid = x_fdim/2;
int y_fmid = y_fdim/2;
int base_res_pos;
fptr reflect = edge_function(edges); /* look up edge-handling function */
if (!reflect) return(-1);
/* shift start/stop coords to filter upper left hand corner */
x_start -= x_fmid; y_start -= y_fmid;
x_stop -= x_fmid; y_stop -= y_fmid;
if (x_stop < x_ctr_stop) x_ctr_stop = x_stop;
if (y_stop < y_ctr_stop) y_ctr_stop = y_stop;
for (res_pos=0, y_pos=y_start; /* TOP ROWS */
y_pos<y_ctr_start;
y_pos+=y_step)
{
for (x_pos=x_start; /* TOP-LEFT CORNER */
x_pos<x_ctr_start;
x_pos+=x_step, res_pos++)
{
(*reflect)(filt,x_fdim,y_fdim,x_pos-1,y_pos-1,temp,REDUCE);
INPROD(0,0)
}
(*reflect)(filt,x_fdim,y_fdim,0,y_pos-1,temp,REDUCE);
for (; /* TOP EDGE */
x_pos<x_ctr_stop;
x_pos+=x_step, res_pos++)
INPROD(x_pos,0)
for (; /* TOP-RIGHT CORNER */
x_pos<x_stop;
x_pos+=x_step, res_pos++)
{
(*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,y_pos-1,temp,REDUCE);
INPROD(x_ctr_stop,0)
}
} /* end TOP ROWS */
y_ctr_start = y_pos; /* hold location of top */
for (base_res_pos=res_pos, x_pos=x_start; /* LEFT EDGE */
x_pos<x_ctr_start;
x_pos+=x_step, base_res_pos++)
{
(*reflect)(filt,x_fdim,y_fdim,x_pos-1,0,temp,REDUCE);
for (y_pos=y_ctr_start, res_pos=base_res_pos;
y_pos<y_ctr_stop;
y_pos+=y_step, res_pos+=x_res_dim)
INPROD(0,y_pos)
}
(*reflect)(filt,x_fdim,y_fdim,0,0,temp,REDUCE);
for (; /* CENTER */
x_pos<x_ctr_stop;
x_pos+=x_step, base_res_pos++)
for (y_pos=y_ctr_start, res_pos=base_res_pos;
y_pos<y_ctr_stop;
y_pos+=y_step, res_pos+=x_res_dim)
INPROD(x_pos,y_pos)
for (; /* RIGHT EDGE */
x_pos<x_stop;
x_pos+=x_step, base_res_pos++)
{
(*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,0,temp,REDUCE);
for (y_pos=y_ctr_start, res_pos=base_res_pos;
y_pos<y_ctr_stop;
y_pos+=y_step, res_pos+=x_res_dim)
INPROD(x_ctr_stop,y_pos)
}
for (res_pos-=(x_res_dim-1);
y_pos<y_stop; /* BOTTOM ROWS */
y_pos+=y_step)
{
for (x_pos=x_start; /* BOTTOM-LEFT CORNER */
x_pos<x_ctr_start;
x_pos+=x_step, res_pos++)
{
(*reflect)(filt,x_fdim,y_fdim,x_pos-1,y_pos-y_ctr_stop+1,temp,REDUCE);
INPROD(0,y_ctr_stop)
}
(*reflect)(filt,x_fdim,y_fdim,0,y_pos-y_ctr_stop+1,temp,REDUCE);
for (; /* BOTTOM EDGE */
x_pos<x_ctr_stop;
x_pos+=x_step, res_pos++)
INPROD(x_pos,y_ctr_stop)
for (; /* BOTTOM-RIGHT CORNER */
x_pos<x_stop;
x_pos+=x_step, res_pos++)
{
(*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,y_pos-y_ctr_stop+1,temp,REDUCE);
INPROD(x_ctr_stop,y_ctr_stop)
}
} /* end BOTTOM */
return(0);
} /* end of internal_reduce */