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...) Expand 10 before | Expand all | Expand 10 after 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 |
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 * 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 |
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 22 matching lines...) Expand all Loading... |
229 return (size_t)this->minRowBytes64(); | 255 return (size_t)this->minRowBytes64(); |
230 } | 256 } |
231 | 257 |
232 bool operator==(const SkImageInfo& other) const { | 258 bool operator==(const SkImageInfo& other) const { |
233 return 0 == memcmp(this, &other, sizeof(other)); | 259 return 0 == memcmp(this, &other, sizeof(other)); |
234 } | 260 } |
235 bool operator!=(const SkImageInfo& other) const { | 261 bool operator!=(const SkImageInfo& other) const { |
236 return 0 != memcmp(this, &other, sizeof(other)); | 262 return 0 != memcmp(this, &other, sizeof(other)); |
237 } | 263 } |
238 | 264 |
| 265 // DEPRECATED : use the static Unflatten |
239 void unflatten(SkReadBuffer&); | 266 void unflatten(SkReadBuffer&); |
240 void flatten(SkWriteBuffer&) const; | 267 void flatten(SkWriteBuffer&) const; |
| 268 |
| 269 static SkImageInfo Unflatten(SkReadBuffer&); |
241 | 270 |
242 int64_t getSafeSize64(size_t rowBytes) const { | 271 int64_t getSafeSize64(size_t rowBytes) const { |
243 if (0 == fHeight) { | 272 if (0 == fHeight) { |
244 return 0; | 273 return 0; |
245 } | 274 } |
246 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; | 275 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; |
247 } | 276 } |
248 | 277 |
249 size_t getSafeSize(size_t rowBytes) const { | 278 size_t getSafeSize(size_t rowBytes) const { |
250 return (size_t)this->getSafeSize64(rowBytes); | 279 return (size_t)this->getSafeSize64(rowBytes); |
251 } | 280 } |
252 | 281 |
253 bool validRowBytes(size_t rowBytes) const { | 282 bool validRowBytes(size_t rowBytes) const { |
254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 283 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
255 return rowBytes >= rb; | 284 return rowBytes >= rb; |
256 } | 285 } |
257 | 286 |
258 SkDEBUGCODE(void validate() const;) | 287 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; } |
259 }; | 299 }; |
260 | 300 |
261 #endif | 301 #endif |
OLD | NEW |