Chromium Code Reviews| Index: include/core/SkColorSpace.h |
| diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h |
| index 715cc403e3fe8fac354bf46d8ddde7c9e0fc11dc..8559d4e05ca5174c184c2c845b4b5405c4587278 100644 |
| --- a/include/core/SkColorSpace.h |
| +++ b/include/core/SkColorSpace.h |
| @@ -13,6 +13,105 @@ |
| class SkData; |
| +/** |
| + * Describes a color gamut with primaries and a white point. |
| + */ |
| +struct SK_API SkPrimaries { |
| + |
| + float fRX, fRY; |
| + float fGX, fGY; |
| + float fBX, fBY; |
| + float fWX, fWY; |
| + |
| + enum Named { |
| + kBT2020_Named, |
| + kBT709_Named, |
| + }; |
| + |
| + /** |
| + * Just a few examples. Clients are free to fill in their own gamut. |
| + */ |
| + 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
|
| + switch (named) { |
| + case kBT2020_Named: |
| + fRX = 0.708f; |
| + fRY = 0.292f; |
| + fGX = 0.170f; |
| + fGY = 0.797f; |
| + fBX = 0.131f; |
| + fBY = 0.046f; |
| + fWX = 0.3127f; |
| + fWY = 0.3290f; |
| + break; |
| + case kBT709_Named: |
| + fRX = 0.640f; |
| + fRY = 0.330f; |
| + fGX = 0.300f; |
| + fGY = 0.600f; |
| + fBX = 0.150f; |
| + fBY = 0.060f; |
| + fWX = 0.3127f; |
| + fWY = 0.3290f; |
| + break; |
| + } |
| + } |
| +}; |
| + |
| +/** |
| + * Contains the coefficients for a common transfer function equation, specified as |
| + * a transformation from a curved space to linear. |
| + * |
| + * LinearVal = E*InputVal + F , for 0.0f <= InputVal < D |
| + * LinearVal = (A*InputVal + B)^G + C, for D <= InputVal <= 1.0f |
| + * |
| + * Function is undefined if InputVal is not in [ 0.0f, 1.0f ]. |
| + * Resulting LinearVals must be in [ 0.0f, 1.0f ]. |
| + * Function must be increasing. |
| + */ |
| +struct SkTransferFn { |
| + |
| + float fG; |
| + float fA; |
| + float fB; |
| + float fC; |
| + float fD; |
| + float fE; |
| + float fF; |
| + |
| + enum Named { |
| + kBT2020_Named, |
| + kBT709_Named, |
| + k2Dot2_Named, |
| + }; |
| + |
| + /** |
| + * Just a few examples. Clients are free to fill in their own function. |
| + */ |
| + SkTransferFn(Named named) { |
| + switch (named) { |
| + case kBT2020_Named: |
| + case kBT709_Named: |
| + fG = (1.0f / 0.45f); |
| + fA = (1.0f / 1.099296826809442f); |
| + fB = (0.099296826809442f / 1.099296826809442f); |
| + fC = 0.0f; |
| + fD = 0.081f; |
| + fE = (1.0f / 4.0f); |
| + fF = 0.0f; |
| + break; |
| + case k2Dot2_Named: |
| + fG = 2.2f; |
| + fA = 1.0f; |
| + fB = 0.0f; |
| + fC = 0.0f; |
| + fD = 0.0f; |
| + fE = 0.0f; |
| + fF = 0.0f; |
| + break; |
| + } |
| + } |
| +}; |
| + |
| class SK_API SkColorSpace : public SkRefCnt { |
| public: |
| @@ -44,9 +143,25 @@ public: |
| }; |
| /** |
| - * Create an SkColorSpace from the src gamma and a transform from src gamut to D50 XYZ. |
| + * Convert primaries and a white point to a toXYZD50 matrix, the preferred color gamut |
| + * representation of SkColorSpace. |
| + */ |
| + 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.
|
| + // TODO: Implement this. |
| + return false; |
| + } |
| + |
| + /** |
| + * Create an SkColorSpace from a transfer function and a gamut. |
| + * |
| + * Transfer function can be specified using an enum or the coefficients to an equation. |
| + * Gamut can specified using the to D50 matrix transformation or using a set |
| + * of primaries and a white point. |
| */ |
| static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& toXYZD50); |
| + static sk_sp<SkColorSpace> NewRGB(const SkTransferFn& coeffs, const SkMatrix44& toXYZD50); |
| + static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkPrimaries& primaries); |
| + static sk_sp<SkColorSpace> NewRGB(const SkTransferFn& coeffs, const SkPrimaries& primaries); |
| /** |
| * Create a common, named SkColorSpace. |