rgrit_core/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![no_std]

use core::fmt::Formatter;

#[derive(Clone)]
pub struct StaticBitmap {
    pub gfx: &'static [u8],
    pub palette: &'static [u8],
    pub map: &'static [u8],
    pub meta: &'static [u8],
    pub spec: BitmapSpec,
}

#[derive(Clone, Copy, Debug, Default)]
pub enum Compression {
    #[default]
    Off,
    LZ77,
    Huffman,
    RLE,
    OffHeader,
}

#[derive(Clone, Copy, Debug)]
pub enum Color {
    RGB { r: u8, g: u8, b: u8 },
    GBR16(u16),
}

#[derive(Clone, Copy, Debug)]
pub enum Transparency {
    Disabled,
    Color(Color),
}

impl Default for Transparency {
    fn default() -> Self {
        Transparency::Color(Color::RGB {
            r: 0xFF,
            g: 0,
            b: 0xFF,
        })
    }
}

#[derive(Clone, Copy, Debug)]
pub enum BitDepth {
    A3I5,
    A5I3,
    FourByFour,
    Custom(u8),
}

#[derive(Clone, Copy, Debug)]
pub struct BitmapSpec {
    pub bit_depth: Option<BitDepth>,
    pub format: GfxFormat,
    pub transparency: Transparency,
}

#[derive(Clone, Copy, Debug, Default)]
pub enum GfxFormat {
    #[default]
    Bitmap,
    Tile,
}

impl core::fmt::Debug for StaticBitmap {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        f.debug_struct("StaticBitmap")
            .field("gfx", &format_args!("[u8; {}]", self.gfx.len()))
            .field("palette", &format_args!("[u8; {}]", self.palette.len()))
            .field("map", &format_args!("[u8; {}]", self.map.len()))
            .field("meta", &format_args!("[u8; {}]", self.meta.len()))
            .field("spec", &self.spec)
            .finish()
    }
}