1#[cfg(feature = "argb")]
2use crate::alt::{ARGB};
3use crate::alt::{BGR, BGRA};
4use crate::{RGB, RGBA};
5
6impl<T: Copy> From<[T; 3]> for RGB<T> {
7 #[inline(always)]
8 fn from(other: [T; 3]) -> Self {
9 Self {
10 r: other[0],
11 g: other[1],
12 b: other[2],
13 }
14 }
15}
16
17impl<T> Into<[T; 3]> for RGB<T> {
18 #[inline(always)]
19 fn into(self) -> [T; 3] {
20 [self.r, self.g, self.b]
21 }
22}
23
24impl<T: Copy> From<[T; 4]> for RGBA<T> {
25 #[inline(always)]
26 fn from(other: [T; 4]) -> Self {
27 Self {
28 r: other[0],
29 g: other[1],
30 b: other[2],
31 a: other[3],
32 }
33 }
34}
35
36impl<T> Into<[T; 4]> for RGBA<T> {
37 #[inline(always)]
38 fn into(self) -> [T; 4] {
39 [self.r, self.g, self.b, self.a]
40 }
41}
42
43#[cfg(feature = "argb")]
44impl<T: Copy> From<[T; 4]> for ARGB<T> {
45 #[inline(always)]
46 fn from(other: [T; 4]) -> Self {
47 Self {
48 a: other[0],
49 r: other[1],
50 g: other[2],
51 b: other[3],
52 }
53 }
54}
55
56#[cfg(feature = "argb")]
57impl<T> Into<[T; 4]> for ARGB<T> {
58 #[inline(always)]
59 fn into(self) -> [T; 4] {
60 [self.a, self.r, self.g, self.b]
61 }
62}
63
64impl<T: Copy> From<[T; 3]> for BGR<T> {
65 #[inline(always)]
66 fn from(other: [T; 3]) -> Self {
67 Self {
68 b: other[0],
69 g: other[1],
70 r: other[2],
71 }
72 }
73}
74
75impl<T> Into<[T; 3]> for BGR<T> {
76 #[inline(always)]
77 fn into(self) -> [T; 3] {
78 [self.b, self.g, self.r]
79 }
80}
81
82impl<T: Copy> From<[T; 4]> for BGRA<T> {
83 #[inline(always)]
84 fn from(other: [T; 4]) -> Self {
85 Self {
86 b: other[0],
87 g: other[1],
88 r: other[2],
89 a: other[3],
90 }
91 }
92}
93
94impl<T> Into<[T; 4]> for BGRA<T> {
95 #[inline(always)]
96 fn into(self) -> [T; 4] {
97 [self.b, self.g, self.r, self.a]
98 }
99}
100
101#[test]
102#[allow(deprecated)]
103fn convert_array() {
104 use crate::alt::{BGR8, BGRA8};
105 use crate::{RGB8, RGBA8};
106
107 assert_eq!(RGB8::from([1, 2, 3]), RGB8::new(1, 2, 3));
108 assert_eq!(Into::<[u8; 3]>::into(RGB8::new(1, 2, 3)), [1, 2, 3]);
109 assert_eq!(RGBA8::from([1, 2, 3, 4]), RGBA8::new(1, 2, 3, 4));
110 assert_eq!(Into::<[u8; 4]>::into(RGBA8::new(1, 2, 3, 4)), [1, 2, 3, 4]);
111 assert_eq!(BGR8::from([3, 2, 1]), BGR8::new(1, 2, 3));
112 assert_eq!(Into::<[u8; 3]>::into(BGR8::new(1, 2, 3)), [3, 2, 1]);
113 assert_eq!(BGRA8::from([3, 2, 1, 4]), BGRA8::new(1, 2, 3, 4));
114 assert_eq!(Into::<[u8; 4]>::into(BGRA8::new(1, 2, 3, 4)), [3, 2, 1, 4]);
115}
116