drop SDL dep
This commit is contained in:
@@ -12,12 +12,10 @@ memmap = "~0.2"
|
|||||||
gl = "*"
|
gl = "*"
|
||||||
gfx = "*"
|
gfx = "*"
|
||||||
gfx_device_gl = "*"
|
gfx_device_gl = "*"
|
||||||
|
image = "*"
|
||||||
nalgebra = "*"
|
nalgebra = "*"
|
||||||
num-traits = "*"
|
num-traits = "*"
|
||||||
openvr = { git = "https://github.com/rust-openvr/rust-openvr" }
|
openvr = { git = "https://github.com/rust-openvr/rust-openvr" }
|
||||||
openvr_sys = "*"
|
openvr_sys = "*"
|
||||||
piston = "*"
|
piston = "*"
|
||||||
piston_window = "*"
|
piston_window = "*"
|
||||||
|
|
||||||
sdl2 = "0.22"
|
|
||||||
sdl2_image = "0.22"
|
|
||||||
|
|||||||
@@ -1,32 +1,26 @@
|
|||||||
|
extern crate image;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate sdl2;
|
|
||||||
extern crate sdl2_image;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use itertools::Itertools;
|
static EGA_PALETTE: [[u8; 4]; 16] = [[0x00, 0x00, 0x00, 0x00],
|
||||||
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, 0x00, 0xAA, 0x00],
|
||||||
|
[0x00, 0xAA, 0x00, 0x00],
|
||||||
[0x00, 0xAA, 0xAA, 0x00],
|
[0x00, 0xAA, 0xAA, 0x00],
|
||||||
[0x00, 0x00, 0x00, 0xAA],
|
[0xAA, 0x00, 0x00, 0x00],
|
||||||
[0x00, 0xAA, 0x00, 0xAA],
|
[0xAA, 0x00, 0xAA, 0x00],
|
||||||
[0x00, 0x00, 0x55, 0xAA],
|
[0xAA, 0x55, 0x00, 0x00],
|
||||||
[0x00, 0xAA, 0xAA, 0xAA],
|
[0xAA, 0xAA, 0xAA, 0x00],
|
||||||
[0x00, 0x55, 0x55, 0x55],
|
[0x55, 0x55, 0x55, 0x00],
|
||||||
[0x00, 0xFF, 0x55, 0x55],
|
[0x55, 0x55, 0xFF, 0x00],
|
||||||
[0x00, 0x55, 0xFF, 0x55],
|
[0x55, 0xFF, 0x55, 0x00],
|
||||||
[0x00, 0xFF, 0xFF, 0x55],
|
[0x55, 0xFF, 0xFF, 0x00],
|
||||||
[0x00, 0x55, 0x55, 0xFF],
|
[0xFF, 0x55, 0x55, 0x00],
|
||||||
[0x00, 0xFF, 0x55, 0xFF],
|
[0xFF, 0x55, 0xFF, 0x00],
|
||||||
[0x00, 0x55, 0xFF, 0xFF],
|
[0xFF, 0xFF, 0x55, 0x00],
|
||||||
[0x00, 0xFF, 0xFF, 0xFF]];
|
[0xFF, 0xFF, 0xFF, 0x00]];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -39,28 +33,24 @@ pub fn main() {
|
|||||||
filename = "data/SHAPES.EGA";
|
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 file = std::fs::File::open(Path::new(filename)).unwrap();
|
||||||
let mut tile_buf = [0u8; 128];
|
let mut tile_buf = [0u8; 128];
|
||||||
let mut surface = Surface::new(16, 16, PixelFormatEnum::RGBX8888).unwrap();
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while file.read_exact(&mut tile_buf).is_ok() {
|
while file.read_exact(&mut tile_buf).is_ok() {
|
||||||
surface.with_lock_mut(|pixel_bytes| {
|
let tilepixels = tile_buf.iter()
|
||||||
pixel_bytes.iter_mut().set_from(tile_buf.iter()
|
.flat_map(|tile_byte| {
|
||||||
.flat_map(|tile_byte| {
|
EGA_PALETTE[(tile_byte >> 4u8 & 0xF) as usize]
|
||||||
EGA_PALETTE[(tile_byte >> 4u8 & 0xF) as usize]
|
.into_iter()
|
||||||
.into_iter()
|
.chain(EGA_PALETTE[(tile_byte & 0xF) as usize]
|
||||||
.chain(EGA_PALETTE[(tile_byte & 0xF) as usize]
|
.into_iter())
|
||||||
.into_iter())
|
})
|
||||||
})
|
.map(|x| *x)
|
||||||
.map(|x| *x));
|
.collect::<Vec<u8>>();
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
let out_name = format!("out/{}.png", i);
|
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;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user