remove alphatype from colortable

the owning bitmap is (already) responsible for knowing the alphatype

BUG=skia:
R=djsollen@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/611093002
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp
index e9ba1dc..efd6d96 100644
--- a/bench/BitmapBench.cpp
+++ b/bench/BitmapBench.cpp
@@ -44,7 +44,7 @@
             }
         }
     }
-    SkColorTable* ctable = new SkColorTable(storage, 216, aType);
+    SkColorTable* ctable = new SkColorTable(storage, 216);
     dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, aType),
                      NULL, ctable);
     ctable->unref();
diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp
index cf29b6a..cf147d8 100644
--- a/bench/RepeatTileBench.cpp
+++ b/bench/RepeatTileBench.cpp
@@ -63,7 +63,7 @@
             }
         }
     }
-    SkColorTable* ctable = new SkColorTable(storage, 216, kOpaque_SkAlphaType);
+    SkColorTable* ctable = new SkColorTable(storage, 216);
     dst->allocPixels(SkImageInfo::Make(src.width(), src.height(),
                                        kIndex_8_SkColorType, kOpaque_SkAlphaType),
                      NULL, ctable);
diff --git a/include/core/SkColorTable.h b/include/core/SkColorTable.h
index c73b431..00ef854 100644
--- a/include/core/SkColorTable.h
+++ b/include/core/SkColorTable.h
@@ -26,16 +26,9 @@
     /** Makes a deep copy of colors.
      */
     SkColorTable(const SkColorTable& src);
-    SkColorTable(const SkPMColor colors[], int count,
-                 SkAlphaType alphaType = kPremul_SkAlphaType);
+    SkColorTable(const SkPMColor colors[], int count);
     virtual ~SkColorTable();
 
-    SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; }
-
-    bool isOpaque() const {
-        return SkAlphaTypeIsOpaque(this->alphaType());
-    }
-
     /** Returns the number of colors in the table.
     */
     int count() const { return fCount; }
@@ -44,7 +37,7 @@
         the index is in range (0 <= index < count).
     */
     SkPMColor operator[](int index) const {
-        SkASSERT(fColors != NULL && (unsigned)index < fCount);
+        SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount);
         return fColors[index];
     }
 
@@ -81,11 +74,12 @@
 private:
     SkPMColor*  fColors;
     uint16_t*   f16BitCache;
-    uint16_t    fCount;
-    uint8_t     fAlphaType;
+    int         fCount;
     SkDEBUGCODE(int fColorLockCount;)
     SkDEBUGCODE(int f16BitCacheLockCount;)
 
+    void init(const SkPMColor* colors, int count);
+
     void inval16BitCache();
 
     typedef SkRefCnt INHERITED;
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index af4f123..9da8de9 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -249,13 +249,14 @@
     // V33: Serialize only public API of effects.
     // V34: Add SkTextBlob serialization.
     // V35: Store SkRect (rather then width & height) in header
+    // V36: Remove (obsolete) alphatype from SkColorTable
 
     // Note: If the picture version needs to be increased then please follow the
     // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
 
     // Only SKPs within the min/current picture version range (inclusive) can be read.
     static const uint32_t MIN_PICTURE_VERSION = 19;
-    static const uint32_t CURRENT_PICTURE_VERSION = 35;
+    static const uint32_t CURRENT_PICTURE_VERSION = 36;
 
     mutable uint32_t      fUniqueID;
 
diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp
index e05d074..d825c71 100644
--- a/samplecode/SampleDitherBitmap.cpp
+++ b/samplecode/SampleDitherBitmap.cpp
@@ -57,11 +57,10 @@
     for (int i = 0; i < 256; i++) {
         c[i] = SkPackARGB32(0xFF, i, 0, 0);
     }
-    SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType);
+    SkColorTable* ctable = new SkColorTable(c, 256);
 
     SkBitmap bm;
-    bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType,
-                                     kPremul_SkAlphaType),
+    bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, kPremul_SkAlphaType),
                    NULL, ctable);
     ctable->unref();
 
diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp
index 2607f9a..f2eab61 100644
--- a/src/core/SkColorTable.cpp
+++ b/src/core/SkColorTable.cpp
@@ -13,44 +13,36 @@
 #include "SkStream.h"
 #include "SkTemplates.h"
 
-// As copy constructor is hidden in the class hierarchy, we need to call
-// default constructor explicitly to suppress a compiler warning.
-SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() {
-    f16BitCache = NULL;
-    fAlphaType = src.fAlphaType;
-    int count = src.count();
-    fCount = SkToU16(count);
-    fColors = reinterpret_cast<SkPMColor*>(
-                                    sk_malloc_throw(count * sizeof(SkPMColor)));
-    memcpy(fColors, src.fColors, count * sizeof(SkPMColor));
+void SkColorTable::init(const SkPMColor colors[], int count) {
+    SkASSERT((unsigned)count <= 256);
 
+    f16BitCache = NULL;
+    fCount = count;
+    fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));
+    
+    memcpy(fColors, colors, count * sizeof(SkPMColor));
+    
     SkDEBUGCODE(fColorLockCount = 0;)
     SkDEBUGCODE(f16BitCacheLockCount = 0;)
 }
 
-SkColorTable::SkColorTable(const SkPMColor colors[], int count, SkAlphaType at)
-    : f16BitCache(NULL), fAlphaType(SkToU8(at))
-{
-    SkASSERT(0 == count || colors);
+// As copy constructor is hidden in the class hierarchy, we need to call
+// default constructor explicitly to suppress a compiler warning.
+SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() {
+    this->init(src.fColors, src.fCount);
+}
 
+SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
+    SkASSERT(0 == count || colors);
     if (count < 0) {
         count = 0;
     } else if (count > 256) {
         count = 256;
     }
-
-    fCount = SkToU16(count);
-    fColors = reinterpret_cast<SkPMColor*>(
-                                    sk_malloc_throw(count * sizeof(SkPMColor)));
-
-    memcpy(fColors, colors, count * sizeof(SkPMColor));
-
-    SkDEBUGCODE(fColorLockCount = 0;)
-    SkDEBUGCODE(f16BitCacheLockCount = 0;)
+    this->init(colors, count);
 }
 
