1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2017, Marty Mills <daggerbot@gmail.com>
// This software is available under the terms of the zlib license.
// See COPYING.md for more information.

extern crate dnum;
#[cfg(feature = "serde_")]
extern crate serde;
#[cfg(feature = "serde_")]
#[macro_use]
extern crate serde_derive;

mod clamp;
mod consts;
mod conv;
mod lum;
mod ops;
mod rgb;

pub use clamp::{Clamp, ClampFrom, ClampInto};
pub use consts::{Color};
pub use conv::{FromColor, IntoColor};
pub use lum::{Lum, Luma, Luminance};
pub use rgb::{Rgb, Rgba};

/// Gets a color from an RGB constant.
pub fn rgb<T> (n: u32) -> T
    where Rgb<u8>: IntoColor<T>
{
    Rgb {
        r: (n >> 16) as u8,
        g: (n >> 8) as u8,
        b: n as u8,
    }.into_color()
}

/// Gets a color from an ARGB constant.
pub fn argb<T> (n: u32) -> T
    where Rgba<u8>: IntoColor<T>
{
    Rgba {
        r: (n >> 16) as u8,
        g: (n >> 8) as u8,
        b: n as u8,
        a: (n >> 24) as u8,
    }.into_color()
}