#[path = "../fixtures/generator.rs"]
mod generator;
#[path = "../fixtures/png_writer.rs"]
mod png_writer;
fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Some(directory) = std::env::args_os().nth(1) {
write_all(std::path::Path::new(&directory))?;
} else {
print_table();
}
Ok(())
}
fn write_all(directory: &std::path::Path) -> Result<(), Box<dyn std::error::Error>> {
std::fs::create_dir_all(directory)?;
for fixture in generator::all() {
let path = directory.join(format!("{}.png", fixture.name));
let output = std::io::BufWriter::new(std::fs::File::create(path)?);
png_writer::write(
output,
fixture.width,
fixture.height,
png::ColorType::Rgba,
&fixture.rgba,
)?;
}
Ok(())
}
fn print_table() {
for fixture in generator::all() {
let transparent = fixture
.rgba
.iter()
.skip(3)
.step_by(4)
.any(|byte| *byte < 255);
println!(
"{} {}x{} alpha={} bytes={}",
fixture.name,
fixture.width,
fixture.height,
transparent,
fixture.rgba.len()
);
}
}