Crates.io | zune-hdr |
lib.rs | zune-hdr |
version | 0.5.0-rc0 |
source | src |
created_at | 2023-11-12 21:23:12.97546 |
updated_at | 2024-04-07 16:05:15.78976 |
description | Radiance/HDR image decoder and encoder |
homepage | https://github.com/etemesi254/zune-image/tree/dev/crates/zune-hdr |
repository | |
max_upload_size | |
id | 1033045 |
size | 37,332 |
A fast,small versatile hdr decoder and encoder
This crate contains a small and fast Radiance (.hdr) decoder and encoder.
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()?;
}
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"
field | image-rs/hdr | zune-hdr |
---|---|---|
time | 16.561 ms | 6.4180 ms |
thrpt | 77.363 MiB/s | 199.63 MiB/s |
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]
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