Skip to content

Instantly share code, notes, and snippets.

@DGriffin91
Created February 17, 2023 21:57
Show Gist options
  • Save DGriffin91/e119bf32b520e219f6e102a6eba4a0cf to your computer and use it in GitHub Desktop.
Save DGriffin91/e119bf32b520e219f6e102a6eba4a0cf to your computer and use it in GitHub Desktop.
Generate log2 LUT stimulus vertical strip
// Generate log2 LUT stimulus
// [dependencies]
// image = "0.24"
// glam = "0.22"
use glam::{vec3, Vec3};
use image::{ImageBuffer, Rgb};
extern crate image;
fn convert_normalized_log2_to_open_domain(color: Vec3, minimum_ev: f32, maximum_ev: f32) -> Vec3 {
let mut color = color;
let in_midgrey = 0.18;
let total_exposure = maximum_ev - minimum_ev;
color = (color * total_exposure) + minimum_ev;
color = vec3(
(2.0_f32).powf(color.x),
(2.0_f32).powf(color.y),
(2.0_f32).powf(color.z),
);
color = color * in_midgrey;
return color;
}
fn generate(block_size: u32, minimum_ev: f32, maximum_ev: f32) -> ImageBuffer<Rgb<f32>, Vec<f32>> {
let imgx = block_size;
let imgy = block_size * block_size;
let m = 1.0 / (imgx as f32);
// Create a new ImgBuf with width: imgx and height: imgy
let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
// Iterate over the coordinates and pixels of the image
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
let r = x as f32;
let g = (y % block_size) as f32;
let b = (y / block_size) as f32;
let c = convert_normalized_log2_to_open_domain(
vec3(r * m, g * m, b * m),
minimum_ev,
maximum_ev,
);
*pixel = image::Rgb([c.x, c.y, c.z]);
}
imgbuf
}
fn main() {
generate(64, -11.0, 12.0)
.save("empty_exp_lut_vert.exr")
.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment