Pixel arrayindexoutofbounds
in
Programming Questions
•
1 month ago
For my program, I am using processing to make a bayer pattern of an image, then interpolate that bayer pattern. The program works until I get to edge cases. I have made if statements in order to catch these, but I still get the exception arrayindexoutofbounds when I try to use it.
If I make the loops go until height -1 and width -1, it works successfully... but I need to interpolate the edges still.
Where I call the method -
- loadPixels();
- // Loop through every pixel column
- for (int x2 = 640; x2 < 960; x2++) {
- // Loop through every pixel row
- for (int y2 = 0; y2 < height; y2++) {
- int loc2 = x2 + y2 * width;
- pixels[loc2]= rgb(x2, y2, loc2);
- updatePixels();
- }
Part of rgb method that errors out -
- if (x2 ==640 && y2%2==1) {
- r = red(pixels[loc]);
- System.out.println("" + loc);
- g = green(pixels[loc]);
- b = blue(pixels[loc]);
- g1 = green(pixels[loc9]);
- g2 = green(pixels[loc7]);
- System.out.println("" + x2 + " " + y2);
- g3 = green(pixels[loc5]);
- b1 = blue(pixels[loc8]);
- b2 = blue(pixels[loc6]);
- gcalc2 = (g1+g2) *.33;
- bcalc3 = (b1+b2) *.5;
- result = color(r, gcalc2, bcalc3);
- return result;
I initialize the surronding pixels earlier in the method, right here -
- int loc2 = (x2-1) + (y2-1) * width; //ul
- int loc3 = (x2-1) + (y2) * width; //l
- int loc4 = (x2-1) + (y2+1) * width; //bl
- int loc5 = (x2) + (y2+1) * width; //b
- int loc6 = (x2+1) + (y2+1) * width; //br
- int loc7 = (x2+1) + (y2) * width; //r
- int loc8 = (x2+1) + (y2-1) * width; //ur
- int loc9 = (x2) + (y2-1) * width; //u
ul, ur, b, etc all stand for the position of the pixel I am looking at relative to the one I am currently on. ul means upper left, b bottom, etc. I use these to get the color information of the surronding pixels so that I can interpolate.
Does anyone have any ideas as to why an outofbounds exception is being thrown in this case?
1