OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void SkBitmap::reset() { | 89 void SkBitmap::reset() { |
90 this->freePixels(); | 90 this->freePixels(); |
91 sk_bzero(this, sizeof(*this)); | 91 sk_bzero(this, sizeof(*this)); |
92 } | 92 } |
93 | 93 |
94 SkBitmap::Config SkBitmap::config() const { | 94 SkBitmap::Config SkBitmap::config() const { |
95 return SkColorTypeToBitmapConfig(fInfo.colorType()); | 95 return SkColorTypeToBitmapConfig(fInfo.colorType()); |
96 } | 96 } |
97 | 97 |
| 98 #ifdef SK_SUPPORT_LEGACY_COMPUTE_CONFIG_SIZE |
98 int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) { | 99 int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) { |
99 int bpp; | 100 int bpp; |
100 switch (config) { | 101 switch (config) { |
101 case kNo_Config: | 102 case kNo_Config: |
102 bpp = 0; // not applicable | 103 bpp = 0; // not applicable |
103 break; | 104 break; |
104 case kA8_Config: | 105 case kA8_Config: |
105 case kIndex8_Config: | 106 case kIndex8_Config: |
106 bpp = 1; | 107 bpp = 1; |
107 break; | 108 break; |
(...skipping 19 matching lines...) Expand all Loading... |
127 int64_t SkBitmap::ComputeSize64(Config config, int width, int height) { | 128 int64_t SkBitmap::ComputeSize64(Config config, int width, int height) { |
128 SkColorType ct = SkBitmapConfigToColorType(config); | 129 SkColorType ct = SkBitmapConfigToColorType(config); |
129 int64_t rowBytes = sk_64_mul(SkColorTypeBytesPerPixel(ct), width); | 130 int64_t rowBytes = sk_64_mul(SkColorTypeBytesPerPixel(ct), width); |
130 return rowBytes * height; | 131 return rowBytes * height; |
131 } | 132 } |
132 | 133 |
133 size_t SkBitmap::ComputeSize(Config c, int width, int height) { | 134 size_t SkBitmap::ComputeSize(Config c, int width, int height) { |
134 int64_t size = SkBitmap::ComputeSize64(c, width, height); | 135 int64_t size = SkBitmap::ComputeSize64(c, width, height); |
135 return sk_64_isS32(size) ? sk_64_asS32(size) : 0; | 136 return sk_64_isS32(size) ? sk_64_asS32(size) : 0; |
136 } | 137 } |
137 | 138 #endif |
138 int64_t SkBitmap::ComputeSafeSize64(Config config, | |
139 uint32_t width, | |
140 uint32_t height, | |
141 size_t rowBytes) { | |
142 SkImageInfo info = SkImageInfo::Make(width, height, | |
143 SkBitmapConfigToColorType(config), | |
144 kPremul_SkAlphaType); | |
145 return info.getSafeSize64(rowBytes); | |
146 } | |
147 | |
148 size_t SkBitmap::ComputeSafeSize(Config config, | |
149 uint32_t width, | |
150 uint32_t height, | |
151 size_t rowBytes) { | |
152 int64_t safeSize = ComputeSafeSize64(config, width, height, rowBytes); | |
153 int32_t safeSize32 = (int32_t)safeSize; | |
154 | |
155 if (safeSize32 != safeSize) { | |
156 safeSize32 = 0; | |
157 } | |
158 return safeSize32; | |
159 } | |
160 | 139 |
161 void SkBitmap::getBounds(SkRect* bounds) const { | 140 void SkBitmap::getBounds(SkRect* bounds) const { |
162 SkASSERT(bounds); | 141 SkASSERT(bounds); |
163 bounds->set(0, 0, | 142 bounds->set(0, 0, |
164 SkIntToScalar(fInfo.fWidth), SkIntToScalar(fInfo.fHeight)); | 143 SkIntToScalar(fInfo.fWidth), SkIntToScalar(fInfo.fHeight)); |
165 } | 144 } |
166 | 145 |
167 void SkBitmap::getBounds(SkIRect* bounds) const { | 146 void SkBitmap::getBounds(SkIRect* bounds) const { |
168 SkASSERT(bounds); | 147 SkASSERT(bounds); |
169 bounds->set(0, 0, fInfo.fWidth, fInfo.fHeight); | 148 bounds->set(0, 0, fInfo.fWidth, fInfo.fHeight); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 fPixels = p; | 250 fPixels = p; |
272 fColorTable = fPixelRef->colorTable(); | 251 fColorTable = fPixelRef->colorTable(); |
273 } else { | 252 } else { |
274 SkASSERT(0 == fPixelLockCount); | 253 SkASSERT(0 == fPixelLockCount); |
275 fPixels = NULL; | 254 fPixels = NULL; |
276 fColorTable = NULL; | 255 fColorTable = NULL; |
277 } | 256 } |
278 } | 257 } |
279 } | 258 } |
280 | 259 |
281 static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) { | |
282 SkColorType ct; | |
283 switch (config) { | |
284 case SkBitmap::kA8_Config: | |
285 ct = kAlpha_8_SkColorType; | |
286 break; | |
287 case SkBitmap::kIndex8_Config: | |
288 ct = kIndex_8_SkColorType; | |
289 break; | |
290 case SkBitmap::kRGB_565_Config: | |
291 ct = kRGB_565_SkColorType; | |
292 break; | |
293 case SkBitmap::kARGB_4444_Config: | |
294 ct = kARGB_4444_SkColorType; | |
295 break; | |
296 case SkBitmap::kARGB_8888_Config: | |
297 ct = kN32_SkColorType; | |
298 break; | |
299 case SkBitmap::kNo_Config: | |
300 default: | |
301 return false; | |
302 } | |
303 if (ctOut) { | |
304 *ctOut = ct; | |
305 } | |
306 return true; | |
307 } | |
308 | |
309 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { | 260 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { |
310 #ifdef SK_DEBUG | 261 #ifdef SK_DEBUG |
311 if (pr) { | 262 if (pr) { |
312 if (kUnknown_SkColorType != fInfo.colorType()) { | 263 if (kUnknown_SkColorType != fInfo.colorType()) { |
313 const SkImageInfo& prInfo = pr->info(); | 264 const SkImageInfo& prInfo = pr->info(); |
314 SkASSERT(fInfo.fWidth <= prInfo.fWidth); | 265 SkASSERT(fInfo.fWidth <= prInfo.fWidth); |
315 SkASSERT(fInfo.fHeight <= prInfo.fHeight); | 266 SkASSERT(fInfo.fHeight <= prInfo.fHeight); |
316 SkASSERT(fInfo.fColorType == prInfo.fColorType); | 267 SkASSERT(fInfo.fColorType == prInfo.fColorType); |
317 switch (prInfo.fAlphaType) { | 268 switch (prInfo.fAlphaType) { |
318 case kIgnore_SkAlphaType: | 269 case kIgnore_SkAlphaType: |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 bool SkBitmap::installMaskPixels(const SkMask& mask) { | 416 bool SkBitmap::installMaskPixels(const SkMask& mask) { |
466 if (SkMask::kA8_Format != mask.fFormat) { | 417 if (SkMask::kA8_Format != mask.fFormat) { |
467 this->reset(); | 418 this->reset(); |
468 return false; | 419 return false; |
469 } | 420 } |
470 return this->installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), | 421 return this->installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), |
471 mask.fBounds.height()), | 422 mask.fBounds.height()), |
472 mask.fImage, mask.fRowBytes); | 423 mask.fImage, mask.fRowBytes); |
473 } | 424 } |
474 | 425 |
475 bool SkBitmap::allocConfigPixels(Config config, int width, int height, | |
476 bool isOpaque) { | |
477 SkColorType ct; | |
478 if (!config_to_colorType(config, &ct)) { | |
479 return false; | |
480 } | |
481 | |
482 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | |
483 return this->allocPixels(SkImageInfo::Make(width, height, ct, at)); | |
484 } | |
485 | |
486 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
487 | 427 |
488 void SkBitmap::freePixels() { | 428 void SkBitmap::freePixels() { |
489 if (NULL != fPixelRef) { | 429 if (NULL != fPixelRef) { |
490 if (fPixelLockCount > 0) { | 430 if (fPixelLockCount > 0) { |
491 fPixelRef->unlockPixels(); | 431 fPixelRef->unlockPixels(); |
492 } | 432 } |
493 fPixelRef->unref(); | 433 fPixelRef->unref(); |
494 fPixelRef = NULL; | 434 fPixelRef = NULL; |
495 fPixelRefOrigin.setZero(); | 435 fPixelRefOrigin.setZero(); |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 /////////////////////////////////////////////////////////////////////////////// | 1416 /////////////////////////////////////////////////////////////////////////////// |
1477 | 1417 |
1478 #ifdef SK_DEBUG | 1418 #ifdef SK_DEBUG |
1479 void SkImageInfo::validate() const { | 1419 void SkImageInfo::validate() const { |
1480 SkASSERT(fWidth >= 0); | 1420 SkASSERT(fWidth >= 0); |
1481 SkASSERT(fHeight >= 0); | 1421 SkASSERT(fHeight >= 0); |
1482 SkASSERT(SkColorTypeIsValid(fColorType)); | 1422 SkASSERT(SkColorTypeIsValid(fColorType)); |
1483 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1423 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1484 } | 1424 } |
1485 #endif | 1425 #endif |
OLD | NEW |