OLD | NEW |
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...) Loading... |
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 | |
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 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 * Note that if the requested gamma is unsupported for the requested color
type, then the gamma | |
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 | |
185 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) { |
186 return MakeWithGamma(width, height, ct, at, 1); | 145 SkImageInfo info = { |
| 146 width, height, ct, at |
| 147 }; |
| 148 return info; |
187 } | 149 } |
188 | 150 |
189 /** | 151 /** |
190 * Sets colortype to the native ARGB32 type. | 152 * Sets colortype to the native ARGB32 type. |
191 */ | 153 */ |
192 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { | 154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { |
193 return SkImageInfo(width, height, kN32_SkColorType, at, kExponential_Pro
file, 1); | 155 SkImageInfo info = { |
| 156 width, height, kN32_SkColorType, at |
| 157 }; |
| 158 return info; |
194 } | 159 } |
195 | 160 |
196 /** | 161 /** |
197 * 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. |
198 */ | 163 */ |
199 static SkImageInfo MakeN32Premul(int width, int height) { | 164 static SkImageInfo MakeN32Premul(int width, int height) { |
200 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, | 165 SkImageInfo info = { |
201 kExponential_Profile, 1); | 166 width, height, kN32_SkColorType, kPremul_SkAlphaType |
| 167 }; |
| 168 return info; |
202 } | 169 } |
203 | 170 |
204 /** | 171 /** |
205 * 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. |
206 */ | 173 */ |
207 static SkImageInfo MakeN32Premul(const SkISize& size) { | 174 static SkImageInfo MakeN32Premul(const SkISize& size) { |
208 return MakeN32Premul(size.width(), size.height()); | 175 return MakeN32Premul(size.width(), size.height()); |
209 } | 176 } |
210 | 177 |
211 static SkImageInfo MakeA8(int width, int height) { | 178 static SkImageInfo MakeA8(int width, int height) { |
212 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype, | 179 SkImageInfo info = { |
213 kUnknown_Profile, 0); | 180 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType |
| 181 }; |
| 182 return info; |
214 } | 183 } |
215 | 184 |
216 static SkImageInfo MakeUnknown(int width, int height) { | 185 static SkImageInfo MakeUnknown(int width, int height) { |
217 return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaT
ype, | 186 SkImageInfo info = { |
218 kUnknown_Profile, 0); | 187 width, height, kUnknown_SkColorType, kIgnore_SkAlphaType |
| 188 }; |
| 189 return info; |
219 } | 190 } |
220 | 191 |
221 static SkImageInfo MakeUnknown() { | 192 static SkImageInfo MakeUnknown() { |
222 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; |
223 } | 197 } |
224 | 198 |
225 int width() const { return fWidth; } | 199 int width() const { return fWidth; } |
226 int height() const { return fHeight; } | 200 int height() const { return fHeight; } |
227 SkColorType colorType() const { return fColorType; } | 201 SkColorType colorType() const { return fColorType; } |
228 SkAlphaType alphaType() const { return fAlphaType; } | 202 SkAlphaType alphaType() const { return fAlphaType; } |
229 | 203 |
230 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } | 204 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
231 | 205 |
232 bool isOpaque() const { | 206 bool isOpaque() const { |
(...skipping 22 matching lines...) Loading... |
255 return (size_t)this->minRowBytes64(); | 229 return (size_t)this->minRowBytes64(); |
256 } | 230 } |
257 | 231 |
258 bool operator==(const SkImageInfo& other) const { | 232 bool operator==(const SkImageInfo& other) const { |
259 return 0 == memcmp(this, &other, sizeof(other)); | 233 return 0 == memcmp(this, &other, sizeof(other)); |
260 } | 234 } |
261 bool operator!=(const SkImageInfo& other) const { | 235 bool operator!=(const SkImageInfo& other) const { |
262 return 0 != memcmp(this, &other, sizeof(other)); | 236 return 0 != memcmp(this, &other, sizeof(other)); |
263 } | 237 } |
264 | 238 |
265 // DEPRECATED : use the static Unflatten | |
266 void unflatten(SkReadBuffer&); | 239 void unflatten(SkReadBuffer&); |
267 void flatten(SkWriteBuffer&) const; | 240 void flatten(SkWriteBuffer&) const; |
268 | |
269 static SkImageInfo Unflatten(SkReadBuffer&); | |
270 | 241 |
271 int64_t getSafeSize64(size_t rowBytes) const { | 242 int64_t getSafeSize64(size_t rowBytes) const { |
272 if (0 == fHeight) { | 243 if (0 == fHeight) { |
273 return 0; | 244 return 0; |
274 } | 245 } |
275 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; | 246 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; |
276 } | 247 } |
277 | 248 |
278 size_t getSafeSize(size_t rowBytes) const { | 249 size_t getSafeSize(size_t rowBytes) const { |
279 return (size_t)this->getSafeSize64(rowBytes); | 250 return (size_t)this->getSafeSize64(rowBytes); |
280 } | 251 } |
281 | 252 |
282 bool validRowBytes(size_t rowBytes) const { | 253 bool validRowBytes(size_t rowBytes) const { |
283 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
284 return rowBytes >= rb; | 255 return rowBytes >= rb; |
285 } | 256 } |
286 | 257 |
287 SkDEBUGCODE(void validate() const;) | 258 SkDEBUGCODE(void validate() const;) |
288 | |
289 /** | |
290 * If the Info was tagged to be sRGB, return true, else return false. | |
291 */ | |
292 bool isSRGB() const { return kSRGB_Profile == fProfile; } | |
293 | |
294 /** | |
295 * If this was tagged with an explicit gamma value, return that value, else
return 0. | |
296 * If this was tagged as sRGB, return 0. | |
297 */ | |
298 float gamma() const { return fGamma; } | |
299 }; | 259 }; |
300 | 260 |
301 #endif | 261 #endif |
OLD | NEW |