Guard to remove kIndex_8_SkColorType

Bug: skia:6828
Change-Id: Ia942a36abb18213184f8d436555a658270d97d47
Reviewed-on: https://skia-review.googlesource.com/22721
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Herb Derby <herb@google.com>
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 7a0130e..10d1c25 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -121,7 +121,12 @@
     /** Return true iff drawing this bitmap has no effect.
      */
     bool drawsNothing() const {
-        return this->colorType() == kIndex_8_SkColorType || this->empty() || this->isNull();
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
+        if (this->colorType() == kIndex_8_SkColorType) {
+            return true;
+        }
+#endif
+        return this->empty() || this->isNull();
     }
 
     /** Return the number of bytes between subsequent rows of the bitmap. */
@@ -424,8 +429,12 @@
         non-null colortable. Returns true if all of the above are met.
     */
     bool readyToDraw() const {
-        return this->getPixels() != NULL &&
-               (this->colorType() != kIndex_8_SkColorType || this->getColorTable());
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
+        if (this->colorType() == kIndex_8_SkColorType) {
+            return false;
+        }
+#endif
+        return this->getPixels() != NULL;
     }
 
     /** Return the bitmap's colortable, if it uses one (i.e. colorType is
@@ -725,6 +734,7 @@
     return (uint8_t*)fPixels + y * fRowBytes + x;
 }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const {
     SkASSERT(fPixels);
     SkASSERT(kIndex_8_SkColorType == this->colorType());
@@ -732,5 +742,6 @@
     SkASSERT(this->getColorTable());
     return (*this->getColorTable())[*((const uint8_t*)fPixels + y * fRowBytes + x)];
 }
+#endif
 
 #endif
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 4a8c286..551eb86 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -72,7 +72,9 @@
     kARGB_4444_SkColorType,
     kRGBA_8888_SkColorType,
     kBGRA_8888_SkColorType,
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     kIndex_8_SkColorType,
+#endif
     kGray_8_SkColorType,
     kRGBA_F16_SkColorType,
 
@@ -95,7 +97,9 @@
         2,  // ARGB_4444
         4,  // RGBA_8888
         4,  // BGRA_8888
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         1,  // kIndex_8
+#endif
         1,  // kGray_8
         8,  // kRGBA_F16
     };
@@ -114,7 +118,9 @@
         1,  // ARGB_4444
         2,  // RGBA_8888
         2,  // BGRA_8888
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         0,  // kIndex_8
+#endif
         0,  // kGray_8
         3,  // kRGBA_F16
     };
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index 1e79bba..be821ec 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -30,9 +30,12 @@
              SkColorTable* ctable = NULL)
         : fPixels(addr), fCTable(ctable), fRowBytes(rowBytes), fInfo(info)
     {
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         if (kIndex_8_SkColorType == info.colorType()) {
             SkASSERT(ctable);
-        } else {
+        } else
+#endif
+        {
             SkASSERT(NULL == ctable);
         }
     }
diff --git a/src/android/SkBitmapRegionCodec.cpp b/src/android/SkBitmapRegionCodec.cpp
index c4e1ea1..52774bc 100644
--- a/src/android/SkBitmapRegionCodec.cpp
+++ b/src/android/SkBitmapRegionCodec.cpp
@@ -57,7 +57,9 @@
     SkImageInfo decodeInfo = SkImageInfo::Make(scaledSize.width(), scaledSize.height(),
                                                dstColorType, dstAlphaType, dstColorSpace);
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     SkASSERT(dstColorType != kIndex_8_SkColorType);
+#endif
 
     // Initialize the destination bitmap
     int scaledOutX = 0;
diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp
index 6c9152b..8f3146e 100644
--- a/src/codec/SkAndroidCodec.cpp
+++ b/src/codec/SkAndroidCodec.cpp
@@ -17,6 +17,7 @@
     return sampleSize > 0;
 }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 /**
  *  Loads the gamut as a set of three points (triangle).
  */
@@ -59,6 +60,7 @@
 
     return false;
 }
