Class MultiBandsIndexColorModel

java.lang.Object
java.awt.image.ColorModel
java.awt.image.IndexColorModel
org.apache.sis.internal.coverage.j2d.MultiBandsIndexColorModel
All Implemented Interfaces:
Transparency

final class MultiBandsIndexColorModel extends IndexColorModel
An IndexColorModel tolerant with image having more than one band. This class can support only the types supported by IndexColorModel parent class. As of Java 14 they are restricted to DataBuffer.TYPE_BYTE and DataBuffer#TYPE_USHORT.

Reminder: ColorModel.getNumComponents() will return 3 or 4 no matter how many bands were specified to the constructor. This is not specific to this class; IndexColorModel behave that way. So we cannot rely on this method for checking the number of bands.

Since:
1.0
Version:
1.1
  • Field Details

    • numBands

      final int numBands
      The number of bands.
    • visibleBand

      final int visibleBand
      The visible band.
  • Constructor Details

    • MultiBandsIndexColorModel

      public MultiBandsIndexColorModel(int bits, int size, int[] cmap, int start, boolean hasAlpha, int transparent, int transferType, int numBands, int visibleBand)
      Constructs an index color model with the specified properties.
      Parameters:
      bits - the number of bits each pixel occupies.
      size - the size of the color component arrays.
      cmap - the array of color components.
      start - the starting offset of the first color component.
      hasAlpha - indicates whether alpha values are contained in the cmap array.
      transparent - The index of the fully transparent pixel.
      transferType - The data type of the array used to represent pixel values.
      numBands - the number of bands.
      visibleBand - the band to display.
      Throws:
      IllegalArgumentException - if bits is less than 1 or greater than 16.
      IllegalArgumentException - if size is less than 1.
      IllegalArgumentException - if transferType is not one of DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT.
  • Method Details

    • createSubsetColorModel

      final IndexColorModel createSubsetColorModel(int[] bands)
      Creates a new color model with only a subset of the bands in this color model.

      Note: the new color model will use a copy of the color map of this color model. There is no way to share the int[] array of ARGB values between two IndexColorModels.

    • getARGB

      private int[] getARGB()
      Returns all ARGB colors in this color model. This is a copy of the cmap used by this color model.
    • getDataElements

      public Object getDataElements(int RGB, Object pixel)
      Converts a RGB color to a representation of a pixel in this color model. This method returns an array with a length equal to the number of bands specified to the constructor (IndexColorModel would returns an array of length 1). All array elements are set to the same value. Replicating the pixel value is a somewhat arbitrary choice, but this choice makes this image appears as a gray scale image if the underlying DataBuffer were displayed again with a RGB color model instead of this one. Such a gray scale image seems more neutral than an image where only the Red component would vary.

      All other getDataElement(…) methods in this color model are ultimately defined in terms of this method, so overriding this method if needed should be enough.

      Overrides:
      getDataElements in class IndexColorModel
    • pixel

      private int pixel(Object inData)
      Returns the pixel value as an integer.
    • getComponents

      public int[] getComponents(Object pixel, int[] components, int offset)
      Returns an array of unnormalized color/alpha components for a specified pixel in this color model. This method is the converse of getDataElements(int, Object).
      Overrides:
      getComponents in class IndexColorModel
    • getRed

      public int getRed(Object inData)
      Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace.
      Overrides:
      getRed in class ColorModel
    • getGreen

      public int getGreen(Object inData)
      Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace.
      Overrides:
      getGreen in class ColorModel
    • getBlue

      public int getBlue(Object inData)
      Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGB ColorSpace.
      Overrides:
      getBlue in class ColorModel
    • getAlpha

      public int getAlpha(Object inData)
      Returns the alpha component for the specified pixel, scaled from 0 to 255.
      Overrides:
      getAlpha in class ColorModel
    • createCompatibleWritableRaster

      public WritableRaster createCompatibleWritableRaster(int width, int height)
      Creates a WritableRaster with the specified width and height that has a data layout (SampleModel) compatible with this ColorModel. The difference with standard implementation is that this method creates a banded raster on the assumption that the number of bands is greater than 1. By contrast, the standard implementation provides various optimizations for one-banded raster.
      Overrides:
      createCompatibleWritableRaster in class IndexColorModel
    • createCompatibleSampleModel

      public SampleModel createCompatibleSampleModel(int width, int height)
      Creates a SampleModel with the specified width and height that has a data layout compatible with this ColorModel.
      Overrides:
      createCompatibleSampleModel in class IndexColorModel
    • isCompatibleRaster

      public boolean isCompatibleRaster(Raster raster)
      Returns true if raster is compatible with this ColorModel. This method performs the same checks than the standard implementation except for the number of bands, which is required to be equal to numBands instead of 1. The actual checks are delegated to isCompatibleSampleModel(SampleModel) instead of duplicated in this method.
      Overrides:
      isCompatibleRaster in class IndexColorModel
    • isCompatibleSampleModel

      public boolean isCompatibleSampleModel(SampleModel sm)
      Checks if the specified SampleModel is compatible with this ColorModel. This method performs the same checks than the standard implementation except for the number of bands and for not accepting MultiPixelPackedSampleModel.
      Overrides:
      isCompatibleSampleModel in class IndexColorModel