#[non_exhaustive]#[repr(u8)]pub enum Algorithm {
DeltaE76 = 0,
Cie94 = 1,
Ciede2000 = 2,
Ciede2000Exact = 3,
}Expand description
Color-difference algorithm used to map an arbitrary RGB query to
its nearest Color in the xkcd palette.
Each variant corresponds to one of the per-metric
Color::nearest_to_* methods. The enum exists so callers can
store the choice as a value and pass it to higher-level APIs like
colorthief::extract_with without committing to a specific
Color::nearest_to_* callsite.
Marked #[non_exhaustive] so adding a future variant (e.g. CMC,
CIEDE2010) is a non-breaking change for downstream consumers.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
DeltaE76 = 0
Delta E 76 — squared Euclidean LAB distance. Fastest by a wide margin (~470 ns/query on Apple Silicon NEON, ~940 ns scalar). SIMD-dispatched on every supported arch with bit- identical parity. Recommended for search-vocabulary indexing where throughput matters more than borderline accuracy.
Cie94 = 1
CIE94 (Delta E 94, graphic-arts weighting) — middle ground
between Delta E 76’s speed and CIEDE2000’s accuracy. Uses only
sqrt for transcendentals, so it vectorises cleanly. ~900 ns
NEON / ~4.4 µs scalar. Asymmetric: the palette entry is the
reference, the query is the sample.
Ciede2000 = 2
CIEDE2000 — the modern perceptual gold-standard formula.
With feature = "lut" (the default) routes through the
candidate-set LUT (~230 ns/query, provably exact at u8 RGB);
without the feature falls back to the full-scan reference
(~71 µs/query, also provably exact). Behaviorally equivalent
to Self::Ciede2000Exact under both feature configurations.
Ciede2000Exact = 3
CIEDE2000, retained as a distinct variant for API
stability. Behaviorally equivalent to Self::Ciede2000 —
both go through the LUT when feature = "lut" is enabled and
the full-scan reference otherwise. Default. Returned by
Algorithm::default so consumers of Algorithm::extract
and crate-level entry points like colorthief::extract get
the perceptual gold-standard out of the box.
Implementations§
Source§impl Algorithm
impl Algorithm
Sourcepub fn extract(&self, rgb: [u8; 3]) -> &'static Color
pub fn extract(&self, rgb: [u8; 3]) -> &'static Color
Find the Color whose pre-computed LAB is closest to the
given RGB under this algorithm’s distance metric.
Equivalent to dispatching to the corresponding
Color::nearest_to* method by hand:
Sourcepub const fn as_str(&self) -> &'static str
pub const fn as_str(&self) -> &'static str
Stable string identifier for this algorithm — useful for log
lines, telemetry, and search-index metadata. Mirrors the
Family::as_str / Kind::as_str convention.