Srgb module

srgb_to_linear_fast

procedure · 3 overloadsSource

The fast path uses a piecewise linear interpolant of the exact transfer curve. Sampling in encoded space concentrates linear-domain samples near black. A faster srgb_to_linear for values in [0, 1]: linear interpolation over a 64-segment table of the exact curve, built at compile time, so there is no pow call at run time. The error is below about 0.002 in the linear result. Inputs of 1 or more fall back to the exact curve, and the linear segment below 0.04045 is exact.

ExampleOpen in playground ↗
#import "Math";
x := srgb_to_linear_fast(0.5);
assert(abs(x - srgb_to_linear(0.5)) < 0.002);
srgb_to_linear_fast :: (x: float) -> float

The fast path uses a piecewise linear interpolant of the exact transfer curve. Sampling in encoded space concentrates linear-domain samples near black. A faster srgb_to_linear for values in [0, 1]: linear interpolation over a 64-segment table of the exact curve, built at compile time, so there is no pow call at run time. The error is below about 0.002 in the linear result. Inputs of 1 or more fall back to the exact curve, and the linear segment below 0.04045 is exact.

Parameters

x: float

Returns

float
ExampleOpen in playground ↗
#import "Math";
x := srgb_to_linear_fast(0.5);
assert(abs(x - srgb_to_linear(0.5)) < 0.002);
srgb_to_linear_fast :: (c: Vector3) -> Vector3

The Vector3 form converts the three color channels, each as the scalar form does.

Parameters

Returns

srgb_to_linear_fast :: (c: Vector4) -> Vector4

The Vector4 form converts the red, green and blue channels and leaves alpha (w) untouched.

Parameters

Returns

See also