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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkImageInfo { | 138 struct SK_API 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 /* |
| 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 |
144 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { | 165 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { |
145 SkImageInfo info = { | 166 return MakeWithGamma(width, height, ct, at, 1); |
146 width, height, ct, at | |
147 }; | |
148 return info; | |
149 } | 167 } |
150 | 168 |
151 /** | 169 /** |
152 * Sets colortype to the native ARGB32 type. | 170 * Sets colortype to the native ARGB32 type. |
153 */ | 171 */ |
154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { | 172 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { |
155 SkImageInfo info = { | 173 return SkImageInfo(width, height, kN32_SkColorType, at, kExponential_Pro
file, 1); |
156 width, height, kN32_SkColorType, at | |
157 }; | |
158 return info; | |
159 } | 174 } |
160 | 175 |
161 /** | 176 /** |
162 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 177 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
163 */ | 178 */ |
164 static SkImageInfo MakeN32Premul(int width, int height) { | 179 static SkImageInfo MakeN32Premul(int width, int height) { |
165 SkImageInfo info = { | 180 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, |
166 width, height, kN32_SkColorType, kPremul_SkAlphaType | 181 kExponential_Profile, 1); |
167 }; | |
168 return info; | |
169 } | 182 } |
170 | 183 |
171 /** | 184 /** |
172 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 185 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
173 */ | 186 */ |
174 static SkImageInfo MakeN32Premul(const SkISize& size) { | 187 static SkImageInfo MakeN32Premul(const SkISize& size) { |
175 return MakeN32Premul(size.width(), size.height()); | 188 return MakeN32Premul(size.width(), size.height()); |
176 } | 189 } |
177 | 190 |
178 static SkImageInfo MakeA8(int width, int height) { | 191 static SkImageInfo MakeA8(int width, int height) { |
179 SkImageInfo info = { | 192 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype, |
180 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType | 193 kUnknown_Profile, 0); |
181 }; | |
182 return info; | |
183 } | 194 } |
184 | 195 |
185 static SkImageInfo MakeUnknown(int width, int height) { | 196 static SkImageInfo MakeUnknown(int width, int height) { |
186 SkImageInfo info = { | 197 return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaT
ype, |
187 width, height, kUnknown_SkColorType, kIgnore_SkAlphaType | 198 kUnknown_Profile, 0); |
188 }; | |
189 return info; | |
190 } | 199 } |
191 | 200 |
192 static SkImageInfo MakeUnknown() { | 201 static SkImageInfo MakeUnknown() { |
193 SkImageInfo info = { | 202 return SkImageInfo(0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType, kUnk
nown_Profile, 0); |
194 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType | |
195 }; | |
196 return info; | |
197 } | 203 } |
198 | 204 |
199 int width() const { return fWidth; } | 205 int width() const { return fWidth; } |
200 int height() const { return fHeight; } | 206 int height() const { return fHeight; } |
201 SkColorType colorType() const { return fColorType; } | 207 SkColorType colorType() const { return fColorType; } |
202 SkAlphaType alphaType() const { return fAlphaType; } | 208 SkAlphaType alphaType() const { return fAlphaType; } |
203 | 209 |
204 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } | 210 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
205 | 211 |
206 bool isOpaque() const { | 212 bool isOpaque() const { |
(...skipping 22 matching lines...) Expand all Loading... |
229 return (size_t)this->minRowBytes64(); | 235 return (size_t)this->minRowBytes64(); |
230 } | 236 } |
231 | 237 |
232 bool operator==(const SkImageInfo& other) const { | 238 bool operator==(const SkImageInfo& other) const { |
233 return 0 == memcmp(this, &other, sizeof(other)); | 239 return 0 == memcmp(this, &other, sizeof(other)); |
234 } | 240 } |
235 bool operator!=(const SkImageInfo& other) const { | 241 bool operator!=(const SkImageInfo& other) const { |
236 return 0 != memcmp(this, &other, sizeof(other)); | 242 return 0 != memcmp(this, &other, sizeof(other)); |
237 } | 243 } |
238 | 244 |
| 245 // DEPRECATED : use the static Unflatten |
239 void unflatten(SkReadBuffer&); | 246 void unflatten(SkReadBuffer&); |
240 void flatten(SkWriteBuffer&) const; | 247 void flatten(SkWriteBuffer&) const; |
| 248 |
| 249 static SkImageInfo Unflatten(SkReadBuffer&); |
241 | 250 |
242 int64_t getSafeSize64(size_t rowBytes) const { | 251 int64_t getSafeSize64(size_t rowBytes) const { |
243 if (0 == fHeight) { | 252 if (0 == fHeight) { |
244 return 0; | 253 return 0; |
245 } | 254 } |
246 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; | 255 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel()
; |
247 } | 256 } |
248 | 257 |
249 size_t getSafeSize(size_t rowBytes) const { | 258 size_t getSafeSize(size_t rowBytes) const { |
250 return (size_t)this->getSafeSize64(rowBytes); | 259 return (size_t)this->getSafeSize64(rowBytes); |
251 } | 260 } |
252 | 261 |
253 bool validRowBytes(size_t rowBytes) const { | 262 bool validRowBytes(size_t rowBytes) const { |
254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 263 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
255 return rowBytes >= rb; | 264 return rowBytes >= rb; |
256 } | 265 } |
257 | 266 |
258 SkDEBUGCODE(void validate() const;) | 267 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 {} |
259 }; | 298 }; |
260 | 299 |
261 #endif | 300 #endif |
OLD | NEW |