/** * Sets the pixel's value for all the bands using an array. * * @param x pixel coordinate. * @param y pixel coordinate. * @param value The pixel's new value for each band. */ public void set(int x, int y, byte... value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { data[index] = value[i]; } }
/** * Returns the pixel's value for all the bands as an array. * * @param x pixel coordinate. * @param y pixel coordinate. * @param storage If not null then the pixel's value is written here. If null a new array is created. * @return The pixel's value. */ public byte[] get(int x, int y, byte[] storage) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds"); if (storage == null) { storage = new byte[numBands]; } int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { storage[i] = data[index]; } return storage; }
@Override public void setBand(int x, int y, int band, int value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds."); if (band < 0 || band >= numBands) throw new ImageAccessException("Invalid band requested."); data[getIndex(x, y, band)] = (byte)value; }
/** * Returns the value of the specified band in the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param band which color band in the pixel * @param value The new value of the element. */ public void setBand(int x, int y, int band, byte value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds."); if (band < 0 || band >= numBands) throw new ImageAccessException("Invalid band requested."); data[getIndex(x, y, band)] = value; }