Class ColorConverter

java.lang.Object
com.github.darksoulq.abyssallib.common.color.ColorConverter

public final class ColorConverter extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.Color
    fromCMYK(float c, float m, float y, float k)
    Creates a Color from CMYK components.
    static org.bukkit.Color
    Parses a hexadecimal string into a Bukkit Color.
    static org.bukkit.Color
    fromHSB(float h, float s, float b)
    Creates a Color from HSB components.
    static org.bukkit.Color
    fromLab(double l, double a, double b)
    Creates a Color from CIE Lab coordinates.
    static org.bukkit.Color
    fromLch(double l, double c, double h)
    Creates a Color from LCH coordinates.
    static org.bukkit.Color
    fromOkLab(double L, double a, double b)
    Creates a Color from OkLab coordinates.
    static org.bukkit.Color
    fromXYZ(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 String
    toHex(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.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ColorConverter

      public ColorConverter()
  • Method Details

    • fromHex

      public static org.bukkit.Color fromHex(String hex)
      Parses a hexadecimal string into a Bukkit Color.
      Parameters:
      hex - The hexadecimal string (e.g., "#FFFFFF").
      Returns:
      The resulting Color object.
    • toHex

      public static String toHex(org.bukkit.Color color)
      Converts a Color into a hexadecimal string representation.
      Parameters:
      color - The Color to convert.
      Returns:
      A string formatted as "#RRGGBB".
    • toHSB

      public static float[] toHSB(org.bukkit.Color color)
      Extracts HSB components from a Color.
      Parameters:
      color - The Color to 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 - The Color to 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 - The Color to 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 - The Color to 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 - The Color to 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 - The Color to 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.