| 1 | extern crate exrrust-analyzer cargo exr 1.74.0 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 mainrust-analyzer cargo exr 1.74.0 main().() { |
| 8 | let image = exrrust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::read_first_rgba_layer_from_filerust-analyzer cargo exr 1.74.0 image/read/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 = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ default_pixel; resolution.widthrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]width().() ]; |
| 15 | let empty_image = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ empty_line; resolution.heightrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]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[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().position.yrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]y().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().position.xrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]x().()]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = [r, g, b, a] |
| 24 | }, |
| 25 | |
| 26 | ).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]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 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("opened file generated_rgba.exr: {:#?}", image.layer_datarust-analyzer cargo exr 1.74.0 image/Image#layer_data..attributesrust-analyzer cargo exr 1.74.0 image/Layer#attributes.); |
| 30 | } |