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 // Some terms | 11 // Some terms |
12 // | 12 // |
13 // PCS : Profile Connection Space : where color number values have an absolute meaning. | 13 // PCS : Profile Connection Space : where color number values have an absolute meaning. |
14 // Part of the work float is to convert colors to and from this space... | 14 // Part of the work float is to convert colors to and from this space... |
15 // src_linear_unit_floats --> PCS --> PCS' --> dst_linear_unit_floats | 15 // src_linear_unit_floats --> PCS --> PCS' --> dst_linear_unit_floats |
16 // | 16 // |
17 // Some nice documents | 17 // Some nice documents |
18 // | 18 // |
19 // http://www.cambridgeincolour.com/tutorials/color-space-conversion.htm | 19 // http://www.cambridgeincolour.com/tutorials/color-space-conversion.htm |
20 // https://www.w3.org/Graphics/Color/srgb | 20 // https://www.w3.org/Graphics/Color/srgb |
21 // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html | 21 // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html |
22 // | 22 // |
23 | 23 |
24 #include "SkMatrix44.h" | |
24 #include "SkRefCnt.h" | 25 #include "SkRefCnt.h" |
25 #include "SkMatrix44.h" | 26 #include "SkTemplates.h" |
scroggo
2016/05/17 16:54:27
I think the new way to include this file is "../pr
msarett
2016/05/17 17:27:13
Acknowledged.
| |
26 | 27 |
27 struct SkFloat3 { | 28 struct SkColorLookUpTable; |
28 float fVec[3]; | 29 struct SkGammaCurve; |
29 | 30 struct SkGammas; |
30 void dump() const; | |
31 }; | |
32 | 31 |
33 class SkColorSpace : public SkRefCnt { | 32 class SkColorSpace : public SkRefCnt { |
34 private: | 33 public: |
35 struct SkGammaCurve { | |
36 bool isValue() const { | |
37 bool result = (0.0f != fValue); | |
38 SkASSERT(!result || (0 == fTableSize)); | |
39 return result; | |
40 } | |
41 | 34 |
42 bool isTable() const { | |
43 bool result = (0 != fTableSize); | |
44 SkASSERT(!result || (0.0f == fValue)); | |
45 SkASSERT(!result || fTable); | |
46 return result; | |
47 } | |
48 | |
49 bool isParametric() const { return false; } | |
50 | |
51 // We have three different ways to represent gamma. | |
52 // (1) A single value: | |
53 float fValue; | |
54 | |
55 // (2) A lookup table: | |
56 uint32_t fTableSize; | |
57 std::unique_ptr<float[]> fTable; | |
58 | |
59 // (3) Parameters for a curve: | |
60 // FIXME (msarett): Handle parametric curves. | |
61 | |
62 SkGammaCurve() { | |
63 memset(this, 0, sizeof(struct SkGammaCurve)); | |
64 } | |
65 | |
66 SkGammaCurve(float value) | |
67 : fValue(value) | |
68 , fTableSize(0) | |
69 , fTable(nullptr) | |
70 {} | |
71 }; | |
72 | |
73 struct SkColorLookUpTable { | |
74 static const uint8_t kMaxChannels = 16; | |
75 | |
76 uint8_t fInputChannels; | |
77 uint8_t fOutputChannels; | |
78 uint8_t fGridPoints[kMaxChannels]; | |
79 std::unique_ptr<float[]> fTable; | |
80 | |
81 SkColorLookUpTable() { | |
82 memset(this, 0, sizeof(struct SkColorLookUpTable)); | |
83 } | |
84 }; | |
85 | |
86 public: | |
87 enum Named { | 35 enum Named { |
88 kUnknown_Named, | 36 kUnknown_Named, |
89 kSRGB_Named, | 37 kSRGB_Named, |
90 kAdobeRGB_Named, | 38 kAdobeRGB_Named, |
91 }; | 39 }; |
92 | 40 |
93 struct SkGammas { | |
94 public: | |
95 SkGammas(float red, float green, float blue) | |
96 : fRed(red) | |
97 , fGreen(green) | |
98 , fBlue(blue) | |
99 {} | |
100 | |
101 SkGammas() {} | |
102 | |
103 SkDEBUGCODE(float red() const { return fRed.fValue; }) | |
104 SkDEBUGCODE(float green() const { return fGreen.fValue; }) | |
105 SkDEBUGCODE(float blue() const { return fBlue.fValue; }) | |
106 | |
107 private: | |
108 SkGammaCurve fRed; | |
109 SkGammaCurve fGreen; | |
110 SkGammaCurve fBlue; | |
111 | |
112 friend class SkColorSpace; | |
113 }; | |
114 | |
115 /** | 41 /** |
116 * Return a colorspace instance, given a transform from linear_RGB to D50_X YZ | 42 * Given the src gamma and a transform from src gamut to D50_XYZ, return a SkColorSpace. |
117 * and the src-gamma, return a ColorSpace | |
118 */ | 43 */ |
119 static sk_sp<SkColorSpace> NewRGB(SkGammas gammas, const SkMatrix44& toXYZD5 0); | 44 static sk_sp<SkColorSpace> NewRGB(float gammas[3], const SkMatrix44& toXYZD5 0); |
120 | 45 |
121 static sk_sp<SkColorSpace> NewNamed(Named); | 46 static sk_sp<SkColorSpace> NewNamed(Named); |
122 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 47 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
123 | 48 |
124 const SkGammas& gammas() const { return fGammas; } | 49 SkGammas* gammas() const { return fGammas.get(); } |
reed1
2016/05/17 13:59:24
Do we need this getter to be public? I guess its o
msarett
2016/05/17 15:40:52
Agreed that it's funny, but it's useful for test c
scroggo
2016/05/17 16:54:27
Maybe we should document that it is only meant to
msarett
2016/05/17 17:27:13
sgtm
| |
125 SkMatrix44 xyz() const { return fToXYZD50; } | 50 SkMatrix44 xyz() const { return fToXYZD50; } |
126 Named named() const { return fNamed; } | 51 Named named() const { return fNamed; } |
127 uint32_t uniqueID() const { return fUniqueID; } | 52 uint32_t uniqueID() const { return fUniqueID; } |
128 | 53 |
129 private: | 54 private: |
130 | 55 |
131 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr c, size_t len); | 56 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr c, size_t len); |
132 | 57 |
133 | 58 |
134 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel s, | 59 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel s, |
135 uint32_t outputChannels, const uint8_t* src, size_t len); | 60 uint32_t outputChannels, const uint8_t* src, size_t len); |
136 | 61 |
137 | 62 |
138 static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkMatri x44* toXYZ, | 63 static bool LoadA2B0(SkColorLookUpTable* colorLUT, sk_sp<SkGammas> gammas, S kMatrix44* toXYZ, |
139 const uint8_t* src, size_t len); | 64 const uint8_t* src, size_t len); |
140 | 65 |
141 SkColorSpace(SkGammas gammas, const SkMatrix44& toXYZ, Named); | 66 SkColorSpace(sk_sp<SkGammas> gammas, const SkMatrix44& toXYZ, Named); |
142 | 67 |
143 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, | 68 SkColorSpace(SkColorLookUpTable* colorLUT, sk_sp<SkGammas> gammas, const SkM atrix44& toXYZ); |
144 const SkMatrix44& toXYZ); | |
145 | 69 |
146 const SkColorLookUpTable fColorLUT; | 70 SkAutoTDelete<SkColorLookUpTable> fColorLUT; |
147 const SkGammas fGammas; | 71 sk_sp<SkGammas> fGammas; |
148 const SkMatrix44 fToXYZD50; | 72 const SkMatrix44 fToXYZD50; |
149 | 73 |
150 const uint32_t fUniqueID; | 74 const uint32_t fUniqueID; |
151 const Named fNamed; | 75 const Named fNamed; |
152 }; | 76 }; |
153 | 77 |
154 #endif | 78 #endif |
OLD | NEW |