Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: src/core/SkColorSpace.h

Issue 1928123002: Introduce SkGammas type to represent ICC gamma curves (Closed) Base URL: https://skia.googlesource.com/skia.git@delcolorspace
Patch Set: Fix Mac clang again Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkPngCodec.cpp ('k') | src/core/SkColorSpace.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 {
41 bool isValue() const {
42 bool result = (0.0f != fValue);
43 SkASSERT(!result || (0 == fTableSize));
44 return result;
45 }
40 46
41 uint8_t fInputChannels; 47 bool isTable() const {
42 uint8_t fOutputChannels; 48 bool result = (0 != fTableSize);
43 uint8_t fGridPoints[kMaxChannels]; 49 SkASSERT(!result || (0.0f == fValue));
44 std::unique_ptr<float[]> fTable; 50 SkASSERT(!result || fTable);
51 return result;
52 }
45 53
46 SkColorLookUpTable() { 54 bool isParametric() const { return false; }
47 memset(this, 0, sizeof(struct SkColorLookUpTable));
48 }
49 55
50 SkColorLookUpTable(SkColorLookUpTable&& that) 56 // We have three different ways to represent gamma.
51 : fInputChannels(that.fInputChannels) 57 // (1) A single value:
52 , fOutputChannels(that.fOutputChannels) 58 float fValue;
53 , fTable(std::move(that.fTable))
54 {
55 memcpy(fGridPoints, that.fGridPoints, kMaxChannels);
56 }
57 };
58 59
59 class SkColorSpace : public SkRefCnt { 60 // (2) A lookup table:
61 uint32_t fTableSize;
62 std::unique_ptr<float[]> fTable;
63
64 // (3) Parameters for a curve:
65 // FIXME (msarett): Handle parametric curves.
66
67 SkGammaCurve() {
68 memset(this, 0, sizeof(struct SkGammaCurve));
69 }
70
71 SkGammaCurve(float value)
72 : fValue(value)
73 , fTableSize(0)
74 , fTable(nullptr)
75 {}
76 };
77
78 struct SkColorLookUpTable {
79 static const uint8_t kMaxChannels = 16;
80
81 uint8_t fInputChannels;
82 uint8_t fOutputChannels;
83 uint8_t fGridPoints[kMaxChannels];
84 std::unique_ptr<float[]> fTable;
85
86 SkColorLookUpTable() {
87 memset(this, 0, sizeof(struct SkColorLookUpTable));
88 }
89 };
90
60 public: 91 public:
61 enum Named { 92 enum Named {
62 kUnknown_Named, 93 kUnknown_Named,
63 kSRGB_Named, 94 kSRGB_Named,
64 }; 95 };
65 96
97 struct SkGammas {
98 public:
99 SkGammas(float red, float green, float blue)
100 : fRed(red)
101 , fGreen(green)
102 , fBlue(blue)
103 {}
104
105 SkGammas() {}
106
107 SkDEBUGCODE(float red() const { return fRed.fValue; })
108 SkDEBUGCODE(float green() const { return fGreen.fValue; })
109 SkDEBUGCODE(float blue() const { return fBlue.fValue; })
110
111 private:
112 SkGammaCurve fRed;
113 SkGammaCurve fGreen;
114 SkGammaCurve fBlue;
115
116 friend class SkColorSpace;
117 };
118
66 /** 119 /**
67 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D 50_XYZ 120 * Return a colorspace instance, given a 3x3 transform from linear_RGB to D 50_XYZ
68 * and the src-gamma, return a ColorSpace 121 * and the src-gamma, return a ColorSpace
69 */ 122 */
70 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3 & gamma); 123 static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gamma s);
71 124
72 static sk_sp<SkColorSpace> NewNamed(Named); 125 static sk_sp<SkColorSpace> NewNamed(Named);
73 static sk_sp<SkColorSpace> NewICC(const void*, size_t); 126 static sk_sp<SkColorSpace> NewICC(const void*, size_t);
74 127
75 SkFloat3 gamma() const { return fGamma; } 128 const SkGammas& gammas() const { return fGammas; }
76 SkFloat3x3 xyz() const { return fToXYZD50; } 129 SkFloat3x3 xyz() const { return fToXYZD50; }
77 SkFloat3 xyzOffset() const { return fToXYZOffset; } 130 SkFloat3 xyzOffset() const { return fToXYZOffset; }
78 Named named() const { return fNamed; } 131 Named named() const { return fNamed; }
79 uint32_t uniqueID() const { return fUniqueID; } 132 uint32_t uniqueID() const { return fUniqueID; }
80 133
81 private: 134 private:
82 SkColorSpace(const SkFloat3& gamma, const SkFloat3x3& toXYZ, Named);
83 135
84 SkColorSpace(SkColorLookUpTable colorLUT, const SkFloat3& gamma, const SkFlo at3x3& toXYZ, 136 static bool LoadGammas(SkGammaCurve* gammas, uint32_t num, const uint8_t* sr c, size_t len);
85 const SkFloat3& toXYZOffset); 137
138
139 static bool LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChannel s,
140 uint32_t outputChannels, const uint8_t* src, size_t len);
141
142
143 static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat 3x3* toXYZ,
144 SkFloat3* toXYZOffset, const uint8_t* src, size_t len);
145
146 SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named);
147
148 SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas,
149 const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset);
86 150
87 const SkColorLookUpTable fColorLUT; 151 const SkColorLookUpTable fColorLUT;
88 const SkFloat3 fGamma; 152 const SkGammas fGammas;
89 const SkFloat3x3 fToXYZD50; 153 const SkFloat3x3 fToXYZD50;
90 const SkFloat3 fToXYZOffset; 154 const SkFloat3 fToXYZOffset;
91 155
92 const uint32_t fUniqueID; 156 const uint32_t fUniqueID;
93 const Named fNamed; 157 const Named fNamed;
94 }; 158 };
95 159
96 #endif 160 #endif
OLDNEW
« no previous file with comments | « src/codec/SkPngCodec.cpp ('k') | src/core/SkColorSpace.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698