A faster linear_to_srgb for values in [0, 1], using a lookup table instead of pow. Off by less than 0.003.
#import "Math";
assert(abs(linear_to_srgb_fast(0.5) - linear_to_srgb(0.5)) < 0.003);linear_to_srgb_fast :: (x: float) -> float
Parameters
- x: float
Returns
- float
linear_to_srgb_fast :: (c: Vector3) -> Vector3
Converts the red, green and blue channels of c.
Parameters
- c: Vector3
Returns
#import "Math";
encoded := linear_to_srgb_fast(xyz(0.214, 0, 1));
assert(abs(encoded.x - 0.5) < 0.003);linear_to_srgb_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";
encoded := linear_to_srgb_fast(xyzw(0.214, 0, 1, 0.3));
assert(abs(encoded.x - 0.5) < 0.003 && encoded.w == 0.3);