I am working on blur in filter and it says my index is our if bound -1
// Create count starts and end count
int sh = -1;
int eh = 1;
int sw = -1;
int ew = 1;
//Modify start for first height
if (h == 0)
{
sh = 0;
}
if (h == height - 1)
{
eh = 0;
}
if (w == 0)
{
sw = 0;
}
if (w == width - 1)
{
ew = 0;
}
// Calculate averige
// Iterate over height
for (int hi = sh; hi < eh; hi++)
{
// Iterate over width
for (int wi = sw; wi < ew; wi++)
{
// Add up the value of the 10 pixels
blue = blue + temp[h - hi][w - wi].rgbtBlue;
green = green + temp[h - hi][w - wi].rgbtGreen;
red = red + temp[h - hi][w - wi].rgbtRed;
}
}
I have tested everything I can think. Is it time hat my approach will not work in general and I need to go back to the drawing board?
~/pset4/filter/ $ ./filter -b images/tower.bmp t.bmp
helpers.c:185:39: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:186:41: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:187:37: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:185:39: runtime error: index -1 out of bounds for type 'RGBTRIPLE [height][width]'
helpers.c:186:41: runtime error: index -1 out of bounds for type 'RGBTRIPLE [height][width]'
helpers.c:187:37: runtime error: index -1 out of bounds for type 'RGBTRIPLE [height][width]'
h-hi
is -1 and sometimesw-wi
is -1 and you can't have negative indices into your array. – curiouskiwi♦ Jan 20 '20 at 22:56h
andw
are both 0 (ie, the very top left pixel)?ew
is 3, so your wi loop runs 3 times, and you get w-wi is 0, then -1, then -2. – curiouskiwi♦ Jan 20 '20 at 23:26