- java.lang.Object
- 
- java.awt.image.SampleModel
- 
- java.awt.image.MultiPixelPackedSampleModel
 
 
- 
 public class MultiPixelPackedSampleModel extends SampleModel TheMultiPixelPackedSampleModelclass 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. Pixel bit stride is equal to the number of bits per pixel. Scanline stride is in data elements and the last several data elements might be padded with unused pixels. Data bit offset is the offset in bits from the beginning of theDataBufferto the first pixel and must be a multiple of pixel bit stride.The following code illustrates extracting the bits for pixel x, yfromDataBuffer dataand storing the pixel data in data elements of typedataType:int dataElementSize = DataBuffer.getDataTypeSize(dataType); int bitnum = dataBitOffset + x*pixelBitStride; int element = data.getElem(y*scanlineStride + bitnum/dataElementSize); int shift = dataElementSize - (bitnum & (dataElementSize-1)) - pixelBitStride; int pixel = (element >> shift) & ((1 << pixelBitStride) - 1);
- 
- 
Field Summary- 
Fields declared in class java.awt.image.SampleModeldataType, height, numBands, width
 
- 
 - 
Constructor SummaryConstructors Constructor Description MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits)Constructs aMultiPixelPackedSampleModelwith the specified data type, width, height and number of bits per pixel.MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits, int scanlineStride, int dataBitOffset)Constructs aMultiPixelPackedSampleModelwith specified data type, width, height, number of bits per pixel, scanline stride and data bit offset.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description SampleModelcreateCompatibleSampleModel(int w, int h)Creates a newMultiPixelPackedSampleModelwith the specified width and height.DataBuffercreateDataBuffer()Creates aDataBufferthat corresponds to thisMultiPixelPackedSampleModel.SampleModelcreateSubsetSampleModel(int[] bands)Creates a newMultiPixelPackedSampleModelwith a subset of the bands of thisMultiPixelPackedSampleModel.intgetBitOffset(int x)Returns the offset, in bits, into the data element in which it is stored for thexth pixel of a scanline.intgetDataBitOffset()Returns the data bit offset in bits.ObjectgetDataElements(int x, int y, Object obj, DataBuffer data)Returns data for a single pixel in a primitive array of type TransferType.intgetNumDataElements()Returns the number of data elements needed to transfer one pixel via thegetDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)andsetDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)methods.intgetOffset(int x, int y)Returns the offset of pixel (x, y) in data array elements.int[]getPixel(int x, int y, int[] iArray, DataBuffer data)Returns the specified single band pixel in the first element of anintarray.intgetPixelBitStride()Returns the pixel bit stride in bits.intgetSample(int x, int y, int b, DataBuffer data)Returns asintthe sample in a specified band for the pixel located at (x, y).int[]getSampleSize()Returns the number of bits per sample for all bands.intgetSampleSize(int band)Returns the number of bits per sample for the specified band.intgetScanlineStride()Returns the scanline stride.intgetTransferType()Returns the TransferType used to transfer pixels by way of thegetDataElementsandsetDataElementsmethods.voidsetDataElements(int x, int y, Object obj, DataBuffer data)Sets the data for a single pixel in the specifiedDataBufferfrom a primitive array of type TransferType.voidsetPixel(int x, int y, int[] iArray, DataBuffer data)Sets a pixel in theDataBufferusing anintarray for input.voidsetSample(int x, int y, int b, int s, DataBuffer data)Sets a sample in the specified band for the pixel located at (x, y) in theDataBufferusing anintfor input.- 
Methods declared in class java.awt.image.SampleModelgetDataElements, getDataType, getHeight, getNumBands, getPixel, getPixel, getPixels, getPixels, getPixels, getSampleDouble, getSampleFloat, getSamples, getSamples, getSamples, getWidth, setDataElements, setPixel, setPixel, setPixels, setPixels, setPixels, setSample, setSample, setSamples, setSamples, setSamples
 
- 
 
