Chromium Code Reviews| 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 "SkTArray.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 struct SkFloat3x3 { |
| 33 float fMat[9]; | 34 float fMat[9]; |
| 34 | 35 |
| 35 void dump() const; | 36 void dump() const; |
| 36 }; | 37 }; |
| 37 | 38 |
| 39 struct SkGammaCurve { | |
| 40 bool isValue() const { return 0.0f != fValue; } | |
| 41 bool isTable() const { return 0 != fTableSize; } | |
| 42 bool isParametric() const { return false; } | |
| 43 | |
| 44 // We have three different ways to represent gamma. | |
| 45 // (1) A single value: | |
| 46 float fValue; | |
| 47 | |
| 48 // (2) A lookup table: | |
| 49 uint32_t fTableSize; | |
| 50 std::unique_ptr<float[]> fTable; | |
| 51 | |
| 52 // (3) Parameters for a curve: | |
| 53 // FIXME (msarett): Handle parametric curves. | |
| 54 | |
| 55 SkGammaCurve() { | |
| 56 memset(this, 0, sizeof(struct SkGammaCurve)); | |
| 57 } | |
| 58 | |
| 59 SkGammaCurve(float value) | |
| 60 : fValue(value) | |
| 61 , fTableSize(0) | |
| 62 , fTable(nullptr) | |
| 63 {} | |
| 64 }; | |
| 65 | |
| 66 struct SkGammas { | |
| 67 SkGammaCurve fRed; | |
| 68 SkGammaCurve fGreen; | |
| 69 SkGammaCurve fBlue; | |
| 70 }; | |
| 71 | |
| 38 struct SkColorLookUpTable { | 72 struct SkColorLookUpTable { |
| 39 static const uint8_t kMaxChannels = 16; | 73 static const uint8_t kMaxChannels = 16; |
| 40 | 74 |
| 41 uint8_t fInputChannels; | 75 uint8_t fInputChannels; |
| 42 uint8_t fOutputChannels; | 76 uint8_t fOutputChannels; |
| 43 uint8_t fGridPoints[kMaxChannels]; | 77 uint8_t fGridPoints[kMaxChannels]; |
| 44 std::unique_ptr<float[]> fTable; | 78 std::unique_ptr<float[]> fTable; |
| 45 | 79 |
| 46 SkColorLookUpTable() { | 80 SkColorLookUpTable() { |
| 47 memset(this, 0, sizeof(struct SkColorLookUpTable)); | 81 memset(this, 0, sizeof(struct SkColorLookUpTable)); |
| 48 } | 82 } |
| 49 | |
| 50 SkColorLookUpTable(SkColorLookUpTable&& that) | |
|
msarett
2016/04/28 21:26:48
Now that we are on VS 2015, I think that this is n
| |
| 51 : fInputChannels(that.fInputChannels) | |
| 52 , fOutputChannels(that.fOutputChannels) | |
| 53 , fTable(std::move(that.fTable)) | |
| 54 { | |
| 55 memcpy(fGridPoints, that.fGridPoints, kMaxChannels); | |
| 56 } | |
| 57 }; | 83 }; |
| 58 | 84 |
| 59 class SkColorSpace : public SkRefCnt { | 85 class SkColorSpace : public SkRefCnt { |
| 60 public: | 86 public: |
| 61 enum Named { | 87 enum Named { |
| 62 kUnknown_Named, | 88 kUnknown_Named, |
| 63 kSRGB_Named, | 89 kSRGB_Named, |
| 64 }; | 90 }; |
| 65 | 91 |
| 66 /** | 92 /** |
| 67 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D 50_XYZ | 93 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D 50_XYZ |
| 68 * and the src-gamma, return a ColorSpace | 94 * and the src-gamma, return a ColorSpace |
| 69 */ | 95 */ |
| 70 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3 & gamma); | 96 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gamma s); |
| 71 | 97 |
| 72 static sk_sp<SkColorSpace> NewNamed(Named); | 98 static sk_sp<SkColorSpace> NewNamed(Named); |
| 73 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 99 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| 74 | 100 |
| 75 SkFloat3 gamma() const { return fGamma; } | 101 const SkGammas& gammas() const { return fGammas; } |
| 76 SkFloat3x3 xyz() const { return fToXYZD50; } | 102 SkFloat3x3 xyz() const { return fToXYZD50; } |
| 77 SkFloat3 xyzOffset() const { return fToXYZOffset; } | 103 SkFloat3 xyzOffset() const { return fToXYZOffset; } |
| 78 Named named() const { return fNamed; } | 104 Named named() const { return fNamed; } |
| 79 uint32_t uniqueID() const { return fUniqueID; } | 105 uint32_t uniqueID() const { return fUniqueID; } |
| 80 | 106 |
| 81 private: | 107 private: |
| 82 SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named); | 108 SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); |
| 83 | 109 |
| 84 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFlo at3x3& toXYZ, | 110 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, |
| 85 const SkFloat3& toXYZOffset); | 111 const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset); |
| 86 | 112 |
| 87 const SkColorLookUpTable fColorLUT; | 113 const SkColorLookUpTable fColorLUT; |
| 88 const SkFloat3 fGamma; | 114 const SkGammas fGammas; |
| 89 const SkFloat3x3 fToXYZD50; | 115 const SkFloat3x3 fToXYZD50; |
| 90 const SkFloat3 fToXYZOffset; | 116 const SkFloat3 fToXYZOffset; |
| 91 | 117 |
| 92 const uint32_t fUniqueID; | 118 const uint32_t fUniqueID; |
| 93 const Named fNamed; | 119 const Named fNamed; |
| 94 }; | 120 }; |
| 95 | 121 |
| 96 #endif | 122 #endif |
| OLD | NEW |