blurhash-update/examples/stdin.rs
asonix 1f7957778f
All checks were successful
/ clippy (push) Successful in 9s
/ tests (push) Successful in 48s
/ check (aarch64-unknown-linux-musl) (push) Successful in 6s
/ check (armv7-unknown-linux-musleabihf) (push) Successful in 7s
/ check (x86_64-unknown-linux-musl) (push) Successful in 6s
Bench and test auto
2024-02-22 22:38:53 -06:00

54 lines
1 KiB
Rust

use std::io::Read;
use blurhash_update::{Components, Encoder, ImageBounds};
use clap::Parser;
#[derive(clap::Parser)]
struct Args {
/// Width of the provided image
#[clap(long)]
width: u32,
/// Height of the provided image
#[clap(long)]
height: u32,
#[clap(long, default_value = "8")]
skip: u32,
}
// Example usage:
// ```bash
// magick convert /path/to/image RGBA:- | \
// cargo r --example --release -- --width blah --height blah
// ```
fn main() -> Result<(), Box<dyn std::error::Error>> {
let Args {
width,
height,
skip,
} = Args::parse();
let mut encoder = Encoder::new(
Components { x: 4, y: 3 },
ImageBounds { width, height },
skip,
)?;
let mut stdin = std::io::stdin().lock();
let mut buf = [0u8; 1024];
loop {
let n = stdin.read(&mut buf)?;
if n == 0 {
break;
}
encoder.update(&buf[..n]);
}
println!("{}", encoder.finalize());
Ok(())
}