- 
- 
- 
Constructor Detail- 
MultiPixelPackedSampleModelpublic MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits)Constructs aMultiPixelPackedSampleModelwith the specified data type, width, height and number of bits per pixel.- Parameters:
- dataType- the data type for storing samples
- w- the width, in pixels, of the region of image data described
- h- the height, in pixels, of the region of image data described
- numberOfBits- the number of bits per pixel
- Throws:
- IllegalArgumentException- if- dataTypeis not either- DataBuffer.TYPE_BYTE,- DataBuffer.TYPE_USHORT, or- DataBuffer.TYPE_INT
 
 - 
MultiPixelPackedSampleModelpublic MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits, int scanlineStride, int dataBitOffset)Constructs aMultiPixelPackedSampleModelwith specified data type, width, height, number of bits per pixel, scanline stride and data bit offset.- Parameters:
- dataType- the data type for storing samples
- w- the width, in pixels, of the region of image data described
- h- the height, in pixels, of the region of image data described
- numberOfBits- the number of bits per pixel
- scanlineStride- the line stride of the image data
- dataBitOffset- the data bit offset for the region of image data described
- Throws:
- 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.
- IllegalArgumentException- if- wor- his not greater than 0
- IllegalArgumentException- if- dataTypeis not either- DataBuffer.TYPE_BYTE,- DataBuffer.TYPE_USHORT, or- DataBuffer.TYPE_INT
 
 
- 
 - 
Method Detail- 
createCompatibleSampleModelpublic SampleModel createCompatibleSampleModel(int w, int h) Creates a newMultiPixelPackedSampleModelwith the specified width and height. The newMultiPixelPackedSampleModelhas the same storage data type and number of bits per pixel as thisMultiPixelPackedSampleModel.- Specified by:
- createCompatibleSampleModelin class- SampleModel
- Parameters:
- w- the specified width
- h- the specified height
- Returns:
- a SampleModelwith the specified width and height and with the same storage data type and number of bits per pixel as thisMultiPixelPackedSampleModel.
- Throws:
- IllegalArgumentException- if- wor- his not greater than 0
 
 - 
createDataBufferpublic DataBuffer createDataBuffer() Creates aDataBufferthat corresponds to thisMultiPixelPackedSampleModel. TheDataBufferobject's data type and size is consistent with thisMultiPixelPackedSampleModel. TheDataBufferhas a single bank.- Specified by:
- createDataBufferin class- SampleModel
- Returns:
- a DataBufferwith the same data type and size as thisMultiPixelPackedSampleModel.
 
 - 
getNumDataElementspublic int getNumDataElements() Returns the number of data elements needed to transfer one pixel via thegetDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)andsetDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)methods. For aMultiPixelPackedSampleModel, this is one.- Specified by:
- getNumDataElementsin class- SampleModel
- Returns:
- the number of data elements.
- See Also:
- SampleModel.getDataElements(int, int, Object, DataBuffer),- SampleModel.getDataElements(int, int, int, int, Object, DataBuffer),- SampleModel.setDataElements(int, int, Object, DataBuffer),- SampleModel.setDataElements(int, int, int, int, Object, DataBuffer),- SampleModel.getTransferType()
 
 - 
getSampleSizepublic int[] getSampleSize() Returns the number of bits per sample for all bands.- Specified by:
- getSampleSizein class- SampleModel
- Returns:
- the number of bits per sample.
 
 - 
getSampleSizepublic int getSampleSize(int band) Returns the number of bits per sample for the specified band.- Specified by:
- getSampleSizein class- SampleModel
- Parameters:
- band- the specified band
- Returns:
- the number of bits per sample for the specified band.
 
 - 
getOffsetpublic int getOffset(int x, int y)Returns the offset of pixel (x, y) in data array elements.- Parameters:
- x- the X coordinate of the specified pixel
- y- the Y coordinate of the specified pixel
- Returns:
- the offset of the specified pixel.
 
 - 
getBitOffsetpublic int getBitOffset(int x) Returns the offset, in bits, into the data element in which it is stored for thexth pixel of a scanline. This offset is the same for all scanlines.- Parameters:
- x- the specified pixel
- Returns:
- the bit offset of the specified pixel.
 
 - 
