This function is supposed to, pixel by pixel, blur the image by turning the color of each pixel on the mean of the colors around it in a 2n+1 "radius".
(The part where it skips to the next pixel is already implemented, don't worry).
I successfully compiled this code:
void
blur_pixels(image *img, pixel *p, size_t i, size_t j)
{
//i = current height of pixel, j = current width of pixel
int side = 2*blurRate+1;
int total = 0;
int leftRight = i-blurRate;
int upDown = j-blurRate;
int tmpHr = 0, tmpHg = 0, tmpHb = 0;
for(; upDown < j+blurRate; upDown++) {
if(upDown >= 0 && upDown < img->height) {
for(; leftRight < i+blurRate; leftRight++) {
if(leftRight >= 0 && leftRight < img->width) {
tmpHr += (p+leftRight)->r;
tmpHg += (p+leftRight)->g;
tmpHb += (p+leftRight)->b;
total++;
}
}
}
}
p->r=tmpHr/total;
p->g=tmpHg/total;
p->b=tmpHb/total;
}
But when I run the code I get the following exception:
Floating point exception
Does anyone know why?