Revert "Remove support for decoding to kIndex_8"

This reverts commit 742a3e298fda669006147e4a305bab8452369b1f.

Reason for revert: Breaking Android roll:
frameworks/base/core/jni/android/graphics/BitmapFactory.cpp:453:18: error: no member named 'fColorPtr' in 'SkAndroidCodec::AndroidOptions'
    codecOptions.fColorPtr = colorPtr;
    ~~~~~~~~~~~~ ^
frameworks/base/core/jni/android/graphics/BitmapFactory.cpp:454:18: error: no member named 'fColorCount' in 'SkAndroidCodec::AndroidOptions'
    codecOptions.fColorCount = colorCount;
    ~~~~~~~~~~~~ ^

Original change's description:
> Remove support for decoding to kIndex_8
> 
> Fix up callsites, and remove tests that no longer make sense.
> 
> Bug: skia:6828
> Change-Id: I2548c4b7528b7b1be7412563156f27b52c9d4295
> Reviewed-on: https://skia-review.googlesource.com/21664
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Leon Scroggins <scroggo@google.com>

TBR=djsollen@google.com,scroggo@google.com

Change-Id: I1bc669441f250690884e75a9a61427fdf75c6907
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:6828
Reviewed-on: https://skia-review.googlesource.com/22120
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 4bd3917..26b31ae 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -167,6 +167,19 @@
     return this->onRewind();
 }
 
+#define CHECK_COLOR_TABLE                                   \
+    if (kIndex_8_SkColorType == info.colorType()) {         \
+        if (nullptr == ctable || nullptr == ctableCount) {  \
+            return SkCodec::kInvalidParameters;             \
+        }                                                   \
+    } else {                                                \
+        if (ctableCount) {                                  \
+            *ctableCount = 0;                               \
+        }                                                   \
+        ctableCount = nullptr;                              \
+        ctable = nullptr;                                   \
+    }
+
 static void zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
                       SkIRect frameRect) {
     if (!frameRect.intersect(dstInfo.bounds())) {
@@ -192,6 +205,11 @@
         return kInvalidParameters;
     }
 
+    // index 8 is not supported beyond the first frame.
+    if (index < 0 || info.colorType() == kIndex_8_SkColorType) {
+        return kInvalidParameters;
+    }
+
     if (index >= this->onGetFrameCount()) {
         return kIncompleteInput;
     }
@@ -234,7 +252,8 @@
     Options prevFrameOptions(options);
     prevFrameOptions.fFrameIndex = requiredFrame;
     prevFrameOptions.fZeroInitialized = kNo_ZeroInitialized;
-    const Result result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions);
+    const Result result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions,
+                                          nullptr, nullptr);
     if (result == kSuccess) {
         const auto* prevFrame = frameHolder->getFrame(requiredFrame);
         const auto disposalMethod = prevFrame->getDisposalMethod();
@@ -247,7 +266,7 @@
 }
 
 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
-                                   const Options* options) {
+                                   const Options* options, SkPMColor ctable[], int* ctableCount) {
     if (kUnknown_SkColorType == info.colorType()) {
         return kInvalidConversion;
     }
@@ -258,6 +277,8 @@
         return kInvalidParameters;
     }
 
+    CHECK_COLOR_TABLE;
+
     if (!this->rewindIfNeeded()) {
         return kCouldNotRewind;
     }
@@ -293,7 +314,14 @@
     // On an incomplete decode, the subclass will specify the number of scanlines that it decoded
     // successfully.
     int rowsDecoded = 0;
-    const Result result = this->onGetPixels(info, pixels, rowBytes, *options, &rowsDecoded);
+    const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount,
+            &rowsDecoded);
+
+    if (ctableCount) {
+        if (kIncompleteInput == result || kSuccess == result || kErrorInInput == result) {
+            SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
+        }
+    }
 
     // A return value of kIncompleteInput indicates a truncated image stream.
     // In this case, we will fill any uninitialized memory with a default value.
@@ -314,8 +342,12 @@
     return result;
 }
 
+SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
+    return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr);
+}
+
 SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* pixels,
-        size_t rowBytes, const SkCodec::Options* options) {
+        size_t rowBytes, const SkCodec::Options* options, SkPMColor* ctable, int* ctableCount) {
     fStartedIncrementalDecode = false;
 
     if (kUnknown_SkColorType == info.colorType()) {
@@ -325,6 +357,9 @@
         return kInvalidParameters;
     }
 
+    // Ensure that valid color ptrs are passed in for kIndex8 color type
+    CHECK_COLOR_TABLE;
+
     // FIXME: If the rows come after the rows of a previous incremental decode,
     // we might be able to skip the rewind, but only the implementation knows
     // that. (e.g. PNG will always need to rewind, since we called longjmp, but
@@ -364,7 +399,8 @@
     fDstInfo = info;
     fOptions = *options;
 
-    const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, fOptions);
+    const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes,
+            fOptions, ctable, ctableCount);
     if (kSuccess == result) {
         fStartedIncrementalDecode = true;
     } else if (kUnimplemented == result) {
@@ -382,9 +418,11 @@
 
 
 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info,
-        const SkCodec::Options* options) {
+        const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) {
     // Reset fCurrScanline in case of failure.
     fCurrScanline = -1;
+    // Ensure that valid color ptrs are passed in for kIndex8 color type
+    CHECK_COLOR_TABLE;
 
     if (!this->rewindIfNeeded()) {
         return kCouldNotRewind;
@@ -412,7 +450,7 @@
         return kInvalidScale;
     }
 
-    const Result result = this->onStartScanlineDecode(info, *options);
+    const Result result = this->onStartScanlineDecode(info, *options, ctable, ctableCount);
     if (result != SkCodec::kSuccess) {
         return result;
     }
@@ -423,6 +461,12 @@
     return kSuccess;
 }
 
+#undef CHECK_COLOR_TABLE
+
+SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info) {
+    return this->startScanlineDecode(info, nullptr, nullptr, nullptr);
+}
+
 int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) {
     if (fCurrScanline < 0) {
         return 0;
@@ -486,7 +530,7 @@
             return (kOpaque_SkAlphaType == fSrcInfo.alphaType()) ? opaqueColor : transparentColor;
         }
         default: {
-            // This not only handles the kN32 case, but also k565, kGray8, since
+            // This not only handles the kN32 case, but also k565, kGray8, kIndex8, since
             // the low bits are zeros.
             return (kOpaque_SkAlphaType == fSrcInfo.alphaType()) ?
                     SK_ColorBLACK : SK_ColorTRANSPARENT;
@@ -539,6 +583,7 @@
         case kBGRA_8888_SkColorType:
             return SkColorSpaceXform::kBGRA_8888_ColorFormat;
         case kRGB_565_SkColorType:
+        case kIndex_8_SkColorType:
 #ifdef SK_PMCOLOR_IS_RGBA
             return SkColorSpaceXform::kRGBA_8888_ColorFormat;
 #else