public class ColorUtil extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.awt.color.ColorSpace |
sRGB
RGB colorSpace
|
Constructor and Description |
---|
ColorUtil() |
Modifier and Type | Method and Description |
---|---|
static java.awt.Color |
add(java.awt.Color c1,
java.awt.Color c2)
Add 2 colors
|
static java.awt.Color |
add(java.awt.Color c1,
java.awt.Color c2,
boolean useAlpha)
Add 2 colors
|
static float[] |
fromHSV(float[] hsv)
Convert the specified HSV color to RGB color.
|
static float[] |
fromXYZ(float[] xyz)
Convert the specified XYZ color to RGB color.
|
static java.awt.Color[] |
generateRainbow(float saturation,
float brightness,
int size,
boolean black,
boolean white,
boolean gray)
Generates a rainbow color table (HSV ramp) of the specified size.
|
static java.awt.Color[] |
generateRainbow(int size)
Generates a rainbow color table (HSV ramp) of the specified size.
|
static java.awt.Color[] |
generateRainbow(int size,
boolean black,
boolean white,
boolean gray)
Generates a rainbow color table (HSV ramp) of the specified size.
|
static java.awt.Color |
getColorFromWavelength(double wavelength)
Converts a wavelength into a
Color object. |
static double |
getDistance(java.awt.Color c1,
java.awt.Color c2,
boolean hsv)
Compute and returns the distance between the 2 colors.
|
static java.awt.Color |
getDominantColor(java.awt.Color[] colors)
Returns the dominant color from the specified color array.
|
static java.awt.Color |
getDominantColor(java.awt.Color[] colors,
int binNumber)
Returns the dominant color from the specified color array.
|
static java.awt.Color |
getGrayColorLum(java.awt.Color c)
Convert to gray level color (from luminance calculation)
|
static java.awt.Color |
getGrayColorMix(java.awt.Color c)
Convert to gray level color (simple RGB mix)
|
static int |
getGrayMix(java.awt.Color c)
get to gray level (simple RGB mix)
|
static int |
getGrayMix(int rgb)
get to gray level (simple RGB mix)
|
static int |
getLuminance(java.awt.Color c)
Return luminance (in [0..255] range)
|
static java.awt.Color |
getRandomColor()
Returns a random color.
|
static boolean |
isBlack(java.awt.Color color)
Returns
true if the specified color is pure black (alpha is not verified) |
static java.awt.Color |
mix(java.awt.Color c1,
java.awt.Color c2)
Mix 2 colors (no alpha)
|
static java.awt.Color |
mix(java.awt.Color c1,
java.awt.Color c2,
boolean useAlpha)
Mix 2 colors without "priority" color
|
static java.awt.Color |
mix(java.awt.Color c1,
java.awt.Color c2,
float ratio)
Mix 2 colors using the following ratio for mixing:
0f means 100% of color 1 and 0% of color 2 0.5f means 50% of color 1 and 50% of color 2 1f means 0% of color 1 and 100% of color 2 |
static java.awt.Color |
mixOver(java.awt.Color backColor,
java.awt.Color frontColor)
Mix 2 colors with priority color
|
static java.awt.Color |
sub(java.awt.Color c1,
java.awt.Color c2)
Subtract 2 colors
|
static java.awt.Color |
sub(java.awt.Color c1,
java.awt.Color c2,
boolean useAlpha)
Sub 2 colors
|
static float[] |
toHSV(java.awt.Color c)
Convert the specified color to HSV color.
|
static float[] |
toHSV(float[] rgb)
Convert the specified RGB color to HSV color.
|
static float[] |
toLAB(java.awt.Color c)
Convert the specified color to LAB color.
|
static float[] |
toLAB(float[] rgb)
Convert the specified RGB color to LAB color.
|
static java.lang.String |
toString(java.awt.Color color)
Get String representation of the specified color.
|
static java.lang.String |
toString(java.awt.Color color,
boolean hexa)
Get String representation of the specified Color value.
|
static java.lang.String |
toString(java.awt.Color color,
boolean hexa,
java.lang.String sep)
Get String representation of the specified color.
|
static java.lang.String |
toString(int rgb)
Get String representation of the specified rgb value.
|
static java.lang.String |
toString(int rgb,
boolean hexa)
Get String representation of the specified rgb value.
|
static java.lang.String |
toString(int rgb,
boolean hexa,
java.lang.String sep)
Get String representation of the specified rgb value.
|
static float[] |
toXYZ(java.awt.Color c)
Convert the specified color to XYZ color.
|
static float[] |
toXYZ(float[] rgb)
Convert the specified RGB color to XYZ color.
|
static java.awt.Color |
xor(java.awt.Color c)
Get opposite (XORed) color
|
static float[] |
XYZtoLAB(float[] xyz)
Convert the specified XYZ color to LAB color.
|
public static final java.awt.color.ColorSpace sRGB
public ColorUtil()
public static java.awt.Color getRandomColor()
public static java.awt.Color[] generateRainbow(float saturation, float brightness, int size, boolean black, boolean white, boolean gray)
saturation
- saturation factor (from 0 to 1).brightness
- brightness factor (from 0 to 1).size
- the size of rainbow color table.black
- if true the table will also contains a black color entry.white
- if true the table will also contains a white color entry.gray
- if true the table will also contains a gray color entry.public static java.awt.Color[] generateRainbow(int size, boolean black, boolean white, boolean gray)
size
- the size of the rainbow color table.black
- if true the table will also contains a black color entry.white
- if true the table will also contains a white color entry.gray
- if true the table will also contains a gray color entry.public static java.awt.Color[] generateRainbow(int size)
size
- the size of the HSV color table.public static java.lang.String toString(java.awt.Color color)
color
- public static java.lang.String toString(int rgb)
rgb
- public static java.lang.String toString(java.awt.Color color, boolean hexa)
color
- hexa
- component level are represented in hexadecimal (2 digits)public static java.lang.String toString(int rgb, boolean hexa)
rgb
- hexa
- component level are represented in hexadecimal (2 digits)public static java.lang.String toString(java.awt.Color color, boolean hexa, java.lang.String sep)
color
- hexa
- component level are represented in hexadecimal (2 digits)public static java.lang.String toString(int rgb, boolean hexa, java.lang.String sep)
rgb
- hexa
- component level are represented in hexadecimal (2 digits)public static boolean isBlack(java.awt.Color color)
true
if the specified color is pure black (alpha is not verified)public static java.awt.Color mixOver(java.awt.Color backColor, java.awt.Color frontColor)
public static java.awt.Color mix(java.awt.Color c1, java.awt.Color c2, float ratio)
public static java.awt.Color mix(java.awt.Color c1, java.awt.Color c2, boolean useAlpha)
public static java.awt.Color mix(java.awt.Color c1, java.awt.Color c2)
public static java.awt.Color add(java.awt.Color c1, java.awt.Color c2, boolean useAlpha)
public static java.awt.Color add(java.awt.Color c1, java.awt.Color c2)
public static java.awt.Color sub(java.awt.Color c1, java.awt.Color c2, boolean useAlpha)
public static java.awt.Color sub(java.awt.Color c1, java.awt.Color c2)
public static java.awt.Color xor(java.awt.Color c)
public static int getGrayMix(java.awt.Color c)
public static int getGrayMix(int rgb)
public static java.awt.Color getGrayColorMix(java.awt.Color c)
public static java.awt.Color getGrayColorLum(java.awt.Color c)
public static int getLuminance(java.awt.Color c)
public static float[] toHSV(java.awt.Color c)
public static float[] toHSV(float[] rgb)
public static float[] fromHSV(float[] hsv)
public static float[] fromXYZ(float[] xyz)
public static float[] toXYZ(java.awt.Color c)
public static float[] toXYZ(float[] rgb)
public static float[] toLAB(java.awt.Color c)
public static float[] toLAB(float[] rgb)
public static float[] XYZtoLAB(float[] xyz)
public static double getDistance(java.awt.Color c1, java.awt.Color c2, boolean hsv)
c1
- first colorc2
- second colorhsv
- If set to true we use the HSV color space to compute the color distance otherwise we
use the LAB color space.public static java.awt.Color getDominantColor(java.awt.Color[] colors)
public static java.awt.Color getDominantColor(java.awt.Color[] colors, int binNumber)
colors
- Color array we want to retrieve the dominant color from.binNumber
- the number of bin to construct the rainbow gradient.public static java.awt.Color getColorFromWavelength(double wavelength)
wavelength
- the wavelength to convert (in nanometers)Color
object representing the specified wavelength