formatting

png-branch
an 2019-02-10 23:33:38 -05:00
parent 627e9969a3
commit b7a2e2cfde
4 changed files with 30 additions and 33 deletions

View File

@ -1,9 +1,7 @@
//! Binary data conversion utilities.
use crate::durandal::err::*;
use std::{fmt,
num::NonZeroU16,
slice::SliceIndex};
use std::{fmt, num::NonZeroU16, slice::SliceIndex};
/// Returns a byte array from `b` at `i`.
pub fn c_data<I>(b: &[u8], i: I) -> ResultS<&<I as SliceIndex<[u8]>>::Output>

View File

@ -5,21 +5,19 @@ pub use failure::{Error, Fail};
use crate::durandal::traits::PrimInt;
use std::fmt;
macro_rules! ok
{
macro_rules! ok {
($v:expr, $msg:expr) => {
match $v {
Some(v) => Ok(v),
None => Err(err_msg($msg)),
}
}
};
}
macro_rules! bail
{
macro_rules! bail {
($e:expr) => {
return Err(err_msg($e))
}
return Err(err_msg($e));
};
}
pub fn err_msg(msg: &'static str) -> Error

View File

@ -360,13 +360,12 @@ fn read_rle_data<F, N>(cmp: bool, len: usize, out: &mut Vec<u8>, mut read: F)
/// Expand packed pixel data based on bit depth.
pub fn expand_data(b: Vec<u8>, depth: u16) -> ResultS<Vec<u8>>
{
let mut o =
Vec::with_capacity(match depth {
4 => b.len() * 2,
2 => b.len() * 4,
1 => b.len() * 8,
_ => bail!("invalid bit depth"),
});
let mut o = Vec::with_capacity(match depth {
4 => b.len() * 2,
2 => b.len() * 4,
1 => b.len() * 8,
_ => bail!("invalid bit depth"),
});
for ch in b {
match depth {

View File

@ -19,8 +19,10 @@ fn color(b: &[u8]) -> ResultS<(usize, ColorShp)>
Ok((i, ColorShp::Opaque{r, g, b, l}))
}
fn clut_collection(b: &[u8], clr_num: usize, clu_num: usize)
-> ResultS<Vec<Vec<ColorShp>>>
fn clut_collection(b: &[u8],
clr_num: usize,
clu_num: usize)
-> ResultS<Vec<Vec<ColorShp>>>
{
let mut tables = vec![vec![ColorShp::Translucent; clr_num]; clu_num];
let mut p = 0;
@ -162,18 +164,17 @@ pub fn testfn_replaceme(b: &[u8]) -> ResultS<()>
let offset_hi = c_u32b(b, p + 12)? as usize;
let length_hi = c_u32b(b, p + 16)? as usize;
let collections = (
if offset_lo != u32::max_value() as usize {
Some(collection(c_data(b, offset_lo..offset_lo + length_lo)?)?)
} else {
None
},
if offset_hi != u32::max_value() as usize {
Some(collection(c_data(b, offset_hi..offset_hi + length_hi)?)?)
} else {
None
}
);
let collections =
(if offset_lo != u32::max_value() as usize {
Some(collection(c_data(b, offset_lo..offset_lo + length_lo)?)?)
} else {
None
},
if offset_hi != u32::max_value() as usize {
Some(collection(c_data(b, offset_hi..offset_hi + length_hi)?)?)
} else {
None
});
dbg!(collections);
}
@ -236,12 +237,13 @@ impl Color for ColorShp
enum ColorShp
{
Translucent,
Opaque {
Opaque
{
r: u16,
g: u16,
b: u16,
l: bool,
}
},
}
#[derive(Debug)]