Class ColorMath

java.lang.Object
dev.despical.pixelpainter.core.ColorMath

public final class ColorMath extends Object
Converts sRGB samples into Oklab and measures perceptual color distance.

Conversion linearizes the three color channels before transforming them. No Bukkit state or mutable shared cache is used, so matching may run on background image workers.

  • Method Details

    • lab

      public static double[] lab(int rgb)
      Converts an RGB sample into Oklab coordinates.
      Parameters:
      rgb - packed sRGB sample; the alpha byte is ignored
      Returns:
      a new three-element array containing lightness, a and b
    • distance

      public static double distance(double[] a, double[] b)
      Measures squared Euclidean distance between Oklab coordinates.
      Parameters:
      a - first array with at least three elements
      b - second array with at least three elements
      Returns:
      squared distance; smaller values represent closer colors