#[macro_use]
extern crate smallvec;
extern crate half;
extern crate rand;
use std::{convert::TryInto, fs::File, io::BufWriter};
use exr::block::{writer::ChunksWriter, UncompressedBlock};
extern crate exr;
fn main() {
use attribute::*;
use exr::{math::*, prelude::*};
let random_values: Vec<f32> = (0..64).map(|_| rand::random::<f32>()).collect();
let size = (2048 * 8, 2048 * 8);
let header = exr::meta::header::Header::new(
"test-image".try_into().unwrap(),
size,
smallvec![
attribute::ChannelDescription::new("B", SampleType::F32, true),
attribute::ChannelDescription::new("G", SampleType::F32, true),
attribute::ChannelDescription::new("R", SampleType::F32, true),
attribute::ChannelDescription::new("Z", SampleType::F32, true),
],
);
let mut header = header.with_encoding(
Compression::Uncompressed,
exr::meta::BlockDescription::Tiles(TileDescription {
tile_size: Vec2(64, 64),
level_mode: LevelMode::Singular,
rounding_mode: RoundingMode::Down,
}),
LineOrder::Increasing,
);
header.own_attributes.exposure = Some(1.0);
let headers = smallvec![header];
let file = BufWriter::new(File::create("3GB.exr").unwrap());
let start_time = ::std::time::Instant::now();
exr::block::write(file, headers, true, |meta_data, chunk_writer| {
let blocks = meta_data.collect_ordered_blocks(|block_index| {
let channel_description = &meta_data.headers[block_index.layer].channels;
UncompressedBlock::from_lines(channel_description, block_index, |line_mut| {
let chan = line_mut.location.channel;
if chan == 3 {
line_mut
.write_samples(|_| start_time.elapsed().as_secs_f32())
.expect("write to line bug");
} else {
line_mut
.write_samples(|sample_index| {
random_values[(sample_index + chan) % random_values.len()]
})
.expect("write to line bug");
}
})
});
let mut current_progress_percentage = 0;
chunk_writer
.on_progress(|progress| {
let new_progress = (progress * 100.0) as usize;
if new_progress != current_progress_percentage {
current_progress_percentage = new_progress;
println!("progress: {}%", current_progress_percentage)
}
})
.compress_all_blocks_parallel(&meta_data, blocks)?;
Ok(())
})
.unwrap();
println!("\ncreated file 3GB.exr in {:?}s", start_time.elapsed().as_secs_f32());
}