aboutsummaryrefslogtreecommitdiffstats
path: root/src/color.rs
blob: 52d9d613fcc7cbc7015ecee2ae4d6b3887d5dc59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std;

use types;

#[derive(Eq,PartialEq,Debug)]
pub enum Color {
    ColorDefault,
    ColorIdx(u8),
    ColorRgb(u8, u8, u8),
}

impl Color {
    pub fn new(color_impl: &types::ColorImpl) -> Color {
        let &types::ColorImpl(color_repr) = color_impl;
        let bytes: [u8; 4] = unsafe { std::mem::transmute(color_repr) };
        match bytes[3] {
            0 => Color::ColorDefault,
            1 => Color::ColorIdx(bytes[0]),
            2 => Color::ColorRgb(bytes[0], bytes[1], bytes[2]),
            _ => panic!("invalid color type"),
        }
    }
}