gather_i8

CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD

Change-Id: Ia7a133f515e29e16700aabc0633c77a703425f41
Reviewed-on: https://skia-review.googlesource.com/5239
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 134cc1c..3def5ec 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -289,7 +289,6 @@
     // TODO: all formats
     switch (info.colorType()) {
         case kAlpha_8_SkColorType:
-        case kIndex_8_SkColorType:
             return false;
         default: break;
     }
@@ -319,11 +318,11 @@
     }
 
     auto ctx = scratch->make<SkImageShaderContext>();
-
-    ctx->pixels   = pm.addr();
-    ctx->stride   = pm.rowBytesAsPixels();
-    ctx->width    = pm.width();
-    ctx->height   = pm.height();
+    ctx->pixels = pm.addr();
+    ctx->ctable = pm.ctable();
+    ctx->stride = pm.rowBytesAsPixels();
+    ctx->width  = pm.width();
+    ctx->height = pm.height();
     if (matrix.asAffine(ctx->matrix)) {
         p->append(SkRasterPipeline::matrix_2x3, ctx->matrix);
     } else {
@@ -343,6 +342,7 @@
             case kRepeat_TileMode: p->append(SkRasterPipeline::repeat_y, &ctx->height); break;
         }
         switch (info.colorType()) {
+            case kIndex_8_SkColorType:   p->append(SkRasterPipeline::gather_i8,   ctx); break;
             case kGray_8_SkColorType:    p->append(SkRasterPipeline::gather_g8,   ctx); break;
             case kRGB_565_SkColorType:   p->append(SkRasterPipeline::gather_565,  ctx); break;
             case kARGB_4444_SkColorType: p->append(SkRasterPipeline::gather_4444, ctx); break;
@@ -379,7 +379,11 @@
         p->append(SkRasterPipeline::move_dst_src);
     }
 
-    if (info.colorType() == kBGRA_8888_SkColorType) {
+    auto effective_color_type = [](SkColorType ct) {
+        return ct == kIndex_8_SkColorType ? kN32_SkColorType : ct;
+    };
+
+    if (effective_color_type(info.colorType()) == kBGRA_8888_SkColorType) {
         p->append(SkRasterPipeline::swap_rb);
     }
     if (info.alphaType() == kUnpremul_SkAlphaType) {