Interface Color
- All Known Implementing Classes:
ImmutableColor,MutableColor
public interface Color
A robust RGBA color class with support for multiple color spaces,
conversion routines, and named‐color parsing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ImmutableColorstatic final ImmutableColorstatic final ImmutableColorstatic final ImmutableColorstatic final ImmutableColorstatic final ImmutableColor -
Method Summary
Modifier and TypeMethodDescriptionfloata()Alpha component [0..1]a(float alpha) Sets the alpha of this color.default <T extends Color>
Tfloatb()Blue component [0..1]b(float blue) Sets the blue value of this color.default <T extends Color>
TAlpha‐compositesoveron top of this color (this = “background,” over = “foreground”).default <T extends Color>
Tbrighten(float factor) Returns a brighter version of this color by multiplying each RGB byfactor(>1).default <T extends Color>
Tdefault booleancolorEquals(Object obj) default intdefault Stringdarken(float factor) Returns a darker version of this color by dividing each RGB byfactor(>1).default <T extends Color>
Tstatic ImmutableColorfromCMYK(float c, float m, float y, float k) Creates a Color from CMYK values (all in [0..1]), alpha defaults to 1.static ImmutableColorfromHSL(float h, float s, float l) Creates a Color from HSL values (all in [0..1]), alpha defaults to 1.static ImmutableColorfromHSL(float h, float s, float l, float a) Creates a Color from HSLA values (all in [0..1]).static ImmutableColorfromHSV(float h, float s, float v) Creates a Color from HSB/HSV values (all in [0..1]).static voidOutputs a Color from HSB/HSV values (all in [0..1]).static ImmutableColorfromIntARGB(int argb) Creates a Color from a packed ARGB int (0xAARRGGBB).static ImmutableColorfromIntRGB(int rgb) Creates a Color from a packed RGB int (0xRRGGBB).static ImmutableColorfromIntRGBA(int rgba) Creates a Color from a packed RGBA int (0xRRGGBBAA).floatg()Green component [0..1]g(float green) Sets the green value of this color.default <T extends Color>
Tdefault intdefault intdefault intdefault intReturns a grayscale version of this color, preserving alpha.default <T extends Color>
Tinvert()Returns an inverted‐color version of this color (ignoring alpha).default <T extends Color>
TReturns a new Color that is the linear interpolation between this andother.default <T extends Color>
TReturns a new Color that is this color multiplied component‐wise byother.default <T extends Color>
Tstatic ImmutableColorParses a color from a string.floatr()Red component [0..1]r(float red) Sets the red value of this color.default <T extends Color>
Tdefault float[]toCMYK()Converts this RGB color to CMYK (cyan, magenta, yellow, key/black), each in [0..1].default Stringdefault float[]toHSL()Converts this RGB color to HSL (hue, saturation, lightness), each in [0..1].default float[]toHSLA()Converts this RGB color to HSLA (hue, saturation, lightness, alpha), each in [0..1].default float[]toHSV()Converts this RGB color to HSB/HSV (hue, saturation, brightness), each in [0..1].default ImmutableColordefault intPacks this color into a 32‐bit ARGB int (0xAARRGGBB).default inttoIntRGB()Packs this color into a 24‐bit RGB int (0xRRGGBB), discarding alpha.default intPacks this color into 32‐bit RGBA int (0xRRGGBBAA).default MutableColorwithValues(float r, float g, float b) withValues(float r, float g, float b, float a)
-
Field Details
-
WHITE
-
BLACK
-
RED
-
GREEN
-
BLUE
-
TRANSPARENT
-
-
Method Details
-
r
float r()Red component [0..1] -
g
float g()Green component [0..1] -
b
float b()Blue component [0..1] -
a
float a()Alpha component [0..1] -
withValues
-
withValues
-
toImmutable
-
toMutable
-
parse
Parses a color from a string. Supports: Named colors via Color.named(name) Hex: "#RGB", "#RGBA", "#RRGGBB", "#RRGGBBAA", with optional "0x" prefix Integer literals: decimal or hex (via Integer.decode) If parsing fails, throws IllegalArgumentException. -
toHexRGBString
-
fromIntARGB
Creates a Color from a packed ARGB int (0xAARRGGBB).- Parameters:
argb- packed color ARGB- Returns:
- new IColor
-
fromIntRGB
Creates a Color from a packed RGB int (0xRRGGBB). Alpha defaults to 1.0.- Parameters:
rgb- packed color- Returns:
- new IColor
-
fromIntRGBA
Creates a Color from a packed RGBA int (0xRRGGBBAA).- Parameters:
rgba- packed color in RRGGBBAA format- Returns:
- new IColor instance
-
fromHSV
Creates a Color from HSB/HSV values (all in [0..1]). HSB and HSV are identical.- Parameters:
h- hue (0.0–1.0)s- saturation (0.0–1.0)v- brightness (0.0–1.0)- Returns:
- new IColor
-
fromHSV
Outputs a Color from HSB/HSV values (all in [0..1]). HSB and HSV are identical. All values aside from alpha will be modified- Parameters:
h- hue (0.0–1.0)s- saturation (0.0–1.0)v- brightness (0.0–1.0)out- the color being modified
-
fromHSL
Creates a Color from HSL values (all in [0..1]), alpha defaults to 1.- Parameters:
h- hue (0.0–1.0)s- saturation (0.0–1.0)l- lightness (0.0–1.0)- Returns:
- new IColor
-
fromHSL
Creates a Color from HSLA values (all in [0..1]).- Parameters:
h- hue (0.0–1.0)s- saturation (0.0–1.0)l- lightness (0.0–1.0)a- alpha (0.0–1.0)- Returns:
- new IColor
-
fromCMYK
Creates a Color from CMYK values (all in [0..1]), alpha defaults to 1.- Parameters:
c- cyan (0.0–1.0)m- magenta (0.0–1.0)y- yellow (0.0–1.0)k- key/black (0.0–1.0)- Returns:
- new IColor
-
toIntARGB
default int toIntARGB()Packs this color into a 32‐bit ARGB int (0xAARRGGBB). Each channel is multiplied by 255 and floored. -
toIntRGB
default int toIntRGB()Packs this color into a 24‐bit RGB int (0xRRGGBB), discarding alpha. -
toIntRGBA
default int toIntRGBA()Packs this color into 32‐bit RGBA int (0xRRGGBBAA). -
getRedInt
default int getRedInt()- Returns:
- red channel as 0–255 int.
-
getGreenInt
default int getGreenInt()- Returns:
- green channel as 0–255 int.
-
getBlueInt
default int getBlueInt()- Returns:
- blue channel as 0–255 int.
-
getAlphaInt
default int getAlphaInt()- Returns:
- alpha channel as 0–255 int.
-
toHSV
@Nonnull default float[] toHSV()Converts this RGB color to HSB/HSV (hue, saturation, brightness), each in [0..1]. HSB is identical to HSV.- Returns:
- float[3] = {h, s, v}
-
toHSL
@Nonnull default float[] toHSL()Converts this RGB color to HSL (hue, saturation, lightness), each in [0..1].- Returns:
- float[3] = {h, s, l}
-
toHSLA
@Nonnull default float[] toHSLA()Converts this RGB color to HSLA (hue, saturation, lightness, alpha), each in [0..1].- Returns:
- float[4] = {h, s, l, a}
-
toCMYK
@Nonnull default float[] toCMYK()Converts this RGB color to CMYK (cyan, magenta, yellow, key/black), each in [0..1].- Returns:
- float[4] = {c, m, y, k}
-
lerp
Returns a new Color that is the linear interpolation between this andother.- Parameters:
other- target colort- interpolation factor [0..1]
-
lerp
-
multiply
Returns a new Color that is this color multiplied component‐wise byother.- Parameters:
other- multiplier color
-
multiply
-
blend
Alpha‐compositesoveron top of this color (this = “background,” over = “foreground”). -
blend
-
invert
Returns an inverted‐color version of this color (ignoring alpha). -
invert
-
grayscale
Returns a grayscale version of this color, preserving alpha. Uses standard luminosity formula: gray = 0.299R + 0.587G + 0.114B. -
grayscale
-
brighten
Returns a brighter version of this color by multiplying each RGB byfactor(>1). Alpha is unchanged. -
brighten
-
darken
Returns a darker version of this color by dividing each RGB byfactor(>1). Alpha is unchanged. -
darken
-
r
Sets the red value of this color. -
r
-
g
Sets the green value of this color. -
g
-
b
Sets the blue value of this color. -
b
-
a
Sets the alpha of this color. -
a
-
colorEquals
-
colorHashCode
default int colorHashCode() -
colorToString
-