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
use crate::alt::BGR;
use crate::alt::BGRA;
use crate::RGB;
use crate::RGBA;
use core::convert::*;

impl<T> From<(T,T,T)> for RGB<T> {
    #[inline]
    fn from(other: (T,T,T)) -> Self {
        Self {
            r: other.0,
            g: other.1,
            b: other.2,
        }
    }
}

impl<T> Into<(T,T,T)> for RGB<T> {
    #[inline]
    fn into(self) -> (T,T,T) {
        (self.r, self.g, self.b)
    }
}

impl<T,A> From<(T,T,T,A)> for RGBA<T,A> {
    #[inline]
    fn from(other: (T,T,T,A)) -> Self {
        Self {
            r: other.0,
            g: other.1,
            b: other.2,
            a: other.3,
        }
    }
}

impl<T,A> Into<(T,T,T,A)> for RGBA<T,A> {
    #[inline]
    fn into(self) -> (T,T,T,A) {
        (self.r, self.g, self.b, self.a)
    }
}

impl<T> From<(T,T,T)> for BGR<T> {
    #[inline(always)]
    fn from(other: (T,T,T)) -> Self {
        Self {
            b: other.0,
            g: other.1,
            r: other.2,
        }
    }
}

impl<T> Into<(T,T,T)> for BGR<T> {
    #[inline(always)]
    fn into(self) -> (T,T,T) {
        (self.b, self.g, self.r)
    }
}

impl<T,A> From<(T,T,T,A)> for BGRA<T,A> {
    #[inline(always)]
    fn from(other: (T,T,T,A)) -> Self {
        Self {
            b: other.0,
            g: other.1,
            r: other.2,
            a: other.3,
        }
    }
}

impl<T,A> Into<(T,T,T,A)> for BGRA<T,A> {
    #[inline(always)]
    fn into(self) -> (T,T,T,A) {
        (self.b, self.g, self.r, self.a)
    }
}

#[test]
fn converts() {
    assert_eq!((1,2,3), RGB {r:1u8,g:2,b:3}.into());
    assert_eq!(RGB {r:1u8,g:2,b:3}, (1,2,3).into());
    assert_eq!((1,2,3,4), RGBA {r:1,g:2,b:3,a:4}.into());
    assert_eq!(RGBA {r:1u8,g:2,b:3,a:4}, (1,2,3,4).into());
    assert_eq!(BGRA {r:1u8,g:2,b:3,a:4}, (3,2,1,4).into());
    assert_eq!(BGR {r:1u8,g:2,b:3}, (3,2,1).into());
}