Skip to main content

rosetta_squint_decode/
types.rs

1/// Number of color channels in a DecodedImage's pixel buffer.
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3pub enum Channels {
4    Rgb,
5    Rgba,
6}
7
8impl Channels {
9    /// Returns 3 for Rgb, 4 for Rgba.
10    pub fn bytes_per_pixel(&self) -> usize {
11        match self {
12            Channels::Rgb => 3,
13            Channels::Rgba => 4,
14        }
15    }
16}
17
18/// Image format tag.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub enum Format {
21    Bmp,
22    Png,
23    Gif,
24    Jpeg,
25    Webp,
26    Tiff,
27    Heic,
28    Emf,
29    Wmf,
30}
31
32impl std::fmt::Display for Format {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        let s = match self {
35            Format::Bmp => "bmp",
36            Format::Png => "png",
37            Format::Gif => "gif",
38            Format::Jpeg => "jpeg",
39            Format::Webp => "webp",
40            Format::Tiff => "tiff",
41            Format::Heic => "heic",
42            Format::Emf => "emf",
43            Format::Wmf => "wmf",
44        };
45        f.write_str(s)
46    }
47}
48
49/// Result of a successful Decode call.
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub struct DecodedImage {
52    pub width: usize,
53    pub height: usize,
54    pub data: Vec<u8>,
55    pub channels: Channels,
56    pub format: Format,
57}