I'm doing CS50 and trying really hard to keep sane while I try to finish the last part of the Filter (less) exercise. I'm stuck on "Blur". I've tried to resist looking for help online because I really want to understand what I'm doing wrong. In my head my code works, so I'm afraid maybe I'm already blind to any mistakes.
I appreciate all the help! Thanks in advance, Ana
Here's my code:
void blur(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int sum_red = 0;
int sum_green = 0;
int sum_blue = 0;
int counter = 0;
for (int add_i = -1; add_i < 2; add_i++)
{
for (int add_j = -1; add_j < 2; add_j++)
{
if (!(add_i + i < 0) && !(add_j + j < 0) && (add_i + i <= height) && (add_j + j <= width))
{
sum_red = sum_red + image[i + add_i][j + add_j].rgbtRed;
sum_green = sum_green + image[i + add_i][j + add_j].rgbtGreen;
sum_blue = sum_blue + image[i + add_i][j + add_j].rgbtBlue;
counter++;
}
}
}
image[i][j].rgbtRed = round(sum_red / counter);
image[i][j].rgbtGreen = round(sum_green / counter);
image[i][j].rgbtBlue = round(sum_blue / counter);
}
}
return;
}