+#endif
 
 SkAndroidCodec::SkAndroidCodec(SkCodec* codec)
     : fInfo(codec->getInfo())
@@ -110,7 +112,9 @@
         case kARGB_4444_SkColorType:
             return kN32_SkColorType;
         case kN32_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
             break;
         case kAlpha_8_SkColorType:
             // Fall through to kGray_8.  Before kGray_8_SkColorType existed,
@@ -148,6 +152,7 @@
     switch (outputColorType) {
         case kRGBA_8888_SkColorType:
         case kBGRA_8888_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType: {
             // If |prefColorSpace| is supported, choose it.
             SkColorSpaceTransferFn fn;
@@ -169,6 +174,7 @@
 
             return SkColorSpace::MakeSRGB();
         }
+#endif
         case kRGBA_F16_SkColorType:
             // Note that |prefColorSpace| is ignored, F16 is always linear sRGB.
             return SkColorSpace::MakeSRGBLinear();
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index 57f7fb8..79cb253 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -23,10 +23,11 @@
         newInfo = newInfo.makeAlphaType(kPremul_SkAlphaType);
     }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (kIndex_8_SkColorType == info.colorType()) {
         newInfo = newInfo.makeColorType(kN32_SkColorType);
     }
-
+#endif
     return newInfo;
 }
 
diff --git a/src/codec/SkSampler.cpp b/src/codec/SkSampler.cpp
index 244aa3b..0dbe320 100644
--- a/src/codec/SkSampler.cpp
+++ b/src/codec/SkSampler.cpp
@@ -57,9 +57,11 @@
             }
             break;
         }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             // On an index destination color type, always assume the input is an index.
             // Fall through
+#endif
         case kGray_8_SkColorType:
             // If the destination is kGray, the caller passes in an 8-bit color.
             // We will not assert that the high bits of colorOrIndex must be zeroed.
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
index 31fc063..c19dd05 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -104,6 +104,7 @@
 #undef GRAYSCALE_BLACK
 #undef GRAYSCALE_WHITE
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assigned to dst[x]
 static void swizzle_bit_to_index(
         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
@@ -124,6 +125,7 @@
         dst[x] = ((currByte >> (7-bitIndex)) & 1);
     }
 }
+#endif
 
 // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value assigned to dst[x]
 static void swizzle_bit_to_n32(
@@ -203,6 +205,7 @@
 
 // kIndex1, kIndex2, kIndex4
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 static void swizzle_small_index_to_index(
         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -223,6 +226,7 @@
         dst[x] = index;
     }
 }
+#endif
 
 static void swizzle_small_index_to_565(
         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
@@ -887,9 +891,11 @@
                             case kBGRA_8888_SkColorType:
                                 proc = &swizzle_bit_to_n32;
                                 break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
                             case kIndex_8_SkColorType:
                                 proc = &swizzle_bit_to_index;
                                 break;
+#endif
                             case kRGB_565_SkColorType:
                                 proc = &swizzle_bit_to_565;
                                 break;
@@ -970,9 +976,11 @@
                             case kRGB_565_SkColorType:
                                 proc = &swizzle_small_index_to_565;
                                 break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
                             case kIndex_8_SkColorType:
                                 proc = &swizzle_small_index_to_index;
                                 break;
+#endif
                             default:
                                 return nullptr;
                         }
@@ -990,10 +998,12 @@
                             case kRGB_565_SkColorType:
                                 proc = &swizzle_index_to_565;
                                 break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
                             case kIndex_8_SkColorType:
                                 proc = &sample1;
                                 fastProc = &copy;
                                 break;
