From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- .../examples/3b_read_all_channels_with_metadata.rs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 vendor/exr/examples/3b_read_all_channels_with_metadata.rs (limited to 'vendor/exr/examples/3b_read_all_channels_with_metadata.rs') diff --git a/vendor/exr/examples/3b_read_all_channels_with_metadata.rs b/vendor/exr/examples/3b_read_all_channels_with_metadata.rs new file mode 100644 index 0000000..cd9fc04 --- /dev/null +++ b/vendor/exr/examples/3b_read_all_channels_with_metadata.rs @@ -0,0 +1,35 @@ + +// exr imports +extern crate exr; + +/// Read an image and print information about the image into the console. +/// This example shows how to read an image with multiple layers and arbitrary channels. +/// For example, a layer with XYZ channels, and additionally a separate Depth layer. +/// This example does not include resolution levels (mipmaps or ripmaps). +fn main() { + use exr::prelude::*; + + let image = read().no_deep_data() + .largest_resolution_level().all_channels().all_layers().all_attributes() + .on_progress(|progress| println!("progress: {:.1}", progress*100.0)) + .from_file("generated_rgba_with_meta.exr") + .expect("run example `1_write_rgba_with_metadata` to generate this image file"); + + println!("image was read: {:#?}", image); + + // output the average value for each channel of each layer + for layer in &image.layer_data { + for channel in &layer.channel_data.list { + + let sample_vec = &channel.sample_data; + let average = sample_vec.values_as_f32().sum::() / sample_vec.len() as f32; + + if let Some(layer_name) = &layer.attributes.layer_name { + println!("Channel `{}` of Layer `{}` has an average value of {}", channel.name, layer_name, average); + } + else { + println!("Channel `{}` has an average value of {}", channel.name, average); + } + } + } +} \ No newline at end of file -- cgit v1.2.3