Maraiah/src/main.rs

74 lines
1.9 KiB
Rust

use maraiah::durandal::{chunk::*, err::*, image::Image};
use maraiah::marathon::{map, pict, term, wad};
use memmap::Mmap;
use std::{io, io::Write, fs, env};
fn write_ppm(fname: &str, im: &Image) -> io::Result<()>
{
let out = fs::File::create(fname)?;
let mut out = io::BufWriter::new(out);
write!(&mut out, "P3\n{} {}\n255\n", im.w(), im.h())?;
for y in 0..im.h() {
for x in 0..im.w() {
let cr = &im[(x, y)];
write!(&mut out, "{} {} {} ", cr.r, cr.g, cr.b)?;
}
}
Ok(())
}
fn main() -> ResultS<()>
{
let arg = env::args().nth(1).expect("need at least 1 argument");
let fp = fs::File::open(arg)?;
let mm = unsafe{Mmap::map(&fp)?};
let wad = wad::Wad::new(&mm)?;
println!("{:#?}", wad);
for (id, ent) in wad.entries {
if let Some(b) = ent.chunks.get(b"PICT") {
let im = pict::load_pict(b)?;
println!("entry {} has PICT {}x{}", id, im.w(), im.h());
write_ppm(&format!("out_{}.ppm", id), &im)?;
}
if let Some(b) = ent.chunks.get(b"Minf") {
let minf = map::Minf::chunk(b)?;
println!("entry {} has {:#?}", id, minf);
}
if let Some(b) = ent.chunks.get(b"EPNT") {
let epnt = map::Endpoint::chunk(b)?;
println!("entry {} has EPNT {:#?}", id, epnt);
}
if let Some(b) = ent.chunks.get(b"PNTS") {
let epnt = map::Point::chunk(b)?;
println!("entry {} has PNTS {:#?}", id, epnt);
}
if let Some(b) = ent.chunks.get(b"LINS") {
let line = map::Line::chunk(b)?;
println!("entry {} has LINS {:#?}", id, line);
}
if let Some(b) = ent.chunks.get(b"SIDS") {
let line = map::Side::chunk(b)?;
println!("entry {} has SIDS {:#?}", id, line);
}
if let Some(b) = ent.chunks.get(b"term") {
let term = term::Terminal::chunk(b)?;
println!("entry {} has term {:#?}", id, term);
}
}
Ok(())
}
// EOF