Chromium Code Reviews| Index: src/core/SkColorSpace.h |
| diff --git a/src/core/SkColorSpace.h b/src/core/SkColorSpace.h |
| index 2b3b15fe95576c33f5def8e4a341c5797a9bac30..65779736f036d28aecd988de5b383b7c344b6757 100644 |
| --- a/src/core/SkColorSpace.h |
| +++ b/src/core/SkColorSpace.h |
| @@ -35,57 +35,110 @@ struct SkFloat3x3 { |
| void dump() const; |
| }; |
| -struct SkColorLookUpTable { |
| - static const uint8_t kMaxChannels = 16; |
| - |
| - uint8_t fInputChannels; |
| - uint8_t fOutputChannels; |
| - uint8_t fGridPoints[kMaxChannels]; |
| - std::unique_ptr<float[]> fTable; |
| - |
| - SkColorLookUpTable() { |
| - memset(this, 0, sizeof(struct SkColorLookUpTable)); |
| - } |
| - |
| - SkColorLookUpTable(SkColorLookUpTable&& that) |
| - : fInputChannels(that.fInputChannels) |
| - , fOutputChannels(that.fOutputChannels) |
| - , fTable(std::move(that.fTable)) |
| - { |
| - memcpy(fGridPoints, that.fGridPoints, kMaxChannels); |
| - } |
| -}; |
| - |
| class SkColorSpace : public SkRefCnt { |
| +private: |
| + 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.
|
| + bool isValue() const { return 0.0f != fValue; } |
| + 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
|
| + bool isParametric() const { return false; } |
| + |
| + // We have three different ways to represent gamma. |
| + // (1) A single value: |
| + float fValue; |
| + |
| + // (2) A lookup table: |
| + uint32_t fTableSize; |
| + std::unique_ptr<float[]> fTable; |
| + |
| + // (3) Parameters for a curve: |
| + // FIXME (msarett): Handle parametric curves. |
| + |
| + SkGammaCurve() { |
| + memset(this, 0, sizeof(struct SkGammaCurve)); |
| + } |
| + |
| + SkGammaCurve(float value) |
| + : fValue(value) |
| + , fTableSize(0) |
| + , fTable(nullptr) |
| + {} |
| + }; |
| + |
| + struct SkColorLookUpTable { |
| + static const uint8_t kMaxChannels = 16; |
| + |
| + uint8_t fInputChannels; |
| + uint8_t fOutputChannels; |
| + uint8_t fGridPoints[kMaxChannels]; |
| + std::unique_ptr<float[]> fTable; |
| + |
| + SkColorLookUpTable() { |
| + memset(this, 0, sizeof(struct SkColorLookUpTable)); |
| + } |
| + }; |
| + |
| public: |
| enum Named { |
| kUnknown_Named, |
| kSRGB_Named, |
| }; |
| + struct SkGammas { |
| + public: |
| + SkGammas(float red, float green, float blue) |
| + : fRed(red) |
| + , fGreen(green) |
| + , fBlue(blue) |
| + {} |
| + |
| + SkGammas() {} |
| + |
| + 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!
|
| + 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
|
| + float blue() const { return fBlue.fValue; } |
| + |
| + private: |
| + SkGammaCurve fRed; |
| + SkGammaCurve fGreen; |
| + SkGammaCurve fBlue; |
| + |
| + friend class SkColorSpace; |
| + }; |
| + |
| /** |
| * Return a colorspace instance, given a 3x3 transform from linear_RGB to D50_XYZ |
| * and the src-gamma, return a ColorSpace |
| */ |
| - static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3& gamma); |
| + static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gammas); |
| static sk_sp<SkColorSpace> NewNamed(Named); |
| static sk_sp<SkColorSpace> NewICC(const void*, size_t); |
| - SkFloat3 gamma() const { return fGamma; } |
| + const SkGammas& gammas() const { return fGammas; } |
| SkFloat3x3 xyz() const { return fToXYZD50; } |
| SkFloat3 xyzOffset() const { return fToXYZOffset; } |
| Named named() const { return fNamed; } |
| uint32_t uniqueID() const { return fUniqueID; } |
| private: |
| - SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named); |
| - SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFloat3x3& toXYZ, |
| - const SkFloat3& toXYZOffset); |
| + static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* src, size_t len); |
| + |
| + |
| + static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannels, |
| + uint32_t outputChannels, const uint8_t* src, size_t len); |
| + |
| + |
| + static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat3x3* toXYZ, |
| + SkFloat3* toXYZOffset, const uint8_t* src, size_t len); |
| + |
| + SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); |
| + |
| + SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, |
| + const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset); |
| const SkColorLookUpTable fColorLUT; |
| - const SkFloat3 fGamma; |
| + const SkGammas fGammas; |
| const SkFloat3x3 fToXYZD50; |
| const SkFloat3 fToXYZOffset; |