trim down colortable impl

Bug: skia:
Change-Id: I2a7d3719ccde753b723d33231be49b028ff1c313
Reviewed-on: https://skia-review.googlesource.com/26304
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index e96e968..005e215 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -700,28 +700,10 @@
     }
 
     if (buffer->readBool()) {
-        sk_sp<SkColorTable> ctable = SkColorTable::Create(*buffer);
-        if (!ctable) {
+        SkColorTable::Skip(*buffer);
+        if (!buffer->isValid()) {
             return false;
         }
-
-        if (info.isEmpty()) {
-            // require an empty ctable
-            if (ctable->count() != 0) {
-                buffer->validate(false);
-                return false;
-            }
-        } else {
-            // require a non-empty ctable
-            if (ctable->count() == 0) {
-                buffer->validate(false);
-                return false;
-            }
-            unsigned char maxIndex = ctable->count() - 1;
-            for (uint64_t i = 0; i < ramSize; ++i) {
-                dst[i] = SkTMin(dst[i], maxIndex);
-            }
-        }
     }
 
     sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithData(info, info.minRowBytes(),
diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp
index 2816de9..fab3c3d 100644
--- a/src/core/SkColorTable.cpp
+++ b/src/core/SkColorTable.cpp
@@ -5,15 +5,13 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkColorTable.h"
 #include "SkReadBuffer.h"
 #include "SkWriteBuffer.h"
-#include "SkStream.h"
-#include "SkTemplates.h"
 
-void SkColorTable::init(const SkPMColor colors[], int count) {
-    SkASSERT((unsigned)count <= 256);
+SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
+    SkASSERT(0 == count || colors);
+    SkASSERT(count >= 0 && count <= 256);
 
     fCount = count;
     fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));
@@ -21,92 +19,15 @@
     memcpy(fColors, colors, count * sizeof(SkPMColor));
 }
 
-SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
-    SkASSERT(0 == count || colors);
-    SkASSERT(count >= 0 && count <= 256);
-    this->init(colors, count);
-}
-
-SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc)
-    : fColors(colors)
-    , fCount(count)
-{
-    SkASSERT(count > 0 && count <= 256);
-    SkASSERT(colors);
-}
-
 SkColorTable::~SkColorTable() {
     sk_free(fColors);
-    sk_free(f16BitCache);
 }
 
-#include "SkColorPriv.h"
-
-const uint16_t* SkColorTable::read16BitCache() const {
-    f16BitCacheOnce([this] {
-        f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
-        for (int i = 0; i < fCount; i++) {
-            f16BitCache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
-        }
-    });
-    return f16BitCache;
-}
-
-sk_sp<SkColorTable> SkColorTable::Make(const SkPMColor colors[], int count) {
-    if (count < 0 || count > 256) {
-        return nullptr;
-    }
-    if (count && !colors) {
-        return nullptr;
-    }
-    return sk_make_sp<SkColorTable>(colors, count);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-#if 0
-SkColorTable::SkColorTable(SkReadBuffer& buffer) {
-    if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
-        /*fAlphaType = */buffer.readUInt();
-    }
-
-    fCount = buffer.getArrayCount();
-    size_t allocSize = fCount * sizeof(SkPMColor);
-    SkDEBUGCODE(bool success = false;)
-    if (buffer.validateAvailable(allocSize)) {
-        fColors = (SkPMColor*)sk_malloc_throw(allocSize);
-        SkDEBUGCODE(success =) buffer.readColorArray(fColors, fCount);
-    } else {
-        fCount = 0;
-        fColors = nullptr;
-    }
-#ifdef SK_DEBUG
-    SkASSERT((unsigned)fCount <= 256);
-    SkASSERT(success);
-#endif
-}
-#endif
-
-void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const {
-    buffer.writeColorArray(fColors, fCount);
-}
-
-sk_sp<SkColorTable> SkColorTable::Create(SkReadBuffer& buffer) {
+void SkColorTable::Skip(SkReadBuffer& buffer) {
     const int count = buffer.getArrayCount();
-    if (0 == count) {
-        return sk_sp<SkColorTable>(new SkColorTable(nullptr, 0));
-    }
-
     if (count < 0 || count > 256) {
         buffer.validate(false);
-        return nullptr;
+    } else {
+        buffer.skip(count * sizeof(SkPMColor));
     }
-
-    const size_t allocSize = count * sizeof(SkPMColor);
-    std::unique_ptr<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize));
-    if (!buffer.readColorArray(colors.get(), count)) {
-        return nullptr;
-    }
-
-    return sk_sp<SkColorTable>(new SkColorTable(colors.release(), count, kAllocatedWithMalloc));
 }
diff --git a/src/core/SkColorTable.h b/src/core/SkColorTable.h
index ca5efd1..ef8712d 100644
--- a/src/core/SkColorTable.h
+++ b/src/core/SkColorTable.h
@@ -22,10 +22,8 @@
 
     SkColorTable is thread-safe.
 */
-class SK_API SkColorTable : public SkRefCnt {
+class SkColorTable : public SkRefCnt {
 public:
-    static sk_sp<SkColorTable> Make(const SkPMColor colors[], int count);
-
     /** Copy up to 256 colors into a new SkColorTable.
      */
     SkColorTable(const SkPMColor colors[], int count);
@@ -43,34 +41,15 @@
         return fColors[index];
     }
 
-    /** Return the array of colors for reading.
-     */
+    /** Return the array of colors for reading. */
     const SkPMColor* readColors() const { return fColors; }
 
-    /** read16BitCache() returns the array of RGB16 colors that mirror the 32bit colors.
-     */
-    const uint16_t* read16BitCache() const;
-
-    void writeToBuffer(SkWriteBuffer&) const;
-
     // may return null
-    static sk_sp<SkColorTable> Create(SkReadBuffer&);
+    static void Skip(SkReadBuffer&);
 
 private:
-    enum AllocatedWithMalloc {
-        kAllocatedWithMalloc
-    };
-    // assumes ownership of colors (assumes it was allocated w/ malloc)
-    SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc);
-
-    SkPMColor*            fColors;
-    mutable uint16_t*     f16BitCache = nullptr;
-    mutable SkOnce        f16BitCacheOnce;
-    int                   fCount;
-
-    void init(const SkPMColor* colors, int count);
-
-    friend class SkImageGenerator;
+    SkPMColor*  fColors;
+    int         fCount;
 
     typedef SkRefCnt INHERITED;
 };