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 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 void dump() const; | 29 void dump() const; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 struct SkFloat3x3 { | 32 struct SkFloat3x3 { |
| 33 float fMat[9]; | 33 float fMat[9]; |
| 34 | 34 |
| 35 void dump() const; | 35 void dump() const; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 struct SkColorLookUpTable { | 38 class SkColorSpace : public SkRefCnt { |
| 39 static const uint8_t kMaxChannels = 16; | 39 private: |
| 40 struct SkGammaCurve { | |
|
msarett
2016/04/29 14:07:08
Strange to have the private structs first, but I n
scroggo
2016/04/29 14:17:23
Would forward declaring them fix this?
msarett
2016/04/29 14:44:12
Unfortunately no, that doesn't work.
| |
| 41 bool isValue() const { return 0.0f != fValue; } | |
| 42 bool isTable() const { return 0 != fTableSize; } | |
|
scroggo
2016/04/29 14:17:23
It seems this does not do anything to protect from
msarett
2016/04/29 14:44:12
Good point. Now that this is private, that could
| |
| 43 bool isParametric() const { return false; } | |
| 40 | 44 |
| 41 uint8_t fInputChannels; | 45 // We have three different ways to represent gamma. |
| 42 uint8_t fOutputChannels; | 46 // (1) A single value: |
| 43 uint8_t fGridPoints[kMaxChannels]; | 47 float fValue; |
| 44 std::unique_ptr<float[]> fTable; | |
| 45 | 48 |
| 46 SkColorLookUpTable() { | 49 // (2) A lookup table: |
| 47 memset(this, 0, sizeof(struct SkColorLookUpTable)); | 50 uint32_t fTableSize; |
| 48 } | 51 std::unique_ptr<float[]> fTable; |
| 49 | 52 |
| 50 SkColorLookUpTable(SkColorLookUpTable&& that) | 53 // (3) Parameters for a curve: |
| 51 : fInputChannels(that.fInputChannels) | 54 // FIXME (msarett): Handle parametric curves. |
| 52 , fOutputChannels(that.fOutputChannels) | |
| 53 , fTable(std::move(that.fTable)) | |
| 54 { | |
| 55 memcpy(fGridPoints, that.fGridPoints, kMaxChannels); | |
| 56 } | |
| 57 }; | |
| 58 | 55 |
| 59 class SkColorSpace : public SkRefCnt { | 56 SkGammaCurve() { |
| 57 memset(this, 0, sizeof(struct SkGammaCurve)); | |
| 58 } | |
| 59 | |
| 60 SkGammaCurve(float value) | |
| 61 : fValue(value) | |
| 62 , fTableSize(0) | |
| 63 , fTable(nullptr) | |
| 64 {} | |
| 65 }; | |
| 66 | |
| 67 struct SkColorLookUpTable { | |
| 68 static const uint8_t kMaxChannels = 16; | |
| 69 | |
| 70 uint8_t fInputChannels; | |
| 71 uint8_t fOutputChannels; | |
| 72 uint8_t fGridPoints[kMaxChannels]; | |
| 73 std::unique_ptr<float[]> fTable; | |
| 74 | |
| 75 SkColorLookUpTable() { | |
| 76 memset(this, 0, sizeof(struct SkColorLookUpTable)); | |
| 77 } | |
| 78 }; | |
| 79 | |
| 60 public: | 80 public: |
| 61 enum Named { | 81 enum Named { |
| 62 kUnknown_Named, | 82 kUnknown_Named, |
| 63 kSRGB_Named, | 83 kSRGB_Named, |
| 64 }; | 84 }; |
| 65 | 85 |
| 86 struct SkGammas { | |
| 87 public: | |
| 88 SkGammas(float red, float green, float blue) | |
| 89 : fRed(red) | |
| 90 , fGreen(green) | |
| 91 , fBlue(blue) | |
| 92 {} | |
| 93 | |
| 94 SkGammas() {} | |
| 95 | |
| 96 float red() const { return fRed.fValue; } | |
|
msarett
2016/04/29 14:07:08
May not even need to expose these, but they are us
scroggo
2016/04/29 14:17:23
SkDEBUGCODE?
msarett
2016/04/29 14:44:12
Good idea!
| |
| 97 float green() const { return fGreen.fValue; } | |
|
scroggo
2016/04/29 14:17:23
Is it okay to return fValue if !isValue()?
msarett
2016/04/29 14:44:12
In that case, we return 0.0f. This is a bit weird
| |
| 98 float blue() const { return fBlue.fValue; } | |
| 99 | |
| 100 private: | |
| 101 SkGammaCurve fRed; | |
| 102 SkGammaCurve fGreen; | |
| 103 SkGammaCurve fBlue; | |
| 104 | |
| 105 friend class SkColorSpace; | |
| 106 }; | |
| 107 | |
| 66 /** | 108 /** |
| 67 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D 50_XYZ | 109 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D 50_XYZ |
| 68 * and the src-gamma, return a ColorSpace | 110 * and the src-gamma, return a ColorSpace |
| 69 */ | 111 */ |
| 70 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3 & gamma); | 112 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gamma s); |
| 71 | 113 |
| 72 static sk_sp<SkColorSpace> NewNamed(Named); | 114 static sk_sp<SkColorSpace> NewNamed(Named); |
| 73 static sk_sp<SkColorSpace> NewICC(const void*, size_t); | 115 static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| 74 | 116 |
| 75 SkFloat3 gamma() const { return fGamma; } | 117 const SkGammas& gammas() const { return fGammas; } |
| 76 SkFloat3x3 xyz() const { return fToXYZD50; } | 118 SkFloat3x3 xyz() const { return fToXYZD50; } |
| 77 SkFloat3 xyzOffset() const { return fToXYZOffset; } | 119 SkFloat3 xyzOffset() const { return fToXYZOffset; } |
| 78 Named named() const { return fNamed; } | 120 Named named() const { return fNamed; } |
| 79 uint32_t uniqueID() const { return fUniqueID; } | 121 uint32_t uniqueID() const { return fUniqueID; } |
| 80 | 122 |
| 81 private: | 123 private: |
| 82 SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named); | |
| 83 | 124 |
| 84 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFlo at3x3& toXYZ, | 125 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr c, size_t len); |
| 85 const SkFloat3& toXYZOffset); | 126 |
| 127 | |
| 128 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel s, | |
| 129 uint32_t outputChannels, const uint8_t* src, size_t len); | |
| 130 | |
| 131 | |
| 132 static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat 3x3* toXYZ, | |
| 133 SkFloat3* toXYZOffset, const uint8_t* src, size_t len); | |
| 134 | |
| 135 SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); | |
| 136 | |
| 137 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, | |
| 138 const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset); | |
| 86 | 139 |
| 87 const SkColorLookUpTable fColorLUT; | 140 const SkColorLookUpTable fColorLUT; |
| 88 const SkFloat3 fGamma; | 141 const SkGammas fGammas; |
| 89 const SkFloat3x3 fToXYZD50; | 142 const SkFloat3x3 fToXYZD50; |
| 90 const SkFloat3 fToXYZOffset; | 143 const SkFloat3 fToXYZOffset; |
| 91 | 144 |
| 92 const uint32_t fUniqueID; | 145 const uint32_t fUniqueID; |
| 93 const Named fNamed; | 146 const Named fNamed; |
| 94 }; | 147 }; |
| 95 | 148 |
| 96 #endif | 149 #endif |
| OLD | NEW |