< prev index next >
src/java.desktop/share/classes/java/awt/image/MultiPixelPackedSampleModel.java
Print this page
*** 34,44 ****
******************************************************************/
package java.awt.image;
/**
! * The <code>MultiPixelPackedSampleModel</code> class represents
* one-banded images and can pack multiple one-sample
* pixels into one data element. Pixels are not allowed to span data elements.
* The data type can be DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
* or DataBuffer.TYPE_INT. Each pixel must be a power of 2 number of bits
* and a power of 2 number of pixels must fit exactly in one data element.
--- 34,44 ----
******************************************************************/
package java.awt.image;
/**
! * The {@code MultiPixelPackedSampleModel} class represents
* one-banded images and can pack multiple one-sample
* pixels into one data element. Pixels are not allowed to span data elements.
* The data type can be DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
* or DataBuffer.TYPE_INT. Each pixel must be a power of 2 number of bits
* and a power of 2 number of pixels must fit exactly in one data element.
*** 47,59 ****
* padded with unused pixels. Data bit offset is the offset in bits from
* the beginning of the {@link DataBuffer} to the first pixel and must be
* a multiple of pixel bit stride.
* <p>
* The following code illustrates extracting the bits for pixel
! * <code>x, y</code> from <code>DataBuffer</code> <code>data</code>
* and storing the pixel data in data elements of type
! * <code>dataType</code>:
* <pre>{@code
* int dataElementSize = DataBuffer.getDataTypeSize(dataType);
* int bitnum = dataBitOffset + x*pixelBitStride;
* int element = data.getElem(y*scanlineStride + bitnum/dataElementSize);
* int shift = dataElementSize - (bitnum & (dataElementSize-1))
--- 47,59 ----
* padded with unused pixels. Data bit offset is the offset in bits from
* the beginning of the {@link DataBuffer} to the first pixel and must be
* a multiple of pixel bit stride.
* <p>
* The following code illustrates extracting the bits for pixel
! * <code>x, y</code> from {@code DataBuffer data}
* and storing the pixel data in data elements of type
! * {@code dataType}:
* <pre>{@code
* int dataElementSize = DataBuffer.getDataTypeSize(dataType);
* int bitnum = dataBitOffset + x*pixelBitStride;
* int element = data.getElem(y*scanlineStride + bitnum/dataElementSize);
* int shift = dataElementSize - (bitnum & (dataElementSize-1))
*** 85,106 ****
/** ScanlineStride of the data buffer described in data array elements. */
int scanlineStride;
/**
! * Constructs a <code>MultiPixelPackedSampleModel</code> with the
* specified data type, width, height and number of bits per pixel.
* @param dataType the data type for storing samples
* @param w the width, in pixels, of the region of
* image data described
* @param h the height, in pixels, of the region of
* image data described
* @param numberOfBits the number of bits per pixel
! * @throws IllegalArgumentException if <code>dataType</code> is not
! * either <code>DataBuffer.TYPE_BYTE</code>,
! * <code>DataBuffer.TYPE_USHORT</code>, or
! * <code>DataBuffer.TYPE_INT</code>
*/
public MultiPixelPackedSampleModel(int dataType,
int w,
int h,
int numberOfBits) {
--- 85,106 ----
/** ScanlineStride of the data buffer described in data array elements. */
int scanlineStride;
/**
! * Constructs a {@code MultiPixelPackedSampleModel} with the
* specified data type, width, height and number of bits per pixel.
* @param dataType the data type for storing samples
* @param w the width, in pixels, of the region of
* image data described
* @param h the height, in pixels, of the region of
* image data described
* @param numberOfBits the number of bits per pixel
! * @throws IllegalArgumentException if {@code dataType} is not
! * either {@code DataBuffer.TYPE_BYTE},
! * {@code DataBuffer.TYPE_USHORT}, or
! * {@code DataBuffer.TYPE_INT}
*/
public MultiPixelPackedSampleModel(int dataType,
int w,
int h,
int numberOfBits) {
*** 116,126 ****
dataType);
}
}
/**
! * Constructs a <code>MultiPixelPackedSampleModel</code> with
* specified data type, width, height, number of bits per pixel,
* scanline stride and data bit offset.
* @param dataType the data type for storing samples
* @param w the width, in pixels, of the region of
* image data described
--- 116,126 ----
dataType);
}
}
/**
! * Constructs a {@code MultiPixelPackedSampleModel} with
* specified data type, width, height, number of bits per pixel,
* scanline stride and data bit offset.
* @param dataType the data type for storing samples
* @param w the width, in pixels, of the region of
* image data described
*** 131,146 ****
* @param dataBitOffset the data bit offset for the region of image
* data described
* @exception RasterFormatException if the number of bits per pixel
* is not a power of 2 or if a power of 2 number of
* pixels do not fit in one data element.
! * @throws IllegalArgumentException if <code>w</code> or
! * <code>h</code> is not greater than 0
! * @throws IllegalArgumentException if <code>dataType</code> is not
! * either <code>DataBuffer.TYPE_BYTE</code>,
! * <code>DataBuffer.TYPE_USHORT</code>, or
! * <code>DataBuffer.TYPE_INT</code>
*/
public MultiPixelPackedSampleModel(int dataType, int w, int h,
int numberOfBits,
int scanlineStride,
int dataBitOffset) {
--- 131,146 ----
* @param dataBitOffset the data bit offset for the region of image
* data described
* @exception RasterFormatException if the number of bits per pixel
* is not a power of 2 or if a power of 2 number of
* pixels do not fit in one data element.
! * @throws IllegalArgumentException if {@code w} or
! * {@code h} is not greater than 0
! * @throws IllegalArgumentException if {@code dataType} is not
! * either {@code DataBuffer.TYPE_BYTE},
! * {@code DataBuffer.TYPE_USHORT}, or
! * {@code DataBuffer.TYPE_INT}
*/
public MultiPixelPackedSampleModel(int dataType, int w, int h,
int numberOfBits,
int scanlineStride,
int dataBitOffset) {
*** 165,201 ****
this.bitMask = (1 << numberOfBits) - 1;
}
/**
! * Creates a new <code>MultiPixelPackedSampleModel</code> with the
* specified width and height. The new
! * <code>MultiPixelPackedSampleModel</code> has the
* same storage data type and number of bits per pixel as this
! * <code>MultiPixelPackedSampleModel</code>.
* @param w the specified width
* @param h the specified height
* @return a {@link SampleModel} with the specified width and height
* and with the same storage data type and number of bits per pixel
! * as this <code>MultiPixelPackedSampleModel</code>.
! * @throws IllegalArgumentException if <code>w</code> or
! * <code>h</code> is not greater than 0
*/
public SampleModel createCompatibleSampleModel(int w, int h) {
SampleModel sampleModel =
new MultiPixelPackedSampleModel(dataType, w, h, pixelBitStride);
return sampleModel;
}
/**
! * Creates a <code>DataBuffer</code> that corresponds to this
! * <code>MultiPixelPackedSampleModel</code>. The
! * <code>DataBuffer</code> object's data type and size
! * is consistent with this <code>MultiPixelPackedSampleModel</code>.
! * The <code>DataBuffer</code> has a single bank.
! * @return a <code>DataBuffer</code> with the same data type and
! * size as this <code>MultiPixelPackedSampleModel</code>.
*/
public DataBuffer createDataBuffer() {
DataBuffer dataBuffer = null;
int size = scanlineStride*height;
--- 165,201 ----
this.bitMask = (1 << numberOfBits) - 1;
}
/**
! * Creates a new {@code MultiPixelPackedSampleModel} with the
* specified width and height. The new
! * {@code MultiPixelPackedSampleModel} has the
* same storage data type and number of bits per pixel as this
! * {@code MultiPixelPackedSampleModel}.
* @param w the specified width
* @param h the specified height
* @return a {@link SampleModel} with the specified width and height
* and with the same storage data type and number of bits per pixel
! * as this {@code MultiPixelPackedSampleModel}.
! * @throws IllegalArgumentException if {@code w} or
! * {@code h} is not greater than 0
*/
public SampleModel createCompatibleSampleModel(int w, int h) {
SampleModel sampleModel =
new MultiPixelPackedSampleModel(dataType, w, h, pixelBitStride);
return sampleModel;
}
/**
! * Creates a {@code DataBuffer} that corresponds to this
! * {@code MultiPixelPackedSampleModel}. The
! * {@code DataBuffer} object's data type and size
! * is consistent with this {@code MultiPixelPackedSampleModel}.
! * The {@code DataBuffer} has a single bank.
! * @return a {@code DataBuffer} with the same data type and
! * size as this {@code MultiPixelPackedSampleModel}.
*/
public DataBuffer createDataBuffer() {
DataBuffer dataBuffer = null;
int size = scanlineStride*height;
*** 214,224 ****
}
/**
* Returns the number of data elements needed to transfer one pixel
* via the {@link #getDataElements} and {@link #setDataElements}
! * methods. For a <code>MultiPixelPackedSampleModel</code>, this is
* one.
* @return the number of data elements.
*/
public int getNumDataElements() {
return 1;
--- 214,224 ----
}
/**
* Returns the number of data elements needed to transfer one pixel
* via the {@link #getDataElements} and {@link #setDataElements}
! * methods. For a {@code MultiPixelPackedSampleModel}, this is
* one.
* @return the number of data elements.
*/
public int getNumDataElements() {
return 1;
*** 254,264 ****
return offset;
}
/**
* Returns the offset, in bits, into the data element in which it is
! * stored for the <code>x</code>th pixel of a scanline.
* This offset is the same for all scanlines.
* @param x the specified pixel
* @return the bit offset of the specified pixel.
*/
public int getBitOffset(int x){
--- 254,264 ----
return offset;
}
/**
* Returns the offset, in bits, into the data element in which it is
! * stored for the {@code x}th pixel of a scanline.
* This offset is the same for all scanlines.
* @param x the specified pixel
* @return the bit offset of the specified pixel.
*/
public int getBitOffset(int x){
*** 266,303 ****
}
/**
* Returns the scanline stride.
* @return the scanline stride of this
! * <code>MultiPixelPackedSampleModel</code>.
*/
public int getScanlineStride() {
return scanlineStride;
}
/**
* Returns the pixel bit stride in bits. This value is the same as
* the number of bits per pixel.
! * @return the <code>pixelBitStride</code> of this
! * <code>MultiPixelPackedSampleModel</code>.
*/
public int getPixelBitStride() {
return pixelBitStride;
}
/**
* Returns the data bit offset in bits.
! * @return the <code>dataBitOffset</code> of this
! * <code>MultiPixelPackedSampleModel</code>.
*/
public int getDataBitOffset() {
return dataBitOffset;
}
/**
* Returns the TransferType used to transfer pixels by way of the
! * <code>getDataElements</code> and <code>setDataElements</code>
* methods. The TransferType might or might not be the same as the
* storage DataType. The TransferType is one of
* DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
* or DataBuffer.TYPE_INT.
* @return the transfertype.
--- 266,303 ----
}
/**
* Returns the scanline stride.
* @return the scanline stride of this
! * {@code MultiPixelPackedSampleModel}.
*/
public int getScanlineStride() {
return scanlineStride;
}
/**
* Returns the pixel bit stride in bits. This value is the same as
* the number of bits per pixel.
! * @return the {@code pixelBitStride} of this
! * {@code MultiPixelPackedSampleModel}.
*/
public int getPixelBitStride() {
return pixelBitStride;
}
/**
* Returns the data bit offset in bits.
! * @return the {@code dataBitOffset} of this
! * {@code MultiPixelPackedSampleModel}.
*/
public int getDataBitOffset() {
return dataBitOffset;
}
/**
* Returns the TransferType used to transfer pixels by way of the
! * {@code getDataElements} and {@code setDataElements}
* methods. The TransferType might or might not be the same as the
* storage DataType. The TransferType is one of
* DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
* or DataBuffer.TYPE_INT.
* @return the transfertype.
*** 310,332 ****
else
return DataBuffer.TYPE_BYTE;
}
/**
! * Creates a new <code>MultiPixelPackedSampleModel</code> with a
* subset of the bands of this
! * <code>MultiPixelPackedSampleModel</code>. Since a
! * <code>MultiPixelPackedSampleModel</code> only has one band, the
* bands argument must have a length of one and indicate the zeroth
* band.
* @param bands the specified bands
! * @return a new <code>SampleModel</code> with a subset of bands of
! * this <code>MultiPixelPackedSampleModel</code>.
* @exception RasterFormatException if the number of bands requested
* is not one.
! * @throws IllegalArgumentException if <code>w</code> or
! * <code>h</code> is not greater than 0
*/
public SampleModel createSubsetSampleModel(int bands[]) {
if (bands != null) {
if (bands.length != 1)
throw new RasterFormatException("MultiPixelPackedSampleModel has "
--- 310,332 ----
else
return DataBuffer.TYPE_BYTE;
}
/**
! * Creates a new {@code MultiPixelPackedSampleModel} with a
* subset of the bands of this
! * {@code MultiPixelPackedSampleModel}. Since a
! * {@code MultiPixelPackedSampleModel} only has one band, the
* bands argument must have a length of one and indicate the zeroth
* band.
* @param bands the specified bands
! * @return a new {@code SampleModel} with a subset of bands of
! * this {@code MultiPixelPackedSampleModel}.
* @exception RasterFormatException if the number of bands requested
* is not one.
! * @throws IllegalArgumentException if {@code w} or
! * {@code h} is not greater than 0
*/
public SampleModel createSubsetSampleModel(int bands[]) {
if (bands != null) {
if (bands.length != 1)
throw new RasterFormatException("MultiPixelPackedSampleModel has "
*** 335,352 ****
SampleModel sm = createCompatibleSampleModel(width, height);
return sm;
}
/**
! * Returns as <code>int</code> the sample in a specified band for the
* pixel located at (x, y). An
! * <code>ArrayIndexOutOfBoundsException</code> is thrown if the
* coordinates are not in bounds.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param b the band to return, which is assumed to be 0
! * @param data the <code>DataBuffer</code> containing the image
* data
* @return the specified band containing the sample of the specified
* pixel.
* @exception ArrayIndexOutOfBoundsException if the specified
* coordinates are not in bounds.
--- 335,352 ----
SampleModel sm = createCompatibleSampleModel(width, height);
return sm;
}
/**
! * Returns as {@code int} the sample in a specified band for the
* pixel located at (x, y). An
! * {@code ArrayIndexOutOfBoundsException} is thrown if the
* coordinates are not in bounds.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param b the band to return, which is assumed to be 0
! * @param data the {@code DataBuffer} containing the image
* data
* @return the specified band containing the sample of the specified
* pixel.
* @exception ArrayIndexOutOfBoundsException if the specified
* coordinates are not in bounds.
*** 366,384 ****
return (element >> shift) & bitMask;
}
/**
* Sets a sample in the specified band for the pixel located at
! * (x, y) in the <code>DataBuffer</code> using an
! * <code>int</code> for input.
! * An <code>ArrayIndexOutOfBoundsException</code> is thrown if the
* coordinates are not in bounds.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param b the band to return, which is assumed to be 0
! * @param s the input sample as an <code>int</code>
! * @param data the <code>DataBuffer</code> where image data is stored
* @exception ArrayIndexOutOfBoundsException if the coordinates are
* not in bounds.
* @see #getSample(int, int, int, DataBuffer)
*/
public void setSample(int x, int y, int b, int s,
--- 366,384 ----
return (element >> shift) & bitMask;
}
/**
* Sets a sample in the specified band for the pixel located at
! * (x, y) in the {@code DataBuffer} using an
! * {@code int} for input.
! * An {@code ArrayIndexOutOfBoundsException} is thrown if the
* coordinates are not in bounds.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param b the band to return, which is assumed to be 0
! * @param s the input sample as an {@code int}
! * @param data the {@code DataBuffer} where image data is stored
* @exception ArrayIndexOutOfBoundsException if the coordinates are
* not in bounds.
* @see #getSample(int, int, int, DataBuffer)
*/
public void setSample(int x, int y, int b, int s,
*** 399,453 ****
data.setElem(index,element);
}
/**
* Returns data for a single pixel in a primitive array of type
! * TransferType. For a <code>MultiPixelPackedSampleModel</code>,
* the array has one element, and the type is the smallest of
* DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
! * that can hold a single pixel. Generally, <code>obj</code>
! * should be passed in as <code>null</code>, so that the
! * <code>Object</code> is created automatically and is the
* correct primitive data type.
* <p>
* The following code illustrates transferring data for one pixel from
! * <code>DataBuffer</code> <code>db1</code>, whose storage layout is
! * described by <code>MultiPixelPackedSampleModel</code>
! * <code>mppsm1</code>, to <code>DataBuffer</code> <code>db2</code>,
* whose storage layout is described by
! * <code>MultiPixelPackedSampleModel</code> <code>mppsm2</code>.
* The transfer is generally more efficient than using
! * <code>getPixel</code> or <code>setPixel</code>.
* <pre>
* MultiPixelPackedSampleModel mppsm1, mppsm2;
* DataBufferInt db1, db2;
* mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null,
* db1), db2);
* </pre>
! * Using <code>getDataElements</code> or <code>setDataElements</code>
! * to transfer between two <code>DataBuffer/SampleModel</code> pairs
! * is legitimate if the <code>SampleModels</code> have the same number
* of bands, corresponding bands have the same number of
* bits per sample, and the TransferTypes are the same.
* <p>
! * If <code>obj</code> is not <code>null</code>, it should be a
* primitive array of type TransferType. Otherwise, a
! * <code>ClassCastException</code> is thrown. An
! * <code>ArrayIndexOutOfBoundsException</code> is thrown if the
! * coordinates are not in bounds, or if <code>obj</code> is not
! * <code>null</code> and is not large enough to hold the pixel data.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param obj a primitive array in which to return the pixel data or
! * <code>null</code>.
! * @param data the <code>DataBuffer</code> containing the image data.
! * @return an <code>Object</code> containing data for the specified
* pixel.
! * @exception ClassCastException if <code>obj</code> is not a
! * primitive array of type TransferType or is not <code>null</code>
* @exception ArrayIndexOutOfBoundsException if the coordinates are
! * not in bounds, or if <code>obj</code> is not <code>null</code> or
* not large enough to hold the pixel data
* @see #setDataElements(int, int, Object, DataBuffer)
*/
public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
--- 399,453 ----
data.setElem(index,element);
}
/**
* Returns data for a single pixel in a primitive array of type
! * TransferType. For a {@code MultiPixelPackedSampleModel},
* the array has one element, and the type is the smallest of
* DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
! * that can hold a single pixel. Generally, {@code obj}
! * should be passed in as {@code null}, so that the
! * {@code Object} is created automatically and is the
* correct primitive data type.
* <p>
* The following code illustrates transferring data for one pixel from
! * {@code DataBuffer db1}, whose storage layout is
! * described by {@code MultiPixelPackedSampleModel}
! * {@code mppsm1}, to {@code DataBuffer db2},
* whose storage layout is described by
! * {@code MultiPixelPackedSampleModel mppsm2}.
* The transfer is generally more efficient than using
! * {@code getPixel} or {@code setPixel}.
* <pre>
* MultiPixelPackedSampleModel mppsm1, mppsm2;
* DataBufferInt db1, db2;
* mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null,
* db1), db2);
* </pre>
! * Using {@code getDataElements} or {@code setDataElements}
! * to transfer between two {@code DataBuffer/SampleModel} pairs
! * is legitimate if the {@code SampleModels} have the same number
* of bands, corresponding bands have the same number of
* bits per sample, and the TransferTypes are the same.
* <p>
! * If {@code obj} is not {@code null}, it should be a
* primitive array of type TransferType. Otherwise, a
! * {@code ClassCastException} is thrown. An
! * {@code ArrayIndexOutOfBoundsException} is thrown if the
! * coordinates are not in bounds, or if {@code obj} is not
! * {@code null} and is not large enough to hold the pixel data.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param obj a primitive array in which to return the pixel data or
! * {@code null}.
! * @param data the {@code DataBuffer} containing the image data.
! * @return an {@code Object} containing data for the specified
* pixel.
! * @exception ClassCastException if {@code obj} is not a
! * primitive array of type TransferType or is not {@code null}
* @exception ArrayIndexOutOfBoundsException if the coordinates are
! * not in bounds, or if {@code obj} is not {@code null} or
* not large enough to hold the pixel data
* @see #setDataElements(int, int, Object, DataBuffer)
*/
public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
*** 515,532 ****
return obj;
}
/**
* Returns the specified single band pixel in the first element
! * of an <code>int</code> array.
! * <code>ArrayIndexOutOfBoundsException</code> is thrown if the
* coordinates are not in bounds.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param iArray the array containing the pixel to be returned or
! * <code>null</code>
! * @param data the <code>DataBuffer</code> where image data is stored
* @return an array containing the specified pixel.
* @exception ArrayIndexOutOfBoundsException if the coordinates
* are not in bounds
* @see #setPixel(int, int, int[], DataBuffer)
*/
--- 515,532 ----
return obj;
}
/**
* Returns the specified single band pixel in the first element
! * of an {@code int} array.
! * {@code ArrayIndexOutOfBoundsException} is thrown if the
* coordinates are not in bounds.
* @param x the X coordinate of the specified pixel
* @param y the Y coordinate of the specified pixel
* @param iArray the array containing the pixel to be returned or
! * {@code null}
! * @param data the {@code DataBuffer} where image data is stored
* @return an array containing the specified pixel.
* @exception ArrayIndexOutOfBoundsException if the coordinates
* are not in bounds
* @see #setPixel(int, int, int[], DataBuffer)
*/
*** 549,594 ****
return pixels;
}
/**
* Sets the data for a single pixel in the specified
! * <code>DataBuffer</code> from a primitive array of type
! * TransferType. For a <code>MultiPixelPackedSampleModel</code>,
* only the first element of the array holds valid data,
* and the type must be the smallest of
* DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
* that can hold a single pixel.
* <p>
* The following code illustrates transferring data for one pixel from
! * <code>DataBuffer</code> <code>db1</code>, whose storage layout is
! * described by <code>MultiPixelPackedSampleModel</code>
! * <code>mppsm1</code>, to <code>DataBuffer</code> <code>db2</code>,
* whose storage layout is described by
! * <code>MultiPixelPackedSampleModel</code> <code>mppsm2</code>.
* The transfer is generally more efficient than using
! * <code>getPixel</code> or <code>setPixel</code>.
* <pre>
* MultiPixelPackedSampleModel mppsm1, mppsm2;
* DataBufferInt db1, db2;
* mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null,
* db1), db2);
* </pre>
! * Using <code>getDataElements</code> or <code>setDataElements</code> to
! * transfer between two <code>DataBuffer/SampleModel</code> pairs is
! * legitimate if the <code>SampleModel</code> objects have
* the same number of bands, corresponding bands have the same number of
* bits per sample, and the TransferTypes are the same.
* <p>
! * <code>obj</code> must be a primitive array of type TransferType.
! * Otherwise, a <code>ClassCastException</code> is thrown. An
! * <code>ArrayIndexOutOfBoundsException</code> is thrown if the
! * coordinates are not in bounds, or if <code>obj</code> is not large
* enough to hold the pixel data.
* @param x the X coordinate of the pixel location
* @param y the Y coordinate of the pixel location
* @param obj a primitive array containing pixel data
! * @param data the <code>DataBuffer</code> containing the image data
* @see #getDataElements(int, int, Object, DataBuffer)
*/
public void setDataElements(int x, int y, Object obj, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
throw new ArrayIndexOutOfBoundsException
--- 549,594 ----
return pixels;
}
/**
* Sets the data for a single pixel in the specified
! * {@code DataBuffer} from a primitive array of type
! * TransferType. For a {@code MultiPixelPackedSampleModel},
* only the first element of the array holds valid data,
* and the type must be the smallest of
* DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, or DataBuffer.TYPE_INT
* that can hold a single pixel.
* <p>
* The following code illustrates transferring data for one pixel from
! * {@code DataBuffer db1}, whose storage layout is
! * described by {@code MultiPixelPackedSampleModel}
! * {@code mppsm1}, to {@code DataBuffer db2},
* whose storage layout is described by
! * {@code MultiPixelPackedSampleModel mppsm2}.
* The transfer is generally more efficient than using
! * {@code getPixel} or {@code setPixel}.
* <pre>
* MultiPixelPackedSampleModel mppsm1, mppsm2;
* DataBufferInt db1, db2;
* mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null,
* db1), db2);
* </pre>
! * Using {@code getDataElements} or {@code setDataElements} to
! * transfer between two {@code DataBuffer/SampleModel} pairs is
! * legitimate if the {@code SampleModel} objects have
* the same number of bands, corresponding bands have the same number of
* bits per sample, and the TransferTypes are the same.
* <p>
! * {@code obj} must be a primitive array of type TransferType.
! * Otherwise, a {@code ClassCastException} is thrown. An
! * {@code ArrayIndexOutOfBoundsException} is thrown if the
! * coordinates are not in bounds, or if {@code obj} is not large
* enough to hold the pixel data.
* @param x the X coordinate of the pixel location
* @param y the Y coordinate of the pixel location
* @param obj a primitive array containing pixel data
! * @param data the {@code DataBuffer} containing the image data
* @see #getDataElements(int, int, Object, DataBuffer)
*/
public void setDataElements(int x, int y, Object obj, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
throw new ArrayIndexOutOfBoundsException
*** 627,644 ****
break;
}
}
/**
! * Sets a pixel in the <code>DataBuffer</code> using an
! * <code>int</code> array for input.
! * <code>ArrayIndexOutOfBoundsException</code> is thrown if
* the coordinates are not in bounds.
* @param x the X coordinate of the pixel location
* @param y the Y coordinate of the pixel location
! * @param iArray the input pixel in an <code>int</code> array
! * @param data the <code>DataBuffer</code> containing the image data
* @see #getPixel(int, int, int[], DataBuffer)
*/
public void setPixel(int x, int y, int[] iArray, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
throw new ArrayIndexOutOfBoundsException
--- 627,644 ----
break;
}
}
/**
! * Sets a pixel in the {@code DataBuffer} using an
! * {@code int} array for input.
! * {@code ArrayIndexOutOfBoundsException} is thrown if
* the coordinates are not in bounds.
* @param x the X coordinate of the pixel location
* @param y the Y coordinate of the pixel location
! * @param iArray the input pixel in an {@code int} array
! * @param data the {@code DataBuffer} containing the image data
* @see #getPixel(int, int, int[], DataBuffer)
*/
public void setPixel(int x, int y, int[] iArray, DataBuffer data) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
throw new ArrayIndexOutOfBoundsException
< prev index next >