Chromium Code Reviews| 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 #ifndef SkColorSpace_DEFINED | 8 #ifndef SkColorSpace_DEFINED |
| 9 #define SkColorSpace_DEFINED | 9 #define SkColorSpace_DEFINED |
| 10 | 10 |
| 11 #include "SkMatrix44.h" | 11 #include "SkMatrix44.h" |
| 12 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
| 13 | 13 |
| 14 class SkData; | 14 class SkData; |
| 15 | 15 |
| 16 /** | |
| 17 * Describes a color gamut with primaries and a white point. | |
| 18 */ | |
| 19 struct SK_API SkPrimaries { | |
| 20 | |
| 21 float fRX, fRY; | |
| 22 float fGX, fGY; | |
| 23 float fBX, fBY; | |
| 24 float fWX, fWY; | |
| 25 | |
| 26 enum Named { | |
| 27 kBT2020_Named, | |
| 28 kBT709_Named, | |
| 29 }; | |
| 30 | |
| 31 /** | |
| 32 * Just a few examples. Clients are free to fill in their own gamut. | |
| 33 */ | |
| 34 SkPrimaries(Named named) { | |
|
reed1
2016/09/06 23:19:48
like not inlined, right?
msarett
2016/09/07 14:01:20
Yes, not here.
I've added a default constructor a
| |
| 35 switch (named) { | |
| 36 case kBT2020_Named: | |
| 37 fRX = 0.708f; | |
| 38 fRY = 0.292f; | |
| 39 fGX = 0.170f; | |
| 40 fGY = 0.797f; | |
| 41 fBX = 0.131f; | |
| 42 fBY = 0.046f; | |
| 43 fWX = 0.3127f; | |
| 44 fWY = 0.3290f; | |
| 45 break; | |
| 46 case kBT709_Named: | |
| 47 fRX = 0.640f; | |
| 48 fRY = 0.330f; | |
| 49 fGX = 0.300f; | |
| 50 fGY = 0.600f; | |
| 51 fBX = 0.150f; | |
| 52 fBY = 0.060f; | |
| 53 fWX = 0.3127f; | |
| 54 fWY = 0.3290f; | |
| 55 break; | |
| 56 } | |
| 57 } | |
| 58 }; | |
| 59 | |
| 60 /** | |
| 61 * Contains the coefficients for a common transfer function equation, specified as | |
| 62 * a transformation from a curved space to linear. | |
| 63 * | |
| 64 * LinearVal = E*InputVal + F , for 0.0f <= InputVal < D | |
| 65 * LinearVal = (A*InputVal + B)^G + C, for D <= InputVal <= 1.0f | |
| 66 * | |
| 67 * Function is undefined if InputVal is not in [ 0.0f, 1.0f ]. | |
| 68 * Resulting LinearVals must be in [ 0.0f, 1.0f ]. | |
| 69 * Function must be increasing. | |
| 70 */ | |
| 71 struct SkTransferFn { | |
| 72 | |
| 73 float fG; | |
| 74 float fA; | |
| 75 float fB; | |
| 76 float fC; | |
| 77 float fD; | |
| 78 float fE; | |
| 79 float fF; | |
| 80 | |
| 81 enum Named { | |
| 82 kBT2020_Named, | |
| 83 kBT709_Named, | |
| 84 k2Dot2_Named, | |
| 85 }; | |
| 86 | |
| 87 /** | |
| 88 * Just a few examples. Clients are free to fill in their own function. | |
| 89 */ | |
| 90 SkTransferFn(Named named) { | |
| 91 switch (named) { | |
| 92 case kBT2020_Named: | |
| 93 case kBT709_Named: | |
| 94 fG = (1.0f / 0.45f); | |
| 95 fA = (1.0f / 1.099296826809442f); | |
| 96 fB = (0.099296826809442f / 1.099296826809442f); | |
| 97 fC = 0.0f; | |
| 98 fD = 0.081f; | |
| 99 fE = (1.0f / 4.0f); | |
| 100 fF = 0.0f; | |
| 101 break; | |
| 102 case k2Dot2_Named: | |
| 103 fG = 2.2f; | |
| 104 fA = 1.0f; | |
| 105 fB = 0.0f; | |
| 106 fC = 0.0f; | |
| 107 fD = 0.0f; | |
| 108 fE = 0.0f; | |
| 109 fF = 0.0f; | |
| 110 break; | |
| 111 } | |
| 112 } | |
| 113 }; | |
| 114 | |
| 16 class SK_API SkColorSpace : public SkRefCnt { | 115 class SK_API SkColorSpace : public SkRefCnt { |
| 17 public: | 116 public: |
| 18 | 117 |
| 19 /** | 118 /** |
| 20 * Common, named profiles that we can recognize. | 119 * Common, named profiles that we can recognize. |
| 21 */ | 120 */ |
| 22 enum Named : uint8_t { | 121 enum Named : uint8_t { |
| 23 /** | 122 /** |
| 24 * By far the most common color space. | 123 * By far the most common color space. |
| 25 * This is the default space for images, unmarked content, and monitors . | 124 * This is the default space for images, unmarked content, and monitors . |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 kLinear_GammaNamed, | 136 kLinear_GammaNamed, |
| 38 | 137 |
| 39 /** | 138 /** |
| 40 * Transfer function is the canonical sRGB curve, which has a short lin ear segment | 139 * Transfer function is the canonical sRGB curve, which has a short lin ear segment |
| 41 * followed by a 2.4f exponential. | 140 * followed by a 2.4f exponential. |
| 42 */ | 141 */ |
| 43 kSRGB_GammaNamed, | 142 kSRGB_GammaNamed, |
| 44 }; | 143 }; |
| 45 | 144 |
| 46 /** | 145 /** |
| 47 * Create an SkColorSpace from the src gamma and a transform from src gamut to D50 XYZ. | 146 * Convert primaries and a white point to a toXYZD50 matrix, the preferred color gamut |
| 147 * representation of SkColorSpace. | |
| 148 */ | |
| 149 static bool PrimariesToXYZD50(SkMatrix44* /*toXYZD50*/, const SkPrimaries& / *primaries*/) { | |
|
reed1
2016/09/06 23:19:48
can/should this be a method on primaries?
msarett
2016/09/07 14:01:20
Yes, works for me.
| |
| 150 // TODO: Implement this. | |
| 151 return false; | |
| 152 } | |
| 153 | |
| 154 /** | |
| 155 * Create an SkColorSpace from a transfer function and a gamut. | |
| 156 * | |
| 157 * Transfer function can be specified using an enum or the coefficients to an equation. | |
| 158 * Gamut can specified using the to D50 matrix transformation or using a se t | |
| 159 * of primaries and a white point. | |
| 48 */ | 160 */ |
| 49 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t oXYZD50); | 161 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t oXYZD50); |
| 162 static sk_sp<SkColorSpace> NewRGB(const SkTransferFn& coeffs, const SkMatrix 44& toXYZD50); | |
| 163 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkPrimaries& primaries); | |
| 164 static sk_sp<SkColorSpace> NewRGB(const SkTransferFn& coeffs, const SkPrimar ies& primaries); | |
| 50 | 165 |
| 51 /** | 166 /** |
| 52 * Create a common, named SkColorSpace. | 167 * Create a common, named SkColorSpace. |
| 53 */ | 168 */ |
| 54 static sk_sp<SkColorSpace> NewNamed(Named); | 169 static sk_sp<SkColorSpace> NewNamed(Named); |
| 55 | 170 |
| 56 /** | 171 /** |
| 57 * Create an SkColorSpace from an ICC profile. | 172 * Create an SkColorSpace from an ICC profile. |
| 58 */ | 173 */ |
| 59 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 174 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 */ | 213 */ |
| 99 static bool Equals(const SkColorSpace* src, const SkColorSpace* dst); | 214 static bool Equals(const SkColorSpace* src, const SkColorSpace* dst); |
| 100 | 215 |
| 101 protected: | 216 protected: |
| 102 SkColorSpace(const SkMatrix44& toXYZD50); | 217 SkColorSpace(const SkMatrix44& toXYZD50); |
| 103 | 218 |
| 104 const SkMatrix44 fToXYZD50; | 219 const SkMatrix44 fToXYZD50; |
| 105 }; | 220 }; |
| 106 | 221 |
| 107 #endif | 222 #endif |
| OLD | NEW |