1fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/*
2fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Copyright 2016 Google Inc.
3fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot *
4fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Use of this source code is governed by a BSD-style license that can be
5fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * found in the LICENSE file.
6fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */
7fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#ifndef SkColorSpacePriv_DEFINED
8fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#define SkColorSpacePriv_DEFINED
9fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
10fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include <math.h>
11fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
12fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkColorSpace.h"
13fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkFixed.h"
14fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
15fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#define SkColorSpacePrintf(...)
16fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
17fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr float gSRGB_toXYZD50[] {
18fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.4360747f, 0.3850649f, 0.1430804f, // Rx, Gx, Bx
19fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.2225045f, 0.7168786f, 0.0606169f, // Ry, Gy, Gz
20fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.0139322f, 0.0971045f, 0.7141733f, // Rz, Gz, Bz
21fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot};
22fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
23fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr float gAdobeRGB_toXYZD50[] {
24fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#ifdef SK_SUPPORT_LEGACY_ADOBE_XYZ
25fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.6097559f, 0.2052401f, 0.1492240f, // Rx, Gx, Bx
26fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.3111242f, 0.6256560f, 0.0632197f, // Ry, Gy, Gz
27fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.0194811f, 0.0608902f, 0.7448387f, // Rz, Gz, Bz
28fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#else
29fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // ICC fixed-point (16.16) repesentation of:
30fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // 0.60974, 0.20528, 0.14919,
31fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // 0.31111, 0.62567, 0.06322,
32fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // 0.01947, 0.06087, 0.74457,
33fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    SkFixedToFloat(0x9c18), SkFixedToFloat(0x348d), SkFixedToFloat(0x2631), // Rx, Gx, Bx
34fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    SkFixedToFloat(0x4fa5), SkFixedToFloat(0xa02c), SkFixedToFloat(0x102f), // Ry, Gy, Gz
35fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    SkFixedToFloat(0x04fc), SkFixedToFloat(0x0f95), SkFixedToFloat(0xbe9c), // Rz, Gz, Bz
36fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#endif
37fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot};
38fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
39fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr float gDCIP3_toXYZD50[] {
40fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.515102f,   0.291965f,  0.157153f,  // Rx, Gx, Bx
41fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.241182f,   0.692236f,  0.0665819f, // Ry, Gy, Gz
42fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot   -0.00104941f, 0.0418818f, 0.784378f,  // Rz, Gz, Bz
43fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot};
44fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
45fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr float gRec2020_toXYZD50[] {
46fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.673459f,   0.165661f,  0.125100f,  // Rx, Gx, Bx
47fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    0.279033f,   0.675338f,  0.0456288f, // Ry, Gy, Gz
48fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot   -0.00193139f, 0.0299794f, 0.797162f,  // Rz, Gz, Bz
49fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot};
50fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
51fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr SkColorSpaceTransferFn gSRGB_TransferFn =
52fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        { 2.4f, 1.0f / 1.055f, 0.055f / 1.055f, 1.0f / 12.92f, 0.04045f, 0.0f, 0.0f };
53fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
54fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr SkColorSpaceTransferFn g2Dot2_TransferFn =
55fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        { 2.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
56fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
57fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot// gLinear_TransferFn.fD > 1.0f: Make sure that we use the linear segment of
58fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot// the transfer function even when the x-value is 1.0f.
59fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr SkColorSpaceTransferFn gLinear_TransferFn =
60fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        { 0.0f, 0.0f, 0.0f, 1.0f, 1.0000001f, 0.0f, 0.0f };
61fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
62fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic constexpr SkColorSpaceTransferFn gDCIP3_TransferFn =
63fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    { 2.399994f, 0.947998047f, 0.0520019531f, 0.0769958496f, 0.0390014648f, 0.0f, 0.0f };
64fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
65fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline void to_xyz_d50(SkMatrix44* toXYZD50, SkColorSpace::Gamut gamut) {
66fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    switch (gamut) {
67fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case SkColorSpace::kSRGB_Gamut:
68fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            toXYZD50->set3x3RowMajorf(gSRGB_toXYZD50);
69fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            break;
70fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case SkColorSpace::kAdobeRGB_Gamut:
71fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            toXYZD50->set3x3RowMajorf(gAdobeRGB_toXYZD50);
72fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            break;
73fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case SkColorSpace::kDCIP3_D65_Gamut:
74fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            toXYZD50->set3x3RowMajorf(gDCIP3_toXYZD50);
75fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            break;
76fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case SkColorSpace::kRec2020_Gamut:
77fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            toXYZD50->set3x3RowMajorf(gRec2020_toXYZD50);
78fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            break;
79fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
80fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
81fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
82fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool color_space_almost_equal(float a, float b) {
83fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return SkTAbs(a - b) < 0.01f;
84fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
85fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
86fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot// Let's use a stricter version for transfer functions.  Worst case, these are encoded
87fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot// in ICC format, which offers 16-bits of fractional precision.
88fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool transfer_fn_almost_equal(float a, float b) {
89fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return SkTAbs(a - b) < 0.001f;
90fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
91fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
92fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool is_zero_to_one(float v) {
93fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // Because we allow a value just barely larger than 1, the client can use an
94fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // entirely linear transfer function.
95fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return (0.0f <= v) && (v <= nextafterf(1.0f, 2.0f));
96fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
97fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
98fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool is_valid_transfer_fn(const SkColorSpaceTransferFn& coeffs) {
99fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if (SkScalarIsNaN(coeffs.fA) || SkScalarIsNaN(coeffs.fB) ||
100fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        SkScalarIsNaN(coeffs.fC) || SkScalarIsNaN(coeffs.fD) ||
101fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        SkScalarIsNaN(coeffs.fE) || SkScalarIsNaN(coeffs.fF) ||
102fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        SkScalarIsNaN(coeffs.fG))
103fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    {
104fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        return false;
105fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
106fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
107fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if (!is_zero_to_one(coeffs.fD)) {
108fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        return false;
109fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
110fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
111fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if (coeffs.fD == 0.0f) {
112fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        // Y = (aX + b)^g + e  for always
113fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        if (0.0f == coeffs.fA || 0.0f == coeffs.fG) {
114fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            SkColorSpacePrintf("A or G is zero, constant transfer function "
115fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot                               "is nonsense");
116fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            return false;
117fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        }
118fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
119fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
120fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if (coeffs.fD >= 1.0f) {
121fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        // Y = cX + f          for always
122fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        if (0.0f == coeffs.fC) {
123fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            SkColorSpacePrintf("C is zero, constant transfer function is "
124fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot                               "nonsense");
125fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            return false;
126fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        }
127fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
128fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
129fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if ((0.0f == coeffs.fA || 0.0f == coeffs.fG) && 0.0f == coeffs.fC) {
130fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        SkColorSpacePrintf("A or G, and C are zero, constant transfer function "
131fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot                           "is nonsense");
132fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        return false;
133fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
134fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
135fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if (coeffs.fC < 0.0f) {
136fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        SkColorSpacePrintf("Transfer function must be increasing");
137fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        return false;
138fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
139fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
140fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    if (coeffs.fA < 0.0f || coeffs.fG < 0.0f) {
141fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        SkColorSpacePrintf("Transfer function must be positive or increasing");
142fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        return false;
143fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
144fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
145fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return true;
146fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
147fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
148fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool is_almost_srgb(const SkColorSpaceTransferFn& coeffs) {
149fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return transfer_fn_almost_equal(gSRGB_TransferFn.fA, coeffs.fA) &&
150fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(gSRGB_TransferFn.fB, coeffs.fB) &&
151fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(gSRGB_TransferFn.fC, coeffs.fC) &&
152fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(gSRGB_TransferFn.fD, coeffs.fD) &&
153fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(gSRGB_TransferFn.fE, coeffs.fE) &&
154fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(gSRGB_TransferFn.fF, coeffs.fF) &&
155fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(gSRGB_TransferFn.fG, coeffs.fG);
156fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
157fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
158fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool is_almost_2dot2(const SkColorSpaceTransferFn& coeffs) {
159fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return transfer_fn_almost_equal(1.0f, coeffs.fA) &&
160fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(0.0f, coeffs.fB) &&
161fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(0.0f, coeffs.fE) &&
162fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           transfer_fn_almost_equal(2.2f, coeffs.fG) &&
163fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot           coeffs.fD <= 0.0f;
164fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
165fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
166fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool is_almost_linear(const SkColorSpaceTransferFn& coeffs) {
167fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // OutputVal = InputVal ^ 1.0f
168fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    const bool linearExp =
169fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            transfer_fn_almost_equal(1.0f, coeffs.fA) &&
170fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            transfer_fn_almost_equal(0.0f, coeffs.fB) &&
171fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            transfer_fn_almost_equal(0.0f, coeffs.fE) &&
172fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            transfer_fn_almost_equal(1.0f, coeffs.fG) &&
173fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            coeffs.fD <= 0.0f;
174fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
175fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    // OutputVal = 1.0f * InputVal
176fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    const bool linearFn =
177fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            transfer_fn_almost_equal(1.0f, coeffs.fC) &&
178fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            transfer_fn_almost_equal(0.0f, coeffs.fF) &&
179fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            coeffs.fD >= 1.0f;
180fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
181fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return linearExp || linearFn;
182fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
183fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
184fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool is_just_gamma(const SkColorSpaceTransferFn& coeffs) {
185fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    return transfer_fn_almost_equal(coeffs.fA, 1.0f)
186fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        && transfer_fn_almost_equal(coeffs.fB, 0.0f)
187fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        && transfer_fn_almost_equal(coeffs.fC, 0.0f)
188fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        && transfer_fn_almost_equal(coeffs.fD, 0.0f)
189fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        && transfer_fn_almost_equal(coeffs.fE, 0.0f)
190fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        && transfer_fn_almost_equal(coeffs.fF, 0.0f);
191fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
192fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
193fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
194fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline void value_to_parametric(SkColorSpaceTransferFn* coeffs, float exponent) {
195fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fA = 1.0f;
196fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fB = 0.0f;
197fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fC = 0.0f;
198fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fD = 0.0f;
199fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fE = 0.0f;
200fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fF = 0.0f;
201fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    coeffs->fG = exponent;
202fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
203fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot
204fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool named_to_parametric(SkColorSpaceTransferFn* coeffs,
205fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot                                       SkGammaNamed gammaNamed) {
206fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    switch (gammaNamed) {
207fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case kSRGB_SkGammaNamed:
208fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            *coeffs = gSRGB_TransferFn;
209fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            return true;
210fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case k2Dot2Curve_SkGammaNamed:
211fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            *coeffs = g2Dot2_TransferFn;
212fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            return true;
213fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        case kLinear_SkGammaNamed:
214fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            *coeffs = gLinear_TransferFn;
215fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            return true;
216fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot        default:
217fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot            return false;
218fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot    }
219fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}
220fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#endif  // SkColorSpacePriv_DEFINED
221