Package dev.brachtendorf.graphics
Class ColorUtil
- java.lang.Object
-
- dev.brachtendorf.graphics.ColorUtil
-
public class ColorUtil extends Object
- Author:
- Kilian
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classColorUtil.ColorPalette
-
Constructor Summary
Constructors Constructor Description ColorUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]argbToComponents(int argb)Convert an argb value to it's individual components in range of 0 - 255static javafx.scene.paint.ColorargbToFXColor(int argb)Convert an argb value (alpha 24,red 16, green 8, blue 0) into a java fx color.static javafx.scene.paint.ColorawtToFxColor(Color awtColor)Convert a Java AWT color to it's JavaFX siblingstatic intcomponentsToARGB(int alpha, int red, int green, int blue)Converts the components to a single int argb representation.static doubledistance(Color c1, Color c2)Compute a distance metric of 2 colors.static doubledistance(javafx.scene.paint.Color c1, javafx.scene.paint.Color c2)Compute a distance metric of 2 colors.static ColorfxToAwtColor(javafx.scene.paint.Color fxColor)Convert a JavaFX color to it's awt siblingstatic StringfxToHex(javafx.scene.paint.Color color)Return the hexcode of a colorstatic ColorgetContrastColor(Color input)Return either white or black depending on the supplied color to guarantee readability.static javafx.scene.paint.ColorgetContrastColor(javafx.scene.paint.Color input)Return either white or black depending on the supplied color to guarantee readability.static intgetLuma(Color c)Get the Y (luma component) of the YCrCb color modelstatic doublegetLuma(javafx.scene.paint.Color c)Get the Y (luma component) of the YCrCb color model
-
-
-
Field Detail
-
LUMA_RED
public static final double LUMA_RED
- See Also:
- Constant Field Values
-
LUMA_GREEN
public static final double LUMA_GREEN
- See Also:
- Constant Field Values
-
LUMA_BLUE
public static final double LUMA_BLUE
- See Also:
- Constant Field Values
-
CR_RED
public static final double CR_RED
- See Also:
- Constant Field Values
-
CR_GREEN
public static final double CR_GREEN
- See Also:
- Constant Field Values
-
CR_BLUE
public static final double CR_BLUE
- See Also:
- Constant Field Values
-
CB_RED
public static final double CB_RED
- See Also:
- Constant Field Values
-
CB_GREEN
public static final double CB_GREEN
- See Also:
- Constant Field Values
-
CB_BLUE
public static final double CB_BLUE
- See Also:
- Constant Field Values
-
-
Method Detail
-
fxToAwtColor
public static Color fxToAwtColor(javafx.scene.paint.Color fxColor)
Convert a JavaFX color to it's awt sibling- Parameters:
fxColor- The fx color to convert- Returns:
- The awt color
- Since:
- 1.0.0 com.github.kilianB
-
awtToFxColor
public static javafx.scene.paint.Color awtToFxColor(Color awtColor)
Convert a Java AWT color to it's JavaFX sibling- Parameters:
awtColor- The awt color to convert- Returns:
- The fx color
- Since:
- 1.0.0 com.github.kilianB
-
argbToComponents
public static int[] argbToComponents(int argb)
Convert an argb value to it's individual components in range of 0 - 255- Parameters:
argb- values as int- Returns:
- [0] Alpha, [1] Red, [2] Green, [3] Blue
- Since:
- 1.0.0 com.github.kilianB
-
componentsToARGB
public static int componentsToARGB(int alpha, int red, int green, int blue)Converts the components to a single int argb representation. The individual values are not range checked- Parameters:
alpha- in range of 0 - 255red- in range of 0 - 255green- in range of 0 - 255blue- in range of 0 - 255- Returns:
- a single int representing the argb value
- Since:
- 1.0.0 com.github.kilianB
-
argbToFXColor
public static javafx.scene.paint.Color argbToFXColor(int argb)
Convert an argb value (alpha 24,red 16, green 8, blue 0) into a java fx color.- Parameters:
argb- the argb color as an int- Returns:
- The JavaFX Color
- Since:
- 1.0.0 com.github.kilianB
-
fxToHex
public static String fxToHex(javafx.scene.paint.Color color)
Return the hexcode of a color- Parameters:
color- the color to convert- Returns:
- a hex representation of the color
- Since:
- 1.0.0 com.github.kilianB
-
distance
public static double distance(javafx.scene.paint.Color c1, javafx.scene.paint.Color c2)Compute a distance metric of 2 colors. The distance of a color is greater the further away two colors are.Identical colors will return a distance of 0.
- Parameters:
c1- The first colorc2- The second color- Returns:
- a double value indicating the distance of two colors
- Since:
- 1.0.0 com.github.kilianB
-
distance
public static double distance(Color c1, Color c2)
Compute a distance metric of 2 colors. The distance of a color is greater the further away two colors are.Identical colors will return a distance of 0.
- Parameters:
c1- The first colorc2- The second color- Returns:
- a double value indicating the distance of two colors
- Since:
- 1.0.0 com.github.kilianB
-
getLuma
public static double getLuma(javafx.scene.paint.Color c)
Get the Y (luma component) of the YCrCb color model- Parameters:
c- an javaFX color- Returns:
- the luma component in the tange [0-1]
- Since:
- 1.3.2 com.github.kilianB
-
getLuma
public static int getLuma(Color c)
Get the Y (luma component) of the YCrCb color model- Parameters:
c- an awt color- Returns:
- the luma component in the tange [0-255]
- Since:
- 1.3.2 com.github.kilianB
-
getContrastColor
public static javafx.scene.paint.Color getContrastColor(javafx.scene.paint.Color input)
Return either white or black depending on the supplied color to guarantee readability. The contrast color is assumed to be used as text overlay on top of the input color.- Parameters:
input- the color of the background- Returns:
- the color (white or black) of the foreground whichever guarantees more readability.
- Since:
- 1.0.0 com.github.kilianB
-
getContrastColor
public static Color getContrastColor(Color input)
Return either white or black depending on the supplied color to guarantee readability. The contrast color is assumed to be used as text overlay on top of the input color.- Parameters:
input- the color of the background- Returns:
- the color (white or black) of the foreground whichever guarantees more readability.
- Since:
- 1.3.2 com.github.kilianB
-
-