Class RasterFactory
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.coverage.j2d.RasterFactory
Creates rasters from given properties. Contains also convenience methods for
creating
BufferedImage since that kind of images wraps a single raster.- Since:
- 1.0
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final WeakHashSet<SampleModel>Shared instances ofSampleModels. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BuffercreateBuffer(DataType dataType, int capacity) Creates a NIO buffer of the specified capacity.static BufferedImagecreateGrayScaleImage(int dataType, int width, int height, int numComponents, int visibleBand, double minimum, double maximum) Creates an opaque image with a gray scale color model.static WritableRastercreateRaster(DataBuffer buffer, int width, int height, int pixelStride, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location) Wraps the given data buffer in a raster.(package private) static <T extends SampleModel>
Tunique(T sampleModel) Returns a unique instance of the given sample model.static DataBufferWraps the backing arrays of given NIO buffers into Java2D buffers.
-
Field Details
-
POOL
Shared instances ofSampleModels.- See Also:
-
-
Constructor Details
-
RasterFactory
private RasterFactory()Do not allow instantiation of this class.
-
-
Method Details
-
createGrayScaleImage
public static BufferedImage createGrayScaleImage(int dataType, int width, int height, int numComponents, int visibleBand, double minimum, double maximum) Creates an opaque image with a gray scale color model. The image can have an arbitrary number of bands, but in current implementation only one band is used.Warning: displaying this image is very slow, except in a few special cases. It should be used only when no standard color model can be used.
- Parameters:
dataType- the buffer type as one ofDataBuffer.TYPE_*constants.width- the desired image width.height- the desired image height.numComponents- the number of components.visibleBand- the band to use for computing colors.minimum- the minimal sample value expected.maximum- the maximal sample value expected.- Returns:
- the color space for the given range of values.
-
createRaster
public static WritableRaster createRaster(DataBuffer buffer, int width, int height, int pixelStride, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location) Wraps the given data buffer in a raster. The sample model type is selected according the number of bands and the pixel stride. The number of bands is determined bybandOffsets.length, which should be one of followings:- For banded sample model, all
bandOffsetscan be zero. - For interleaved sample model (
buffer.getNumBanks()= 1), each band needs a different offset. They may be 0, 1, 2, 3….
- Parameters:
buffer- buffer that contains the sample values.width- raster width in pixels.height- raster height in pixels.pixelStride- number of data elements between two samples for the same band on the same line.scanlineStride- number of data elements between a given sample and the corresponding sample in the same column of the next line.bankIndices- bank indices for each band, ornullfor 0, 1, 2, 3….bandOffsets- number of data elements from the first element of the bank to the first sample of the band.location- the upper-left corner of the raster, ornullfor (0,0).- Returns:
- a raster built from given properties.
- Throws:
NullPointerException- ifbufferisnull.RasterFormatException- if the width or height is less than or equal to zero, or if there is an integer overflow.- See Also:
- For banded sample model, all
-
createBuffer
Creates a NIO buffer of the specified capacity. The buffer position will be 0 and its limit will be its capacity.- Parameters:
dataType- type of buffer to create.capacity- theBuffersize.- Returns:
- buffer of the specified type and size.
-
wrap
Wraps the backing arrays of given NIO buffers into Java2D buffers. This method wraps the underlying array of primitive types; data are not copied. For each buffer, the data starts at buffer position and ends at limit.- Parameters:
dataType- type of buffer to create.data- the data, one for each band.- Returns:
- buffer of the given type (never null).
- Throws:
UnsupportedOperationException- if a buffer is not backed by an accessible array.ReadOnlyBufferException- if a buffer is backed by an array but is read-only.ArrayStoreException- if the type of a backing array is notdataType.ArithmeticException- if a buffer position overflows the 32 bits integer capacity.RasterFormatException- if buffers do not have the same amount of remaining values.
-
unique
Returns a unique instance of the given sample model. This method can be invoked after a new sample has been created in order to share the same instance for many similarRasterinstances.- Type Parameters:
T- the type of the givensampleModel.- Parameters:
sampleModel- the sample model to make unique.- Returns:
- a unique instance of the given sample model. May be
sampleModelitself.
-