Index: src/core/SkColorTable.cpp |
diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp |
index 13c4795c3f6139db1604ee56fa9f6675d7a1c5f2..e461a095f0d096416846c01247c0bdd99fdab135 100644 |
--- a/src/core/SkColorTable.cpp |
+++ b/src/core/SkColorTable.cpp |
@@ -32,6 +32,14 @@ SkColorTable::SkColorTable(const SkPMColor colors[], int count) { |
this->init(colors, count); |
} |
+SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc) |
+ : fColors(colors) |
+ , fCount(count) |
+{ |
+ SkASSERT(count > 0 && count <= 255); |
hal.canary
2015/08/28 18:28:02
why not 256?
|
+ SkASSERT(colors); |
+} |
+ |
SkColorTable::~SkColorTable() { |
sk_free(fColors); |
// f16BitCache frees itself |
@@ -63,6 +71,7 @@ const uint16_t* SkColorTable::read16BitCache() const { |
/////////////////////////////////////////////////////////////////////////////// |
+#if 0 |
SkColorTable::SkColorTable(SkReadBuffer& buffer) { |
if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { |
/*fAlphaType = */buffer.readUInt(); |
@@ -83,7 +92,33 @@ SkColorTable::SkColorTable(SkReadBuffer& buffer) { |
SkASSERT(success); |
#endif |
} |
+#endif |
void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const { |
buffer.writeColorArray(fColors, fCount); |
} |
+ |
+SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { |
+ if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { |
+ /*fAlphaType = */buffer.readUInt(); |
+ } |
+ |
+ const int count = buffer.getArrayCount(); |
+ if (0 == count) { |
+ return new SkColorTable(nullptr, 0); |
+ } |
+ |
+ if (count < 0 || count > 255) { |
+ buffer.validate(false); |
+ return nullptr; |
+ } |
+ |
+ const size_t allocSize = count * sizeof(SkPMColor); |
+ SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); |
+ if (!buffer.readColorArray(colors, count)) { |
+ return nullptr; |
+ } |
+ |
+ return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); |
+} |
+ |