0

Not sure what I am doing wrong, I tried casting double to the blurhelper function and check50 still says it is wrong.

void blur(int height, int width, RGBTRIPLE image[height][width])
{

RGBTRIPLE(*temp)[width] = calloc(height, width * sizeof(RGBTRIPLE));
for (int h = 0; h < height; h++) //Loop for height of image.
{
    for (int w = 0; w < width; w++) //Loop for width of image and save color values in temp.
    {
       temp[h][w] = image[h][w];
    }
}
for (int i = 0; i < height; i++)
{
    for (int j = 0; j < width; j++)
    {
        image[i][j].rgbtBlue = round((blurHelper(i, j, temp, 'B')));
        image[i][j].rgbtGreen =  round((blurHelper(i, j, temp, 'G')));
        image[i][j].rgbtRed =  round((blurHelper(i, j, temp, 'R')));
    }
}
return;
}

double blurHelper (int column, int row, RGBTRIPLE(*image)[600], char color)
{
int columns = column - 1;
int rows = row - 1;
double Baverage = 0;
double Gaverage = 0;
double Raverage = 0;
double count = 0;

for (int i = 0; i < 3; i++)
{
    for (int j = 0; j < 3; j++)
    {
        if (columns < 400 && columns >= 0 && rows < 600 && rows >= 0)
        {
        Baverage += (double)(image[columns][rows].rgbtBlue);
        Gaverage += (double)(image[columns][rows].rgbtGreen);
        Raverage += (double)(image[columns][rows].rgbtRed);
        count++;
        }
        rows++;
    }
    columns++;
    rows = rows - 1;

}
if (color == 'B' && Baverage != 0)
{
    return Baverage/count;
}
else if (color == 'G' && Gaverage != 0)
{
    return Gaverage/count;
}
else if (color == 'R' && Raverage != 0)
{
    return Raverage/count;
}
return 0;
}

https://submit.cs50.io/check50/5aeadc8bbc2852506c94616267e24f09f670b106

  • Hardcoding the size of the image might not be a good idea. In check50 it's tested with diferent image sizes. – Tritum Jun 14 at 10:29

You must log in to answer this question.

Browse other questions tagged .