Package ghidra.util

Class ColorUtils

java.lang.Object
ghidra.util.ColorUtils

public class ColorUtils extends Object
  • Field Details

  • 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
    • hasSameRgb

      public static boolean hasSameRgb(Color c1, Color c2)
      Returns true if both colors are not null and have the same RGB value. This is useful to compare colors that may have different classes, such as Color and GColor.
      Parameters:
      c1 - the first color
      c2 - the second color
      Returns:
      true if the colors have the same RGB value