Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 8-bit color indices consistently #66

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/pdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ pub enum Row {
/// Numeric color ID
color: ColorIndex,
/// Unknown field.
unknown3: u8,
unknown3: u16,
/// User-defined name of the color.
name: DeviceSQLString,
},
Expand Down Expand Up @@ -898,8 +898,8 @@ impl Row {
fn parse_color(input: &[u8]) -> IResult<&[u8], Row> {
let (input, unknown1) = nom::number::complete::le_u32(input)?;
let (input, unknown2) = nom::number::complete::u8(input)?;
let (input, color) = ColorIndex::parse_u16(input)?;
let (input, unknown3) = nom::number::complete::u8(input)?;
let (input, color) = ColorIndex::parse(input)?;
let (input, unknown3) = nom::number::complete::le_u16(input)?;
let (input, name) = DeviceSQLString::parse(input)?;
Ok((
input,
Expand Down Expand Up @@ -1021,7 +1021,7 @@ impl Row {
let (input, sample_depth) = nom::number::complete::le_u16(input)?;
let (input, duration) = nom::number::complete::le_u16(input)?;
let (input, unknown5) = nom::number::complete::le_u16(input)?;
let (input, color) = ColorIndex::parse_u8(input)?;
let (input, color) = ColorIndex::parse(input)?;
let (input, rating) = nom::number::complete::u8(input)?;
let (input, unknown6) = nom::number::complete::le_u16(input)?;
let (input, unknown7) = nom::number::complete::le_u16(input)?;
Expand Down
8 changes: 1 addition & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,10 @@ pub enum ColorIndex {

impl ColorIndex {
/// Parse an 8-bit color index from an input slice.
pub fn parse_u8(input: &[u8]) -> IResult<&[u8], Self> {
pub fn parse(input: &[u8]) -> IResult<&[u8], Self> {
let (input, color_id) = nom::number::complete::u8(input)?;
Ok((input, Self::from(u16::from(color_id))))
}

/// Parse a 16-bit color index from an input slice.
pub fn parse_u16(input: &[u8]) -> IResult<&[u8], Self> {
let (input, color_id) = nom::number::complete::le_u16(input)?;
Ok((input, Self::from(color_id)))
}
}

impl From<u16> for ColorIndex {
Expand Down