use std::env;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use tx2_iff::format::IffImage;
use tx2_iff::decoder::{Decoder, DecoderConfig};
fn main() {
pollster::block_on(run());
}
async fn run() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <input.iff>", args[0]);
return;
}
let input_path = Path::new(&args[1]);
let mut file = File::open(input_path).expect("Failed to open input file");
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).expect("Failed to read input file");
println!("Decoding {}...", input_path.display());
let iff_image = IffImage::from_bytes(&buffer).expect("Failed to parse IFF file");
let decoder = Decoder::new(DecoderConfig::default());
let rgb_image = decoder.decode(&iff_image).expect("Failed to decode image");
let width = iff_image.header.width;
let height = iff_image.header.height;
println!("Image decoded: {}x{}", width, height);
let mut rgba_data = Vec::with_capacity((width * height * 4) as usize);
for pixel in rgb_image {
rgba_data.push(pixel[0]);
rgba_data.push(pixel[1]);
rgba_data.push(pixel[2]);
rgba_data.push(255); }
let mut app = tx2_core::App::new().await;
app.renderer.set_image(width, height, &rgba_data);
println!("Starting viewer...");
app.run();
}