Skip to main content

decode_atx/
decode_atx.rs

1//! Decode an ATX file to raw RGBA8 — a thin driver over [`atx_core::decode`] used
2//! by the validation harness (`docs/validation.md`) and for ad-hoc inspection.
3//!
4//! ```text
5//! cargo run --example decode_atx -- <input.atx> <output.rgba>
6//! ```
7//!
8//! On success it writes `width * height * 4` RGBA8 bytes to `<output.rgba>` and
9//! prints `OK <width> <height> <confidence>` to stdout. On failure it prints
10//! `ERR <message>` and exits non-zero (fail-loud — never a silent empty file).
11
12use std::error::Error;
13
14fn main() -> Result<(), Box<dyn Error>> {
15    let mut args = std::env::args().skip(1);
16    let (Some(input), Some(output)) = (args.next(), args.next()) else {
17        eprintln!("usage: decode_atx <input.atx> <output.rgba>");
18        std::process::exit(2);
19    };
20
21    let bytes = std::fs::read(&input)?;
22    match atx_core::decode(&bytes) {
23        Ok(img) => {
24            std::fs::write(&output, &img.rgba)?;
25            println!("OK {} {} {:?}", img.width, img.height, img.confidence);
26            Ok(())
27        }
28        Err(e) => {
29            println!("ERR {e}");
30            std::process::exit(1);
31        }
32    }
33}