+#endif
                             default:
                                 return nullptr;
                         }
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp
index fe9a291..aab0a41 100644
--- a/src/codec/SkWbmpCodec.cpp
+++ b/src/codec/SkWbmpCodec.cpp
@@ -25,7 +25,9 @@
     switch (dstInfo.colorType()) {
         case kRGBA_8888_SkColorType:
         case kBGRA_8888_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
         case kGray_8_SkColorType:
         case kRGB_565_SkColorType:
             return true;
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index e8e409a..096d505 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -311,7 +311,9 @@
         case kUnknown_SkColorType:
         case kAlpha_8_SkColorType:
         case kARGB_4444_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
         case kGray_8_SkColorType:
             SkASSERT(false);
             break;
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index e88fa5e..8f8d70f 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -242,9 +242,11 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) {
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (kIndex_8_SkColorType == requestedInfo.colorType()) {
         return reset_return_false(this);
     }
+#endif
     if (!this->setInfo(requestedInfo, rowBytes)) {
         return reset_return_false(this);
     }
@@ -268,9 +270,11 @@
 
 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, sk_sp<SkColorTable> ctable,
                               uint32_t allocFlags) {
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (kIndex_8_SkColorType == requestedInfo.colorType() && nullptr == ctable) {
         return reset_return_false(this);
     }
+#endif
     if (!this->setInfo(requestedInfo)) {
         return reset_return_false(this);
     }
@@ -428,7 +432,9 @@
                 base += x << 1;
                 break;
             case kAlpha_8_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
             case kIndex_8_SkColorType:
+#endif
             case kGray_8_SkColorType:
                 base += x;
                 break;
@@ -449,7 +455,9 @@
 
     switch (fInfo.colorType()) {
         case kUnknown_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
             // TODO: can we ASSERT that we never get here?
             return; // can't erase. Should we bzero so the memory is not uninitialized?
         default:
@@ -651,11 +659,14 @@
     }
     buffer->writeByteArray(storage.get(), size);
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     const SkColorTable* ct = pmap.ctable();
     if (kIndex_8_SkColorType == info.colorType() && ct) {
         buffer->writeBool(true);
         ct->writeToBuffer(*buffer);
-    } else {
+    } else
+#endif
+    {
         buffer->writeBool(false);
     }
 }
diff --git a/src/core/SkBlitter_Sprite.cpp b/src/core/SkBlitter_Sprite.cpp
index 99b185a..ff7d466 100644
--- a/src/core/SkBlitter_Sprite.cpp
+++ b/src/core/SkBlitter_Sprite.cpp
@@ -105,8 +105,12 @@
     {}
 
     static bool Supports(const SkPixmap& src) {
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         // We'd need to add a load_i8 stage.
         return src.colorType() != kIndex_8_SkColorType;
+#else
+        return true;
+#endif
     }
 
     void setup(const SkPixmap& dst, int left, int top, const SkPaint& paint) override {
diff --git a/src/core/SkConvertPixels.cpp b/src/core/SkConvertPixels.cpp
index 7859972..2f4c889 100644
--- a/src/core/SkConvertPixels.cpp
+++ b/src/core/SkConvertPixels.cpp
@@ -243,6 +243,7 @@
             }
             break;
         }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType: {
             SkASSERT(ctable);
             const uint32_t* table = ctable->readColors();
@@ -256,6 +257,7 @@
             }
             break;
         }
+#endif
         case kRGBA_F16_SkColorType: {
             auto src64 = (const uint64_t*) src;
             for (int y = 0; y < srcInfo.height(); y++) {
@@ -428,6 +430,7 @@
         return;
     }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     // Fast Path 4: Index 8 sources.
     if (kIndex_8_SkColorType == srcInfo.colorType()) {
         SkASSERT(ctable);
@@ -435,6 +438,7 @@
                             ctable, behavior);
         return;
     }
