tile converter
This commit is contained in:
@@ -6,3 +6,6 @@ authors = ["Jared Roberts <jaredr@gmail.com>"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = ">=0.4"
|
itertools = ">=0.4"
|
||||||
memmap = "~0.2"
|
memmap = "~0.2"
|
||||||
|
|
||||||
|
sdl2 = "0.15"
|
||||||
|
sdl2_image = "1.0"
|
||||||
|
|||||||
66
src/bin/tileview.rs
Normal file
66
src/bin/tileview.rs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
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],
|
||||||
|
[0x00, 0x00, 0xAA, 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]];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let filename;
|
||||||
|
if args.len() > 1 {
|
||||||
|
filename = &args[1] as &str;
|
||||||
|
} else {
|
||||||
|
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 out_name = format!("out/{}.png", i);
|
||||||
|
surface.save(Path::new(&out_name)).ok();
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user