1 unstable release

0.4.0 Nov 12, 2023

#500 in Images

Download history 32/week @ 2023-11-11 65/week @ 2023-11-18 26/week @ 2023-11-25 43/week @ 2023-12-02 52/week @ 2023-12-09 34/week @ 2023-12-16 16/week @ 2023-12-23 12/week @ 2023-12-30 29/week @ 2024-01-06 34/week @ 2024-01-13 12/week @ 2024-01-20 31/week @ 2024-01-27 57/week @ 2024-02-03 117/week @ 2024-02-10

223 downloads per month
Used in 2 crates

MIT OR Apache-2.0 OR Zlib

115KB
2K SLoC

zune-hdr

A fast,small versatile hdr decoder and encoder

This crate contains a small and fast Radiance (.hdr) decoder and encoder.

Usage

To use this crate, add zune-hdr to your Cargo.toml or run cargo add zune-hdr

Here is an example of loading a hdr image

use std::error::Error;
use std::fs::read;
use zune_hdr::HdrDeocder;

fn main() -> Result<(), Box<dyn Error>> {
    let contents = read("file.hdr")?;
    let data = HdrDecoder::new(contents);
    let pix: Vec<f32> = data.decode()?;
    println!("first pix:{}", pix[0]);
}

Here is an example of writing a hdr, this generates a black image

use zune_hdr::HdrEncoder;
use zune_core::options::EncoderOptions;

fn main() -> Result<(), Box<dyn Error>> {
    let w = 100;
    let h = 100;
    let comp = 3;

    let in_size: Vec<f32> = vec![0.0; w * h * comp];
    // setup options, we specify width and height here which are needed, colorspace must always 
    // be rgb and the depth is f32, 
    let encoder_opts = EncoderOptions::new(w, h, ColorSpace::RGB, BitDepth::Float32);

    let encoder = HdrEncoder::new(&in_size, encoder_opts);
    encoder.encode()?;
}

Performance

The crate boasts an optimized decoder, with it being about 2.5x faster than image-rs/hdr decoder, the following is a benchmark run on the following image

This can be replicated with

git clone
cd ./zune-image 
cargo bench --workspace "hdr"

Formatted output

field image-rs/hdr zune-hdr
time 16.561 ms 6.4180 ms
thrpt 77.363 MiB/s 199.63 MiB/s

Raw criterion output

Running benches/decode_hdr.rs (deps/decode_hdr-b0d728bd626a2ee2)
hdr: Simple decode(memorial-hdr)/image-rs/hdr
time:   [16.542 ms 16.561 ms 16.581 ms]
thrpt:  [77.271 MiB/s 77.363 MiB/s 77.454 MiB/s]

hdr: Simple decode(memorial-hdr)/zune-image/hdr
time:   [6.3522 ms 6.4180 ms 6.4848 ms]
thrpt:  [197.58 MiB/s 199.63 MiB/s 201.70 MiB/s]

Security

The crate has been extensively fuzzed, additionaly the CI does fuzz testing every day to catch unintended bugs

The crate does not use unsafe and uses #[forbid(unsafe)] to prevent any from creeping in

Dependencies