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 SkColorSpace : public SkRefCnt { | 14 class SkColorSpace : public SkRefCnt { |
15 public: | 15 public: |
16 | 16 |
17 /** | 17 /** |
18 * Common, named profiles that we can recognize. | 18 * Common, named profiles that we can recognize. |
19 */ | 19 */ |
20 enum Named { | 20 enum Named { |
21 kUnknown_Named, | 21 kUnknown_Named, |
22 kSRGB_Named, | 22 kSRGB_Named, |
23 kAdobeRGB_Named, | 23 kAdobeRGB_Named, |
24 }; | 24 }; |
25 | 25 |
26 /** | |
27 * Create an SkColorSpace from the src gamma and a transform from src gamut
to D50 XYZ. | |
28 */ | |
29 static sk_sp<SkColorSpace> NewRGB(const float gammas[3], const SkMatrix44& t
oXYZD50); | |
30 | |
31 /** | |
32 * Create a common, named SkColorSpace. | |
33 */ | |
34 static sk_sp<SkColorSpace> NewNamed(Named); | |
35 | |
36 /** | |
37 * Create an SkColorSpace from an ICC profile. | |
38 */ | |
39 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | |
40 | |
41 enum GammaNamed { | 26 enum GammaNamed { |
42 kLinear_GammaNamed, | 27 kLinear_GammaNamed, |
43 | 28 |
44 /** | 29 /** |
45 * Gamma curve is a close match to the 2.2f exponential curve. This is
by far | 30 * Gamma curve is a close match to the canonical sRGB curve, which has |
46 * the most common gamma, and is used by sRGB and Adobe RGB profiles. | 31 * a short linear segment followed by a 2.4f exponential. |
| 32 */ |
| 33 kSRGB_GammaNamed, |
| 34 |
| 35 /** |
| 36 * Gamma curve is a close match to the 2.2f exponential curve. This is |
| 37 * used by Adobe RGB profiles and is common on monitors as well. |
47 */ | 38 */ |
48 k2Dot2Curve_GammaNamed, | 39 k2Dot2Curve_GammaNamed, |
49 | 40 |
50 /** | 41 /** |
51 * Gamma is represented by a look-up table, a parametric curve, or an u
ncommon | 42 * Gamma is represented by a look-up table, a parametric curve, or an u
ncommon |
52 * exponential curve. Or there is an additional pre-processing step be
fore the | 43 * exponential curve. Or there is an additional pre-processing step be
fore the |
53 * applying the gamma. | 44 * applying the gamma. |
54 */ | 45 */ |
55 kNonStandard_GammaNamed, | 46 kNonStandard_GammaNamed, |
56 }; | 47 }; |
57 | 48 |
| 49 /** |
| 50 * Create an SkColorSpace from the src gamma and a transform from src gamut
to D50 XYZ. |
| 51 */ |
| 52 static sk_sp<SkColorSpace> NewRGB(GammaNamed gammaNamed, const SkMatrix44& t
oXYZD50); |
| 53 |
| 54 /** |
| 55 * Create a common, named SkColorSpace. |
| 56 */ |
| 57 static sk_sp<SkColorSpace> NewNamed(Named); |
| 58 |
| 59 /** |
| 60 * Create an SkColorSpace from an ICC profile. |
| 61 */ |
| 62 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| 63 |
58 GammaNamed gammaNamed() const { return fGammaNamed; } | 64 GammaNamed gammaNamed() const { return fGammaNamed; } |
59 | 65 |
60 /** | 66 /** |
61 * Returns the matrix used to transform src gamut to XYZ D50. | 67 * Returns the matrix used to transform src gamut to XYZ D50. |
62 */ | 68 */ |
63 const SkMatrix44& xyz() const { return fToXYZD50; } | 69 const SkMatrix44& xyz() const { return fToXYZD50; } |
64 | 70 |
| 71 /** |
| 72 * Returns true if the color space gamma is near enough to be approximated
as sRGB. |
| 73 */ |
| 74 bool gammaCloseToSRGB() const { |
| 75 return kSRGB_GammaNamed == fGammaNamed || k2Dot2Curve_GammaNamed == fGam
maNamed; |
| 76 } |
| 77 |
65 protected: | 78 protected: |
66 | 79 |
67 SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named)
; | 80 SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named)
; |
68 | 81 |
69 const GammaNamed fGammaNamed; | 82 const GammaNamed fGammaNamed; |
70 const SkMatrix44 fToXYZD50; | 83 const SkMatrix44 fToXYZD50; |
71 const Named fNamed; | 84 const Named fNamed; |
72 }; | 85 }; |
73 | 86 |
74 #endif | 87 #endif |
OLD | NEW |