Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2392)

Unified Diff: src/core/SkColorTable.cpp

Issue 1307023004: change colortable to use factory for reinflating, check for empty (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: doh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
+
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698