Skip to content
MehVahdJukaar edited this page Jul 25, 2026 · 1 revision

Colors

Color objects in several color spaces, so operations like mixing and brightening actually look right.

Mixing two colors as raw RGB gives muddy results, and "make this 20% brighter" in RGB isn't what your eye means by brighter. These classes convert between RGB, HSV, HSL, LAB, LUV, HCL, HCLV and XYZ, and every operation happens in the space you picked.

This is what makes the texture respriter produce usable palettes.

Getting Started

public static RGBColor modifyColor(RGBColor color) {
    LABColor lab = color.asLAB();
    LABColor pureRed = new RGBColor(1, 0, 0, 1).asLAB();

    // mixing in LAB, which looks right, unlike mixing in RGB
    lab.mixWith(pureRed, 0.2f);
    lab.withLuminance(0.4f);

    return lab.asRGB();
}

Every class extends BaseColor and has the same shape: component accessors, withX(...), mixWith, and asRGB() / asLAB() / ... to convert. Components are floats from 0 to 1.

Example: RGBColorExample

Also here

ColorUtils for packed int colors: pack and unpack, hex parsing (its codec accepts both "#ff0000" and a number, which is what config and json color fields use), and the usual conversions.

KMeans clusters a set of colors, used to reduce an image to a small palette.

Clone this wiki locally