+#endif
 
     // Fast Path 5: Alpha 8 dsts.
     if (kAlpha_8_SkColorType == dstInfo.colorType()) {
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index ab76674..7ce944b 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -16,9 +16,14 @@
 
 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
                                  const Options* opts) {
-    if (kUnknown_SkColorType == info.colorType() || kIndex_8_SkColorType == info.colorType()) {
+    if (kUnknown_SkColorType == info.colorType()) {
         return false;
     }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
+    if (kIndex_8_SkColorType == info.colorType()) {
+        return false;
+    }
+#endif
     if (nullptr == pixels) {
         return false;
     }
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index 5d0710d..667b232 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -9,6 +9,66 @@
 #include "SkReadBuffer.h"
 #include "SkWriteBuffer.h"
 
+// These values must be constant over revisions, though they can be renamed to reflect if/when
+// they are deprecated.
+enum Stored_SkColorType {
+    kUnknown_Stored_SkColorType             = 0,
+    kAlpha_8_Stored_SkColorType             = 1,
+    kRGB_565_Stored_SkColorType             = 2,
+    kARGB_4444_Stored_SkColorType           = 3,
+    kRGBA_8888_Stored_SkColorType           = 4,
+    kBGRA_8888_Stored_SkColorType           = 5,
+    kIndex_8_Stored_SkColorType_DEPRECATED  = 6,
+    kGray_8_Stored_SkColorType              = 7,
+    kRGBA_F16_Stored_SkColorType            = 8,
+
+    kLast_Stored_SkColorType                = kRGBA_F16_Stored_SkColorType,
+};
+
+// Index with Stored_SkColorType
+const SkColorType gStoredToLive[] = {
+    kUnknown_SkColorType,
+    kAlpha_8_SkColorType,
+    kRGB_565_SkColorType,
+    kARGB_4444_SkColorType,
+    kRGBA_8888_SkColorType,
+    kBGRA_8888_SkColorType,
+    kUnknown_SkColorType,       // was kIndex_8
+    kGray_8_SkColorType,
+    kRGBA_F16_SkColorType,
+};
+
+// Index with SkColorType
+const Stored_SkColorType gLiveToStored[] = {
+    kUnknown_Stored_SkColorType,
+    kAlpha_8_Stored_SkColorType,
+    kRGB_565_Stored_SkColorType,
+    kARGB_4444_Stored_SkColorType,
+    kRGBA_8888_Stored_SkColorType,
+    kBGRA_8888_Stored_SkColorType,
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
+    kIndex_8_Stored_SkColorType_DEPRECATED,
+#endif
+    kGray_8_Stored_SkColorType,
+    kRGBA_F16_Stored_SkColorType,
+};
+
+static uint8_t live_to_stored(unsigned ct) {
+    static_assert(SK_ARRAY_COUNT(gLiveToStored) == (kLastEnum_SkColorType + 1), "");
+    SkASSERT(ct < SK_ARRAY_COUNT(gLiveToStored));
+
+    return gLiveToStored[ct];
+}
+
+static SkColorType stored_to_live(unsigned stored) {
+    static_assert(SK_ARRAY_COUNT(gStoredToLive) == (kLast_Stored_SkColorType + 1), "");
+    SkASSERT(stored < SK_ARRAY_COUNT(gStoredToLive));
+
+    return gStoredToLive[stored];
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
 static bool alpha_type_is_valid(SkAlphaType alphaType) {
     return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
 }
@@ -30,7 +90,7 @@
     fHeight = buffer.read32();
 
     uint32_t packed = buffer.read32();
-    fColorType = (SkColorType)((packed >> 0) & kColorTypeMask);
+    fColorType = stored_to_live((SkColorType)((packed >> 0) & kColorTypeMask));
     fAlphaType = (SkAlphaType)((packed >> 8) & kAlphaTypeMask);
     buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType));
 
@@ -44,7 +104,7 @@
 
     SkASSERT(0 == (fAlphaType & ~kAlphaTypeMask));
     SkASSERT(0 == (fColorType & ~kColorTypeMask));
-    uint32_t packed = (fAlphaType << 8) | fColorType;
+    uint32_t packed = (fAlphaType << 8) | live_to_stored(fColorType);
     buffer.write32(packed);
 
     if (fColorSpace) {
@@ -71,7 +131,9 @@
                 alphaType = kPremul_SkAlphaType;
             }
             // fall-through
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
         case kARGB_4444_SkColorType:
         case kRGBA_8888_SkColorType:
         case kBGRA_8888_SkColorType:
diff --git a/src/core/SkImageInfoPriv.h b/src/core/SkImageInfoPriv.h
index c9b4b6c..43680ad 100644
--- a/src/core/SkImageInfoPriv.h
+++ b/src/core/SkImageInfoPriv.h
@@ -111,6 +111,7 @@
         return false;
     }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (kIndex_8_SkColorType == dst.colorType()) {
         if (kIndex_8_SkColorType != src.colorType()) {
             return false;
@@ -126,6 +127,7 @@
             return false;
         }
     }
