Correctly parse colors 232-255

Those are grayscale
This commit is contained in:
Alexandre Bury 2018-01-14 16:57:46 -08:00
parent 3058816f1a
commit a9d9239fac

View File

@ -75,12 +75,19 @@ impl Color {
///
/// * Colors 0-7 are base dark colors.
/// * Colors 8-15 are base light colors.
/// * Colors 16-255 are rgb colors with 6 values per channel.
/// * Colors 16-231 are rgb colors with 6 values per channel (216 colors).
/// * Colors 232-255 are grayscale colors.
pub fn from_256colors(n: u8) -> Self {
if n < 8 {
Color::Dark(BaseColor::from(n))
} else if n < 16 {
Color::Light(BaseColor::from(n))
} else if n >= 232 {
let n = n - 232;
let value = 8 + 10 * n;
// TODO: returns a Grayscale value?
Color::Rgb(value, value, value)
} else {
let n = n - 16;
@ -88,6 +95,10 @@ impl Color {
let g = (n % 36) / 6;
let b = n % 6;
assert!(r < 5);
assert!(g < 5);
assert!(b < 5);
Color::RgbLowRes(r, g, b)
}
}