Debian Codegraph @

examples/0a_write_rgba.rs

raw symbols SCIP
1 extern crate exrrust-analyzer cargo exr 1.74.0 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 mainrust-analyzer cargo exr 1.74.0 main().() {
10 use exrrust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::*;
11
12 // write a file, with 32-bit float precision per channel
13 write_rgba_filerust-analyzer cargo exr 1.74.0 image/write/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 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().2048.0, // red
27 y as f32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().2048.0, // green
28 1.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().(y as f32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().2048.0), // blue
29 1.0 // alpha
30 )
31 }
32
33 ).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
34
35 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("created file minimal_rgb.exr");
36 }