1 个不稳定发布
| 0.1.0 | 2024年2月26日 | 
|---|
#851 in 图像
每月79次下载
在 pict-rs 中使用
1MB
704 行
blurhash-update
用于流式传输字节的blurhash编码器
支持
- 编码
- 解码
动机
已经存在一个blurhash crate,它是一个创建blurhash的好选择,但是它要求所有给定图像的像素都必须存在于内存中才能计算它。对于非常大的图像,这可能不是理想的选择。
blurhash-update提供了一个API来处理图像的字节,当它们可用时。在类似比较中,这并不像blurhash那样高效,但较低的内存开销在某些场景中可能很有用。
blurhash-update还提供了一种通过跳过处理一些输入像素来降低精度的能力。这大大提高了性能,但可能会导致blurhash看起来不太对劲。使用blurhash-update的auto编码器配置将针对基于图像尺寸的极端高效但非常宽松的配置文件。
使用
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,
}
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 }, 1)?;
    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(())
}
示例使用
magick convert /path/to/image RGBA:- | \
    cargo r --example --release -- --width blah --height blah
许可
blurhash-update许可为以下之一