use std::error::Error;
use heif::{BitDepth, EncoderConfig, HeifEncoder};
const SOURCE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/image.jpg");
fn main() -> Result<(), Box<dyn Error>> {
let img = image::open(SOURCE)?;
let config = EncoderConfig {
bit_depth: BitDepth::Ten,
..Default::default()
};
let mut bytes = Vec::new();
match img.write_with_encoder(HeifEncoder::new_with_config(&mut bytes, config)) {
Ok(()) => {
let info = heif::probe(&bytes)?;
println!("encoded {} bytes at {:?}", bytes.len(), info.bit_depth);
let out = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/high-bit-depth-example.heic");
std::fs::write(out, &bytes)?;
println!("saved -> {}", out);
}
Err(e) => {
println!("10-bit encode not supported by the bundled x265 binary: {e}");
}
}
Ok(())
}