0

I'm currently stuck on cs50's pset4 filter (less comfortable). The program compiles perfectly. I have tried out the first three parts of the code (grayscale, sepia & reflection) and their output has been as desired; however, whenever I try out blur, I keep getting hit with a seg fault. Could someone please help me identify where the error(s) lies?

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 c = i + 1;
            int d = j + 1;
            int e = i + 2;
            int f = j + 2;

            float blurred_blue = 0;
            float blurred_green = 0;
            float blurred_red = 0;
            int z = 0;

            if (height - i == 1 && width - j >= 2)
            {
                for (int a = i - 1; a < c; a++)
                {
                    for (int b = j - 1; b < f; b++)
                    {
                        blurred_blue = blurred_blue + image[a][b].rgbtBlue;
                        blurred_green = blurred_green + image[a][b].rgbtGreen;
                        blurred_red = blurred_red + image[a][b].rgbtRed;
                        z++;
                    }
                }
            }
            else if (width - j == 1 && height - i >= 2)
            {
                for(int a = i - 1; a < e; a++)
                {
                    for(int b = j - 1; b < d; b++)
                    {
                        blurred_blue = blurred_blue + image[a][b].rgbtBlue;
                        blurred_green = blurred_green + image[a][b].rgbtGreen;
                        blurred_red = blurred_red + image[a][b].rgbtRed;
                        z++;
                    }
                }
            }
            else
            {
                for(int a = i - 1; a < e; a++)
                {
                    for(int b = j - 1; b < f; b++)
                    {
                        blurred_blue = blurred_blue + image[a][b].rgbtBlue;
                        blurred_green = blurred_green + image[a][b].rgbtGreen;
                        blurred_red = blurred_red + image[a][b].rgbtRed;
                        z++;
                    }
                }
            }
            image[i][j].rgbtBlue = round (blurred_blue / z);
            image[i][j].rgbtGreen = round (blurred_green / z);
            image[i][j].rgbtRed = round (blurred_red / z);
        }
    }
    return;
}

You must log in to answer this question.

Browse other questions tagged .