| 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 specific channels. |
| 7 |
/// This example does not include resolution levels (mipmaps or ripmaps). |
| 8 |
fn main() { |
| 9 |
use exr::prelude::*; |
| 10 |
|
| 11 |
let image = read().no_deep_data() |
| 12 |
.largest_resolution_level() |
| 13 |
|
| 14 |
.specific_channels() |
| 15 |
.optional("A", f16::ONE) |
| 16 |
.required("Y") // TODO also accept a closure with a detailed selection mechanism |
| 17 |
.optional("right.Y", 0.0) |
| 18 |
.collect_pixels( |
| 19 |
|resolution, (a_channel, y_channel, y_right_channel)| { |
| 20 |
println!("image contains alpha channel? {}", a_channel.is_some()); |
| 21 |
println!("image contains stereoscopic luma channel? {}", y_right_channel.is_some()); |
| 22 |
println!("the type of luma samples is {:?}", y_channel.sample_type); |
| 23 |
|
| 24 |
vec![vec![(f16::ZERO, 0.0, 0.0); resolution.width()]; resolution.height()] |
| 25 |
}, |
| 26 |
|
| 27 |
// all samples will be converted to f32 (you can also use the enum `Sample` instead of `f32` here to retain the original data type from the file) |
| 28 |
|vec, position, (a,y,yr): (f16, f32, f32)| { |
| 29 |
vec[position.y()][position.x()] = (a, y, yr) |
| 30 |
} |
| 31 |
) |
| 32 |
|
| 33 |
.all_layers() |
| 34 |
.all_attributes() |
| 35 |
.on_progress(|progress| println!("progress: {:.1}", progress*100.0)) |
| 36 |
.from_file("custom_channels.exr") |
| 37 |
.expect("run example `4_write_custom_fixed_channels` to generate this image file"); |
| 38 |
|
| 39 |
// output a random color of each channel of each layer |
| 40 |
for layer in &image.layer_data { |
| 41 |
let (alpha, luma, luma_right) = layer.channel_data.pixels.first().unwrap().first().unwrap(); |
| 42 |
|
| 43 |
println!( |
| 44 |
"top left color of layer `{}`: (a, y, yr) = {:?}", |
| 45 |
layer.attributes.layer_name.clone().unwrap_or_default(), |
| 46 |
(alpha.to_f32(), luma, luma_right) |
| 47 |
) |
| 48 |
} |
| 49 |
} |