Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamma correction #111

Open
osman-turan opened this issue Oct 3, 2021 · 2 comments
Open

Gamma correction #111

osman-turan opened this issue Oct 3, 2021 · 2 comments

Comments

@osman-turan
Copy link
Contributor

At planned features, the gamma correction is listed. At the same time, the codebase has a commented-out piece of code for gamma correction. See:

/// Apply gamma correction.
// #[wasm_bindgen]
// pub fn gamma_correction(mut photon_image: &mut PhotonImage, red: f32, green: f32, blue: f32) {
// let img = helpers::dyn_image_from_raw(photon_image);
// let (width, height) = img.dimensions();
// let mut img = img.to_rgba8();
// // Initialize gamma arrays
// let mut gammaR: Vec<u8> = vec![];
// let mut gammaG: Vec<u8> = vec![];
// let mut gammaB: Vec<u8> = vec![];
// let MAX_VALUE_INT = 255;
// let MAX_VALUE_FLT = 255.0;
// let REVERSE = 1.0;
// // Set values within gamma arrays
// for i in 0..256 {
// gammaR[i] = min(MAX_VALUE_INT, ((MAX_VALUE_FLT * ((i as f32 / MAX_VALUE_FLT) as u32).powf(REVERSE / red) + 0.5 ) as u8));
// gammaG[i] = min(MAX_VALUE_INT, ((MAX_VALUE_FLT * ((i as f32 / MAX_VALUE_FLT) as u32).powf(REVERSE / green) + 0.5 ) as u8);
// gammaB[i] = min(MAX_VALUE_INT, ((MAX_VALUE_FLT * ((i as f32 / MAX_VALUE_FLT) as u32).powf(REVERSE / blue) + 0.5 ) as u8);
// }
// for x in 0..width {
// for y in 0..height {
// let px_data = img.get_pixel(x, y).data;
// let r_val = px_data[0];
// let g_val = px_data[1];
// let b_val = px_data[2];
// px_data[0] = gammaR[r_val as usize];
// px_data[1] = gammaG[g_val as usize];
// px_data[2] = gammaB[b_val as usize];
// img.put_pixel(x, y, px);
// }
// }
// photon_image.raw_pixels = img.to_vec();
// }

I haven't checked the correctness of the commented-out function. Why is it commented-out? What's the expectation and plan for the gamma correction? I can work on this feature if you like.

@silvia-odwyer
Copy link
Owner

silvia-odwyer commented Oct 4, 2021

@osman-turan Hi Osman,
Thanks for opening this issue and for your interest in working on a gamma correction function!

The current gamma correction code uses features in the image library that are now deprecated, namely accessing the data field of each pixel, hence why the code is commented out. As for the correctness of the algorithm, I haven't been able to test it due to the deprecated code, so it might be better to start a new function and work on the implementation there.

But that said, if you'd like to work on your own function or make use of the logic in this, it's completely up to you! 😄 Thanks again for the help, it's greatly appreciated!

osman-turan added a commit to osman-turan/photon that referenced this issue Oct 4, 2021
@osman-turan
Copy link
Contributor Author

Thanks for the details! Due to rounding, there might be some edge cases at my implementation. If you encounter such inputs, please let me know so that I can work on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants