- 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, yfromDataBufferdataand 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);
-
-
Constructor Summary
Constructors Constructor and 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 Summary
Methods Modifier and Type Method and 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.booleanequals(Object o)Indicates whether some other object is "equal to" this one.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.inthashCode()Returns a hash code value for the object.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 inherited from class java.awt.image.SampleModel
getDataElements, 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
-
MultiPixelPackedSampleModel
public 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 samplesw- the width, in pixels, of the region of image data describedh- the height, in pixels, of the region of image data describednumberOfBits- the number of bits per pixel- Throws:
IllegalArgumentException- ifdataTypeis not eitherDataBuffer.TYPE_BYTE,DataBuffer.TYPE_USHORT, orDataBuffer.TYPE_INT
-
MultiPixelPackedSampleModel
public 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 samplesw- the width, in pixels, of the region of image data describedh- the height, in pixels, of the region of image data describednumberOfBits- the number of bits per pixelscanlineStride- the line stride of the image datadataBitOffset- 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- ifworhis not greater than 0IllegalArgumentException- ifdataTypeis not eitherDataBuffer.TYPE_BYTE,DataBuffer.TYPE_USHORT, orDataBuffer.TYPE_INT
-
-
Method Detail
-
createCompatibleSampleModel
public 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 classSampleModel- Parameters:
w- the specified widthh- 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- ifworhis not greater than 0
-
createDataBuffer
public DataBuffer createDataBuffer()
Creates aDataBufferthat corresponds to thisMultiPixelPackedSampleModel. TheDataBufferobject's data type and size is consistent with thisMultiPixelPackedSampleModel. TheDataBufferhas a single bank.- Specified by:
createDataBufferin classSampleModel- Returns:
- a
DataBufferwith the same data type and size as thisMultiPixelPackedSampleModel.
-
getNumDataElements
public 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 classSampleModel- 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()
-
getSampleSize
public int[] getSampleSize()
Returns the number of bits per sample for all bands.- Specified by:
getSampleSizein classSampleModel- Returns:
- the number of bits per sample.
-
getSampleSize
public int getSampleSize(int band)
Returns the number of bits per sample for the specified band.- Specified by:
getSampleSizein classSampleModel- Parameters:
band- the specified band- Returns:
- the number of bits per sample for the specified band.
-
getOffset
public 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 pixely- the Y coordinate of the specified pixel- Returns:
- the offset of the specified pixel.
-
getBitOffset
public 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.
-
getScanlineStride
public int getScanlineStride()
Returns the scanline stride.- Returns:
- the scanline stride of this
MultiPixelPackedSampleModel.
-
getPixelBitStride
public 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.
-
getDataBitOffset
public int getDataBitOffset()
Returns the data bit offset in bits.- Returns:
- the
dataBitOffsetof thisMultiPixelPackedSampleModel.
-
getTransferType
public 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 classSampleModel- 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
-
createSubsetSampleModel
public 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 classSampleModel- 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- ifworhis not greater than 0
-
getSample
public 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 classSampleModel- Parameters:
x- the X coordinate of the specified pixely- the Y coordinate of the specified pixelb- the band to return, which is assumed to be 0data- theDataBuffercontaining the image data- Returns:
- the specified band containing the sample of the specified pixel.
- Throws:
ArrayIndexOutOfBoundException- if the specified coordinates are not in bounds.- See Also:
setSample(int, int, int, int, DataBuffer)
-
setSample
public 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 classSampleModel- Parameters:
x- the X coordinate of the specified pixely- the Y coordinate of the specified pixelb- the band to return, which is assumed to be 0s- the input sample as anintdata- theDataBufferwhere image data is stored- Throws:
ArrayIndexOutOfBoundsException- if the coordinates are not in bounds.- See Also:
getSample(int, int, int, DataBuffer)
-
getDataElements
public 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
DataBufferdb1, whose storage layout is described byMultiPixelPackedSampleModelmppsm1, toDataBufferdb2, whose storage layout is described byMultiPixelPackedSampleModelmppsm2. 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 classSampleModel- Parameters:
x- the X coordinate of the specified pixely- the Y coordinate of the specified pixelobj- a primitive array in which to return the pixel data ornull.data- theDataBuffercontaining the image data.- Returns:
- an
Objectcontaining data for the specified pixel. - Throws:
ClassCastException- ifobjis not a primitive array of type TransferType or is notnullArrayIndexOutOfBoundsException- if the coordinates are not in bounds, or ifobjis notnullor not large enough to hold the pixel data- See Also:
setDataElements(int, int, Object, DataBuffer)
-
getPixel
public 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 classSampleModel- Parameters:
x- the X coordinate of the specified pixely- the Y coordinate of the specified pixeliArray- the array containing the pixel to be returned ornulldata- theDataBufferwhere 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)
-
setDataElements
public 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
DataBufferdb1, whose storage layout is described byMultiPixelPackedSampleModelmppsm1, toDataBufferdb2, whose storage layout is described byMultiPixelPackedSampleModelmppsm2. 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 classSampleModel- Parameters:
x- the X coordinate of the pixel locationy- the Y coordinate of the pixel locationobj- a primitive array containing pixel datadata- theDataBuffercontaining the image data- See Also:
getDataElements(int, int, Object, DataBuffer)
-
setPixel
public 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 classSampleModel- Parameters:
x- the X coordinate of the pixel locationy- the Y coordinate of the pixel locationiArray- the input pixel in anintarraydata- theDataBuffercontaining the image data- See Also:
getPixel(int, int, int[], DataBuffer)
-
equals
public boolean equals(Object o)
Description copied from class:ObjectIndicates whether some other object is "equal to" this one.The
equalsmethod implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The
equalsmethod for classObjectimplements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesxandy, this method returnstrueif and only ifxandyrefer to the same object (x == yhas the valuetrue).Note that it is generally necessary to override the
hashCodemethod whenever this method is overridden, so as to maintain the general contract for thehashCodemethod, which states that equal objects must have equal hash codes.- Overrides:
equalsin classObject- Parameters:
o- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
- It is reflexive: for any non-null reference value
-
hashCode
public int hashCode()
Description copied from class:ObjectReturns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap.The general contract of
hashCodeis:- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
Object.equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class
Objectdoes return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
09/10/2025 08:58:13 Cette version de la page est en cache (à la date du 09/10/2025 08:58:13) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 31/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/awt/image/MultiPixelPackedSampleModel.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.