| 1 | |
| 2 | // exr imports |
| 3 | extern crate exrrust-analyzer cargo exr 1.74.0 exr/; |
| 4 | |
| 5 | /// Read an image and print information about the image into the console. |
| 6 | /// This example shows how to read an image with multiple layers and arbitrary channels. |
| 7 | /// For example, a layer with XYZ channels, and additionally a separate Depth layer. |
| 8 | /// This example does not include resolution levels (mipmaps or ripmaps). |
| 9 | fn mainrust-analyzer cargo exr 1.74.0 main().() { |
| 10 | use exrrust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::*; |
| 11 | |
| 12 | let image = readrust-analyzer cargo exr 1.74.0 image/read/read().().no_deep_datarust-analyzer cargo exr 1.74.0 image/read/impl#[ReadBuilder]no_deep_data().() |
| 13 | .largest_resolution_levelrust-analyzer cargo exr 1.74.0 image/read/samples/impl#[ReadFlatSamples]largest_resolution_level().().all_channelsrust-analyzer cargo exr 1.74.0 image/read/levels/impl#[`ReadLargestLevel<DeepOrFlatSamples>`]all_channels().().all_layersrust-analyzer cargo exr 1.74.0 image/read/layers/ReadChannels#all_layers().().all_attributesrust-analyzer cargo exr 1.74.0 image/read/image/ReadLayers#all_attributes().() |
| 14 | .on_progressrust-analyzer cargo exr 1.74.0 image/read/image/impl#[`ReadImage<F, L>`]on_progress().(|progress| printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("progress: {:.1}", progress*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().100.0)) |
| 15 | .from_filerust-analyzer cargo exr 1.74.0 image/read/image/impl#[`ReadImage<F, L>`]from_file().("generated_rgba_with_meta.exr") |
| 16 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("run example `1_write_rgba_with_metadata` to generate this image file"); |
| 17 | |
| 18 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("image was read: {:#?}", image); |
| 19 | |
| 20 | // output the average value for each channel of each layer |
| 21 | for layer in &image.layer_datarust-analyzer cargo exr 1.74.0 image/Image#layer_data. { |
| 22 | for channel in &layer.channel_datarust-analyzer cargo exr 1.74.0 image/Layer#channel_data..listrust-analyzer cargo exr 1.74.0 image/AnyChannels#list. { |
| 23 | |
| 24 | let sample_vec = &channel.sample_datarust-analyzer cargo exr 1.74.0 image/AnyChannel#sample_data.; |
| 25 | let average = sample_vec.values_as_f32rust-analyzer cargo exr 1.74.0 image/impl#[FlatSamples]values_as_f32().().sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().::<f32>() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().sample_vec.lenrust-analyzer cargo exr 1.74.0 image/impl#[FlatSamples]len().() as f32; |
| 26 | |
| 27 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(layer_name) = &layer.attributesrust-analyzer cargo exr 1.74.0 image/Layer#attributes..layer_namerust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#layer_name. { |
| 28 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Channel `{}` of Layer `{}` has an average value of {}", channel.namerust-analyzer cargo exr 1.74.0 image/AnyChannel#name., layer_name, average); |
| 29 | } |
| 30 | else { |
| 31 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Channel `{}` has an average value of {}", channel.namerust-analyzer cargo exr 1.74.0 image/AnyChannel#name., average); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |