I'm confused about the reason I can't pass this test, if anyone can notice what's the cause I would be grateful :) here is the log :
:( blur correctly filters 3x3 image
Expected Output:
70 85 95 80 95 105 90 105 115 117 130 140 127 140 149 137 150 159 163 178 188 170 185 194 178 193 201
Actual Output:
70 85 95 80 95 105 90 105 115 117 130 140 127 140 149 137 150 159 163 200 188 170 185 194 178 193 201
{ RGBTRIPLE copy[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
copy[i][j] = image[i][j];
}
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if(i == 0 && j == 0)
{
// top left corner
float red = (copy[i][j].rgbtRed + copy[i][j+1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j+1].rgbtRed) / 4.0;
float green = (copy[i][j].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen) / 4.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j+1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j+1].rgbtBlue) / 4.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if(i == 0 && j == width - 1)
{
// top right corner
float red = (copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j-1].rgbtRed) / 4.0;
float green = (copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j-1].rgbtGreen) / 4.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j-1].rgbtBlue) / 4.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if(i == 0 && j > 0 && j < width - 1)
{
// top edge
float red = (copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i][j+1].rgbtRed + copy[i+1][j-1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j+1].rgbtRed) / 6.0;
float green = (copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i+1][j-1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen) / 6.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i][j+1].rgbtBlue + copy[i+1][j-1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j+1].rgbtBlue) / 6.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if (i == height - 1 && j == 0)
{
// bottom left corner
float red = (copy[i - 1][j].rgbtRed + copy[i - 1][j+1].rgbtRed + copy[i][j].rgbtRed + copy[i][j+1].rgbtRed) / 4.0;
float green = (copy[i - 1][j].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j+1].rgbtGreen) / 4.0;
float blue = (copy[i - 1][j].rgbtBlue + copy[i - 1][j+1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j+1].rgbtBlue) / 4.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if(i == height - 1 && j == width - 1)
{
// bottom right corner
float red = (copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i-1][j].rgbtRed + copy[i-1][j-1].rgbtRed) / 4.0;
float green = (copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i-1][j].rgbtGreen + copy[i-1][j-1].rgbtGreen) / 4.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i-1][j].rgbtBlue + copy[i-1][j-1].rgbtBlue) / 4.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if(i == height - 1 && j > 0 && j < width - 1)
{
// bottom edge
float red = (copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i][j+1].rgbtRed + copy[i-1][j-1].rgbtRed + copy[i-1][j].rgbtRed + copy[i-1][j+1].rgbtRed) / 6.0;
float green = (copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i-1][j-1].rgbtGreen + copy[i-1][j].rgbtGreen + copy[i-1][j+1].rgbtGreen) / 6.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i][j+1].rgbtBlue + copy[i-1][j-1].rgbtBlue + copy[i-1][j].rgbtBlue + copy[i-1][j+1].rgbtBlue) / 6.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if(i != 0 && i != height - 1 && j == 0)
{
// left edge
float red = (copy[i][j].rgbtRed + copy[i][j+1].rgbtRed + copy[i-1][j].rgbtRed + copy[i-1][j+1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j+1].rgbtRed) / 6.0;
float green = (copy[i][j].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i-1][j].rgbtGreen + copy[i-1][j+1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen) / 6.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j+1].rgbtBlue + copy[i-1][j].rgbtBlue + copy[i-1][j+1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j+1].rgbtBlue) / 6.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else if(i != 0 && i != height - 1 && j == width - 1)
{
// right edge
float red = (copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i-1][j].rgbtRed + copy[i-1][j-1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j-1].rgbtRed) / 6.0;
float green = (copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i-1][j].rgbtGreen + copy[i-1][j-1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j-1].rgbtGreen) / 6.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i-1][j].rgbtBlue + copy[i-1][j-1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j-1].rgbtBlue) / 6.0;
image[i][j].rgbtRed = (int)round(red);
image[i][j].rgbtGreen = (int)round(green);
image[i][j].rgbtBlue = (int)round(blue);
}
else
{
// 3*3
float red = (copy[i][j].rgbtRed + copy[i][j-1].rgbtRed + copy[i][j+1].rgbtRed + copy[i-1][j].rgbtRed + copy[i-1][j-1].rgbtRed + copy[i-1][j+1].rgbtRed + copy[i+1][j-1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j+1].rgbtRed) / 9.0;
float green = (copy[i][j].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i-1][j].rgbtGreen + copy[i-1][j-1].rgbtGreen + copy[i-1][j+1].rgbtGreen + copy[i+1][j-1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen) / 9.0;
float blue = (copy[i][j].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i][j+1].rgbtBlue + copy[i-1][j].rgbtBlue + copy[i-1][j-1].rgbtBlue + copy[i-1][j+1].rgbtBlue + copy[i+1][j-1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j+1].rgbtBlue) / 9.0;
image[i][j].rgbtRed = (int) round(red);
image[i][j].rgbtGreen = (int) round(green);
image[i][j].rgbtBlue = (int) round(blue);
}
}
}
}