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

fast and aprox srgb to linear space #410

Open
lassade opened this issue Sep 22, 2023 · 3 comments
Open

fast and aprox srgb to linear space #410

lassade opened this issue Sep 22, 2023 · 3 comments

Comments

@lassade
Copy link

lassade commented Sep 22, 2023

Hi,

I come up with a function that aproximates the gamma conversion is has a RMSE of 0.001064 which is better than the simple x^2 aproach here is the math: https://www.desmos.com/calculator/rbjqw6re8i

pub inline fn linearAprox(val: F32x4) F32x4 {
    var a = val * val;
    var b = a * @sqrt(val);
    b = f32x4s(0.567) * a + f32x4s(1 - 0.567) * b;
    return @shuffle(f32, b, val, [4]i32{ 0, 1, 2, ~@as(i32, 3) });
}
@michal-z
Copy link
Collaborator

Interesting. Please make a PR with some tests.

@mochalins
Copy link
Contributor

I'm getting results that don't quite seem consistent with a RMSE of 0.001064, although that may be because I've happened to pick particularly large error test cases. PR/tests in #459, wasn't sure where to put it (would be an equivalent to function provided in stb_image), so just stuck it in zmath for now.

@lassade
Copy link
Author

lassade commented Jan 10, 2024

I would guess that the RMSE of 0.001064 is error smaller than the actual error because desmos uses a 64-bit float

You can change the 0.567 constant to see if the error improves using 32-bit float

this algorithm is quite silly, I don't think is worth using ...

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

3 participants