I need some advice about optimizing some code.
The smooth function, returns a "smoothed" version of an image, by taking the averages of all the pixels.
My question is... since the smooth function is calling the avg function repeatedly, would my time be better spent trying to speed up the avg function? or the smooth function?
I'm supposed to make it go at least twice as fast by using a technique called blocking... but I'm a little unsure about how to go about that.
Appreciate any help.
static pixel avg(int dim, int i, int j, pixel *src)
int ii, jj;
for(ii = max(i-1, 0); ii <= min(i+1, dim-1); ii++)
for(jj = max(j-1, 0); jj <= min(j+1, dim-1); jj++)
accumulate_sum(&sum, src[RIDX(ii, jj, dim)]);
void naive_smooth(int dim, pixel *src, pixel *dst)
int i, j;
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
dst[RIDX(i, j, dim)] = avg(dim, i, j, src);