Guide API
Skip to main content

rgb_to_xterm256

Function rgb_to_xterm256 

Source
pub fn rgb_to_xterm256(r: u8, g: u8, b: u8) -> u8
Expand description

Map an RGB triplet to the nearest xterm-256 index in the range 16..=255.

The result is never in 0..=15 (the xterm-16 palette). The colour is first quantized to the 6×6×6 colour cube; if that index does not round-trip back to the input, the colour is too achromatic and falls back to the 24-step grayscale ramp.