Class RasterFactory

java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.coverage.j2d.RasterFactory

public final class RasterFactory extends Static
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 Details

  • 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 of DataBuffer.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 by bandOffsets.length, which should be one of followings:
      • For banded sample model, all bandOffsets can 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, or null for 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, or null for (0,0).
      Returns:
      a raster built from given properties.
      Throws:
      NullPointerException - if buffer is null.
      RasterFormatException - if the width or height is less than or equal to zero, or if there is an integer overflow.
      See Also:
    • createBuffer

      public static Buffer createBuffer(DataType dataType, int capacity)
      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 - the Buffer size.
      Returns:
      buffer of the specified type and size.
    • wrap

      public static DataBuffer wrap(DataType dataType, Buffer... data)
      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 not dataType.
      ArithmeticException - if a buffer position overflows the 32 bits integer capacity.
      RasterFormatException - if buffers do not have the same amount of remaining values.
    • unique

      static <T extends SampleModel> T unique(T sampleModel)
      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 similar Raster instances.
      Type Parameters:
      T - the type of the given sampleModel.
      Parameters:
      sampleModel - the sample model to make unique.
      Returns:
      a unique instance of the given sample model. May be sampleModel itself.