#[macro_use]
extern crate smallvec;
extern crate rand;
extern crate half;
use std::convert::TryInto;
use std::io::BufWriter;
use std::fs::File;
extern crate exr;
use exr::prelude::common::*;
use attribute::*;
use exr::meta::*;
use exr::math::*;
fn main() {
let random_values: Vec<f32> = (0..64)
.map(|_| rand::random::<f32>())
.collect();
let size = (2048*8, 2048*8);
let file = BufWriter::new(File::create("tests/images/out/3GB.exr").unwrap());
let header = exr::meta::header::Header::new(
"test-image".try_into().unwrap(),
size,
smallvec![
ChannelInfo::new("B".try_into().unwrap(), SampleType::F32, true),
ChannelInfo::new("G".try_into().unwrap(), SampleType::F32, true),
ChannelInfo::new("R".try_into().unwrap(), SampleType::F32, true),
ChannelInfo::new("Z".try_into().unwrap(), SampleType::F32, true),
],
);
let mut header = header.with_encoding(
Compression::Uncompressed,
Blocks::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 mut count_to_1000_and_then_print = 0;
let start_time = ::std::time::Instant::now();
exr::block::lines::write_all_lines_to_buffered(
file,
headers,
|_meta, 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");
}
},
WriteOptions {
parallel_compression: false,
pedantic: true,
on_progress: |progress, bytes| {
count_to_1000_and_then_print += 1;
if count_to_1000_and_then_print == 1000 {
count_to_1000_and_then_print = 0;
let mega_bytes = bytes / 1000000;
let percent = (progress * 100.0) as usize;
println!("progress: {}%, wrote {} megabytes", percent, mega_bytes);
}
Ok(())
},
}
).unwrap();
println!("\ncreated file 3GB.exr in {:?}s", start_time.elapsed().as_secs_f32());
}