diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/exr/examples/3b_read_all_channels_with_metadata.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/exr/examples/3b_read_all_channels_with_metadata.rs')
-rw-r--r-- | vendor/exr/examples/3b_read_all_channels_with_metadata.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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::<f32>() / 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 |