I tried to apply box blur to an image (without a matrix but just iterating over 9 neighbooring pixels) but I am always getting a segmentation fault
after I get to 408th pixel of an image (on the 1st row). I don't know what could cause it because debugging with printf()
didn't show any meaningful results
void blur(int height, int width, RGBTRIPLE image[height][width])
{
BYTE totalRed, totalGreen, totalBlue;
totalRed = totalGreen = totalBlue = 0;
for (int i = 1; i < height - 1; i++)
{
for (int j = 1; j < width - 1; j++)
{
for (int h = -1; h <= 1; h++)
{
for (int w = -1; w <= 1; w++)
{
totalRed += image[i + h][j + w].rgbtRed;
totalGreen += image[i + h][j + w].rgbtGreen;
totalBlue += image[i + h][j + w].rgbtBlue;
}
}
image[j][i].rgbtRed = round((totalRed / 9));
image[j][i].rgbtGreen = round((totalGreen / 9));
image[j][i].rgbtBlue = round((totalBlue / 9));
}
}
return;
}
EDIT
I fixed the issue, thanks to everyone who answered me.