| 1 | |
| 2 | extern crate smallvec; |
| 3 | extern crate rand; |
| 4 | extern crate half; |
| 5 | |
| 6 | |
| 7 | // exr imports |
| 8 | extern crate exr; |
| 9 | |
| 10 | /// Writes multiple layers into one exr file |
| 11 | /// Note: this may not be supported by legacy software |
| 12 | fn main() { |
| 13 | use exr::prelude::*; |
| 14 | let size = Vec2(512, 512); |
| 15 | |
| 16 | |
| 17 | let layer1 = Layer::new( |
| 18 | size, |
| 19 | LayerAttributes::named("teal rgb"), |
| 20 | Encoding::FAST_LOSSLESS, |
| 21 | SpecificChannels::rgb(|_pos| (0_f32, 0.4_f32, 0.4_f32)), |
| 22 | ); |
| 23 | |
| 24 | let layer2 = Layer::new( |
| 25 | size, |
| 26 | LayerAttributes::named("orange rgba"), |
| 27 | Encoding::FAST_LOSSLESS, |
| 28 | SpecificChannels::rgba(|_pos| (0.8_f32, 0.5_f32, 0.1_f32, 1.0_f32)), |
| 29 | ); |
| 30 | |
| 31 | // define the visible area of the canvas |
| 32 | let attributes = ImageAttributes::new( |
| 33 | // the pixel section that should be shown |
| 34 | IntegerBounds::from_dimensions(size) |
| 35 | ); |
| 36 | |
| 37 | let image = Image::empty(attributes) |
| 38 | .with_layer(layer1) // add an rgb layer of type `SpecificChannels<ClosureA>` |
| 39 | .with_layer(layer2); // add an rgba layer of different type, `SpecificChannels<ClosureB>`, not possible with a vector |
| 40 | |
| 41 | println!("writing image..."); |
| 42 | image.write().to_file("layers.exr").unwrap(); |
| 43 | |
| 44 | println!("created file layers.exr"); |
| 45 | } |