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

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

Issue 525113005: Revert of Add gamma/sRGB tag 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 | « gyp/tests.gypi ('k') | 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 * alphaType for this colorType, return it in canonical. 128 * alphaType for this colorType, return it in canonical.
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 SK_API SkImageInfo { 138 struct SkImageInfo {
139 public:
140 SkImageInfo() {}
141
142 int fWidth; 139 int fWidth;
143 int fHeight; 140 int fHeight;
144 SkColorType fColorType; 141 SkColorType fColorType;
145 SkAlphaType fAlphaType; 142 SkAlphaType fAlphaType;
146 143
147 /*
148 * Return an info with the specified attributes, tagged as sRGB. Note that if the requested
149 * color type does not make sense with sRGB (e.g. kAlpha_8) then the sRGB r equest is ignored.
150 *
151 * You can call isSRGB() on the returned info to determine if the request w as fulfilled.
152 */
153 static SkImageInfo MakeSRGB(int width, int height, SkColorType ct, SkAlphaTy pe at);
154
155 /*
156 * Return an info with the specified attributes, tagged with a specific gam ma.
157 * Note that if the requested gamma is unsupported for the requested color type, then the gamma
158 * value will be set to 1.0 (the default).
159 *
160 * You can call gamma() to query the resulting gamma value.
161 */
162 static SkImageInfo MakeWithGamma(int width, int height, SkColorType ct, SkAl phaType at,
163 float gamma);
164
165 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a t) { 144 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a t) {
166 return MakeWithGamma(width, height, ct, at, 1); 145 SkImageInfo info = {
146 width, height, ct, at
147 };
148 return info;
167 } 149 }
168 150
169 /** 151 /**
170 * Sets colortype to the native ARGB32 type. 152 * Sets colortype to the native ARGB32 type.
171 */ 153 */
172 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { 154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
173 return SkImageInfo(width, height, kN32_SkColorType, at, kExponential_Pro file, 1); 155 SkImageInfo info = {
156 width, height, kN32_SkColorType, at
157 };
158 return info;
174 } 159 }
175 160
176 /** 161 /**
177 * Sets colortype to the native ARGB32 type, and the alphatype to premul. 162 * Sets colortype to the native ARGB32 type, and the alphatype to premul.
178 */ 163 */
179 static SkImageInfo MakeN32Premul(int width, int height) { 164 static SkImageInfo MakeN32Premul(int width, int height) {
180 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, 165 SkImageInfo info = {
181 kExponential_Profile, 1); 166 width, height, kN32_SkColorType, kPremul_SkAlphaType
167 };
168 return info;
182 } 169 }
183 170
184 /** 171 /**
185 * Sets colortype to the native ARGB32 type, and the alphatype to premul. 172 * Sets colortype to the native ARGB32 type, and the alphatype to premul.
186 */ 173 */
187 static SkImageInfo MakeN32Premul(const SkISize& size) { 174 static SkImageInfo MakeN32Premul(const SkISize& size) {
188 return MakeN32Premul(size.width(), size.height()); 175 return MakeN32Premul(size.width(), size.height());
189 } 176 }
190 177
191 static SkImageInfo MakeA8(int width, int height) { 178 static SkImageInfo MakeA8(int width, int height) {
192 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT ype, 179 SkImageInfo info = {
193 kUnknown_Profile, 0); 180 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
181 };
182 return info;
194 } 183 }
195 184
196 static SkImageInfo MakeUnknown(int width, int height) { 185 static SkImageInfo MakeUnknown(int width, int height) {
197 return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaT ype, 186 SkImageInfo info = {
198 kUnknown_Profile, 0); 187 width, height, kUnknown_SkColorType, kIgnore_SkAlphaType
188 };
189 return info;
199 } 190 }
200 191
201 static SkImageInfo MakeUnknown() { 192 static SkImageInfo MakeUnknown() {
202 return SkImageInfo(0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType, kUnk nown_Profile, 0); 193 SkImageInfo info = {
194 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType
195 };
196 return info;
203 } 197 }
204 198
205 int width() const { return fWidth; } 199 int width() const { return fWidth; }
206 int height() const { return fHeight; } 200 int height() const { return fHeight; }
207 SkColorType colorType() const { return fColorType; } 201 SkColorType colorType() const { return fColorType; }
208 SkAlphaType alphaType() const { return fAlphaType; } 202 SkAlphaType alphaType() const { return fAlphaType; }
209 203
210 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } 204 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
211 205
212 bool isOpaque() const { 206 bool isOpaque() const {
(...skipping 22 matching lines...) Expand all
235 return (size_t)this->minRowBytes64(); 229 return (size_t)this->minRowBytes64();
236 } 230 }
237 231
238 bool operator==(const SkImageInfo& other) const { 232 bool operator==(const SkImageInfo& other) const {
239 return 0 == memcmp(this, &other, sizeof(other)); 233 return 0 == memcmp(this, &other, sizeof(other));
240 } 234 }
241 bool operator!=(const SkImageInfo& other) const { 235 bool operator!=(const SkImageInfo& other) const {
242 return 0 != memcmp(this, &other, sizeof(other)); 236 return 0 != memcmp(this, &other, sizeof(other));
243 } 237 }
244 238
245 // DEPRECATED : use the static Unflatten
246 void unflatten(SkReadBuffer&); 239 void unflatten(SkReadBuffer&);
247 void flatten(SkWriteBuffer&) const; 240 void flatten(SkWriteBuffer&) const;
248
249 static SkImageInfo Unflatten(SkReadBuffer&);
250 241
251 int64_t getSafeSize64(size_t rowBytes) const { 242 int64_t getSafeSize64(size_t rowBytes) const {
252 if (0 == fHeight) { 243 if (0 == fHeight) {
253 return 0; 244 return 0;
254 } 245 }
255 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel() ; 246 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel() ;
256 } 247 }
257 248
258 size_t getSafeSize(size_t rowBytes) const { 249 size_t getSafeSize(size_t rowBytes) const {
259 return (size_t)this->getSafeSize64(rowBytes); 250 return (size_t)this->getSafeSize64(rowBytes);
260 } 251 }
261 252
262 bool validRowBytes(size_t rowBytes) const { 253 bool validRowBytes(size_t rowBytes) const {
263 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); 254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
264 return rowBytes >= rb; 255 return rowBytes >= rb;
265 } 256 }
266 257
267 SkDEBUGCODE(void validate() const;) 258 SkDEBUGCODE(void validate() const;)
268
269 /**
270 * If the Info was tagged to be sRGB, return true, else return false.
271 */
272 bool isSRGB() const { return kSRGB_Profile == fProfile; }
273
274 /**
275 * If this was tagged with an explicit gamma value, return that value, else return 0.
276 * If this was tagged as sRGB, return 0.
277 */
278 float gamma() const { return fGamma; }
279
280 private:
281 enum Profile {
282 kUnknown_Profile,
283 kSRGB_Profile,
284 kExponential_Profile,
285 };
286
287 uint32_t fProfile;
288 float fGamma;
289
290 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, Profile p , float g)
291 : fWidth(width)
292 , fHeight(height)
293 , fColorType(ct)
294 , fAlphaType(at)
295 , fProfile(p)
296 , fGamma(g)
297 {}
298 }; 259 };
299 260
300 #endif 261 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | src/core/SkImageInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698