mirror of
https://github.com/typst/typst
synced 2025-05-16 01:55:28 +08:00
79 lines
1.9 KiB
PostScript
79 lines
1.9 KiB
PostScript
{
|
|
% Starting stack: L, A, B
|
|
% /!\ WARNING: The A and B components **MUST** be encoded
|
|
% in the range [0, 1] before calling this function.
|
|
% This is because the function assumes that the
|
|
% A and B components are offset by a factor of 0.5
|
|
% in order to meet the range requirements of the
|
|
% PDF specification.
|
|
|
|
exch 0.5 sub
|
|
exch 0.5 sub
|
|
|
|
% Load L a and b into the stack
|
|
2 index
|
|
2 index
|
|
2 index
|
|
|
|
% Compute f1 = ((0.3963377774 * a) + (0.2158037573 * b) + L)^3
|
|
0.2158037573 mul exch
|
|
0.3963377774 mul add add
|
|
dup dup mul mul
|
|
|
|
% Load L, a, and b into the stack
|
|
3 index
|
|
3 index
|
|
3 index
|
|
|
|
% Compute f2 = ((-0.1055613458 * a) + (-0.0638541728 * b) + L)^3
|
|
-0.0638541728 mul exch
|
|
-0.1055613458 mul add add
|
|
dup dup mul mul
|
|
|
|
% Load L, a, and b into the stack
|
|
4 index
|
|
4 index
|
|
4 index
|
|
|
|
% Compute f3 = ((-0.0894841775 * a) + (-1.2914855480 * b) + L)^3
|
|
-1.2914855480 mul exch
|
|
-0.0894841775 mul add add
|
|
dup dup mul mul
|
|
|
|
% Discard L, a, and b by rolling the stack and popping
|
|
6 3 roll pop pop pop
|
|
|
|
% Load f1, f2, and f3 into the stack
|
|
2 index
|
|
2 index
|
|
2 index
|
|
|
|
% Compute R = f1 * 4.0767416621 + f2 * -3.3077115913 + f3 * 0.2309699292
|
|
0.2309699292 mul exch
|
|
-3.3077115913 mul add exch
|
|
4.0767416621 mul add
|
|
|
|
% Load f1, f2, and f3 into the stack
|
|
3 index
|
|
3 index
|
|
3 index
|
|
|
|
% Compute G = f1 * -1.2684380046 + f2 * 2.6097574011 + f3 * -0.3413193965
|
|
-0.3413193965 mul exch
|
|
2.6097574011 mul add exch
|
|
-1.2684380046 mul add
|
|
|
|
% Load f1, f2, and f3 into the stack
|
|
4 index
|
|
4 index
|
|
4 index
|
|
|
|
% Compute B = f1 * -0.0041960863 + f2 * -0.7034186147 + f3 * 1.7076147010
|
|
1.7076147010 mul exch
|
|
-0.7034186147 mul add exch
|
|
-0.0041960863 mul add
|
|
|
|
% Discard f1, f2, and f3 by rolling the stack and popping
|
|
6 3 roll pop pop pop
|
|
}
|