| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 * Very common wide gamut color space. | 30 * Very common wide gamut color space. |
| 31 * Often used by images and monitors. | 31 * Often used by images and monitors. |
| 32 */ | 32 */ |
| 33 kAdobeRGB_Named, | 33 kAdobeRGB_Named, |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 enum GammaNamed : uint8_t { | 36 enum GammaNamed : uint8_t { |
| 37 kLinear_GammaNamed, | 37 kLinear_GammaNamed, |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Gamma curve is a close match to the canonical sRGB curve, which has | 40 * Transfer function is the canonical sRGB curve, which has a short lin
ear segment |
| 41 * a short linear segment followed by a 2.4f exponential. | 41 * followed by a 2.4f exponential. |
| 42 */ | 42 */ |
| 43 kSRGB_GammaNamed, | 43 kSRGB_GammaNamed, |
| 44 | |
| 45 /** | |
| 46 * Gamma curve is a close match to the 2.2f exponential curve. This is | |
| 47 * used by Adobe RGB profiles and is common on monitors as well. | |
| 48 */ | |
| 49 k2Dot2Curve_GammaNamed, | |
| 50 | |
| 51 /** | |
| 52 * Gamma is represented by a look-up table, a parametric curve, or an u
ncommon | |
| 53 * exponential curve. Or the R, G, and B gammas do not match. | |
| 54 */ | |
| 55 kNonStandard_GammaNamed, | |
| 56 }; | 44 }; |
| 57 | 45 |
| 58 /** | 46 /** |
| 59 * Create an SkColorSpace from the src gamma and a transform from src gamut
to D50 XYZ. | 47 * Create an SkColorSpace from the src gamma and a transform from src gamut
to D50 XYZ. |
| 60 */ | 48 */ |
| 61 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t
oXYZD50); | 49 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t
oXYZD50); |
| 62 | 50 |
| 63 /** | 51 /** |
| 64 * Create a common, named SkColorSpace. | 52 * Create a common, named SkColorSpace. |
| 65 */ | 53 */ |
| 66 static sk_sp<SkColorSpace> NewNamed(Named); | 54 static sk_sp<SkColorSpace> NewNamed(Named); |
| 67 | 55 |
| 68 /** | 56 /** |
| 69 * Create an SkColorSpace from an ICC profile. | 57 * Create an SkColorSpace from an ICC profile. |
| 70 */ | 58 */ |
| 71 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 59 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| 72 | 60 |
| 73 /** | 61 /** |
| 74 * Create an SkColorSpace with the same gamut as this color space, but with
linear gamma. | 62 * Create an SkColorSpace with the same gamut as this color space, but with
linear gamma. |
| 75 */ | 63 */ |
| 76 sk_sp<SkColorSpace> makeLinearGamma(); | 64 sk_sp<SkColorSpace> makeLinearGamma(); |
| 77 | 65 |
| 78 GammaNamed gammaNamed() const { return fGammaNamed; } | |
| 79 | |
| 80 /** | 66 /** |
| 81 * Returns the matrix used to transform src gamut to XYZ D50. | 67 * Returns the matrix used to transform src gamut to XYZ D50. |
| 82 */ | 68 */ |
| 83 const SkMatrix44& xyz() const { return fToXYZD50; } | 69 const SkMatrix44& xyz() const { return fToXYZD50; } |
| 84 | 70 |
| 85 /** | 71 /** |
| 86 * Returns true if the color space gamma is near enough to be approximated
as sRGB. | 72 * Returns true if the color space gamma is near enough to be approximated
as sRGB. |
| 87 */ | 73 */ |
| 88 bool gammaCloseToSRGB() const { | 74 bool gammaCloseToSRGB() const; |
| 89 return kSRGB_GammaNamed == fGammaNamed || k2Dot2Curve_GammaNamed == fGam
maNamed; | |
| 90 } | |
| 91 | 75 |
| 92 /** | 76 /** |
| 93 * To be used only by UMA code. | 77 * Returns true if the color space gamma is linear. |
| 94 */ | 78 */ |
| 95 bool gammasAreMatching() const; | 79 bool gammaIsLinear() const; |
| 96 bool gammasAreNamed() const; | |
| 97 bool gammasAreValues() const; | |
| 98 bool gammasAreTables() const; | |
| 99 bool gammasAreParams() const; | |
| 100 | 80 |
| 101 /** | 81 /** |
| 102 * Returns nullptr on failure. Fails when we fallback to serializing ICC d
ata and | 82 * Returns nullptr on failure. Fails when we fallback to serializing ICC d
ata and |
| 103 * the data is too large to serialize. | 83 * the data is too large to serialize. |
| 104 */ | 84 */ |
| 105 sk_sp<SkData> serialize() const; | 85 sk_sp<SkData> serialize() const; |
| 106 | 86 |
| 107 /** | 87 /** |
| 108 * If |memory| is nullptr, returns the size required to serialize. | 88 * If |memory| is nullptr, returns the size required to serialize. |
| 109 * Otherwise, serializes into |memory| and returns the size. | 89 * Otherwise, serializes into |memory| and returns the size. |
| 110 */ | 90 */ |
| 111 size_t writeToMemory(void* memory) const; | 91 size_t writeToMemory(void* memory) const; |
| 112 | 92 |
| 113 static sk_sp<SkColorSpace> Deserialize(const void* data, size_t length); | 93 static sk_sp<SkColorSpace> Deserialize(const void* data, size_t length); |
| 114 | 94 |
| 115 /** | 95 /** |
| 116 * If both are null, we return true. If one is null and the other is not,
we return false. | 96 * If both are null, we return true. If one is null and the other is not,
we return false. |
| 117 * If both are non-null, we do a deeper compare. | 97 * If both are non-null, we do a deeper compare. |
| 118 */ | 98 */ |
| 119 static bool Equals(const SkColorSpace* src, const SkColorSpace* dst); | 99 static bool Equals(const SkColorSpace* src, const SkColorSpace* dst); |
| 120 | 100 |
| 121 protected: | 101 protected: |
| 122 SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50); | 102 SkColorSpace(const SkMatrix44& toXYZD50); |
| 123 | 103 |
| 124 const GammaNamed fGammaNamed; | |
| 125 const SkMatrix44 fToXYZD50; | 104 const SkMatrix44 fToXYZD50; |
| 126 }; | 105 }; |
| 127 | 106 |
| 128 #endif | 107 #endif |
| OLD | NEW |