1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.compose.ui.graphics.colorspace
18 
19 /**
20  * List of adaptation matrices that can be used for chromatic adaptation using the von Kries
21  * transform. These matrices are used to convert values in the CIE XYZ space to values in the LMS
22  * space (Long Medium Short).
23  *
24  * Given an adaptation matrix `A`, the conversion from XYZ to LMS is straightforward:
25  *
26  * [See
27  * equation](https://developer.android.com/reference/android/graphics/ColorSpace.Adaptation.html)
28  *
29  * The complete von Kries transform `T` uses a diagonal matrix noted `D` to perform the adaptation
30  * in LMS space. In addition to `A` and `D`, the source white point `W1` and the destination white
31  * point `W2` must be specified:
32  *
33  * [See
34  * equation](https://developer.android.com/reference/android/graphics/ColorSpace.Adaptation.html)
35  *
36  * As an example, the resulting matrix `T` can then be used to perform the chromatic adaptation of
37  * sRGB XYZ transform from D65 to D50:
38  *
39  * [See
40  * equation](https://developer.android.com/reference/android/graphics/ColorSpace.Adaptation.html)
41  *
42  * @see Connector
43  * @see ColorSpace.connect
44  */
45 abstract class Adaptation private constructor(internal val transform: FloatArray) {
46     companion object {
47         /**
48          * Bradford chromatic adaptation transform, as defined in the CIECAM97s color appearance
49          * model.
50          */
51         val Bradford =
52             object :
53                 Adaptation(
54                     floatArrayOf(
55                         0.8951f,
56                         -0.7502f,
57                         0.0389f,
58                         0.2664f,
59                         1.7135f,
60                         -0.0685f,
61                         -0.1614f,
62                         0.0367f,
63                         1.0296f
64                     )
65                 ) {
toStringnull66                 override fun toString() = "Bradford"
67             }
68 
69         /** von Kries chromatic adaptation transform. */
70         val VonKries =
71             object :
72                 Adaptation(
73                     floatArrayOf(
74                         0.40024f,
75                         -0.22630f,
76                         0.00000f,
77                         0.70760f,
78                         1.16532f,
79                         0.00000f,
80                         -0.08081f,
81                         0.04570f,
82                         0.91822f
83                     )
84                 ) {
85                 override fun toString() = "VonKries"
86             }
87 
88         /**
89          * CIECAT02 chromatic adaption transform, as defined in the CIECAM02 color appearance model.
90          */
91         val Ciecat02 =
92             object :
93                 Adaptation(
94                     floatArrayOf(
95                         0.7328f,
96                         -0.7036f,
97                         0.0030f,
98                         0.4296f,
99                         1.6975f,
100                         0.0136f,
101                         -0.1624f,
102                         0.0061f,
103                         0.9834f
104                     )
105                 ) {
toStringnull106                 override fun toString() = "Ciecat02"
107             }
108     }
109 }
110