summaryrefslogtreecommitdiff
path: root/crates/typst-pdf/src/oklab.ps
blob: e766bbd8455f08dbce05e53d70318596186ff514 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
    % 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
}