| 1 |
|
| 2 |
// exr imports |
| 3 |
extern crate 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 main() { |
| 10 |
use exr::prelude::*; |
| 11 |
|
| 12 |
let image = read().no_deep_data() |
| 13 |
.largest_resolution_level().all_channels().all_layers().all_attributes() |
| 14 |
.on_progress(|progress| println!("progress: {:.1}", progress*100.0)) |
| 15 |
.from_file("generated_rgba_with_meta.exr") |
| 16 |
.expect("run example `1_write_rgba_with_metadata` to generate this image file"); |
| 17 |
|
| 18 |
println!("image was read: {:#?}", image); |
| 19 |
|
| 20 |
// output the average value for each channel of each layer |
| 21 |
for layer in &image.layer_data { |
| 22 |
for channel in &layer.channel_data.list { |
| 23 |
|
| 24 |
let sample_vec = &channel.sample_data; |
| 25 |
let average = sample_vec.values_as_f32().sum::<f32>() / sample_vec.len() as f32; |
| 26 |
|
| 27 |
if let Some(layer_name) = &layer.attributes.layer_name { |
| 28 |
println!("Channel `{}` of Layer `{}` has an average value of {}", channel.name, layer_name, average); |
| 29 |
} |
| 30 |
else { |
| 31 |
println!("Channel `{}` has an average value of {}", channel.name, average); |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
} |