pub struct Color { /* private fields */ }Expand description
One named entry in the xkcd color hierarchy.
Carries every column from the upstream color_hierarchy.csv:
xkcd / design / common name, hex, and RGB triples for each level,
plus the family / kind / neutrality classification. The xkcd LAB
triple is pre-computed at codegen time for nearest-neighbor lookup
in Self::nearest_to.
Implementations§
Source§impl Color
impl Color
Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
xkcd-survey name (~950 unique values, e.g. "burnt orange",
"vermilion").
Sourcepub const fn rgb(&self) -> [u8; 3]
pub const fn rgb(&self) -> [u8; 3]
xkcd RGB triple, e.g. [189, 108, 72]. The exact 8-bit value the
xkcd survey reports for this name.
Sourcepub const fn lab(&self) -> [f32; 3]
pub const fn lab(&self) -> [f32; 3]
Pre-computed CIE LAB (D65 illuminant, 2° observer) for Self::rgb.
Used internally by Self::nearest_to; exposed publicly so callers
can implement their own distance metric (e.g. CIEDE2000) on top of
the same cached values.
Sourcepub const fn design_name(&self) -> &'static str
pub const fn design_name(&self) -> &'static str
Coarser design-palette name (~250 unique, e.g. "russet brown").
Sourcepub const fn design_hex(&self) -> &'static str
pub const fn design_hex(&self) -> &'static str
Hex string for the design-palette anchor color.
Sourcepub const fn design_rgb(&self) -> [u8; 3]
pub const fn design_rgb(&self) -> [u8; 3]
RGB triple for the design-palette anchor color (the canonical
8-bit representation of Self::design_name). Differs from
Self::rgb when the xkcd entry sits at the edge of its
design-palette bucket.
Sourcepub const fn common_name(&self) -> &'static str
pub const fn common_name(&self) -> &'static str
Coarser still common name (~120 unique, e.g. "sienna"). The
search-friendly default for indexing pipelines.
Sourcepub const fn common_hex(&self) -> &'static str
pub const fn common_hex(&self) -> &'static str
Hex string for the common-name anchor color.
Sourcepub const fn common_rgb(&self) -> [u8; 3]
pub const fn common_rgb(&self) -> [u8; 3]
RGB triple for the common-name anchor color.
Sourcepub const fn family(&self) -> Family
pub const fn family(&self) -> Family
Color family classification (26 values, e.g. Family::Yellow,
Family::BlueGreen, [Family::Neutral]). Call
Family::as_str for the original CSV string.
Sourcepub const fn kind(&self) -> Kind
pub const fn kind(&self) -> Kind
Color kind / texture classification (11 values, e.g.
Kind::NeonColor, Kind::PainterlyNeutral). Call
Kind::as_str for the original CSV string.
Sourcepub const fn is_neutral(&self) -> bool
pub const fn is_neutral(&self) -> bool
true if the entry is classified as a neutral (vs a chromatic
color). Drives the color_or_neutral axis in the original Stitch
Fix taxonomy.
Sourcepub const fn all() -> &'static [&'static Color]
pub const fn all() -> &'static [&'static Color]
Every entry in the dataset, in CSV (alphabetical-by-name) order.
Sourcepub fn nearest_to(rgb: [u8; 3]) -> &'static Color
pub fn nearest_to(rgb: [u8; 3]) -> &'static Color
Find the entry whose pre-computed LAB is closest to the given query RGB by Delta E 76 (squared Euclidean LAB).
Always returns an entry — COLORS is non-empty and verified at
codegen time. The scan dispatches to a per-arch SIMD backend
(NEON / AVX2 / SSE4.1 / WASM SIMD128) on every target that has
one; other targets fall through to the scalar reference. Every
backend is bit-identical — see [crate::nearest] for the
dispatch contract and parity tests.
§When to use this method
Delta E 76 is the fast metric: against this crate’s well-
clustered 949-entry xkcd palette it picks the same named entry
as CIEDE2000 in the overwhelming majority of cases, at ~150×
the throughput of Algorithm::Ciede2000Exact (the default
returned by Algorithm::default). Reach for it when you’ve
measured the slower default bottlenecking real workloads and
can tolerate borderline misnamings near the gray / yellow
boundary.
Sourcepub fn nearest_to_ciede2000(rgb: [u8; 3]) -> &'static Color
pub fn nearest_to_ciede2000(rgb: [u8; 3]) -> &'static Color
Find the entry whose pre-computed LAB is closest to the given query RGB by CIEDE2000 — the modern perceptual gold-standard colour-difference formula.
CIEDE2000 corrects Delta E 76’s known biases (over-weighting
yellows, under-weighting blues, hue-rotation in the saturated
blue region) at the cost of atan2 / sin / cos / exp per
pair plus branchy hue-wraparound logic.
§Implementation
- With
feature = "lut"(the default): O(1) cell lookup → small candidate scan via the pre-computed candidate-set LUT ([crate::nearest::ciede2000_lut]). Provably exact at u8 RGB resolution; ~few-hundred-ns/query. - Without
feature = "lut": full-scan reference over all 949 palette entries (~71 µs/query). Same correctness guarantee, slower.
Both modes are scalar — CIEDE2000’s transcendentals don’t
vectorise usefully (see [crate::nearest::ciede2000]).
Sourcepub fn nearest_to_ciede2000_exact(rgb: [u8; 3]) -> &'static Color
pub fn nearest_to_ciede2000_exact(rgb: [u8; 3]) -> &'static Color
Strict CIEDE2000 nearest-neighbor. Behaviorally equivalent to
Self::nearest_to_ciede2000 — both are exact under both
feature configurations (the LUT path is provably exact, the
no-LUT path is full-scan). Retained as a distinct entry point
for API stability; consumers picking between the two by name
should prefer Self::nearest_to_ciede2000.
Sourcepub fn nearest_to_cie94(rgb: [u8; 3]) -> &'static Color
pub fn nearest_to_cie94(rgb: [u8; 3]) -> &'static Color
Find the entry whose pre-computed LAB is closest to the given query RGB by CIE94 (Delta E 94, graphic-arts weighting).
CIE94 sits between Delta E 76 and CIEDE2000 in both perceptual
accuracy and arithmetic cost. It uses no transcendentals beyond
sqrt, so unlike CIEDE2000 the formula vectorises cleanly —
SIMD backends are a planned follow-up that will mirror the
Delta E 76 module structure.
CIE94 is asymmetric (the S_C / S_H scale factors depend on the reference’s chroma C₁); this implementation treats the palette entry as the reference and the query as the sample.