release-request-05263112-375a-4b1f-a657-a14bb2a5c5a3-for-git_oc-mr1-release-4185249 snap-temp-L63000000082739046

Change-Id: I006cce1d727701b7648b24823122e36c5d996c24
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 7e23f97..e536b67 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -593,10 +593,27 @@
       break;
     }
     case 8:
+      // we upscale ctables to 32bit.
       if (pSource->GetPalette()) {
-        *ctPtr =
-            new SkColorTable(pSource->GetPalette(), pSource->GetPaletteSize());
-        colorType = SkColorType::kIndex_8_SkColorType;
+        dst32Storage.reset(FX_Alloc2D(uint32_t, width, height));
+        SkPMColor* dst32Pixels = dst32Storage.get();
+        const SkPMColor* ctable = pSource->GetPalette();
+        const unsigned ctableSize = pSource->GetPaletteSize();
+        for (int y = 0; y < height; ++y) {
+          const uint8_t* srcRow =
+              static_cast<const uint8_t*>(buffer) + y * rowBytes;
+          uint32_t* dstRow = dst32Pixels + y * width;
+          for (int x = 0; x < width; ++x) {
+            unsigned index = srcRow[x];
+            if (index >= ctableSize) {
+              index = 0;
+            }
+            dstRow[x] = ctable[index];
+          }
+        }
+        buffer = dst32Storage.get();
+        rowBytes = width * sizeof(uint32_t);
+        colorType = SkColorType::kN32_SkColorType;
       }
       break;
     case 24: {