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