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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 SkIntToScalar(fWidth), SkIntToScalar(fHeight)); | 259 SkIntToScalar(fWidth), SkIntToScalar(fHeight)); |
260 } | 260 } |
261 | 261 |
262 void SkBitmap::getBounds(SkIRect* bounds) const { | 262 void SkBitmap::getBounds(SkIRect* bounds) const { |
263 SkASSERT(bounds); | 263 SkASSERT(bounds); |
264 bounds->set(0, 0, fWidth, fHeight); | 264 bounds->set(0, 0, fWidth, fHeight); |
265 } | 265 } |
266 | 266 |
267 /////////////////////////////////////////////////////////////////////////////// | 267 /////////////////////////////////////////////////////////////////////////////// |
268 | 268 |
269 bool SkBitmap::IsValidConfig(Config config) { | |
reed1
2013/09/03 20:25:21
I'm not 100% sure that the compile will always exe
sugoi1
2013/09/04 18:01:10
Not sure, but I've changed it just to be certain.
| |
270 switch (config) { | |
271 case kNo_Config: | |
272 case kA1_Config: | |
273 case kA8_Config: | |
274 case kIndex8_Config: | |
275 case kRGB_565_Config: | |
276 case kARGB_4444_Config: | |
277 case kARGB_8888_Config: | |
278 return true; | |
279 default: | |
280 break; | |
281 } | |
282 return false; | |
283 } | |
284 | |
269 void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) { | 285 void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) { |
270 this->freePixels(); | 286 this->freePixels(); |
271 | 287 |
272 if ((width | height) < 0) { | 288 if ((width | height) < 0) { |
273 goto err; | 289 goto err; |
274 } | 290 } |
275 | 291 |
276 if (rowBytes == 0) { | 292 if (rowBytes == 0) { |
277 rowBytes = SkBitmap::ComputeRowBytes(c, width); | 293 rowBytes = SkBitmap::ComputeRowBytes(c, width); |
278 if (0 == rowBytes && kNo_Config != c) { | 294 if (0 == rowBytes && kNo_Config != c) { |
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1600 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE); | 1616 buffer.writeInt(SERIALIZE_PIXELTYPE_NONE); |
1601 } | 1617 } |
1602 } | 1618 } |
1603 | 1619 |
1604 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { | 1620 void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { |
1605 this->reset(); | 1621 this->reset(); |
1606 | 1622 |
1607 int width = buffer.readInt(); | 1623 int width = buffer.readInt(); |
1608 int height = buffer.readInt(); | 1624 int height = buffer.readInt(); |
1609 int rowBytes = buffer.readInt(); | 1625 int rowBytes = buffer.readInt(); |
1610 int config = buffer.readInt(); | 1626 Config config = (Config)buffer.readInt(); |
1627 buffer.validateData((width >= 0) && (height >= 0) && (rowBytes >= 0) && | |
1628 IsValidConfig(config)); | |
1611 | 1629 |
1612 this->setConfig((Config)config, width, height, rowBytes); | 1630 this->setConfig(config, width, height, rowBytes); |
1613 this->setIsOpaque(buffer.readBool()); | 1631 this->setIsOpaque(buffer.readBool()); |
1614 | 1632 |
1615 int reftype = buffer.readInt(); | 1633 int reftype = buffer.readInt(); |
1616 switch (reftype) { | 1634 switch (reftype) { |
1617 case SERIALIZE_PIXELTYPE_REF_DATA: { | 1635 case SERIALIZE_PIXELTYPE_REF_DATA: { |
1618 size_t offset = buffer.readUInt(); | 1636 size_t offset = buffer.readUInt(); |
1619 SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>(); | 1637 SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>(); |
1620 SkSafeUnref(this->setPixelRef(pr, offset)); | 1638 SkSafeUnref(this->setPixelRef(pr, offset)); |
1621 break; | 1639 break; |
1622 } | 1640 } |
1623 case SERIALIZE_PIXELTYPE_NONE: | 1641 case SERIALIZE_PIXELTYPE_NONE: |
1624 break; | 1642 break; |
1625 default: | 1643 default: |
1644 buffer.validateData(false); | |
1626 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); | 1645 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); |
1627 sk_throw(); | 1646 sk_throw(); |
1628 } | 1647 } |
1629 } | 1648 } |
1630 | 1649 |
1631 /////////////////////////////////////////////////////////////////////////////// | 1650 /////////////////////////////////////////////////////////////////////////////// |
1632 | 1651 |
1633 SkBitmap::RLEPixels::RLEPixels(int width, int height) { | 1652 SkBitmap::RLEPixels::RLEPixels(int width, int height) { |
1634 fHeight = height; | 1653 fHeight = height; |
1635 fYPtrs = (uint8_t**)sk_malloc_throw(height * sizeof(uint8_t*)); | 1654 fYPtrs = (uint8_t**)sk_malloc_throw(height * sizeof(uint8_t*)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1700 if (NULL != uri) { | 1719 if (NULL != uri) { |
1701 str->appendf(" uri:\"%s\"", uri); | 1720 str->appendf(" uri:\"%s\"", uri); |
1702 } else { | 1721 } else { |
1703 str->appendf(" pixelref:%p", pr); | 1722 str->appendf(" pixelref:%p", pr); |
1704 } | 1723 } |
1705 } | 1724 } |
1706 | 1725 |
1707 str->append(")"); | 1726 str->append(")"); |
1708 } | 1727 } |
1709 #endif | 1728 #endif |
OLD | NEW |