A faster srgb_to_linear for values in [0, 1], using a lookup table instead of pow. Off by less than 0.002.
#import "Math";
assert(abs(srgb_to_linear_fast(0.5) - srgb_to_linear(0.5)) < 0.002);srgb_to_linear_fast :: (x: float) -> float
Parameters
- x: float
Returns
- float
srgb_to_linear_fast :: (c: Vector3) -> Vector3
Converts the red, green and blue channels of c.
Parameters
- c: Vector3
Returns
#import "Math";
linear := srgb_to_linear_fast(xyz(0.5, 0, 1));
assert(abs(linear.x - 0.214) < 0.002);srgb_to_linear_fast :: (c: Vector4) -> Vector4
Converts the red, green and blue channels of c and leaves alpha as it is.
Parameters
- c: Vector4
Returns
#import "Math";
linear := srgb_to_linear_fast(xyzw(0.5, 0, 1, 0.3));
assert(abs(linear.x - 0.214) < 0.002 && linear.w == 0.3);