Class ColorConverter
java.lang.Object
com.github.darksoulq.abyssallib.common.color.ColorConverter
A specialized utility class for converting between various color spaces.
This class provides low-level mathematical conversions for:
- RGB / Hex: Standard web and computer colors.
- HSB: Hue, Saturation, and Brightness.
- CMYK: Cyan, Magenta, Yellow, and Key (Black) for print modeling.
- CIE XYZ: The device-independent color space foundation.
- CIE Lab: A perceptually uniform color space.
- OkLab: A modern perceptually uniform space designed for better gradients.
- LCH: Cylindrical representation of Lab (Lightness, Chroma, Hue).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.ColorfromCMYK(float c, float m, float y, float k) Creates a Color from CMYK components.static org.bukkit.ColorParses a hexadecimal string into a BukkitColor.static org.bukkit.ColorfromHSB(float h, float s, float b) Creates a Color from HSB components.static org.bukkit.ColorfromLab(double l, double a, double b) Creates a Color from CIE Lab coordinates.static org.bukkit.ColorfromLch(double l, double c, double h) Creates a Color from LCH coordinates.static org.bukkit.ColorfromOkLab(double L, double a, double b) Creates a Color from OkLab coordinates.static org.bukkit.ColorfromXYZ(double x, double y, double z) Converts CIE XYZ coordinates back into a Color.static float[]toCMYK(org.bukkit.Color color) Converts a Color into CMYK components.static StringtoHex(org.bukkit.Color color) Converts a Color into a hexadecimal string representation.static float[]toHSB(org.bukkit.Color color) Extracts HSB components from a Color.static double[]toLab(org.bukkit.Color c) Converts a Color to CIE Lab space.static double[]toLch(org.bukkit.Color c) Converts a Color to LCH (Lightness, Chroma, Hue) coordinates.static double[]toOkLab(org.bukkit.Color c) Converts a Color to the OkLab space.static double[]toXYZ(org.bukkit.Color c) Converts a Color to CIE XYZ space.
-
Constructor Details
-
ColorConverter
public ColorConverter()
-
-
Method Details
-
fromHex
Parses a hexadecimal string into a BukkitColor.- Parameters:
hex- The hexadecimal string (e.g., "#FFFFFF").- Returns:
- The resulting Color object.
-
toHex
Converts a Color into a hexadecimal string representation.- Parameters:
color- TheColorto convert.- Returns:
- A string formatted as "#RRGGBB".
-
toHSB
public static float[] toHSB(org.bukkit.Color color) Extracts HSB components from a Color.- Parameters:
color- TheColorto convert.- Returns:
- A float array containing [Hue, Saturation, Brightness].
-
fromHSB
public static org.bukkit.Color fromHSB(float h, float s, float b) Creates a Color from HSB components.- Parameters:
h- Hue (0.0 to 1.0).s- Saturation (0.0 to 1.0).b- Brightness (0.0 to 1.0).- Returns:
- The resulting
Color.
-
toCMYK
public static float[] toCMYK(org.bukkit.Color color) Converts a Color into CMYK components.- Parameters:
color- TheColorto convert.- Returns:
- A float array containing [C, M, Y, K] values (0.0 to 1.0).
-
fromCMYK
public static org.bukkit.Color fromCMYK(float c, float m, float y, float k) Creates a Color from CMYK components.- Parameters:
c- Cyan (0.0 to 1.0).m- Magenta (0.0 to 1.0).y- Yellow (0.0 to 1.0).k- Key/Black (0.0 to 1.0).- Returns:
- The resulting
Color.
-
toXYZ
public static double[] toXYZ(org.bukkit.Color c) Converts a Color to CIE XYZ space. Uses sRGB D65 constants and performs linearization (gamma expansion).- Parameters:
c- TheColorto convert.- Returns:
- A double array containing [X, Y, Z].
-
fromXYZ
public static org.bukkit.Color fromXYZ(double x, double y, double z) Converts CIE XYZ coordinates back into a Color.- Parameters:
x- Coordinate X.y- Coordinate Y.z- Coordinate Z.- Returns:
- The resulting
Color.
-
toLab
public static double[] toLab(org.bukkit.Color c) Converts a Color to CIE Lab space. This space is designed to be perceptually uniform, where a change in value corresponds to a similar change in human perception.- Parameters:
c- TheColorto convert.- Returns:
- A double array containing [L, a, b].
-
fromLab
public static org.bukkit.Color fromLab(double l, double a, double b) Creates a Color from CIE Lab coordinates.- Parameters:
l- Lightness (0.0 to 100.0).a- The green-red axis.b- The blue-yellow axis.- Returns:
- The resulting
Color.
-
toOkLab
public static double[] toOkLab(org.bukkit.Color c) Converts a Color to the OkLab space. OkLab is a modern perceptually uniform space that improves upon CIELAB, specifically for better hue preservation and uniform lightness.- Parameters:
c- TheColorto convert.- Returns:
- A double array containing [L, a, b] in OkLab format.
-
fromOkLab
public static org.bukkit.Color fromOkLab(double L, double a, double b) Creates a Color from OkLab coordinates.- Parameters:
L- Lightness.a- The a-axis (green to red).b- The b-axis (blue to yellow).- Returns:
- The resulting
Color.
-
toLch
public static double[] toLch(org.bukkit.Color c) Converts a Color to LCH (Lightness, Chroma, Hue) coordinates. This is a cylindrical representation of the Lab space.- Parameters:
c- TheColorto convert.- Returns:
- A double array containing [Lightness, Chroma, Hue in degrees].
-
fromLch
public static org.bukkit.Color fromLch(double l, double c, double h) Creates a Color from LCH coordinates.- Parameters:
l- Lightness.c- Chroma.h- Hue (in degrees, 0.0 to 360.0).- Returns:
- The resulting
Color.
-