+#endif
 
     if (kGray_8_SkColorType == dst.colorType()) {
         if (kGray_8_SkColorType != src.colorType()) {
diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp
index cf2dfdc..8c4d062 100644
--- a/src/core/SkLinearBitmapPipeline.cpp
+++ b/src/core/SkLinearBitmapPipeline.cpp
@@ -372,9 +372,11 @@
 
     // If it is an index 8 color type, the sampler converts to unpremul for better fidelity.
     SkAlphaType alphaType = srcImageInfo.alphaType();
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (srcPixmap.colorType() == kIndex_8_SkColorType) {
         alphaType = kUnpremul_SkAlphaType;
     }
+#endif
 
     float postAlpha = SkColorGetA(paintColor) * (1.0f / 255.0f);
     // As the stages are built, the chooser function may skip a stage. For example, with the
@@ -596,8 +598,10 @@
             return this->chooseSpecificAccessor<kRGBA_8888_SkColorType>(srcPixmap, allocator);
         case kBGRA_8888_SkColorType:
             return this->chooseSpecificAccessor<kBGRA_8888_SkColorType>(srcPixmap, allocator);
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             return this->chooseSpecificAccessor<kIndex_8_SkColorType>(srcPixmap, allocator);
+#endif
         case kGray_8_SkColorType:
             return this->chooseSpecificAccessor<kGray_8_SkColorType>(srcPixmap, allocator);
         case kRGBA_F16_SkColorType: {
@@ -632,12 +636,14 @@
                         PixelAccessor<kN32_SkColorType, kSRGB_SkGammaType>, Blender>;
                     return allocator->make<Sampler>(next, srcPixmap);
                 }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
                 case kIndex_8_SkColorType: {
                     using Sampler =
                     NearestNeighborSampler<
                         PixelAccessor<kIndex_8_SkColorType, kSRGB_SkGammaType>, Blender>;
                     return allocator->make<Sampler>(next, srcPixmap);
                 }
+#endif
                 default:
                     break;
             }
@@ -649,12 +655,14 @@
                         PixelAccessor<kN32_SkColorType, kSRGB_SkGammaType>, Blender>;
                     return allocator->make<Sampler>(next, dimensions, xTile, yTile, srcPixmap);
                 }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
                 case kIndex_8_SkColorType: {
                     using Sampler =
                     BilerpSampler<
                         PixelAccessor<kIndex_8_SkColorType, kSRGB_SkGammaType>, Blender>;
                     return allocator->make<Sampler>(next, dimensions, xTile, yTile, srcPixmap);
                 }
+#endif
                 default:
                     break;
             }
diff --git a/src/core/SkLinearBitmapPipeline_sample.h b/src/core/SkLinearBitmapPipeline_sample.h
index a7f5d73..7459978 100644
--- a/src/core/SkLinearBitmapPipeline_sample.h
+++ b/src/core/SkLinearBitmapPipeline_sample.h
@@ -133,6 +133,7 @@
     }
 };
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 template <SkGammaType gammaType>
 class PixelConverter<kIndex_8_SkColorType, gammaType> {
 public:
@@ -166,7 +167,8 @@
     SkAutoMalloc        fColorTableStorage{kColorTableSize};
     Sk4f*               fColorTable;
 };
