Debian Codegraph @

.cargo/vendor/exr/examples/0c_read_rgba.rs

raw
1 extern crate exr;
2
3 /// `exr` offers a few simplified functions for the most basic use cases.
4 /// `read_first_rgba_layer_from_file` is a such a function, which loads rgba exr files.
5 /// To load the pixel data, you need to specify
6 /// how to create and how to set the pixels of your image.
7 fn main() {
8 let image = exr::prelude::read_first_rgba_layer_from_file(
9 "generated_rgba.exr",
10
11 // instantiate your image type with the size of the image in file
12 |resolution, _| {
13 let default_pixel = [0.0, 0.0, 0.0, 0.0];
14 let empty_line = vec![ default_pixel; resolution.width() ];
15 let empty_image = vec![ empty_line; resolution.height() ];
16 empty_image
17 },
18
19 // transfer the colors from the file to your image type,
20 // requesting all values to be converted to f32 numbers (you can also directly use f16 instead)
21 // and you could also use `Sample` instead of `f32` to keep the original data type from the file
22 |pixel_vector, position, (r,g,b, a): (f32, f32, f32, f32)| {
23 pixel_vector[position.y()][position.x()] = [r, g, b, a]
24 },
25
26 ).expect("run the `1_write_rgba` example to generate the required file");
27
28 // printing all pixels might kill the console, so only print some meta data about the image
29 println!("opened file generated_rgba.exr: {:#?}", image.layer_data.attributes);
30 }