hct-cam16
hct-cam16 is a small Rust crate implementing CAM16 + HCT perceptual color math with sRGB/XYZ/L* conversions and a gamut-mapping solver. Designed for deterministic ARGB-in/ARGB-out use, with no UI/engine dependencies.
What are CAM16 and HCT?
CAM16 is a color appearance model. Unlike simple RGB/HSV/HSL, it tries to model how humans perceive color (hue / colorfulness / lightness) under viewing conditions.
HCT (Hue–Chroma–Tone) is the Material Design 3 color space built on top of CAM16:
- Hue: the “angle” of the color (0–360°) in CAM16.
- Chroma: perceived colorfulness/saturation (how vivid it is).
- Tone: perceptual lightness (0–100), based on L*.
This crate lets you:
- Convert sRGB colors to/from perceptual HCT.
- Adjust hue/chroma/tone in a way that tracks human perception better than HSL.
- Generate Material-style tonal palettes (consistent hue/chroma across tones).
- Generate a full Material Design 3 color scheme from a seed color.
Quick start
use Hct;
let seed = from_hex.unwrap;
let color = new;
println!;
Examples
1) Convert a color to HCT and inspect it
use Hct;
let hct = from_argb;
println!;
2) Make a lighter/darker tone (great for contrast ramps)
use Hct;
let base = from_hex.unwrap;
let lighter = base.with_tone;
let darker = base.with_tone;
println!;
3) Rotate hue while keeping tone (useful for accents)
use Hct;
let base = from_argb;
let rotated = base.with_hue;
println!;
4) Generate a tonal palette (Material “tones”)
use ;
let seed = from_hex.unwrap;
let mut palette = from_hct;
// Common tones: 0..100. Material uses a standard set like 40, 90, 100, etc.
let t40 = palette.tone;
let t90 = palette.tone;
println!;
5) Generate a full Material Design 3 color scheme
use MaterialColorScheme;
let scheme = from_seed;
// All fields are ARGB (u32)
println!;
Docs
- HCT solver overview: docs/HCT_SOLVER.md