| 1 | |
| 2 | extern crate smallvecrust-analyzer cargo exr 1.74.0 smallvec/; |
| 3 | extern crate randrust-analyzer cargo exr 1.74.0 rand/; |
| 4 | extern crate halfrust-analyzer cargo exr 1.74.0 half/; |
| 5 | |
| 6 | |
| 7 | // exr imports |
| 8 | extern crate exrrust-analyzer cargo exr 1.74.0 exr/; |
| 9 | |
| 10 | /// Writes multiple layers into one exr file |
| 11 | /// Note: this may not be supported by legacy software |
| 12 | fn mainrust-analyzer cargo exr 1.74.0 main().() { |
| 13 | use exrrust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::*; |
| 14 | let size = Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#(512, 512); |
| 15 | |
| 16 | |
| 17 | let layer1 = Layerrust-analyzer cargo exr 1.74.0 image/Layer#::newrust-analyzer cargo exr 1.74.0 image/impl#[`Layer<ChannelData>`]new().( |
| 18 | size, |
| 19 | LayerAttributesrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#::namedrust-analyzer cargo exr 1.74.0 meta/header/impl#[LayerAttributes]named().("teal rgb"), |
| 20 | Encodingrust-analyzer cargo exr 1.74.0 image/Encoding#::FAST_LOSSLESSrust-analyzer cargo exr 1.74.0 image/impl#[Encoding]FAST_LOSSLESS., |
| 21 | SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#::rgbrust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannels<SampleStorage, (ChannelDescription, ChannelDescription, ChannelDescription)>`]rgb().(|_pos| (0_f32, 0.4_f32, 0.4_f32)), |
| 22 | ); |
| 23 | |
| 24 | let layer2 = Layerrust-analyzer cargo exr 1.74.0 image/Layer#::newrust-analyzer cargo exr 1.74.0 image/impl#[`Layer<ChannelData>`]new().( |
| 25 | size, |
| 26 | LayerAttributesrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#::namedrust-analyzer cargo exr 1.74.0 meta/header/impl#[LayerAttributes]named().("orange rgba"), |
| 27 | Encodingrust-analyzer cargo exr 1.74.0 image/Encoding#::FAST_LOSSLESSrust-analyzer cargo exr 1.74.0 image/impl#[Encoding]FAST_LOSSLESS., |
| 28 | SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#::rgbarust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannels<SampleStorage, (ChannelDescription, ChannelDescription, ChannelDescription, ChannelDescription)>`]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 = ImageAttributesrust-analyzer cargo exr 1.74.0 meta/header/ImageAttributes#::newrust-analyzer cargo exr 1.74.0 meta/header/impl#[ImageAttributes]new().( |
| 33 | // the pixel section that should be shown |
| 34 | IntegerBoundsrust-analyzer cargo exr 1.74.0 meta/attribute/IntegerBounds#::from_dimensionsrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[IntegerBounds]from_dimensions().(size) |
| 35 | ); |
| 36 | |
| 37 | let image = Imagerust-analyzer cargo exr 1.74.0 image/Image#::emptyrust-analyzer cargo exr 1.74.0 image/impl#[`Image<NoneMore>`]empty().(attributes) |
| 38 | .with_layerrust-analyzer cargo exr 1.74.0 image/impl#[`Image<InnerLayers>`]with_layer().(layer1) // add an rgb layer of type `SpecificChannels<ClosureA>` |
| 39 | .with_layerrust-analyzer cargo exr 1.74.0 image/impl#[`Image<InnerLayers>`]with_layer().(layer2); // add an rgba layer of different type, `SpecificChannels<ClosureB>`, not possible with a vector |
| 40 | |
| 41 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("writing image..."); |
| 42 | image.writerust-analyzer cargo exr 1.74.0 image/write/impl#[`&'img Image<WritableLayers>`][`WritableImage<'img, WritableLayers>`]write().().to_filerust-analyzer cargo exr 1.74.0 image/write/impl#[`WriteImageWithOptions<'img, L, F>`]to_file().("layers.exr").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 43 | |
| 44 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("created file layers.exr"); |
| 45 | } |