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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use core::ops;
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct BGR<ComponentType> {
pub b: ComponentType,
pub g: ComponentType,
pub r: ComponentType,
}
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct BGRA<ComponentType, AlphaComponentType = ComponentType> {
pub b: ComponentType,
pub g: ComponentType,
pub r: ComponentType,
pub a: AlphaComponentType,
}
pub type BGR8 = BGR<u8>;
pub type BGR16 = BGR<u16>;
pub type BGRA8 = BGRA<u8>;
pub type BGRA16 = BGRA<u16>;
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Gray<ComponentType>(
pub ComponentType);
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct GrayAlpha<ComponentType, AlphaComponentType = ComponentType>(
pub ComponentType,
pub AlphaComponentType);
pub type GRAY8 = Gray<u8>;
pub type GRAY16 = Gray<u16>;
pub type GRAYA8 = Gray<u8>;
pub type GRAYA16 = Gray<u16>;
impl<T> ops::Deref for Gray<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
#[test]
fn gray() {
let rgb: ::RGB<_> = Gray(1).into();
assert_eq!(rgb.r, 1);
assert_eq!(rgb.g, 1);
assert_eq!(rgb.b, 1);
assert_eq!(110, *Gray(100) + 10);
assert_eq!(110, 10 + Gray(100).as_ref());
let rgba: ::RGBA<_> = GrayAlpha(1,2).into();
assert_eq!(rgba.r, 1);
assert_eq!(rgba.g, 1);
assert_eq!(rgba.b, 1);
assert_eq!(rgba.a, 2);
}