Skip to content

Instantly share code, notes, and snippets.

@DGriffin91
Created February 17, 2023 21:35
Show Gist options
  • Save DGriffin91/fc8e0cfd55aaa175ac10199403bc19b8 to your computer and use it in GitHub Desktop.
Save DGriffin91/fc8e0cfd55aaa175ac10199403bc19b8 to your computer and use it in GitHub Desktop.
AgX-default_contrast.lut.png to vertical exr
// for converting https://github.com/MrLixm/AgXc/blob/main/obs/obs-script/AgX-default_contrast.lut.png
// to a vertical exr
// [dependencies]
// image = "0.24"
// glam = "0.22"
use std::path::Path;
use image::{DynamicImage, GenericImage, GenericImageView, ImageBuffer, Rgb};
extern crate image;
fn main() {
let binding = image::open(Path::new("AgX-default_contrast.lut.png")).unwrap();
let im = binding.as_rgb16().unwrap();
let block_size = im.height();
let mut imgbuf: ImageBuffer<Rgb<f32>, Vec<f32>> =
image::ImageBuffer::new(im.height(), im.width());
// rearrange into vertical blocks
for i in 0..block_size {
let view = DynamicImage::ImageRgb16(
im.view(i * block_size, 0, block_size, block_size)
.to_image(),
);
let mut f32_image = view.clone().into_rgb32f();
for (f32sample, u16sample) in f32_image
.iter_mut()
.zip(view.as_flat_samples_u16().unwrap().samples)
{
// Convert from u16 to f32 and apply cctf decoding
*f32sample = ((*u16sample as f64) / u16::MAX as f64).powf(2.2) as f32;
}
imgbuf.copy_from(&f32_image, 0, i * block_size).unwrap();
}
imgbuf
.save(Path::new("AgX-default_contrast_vert.lut.exr"))
.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment