1use crate::sample::SampleType;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[non_exhaustive]
8pub enum PixelLayout {
9 Rgb,
11 Rgba,
13 Gray,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19#[non_exhaustive]
20pub enum PixelFormat {
21 Rgb8,
23 Rgba8,
25 Gray8,
27 Rgb16,
29 Rgba16,
31 Gray16,
33}
34
35impl PixelFormat {
36 pub const fn layout(self) -> PixelLayout {
38 match self {
39 Self::Rgb8 | Self::Rgb16 => PixelLayout::Rgb,
40 Self::Rgba8 | Self::Rgba16 => PixelLayout::Rgba,
41 Self::Gray8 | Self::Gray16 => PixelLayout::Gray,
42 }
43 }
44
45 pub const fn sample(self) -> SampleType {
47 match self {
48 Self::Rgb8 | Self::Rgba8 | Self::Gray8 => SampleType::U8,
49 Self::Rgb16 | Self::Rgba16 | Self::Gray16 => SampleType::U16,
50 }
51 }
52
53 pub const fn channels(self) -> usize {
55 match self.layout() {
56 PixelLayout::Rgb => 3,
57 PixelLayout::Rgba => 4,
58 PixelLayout::Gray => 1,
59 }
60 }
61
62 pub const fn bytes_per_sample(self) -> usize {
64 match self.sample() {
65 SampleType::U8 => 1,
66 SampleType::U16 => 2,
67 }
68 }
69
70 pub const fn bytes_per_pixel(self) -> usize {
72 self.channels() * self.bytes_per_sample()
73 }
74}