Debian Codegraph @

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

raw
1 extern crate exr;
2
3
4 /// `exr` offers a few simplified functions for the most basic use cases.
5 /// `write_rgb_f32_file` is a such a function, which writes a plain rgba exr file.
6 ///
7 /// To write your image data, you need to specify how to retrieve a single pixel from it.
8 /// The closure may capture variables or generate data on the fly.
9 fn main() {
10 use exr::prelude::*;
11
12 // write a file, with 32-bit float precision per channel
13 write_rgba_file(
14
15 // this accepts paths or &str
16 "minimal_rgba.exr",
17
18 // image resolution is 2k
19 2048, 2048,
20
21 // generate (or lookup in your own image)
22 // an f32 rgb color for each of the 2048x2048 pixels
23 // (you could also create f16 values here to save disk space)
24 |x,y| {
25 (
26 x as f32 / 2048.0, // red
27 y as f32 / 2048.0, // green
28 1.0 - (y as f32 / 2048.0), // blue
29 1.0 // alpha
30 )
31 }
32
33 ).unwrap();
34
35 println!("created file minimal_rgb.exr");
36 }