pbrt_r3/core/imageio/
write_image_exr.rs1use crate::core::base::*;
2use crate::core::error::*;
3use crate::core::geometry::*;
4
5use image::*;
6
7pub fn write_image_exr(
8 name: &str,
9 rgb: &[Float],
10 output_bounds: &Bounds2i,
11 _total_resolution: &Point2i,
12) -> Result<(), PbrtError> {
13 let resolution = output_bounds.diagonal();
14 let mut float_img: Vec<f32> = vec![0.0; (resolution.x * resolution.y * 3) as usize];
15 {
16 let x0: u32 = output_bounds.min.x as u32;
17 let x1: u32 = output_bounds.max.x as u32;
18 let y0: u32 = output_bounds.min.y as u32;
19 let y1: u32 = output_bounds.max.y as u32;
20
21 let width = x1 - x0;
22
23 for y in y0..y1 {
24 let yy = y - y0;
25 for x in x0..x1 {
26 let xx = x - x0;
27 let index: usize = (yy * width + xx) as usize;
28 float_img[3 * index + 0] = rgb[3 * index + 0] as f32;
29 float_img[3 * index + 1] = rgb[3 * index + 1] as f32;
30 float_img[3 * index + 2] = rgb[3 * index + 2] as f32;
31 }
32 }
33 }
34 let img = Rgb32FImage::from_vec(resolution.x as u32, resolution.y as u32, float_img).unwrap();
35 match img.save(name) {
36 Ok(()) => {
37 return Ok(());
38 }
39 Err(e) => {
40 return Err(PbrtError::from(e));
41 }
42 }
43}