OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #define SkColorSpacePrintf(...) | 8 #define SkColorSpacePrintf(...) |
9 | 9 |
10 inline bool color_space_almost_equal(float a, float b) { | 10 static inline bool color_space_almost_equal(float a, float b) { |
11 return SkTAbs(a - b) < 0.01f; | 11 return SkTAbs(a - b) < 0.01f; |
12 } | 12 } |
| 13 |
| 14 static inline bool is_zero_to_one(float v) { |
| 15 return (0.0f <= v) && (v <= 1.0f); |
| 16 } |
| 17 |
| 18 static inline bool is_valid_transfer_fn(const SkColorSpaceTransferFn& coeffs) { |
| 19 if (SkScalarIsNaN(coeffs.fA) || SkScalarIsNaN(coeffs.fB) || |
| 20 SkScalarIsNaN(coeffs.fC) || SkScalarIsNaN(coeffs.fD) || |
| 21 SkScalarIsNaN(coeffs.fE) || SkScalarIsNaN(coeffs.fF) || |
| 22 SkScalarIsNaN(coeffs.fG)) |
| 23 { |
| 24 return false; |
| 25 } |
| 26 |
| 27 if (!is_zero_to_one(coeffs.fD)) { |
| 28 return false; |
| 29 } |
| 30 |
| 31 if (coeffs.fD == 0.0f) { |
| 32 // Y = (aX + b)^g + c for always |
| 33 if (0.0f == coeffs.fA || 0.0f == coeffs.fG) { |
| 34 SkColorSpacePrintf("A or G is zero, constant transfer function " |
| 35 "is nonsense"); |
| 36 return false; |
| 37 } |
| 38 } |
| 39 |
| 40 if (coeffs.fD == 1.0f) { |
| 41 // Y = eX + f for always |
| 42 if (0.0f == coeffs.fE) { |
| 43 SkColorSpacePrintf("E is zero, constant transfer function is " |
| 44 "nonsense"); |
| 45 return false; |
| 46 } |
| 47 } |
| 48 |
| 49 if ((0.0f == coeffs.fA || 0.0f == coeffs.fG) && 0.0f == coeffs.fE) { |
| 50 SkColorSpacePrintf("A or G, and E are zero, constant transfer function " |
| 51 "is nonsense"); |
| 52 return false; |
| 53 } |
| 54 |
| 55 if (coeffs.fE < 0.0f) { |
| 56 SkColorSpacePrintf("Transfer function must be increasing"); |
| 57 return false; |
| 58 } |
| 59 |
| 60 if (coeffs.fA < 0.0f || coeffs.fG < 0.0f) { |
| 61 SkColorSpacePrintf("Transfer function must be positive or increasing"); |
| 62 return false; |
| 63 } |
| 64 |
| 65 return true; |
| 66 } |
| 67 |
| 68 static inline bool is_almost_srgb(const SkColorSpaceTransferFn& coeffs) { |
| 69 return color_space_almost_equal(0.9479f, coeffs.fA) && |
| 70 color_space_almost_equal(0.0521f, coeffs.fB) && |
| 71 color_space_almost_equal(0.0000f, coeffs.fC) && |
| 72 color_space_almost_equal(0.0405f, coeffs.fD) && |
| 73 color_space_almost_equal(0.0774f, coeffs.fE) && |
| 74 color_space_almost_equal(0.0000f, coeffs.fF) && |
| 75 color_space_almost_equal(2.4000f, coeffs.fG); |
| 76 } |
| 77 |
| 78 static inline bool is_almost_2dot2(const SkColorSpaceTransferFn& coeffs) { |
| 79 return color_space_almost_equal(1.0f, coeffs.fA) && |
| 80 color_space_almost_equal(0.0f, coeffs.fB) && |
| 81 color_space_almost_equal(0.0f, coeffs.fC) && |
| 82 color_space_almost_equal(0.0f, coeffs.fD) && |
| 83 color_space_almost_equal(0.0f, coeffs.fE) && |
| 84 color_space_almost_equal(0.0f, coeffs.fF) && |
| 85 color_space_almost_equal(2.2f, coeffs.fG); |
| 86 } |
OLD | NEW |