tx2-iff 0.1.0

PPF-IFF (Involuted Fractal Format) - Image codec using Physics-Prime Factorization, 360-prime quantization, and symplectic warping
Documentation
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() {
    // env_logger::init(); // Initialized in App::new()

    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]);

    // Read file
    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");

    // Decode
    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);

    // Convert RGB to RGBA
    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); // Alpha
    }

    // Initialize App
    let mut app = tx2_core::App::new().await;
    
    // Set image
    app.renderer.set_image(width, height, &rgba_data);

    println!("Starting viewer...");
    app.run();
}