| 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 struct SkColorLookUpTable { | 33 struct SkColorLookUpTable { |
| 39 static const uint8_t kMaxChannels = 16; | 34 static const uint8_t kMaxChannels = 16; |
| 40 | 35 |
| 41 uint8_t fInputChannels; | 36 uint8_t fInputChannels; |
| 42 uint8_t fOutputChannels; | 37 uint8_t fOutputChannels; |
| 43 uint8_t fGridPoints[kMaxChannels]; | 38 uint8_t fGridPoints[kMaxChannels]; |
| 44 std::unique_ptr<float[]> fTable; | 39 std::unique_ptr<float[]> fTable; |
| 45 | 40 |
| 46 SkColorLookUpTable() { | 41 SkColorLookUpTable() { |
| 47 memset(this, 0, sizeof(struct SkColorLookUpTable)); | 42 memset(this, 0, sizeof(struct SkColorLookUpTable)); |
| 48 } | 43 } |
| 49 | 44 |
| 50 SkColorLookUpTable(SkColorLookUpTable&& that) | 45 SkColorLookUpTable(SkColorLookUpTable&& that) |
| 51 : fInputChannels(that.fInputChannels) | 46 : fInputChannels(that.fInputChannels) |
| 52 , fOutputChannels(that.fOutputChannels) | 47 , fOutputChannels(that.fOutputChannels) |
| 53 , fTable(std::move(that.fTable)) | 48 , fTable(std::move(that.fTable)) |
| 54 { | 49 { |
| 55 memcpy(fGridPoints, that.fGridPoints, kMaxChannels); | 50 memcpy(fGridPoints, that.fGridPoints, kMaxChannels); |
| 56 } | 51 } |
| 57 }; | 52 }; |
| 58 | 53 |
| 59 class SkColorSpace : public SkRefCnt { | 54 class SkColorSpace : public SkRefCnt { |
| 60 public: | 55 public: |
| 61 enum Named { | 56 enum Named { |
| 62 kUnknown_Named, | 57 kUnknown_Named, |
| 63 kSRGB_Named, | 58 kSRGB_Named, |
| 64 }; | 59 }; |
| 65 | 60 |
| 66 /** | 61 /** |
| 67 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D
50_XYZ | 62 * Return a colorspace instance, given a transform from linear_RGB to D50_X
YZ |
| 68 * and the src-gamma, return a ColorSpace | 63 * and the src-gamma, return a ColorSpace |
| 69 */ | 64 */ |
| 70 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3
& gamma); | 65 static sk_sp<SkColorSpace> NewRGB(const SkMatrix44& toXYZD50, const SkFloat3
& gamma); |
| 71 | 66 |
| 72 static sk_sp<SkColorSpace> NewNamed(Named); | 67 static sk_sp<SkColorSpace> NewNamed(Named); |
| 73 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 68 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| 74 | 69 |
| 75 SkFloat3 gamma() const { return fGamma; } | 70 SkFloat3 gamma() const { return fGamma; } |
| 76 SkFloat3x3 xyz() const { return fToXYZD50; } | 71 SkMatrix44 xyz() const { return fToXYZD50; } |
| 77 SkFloat3 xyzOffset() const { return fToXYZOffset; } | |
| 78 Named named() const { return fNamed; } | 72 Named named() const { return fNamed; } |
| 79 uint32_t uniqueID() const { return fUniqueID; } | 73 uint32_t uniqueID() const { return fUniqueID; } |
| 80 | 74 |
| 81 private: | 75 private: |
| 82 SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named); | 76 SkColorSpace(const SkFloat3& gamma, const SkMatrix44& toXYZ, Named); |
| 83 | 77 |
| 84 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFlo
at3x3& toXYZ, | 78 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkMat
rix44& toXYZ); |
| 85 const SkFloat3& toXYZOffset); | |
| 86 | 79 |
| 87 const SkColorLookUpTable fColorLUT; | 80 const SkColorLookUpTable fColorLUT; |
| 88 const SkFloat3 fGamma; | 81 const SkFloat3 fGamma; |
| 89 const SkFloat3x3 fToXYZD50; | 82 const SkMatrix44 fToXYZD50; |
| 90 const SkFloat3 fToXYZOffset; | |
| 91 | 83 |
| 92 const uint32_t fUniqueID; | 84 const uint32_t fUniqueID; |
| 93 const Named fNamed; | 85 const Named fNamed; |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 #endif | 88 #endif |
| OLD | NEW |