-SkColorTable::~SkColorTable()
-{
+SkColorTable::~SkColorTable() {
     SkASSERT(fColorLockCount == 0);
     SkASSERT(f16BitCacheLockCount == 0);
 
@@ -73,9 +65,6 @@
 }
 
 const uint16_t* SkColorTable::lock16BitCache() {
-    // Assert that we're opaque, since our 16-bit cache will be sort of useless
-    // if there is alpha (which we're throwing away)
-    SkASSERT(this->isOpaque());
     if (NULL == f16BitCache) {
         f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
         build_16bitcache(f16BitCache, fColors, fCount);
@@ -92,7 +81,10 @@
     SkDEBUGCODE(fColorLockCount = 0;)
     SkDEBUGCODE(f16BitCacheLockCount = 0;)
 
-    fAlphaType = SkToU8(buffer.readUInt());
+    if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
+        /*fAlphaType = */buffer.readUInt();
+    }
+
     fCount = buffer.getArrayCount();
     size_t allocSize = fCount * sizeof(SkPMColor);
     SkDEBUGCODE(bool success = false;)
@@ -110,6 +102,5 @@
 }
 
 void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const {
-    buffer.writeUInt(fAlphaType);
     buffer.writeColorArray(fColors, fCount);
 }
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index a5b9830..b073847 100644
--- a/src/core/SkReadBuffer.h
+++ b/src/core/SkReadBuffer.h
@@ -49,6 +49,7 @@
         kImageFilterUniqueID_Version       = 31,
         kRemoveAndroidPaintOpts_Version    = 32,
         kFlattenCreateProc_Version         = 33,
+        kRemoveColorTableAlpha_Version     = 36,
     };
 
     /**
diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp
index 745f4e1..81071c9 100644
--- a/src/images/SkImageDecoder_libgif.cpp
+++ b/src/images/SkImageDecoder_libgif.cpp
@@ -332,7 +332,6 @@
                 // Declare colorPtr here for scope.
                 SkPMColor colorPtr[256]; // storage for worst-case
                 const ColorMapObject* cmap = find_colormap(gif);
-                SkAlphaType alphaType = kOpaque_SkAlphaType;
                 if (cmap != NULL) {
                     SkASSERT(cmap->ColorCount == (1 << (cmap->BitsPerPixel)));
                     colorCount = cmap->ColorCount;
@@ -355,16 +354,13 @@
                 transpIndex = find_transpIndex(temp_save, colorCount);
                 if (transpIndex >= 0) {
                     colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a transparent SkPMColor
-                    alphaType = kPremul_SkAlphaType;
                     fillIndex = transpIndex;
                 } else if (fillIndex >= colorCount) {
                     // gif->SBackGroundColor should be less than colorCount.
                     fillIndex = 0;  // If not, fix it.
                 }
 
-                SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable,
-                                                  (colorPtr, colorCount,
-                                                   alphaType)));
+                SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, (colorPtr, colorCount)));
                 if (!this->allocPixelRef(bm, ctable)) {
                     return error_return(*bm, "allocPixelRef");
                 }
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index dd1d1c8..7911a29 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -709,17 +709,7 @@
         *colorPtr = colorPtr[-1];
     }
 
-    SkAlphaType alphaType = kOpaque_SkAlphaType;
-    if (reallyHasAlpha) {
-        if (this->getRequireUnpremultipliedColors()) {
-            alphaType = kUnpremul_SkAlphaType;
-        } else {
-            alphaType = kPremul_SkAlphaType;
-        }
-    }
-
-    *colorTablep = SkNEW_ARGS(SkColorTable,
-                              (colorStorage, colorCount, alphaType));
+    *colorTablep = SkNEW_ARGS(SkColorTable, (colorStorage, colorCount));
     *reallyHasAlphap = reallyHasAlpha;
     return true;
 }
diff --git a/src/images/SkImageDecoder_wbmp.cpp b/src/images/SkImageDecoder_wbmp.cpp
index ddb7c3d..0bf1389 100644
--- a/src/images/SkImageDecoder_wbmp.cpp
+++ b/src/images/SkImageDecoder_wbmp.cpp
@@ -119,7 +119,7 @@
     }
 
     const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
-    SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2, kOpaque_SkAlphaType));
+    SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2));
     SkAutoUnref   aur(ct);
 
     if (!this->allocPixelRef(decodedBitmap, ct)) {
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 3923846..eb7c663 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -61,11 +61,11 @@
     }
 }
 
-static SkColorTable* init_ctable(SkAlphaType alphaType) {
+static SkColorTable* init_ctable() {
     static const SkColor colors[] = {
         SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
     };
-    return new SkColorTable(colors, SK_ARRAY_COUNT(colors), alphaType);
+    return new SkColorTable(colors, SK_ARRAY_COUNT(colors));
 }
 
 struct Pair {
@@ -196,19 +196,16 @@
 
 static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
                               SkColorType ct) {
-    SkColorTable* ctOpaque = NULL;
-    SkColorTable* ctPremul = NULL;
+    SkColorTable* ctable = NULL;
     if (kIndex_8_SkColorType == ct) {
-        ctOpaque = init_ctable(kOpaque_SkAlphaType);
-        ctPremul = init_ctable(kPremul_SkAlphaType);
+        ctable = init_ctable();
     }
 
     srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType),
-                           NULL, ctOpaque);
+                           NULL, ctable);
     srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType),
-                           NULL, ctPremul);
-    SkSafeUnref(ctOpaque);
-    SkSafeUnref(ctPremul);
+                           NULL, ctable);
+    SkSafeUnref(ctable);
     init_src(*srcOpaque);
     init_src(*srcPremul);
 }
@@ -384,7 +381,7 @@
             SkBitmap src, subset;
             SkColorTable* ct = NULL;
             if (kIndex_8_SkColorType == src.colorType()) {
-                ct = init_ctable(kPremul_SkAlphaType);
+                ct = init_ctable();
             }
 
             int localSubW;