| 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 "SkRefCnt.h" | 24 #include "SkRefCnt.h" |
| 25 #include "SkMatrix44.h" |
| 25 | 26 |
| 26 struct SkFloat3 { | 27 struct SkFloat3 { |
| 27 float fVec[3]; | 28 float fVec[3]; |
| 28 | 29 |
| 29 void dump() const; | 30 void dump() const; |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 struct SkFloat3x3 { | |
| 33 float fMat[9]; | |
| 34 | |
| 35 void dump() const; | |
| 36 }; | |
| 37 | |
| 38 class SkColorSpace : public SkRefCnt { | 33 class SkColorSpace : public SkRefCnt { |
| 39 private: | 34 private: |
| 40 struct SkGammaCurve { | 35 struct SkGammaCurve { |
| 41 bool isValue() const { | 36 bool isValue() const { |
| 42 bool result = (0.0f != fValue); | 37 bool result = (0.0f != fValue); |
| 43 SkASSERT(!result || (0 == fTableSize)); | 38 SkASSERT(!result || (0 == fTableSize)); |
| 44 return result; | 39 return result; |
| 45 } | 40 } |
| 46 | 41 |
| 47 bool isTable() const { | 42 bool isTable() const { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 105 |
| 111 private: | 106 private: |
| 112 SkGammaCurve fRed; | 107 SkGammaCurve fRed; |
| 113 SkGammaCurve fGreen; | 108 SkGammaCurve fGreen; |
| 114 SkGammaCurve fBlue; | 109 SkGammaCurve fBlue; |
| 115 | 110 |
| 116 friend class SkColorSpace; | 111 friend class SkColorSpace; |
| 117 }; | 112 }; |
| 118 | 113 |
| 119 /** | 114 /** |
| 120 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D
50_XYZ | 115 * Return a colorspace instance, given a transform from linear_RGB to D50_X
YZ |
| 121 * and the src-gamma, return a ColorSpace | 116 * and the src-gamma, return a ColorSpace |
| 122 */ | 117 */ |
| 123 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gamma
s); | 118 static sk_sp<SkColorSpace> NewRGB(const SkMatrix44& toXYZD50, SkGammas gamma
s); |
| 124 | 119 |
| 125 static sk_sp<SkColorSpace> NewNamed(Named); | 120 static sk_sp<SkColorSpace> NewNamed(Named); |
| 126 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 121 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| 127 | 122 |
| 128 const SkGammas& gammas() const { return fGammas; } | 123 const SkGammas& gammas() const { return fGammas; } |
| 129 SkFloat3x3 xyz() const { return fToXYZD50; } | 124 SkMatrix44 xyz() const { return fToXYZD50; } |
| 130 SkFloat3 xyzOffset() const { return fToXYZOffset; } | |
| 131 Named named() const { return fNamed; } | 125 Named named() const { return fNamed; } |
| 132 uint32_t uniqueID() const { return fUniqueID; } | 126 uint32_t uniqueID() const { return fUniqueID; } |
| 133 | 127 |
| 134 private: | 128 private: |
| 135 | 129 |
| 136 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr
c, size_t len); | 130 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr
c, size_t len); |
| 137 | 131 |
| 138 | 132 |
| 139 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel
s, | 133 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel
s, |
| 140 uint32_t outputChannels, const uint8_t* src, size_t
len); | 134 uint32_t outputChannels, const uint8_t* src, size_t
len); |
| 141 | 135 |
| 142 | 136 |
| 143 static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat
3x3* toXYZ, | 137 static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkMatri
x44* toXYZ, |
| 144 SkFloat3* toXYZOffset, const uint8_t* src, size_t len); | 138 const uint8_t* src, size_t len); |
| 145 | 139 |
| 146 SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); | 140 SkColorSpace(SkGammas gammas, const SkMatrix44& toXYZ, Named); |
| 147 | 141 |
| 148 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, | 142 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, |
| 149 const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset); | 143 const SkMatrix44& toXYZ); |
| 150 | 144 |
| 151 const SkColorLookUpTable fColorLUT; | 145 const SkColorLookUpTable fColorLUT; |
| 152 const SkGammas fGammas; | 146 const SkGammas fGammas; |
| 153 const SkFloat3x3 fToXYZD50; | 147 const SkMatrix44 fToXYZD50; |
| 154 const SkFloat3 fToXYZOffset; | |
| 155 | 148 |
| 156 const uint32_t fUniqueID; | 149 const uint32_t fUniqueID; |
| 157 const Named fNamed; | 150 const Named fNamed; |
| 158 }; | 151 }; |
| 159 | 152 |
| 160 #endif | 153 #endif |
| OLD | NEW |