Package ghidra.util

# Class ColorUtils

java.lang.Object
ghidra.util.ColorUtils

public class ColorUtils extends Object

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `ColorUtils.ColorBlender`
  Blender of colors

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static Comparator<Color>`
  `COMPARATOR`
  A color `Comparator` for ordering colors.
  `static final float`
  `HUE_BLUE`
  `static final float`
  `HUE_GREEN`
  `static final float`
  `HUE_LIME`
  `static final float`
  `HUE_ORANGE`
  `static final float`
  `HUE_PINE`
  `static final float`
  `HUE_PINK`
  `static final float`
  `HUE_PURPLE`
  `static final float`
  `HUE_RED`
  `static final float`
  `HUE_ROYAL`
  `static final float`
  `HUE_SAPPHIRE`
  `static final float`
  `HUE_TURQUISE`
  `static final float`
  `HUE_YELLOW`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ColorUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Color`
  `addColors(Color primary, Color secondary)`
  Combines colors in a way the makes them stand out from each other more than just averaging them together.
  `static Color`
  `average(Color color1, Color color2)`
  Creates a new color by averaging the red, green, blue, and alpha values from the given colors.
  `static Color`
  `blend(Color c1, Color c2, double ratio)`
  Takes the first color, blending into it the second color, using the given ratio.
  `static Color`
  `contrastForegroundColor(Color color)`
  A method to produce a color (either black or white) that contrasts with the given color.
  `static Color`
  `deriveBackground(Color background, float hue)`
  `static Color`
  `deriveBackground(Color src, float hue, float sfact, float bfact)`
  `static Color`
  `deriveForeground(Color bg, float hue)`
  `static Color`
  `deriveForeground(Color bg, float hue, float brt)`
  `static Color`
  `getColor(int rgba)`
  Return the color object given a rgba value that includes the desired alpha value.
  `static Color`
  `getColor(int red, int green, int blue)`
  Return an opaque color object given for the given red, green, and blue values.
  `static Color`
  `getColor(int red, int green, int blue, int alpha)`
  Return the color object given for the given red, green, blue, and alpha values.
  `static Color`
  `getOpaqueColor(int rgb)`
  Returns an opaque color with the given rgb value.
  `static Color`
  `withAlpha(Color c, int alpha)`
  Returns a new color that is comprised of the given color's rgb value and the given alpha value.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### HUE_RED

    public static final float HUE_RED
    See Also:
      - Constant Field Values

  - ### HUE_ORANGE

    public static final float HUE_ORANGE
    See Also:
      - Constant Field Values

  - ### HUE_YELLOW

    public static final float HUE_YELLOW
    See Also:
      - Constant Field Values

  - ### HUE_LIME

    public static final float HUE_LIME
    See Also:
      - Constant Field Values

  - ### HUE_GREEN

    public static final float HUE_GREEN
    See Also:
      - Constant Field Values

  - ### HUE_PINE

    public static final float HUE_PINE
    See Also:
      - Constant Field Values

  - ### HUE_TURQUISE

    public static final float HUE_TURQUISE
    See Also:
      - Constant Field Values

  - ### HUE_SAPPHIRE

    public static final float HUE_SAPPHIRE
    See Also:
      - Constant Field Values

  - ### HUE_BLUE

    public static final float HUE_BLUE
    See Also:
      - Constant Field Values

  - ### HUE_ROYAL

    public static final float HUE_ROYAL
    See Also:
      - Constant Field Values

  - ### HUE_PURPLE

    public static final float HUE_PURPLE
    See Also:
      - Constant Field Values

  - ### HUE_PINK

    public static final float HUE_PINK
    See Also:
      - Constant Field Values

  - ### COMPARATOR

    public static Comparator<Color> COMPARATOR
    A color `Comparator` for ordering colors.

- ## Constructor Details

  - ### ColorUtils

    public ColorUtils()

- ## Method Details

  - ### deriveBackground

    public static Color deriveBackground(Color src, float hue, float sfact, float bfact)

  - ### deriveBackground

    public static Color deriveBackground(Color background, float hue)

  - ### deriveForeground

    public static Color deriveForeground(Color bg, float hue, float brt)

  - ### deriveForeground

    public static Color deriveForeground(Color bg, float hue)

  - ### contrastForegroundColor

    public static Color contrastForegroundColor(Color color)
    A method to produce a color (either black or white) that contrasts with the given color. This is useful for finding a readable foreground color for a given background.
    Parameters:
      `color` - the color for which to find a contrast.
    Returns:
      the contrasting color.

  - ### blend

    public static Color blend(Color c1, Color c2, double ratio)
    Takes the first color, blending into it the second color, using the given ratio. A lower ratio (say .1f) signals to use very little of the first color; a larger ratio signals to use more of the first color.
    Parameters:
      `c1` - the first color
      `c2` - the second color
      `ratio` - the amount of the first color to include in the final output
    Returns:
      the new color

  - ### addColors

    public static Color addColors(Color primary, Color secondary)
    Combines colors in a way the makes them stand out from each other more than just averaging them together. Basically if the colors are bright, the result is a darker value than the primary, adjusted based on the values in the secondary. If the colors are dark, then the result is a brighter version of the primary color adjusted based on values in the secondary color.
    Parameters:
      `primary` - the primary color to be tweaked
      `secondary` - the color to used to determine the amount to tweak the red,green,blue values
    Returns:
      a new color that is a combination of the two colors

  - ### withAlpha

    public static Color withAlpha(Color c, int alpha)
    Returns a new color that is comprised of the given color's rgb value and the given alpha value.
    Parameters:
      `c` - the color
      `alpha` - the alpha
    Returns:
      the new color

  - ### getColor

    public static Color getColor(int rgba)
    Return the color object given a rgba value that includes the desired alpha value.
    Parameters:
      `rgba` - value where bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue
    Returns:
      the color object given a rgba value that includes the desired alpha value

  - ### getColor

    public static Color getColor(int red, int green, int blue)
    Return an opaque color object given for the given red, green, and blue values.
    Parameters:
      `red` - the red value (0 - 255)
      `green` - the green value (0 - 255)
      `blue` - the blue value (0 - 255)
    Returns:
      the color object for the given values

  - ### getColor

    public static Color getColor(int red, int green, int blue, int alpha)
    Return the color object given for the given red, green, blue, and alpha values.
    Parameters:
      `red` - the red value (0 - 255)
      `green` - the green value (0 - 255)
      `blue` - the blue value (0 - 255)
      `alpha` - the alpha (transparency) value (0 - 255) with 0 being fully transparent and 255 being fully opaque opaque
    Returns:
      the color object for the given values

  - ### getOpaqueColor

    public static Color getOpaqueColor(int rgb)
    Returns an opaque color with the given rgb value. The resulting color will have an alpha value of 0xff.
    Parameters:
      `rgb` - the value where bits 16-23 are red, 8-15 are green, 0-7 are blue. Bits 24-31 will be set to 0xff.
    Returns:
      an opaque color with the given rgb value

  - ### average

    public static Color average(Color color1, Color color2)
    Creates a new color by averaging the red, green, blue, and alpha values from the given colors.
    Parameters:
      `color1` - the first color to average
      `color2` - the second color to average
    Returns:
      a new color that is the average of the two given colors