From 55195368e29d4e30375750823f8780a9a2cc9154 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 9 Sep 2018 18:21:31 -0400 Subject: [PATCH] Add new test code --- src/main.rs | 72 ++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3022978..7b12e84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,47 +1,51 @@ extern crate memmap; +extern crate generic_array; pub mod durandal; pub mod marathon; -use std::{io, fs}; +use std::{io, fs, env}; +use std::io::Write; + use memmap::Mmap; +use marathon::wad; +use durandal::pict::load_pict; + fn main() -> io::Result<()> { - let fp = fs::File::open("data/Rubicon Map.sceA")?; - let mm = unsafe{Mmap::map(&fp)?}; - println!("{:?}", marathon::wad::Wad::new(&mm)); + 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.ent + { + if let Some(c) = ent.map.get(b"PICT") + { + let im = load_pict(c); + match im { + Ok(im) => { + let out = fs::File::create(format!("out_{}.ppm", id))?; + let mut out = io::BufWriter::new(out); + println!("entry {} has PICT {}x{}", id, im.w(), im.h()); + 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)?; + } + } + }, + Err(e) => println!("entry {} has PICT (invalid: {:?})", id, e), + } + } + } + Ok(()) } -/* -extern crate gtk; -use gtk::prelude::*; -use gtk::{Button, Window, WindowType}; - -fn main() -{ - if gtk::init().is_err() { - println!("failed to initialize GTK"); - return - } - - let win = Window::new(WindowType::Toplevel); - win.set_title("GTK test"); - win.set_default_size(350, 70); - let btn = Button::new_with_label("butts"); - win.add(&btn); - win.show_all(); - - win.connect_delete_event(|_, _| { - gtk::main_quit(); - Inhibit(false) - }); - - btn.connect_clicked(|_| {println!("clicc");}); - - gtk::main(); -} -*/ - // EOF