code cleanup

png-branch
an 2019-02-16 12:07:28 -05:00
parent 5dddf61119
commit 2fd48d53a2
4 changed files with 17 additions and 4 deletions

View File

@ -28,7 +28,7 @@ pub fn crc32(b: &[u8], s: u32) -> u32
#[test]
fn crc32_lorem_ipsum()
{
assert_eq!(crc32(b"Lorem ipsum dolor sit amet", !0), 0x5F29D461);
assert_eq!(crc32(b"Lorem ipsum dolor sit amet", !0), 0x5F29_D461);
}
// EOF

View File

@ -295,7 +295,7 @@ pub fn get_clut(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>
for i in 0..num {
// with device mapping, we ignore the index entirely
let n = if !dev {c_byte(b, p + 1)? as usize} else {i};
let n = if !dev {c_u16b(b, p)? as usize} else {i};
let r = c_byte(b, p + 2)?;
let g = c_byte(b, p + 4)?;
let b = c_byte(b, p + 6)?;

View File

@ -384,7 +384,7 @@ pub struct Collection
pub type CollectionDef = (Option<Collection>, Option<Collection>);
bitflags! {
pub struct BmpFlags: u16
struct BmpFlags: u16
{
const ColumnMajor = 0x80_00;
const Transparent = 0x40_00;

View File

@ -1,9 +1,11 @@
use crate::durandal::{bin::*, chunk::*, err::*, text::*};
use bitflags::bitflags;
use serde::Serialize;
use std::fmt;
fn read_group(b: &[u8], text: &[u8]) -> ResultS<Group>
{
let flags = c_u16b(b, 0)?;
let ttype = c_u16b(b, 2)?;
let pdata = c_i16b(b, 4)?;
let start = c_u16b(b, 6)? as usize;
@ -11,9 +13,10 @@ fn read_group(b: &[u8], text: &[u8]) -> ResultS<Group>
let lines = c_u16b(b, 10)?;
let text = c_data(text, start..start + size)?;
let text = mac_roman_conv(text);
let flags = ok!(GroupFlags::from_bits(flags), "bad GroupFlags")?;
let ttype = GroupType::from_repr(ttype)?;
Ok(Group{ttype, pdata, lines, text})
Ok(Group{flags, ttype, pdata, lines, text})
}
fn read_face(b: &[u8]) -> ResultS<Face>
@ -98,12 +101,22 @@ pub struct Face
#[derive(Serialize)]
pub struct Group
{
flags: GroupFlags,
ttype: GroupType,
pdata: i16,
lines: u16,
text: String,
}
bitflags! {
#[derive(Serialize)]
pub struct GroupFlags: u16
{
const DrawOnRight = 0x00_01;
const DrawCenter = 0x00_02;
}
}
c_enum! {
#[derive(Debug, Serialize)]
pub enum GroupType: u16