Maraiah/src/main.rs

74 lines
1.9 KiB
Rust
Raw Normal View History

2019-02-04 21:12:10 -08:00
use maraiah::durandal::{chunk::*, err::*, image::Image};
use maraiah::marathon::{map, pict, term, wad};
2018-09-11 01:21:36 -07:00
use memmap::Mmap;
2018-12-10 23:33:38 -08:00
use std::{io, io::Write, fs, env};
2018-09-10 07:30:46 -07:00
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() {
2018-12-10 23:32:59 -08:00
for x in 0..im.w() {
2018-09-10 07:30:46 -07:00
let cr = &im[(x, y)];
write!(&mut out, "{} {} {} ", cr.r, cr.g, cr.b)?;
}
}
Ok(())
}
2018-09-06 09:01:52 -07:00
2018-12-11 00:08:23 -08:00
fn main() -> ResultS<()>
2018-09-06 09:01:52 -07:00
{
2018-09-09 15:21:31 -07:00
let arg = env::args().nth(1).expect("need at least 1 argument");
let fp = fs::File::open(arg)?;
let mm = unsafe{Mmap::map(&fp)?};
2018-12-11 00:08:23 -08:00
let wad = wad::Wad::new(&mm)?;
2018-09-09 15:21:31 -07:00
2018-09-11 01:21:36 -07:00
println!("{:#?}", wad);
2018-09-09 15:21:31 -07:00
2018-12-10 23:32:59 -08:00
for (id, ent) in wad.entries {
if let Some(b) = ent.chunks.get(b"PICT") {
2019-02-04 21:12:10 -08:00
let im = pict::load_pict(b)?;
2018-12-11 15:50:23 -08:00
println!("entry {} has PICT {}x{}", id, im.w(), im.h());
write_ppm(&format!("out_{}.ppm", id), &im)?;
2018-09-09 15:21:31 -07:00
}
2018-12-10 23:32:59 -08:00
if let Some(b) = ent.chunks.get(b"Minf") {
2018-12-11 19:59:15 -08:00
let minf = map::Minf::chunk(b)?;
println!("entry {} has {:#?}", id, minf);
}
2018-12-13 01:08:02 -08:00
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);
}
2018-12-10 23:32:59 -08:00
if let Some(b) = ent.chunks.get(b"term") {
2018-12-11 15:50:23 -08:00
let term = term::Terminal::chunk(b)?;
println!("entry {} has term {:#?}", id, term);
2018-09-11 01:21:36 -07:00
}
2018-09-06 09:01:52 -07:00
}
2018-09-09 15:21:31 -07:00
Ok(())
2018-09-06 09:01:52 -07:00
}
// EOF