Function encodeSrgbBatch
Encodes a batch with the exact scalar sRGB transfer semantics.
bool encodeSrgbBatch(T)(
scope const LinearSRgb!T[] input,
scope SRgb!T[] output
) pure nothrow @nogc @safe
if (is(T == float) || is(T == double));
Returns false without writing when the input and output lengths differ.
The operation performs no allocation, clipping, gamut mapping, or implicit
quantization.
Example
const table = makeSRgb8Decoder!double();
assert(table[0] == 0.0);
assert(table[255] == 1.0);
assert(
table[128] > 0.21586050011389926 - 1e-15 &&
table[128] < 0.21586050011389926 + 1e-15
);
Example
const SRgbd[2] encoded =
[
SRgbd(0.0, 0.5, 1.0),
SRgbd(-0.25, 0.25, 1.25)
];
LinearSRgbd[2] linear;
SRgbd[2] roundTrip;
assert(decodeSrgbBatch(encoded[], linear[]));
assert(linear[0] == encoded[0] .toLinear);
assert(linear[1] == encoded[1] .toLinear);
assert(encodeSrgbBatch(linear[], roundTrip[]));
assert(
roundTrip[0] .r > encoded[0] .r - 1e-12 &&
roundTrip[0] .r < encoded[0] .r + 1e-12 &&
roundTrip[0] .g > encoded[0] .g - 1e-12 &&
roundTrip[0] .g < encoded[0] .g + 1e-12 &&
roundTrip[0] .b > encoded[0] .b - 1e-12 &&
roundTrip[0] .b < encoded[0] .b + 1e-12
);
assert(
roundTrip[1] .r > encoded[1] .r - 1e-12 &&
roundTrip[1] .r < encoded[1] .r + 1e-12
);
LinearSRgbd[1] tooShortLinear;
SRgbd[1] tooShortEncoded;
assert(!decodeSrgbBatch(encoded[], tooShortLinear[]));
assert(!encodeSrgbBatch(linear[], tooShortEncoded[]));