| 1 | |
| 2 | // exr imports |
| 3 | extern crate exr; |
| 4 | |
| 5 | /// Create an image with strange channels and write it to a file. |
| 6 | fn main() { |
| 7 | use exr::prelude::*; |
| 8 | |
| 9 | let pixels = SpecificChannels::build() |
| 10 | .with_channel("Kharthanasus Korthus") |
| 11 | .with_channel("Y") |
| 12 | .with_channel("11023") |
| 13 | .with_channel("*?!") |
| 14 | .with_channel("`--\"") |
| 15 | .with_channel("\r\r\r\n\n") |
| 16 | .with_pixel_fn(|position|{ |
| 17 | if position.0 < 1000 { |
| 18 | (f16::from_f32(0.2), 0.666_f32, 4_u32, 1532434.0213_f32, 0.99999_f32, 3.142594_f32/4.0) |
| 19 | } |
| 20 | else { |
| 21 | (f16::from_f32(0.4), 0.777_f32, 8_u32, 102154.3_f32, 0.00001_f32, 3.142594_f32/4.0) |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | let image = Image::from_channels((2000, 1400), pixels); |
| 26 | |
| 27 | // print progress only if it advances more than 1% |
| 28 | let mut current_progress_percentage = 0; |
| 29 | |
| 30 | image.write() |
| 31 | .on_progress(|progress| { |
| 32 | let new_progress = (progress * 100.0) as usize; |
| 33 | if new_progress != current_progress_percentage { |
| 34 | current_progress_percentage = new_progress; |
| 35 | println!("progress: {}%", current_progress_percentage) |
| 36 | } |
| 37 | }) |
| 38 | .to_file("custom_channels.exr").unwrap(); |
| 39 | |
| 40 | println!("created file custom_channels.exr"); |
| 41 | } |