1use crate::alt::BGR;
2use crate::alt::BGRA;
3use crate::RGB;
4use crate::RGBA;
5use core::convert::*;
6
7impl<T> From<(T,T,T)> for RGB<T> {
8 #[inline]
9 fn from(other: (T,T,T)) -> Self {
10 Self {
11 r: other.0,
12 g: other.1,
13 b: other.2,
14 }
15 }
16}
17
18impl<T> Into<(T,T,T)> for RGB<T> {
19 #[inline]
20 fn into(self) -> (T,T,T) {
21 (self.r, self.g, self.b)
22 }
23}
24
25impl<T,A> From<(T,T,T,A)> for RGBA<T,A> {
26 #[inline]
27 fn from(other: (T,T,T,A)) -> Self {
28 Self {
29 r: other.0,
30 g: other.1,
31 b: other.2,
32 a: other.3,
33 }
34 }
35}
36
37impl<T,A> Into<(T,T,T,A)> for RGBA<T,A> {
38 #[inline]
39 fn into(self) -> (T,T,T,A) {
40 (self.r, self.g, self.b, self.a)
41 }
42}
43
44impl<T> From<(T,T,T)> for BGR<T> {
45 #[inline(always)]
46 fn from(other: (T,T,T)) -> Self {
47 Self {
48 b: other.0,
49 g: other.1,
50 r: other.2,
51 }
52 }
53}
54
55impl<T> Into<(T,T,T)> for BGR<T> {
56 #[inline(always)]
57 fn into(self) -> (T,T,T) {
58 (self.b, self.g, self.r)
59 }
60}
61
62impl<T,A> From<(T,T,T,A)> for BGRA<T,A> {
63 #[inline(always)]
64 fn from(other: (T,T,T,A)) -> Self {
65 Self {
66 b: other.0,
67 g: other.1,
68 r: other.2,
69 a: other.3,
70 }
71 }
72}
73
74impl<T,A> Into<(T,T,T,A)> for BGRA<T,A> {
75 #[inline(always)]
76 fn into(self) -> (T,T,T,A) {
77 (self.b, self.g, self.r, self.a)
78 }
79}
80
81#[test]
82fn converts() {
83 assert_eq!((1,2,3), RGB {r:1u8,g:2,b:3}.into());
84 assert_eq!(RGB {r:1u8,g:2,b:3}, (1,2,3).into());
85 assert_eq!((1,2,3,4), RGBA {r:1,g:2,b:3,a:4}.into());
86 assert_eq!(RGBA {r:1u8,g:2,b:3,a:4}, (1,2,3,4).into());
87 assert_eq!(BGRA {r:1u8,g:2,b:3,a:4}, (3,2,1,4).into());
88 assert_eq!(BGR {r:1u8,g:2,b:3}, (3,2,1).into());
89}
90