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
#![no_std]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
mod header;
use header::parse_header;
pub use header::{FileType, Header};
#[derive(Debug, Clone, PartialEq)]
pub struct Bmp<'a> {
pub header: Header,
image_data: &'a [u8],
}
impl<'a> Bmp<'a> {
pub fn from_slice(bytes: &'a [u8]) -> Result<Self, ()> {
let (_remaining, header) = parse_header(bytes).map_err(|_| ())?;
let image_data = &bytes[header.image_data_start..];
Ok(Bmp { header, image_data })
}
pub fn image_data(&'a self) -> &'a [u8] {
self.image_data
}
pub fn width(&self) -> u32 {
self.header.image_width
}
pub fn height(&self) -> u32 {
self.header.image_height
}
pub fn dimensions(&self) -> (u32, u32) {
(self.header.image_width, self.header.image_height)
}
pub fn bpp(&self) -> u32 {
self.header.bpp as u32
}
}