-
+#endif
+    
 template <SkGammaType gammaType>
 class PixelConverter<kGray_8_SkColorType, gammaType> {
 public:
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index cf4fac7..ce1c6c1 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -144,9 +144,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 static sk_sp<SkColorTable> sanitize(const SkImageInfo& info, sk_sp<SkColorTable> ctable) {
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (kIndex_8_SkColorType == info.colorType()) {
         SkASSERT(ctable);
-    } else {
+    } else
+#endif
+    {
         ctable.reset(nullptr);
     }
     return ctable;
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp
index 9646d7c..cbb40a8 100644
--- a/src/core/SkPixmap.cpp
+++ b/src/core/SkPixmap.cpp
@@ -272,11 +272,13 @@
         case kAlpha_8_SkColorType: {
             return SkColorSetA(0, *this->addr8(x, y));
         }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType: {
             SkASSERT(this->ctable());
             SkPMColor c = (*this->ctable())[*this->addr8(x, y)];
             return toColor(c);
         }
+#endif
         case kRGB_565_SkColorType: {
             return SkPixel16ToColor(*this->addr16(x, y));
         }
@@ -332,6 +334,7 @@
             }
             return true;
         } break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType: {
             const SkColorTable* ctable = this->ctable();
             if (nullptr == ctable) {
@@ -344,6 +347,7 @@
             }
             return 0xFF == SkGetPackedA32(c);
         } break;
+#endif
         case kRGB_565_SkColorType:
         case kGray_8_SkColorType:
             return true;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 35cd843..b9c63ac 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -113,6 +113,7 @@
         pmap = tmpPixmap;
         // must rebuild desc, since we've forced the info to be N32
         *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps);
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     } else if (kIndex_8_SkColorType == pixmap.colorType()) {
         SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.height());
         tmpBitmap->allocPixels(info);
@@ -125,6 +126,7 @@
         pmap = tmpPixmap;
         // must rebuild desc, since we've forced the info to be N32
         *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps);
+#endif
     }
 
     return pmap;
@@ -339,8 +341,10 @@
         case kBGRA_8888_SkColorType:
             return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
                    ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             return kSkia8888_GrPixelConfig;
+#endif
         case kGray_8_SkColorType:
             return kGray_8_GrPixelConfig;
         case kRGBA_F16_SkColorType:
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index 09130a6..809ada0 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -201,11 +201,13 @@
         fUniqueID = SkNextID::ImageID();
     }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     // colortables are poorly to not-at-all supported in our resourcecache, so we
     // bully them into N32 (the generator will perform the up-sample)
     if (fInfo.colorType() == kIndex_8_SkColorType) {
         fInfo = fInfo.makeColorType(kN32_SkColorType);
     }
