| Crates.io | hct-cam16 |
| lib.rs | hct-cam16 |
| version | 0.1.0 |
| created_at | 2025-12-31 17:06:42.326413+00 |
| updated_at | 2025-12-31 17:06:42.326413+00 |
| description | CAM16 + HCT perceptual color math with sRGB/XYZ/L* conversions and a gamut-mapping solver. Deterministic ARGB-in/ARGB-out, no UI/engine dependencies. |
| homepage | |
| repository | https://github.com/edgarhsanchez/hct_cam16 |
| max_upload_size | |
| id | 2015013 |
| size | 60,343 |
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.
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:
This crate lets you:
use hct_cam16::Hct;
let seed = Hct::from_hex("#6750A4").unwrap();
let color = Hct::new(seed.hue(), seed.chroma(), 50.0);
println!("{:08X}", color.to_argb());
use hct_cam16::Hct;
let hct = Hct::from_argb(0xFF6750A4);
println!("hue={:.1} chroma={:.1} tone={:.1}", hct.hue(), hct.chroma(), hct.tone());
use hct_cam16::Hct;
let base = Hct::from_hex("#6750A4").unwrap();
let lighter = base.with_tone(80.0);
let darker = base.with_tone(30.0);
println!("lighter={:08X} darker={:08X}", lighter.to_argb(), darker.to_argb());
use hct_cam16::Hct;
let base = Hct::from_argb(0xFF6750A4);
let rotated = base.with_hue((base.hue() + 60.0) % 360.0);
println!("{:08X}", rotated.to_argb());
use hct_cam16::{Hct, TonalPalette};
let seed = Hct::from_hex("#6750A4").unwrap();
let mut palette = TonalPalette::from_hct(&seed);
// Common tones: 0..100. Material uses a standard set like 40, 90, 100, etc.
let t40 = palette.tone(40);
let t90 = palette.tone(90);
println!("t40={:08X} t90={:08X}", t40, t90);
use hct_cam16::MaterialColorScheme;
let scheme = MaterialColorScheme::from_seed(0xFF6750A4);
// All fields are ARGB (u32)
println!("primary={:08X} on_primary={:08X}", scheme.primary, scheme.on_primary);