Srgb module

srgb_to_linear

procedure3 overloadsSource

Converts an sRGB-encoded value in [0, 1] to linear light, using the exact sRGB curve. Values outside [0, 1] are not clamped.

Example↗
#import "Math";
assert(abs(srgb_to_linear(0.5) - 0.21404114) < 0.00001);
assert(srgb_to_linear(0.0) == 0);
srgb_to_linear :: (x: float) -> float

Parameters

x: float

Returns

float
srgb_to_linear :: (c: Vector3) -> Vector3

Converts the red, green and blue channels of c.

Parameters

Returns

Example↗
#import "Math";
linear := srgb_to_linear(xyz(0.5, 0, 1));
assert(abs(linear.x - 0.214) < 0.001 && linear.y == 0);
srgb_to_linear :: (c: Vector4) -> Vector4

Converts the red, green and blue channels of c and leaves alpha as it is.

Parameters

Returns

Example↗
#import "Math";
linear := srgb_to_linear(xyzw(0.5, 0, 1, 0.3));
assert(abs(linear.x - 0.214) < 0.001 && linear.w == 0.3);

See also