Class SampleModelFactory
java.lang.Object
org.apache.sis.internal.coverage.j2d.SampleModelFactory
A factory for
SampleModel
instances. This class provides a convenient way to get the properties
of an existing sample model, modify them, then create a new sample model with the modified properties.- Since:
- 1.1
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]
Offsets for all bands in data array elements, ornull
if not applicable.private int[]
Index for each bank storing a band of image data, ornull
if not applicable.private int[]
The bit masks for all bands, ornull
if not applicable.private int
The bit offset into the data array where the first pixel begins.private int
Type of sample values as one of theDataBuffer
constants.private final int
Width and height in pixels of tiles using the sample model.private int
Number of bands of the image data.private int
Number of bits per pixel, or 0 if not applicable.private int
Number of sample values to advance for moving to next pixel.private int
Number of sample values to advance for moving to next line.private final int
Width and height in pixels of tiles using the sample model. -
Constructor Summary
ConstructorsConstructorDescriptionSampleModelFactory
(SampleModel model) Creates a new factory initialized to the value of given sample model.SampleModelFactory
(DataType type, int width, int height, int numBands, int bitsPerSample, boolean isBanded) Creates a factory initialized to the given values. -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
bitCount
(int mask) Returns the number of bits in the given mask.build()
Builds a sample model based on current factory configuration.private static int[]
subset
(int[] data, int[] bands, boolean compress) Creates a subset of thedata
arrays for the specified bands.void
subsetAndCompress
(int[] bands) Requests a sample model with only a subset of the bands of the original sample model.
-
Field Details
-
dataType
private int dataTypeType of sample values as one of theDataBuffer
constants. -
width
private final int widthWidth and height in pixels of tiles using the sample model.Warning: changing sample model size has non-obvious implications in
BandedSampleModel
case when all data are in a single bank. TheSampleModel.createCompatibleSampleModel(int, int)
method should be preferred instead. -
height
private final int heightWidth and height in pixels of tiles using the sample model.Warning: changing sample model size has non-obvious implications in
BandedSampleModel
case when all data are in a single bank. TheSampleModel.createCompatibleSampleModel(int, int)
method should be preferred instead. -
numBands
private int numBandsNumber of bands of the image data. Note: do not confuse bands and banks. -
bankIndices
private int[] bankIndicesIndex for each bank storing a band of image data, ornull
if not applicable. -
bandOffsets
private int[] bandOffsetsOffsets for all bands in data array elements, ornull
if not applicable. -
bitMasks
private int[] bitMasksThe bit masks for all bands, ornull
if not applicable. -
dataBitOffset
private int dataBitOffsetThe bit offset into the data array where the first pixel begins. -
numberOfBits
private int numberOfBitsNumber of bits per pixel, or 0 if not applicable. Also known as "pixel bit stride". -
pixelStride
private int pixelStrideNumber of sample values to advance for moving to next pixel. This is 0 whennumberOfBits
should be used instead. -
scanlineStride
private int scanlineStrideNumber of sample values to advance for moving to next line.
-
-
Constructor Details
-
SampleModelFactory
public SampleModelFactory(DataType type, int width, int height, int numBands, int bitsPerSample, boolean isBanded) Creates a factory initialized to the given values.- Parameters:
type
- type of sample values.width
- tile width in pixels.height
- tile height in pixels.numBands
- number of bands.bitsPerSample
- number of bits per sample values.isBanded
-true
if each band is stored in a separated bank.- Throws:
RasterFormatException
- if the arguments imply a sample model of unsupported type.
-
SampleModelFactory
Creates a new factory initialized to the value of given sample model.- Parameters:
model
- the sample model from which to copy values.- Throws:
RasterFormatException
- if the type of the given sample model is not supported.
-
-
Method Details
-
subsetAndCompress
public void subsetAndCompress(int[] bands) Requests a sample model with only a subset of the bands of the original sample model. Special cases:- For
SinglePixelPackedSampleModel
, this method may change the data type if decreasing the number of bands make possible to store pixels in smaller integers.
Comparison with standard method
The standardSampleModel.createSubsetSampleModel(int[])
method also selects a subset of the bands. However, that standard method creates a sample model accepting the sameDataBuffer
than the originalSampleModel
, which is useful for creating a view of image data that are already in memory. By contrast, thisBandSelector
compresses bank indices or pixel masks for leaving no empty space between them. This is useful when done before loading data from a file in order to avoid consuming space for bands that were not requested.- Parameters:
bands
- bands to keep.- See Also:
- For
-
bitCount
private static int bitCount(int mask) Returns the number of bits in the given mask. All bits between the first and last bits are considered set to 1. This is intentional, because masks shall not overlap.- See Also:
-
subset
private static int[] subset(int[] data, int[] bands, boolean compress) Creates a subset of thedata
arrays for the specified bands. Ifcompress
istrue
, then sequences such as {1, 3, 4, 6, …} are replaced by {0, 1, 2, 3, …} (not necessarily in increasing order). -
build
Builds a sample model based on current factory configuration. The factory is still valid after this method call.- Returns:
- the sample model built from current factory configuration.
- Throws:
IllegalArgumentException
- if an error occurred while building a sample model.
-