#[non_exhaustive]pub enum Quantize {
Perceptual,
Euclidean,
}Expand description
The distance metric Color::to_indexed_with and
Color::to_ansi_with use to find a palette entry’s nearest
neighbour.
§Examples
use retroglyph_core::color::{Color, Quantize};
let salmon = Color::Rgb { r: 250, g: 128, b: 114 };
assert_eq!(salmon.to_indexed_with(Quantize::Perceptual), Color::Indexed(210));
assert_eq!(salmon.to_indexed_with(Quantize::Euclidean), Color::Indexed(209));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Perceptual
Euclidean distance in the Oklab perceptually-uniform color space.
Matches human color perception far better than raw RGB distance, at the cost of
converting the input color to Oklab (three powf and three cbrt) on every call. The
palette side of the comparison is precomputed, so that conversion is the whole cost.
The default, and what Color::to_indexed and
Color::to_ansi use.
Euclidean
Euclidean distance over the raw 8-bit RGB channels.
Integer-only and allocation-free, and for Color::to_indexed_with
it finds the 6x6x6 cube’s nearest point by rounding each channel independently rather than
scanning the cube. Perceptually worse than Perceptual (it
over-weights green and under-weights blue), but it’s the rule most terminal tooling
applies, so it’s the one to pick when the output has to agree with another tool’s
downgrade.
Trait Implementations§
impl Copy for Quantize
impl Eq for Quantize
impl StructuralPartialEq for Quantize
Auto Trait Implementations§
impl Freeze for Quantize
impl RefUnwindSafe for Quantize
impl Send for Quantize
impl Sync for Quantize
impl Unpin for Quantize
impl UnsafeUnpin for Quantize
impl UnwindSafe for Quantize
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).