more standardization of style
parent
2cb4e49b49
commit
f65276bcc5
|
@ -52,9 +52,8 @@ impl BinUtil for [u8]
|
|||
}
|
||||
}
|
||||
|
||||
pub fn d_u32b(n: u32) -> [u8; 4] {[(n >> 24) as u8, (n >> 16) as u8,
|
||||
(n >> 8) as u8, (n >> 0) as u8]}
|
||||
pub fn d_u16b(n: u16) -> [u8; 2] {[(n >> 8) as u8, (n >> 0) as u8]}
|
||||
pub fn d_u32b(n: u32) -> [u8; 4] {n.to_be_bytes()}
|
||||
pub fn d_u16b(n: u16) -> [u8; 2] {n.to_be_bytes()}
|
||||
pub fn d_i32b(n: i32) -> [u8; 4] {d_u32b(n as u32)}
|
||||
pub fn d_i16b(n: i16) -> [u8; 2] {d_u16b(n as u16)}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ fn crc_accum(a: u32) -> u32
|
|||
fn crc_init() -> [u32; 256]
|
||||
{
|
||||
let mut t = [0; 256];
|
||||
for n in 0..256 {t[n] = (0..8).fold(n as u32, |a, _| crc_accum(a))}
|
||||
for n in 0..256 {t[n] = (0..8).fold(n as u32, |a, _| crc_accum(a));}
|
||||
t
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,9 @@ impl Image
|
|||
{
|
||||
/// Creates a new Image structure.
|
||||
pub fn new(w: usize, h: usize) -> Image
|
||||
{Image{w, h, cr: Vec::with_capacity(w * h)}}
|
||||
{
|
||||
Image{w, h, cr: Vec::with_capacity(w * h)}
|
||||
}
|
||||
|
||||
pub fn w(&self) -> usize {self.w}
|
||||
pub fn h(&self) -> usize {self.h}
|
||||
|
@ -50,13 +52,17 @@ impl Index<(usize, usize)> for Image
|
|||
type Output = Color;
|
||||
|
||||
fn index(&self, (x, y): (usize, usize)) -> &Color
|
||||
{&self.cr[x + y * self.w]}
|
||||
{
|
||||
&self.cr[x + y * self.w]
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexMut<(usize, usize)> for Image
|
||||
{
|
||||
fn index_mut(&mut self, (x, y): (usize, usize)) -> &mut Color
|
||||
{&mut self.cr[x + y * self.w]}
|
||||
{
|
||||
&mut self.cr[x + y * self.w]
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::durandal::bin::*;
|
|||
/// Checks for an AppleSingle header. Returns offset to the resource fork.
|
||||
pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
||||
{
|
||||
if b.o_u32b(0)? != 0x51600 || b.o_u32b(4)? != 0x20000 {return None}
|
||||
if b.o_u32b(0)? != 0x51600 || b.o_u32b(4)? != 0x20000 {return None;}
|
||||
|
||||
let num = b.o_u16b(24)? as usize;
|
||||
|
||||
|
@ -15,7 +15,7 @@ pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
|||
let ofs = b.o_u32b(p+4)? as usize;
|
||||
let len = b.o_u32b(p+8)? as usize;
|
||||
|
||||
if fid == 1 {return if ofs + len > b.len() {None} else {Some(ofs)}}
|
||||
if fid == 1 {return if ofs + len > b.len() {None} else {Some(ofs)};}
|
||||
}
|
||||
|
||||
None
|
||||
|
@ -24,15 +24,15 @@ pub fn check_apple_single(b: &[u8]) -> Option<usize>
|
|||
/// Checks for a MacBin header. Returns offset to the resource fork.
|
||||
pub fn check_mac_bin(b: &[u8]) -> Option<usize>
|
||||
{
|
||||
if b[0] != 0 || b[1] > 63 || b[74] != 0 || b[123] > 0x81 {return None}
|
||||
if b[0] != 0 || b[1] > 63 || b[74] != 0 || b[123] > 0x81 {return None;}
|
||||
|
||||
let mut crc = 0;
|
||||
|
||||
for i in 0..124 {
|
||||
for j in 8..16 {
|
||||
let d = b[i] as (u16) << j;
|
||||
if (d ^ crc) & 0x8000 != 0 {crc = crc << 1 ^ 0x1021}
|
||||
else {crc <<= 1}
|
||||
if (d ^ crc) & 0x8000 != 0 {crc = crc << 1 ^ 0x1021;}
|
||||
else {crc <<= 1;}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,12 @@ fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Result
|
|||
// planeofs = b.c_u32b(p+34)?;
|
||||
// clut_id = b.c_u32b(p+38)?;
|
||||
|
||||
if pitch_fl & 0x8000 == 0
|
||||
{return err_msg("PICT1 not supported")}
|
||||
if right - left != w || bottom - top != h
|
||||
{return err_msg("image bounds are incorrect")}
|
||||
if pitch_fl & 0x8000 == 0 {
|
||||
return err_msg("PICT1 not supported");
|
||||
}
|
||||
if right - left != w || bottom - top != h {
|
||||
return err_msg("image bounds are incorrect");
|
||||
}
|
||||
|
||||
p += 46; // size of header
|
||||
|
||||
|
@ -51,7 +53,7 @@ fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Result
|
|||
|
||||
p += 18; // srcRect, dstRect, mode
|
||||
|
||||
if clip {p += b.c_u16b(p)? as usize} // maskRgn
|
||||
if clip {p += b.c_u16b(p)? as usize;} // maskRgn
|
||||
|
||||
let rle = pack_typ == PACK_DEFAULT ||
|
||||
(pack_typ == PACK_RLE16 && depth == 16) ||
|
||||
|
@ -79,7 +81,7 @@ fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Result
|
|||
|
||||
p += pp;
|
||||
|
||||
for x in 0..w {im.cr.push(clut[d[x] as usize].clone())}
|
||||
for x in 0..w {im.cr.push(clut[d[x] as usize].clone());}
|
||||
}
|
||||
|
||||
Ok(im)
|
||||
|
@ -103,7 +105,7 @@ fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Result
|
|||
|
||||
p += pp;
|
||||
|
||||
for x in 0..w {im.cr.push(Color::from_r5g5b5(d.c_u16b(x*2)?))}
|
||||
for x in 0..w {im.cr.push(Color::from_r5g5b5(d.c_u16b(x*2)?));}
|
||||
}
|
||||
|
||||
Ok(im)
|
||||
|
@ -114,7 +116,7 @@ fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Result
|
|||
// uncompressed RGB8 or XRGB8
|
||||
for _ in 0..h {
|
||||
for _ in 0..w {
|
||||
if pack_typ != PACK_NOPAD {p += 1}
|
||||
if pack_typ != PACK_NOPAD {p += 1;}
|
||||
let (r, g, b) = (b[p], b[p+1], b[p+2]);
|
||||
p += 3;
|
||||
im.cr.push(Color{r, g, b, a: 255});
|
||||
|
@ -145,7 +147,9 @@ fn read_bitmap_area(mut im: Image, b: &[u8], packed: bool, clip: bool) -> Result
|
|||
|
||||
/// Process a CompressedQuickTime operation.
|
||||
fn read_quicktime_c(_im: Image, _b: &[u8]) -> ResultS<Image>
|
||||
{err_msg("compressed quicktime format not implemented")}
|
||||
{
|
||||
err_msg("compressed quicktime format not implemented")
|
||||
}
|
||||
|
||||
/// Load a PICT image.
|
||||
pub fn load_pict(b: &[u8]) -> ResultS<Image>
|
||||
|
@ -281,9 +285,9 @@ fn read_rle_data<F, N>(cmp: bool, len: usize, out: &mut Vec<u8>, mut read: F)
|
|||
{
|
||||
if cmp {
|
||||
let d = read();
|
||||
for _ in 0..len {for v in d.iter() {out.push(*v)}}
|
||||
for _ in 0..len {for v in d.iter() {out.push(*v);}}
|
||||
} else {
|
||||
for _ in 0..len {let d = read(); for v in d.iter() {out.push(*v)}}
|
||||
for _ in 0..len {let d = read(); for v in d.iter() {out.push(*v);}}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,9 +303,9 @@ fn expand_data(b: Vec<u8>, depth: u16) -> ResultS<Vec<u8>>
|
|||
|
||||
for ch in b {
|
||||
match depth {
|
||||
4 => for i in 1..=0 {o.push(ch >> i * 4 & 0xfu8)}, // 2 nibbles
|
||||
2 => for i in 3..=0 {o.push(ch >> i * 2 & 0x3u8)}, // 4 dibits
|
||||
1 => for i in 7..=0 {o.push(ch >> i * 1 & 0x1u8)}, // 8 bits
|
||||
4 => for i in 1..=0 {o.push(ch >> i * 4 & 0xfu8);}, // 2 nibbles
|
||||
2 => for i in 3..=0 {o.push(ch >> i * 2 & 0x3u8);}, // 4 dibits
|
||||
1 => for i in 7..=0 {o.push(ch >> i * 1 & 0x1u8);}, // 8 bits
|
||||
_ => return err_msg("invalid bit depth")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ pub fn to_binsize(n: u64) -> String
|
|||
const NAMES: [&str; 4] = ["kB", "MB", "GB", "TB"];
|
||||
|
||||
// empty size
|
||||
if n == 0 {return String::from("empty")}
|
||||
if n == 0 {return String::from("empty");}
|
||||
|
||||
// terabytes, gigabytes, megabytes, kilobytes
|
||||
for i in 4..=1 {
|
||||
|
@ -27,8 +27,8 @@ pub fn fuck_string(s: &[u8]) -> Vec<u8>
|
|||
let l = s.len();
|
||||
let mut p = 0;
|
||||
|
||||
for _ in 0..l / 4 {p += 2; v[p] ^= 0xfe; v[p + 1] ^= 0xed; p += 2}
|
||||
for _ in 0..l % 4 {v[p] ^= 0xfe; p += 1}
|
||||
for _ in 0..l / 4 {p += 2; v[p] ^= 0xfe; v[p + 1] ^= 0xed; p += 2;}
|
||||
for _ in 0..l % 4 {v[p] ^= 0xfe; p += 1;}
|
||||
|
||||
v
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ pub fn mac_roman_conv(s: &[u8]) -> String
|
|||
let mut v = String::with_capacity(s.len());
|
||||
|
||||
for i in 0..s.len() {
|
||||
if s[i] == 0 {break}
|
||||
else if s[i] & 0x80 != 0 {v.push(TR[s[i] as usize & 0x7f])}
|
||||
else if s[i] == b'\r' {v.push('\n')}
|
||||
else {v.push(s[i] as char)}
|
||||
if s[i] == 0 {break;}
|
||||
else if s[i] & 0x80 != 0 {v.push(TR[s[i] as usize & 0x7f]);}
|
||||
else if s[i] == b'\r' {v.push('\n');}
|
||||
else {v.push(s[i] as char);}
|
||||
}
|
||||
|
||||
v
|
||||
|
|
|
@ -148,7 +148,9 @@ impl From<u16> for Type
|
|||
impl fmt::Debug for Face
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||
{write!(f, "Face{{{} {} {}}}", self.ind, self.fce, self.col)}
|
||||
{
|
||||
write!(f, "Face{{{} {} {}}}", self.ind, self.fce, self.col)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Group
|
||||
|
@ -156,7 +158,7 @@ impl fmt::Debug for Group
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||
{
|
||||
write!(f, "Group{{{:?} {} {}", self.typ, self.per, self.lns)?;
|
||||
if self.txt.len() != 0 {write!(f, ";\n{}\n", self.txt)?}
|
||||
if self.txt.len() != 0 {write!(f, ";\n{}\n", self.txt)?;}
|
||||
write!(f, "}}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl fmt::Debug for Entry<'_>
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||
{
|
||||
write!(f, "Entry{{ ")?;
|
||||
for (ident, _) in &self.chunks {write!(f, "{} ", mac_roman_conv(ident))?}
|
||||
for (ident, _) in &self.chunks {write!(f, "{} ", mac_roman_conv(ident))?;}
|
||||
write!(f, "}}")
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ impl Wad<'_>
|
|||
pub fn new(b: &[u8]) -> ResultS<Wad>
|
||||
{
|
||||
let b = &b[try_mac_header(b)..];
|
||||
if b.len() < 128 {return err_msg("not enough data for Wad header")}
|
||||
if b.len() < 128 {return err_msg("not enough data for Wad header");}
|
||||
|
||||
let wadver = b.c_u16b( 0)?;
|
||||
let dataver = b.c_u16b( 2)?;
|
||||
|
@ -74,8 +74,7 @@ impl Wad<'_>
|
|||
let mut entries = EntryMap::new();
|
||||
let mut p = dirofs;
|
||||
|
||||
for i in 0..numents
|
||||
{
|
||||
for i in 0..numents {
|
||||
let offset = b.c_u32b(p )? as usize;
|
||||
let size = b.c_u32b(p+4)? as usize;
|
||||
let index = if !is_old {b.c_u16b(p+8)?} else {i as u16};
|
||||
|
@ -101,8 +100,7 @@ fn get_chunks(b: &[u8], is_old: bool) -> ResultS<ChunkMap>
|
|||
let mut chunks = ChunkMap::new();
|
||||
let mut p = 0;
|
||||
|
||||
while p < b.len()
|
||||
{
|
||||
while p < b.len() {
|
||||
let ident = b.c_iden(p )?;
|
||||
// offset = b.c_u32b(p+ 4)?;
|
||||
let size = b.c_u32b(p+ 8)? as usize;
|
||||
|
|
Loading…
Reference in New Issue