Class ColorsForRange

java.lang.Object
org.apache.sis.internal.coverage.j2d.ColorsForRange
All Implemented Interfaces:
Comparable<ColorsForRange>

final class ColorsForRange extends Object implements Comparable<ColorsForRange>
Colors to apply on a range of sample values. Instances of ColorsForRange are temporary, used only the time needed for ColorModelFactory#createColorModel(int, int, int, ColorsForRange[]).
Since:
1.1
Version:
1.3
See Also:
  • ColorModelFactory#createColorModel(int, int, int, ColorsForRange[])
  • Field Details

    • name

      final CharSequence name
      A name identifying the range of values. the category name is used if available, otherwise this is a string representation of the range.
    • sampleRange

      NumberRange<?> sampleRange
      The range of sample values on which the colors will be applied. Shall never be null. May be updated after Colorizer.compact() mapped range of floating point values to range of IndexColorModel values.
    • colors

      private final Color[] colors
      The colors to apply on the range of sample values. A null or empty array means transparent.
    • isData

      final boolean isData
      true if this entry should be taken as data, or false if it should be ignored. Entry to ignore are entries associated to NaN values.
  • Constructor Details

    • ColorsForRange

      ColorsForRange(Category category, Function<Category,Color[]> colors)
      Creates a new instance for the given category.
      Parameters:
      category - the category for which this ColorsForRange is created, or null.
      colors - colors to apply on the category.
    • ColorsForRange

      ColorsForRange(CharSequence name, NumberRange<?> sampleRange, Color[] colors, boolean isData)
      Creates a new instance for the given range of values.
      Parameters:
      name - a name identifying the range of values, or null for automatic.
      sampleRange - range of sample values on which the colors will be applied.
      colors - colors to apply on the range of sample values, or null for transparent.
      isData - whether this entry should be taken as main data (not fill values).
  • Method Details

    • list

      static ColorsForRange[] list(Collection<Map.Entry<NumberRange<?>,Color[]>> colors)
      Converts map entries to an array of ColorsForRange entries. The #category of each entry is left to null.
      Parameters:
      colors - the colors to use for each range of sample values. A null entry value means transparent.
      Returns:
      colors to use for each range of values in the source image. Never null and does not contain null elements.
    • toString

      public String toString()
      Returns a string representation for debugging purposes.
      Overrides:
      toString in class Object
    • appendColorRange

      static void appendColorRange(StringBuilder buffer, int count, IntUnaryOperator colors)
      Appends the range of ARGB codes as hexadecimal values. If the count of ARGB codes is 0, then this method does nothing. If the count is 1, then this method formats the single value. If the count is 2 or more, then this method formats the first and last values.
      Parameters:
      buffer - where to append the range of ARGB codes.
      count - number of ARGB codes.
      colors - providers of ARGB codes for given indices.
    • compareTo

      public int compareTo(ColorsForRange other)
      Comparator for sorting entries by their alpha value. The intent is to have transparent colors first.
      Specified by:
      compareTo in interface Comparable<ColorsForRange>
      Parameters:
      other - the other instance to compare with this instance.
      Returns:
      -1 if this instance if more transparent, +1 if the other instance is more transparent, 0 if equal.
    • getAlpha

      private int getAlpha()
      Returns the maximal alpha value found in colors.
    • toARGB

      final int[] toARGB()
      Returns the ARGB codes for the colors. If all colors are transparent, returns an empty array.
      Returns:
      ARGB codes for the given colors. Never null but may be empty.