I am trying to increase the values of a 2D array using a slider. I essentially want to increase the brightness of an image that is written in by R G and B arrays.I believe my method is called correctly and is listening for the slider value,but I am now concerned about values exceeding 255. I added in modulus operators to prevent this but I am receiving an ArrayOutOfBoundsException starting at the line where I begin adding the amount to the index. I added print statements to see if the values change and they don't, but whenever I move my slider the ArrayOutOfBoundsException appears.
adjustBrightness Method to change values of the arrays:
public void adjustBrightness(int amount) {
int gimmieRows = thePPMImage.getNumRows();
int gimmieCols = thePPMImage.getNumCols();
int[][] gimmieRed = thePPMImage.getRedPixels();
int[][] gimmieBlue = thePPMImage.getBluePixels();
int[][] gimmieGreen = thePPMImage.getGreenPixels();
int[][] brighterRedPixels =new int[gimmieRed.length][gimmieRed[0].length];
int [][] brighterGreenPixels = new int[gimmieGreen.length][gimmieGreen.length];
int [][] brighterBluePixels = new int[gimmieBlue.length][gimmieBlue[0].length];
for (int i = 0; i < gimmieRows; i++) {
for (int j = 0; j < gimmieCols; j++) {
if ((i+amount)%255>1.0 || (j+amount)%255>1.0) {
amount =amount-255;}
else ((i+amount)%255<=1.0 || (j+amount)%255<=1.0)
{amount=amount;}
System.out.println(gimmieRed[11][7]);
brighterRedPixels[i][j] = amount + gimmieRed[i][j];
brighterGreenPixels[i][j] = amount + gimmieGreen[i][j];
brighterBluePixels[i][j] = amount + gimmieBlue[i][j];
System.out.println(gimmieRed[11][7]);
System.out.println(brighterRedPixels[11][7]);
}
}
thePPMImage = new PPMImage(brighterRedPixels, brighterGreenPixels,brighterBluePixels );
thePPMImage.setRedPixels(brighterRedPixels);
thePPMImage.setGreenPixels(brighterGreenPixels);
thePPMImage.setBluePixels(brighterBluePixels);
imageLabel.setIcon(new SImage(
transposeArray(thePPMImage.getRedPixels()),
transposeArray(thePPMImage.getGreenPixels()),
transposeArray(thePPMImage.getBluePixels())));
Change Listener for the slider.
public class event implements ChangeListener {
public void stateChanged (ChangeEvent e){
int amount = brightnessSlider.getValue();
adjustBrightness(amount);
Any insight would be appreciated, this assignment was due like yesterday.