So, I have spent about 5 hours+ trying to figure out what is wrong with my code. I have tried debug50 with a 3x3 file I have manually created in Paint and everything seemed to work as intended; each pixel makes a 3x3 sweep around itself and disregards pixels that do not exist, like the ones in the corners or around edges. The final average values for each of the colors were also correct. Somehow, though, when I checked with check50, it gave out the following message:
With countless tweaking and head-scratching, I have decided that it was probably time for me to turn to the community for help. Here's my code:
{
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
int avgfordiv = 0;
int neighvalgreen = 0;
int neighvalblue = 0;
int neighvalred = 0;
for (int hh = -1; hh < 2; hh++)
{
for (int ww = -1; ww < 2; ww++)
{
if ((h+hh) != height && (w+ww) != width && (h+hh) != -1 && (w+ww) != -1)
{
//sweep
avgfordiv++;//count up for division
neighvalgreen += image[h + hh][w + ww].rgbtGreen;
neighvalred += image[h + hh][w + ww].rgbtRed;
neighvalblue += image[h + hh][w + ww].rgbtBlue;
}
}
}
//add values to pixels
image[h][w].rgbtGreen = (int)(round((float)neighvalgreen / avgfordiv));
image[h][w].rgbtBlue = (int)(round((float)neighvalblue / avgfordiv));
image[h][w].rgbtRed = (int)(round((float)neighvalred / avgfordiv));
//check cap
if (image[h][w].rgbtGreen <= 255)
{}
else
image[h][w].rgbtGreen %= 255;
if (image[h][w].rgbtRed <= 255)
{}
else
image[h][w].rgbtRed %= 255;
if (image[h][w].rgbtBlue <= 255)
{}
else
image[h][w].rgbtBlue %= 255;
}
}
return;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…