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
/// The PaletteEntry Object defines the color and usage of an entry in a
/// palette.
#[derive(Clone, Debug)]
pub struct PaletteEntry {
/// Red (1 byte): An 8-bit unsigned integer that defines the red intensity
/// value for the palette entry.
pub red: u8,
/// Green (1 byte): An 8-bit unsigned integer that defines the green
/// intensity value for the palette entry.
pub green: u8,
/// Blue (1 byte): An 8-bit unsigned integer that defines the blue
/// intensity value for the palette entry.
pub blue: u8,
/// Values (1 byte): An 8-bit unsigned integer that defines how the palette
/// entry is to be used. The Values field MUST be 0x00 or one of the values
/// in the PaletteEntryFlag Enumeration table.
pub values: Option<crate::wmf::parser::PaletteEntryFlag>,
}
impl PaletteEntry {
#[cfg_attr(feature = "tracing", tracing::instrument(
level = tracing::Level::TRACE,
skip_all,
err(level = tracing::Level::ERROR, Display),
))]
pub fn parse<R: crate::wmf::Read>(
buf: &mut R,
) -> Result<(Self, usize), crate::wmf::parser::ParseError> {
let ((red, red_bytes), (green, green_bytes), (blue, blue_bytes), (values, values_bytes)) = (
crate::wmf::parser::read_u8_from_le_bytes(buf)?,
crate::wmf::parser::read_u8_from_le_bytes(buf)?,
crate::wmf::parser::read_u8_from_le_bytes(buf)?,
crate::wmf::parser::read_u8_from_le_bytes(buf)?,
);
let consumed_bytes = red_bytes + green_bytes + blue_bytes + values_bytes;
let values = match values {
0x00 => None,
v => Some(
crate::wmf::parser::PaletteEntryFlag::from_repr(v).ok_or_else(|| {
crate::wmf::parser::ParseError::UnexpectedEnumValue {
cause: format!("invalid value {v} as PaletteEntryFlag"),
}
})?,
),
};
Ok((
Self {
red,
green,
blue,
values,
},
consumed_bytes,
))
}
}