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
79
80
81
82
83
84
85
86
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#define SkColorSpacePrintf(...)
static inline bool color_space_almost_equal(float a, float b) {
return SkTAbs(a - b) < 0.01f;
}
static inline bool is_zero_to_one(float v) {
return (0.0f <= v) && (v <= 1.0f);
}
static inline bool is_valid_transfer_fn(const SkColorSpaceTransferFn& coeffs) {
if (SkScalarIsNaN(coeffs.fA) || SkScalarIsNaN(coeffs.fB) ||
SkScalarIsNaN(coeffs.fC) || SkScalarIsNaN(coeffs.fD) ||
SkScalarIsNaN(coeffs.fE) || SkScalarIsNaN(coeffs.fF) ||
SkScalarIsNaN(coeffs.fG))
{
return false;
}
if (!is_zero_to_one(coeffs.fD)) {
return false;
}
if (coeffs.fD == 0.0f) {
// Y = (aX + b)^g + c for always
if (0.0f == coeffs.fA || 0.0f == coeffs.fG) {
SkColorSpacePrintf("A or G is zero, constant transfer function "
"is nonsense");
return false;
}
}
if (coeffs.fD == 1.0f) {
// Y = eX + f for always
if (0.0f == coeffs.fE) {
SkColorSpacePrintf("E is zero, constant transfer function is "
"nonsense");
return false;
}
}
if ((0.0f == coeffs.fA || 0.0f == coeffs.fG) && 0.0f == coeffs.fE) {
SkColorSpacePrintf("A or G, and E are zero, constant transfer function "
"is nonsense");
return false;
}
if (coeffs.fE < 0.0f) {
SkColorSpacePrintf("Transfer function must be increasing");
return false;
}
if (coeffs.fA < 0.0f || coeffs.fG < 0.0f) {
SkColorSpacePrintf("Transfer function must be positive or increasing");
return false;
}
return true;
}
static inline bool is_almost_srgb(const SkColorSpaceTransferFn& coeffs) {
return color_space_almost_equal(0.9479f, coeffs.fA) &&
color_space_almost_equal(0.0521f, coeffs.fB) &&
color_space_almost_equal(0.0000f, coeffs.fC) &&
color_space_almost_equal(0.0405f, coeffs.fD) &&
color_space_almost_equal(0.0774f, coeffs.fE) &&
color_space_almost_equal(0.0000f, coeffs.fF) &&
color_space_almost_equal(2.4000f, coeffs.fG);
}
static inline bool is_almost_2dot2(const SkColorSpaceTransferFn& coeffs) {
return color_space_almost_equal(1.0f, coeffs.fA) &&
color_space_almost_equal(0.0f, coeffs.fB) &&
color_space_almost_equal(0.0f, coeffs.fC) &&
color_space_almost_equal(0.0f, coeffs.fD) &&
color_space_almost_equal(0.0f, coeffs.fE) &&
color_space_almost_equal(0.0f, coeffs.fF) &&
color_space_almost_equal(2.2f, coeffs.fG);
}
|