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/4b_read_custom_fixed_channels.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/4b_read_custom_fixed_channels.rs')
-rw-r--r-- | vendor/exr/examples/4b_read_custom_fixed_channels.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/exr/examples/4b_read_custom_fixed_channels.rs b/vendor/exr/examples/4b_read_custom_fixed_channels.rs new file mode 100644 index 0000000..a5fd273 --- /dev/null +++ b/vendor/exr/examples/4b_read_custom_fixed_channels.rs @@ -0,0 +1,49 @@ + +// 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 specific channels. +/// This example does not include resolution levels (mipmaps or ripmaps). +fn main() { + use exr::prelude::*; + + let image = read().no_deep_data() + .largest_resolution_level() + + .specific_channels() + .optional("A", f16::ONE) + .required("Y") // TODO also accept a closure with a detailed selection mechanism + .optional("right.Y", 0.0) + .collect_pixels( + |resolution, (a_channel, y_channel, y_right_channel)| { + println!("image contains alpha channel? {}", a_channel.is_some()); + println!("image contains stereoscopic luma channel? {}", y_right_channel.is_some()); + println!("the type of luma samples is {:?}", y_channel.sample_type); + + vec![vec![(f16::ZERO, 0.0, 0.0); resolution.width()]; resolution.height()] + }, + + // 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) + |vec, position, (a,y,yr): (f16, f32, f32)| { + vec[position.y()][position.x()] = (a, y, yr) + } + ) + + .all_layers() + .all_attributes() + .on_progress(|progress| println!("progress: {:.1}", progress*100.0)) + .from_file("custom_channels.exr") + .expect("run example `4_write_custom_fixed_channels` to generate this image file"); + + // output a random color of each channel of each layer + for layer in &image.layer_data { + let (alpha, luma, luma_right) = layer.channel_data.pixels.first().unwrap().first().unwrap(); + + println!( + "top left color of layer `{}`: (a, y, yr) = {:?}", + layer.attributes.layer_name.clone().unwrap_or_default(), + (alpha.to_f32(), luma, luma_right) + ) + } +}
\ No newline at end of file |