Class ColorToolsAwt

java.lang.Object
qupath.lib.color.ColorToolsAwt

public class ColorToolsAwt extends Object
Helper class for converting between packed RGB colors and Java's AWT representation, as well as creating some ColorModels for BufferedImages.
Author:
Pete Bankhead
  • Field Details

    • TRANSLUCENT_WHITE

      public static final Color TRANSLUCENT_WHITE
      White, with 50% opacity.
    • TRANSLUCENT_BLACK

      public static final Color TRANSLUCENT_BLACK
      Black, with 50% opacity.
  • Constructor Details

    • ColorToolsAwt

      public ColorToolsAwt()
  • Method Details

    • getCachedColor

      public static Color getCachedColor(int r, int g, int b, int a)
      Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).
      Parameters:
      r -
      g -
      b -
      a -
      Returns:
    • getCachedColor

      public static Color getCachedColor(int r, int g, int b)
      Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).
      Parameters:
      r -
      g -
      b -
      Returns:
    • getCachedColor

      public static Color getCachedColor(Integer rgb)
      Get cached color. Assumed not to have alpha set, unless the relevant bits are non-zero.
      Parameters:
      rgb -
      Returns:
    • getCachedColor

      public static Color getCachedColor(Integer rgb, boolean hasAlpha)
      Get cached color, explicitly stating whether alpha should be included or not.
      Parameters:
      rgb -
      hasAlpha -
      Returns:
    • getIndexColorModel

      public static IndexColorModel getIndexColorModel(StainVector stain, boolean whiteBackground)
      Get an IndexColorModel representing a color deconvolution stain. The color is just an approximation for visualization purposes, it does not perfectly match the stain itself.
      Parameters:
      stain - the stain to use
      whiteBackground - if true, the color model will have a white background; if false, it will have a black background
      Returns:
    • createIndexColorModel

      public static IndexColorModel createIndexColorModel(int red, int green, int blue, boolean whiteBackground)
      Get an IndexColorModel representing a linear LUT based on a RGB color.
      Parameters:
      red - the red value of the color for the maximum value
      green - the green value of the color for the maximum value
      blue - the blue value of the color for the maximum value
      whiteBackground - if true, the color model will have a white background; if false, it will have a black background
      Returns:
    • getIndexColorModel

      public static IndexColorModel getIndexColorModel(StainVector stain)
      Create an IndexColorModel, ranging from white (low values) to a stain vector color (high values).
      Parameters:
      stain -
      Returns:
    • getMoreTranslucentColor

      public static Color getMoreTranslucentColor(Color color)
      Get a (slightly more) translucent version of the specified color.

      If possible, a cached version will be used.

      Parameters:
      color -
      Returns:
      See Also:
    • darkenColor

      public static Color darkenColor(Color color)
      Get a (slightly) darker version of the specified color.

      If possible, a cached version will be used.

      Parameters:
      color -
      Returns:
    • getTranslucentColor

      public static Color getTranslucentColor(Color color)
      Get a (slightly) translucent version of the specified color.

      If possible, a cached version will be used.

      Parameters:
      color -
      Returns:
    • scaleColor

      public static Color scaleColor(Color color, double factor)
      Get a scaled version of the specified color, where the RGB values are independently scaled by a specified factor.

      The alpha value is preserved unchanged.

      Parameters:
      color -
      factor -
      Returns:
    • getColorWithOpacity

      public static Color getColorWithOpacity(Integer rgb, double opacity)
      Get a color with a specified opacity, based on the packed RGB values in an Integer.
      Parameters:
      rgb -
      opacity -
      Returns:
    • getColorWithOpacity

      public static Color getColorWithOpacity(Color color, double opacity)
      Get a color with a specified opacity, setting the alpha channel accordingly.
      Parameters:
      color -
      opacity -
      Returns: