rawshift-image 0.1.0

Still-image decoding, RAW processing, and encoding for rawshift
Documentation
//! Demonstrates the in-memory encode API, codec enumeration and the header
//! probe — all without touching the filesystem.
//!
//! Run with: `cargo run -p rawshift-image --example encode_in_memory`

use rawshift_image::prelude::{
    EncodeOptions, ImageMetadata, RgbImage, available_encoders, encode_rgb_image_to_vec,
    probe_standard_image,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build a small synthetic gradient (16-bit RGB).
    let (width, height) = (64u32, 64u32);
    let mut data = Vec::with_capacity((width * height * 3) as usize);
    for y in 0..height {
        for x in 0..width {
            let r = (x * 65535 / width) as u16;
            let g = (y * 65535 / height) as u16;
            data.extend_from_slice(&[r, g, 32768]);
        }
    }
    let image = RgbImage::new(width, height, data);
    let metadata = ImageMetadata::default();

    println!("Encoders compiled into this build:");
    for codec in available_encoders() {
        println!("  {:<20} v{}", codec.id, codec.version);
    }
    println!();

    // Encode straight to a `Vec<u8>` with each default encoder, then probe the
    // result's header — no file path is ever needed.
    for opts in [
        EncodeOptions::png(),
        EncodeOptions::jpeg(),
        EncodeOptions::webp_lossy(),
    ] {
        let bytes = encode_rgb_image_to_vec(&image, &metadata, &opts)?;
        let probe = probe_standard_image(&bytes)?;
        println!(
            "{:<8} {:>8} bytes  via {:<18}  probe -> {:?} {}x{}",
            opts.format().name(),
            bytes.len(),
            opts.codec_id().to_string(),
            probe.format,
            probe.size.width,
            probe.size.height,
        );
    }

    Ok(())
}