getScanlineStridepublic int getScanlineStride() Returns the scanline stride.- Returns:
- the scanline stride of this
 MultiPixelPackedSampleModel.
 
 - 
getPixelBitStridepublic int getPixelBitStride() Returns the pixel bit stride in bits. This value is the same as the number of bits per pixel.- Returns:
- the pixelBitStrideof thisMultiPixelPackedSampleModel.
 
 - 
getDataBitOffsetpublic int getDataBitOffset() Returns the data bit offset in bits.- Returns:
- the dataBitOffsetof thisMultiPixelPackedSampleModel.
 
 - 
getTransferTypepublic int getTransferType() Returns the TransferType used to transfer pixels by way of thegetDataElementsandsetDataElementsmethods. 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.- Overrides:
- getTransferTypein class- SampleModel
- Returns:
- the transfertype.
- See Also:
- SampleModel.getDataElements(int, int, Object, DataBuffer),- SampleModel.getDataElements(int, int, int, int, Object, DataBuffer),- SampleModel.setDataElements(int, int, Object, DataBuffer),- SampleModel.setDataElements(int, int, int, int, Object, DataBuffer),- SampleModel.getNumDataElements(),- DataBuffer
 
 - 
createSubsetSampleModelpublic SampleModel createSubsetSampleModel(int[] bands) Creates a newMultiPixelPackedSampleModelwith a subset of the bands of thisMultiPixelPackedSampleModel. Since aMultiPixelPackedSampleModelonly has one band, the bands argument must have a length of one and indicate the zeroth band.- Specified by:
- createSubsetSampleModelin class- SampleModel
- Parameters:
- bands- the specified bands
- Returns:
- a new SampleModelwith a subset of bands of thisMultiPixelPackedSampleModel.
- Throws:
- RasterFormatException- if the number of bands requested is not one.
- IllegalArgumentException- if- wor- his not greater than 0
 
 - 
getSamplepublic int getSample(int x, int y, int b, DataBuffer data)Returns asintthe sample in a specified band for the pixel located at (x, y). AnArrayIndexOutOfBoundsExceptionis thrown if the coordinates are not in bounds.- Specified by:
- getSamplein class- SampleModel
- Parameters:
- x- the X coordinate of the specified pixel
- y- the Y coordinate of the specified pixel
- b- the band to return, which is assumed to be 0
- data- the- DataBuffercontaining the image data
- Returns:
- the specified band containing the sample of the specified pixel.
- Throws:
- ArrayIndexOutOfBoundsException- if the specified coordinates are not in bounds.
- See Also:
- setSample(int, int, int, int, DataBuffer)
 
 - 
setSamplepublic void setSample(int x, int y, int b, int s, DataBuffer data)Sets a sample in the specified band for the pixel located at (x, y) in theDataBufferusing anintfor input. AnArrayIndexOutOfBoundsExceptionis thrown if the coordinates are not in bounds.- Specified by:
- setSamplein class- SampleModel
- Parameters:
- x- the X coordinate of the specified pixel
- y- the Y coordinate of the specified pixel
- b- the band to return, which is assumed to be 0
- s- the input sample as an- int
- data- the- DataBufferwhere image data is stored
- Throws:
- ArrayIndexOutOfBoundsException- if the coordinates are not in bounds.
- See Also:
- getSample(int, int, int, DataBuffer)
 
 - 
