blurhash-update/examples/stdin.rs
asonix 0c988ece22
Some checks failed
/ tests (push) Failing after 1m1s
/ clippy (push) Successful in 12s
/ check (aarch64-unknown-linux-musl) (push) Successful in 11s
/ check (armv7-unknown-linux-musleabihf) (push) Successful in 10s
/ check (x86_64-unknown-linux-musl) (push) Successful in 10s
Add pixel skipping, readme & docs
2024-02-22 21:17:29 -06:00

43 lines
900 B
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,
}
// 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 } = Args::parse();
let mut encoder = Encoder::new(Components { x: 4, y: 3 }, ImageBounds { width, height }, 8)?;
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(())
}