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