getDataElementspublic Object getDataElements(int x, int y, Object obj, DataBuffer data) Returns data for a single pixel in a primitive array of type TransferType. For aMultiPixelPackedSampleModel, 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,objshould be passed in asnull, so that theObjectis created automatically and is the correct primitive data type.The following code illustrates transferring data for one pixel from DataBuffer db1, whose storage layout is described byMultiPixelPackedSampleModelmppsm1, toDataBuffer db2, whose storage layout is described byMultiPixelPackedSampleModel mppsm2. The transfer is generally more efficient than usinggetPixelorsetPixel.MultiPixelPackedSampleModel mppsm1, mppsm2; DataBufferInt db1, db2; mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null, db1), db2);UsinggetDataElementsorsetDataElementsto transfer between twoDataBuffer/SampleModelpairs is legitimate if theSampleModelshave the same number of bands, corresponding bands have the same number of bits per sample, and the TransferTypes are the same.If objis notnull, it should be a primitive array of type TransferType. Otherwise, aClassCastExceptionis thrown. AnArrayIndexOutOfBoundsExceptionis thrown if the coordinates are not in bounds, or ifobjis notnulland is not large enough to hold the pixel data.- Specified by:
- getDataElementsin class- SampleModel
- Parameters:
- x- the X coordinate of the specified pixel
- y- the Y coordinate of the specified pixel
- obj- a primitive array in which to return the pixel data or- null.
- data- the- DataBuffercontaining the image data.
- Returns:
- an Objectcontaining data for the specified pixel.
- Throws:
- ClassCastException- if- objis not a primitive array of type TransferType or is not- null
- ArrayIndexOutOfBoundsException- if the coordinates are not in bounds, or if- objis not- nullor not large enough to hold the pixel data
- See Also:
- setDataElements(int, int, Object, DataBuffer)
 
 - 
getPixelpublic int[] getPixel(int x, int y, int[] iArray, DataBuffer data)Returns the specified single band pixel in the first element of anintarray.ArrayIndexOutOfBoundsExceptionis thrown if the coordinates are not in bounds.- Overrides:
- getPixelin class- SampleModel
- Parameters:
- x- the X coordinate of the specified pixel
- y- the Y coordinate of the specified pixel
- iArray- the array containing the pixel to be returned or- null
- data- the- DataBufferwhere image data is stored
- Returns:
- an array containing the specified pixel.
- Throws:
- ArrayIndexOutOfBoundsException- if the coordinates are not in bounds
- See Also:
- setPixel(int, int, int[], DataBuffer)
 
 - 
setDataElementspublic void setDataElements(int x, int y, Object obj, DataBuffer data)Sets the data for a single pixel in the specifiedDataBufferfrom a primitive array of type TransferType. For aMultiPixelPackedSampleModel, 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.The following code illustrates transferring data for one pixel from DataBuffer db1, whose storage layout is described byMultiPixelPackedSampleModelmppsm1, toDataBuffer db2, whose storage layout is described byMultiPixelPackedSampleModel mppsm2. The transfer is generally more efficient than usinggetPixelorsetPixel.MultiPixelPackedSampleModel mppsm1, mppsm2; DataBufferInt db1, db2; mppsm2.setDataElements(x, y, mppsm1.getDataElements(x, y, null, db1), db2);UsinggetDataElementsorsetDataElementsto transfer between twoDataBuffer/SampleModelpairs is legitimate if theSampleModelobjects have the same number of bands, corresponding bands have the same number of bits per sample, and the TransferTypes are the same.objmust be a primitive array of type TransferType. Otherwise, aClassCastExceptionis thrown. AnArrayIndexOutOfBoundsExceptionis thrown if the coordinates are not in bounds, or ifobjis not large enough to hold the pixel data.- Specified by:
- setDataElementsin class- SampleModel
- Parameters:
- x- the X coordinate of the pixel location
- y- the Y coordinate of the pixel location
- obj- a primitive array containing pixel data
- data- the- DataBuffercontaining the image data
- See Also:
- getDataElements(int, int, Object, DataBuffer)
 
 - 
setPixelpublic void setPixel(int x, int y, int[] iArray, DataBuffer data)Sets a pixel in theDataBufferusing anintarray for input.ArrayIndexOutOfBoundsExceptionis thrown if the coordinates are not in bounds.- Overrides:
- setPixelin class- SampleModel
- Parameters:
- x- the X coordinate of the pixel location
- y- the Y coordinate of the pixel location
- iArray- the input pixel in an- intarray
- data- the- DataBuffercontaining the image data
- See Also:
- getPixel(int, int, int[], DataBuffer)
 
 
- 
 
-