+#endif
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -240,7 +242,9 @@
         , fInfo(validator->fInfo)
         , fOrigin(validator->fOrigin) {
     SkASSERT(fSharedGenerator);
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     SkASSERT(kIndex_8_SkColorType != fInfo.colorType());
+#endif
     // We explicit set the legacy format slot, but leave the others uninitialized (via SkOnce)
     // and only resolove them to IDs as needed (by calling getUniqueID()).
     fIDRecs[kLegacy_CachedFormat].fOnce([this, validator] {
@@ -307,9 +311,11 @@
             // TODO: Ask the codec to decode these to something else (at least sRGB 8888)?
             return kLegacy_CachedFormat;
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             SkDEBUGFAIL("Index_8 should have been remapped at construction time.");
             return kLegacy_CachedFormat;
+#endif
 
         case kGray_8_SkColorType:
             // TODO: What do we do with grayscale sources that have strange color spaces attached?
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index c69e5ff..eba6dc6 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -57,10 +57,11 @@
         if (kUnknown_SkColorType == info.colorType()) {
             return false;
         }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         if (kIndex_8_SkColorType == info.colorType()) {
             return false;
         }
-
+#endif
         if (rowBytes < info.minRowBytes()) {
             return false;
         }
diff --git a/src/images/SkJpegEncoder.cpp b/src/images/SkJpegEncoder.cpp
index a0ee398..ef78b21 100644
--- a/src/images/SkJpegEncoder.cpp
+++ b/src/images/SkJpegEncoder.cpp
@@ -113,6 +113,7 @@
             jpegColorType = JCS_RGB;
             numComponents = 3;
             break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             if (SkJpegEncoder::AlphaOption::kBlendOnBlack == options.fAlphaOption) {
                 return false;
@@ -122,6 +123,7 @@
             jpegColorType = JCS_RGB;
             numComponents = 3;
             break;
+#endif
         case kGray_8_SkColorType:
             SkASSERT(srcInfo.isOpaque());
             jpegColorType = JCS_GRAYSCALE;
diff --git a/src/images/SkPngEncoder.cpp b/src/images/SkPngEncoder.cpp
index b0c2b23..1e11269 100644
--- a/src/images/SkPngEncoder.cpp
+++ b/src/images/SkPngEncoder.cpp
@@ -115,6 +115,7 @@
             pngColorType = srcInfo.isOpaque() ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA;
             fPngBytesPerPixel = 8;
             break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             sigBit.red = 8;
             sigBit.green = 8;
@@ -123,6 +124,7 @@
             pngColorType = PNG_COLOR_TYPE_PALETTE;
             fPngBytesPerPixel = 1;
             break;
+#endif
         case kGray_8_SkColorType:
             sigBit.gray = 8;
             pngColorType = PNG_COLOR_TYPE_GRAY;
@@ -250,7 +252,9 @@
                     SkASSERT(false);
                     return nullptr;
             }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
         case kGray_8_SkColorType:
             return transform_scanline_memcpy;
         case kRGBA_F16_SkColorType:
@@ -270,6 +274,7 @@
     }
 }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 /*
  * Pack palette[] with the corresponding colors, and if the image has alpha, also
  * pack trans[] and return the number of alphas[] entries written. If the image is
@@ -331,6 +336,7 @@
 
     return numWithAlpha;
 }
+#endif
 
 bool SkPngEncoderMgr::setPalette(const SkImageInfo& srcInfo, SkColorTable* colorTable,
                                  SkTransferFunctionBehavior unpremulBehavior) {
@@ -338,6 +344,7 @@
         return false;
     }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     png_color paletteColors[256];
     png_byte trans[256];
     if (kIndex_8_SkColorType == srcInfo.colorType()) {
@@ -351,7 +358,7 @@
             png_set_tRNS(fPngPtr, fInfoPtr, trans, numTrans, nullptr);
         }
     }
-
+#endif
     return true;
 }
 
diff --git a/src/images/SkWebpEncoder.cpp b/src/images/SkWebpEncoder.cpp
index 296d4f4..a5d0ffa 100644
--- a/src/images/SkWebpEncoder.cpp
+++ b/src/images/SkWebpEncoder.cpp
@@ -86,6 +86,7 @@
                 default:
                     return nullptr;
             }
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
             switch (info.alphaType()) {
                 case kOpaque_SkAlphaType:
@@ -98,6 +99,7 @@
                 default:
                     return nullptr;
             }
+#endif
         case kGray_8_SkColorType:
             return transform_scanline_gray;
         case kRGBA_F16_SkColorType:
@@ -147,6 +149,7 @@
     }
 
     const SkPMColor* colors = nullptr;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     SkPMColor storage[256];
     if (kIndex_8_SkColorType == pixmap.colorType()) {
         if (!pixmap.ctable()) {
@@ -162,6 +165,7 @@
             colors = storage;
         }
     }
+#endif
 
     WebPConfig webp_config;
     if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, opts.fQuality)) {
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index 68d5272..47facff 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -20,13 +20,16 @@
     SkColorSpace* legacyColorSpace = nullptr;
     if(as_IB(image)->getROPixels(dst, legacyColorSpace)
        && dst->dimensions() == image->dimensions()) {
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         if (dst->colorType() != kIndex_8_SkColorType) {
             return;
         }
         if (!dst->getColorTable()) {
             // We can't use an indexed bitmap with no colortable.
             dst->reset();
-        } else {
+        } else
+#endif
+        {
             return;
         }
     }
@@ -163,7 +166,9 @@
         case kBGRA_8888_SkColorType:
             return 3;
         case kAlpha_8_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
         case kGray_8_SkColorType:
             return 1;
         case kUnknown_SkColorType:
@@ -234,7 +239,9 @@
             fill_stream(out, '\x00', pixel_count(bm));
             return;
         case kGray_8_SkColorType:
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType:
+#endif
             SkASSERT(1 == pdf_color_component_count(colorType));
             // these two formats need no transformation to serialize.
             for (int y = 0; y < bm.height(); ++y) {
@@ -277,6 +284,7 @@
                 out->write(bm.getAddr8(0, y), bm.width());
             }
             return;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
         case kIndex_8_SkColorType: {
             SkColorTable* ct = bm.getColorTable();
             SkASSERT(ct);
@@ -291,6 +299,7 @@
             }
             return;
         }
+#endif
         case kRGB_565_SkColorType:
         case kGray_8_SkColorType:
             SkDEBUGFAIL("color type has no alpha");
@@ -304,6 +313,7 @@
     }
 }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
 static sk_sp<SkPDFArray> make_indexed_color_space(
         const SkColorTable* table,
         SkAlphaType alphaType) {
@@ -341,6 +351,7 @@
     result->appendString(tableString);
     return result;
 }
+#endif
 
 static void emit_image_xobject(SkWStream* stream,
                                const SkImage* image,
@@ -366,11 +377,13 @@
     pdfDict.insertInt("Height", bitmap.height());
     if (alpha) {
         pdfDict.insertName("ColorSpace", "DeviceGray");
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     } else if (bitmap.colorType() == kIndex_8_SkColorType) {
         SkASSERT(1 == pdf_color_component_count(bitmap.colorType()));
         pdfDict.insertObject("ColorSpace",
                              make_indexed_color_space(bitmap.getColorTable(),
                                                       bitmap.alphaType()));
+#endif
     } else if (1 == pdf_color_component_count(bitmap.colorType())) {
         pdfDict.insertName("ColorSpace", "DeviceGray");
     } else {
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index f8f0f88..1fc9145 100644
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -326,7 +326,9 @@
         }
         switch (info.colorType()) {
             case kAlpha_8_SkColorType:   p->append(SkRasterPipeline::gather_a8,   gather); break;
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
             case kIndex_8_SkColorType:   p->append(SkRasterPipeline::gather_i8,   gather); break;
+#endif
             case kGray_8_SkColorType:    p->append(SkRasterPipeline::gather_g8,   gather); break;
             case kRGB_565_SkColorType:   p->append(SkRasterPipeline::gather_565,  gather); break;
             case kARGB_4444_SkColorType: p->append(SkRasterPipeline::gather_4444, gather); break;
@@ -390,9 +392,11 @@
         p->append(SkRasterPipeline::move_dst_src);
     }
 
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
     if (info.colorType() == kIndex_8_SkColorType && kN32_SkColorType == kBGRA_8888_SkColorType) {
         p->append(SkRasterPipeline::swap_rb);
     }
+#endif
     if (info.colorType() == kAlpha_8_SkColorType) {
         p->append(SkRasterPipeline::set_rgb, &misc->paint_color);
     }
diff --git a/tools/debugger/SkObjectParser.cpp b/tools/debugger/SkObjectParser.cpp
index 227532a..57f7d91 100644
--- a/tools/debugger/SkObjectParser.cpp
+++ b/tools/debugger/SkObjectParser.cpp
@@ -28,7 +28,11 @@
     mBitmap->appendS32(bitmap.height());
 
     const char* gColorTypeStrings[] = {
-        "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8", "G8", "RGBAf16"
+        "None", "A8", "565", "4444", "RGBA", "BGRA",
+#ifdef SK_SUPPORT_LEGACY_INDEX_8_COLORTYPE
+        "Index8",
+#endif
+        "G8", "RGBAf16"
     };
     static_assert(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings),
                   "colortype names do not match colortype enum");