diff --git a/Cargo.toml b/Cargo.toml index 204da7b..feadbb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,12 +12,10 @@ memmap = "~0.2" gl = "*" gfx = "*" gfx_device_gl = "*" +image = "*" nalgebra = "*" num-traits = "*" openvr = { git = "https://github.com/rust-openvr/rust-openvr" } openvr_sys = "*" piston = "*" piston_window = "*" - -sdl2 = "0.22" -sdl2_image = "0.22" diff --git a/src/bin/tileview.rs b/src/bin/tileview.rs index 0e174a5..66d9f38 100644 --- a/src/bin/tileview.rs +++ b/src/bin/tileview.rs @@ -1,32 +1,26 @@ +extern crate image; extern crate itertools; -extern crate sdl2; -extern crate sdl2_image; use std::env; use std::io::Read; use std::path::Path; -use itertools::Itertools; -use sdl2::surface::Surface; -use sdl2::pixels::PixelFormatEnum; -use sdl2_image::SaveSurface; - -static EGA_PALETTE: [[u8; 4]; 16] = [[0x00u8, 0x00, 0x00, 0x00], - [0x00, 0xAA, 0x00, 0x00], +static EGA_PALETTE: [[u8; 4]; 16] = [[0x00, 0x00, 0x00, 0x00], [0x00, 0x00, 0xAA, 0x00], + [0x00, 0xAA, 0x00, 0x00], [0x00, 0xAA, 0xAA, 0x00], - [0x00, 0x00, 0x00, 0xAA], - [0x00, 0xAA, 0x00, 0xAA], - [0x00, 0x00, 0x55, 0xAA], - [0x00, 0xAA, 0xAA, 0xAA], - [0x00, 0x55, 0x55, 0x55], - [0x00, 0xFF, 0x55, 0x55], - [0x00, 0x55, 0xFF, 0x55], - [0x00, 0xFF, 0xFF, 0x55], - [0x00, 0x55, 0x55, 0xFF], - [0x00, 0xFF, 0x55, 0xFF], - [0x00, 0x55, 0xFF, 0xFF], - [0x00, 0xFF, 0xFF, 0xFF]]; + [0xAA, 0x00, 0x00, 0x00], + [0xAA, 0x00, 0xAA, 0x00], + [0xAA, 0x55, 0x00, 0x00], + [0xAA, 0xAA, 0xAA, 0x00], + [0x55, 0x55, 0x55, 0x00], + [0x55, 0x55, 0xFF, 0x00], + [0x55, 0xFF, 0x55, 0x00], + [0x55, 0xFF, 0xFF, 0x00], + [0xFF, 0x55, 0x55, 0x00], + [0xFF, 0x55, 0xFF, 0x00], + [0xFF, 0xFF, 0x55, 0x00], + [0xFF, 0xFF, 0xFF, 0x00]]; @@ -39,28 +33,24 @@ pub fn main() { filename = "data/SHAPES.EGA"; } - let _sdl_context = ::sdl2::init().unwrap(); - let _image_context = ::sdl2_image::init(::sdl2_image::INIT_PNG).unwrap(); - let mut file = std::fs::File::open(Path::new(filename)).unwrap(); let mut tile_buf = [0u8; 128]; - let mut surface = Surface::new(16, 16, PixelFormatEnum::RGBX8888).unwrap(); + let mut i = 0; while file.read_exact(&mut tile_buf).is_ok() { - surface.with_lock_mut(|pixel_bytes| { - pixel_bytes.iter_mut().set_from(tile_buf.iter() - .flat_map(|tile_byte| { - EGA_PALETTE[(tile_byte >> 4u8 & 0xF) as usize] - .into_iter() - .chain(EGA_PALETTE[(tile_byte & 0xF) as usize] - .into_iter()) - }) - .map(|x| *x)); - - - }); + let tilepixels = tile_buf.iter() + .flat_map(|tile_byte| { + EGA_PALETTE[(tile_byte >> 4u8 & 0xF) as usize] + .into_iter() + .chain(EGA_PALETTE[(tile_byte & 0xF) as usize] + .into_iter()) + }) + .map(|x| *x) + .collect::>(); let out_name = format!("out/{}.png", i); - surface.save(Path::new(&out_name)).ok(); + let out_file = std::fs::File::create(Path::new(&out_name)).expect("open out file"); + let enc = image::png::PNGEncoder::new(out_file); + enc.encode(&tilepixels, 16, 16, image::ColorType::RGBA(8)).expect("write png"); i += 1; } }