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

Side by Side Diff: include/core/SkImageInfo.h

Issue 514753002: add gamma/sRGB to SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | src/core/SkImageInfo.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 2013 Google Inc. 2 * Copyright 2013 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 SkImageInfo_DEFINED 8 #ifndef SkImageInfo_DEFINED
9 #define SkImageInfo_DEFINED 9 #define SkImageInfo_DEFINED
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 */ 129 */
130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, 130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
131 SkAlphaType* canonical = NULL); 131 SkAlphaType* canonical = NULL);
132 132
133 /////////////////////////////////////////////////////////////////////////////// 133 ///////////////////////////////////////////////////////////////////////////////
134 134
135 /** 135 /**
136 * Describe an image's dimensions and pixel type. 136 * Describe an image's dimensions and pixel type.
137 */ 137 */
138 struct SkImageInfo { 138 struct SkImageInfo {
139 public:
140 SkImageInfo() {}
141
139 int fWidth; 142 int fWidth;
140 int fHeight; 143 int fHeight;
141 SkColorType fColorType; 144 SkColorType fColorType;
142 SkAlphaType fAlphaType; 145 SkAlphaType fAlphaType;
143 146
147 private:
148 enum Profile {
149 kUnknown_Profile,
150 kSRGB_Profile,
151 kExponential_Profile,
152 };
153
154 uint32_t fProfile;
155 float fGamma;
156
157 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, Profile p , float g)
158 : fWidth(width)
159 , fHeight(height)
160 , fColorType(ct)
161 , fAlphaType(at)
162 , fProfile(p)
163 , fGamma(g)
164 {}
165
166 public:
167 /*
168 * Return an info with the specified attributes, tagged as sRGB. Note that if the requested
169 * color type does not make sense with sRGB (e.g. kAlpha_8) then the sRGB r equest is ignored.
170 *
171 * You can call isSRGB() on the returned info to determine if the request w as fulfilled.
172 */
173 static SkImageInfo MakeSRGB(int width, int height, SkColorType ct, SkAlphaTy pe at);
174
175 /*
176 * Return an info with the specified attributes, tagged with a specific gam ma.
177 * Not that if the requested gamma is unsupported for the requested color t ype, then the gamma
bungeman-skia 2014/08/27 19:48:24 Not[e]
178 * value will be set to 1.0 (the default).
179 *
180 * You can call gamma() to query the resulting gamma value.
181 */
182 static SkImageInfo MakeWithGamma(int width, int height, SkColorType ct, SkAl phaType at,
183 float gamma);
184
144 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a t) { 185 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a t) {
145 SkImageInfo info = { 186 return MakeWithGamma(width, height, ct, at, 1);
146 width, height, ct, at
147 };
148 return info;
149 } 187 }
150 188
151 /** 189 /**
152 * Sets colortype to the native ARGB32 type. 190 * Sets colortype to the native ARGB32 type.
153 */ 191 */
154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { 192 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
155 SkImageInfo info = { 193 return SkImageInfo(width, height, kN32_SkColorType, at, kExponential_Pro file, 1);
156 width, height, kN32_SkColorType, at
157 };
158 return info;
159 } 194 }
160 195
161 /** 196 /**
162 * Sets colortype to the native ARGB32 type, and the alphatype to premul. 197 * Sets colortype to the native ARGB32 type, and the alphatype to premul.
163 */ 198 */
164 static SkImageInfo MakeN32Premul(int width, int height) { 199 static SkImageInfo MakeN32Premul(int width, int height) {
165 SkImageInfo info = { 200 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType,
166 width, height, kN32_SkColorType, kPremul_SkAlphaType 201 kExponential_Profile, 1);
167 };
168 return info;
169 } 202 }
170 203
171 /** 204 /**
172 * Sets colortype to the native ARGB32 type, and the alphatype to premul. 205 * Sets colortype to the native ARGB32 type, and the alphatype to premul.
173 */ 206 */
174 static SkImageInfo MakeN32Premul(const SkISize& size) { 207 static SkImageInfo MakeN32Premul(const SkISize& size) {
175 return MakeN32Premul(size.width(), size.height()); 208 return MakeN32Premul(size.width(), size.height());
176 } 209 }
177 210
178 static SkImageInfo MakeA8(int width, int height) { 211 static SkImageInfo MakeA8(int width, int height) {
179 SkImageInfo info = { 212 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT ype,
180 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType 213 kUnknown_Profile, 0);
181 };
182 return info;
183 } 214 }
184 215
185 static SkImageInfo MakeUnknown(int width, int height) { 216 static SkImageInfo MakeUnknown(int width, int height) {
186 SkImageInfo info = { 217 return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaT ype,
187 width, height, kUnknown_SkColorType, kIgnore_SkAlphaType 218 kUnknown_Profile, 0);
188 };
189 return info;
190 } 219 }
191 220
192 static SkImageInfo MakeUnknown() { 221 static SkImageInfo MakeUnknown() {
193 SkImageInfo info = { 222 return SkImageInfo(0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType, kUnk nown_Profile, 0);
194 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType
195 };
196 return info;
197 } 223 }
198 224
199 int width() const { return fWidth; } 225 int width() const { return fWidth; }
200 int height() const { return fHeight; } 226 int height() const { return fHeight; }
201 SkColorType colorType() const { return fColorType; } 227 SkColorType colorType() const { return fColorType; }
202 SkAlphaType alphaType() const { return fAlphaType; } 228 SkAlphaType alphaType() const { return fAlphaType; }
203 229
204 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } 230 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
205 231
206 bool isOpaque() const { 232 bool isOpaque() const {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 size_t getSafeSize(size_t rowBytes) const { 275 size_t getSafeSize(size_t rowBytes) const {
250 return (size_t)this->getSafeSize64(rowBytes); 276 return (size_t)this->getSafeSize64(rowBytes);
251 } 277 }
252 278
253 bool validRowBytes(size_t rowBytes) const { 279 bool validRowBytes(size_t rowBytes) const {
254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); 280 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
255 return rowBytes >= rb; 281 return rowBytes >= rb;
256 } 282 }
257 283
258 SkDEBUGCODE(void validate() const;) 284 SkDEBUGCODE(void validate() const;)
285
286 /**
287 * If the Info was tagged to be sRGB, return true, else return false.
288 */
289 bool isSRGB() const { return kSRGB_Profile == fProfile; }
290
291 /**
292 * If this was tagged with an explicit gamma value, return that value, else return 0.
293 * If this was tagged as sRGB, return 0.
294 */
295 float gamma() const { return fGamma; }
259 }; 296 };
260 297
261 #endif 298 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkImageInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698