Package icyllis.modernui.graphics

# Class Color

java.lang.Object
icyllis.modernui.graphics.Color

public class Color extends Object

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `COLOR_CHANNEL_A`
  Describes different color channels one can manipulate.
  `static final int`
  `COLOR_CHANNEL_B`
  Describes different color channels one can manipulate.
  `static final int`
  `COLOR_CHANNEL_FLAG_ALPHA`
  Used to represent the channels available in a color type or texture format as a mask.
  `static final int`
  `COLOR_CHANNEL_FLAG_BLUE`
  Used to represent the channels available in a color type or texture format as a mask.
  `static final int`
  `COLOR_CHANNEL_FLAG_GRAY`
  Used to represent the channels available in a color type or texture format as a mask.
  `static final int`
  `COLOR_CHANNEL_FLAG_GREEN`
  Used to represent the channels available in a color type or texture format as a mask.
  `static final int`
  `COLOR_CHANNEL_FLAG_RED`
  Used to represent the channels available in a color type or texture format as a mask.
  `static final int`
  `COLOR_CHANNEL_FLAGS_RG`
  `static final int`
  `COLOR_CHANNEL_FLAGS_RGB`
  `static final int`
  `COLOR_CHANNEL_FLAGS_RGBA`
  `static final int`
  `COLOR_CHANNEL_G`
  Describes different color channels one can manipulate.
  `static final int`
  `COLOR_CHANNEL_R`
  Describes different color channels one can manipulate.
  `static final int`
  `TRANSPARENT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Color()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `alpha(int color)`
  Return the alpha component of a color int.
  `static int`
  `argb(float alpha, float red, float green, float blue)`
  Return a color-int from alpha, red, green, blue float components in the range \([0..1]\).
  `static int`
  `argb(int alpha, int red, int green, int blue)`
  Return a color-int from alpha, red, green, blue components.
  `static int`
  `blend(BlendMode mode, int src, int dst)`
  Blends the two colors using premultiplied alpha on CPU side.
  `static int`
  `blue(int color)`
  Return the blue component of a color int.
  `static boolean`
  `equals_within_tolerance(float[] colA, float[] colB, float tol)`
  `static float`
  `GammaToLinear(float x)`
  Converts a color component from the sRGB space to the linear RGB space, using the sRGB transfer function.
  `static void`
  `GammaToLinear(float[] col)`
  Converts a color from the sRGB space to the linear RGB space, using the sRGB transfer function.
  `static int`
  `green(int color)`
  Return the green component of a color int.
  `static int`
  `HSVToColor(float[] hsv)`
  Converts HSV components to an RGB color.
  `static int`
  `HSVToColor(float h, float s, float v)`
  Converts HSV components to an RGB color.
  `static float`
  `lightness(float lum)`
  Coverts a luminance value to a perceptual lightness value.
  `static float`
  `LinearToGamma(float x)`
  Converts a color component from the linear RGB space to the sRGB space, using the inverse of sRGB transfer function.
  `static void`
  `LinearToGamma(float[] col)`
  Converts a color from the linear RGB space to the sRGB space, using the inverse of sRGB transfer function.
  `static float`
  `luminance(float[] col)`
  Converts a linear RGB color to a luminance value.
  `static float`
  `luminance(float r, float g, float b)`
  Converts a linear RGB color to a luminance value.
  `static int`
  `parseColor(String colorString)`
  Parse the color string, and return the corresponding color-int.
  `static int`
  `red(int color)`
  Return the red component of a color int.
  `static int`
  `rgb(float red, float green, float blue)`
  Return a color-int from red, green, blue float components in the range \([0..1]\).
  `static int`
  `rgb(int red, int green, int blue)`
  Return a color-int from red, green, blue components.
  `static void`
  `RGBToHSV(int color, float[] hsv)`
  Converts RGB to its HSV components.
  `static void`
  `RGBToHSV(int r, int g, int b, float[] hsv)`
  Converts RGB to its HSV components.

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

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

- ## Field Details

  - ### TRANSPARENT

    @ColorInt public static final int TRANSPARENT
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_R

    public static final int COLOR_CHANNEL_R
    Describes different color channels one can manipulate.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_G

    public static final int COLOR_CHANNEL_G
    Describes different color channels one can manipulate.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_B

    public static final int COLOR_CHANNEL_B
    Describes different color channels one can manipulate.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_A

    public static final int COLOR_CHANNEL_A
    Describes different color channels one can manipulate.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAG_RED

    public static final int COLOR_CHANNEL_FLAG_RED
    Used to represent the channels available in a color type or texture format as a mask.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAG_GREEN

    public static final int COLOR_CHANNEL_FLAG_GREEN
    Used to represent the channels available in a color type or texture format as a mask.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAG_BLUE

    public static final int COLOR_CHANNEL_FLAG_BLUE
    Used to represent the channels available in a color type or texture format as a mask.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAG_ALPHA

    public static final int COLOR_CHANNEL_FLAG_ALPHA
    Used to represent the channels available in a color type or texture format as a mask.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAG_GRAY

    public static final int COLOR_CHANNEL_FLAG_GRAY
    Used to represent the channels available in a color type or texture format as a mask.
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAGS_RG

    public static final int COLOR_CHANNEL_FLAGS_RG
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAGS_RGB

    public static final int COLOR_CHANNEL_FLAGS_RGB
    See Also:
      - Constant Field Values

  - ### COLOR_CHANNEL_FLAGS_RGBA

    public static final int COLOR_CHANNEL_FLAGS_RGBA
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Color

    public Color()

- ## Method Details

  - ### alpha

    public static int alpha(@ColorInt int color)
    Return the alpha component of a color int. This is the same as saying color >>> 24

  - ### red

    public static int red(@ColorInt int color)
    Return the red component of a color int. This is the same as saying (color >> 16) invalid input: '&' 0xFF

  - ### green

    public static int green(@ColorInt int color)
    Return the green component of a color int. This is the same as saying (color >> 8) invalid input: '&' 0xFF

  - ### blue

    public static int blue(@ColorInt int color)
    Return the blue component of a color int. This is the same as saying color invalid input: '&' 0xFF

  - ### rgb

    @ColorInt public static int rgb(int red, int green, int blue)
    Return a color-int from red, green, blue components. The alpha component is implicitly 255 (fully opaque). These component values should be \([0..255]\), but there is no range check performed, so if they are out of range, the returned color is undefined.
    Parameters:
      `red` - Red component \([0..255]\) of the color
      `green` - Green component \([0..255]\) of the color
      `blue` - Blue component \([0..255]\) of the color

  - ### rgb

    @ColorInt public static int rgb(float red, float green, float blue)
    Return a color-int from red, green, blue float components in the range \([0..1]\). The alpha component is implicitly 1.0 (fully opaque). If the components are out of range, the returned color is undefined.
    Parameters:
      `red` - Red component \([0..1]\) of the color
      `green` - Green component \([0..1]\) of the color
      `blue` - Blue component \([0..1]\) of the color

  - ### argb

    @ColorInt public static int argb(int alpha, int red, int green, int blue)
    Return a color-int from alpha, red, green, blue components. These component values should be \([0..255]\), but there is no range check performed, so if they are out of range, the returned color is undefined.
    Parameters:
      `alpha` - Alpha component \([0..255]\) of the color
      `red` - Red component \([0..255]\) of the color
      `green` - Green component \([0..255]\) of the color
      `blue` - Blue component \([0..255]\) of the color

  - ### argb

    @ColorInt public static int argb(float alpha, float red, float green, float blue)
    Return a color-int from alpha, red, green, blue float components in the range \([0..1]\). If the components are out of range, the returned color is undefined.
    Parameters:
      `alpha` - Alpha component \([0..1]\) of the color
      `red` - Red component \([0..1]\) of the color
      `green` - Green component \([0..1]\) of the color
      `blue` - Blue component \([0..1]\) of the color

  - ### parseColor

    @ColorInt public static int parseColor(@NonNull String colorString)
    Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception. Supported formats are:
    - `#RRGGBB`
    - `#AARRGGBB`
    - `0xRRGGBB`
    - `0xAARRGGBB`

  - ### RGBToHSV

    public static void RGBToHSV(int r, int g, int b, float[] hsv)
    Converts RGB to its HSV components. hsv[0] contains hsv hue, a value from zero to less than 360. hsv[1] contains hsv saturation, a value from zero to one. hsv[2] contains hsv value, a value from zero to one.
    Parameters:
      `r` - red component value from zero to 255
      `g` - green component value from zero to 255
      `b` - blue component value from zero to 255
      `hsv` - three element array which holds the resulting HSV components

  - ### RGBToHSV

    public static void RGBToHSV(int color, float[] hsv)
    Converts RGB to its HSV components. Alpha in ARGB (if it has) is ignored. hsv[0] contains hsv hue, and is assigned a value from zero to less than 360. hsv[1] contains hsv saturation, a value from zero to one. hsv[2] contains hsv value, a value from zero to one.
    Parameters:
      `color` - RGB or ARGB color to convert
      `hsv` - three element array which holds the resulting HSV components

  - ### HSVToColor

    public static int HSVToColor(float h, float s, float v)
    Converts HSV components to an RGB color. Alpha is NOT implicitly set.

    Out of range hsv values are clamped.

    Parameters:
      `h` - hsv hue, an angle from zero to less than 360
      `s` - hsv saturation, and varies from zero to one
      `v` - hsv value, and varies from zero to one
    Returns:
      RGB equivalent to HSV, without alpha

  - ### HSVToColor

    public static int HSVToColor(float[] hsv)
    Converts HSV components to an RGB color. Alpha is NOT implicitly set. hsv[0] represents hsv hue, an angle from zero to less than 360. hsv[1] represents hsv saturation, and varies from zero to one. hsv[2] represents hsv value, and varies from zero to one.

    Out of range hsv values are clamped.

    Parameters:
      `hsv` - three element array which holds the input HSV components
    Returns:
      RGB equivalent to HSV, without alpha

  - ### GammaToLinear

    public static float GammaToLinear(float x)
    Converts a color component from the sRGB space to the linear RGB space, using the sRGB transfer function.
    Parameters:
      `x` - a color component
    Returns:
      transformed color component

  - ### LinearToGamma

    public static float LinearToGamma(float x)
    Converts a color component from the linear RGB space to the sRGB space, using the inverse of sRGB transfer function.
    Parameters:
      `x` - a color component
    Returns:
      transformed color component

  - ### GammaToLinear

    public static void GammaToLinear(float[] col)
    Converts a color from the sRGB space to the linear RGB space, using the sRGB transfer function.
    Parameters:
      `col` - the color components

  - ### LinearToGamma

    public static void LinearToGamma(float[] col)
    Converts a color from the linear RGB space to the sRGB space, using the inverse of sRGB transfer function.
    Parameters:
      `col` - the color components

  - ### luminance

    public static float luminance(float r, float g, float b)
    Converts a linear RGB color to a luminance value.

  - ### luminance

    public static float luminance(float[] col)
    Converts a linear RGB color to a luminance value.
    Parameters:
      `col` - the color components

  - ### lightness

    public static float lightness(float lum)
    Coverts a luminance value to a perceptual lightness value.

  - ### blend

    @Internal @ColorInt public static int blend(@NonNull BlendMode mode, @ColorInt int src, @ColorInt int dst)
    Blends the two colors using premultiplied alpha on CPU side. This is to simulate the color blending on GPU side, but this is only used for color filtering (tinting). Do NOT premultiply the src and dst colors with alpha on CPU side. The returned color is un-premultiplied by alpha. This method will not lose precision, color components are still 8-bit.
    Parameters:
      `mode` - the blend mode that determines blending factors
      `src` - the source color (straight) to be blended into the destination color
      `dst` - the destination color (straight) on which the source color is to be blended
    Returns:
      the color (straight) resulting from the color blending

  - ### equals_within_tolerance

    @Internal public static boolean equals_within_tolerance(@Size(4L) float[] colA, @Size(4L) float[] colB, float tol)