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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 break; | 246 break; |
247 default: | 247 default: |
248 return false; | 248 return false; |
249 } | 249 } |
250 if (canonical) { | 250 if (canonical) { |
251 *canonical = alphaType; | 251 *canonical = alphaType; |
252 } | 252 } |
253 return true; | 253 return true; |
254 } | 254 } |
255 | 255 |
256 bool SkBitmap::setConfig(const SkImageInfo& info, size_t rowBytes) { | 256 bool SkBitmap::setConfig(const SkImageInfo& origInfo, size_t rowBytes) { |
| 257 SkImageInfo info = origInfo; |
| 258 |
| 259 if (!validate_alphaType(info.fColorType, info.fAlphaType, |
| 260 &info.fAlphaType)) { |
| 261 return reset_return_false(this); |
| 262 } |
| 263 |
257 // require that rowBytes fit in 31bits | 264 // require that rowBytes fit in 31bits |
258 int64_t mrb = info.minRowBytes64(); | 265 int64_t mrb = info.minRowBytes64(); |
259 if ((int32_t)mrb != mrb) { | 266 if ((int32_t)mrb != mrb) { |
260 return reset_return_false(this); | 267 return reset_return_false(this); |
261 } | 268 } |
262 if ((int64_t)rowBytes != (int32_t)rowBytes) { | 269 if ((int64_t)rowBytes != (int32_t)rowBytes) { |
263 return reset_return_false(this); | 270 return reset_return_false(this); |
264 } | 271 } |
265 | 272 |
266 if (info.width() < 0 || info.height() < 0) { | 273 if (info.width() < 0 || info.height() < 0) { |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 | 1619 |
1613 SkBitmap::RLEPixels::~RLEPixels() { | 1620 SkBitmap::RLEPixels::~RLEPixels() { |
1614 sk_free(fYPtrs); | 1621 sk_free(fYPtrs); |
1615 } | 1622 } |
1616 | 1623 |
1617 /////////////////////////////////////////////////////////////////////////////// | 1624 /////////////////////////////////////////////////////////////////////////////// |
1618 | 1625 |
1619 #ifdef SK_DEBUG | 1626 #ifdef SK_DEBUG |
1620 void SkBitmap::validate() const { | 1627 void SkBitmap::validate() const { |
1621 fInfo.validate(); | 1628 fInfo.validate(); |
| 1629 |
| 1630 // ImageInfo may not require this, but Bitmap ensures that opaque-only |
| 1631 // colorTypes report opaque for their alphatype |
| 1632 if (kRGB_565_SkColorType == fInfo.colorType()) { |
| 1633 SkASSERT(kOpaque_SkAlphaType == fInfo.alphaType()); |
| 1634 } |
| 1635 |
1622 SkASSERT(fInfo.validRowBytes(fRowBytes)); | 1636 SkASSERT(fInfo.validRowBytes(fRowBytes)); |
1623 uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImm
utable_Flag; | 1637 uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImm
utable_Flag; |
1624 #ifdef SK_BUILD_FOR_ANDROID | 1638 #ifdef SK_BUILD_FOR_ANDROID |
1625 allFlags |= kHasHardwareMipMap_Flag; | 1639 allFlags |= kHasHardwareMipMap_Flag; |
1626 #endif | 1640 #endif |
1627 SkASSERT(fFlags <= allFlags); | 1641 SkASSERT(fFlags <= allFlags); |
1628 SkASSERT(fPixelLockCount >= 0); | 1642 SkASSERT(fPixelLockCount >= 0); |
1629 | 1643 |
1630 if (fPixels) { | 1644 if (fPixels) { |
1631 SkASSERT(fPixelRef); | 1645 SkASSERT(fPixelRef); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 /////////////////////////////////////////////////////////////////////////////// | 1700 /////////////////////////////////////////////////////////////////////////////// |
1687 | 1701 |
1688 #ifdef SK_DEBUG | 1702 #ifdef SK_DEBUG |
1689 void SkImageInfo::validate() const { | 1703 void SkImageInfo::validate() const { |
1690 SkASSERT(fWidth >= 0); | 1704 SkASSERT(fWidth >= 0); |
1691 SkASSERT(fHeight >= 0); | 1705 SkASSERT(fHeight >= 0); |
1692 SkASSERT(SkColorTypeIsValid(fColorType)); | 1706 SkASSERT(SkColorTypeIsValid(fColorType)); |
1693 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1707 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1694 } | 1708 } |
1695 #endif | 1709 #endif |
OLD | NEW |