rustfmt
parent
717e0c841a
commit
b1d673faf3
|
@ -92,30 +92,11 @@ macro_rules! read_data {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn ident(b: &[u8]) -> Ident
|
||||
{
|
||||
[b[0], b[1], b[2], b[3]]
|
||||
}
|
||||
|
||||
pub fn u32b(b: &[u8]) -> u32
|
||||
{
|
||||
u32::from_be_bytes([b[0], b[1], b[2], b[3]])
|
||||
}
|
||||
|
||||
pub fn u16b(b: &[u8]) -> u16
|
||||
{
|
||||
u16::from_be_bytes([b[0], b[1]])
|
||||
}
|
||||
|
||||
pub fn i32b(b: &[u8]) -> i32
|
||||
{
|
||||
i32::from_be_bytes([b[0], b[1], b[2], b[3]])
|
||||
}
|
||||
|
||||
pub fn i16b(b: &[u8]) -> i16
|
||||
{
|
||||
i16::from_be_bytes([b[0], b[1]])
|
||||
}
|
||||
pub fn ident(b: &[u8]) -> Ident {[b[0], b[1], b[2], b[3]]}
|
||||
pub fn u32b(b: &[u8]) -> u32 {u32::from_be_bytes([b[0], b[1], b[2], b[3]])}
|
||||
pub fn u16b(b: &[u8]) -> u16 {u16::from_be_bytes([b[0], b[1]])}
|
||||
pub fn i32b(b: &[u8]) -> i32 {i32::from_be_bytes([b[0], b[1], b[2], b[3]])}
|
||||
pub fn i16b(b: &[u8]) -> i16 {i16::from_be_bytes([b[0], b[1]])}
|
||||
|
||||
pub fn rd_array<T, F>(b: &[u8], read: F) -> ResultS<Vec<T>>
|
||||
where T: Sized,
|
||||
|
|
|
@ -59,10 +59,7 @@ mod test
|
|||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn c_enum_should_error()
|
||||
{
|
||||
TestEnum::from_repr(3).unwrap();
|
||||
}
|
||||
fn c_enum_should_error() {TestEnum::from_repr(3).unwrap();}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -19,10 +19,7 @@ macro_rules! bail {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn err_msg(msg: &'static str) -> Error
|
||||
{
|
||||
Error::from(ErrMsg(msg))
|
||||
}
|
||||
pub fn err_msg(msg: &'static str) -> Error {Error::from(ErrMsg(msg))}
|
||||
|
||||
impl Fail for ReprError {}
|
||||
impl Fail for ErrMsg {}
|
||||
|
@ -45,10 +42,7 @@ impl fmt::Debug for ReprError
|
|||
|
||||
impl fmt::Display for ErrMsg
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||
{
|
||||
f.write_str(self.0)
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {f.write_str(self.0)}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ErrMsg
|
||||
|
|
|
@ -5,9 +5,7 @@ use std::{fmt::{self, Write},
|
|||
ops};
|
||||
|
||||
macro_rules! define_fixed_type {
|
||||
(
|
||||
$Type:ident : $IT:ident, $UT:ident, $LT:ident, $FracBits:expr
|
||||
) => {
|
||||
($Type:ident : $IT:ident, $UT:ident, $LT:ident, $FracBits:expr) => {
|
||||
#[derive(Clone, PartialEq, Serialize)]
|
||||
pub struct $Type($IT);
|
||||
|
||||
|
@ -17,40 +15,13 @@ macro_rules! define_fixed_type {
|
|||
const FRACMASK: $UT = (1 << Self::FRACBITS) - 1;
|
||||
const ONE: $IT = 1 << Self::FRACBITS;
|
||||
|
||||
pub fn to_bits(&self) -> $UT
|
||||
{
|
||||
self.0 as $UT
|
||||
}
|
||||
|
||||
pub fn set_bits(&mut self, bits: $UT)
|
||||
{
|
||||
self.0 = bits as $IT
|
||||
}
|
||||
|
||||
pub const fn from_bits(bits: $UT) -> Self
|
||||
{
|
||||
$Type(bits as $IT)
|
||||
}
|
||||
|
||||
pub fn integ(&self) -> $LT
|
||||
{
|
||||
(self.0 >> Self::FRACBITS) as $LT
|
||||
}
|
||||
|
||||
pub fn fract(&self) -> u16
|
||||
{
|
||||
(self.0 as $UT & Self::FRACMASK) as u16
|
||||
}
|
||||
|
||||
pub fn mul_i(&self, n: $LT) -> Self
|
||||
{
|
||||
$Type(self.0 * $IT::from(n))
|
||||
}
|
||||
|
||||
pub fn div_i(&self, n: $LT) -> Self
|
||||
{
|
||||
$Type(self.0 / $IT::from(n))
|
||||
}
|
||||
pub fn to_bits(&self) -> $UT {self.0 as $UT}
|
||||
pub fn set_bits(&mut self, bits: $UT) {self.0 = bits as $IT}
|
||||
pub const fn from_bits(bits: $UT) -> Self {$Type(bits as $IT)}
|
||||
pub fn integ(&self) -> $LT {(self.0 >> Self::FRACBITS) as $LT}
|
||||
pub fn fract(&self) -> u16 {(self.0 as $UT & Self::FRACMASK) as u16}
|
||||
pub fn mul_i(&self, n: $LT) -> Self {$Type(self.0 * $IT::from(n))}
|
||||
pub fn div_i(&self, n: $LT) -> Self {$Type(self.0 / $IT::from(n))}
|
||||
|
||||
#[inline]
|
||||
fn fx_div(x: $IT, y: $IT) -> $IT
|
||||
|
@ -67,70 +38,49 @@ macro_rules! define_fixed_type {
|
|||
|
||||
impl From<$LT> for $Type
|
||||
{
|
||||
fn from(n: $LT) -> Self
|
||||
{
|
||||
$Type($IT::from(n) << Self::FRACBITS)
|
||||
}
|
||||
fn from(n: $LT) -> Self {$Type($IT::from(n) << Self::FRACBITS)}
|
||||
}
|
||||
|
||||
impl ops::Add for $Type
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, o: Self) -> Self
|
||||
{
|
||||
$Type(self.0 + o.0)
|
||||
}
|
||||
fn add(self, o: Self) -> Self {$Type(self.0 + o.0)}
|
||||
}
|
||||
|
||||
impl ops::Sub for $Type
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, o: Self) -> Self
|
||||
{
|
||||
$Type(self.0 - o.0)
|
||||
}
|
||||
fn sub(self, o: Self) -> Self {$Type(self.0 - o.0)}
|
||||
}
|
||||
|
||||
impl ops::Mul for $Type
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, o: Self) -> Self
|
||||
{
|
||||
$Type(Self::fx_mul(self.0, o.0))
|
||||
}
|
||||
fn mul(self, o: Self) -> Self {$Type(Self::fx_mul(self.0, o.0))}
|
||||
}
|
||||
|
||||
impl ops::Div for $Type
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn div(self, o: Self) -> Self
|
||||
{
|
||||
$Type(Self::fx_div(self.0, o.0))
|
||||
}
|
||||
fn div(self, o: Self) -> Self {$Type(Self::fx_div(self.0, o.0))}
|
||||
}
|
||||
|
||||
impl ops::Neg for $Type
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self
|
||||
{
|
||||
$Type(-self.0)
|
||||
}
|
||||
fn neg(self) -> Self {$Type(-self.0)}
|
||||
}
|
||||
|
||||
impl ops::Not for $Type
|
||||
{
|
||||
type Output = Self;
|
||||
|
||||
fn not(self) -> Self
|
||||
{
|
||||
$Type(!self.0)
|
||||
}
|
||||
fn not(self) -> Self {$Type(!self.0)}
|
||||
}
|
||||
|
||||
impl fmt::Display for $Type
|
||||
|
@ -183,10 +133,7 @@ fn fixed_basic_ops()
|
|||
#[test]
|
||||
#[should_panic]
|
||||
#[allow(unused_must_use)]
|
||||
fn fixed_overflow()
|
||||
{
|
||||
Fixed::from(i16::max_value()) + 1.into();
|
||||
}
|
||||
fn fixed_overflow() {Fixed::from(i16::max_value()) + 1.into();}
|
||||
|
||||
#[test]
|
||||
fn fixed_printing()
|
||||
|
|
|
@ -142,10 +142,7 @@ impl Image for Image8
|
|||
|
||||
impl Color16
|
||||
{
|
||||
pub const fn new(r: u16, g: u16, b: u16) -> Color16
|
||||
{
|
||||
Color16(r, g, b)
|
||||
}
|
||||
pub const fn new(r: u16, g: u16, b: u16) -> Color16 {Color16(r, g, b)}
|
||||
}
|
||||
|
||||
impl Color for Color16
|
||||
|
@ -158,10 +155,7 @@ impl Color for Color16
|
|||
|
||||
impl Color8
|
||||
{
|
||||
pub const fn new(r: u8, g: u8, b: u8) -> Color8
|
||||
{
|
||||
Color8(r, g, b)
|
||||
}
|
||||
pub const fn new(r: u8, g: u8, b: u8) -> Color8 {Color8(r, g, b)}
|
||||
}
|
||||
|
||||
impl Color for Color8
|
||||
|
|
|
@ -44,10 +44,7 @@ pub trait Sound
|
|||
fn lp_beg(&self) -> usize;
|
||||
fn lp_end(&self) -> usize;
|
||||
|
||||
fn is_empty(&self) -> bool
|
||||
{
|
||||
self.len() == 0
|
||||
}
|
||||
fn is_empty(&self) -> bool {self.len() == 0}
|
||||
|
||||
fn get(&self, p: usize) -> Option<i16>
|
||||
{
|
||||
|
@ -68,7 +65,8 @@ impl Sound16
|
|||
}
|
||||
|
||||
/// Creates a new Sound16 from an unsigned 8-bit stream.
|
||||
pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) -> Self
|
||||
pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8])
|
||||
-> Self
|
||||
{
|
||||
let mut snd = Sound16::new(rate, lp_beg, lp_end, b.len());
|
||||
|
||||
|
@ -80,7 +78,8 @@ impl Sound16
|
|||
}
|
||||
|
||||
/// Creates a new Sound16 from a signed 16-bit stream.
|
||||
pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) -> Self
|
||||
pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8])
|
||||
-> Self
|
||||
{
|
||||
let mut snd = Sound16::new(rate, lp_beg, lp_end, b.len() / 2);
|
||||
|
||||
|
@ -92,10 +91,7 @@ impl Sound16
|
|||
}
|
||||
|
||||
/// Creates a signed 16-bit sample from an unsigned 8-bit sample.
|
||||
pub fn sample_from_8(sample: u8) -> i16
|
||||
{
|
||||
(i16::from(sample) - 0x80) << 8
|
||||
}
|
||||
pub fn sample_from_8(sample: u8) -> i16 {(i16::from(sample) - 0x80) << 8}
|
||||
}
|
||||
|
||||
impl Sound for Sound16
|
||||
|
|
52
src/main.rs
52
src/main.rs
|
@ -201,43 +201,69 @@ fn main() -> ResultS<()>
|
|||
ap.refer(&mut opt.inputs)
|
||||
.add_argument("inputs", Collect, "Input files");
|
||||
|
||||
arg!("--shp-write-tab", opt.shp_tab, StoreTrue,
|
||||
arg!("--shp-write-tab",
|
||||
opt.shp_tab,
|
||||
StoreTrue,
|
||||
"shp: Dump all CLUTs as YAML to standard output");
|
||||
|
||||
arg!("--shp-dump-bitmaps", opt.shp_bmp, StoreTrue,
|
||||
arg!("--shp-dump-bitmaps",
|
||||
opt.shp_bmp,
|
||||
StoreTrue,
|
||||
"shp: Dump bitmaps into a folder");
|
||||
|
||||
arg!("--shp-dump-more-bitmaps", opt.shp_bmp_all, StoreTrue,
|
||||
arg!("--shp-dump-more-bitmaps",
|
||||
opt.shp_bmp_all,
|
||||
StoreTrue,
|
||||
"shp: Dump all color variations of each bitmap");
|
||||
|
||||
arg!("--shp-write-frm", opt.shp_frm, StoreTrue,
|
||||
arg!("--shp-write-frm",
|
||||
opt.shp_frm,
|
||||
StoreTrue,
|
||||
"shp: Dump all frames as YAML to standard output");
|
||||
|
||||
arg!("--shp-write-seq", opt.shp_seq, StoreTrue,
|
||||
arg!("--shp-write-seq",
|
||||
opt.shp_seq,
|
||||
StoreTrue,
|
||||
"shp: Dump all sequences as YAML to standard output");
|
||||
|
||||
arg!("--snd-write", opt.snd_write, StoreTrue,
|
||||
arg!("--snd-write",
|
||||
opt.snd_write,
|
||||
StoreTrue,
|
||||
"snd: Dump all sound headers as YAML to standard output");
|
||||
|
||||
arg!("--snd-dump", opt.snd_dump, StoreTrue,
|
||||
arg!("--snd-dump",
|
||||
opt.snd_dump,
|
||||
StoreTrue,
|
||||
"snd: Dump all sounds to WAVE files");
|
||||
|
||||
arg!("--wad-dump-all", opt.wad_all, StoreTrue,
|
||||
arg!("--wad-dump-all",
|
||||
opt.wad_all,
|
||||
StoreTrue,
|
||||
"wad: Dump all chunks into a folder");
|
||||
|
||||
arg!("--wad-dump-unknown", opt.wad_unknown, StoreTrue,
|
||||
arg!("--wad-dump-unknown",
|
||||
opt.wad_unknown,
|
||||
StoreTrue,
|
||||
"wad: Dump all unknown chunks into a folder");
|
||||
|
||||
arg!("--wad-write-header", opt.wad_header, StoreTrue,
|
||||
arg!("--wad-write-header",
|
||||
opt.wad_header,
|
||||
StoreTrue,
|
||||
"wad: Dump header info as YAML to standard output");
|
||||
|
||||
arg!("--wad-write-chunks", opt.wad_c_temp, Store,
|
||||
arg!("--wad-write-chunks",
|
||||
opt.wad_c_temp,
|
||||
Store,
|
||||
"wad: Dump specified chunks in various formats");
|
||||
|
||||
arg!("--out-dir", opt.out_dir, Store,
|
||||
arg!("--out-dir",
|
||||
opt.out_dir,
|
||||
Store,
|
||||
"Sets output directory for dump options");
|
||||
|
||||
arg!("--out-debug", opt.out_debug, StoreTrue,
|
||||
arg!("--out-debug",
|
||||
opt.out_debug,
|
||||
StoreTrue,
|
||||
"Writes debugging output rather than YAML");
|
||||
|
||||
ap.parse_args_or_exit();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{durandal::{bin::*, err::*, fixed::*,
|
||||
text::mac_roman_conv},
|
||||
use crate::{durandal::{bin::*, err::*, fixed::*, text::mac_roman_conv},
|
||||
marathon::xfer::TransferMode};
|
||||
use bitflags::bitflags;
|
||||
use serde::Serialize;
|
||||
|
|
|
@ -78,12 +78,17 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
|||
// RLE compressed 1, 2, 4 or 8 bit colormap indices
|
||||
for _ in 0..im.h() {
|
||||
let (d, pp) = read_rle(&b[p..], hdr.pitch, false)?;
|
||||
let d = if hdr.depth < 8 {expand_data(d, hdr.depth)?} else {d};
|
||||
let d = if hdr.depth < 8 {
|
||||
expand_data(d, hdr.depth)?
|
||||
} else {
|
||||
d
|
||||
};
|
||||
|
||||
p += pp;
|
||||
|
||||
for &idx in &d {
|
||||
im.cr.push(ok!(clut.get(idx as usize), "invalid index")?.clone());
|
||||
im.cr
|
||||
.push(ok!(clut.get(idx as usize), "invalid index")?.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +138,10 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
|||
{
|
||||
let mut p = 0;
|
||||
|
||||
if hdr.pitch < 8 || hdr.pack_t == PackType::None || hdr.pack_t == PackType::NoPad {
|
||||
if hdr.pitch < 8 ||
|
||||
hdr.pack_t == PackType::None ||
|
||||
hdr.pack_t == PackType::NoPad
|
||||
{
|
||||
// uncompressed RGB8 or XRGB8
|
||||
for _ in 0..im.h() {
|
||||
for _ in 0..im.w() {
|
||||
|
@ -178,10 +186,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
|
|||
}
|
||||
|
||||
/// Process a CopyBits operation.
|
||||
fn read_pm_area(im: Image8,
|
||||
b: &[u8],
|
||||
pack: bool,
|
||||
clip: bool)
|
||||
fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool)
|
||||
-> ResultS<Image8>
|
||||
{
|
||||
let p = if pack {0} else {4};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use maraiah::{durandal::{bin, fixed::*}, marathon::map};
|
||||
use maraiah::{durandal::{bin, fixed::*},
|
||||
marathon::map};
|
||||
|
||||
#[test]
|
||||
fn read_epnt_must_process_this()
|
||||
{
|
||||
assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(), OUTPUT.to_vec());
|
||||
assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(),
|
||||
OUTPUT.to_vec());
|
||||
}
|
||||
|
||||
const INPUT: &'static [u8] = include_bytes!("data/epnt.in");
|
||||
|
|
|
@ -3,15 +3,14 @@ use maraiah::marathon::map;
|
|||
#[test]
|
||||
fn read_minf_must_process_map0()
|
||||
{
|
||||
assert_eq!(map::read_minf(INPUT).unwrap(), map::Minf{
|
||||
env_code: 0,
|
||||
assert_eq!(map::read_minf(INPUT).unwrap(),
|
||||
map::Minf{env_code: 0,
|
||||
physi_id: 1,
|
||||
music_id: 1,
|
||||
msn_flag: map::MsnFlags::Repair,
|
||||
env_flag: map::EnvFlags::empty(),
|
||||
ent_flag: map::EntFlags::Solo | map::EntFlags::CoOp,
|
||||
levelnam: "Waterloo Waterpark".to_string()
|
||||
});
|
||||
levelnam: "Waterloo Waterpark".to_string()});
|
||||
}
|
||||
|
||||
const INPUT: &'static [u8] = include_bytes!("data/minf.in");
|
||||
|
|
Loading…
Reference in New Issue