1pub mod prelude {
2 pub use super::{Bgr, Bgra, Pixel, Rgb, Rgba};
3}
4
5use crate::CaptureFormat;
6
7pub trait Pixel: Copy {
8 const DEFAULT: Self;
9 const FORMAT: CaptureFormat;
10}
11
12#[derive(PartialEq, Eq, Clone, Copy, Debug)]
13#[repr(C, packed)]
14pub struct Rgb(pub [u8; 3]);
15
16impl Rgb {
17 pub(crate) const BLACK: Self = Self([0, 0, 0]);
18
19 #[inline]
20 pub fn r(&self) -> u8 {
21 self.0[0]
22 }
23
24 #[inline]
25 pub fn g(&self) -> u8 {
26 self.0[1]
27 }
28
29 #[inline]
30 pub fn b(&self) -> u8 {
31 self.0[2]
32 }
33}
34
35impl Pixel for Rgb {
36 const DEFAULT: Self = Self::BLACK;
37 const FORMAT: CaptureFormat = CaptureFormat::Rgb;
38}
39
40#[derive(PartialEq, Eq, Clone, Copy, Debug)]
41#[repr(C, packed)]
42pub struct Rgba(pub [u8; 4]);
43
44impl Rgba {
45 pub(crate) const BLACK: Self = Self([0, 0, 0, 255]);
46
47 #[inline]
48 pub fn r(&self) -> u8 {
49 self.0[0]
50 }
51
52 #[inline]
53 pub fn g(&self) -> u8 {
54 self.0[1]
55 }
56
57 #[inline]
58 pub fn b(&self) -> u8 {
59 self.0[2]
60 }
61
62 #[inline]
63 pub fn a(&self) -> u8 {
64 self.0[3]
65 }
66}
67
68impl Pixel for Rgba {
69 const DEFAULT: Self = Self::BLACK;
70 const FORMAT: CaptureFormat = CaptureFormat::Rgba;
71}
72
73#[derive(PartialEq, Eq, Clone, Copy, Debug)]
74#[repr(C, packed)]
75pub struct Bgr(pub [u8; 3]);
76
77impl Bgr {
78 pub(crate) const BLACK: Self = Self([0, 0, 0]);
79
80 #[inline]
81 pub fn b(&self) -> u8 {
82 self.0[0]
83 }
84
85 #[inline]
86 pub fn g(&self) -> u8 {
87 self.0[1]
88 }
89
90 #[inline]
91 pub fn r(&self) -> u8 {
92 self.0[2]
93 }
94}
95
96impl Pixel for Bgr {
97 const DEFAULT: Self = Self::BLACK;
98 const FORMAT: CaptureFormat = CaptureFormat::Bgr;
99}
100
101#[derive(PartialEq, Eq, Clone, Copy, Debug)]
102#[repr(C, packed)]
103pub struct Bgra(pub [u8; 4]);
104
105impl Bgra {
106 pub(crate) const BLACK: Self = Self([0, 0, 0, 255]);
107
108 #[inline]
109 pub fn b(&self) -> u8 {
110 self.0[0]
111 }
112
113 #[inline]
114 pub fn g(&self) -> u8 {
115 self.0[1]
116 }
117
118 #[inline]
119 pub fn r(&self) -> u8 {
120 self.0[2]
121 }
122
123 #[inline]
124 pub fn a(&self) -> u8 {
125 self.0[3]
126 }
127}
128
129impl Pixel for Bgra {
130 const DEFAULT: Self = Self::BLACK;
131 const FORMAT: CaptureFormat = CaptureFormat::Bgra;
132}