Remove more SkColorSpaceXform (and friends)

- gammaencodedpremul GM was just demonstrating something that we
  understand well (and have much better testing for).
- readpixels GM was filled with workarounds for things that are no
  longer true (unpremul images, clamped F16).
- Other uses can be switched to SkConvertPixels trivially.
- Remove SkColorSpaceXformPriv and SkColorLookUpTable, all unused.
- Remove SkColorSpaceXform_skcms.cpp, no longer referenced by clients.

Bug: skia:
Change-Id: I7298bb53aa61b49ad1398ebc504d35c119fd5cf4
Reviewed-on: https://skia-review.googlesource.com/157153
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/bench/ColorSpaceXformBench.cpp b/bench/ColorSpaceXformBench.cpp
index 1a76228..7bddac6 100644
--- a/bench/ColorSpaceXformBench.cpp
+++ b/bench/ColorSpaceXformBench.cpp
@@ -8,7 +8,6 @@
 #include "../src/jumper/SkJumper.h"
 #include "Benchmark.h"
 #include "SkColor.h"
-#include "SkColorSpaceXform.h"
 #include "SkColorSpaceXformer.h"
 #include "SkColorSpaceXformSteps.h"
 #include "SkMakeUnique.h"
@@ -16,14 +15,13 @@
 #include "SkRandom.h"
 #include "SkRasterPipeline.h"
 
-enum class Mode { xform, steps, pipeA, pipeB, xformer };
+enum class Mode { steps, pipeA, pipeB, xformer };
 
 struct ColorSpaceXformBench : public Benchmark {
     ColorSpaceXformBench(Mode mode) : fMode(mode) {}
 
     const Mode fMode;
 
-    std::unique_ptr<SkColorSpaceXform>                  fXform;
     std::unique_ptr<SkColorSpaceXformSteps>             fSteps;
     std::function<void(size_t, size_t, size_t, size_t)> fPipeA;
 
@@ -35,7 +33,6 @@
 
     const char* onGetName() override {
         switch (fMode) {
-            case Mode::xform  : return "ColorSpaceXformBench_xform";
             case Mode::steps  : return "ColorSpaceXformBench_steps";
             case Mode::pipeA  : return "ColorSpaceXformBench_pipeA";
             case Mode::pipeB  : return "ColorSpaceXformBench_pipeB";
@@ -51,7 +48,6 @@
                             dst = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
                                                         SkColorSpace::kDCIP3_D65_Gamut);
 
-        fXform = SkColorSpaceXform::New(src.get(), dst.get());
         fSteps = skstd::make_unique<SkColorSpaceXformSteps>(src.get(), kOpaque_SkAlphaType,
                                                             dst.get(), kPremul_SkAlphaType);
 
@@ -76,12 +72,6 @@
             fPipeDst.pixels = &dst;
 
             switch (fMode) {
-                case Mode::xform: {
-                    fXform->apply(SkColorSpaceXform::kBGRA_8888_ColorFormat, &dst,
-                                  SkColorSpaceXform::kBGRA_8888_ColorFormat, &src,
-                                  1, kUnpremul_SkAlphaType);
-                } break;
-
                 case Mode::steps: {
                     float rgba[4];
                     swizzle_rb(Sk4f_fromL32(src)).store(rgba);
@@ -116,7 +106,6 @@
     }
 };
 
-DEF_BENCH(return new ColorSpaceXformBench{Mode::xform  };)
 DEF_BENCH(return new ColorSpaceXformBench{Mode::steps  };)
 DEF_BENCH(return new ColorSpaceXformBench{Mode::pipeA  };)
 DEF_BENCH(return new ColorSpaceXformBench{Mode::pipeB  };)
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 375d468..5b5c292 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -21,7 +21,6 @@
 #include "SkCodec.h"
 #include "SkCodecImageGenerator.h"
 #include "SkColorSpace.h"
-#include "SkColorSpaceXform.h"
 #include "SkColorSpaceXformCanvas.h"
 #include "SkCommonFlags.h"
 #include "SkCommonFlagsGpu.h"
diff --git a/gm/gammaencodedpremul.cpp b/gm/gammaencodedpremul.cpp
deleted file mode 100644
index 1d7bb57..0000000
--- a/gm/gammaencodedpremul.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "gm.h"
-#include "SkColorPriv.h"
-#include "SkColorSpaceXform.h"
-#include "SkColorSpaceXformPriv.h"
-#include "SkOpts.h"
-#include "SkUtils.h"
-
-static void clamp_to_alpha(uint32_t* pixels, int count) {
-    for (int i = 0; i < count; i++) {
-        uint8_t a = SkGetPackedA32(pixels[i]);
-        uint8_t r = SkGetPackedR32(pixels[i]);
-        uint8_t g = SkGetPackedG32(pixels[i]);
-        uint8_t b = SkGetPackedB32(pixels[i]);
-        pixels[i] = SkPackARGB32(a,
-                                 SkTMin(a, r),
-                                 SkTMin(a, g),
-                                 SkTMin(a, b));
-    }
-}
-
-class GammaEncodedPremulGM : public skiagm::GM {
-public:
-    GammaEncodedPremulGM(sk_sp<SkColorSpace> dst, sk_sp<SkColorSpace> src, const char* desc)
-        : fDstSpace(dst)
-        , fSrcSpace(src)
-        , fXform(SkColorSpaceXform::New(src.get(), dst.get()))
-        , fName(SkStringPrintf("gamma_encoded_premul_dst-v-src_%s", desc))
-    {
-        int i = 0;
-        for (int r = 0; r < kColorSteps; r++) {
-            for (int g = 0; g < kColorSteps; g++) {
-                for (int b = 0; b < kColorSteps; b++) {
-                    fColors[i++] = SkColorSetRGB(r * kColorScale,
-                                                 g * kColorScale,
-                                                 b * kColorScale);
-                }
-            }
-        }
-
-    }
-
-protected:
-    virtual SkISize onISize() override {
-        return SkISize::Make(kAlphaMax, kNumColors * 2 * kStripeHeight);
-    }
-
-    SkString onShortName() override {
-        return fName;
-    }
-
-    void onDraw(SkCanvas* canvas) override {
-        if (canvas->imageInfo().isOpaque()) {
-            return;
-        }
-
-        SkBitmap bitmap;
-        SkImageInfo bitmapInfo = SkImageInfo::MakeN32Premul(kAlphaMax, 1,
-                canvas->imageInfo().refColorSpace());
-        bitmap.allocPixels(bitmapInfo);
-        uint32_t* pixels = bitmap.getAddr32(0, 0);
-
-        for (int i = 0; i < kNumColors; i++) {
-            // Create an entire row of the same color, with the alpha from 0 to kAlphaMax.
-            uint32_t row[kAlphaMax];
-            sk_memset32(row, fColors[i], kAlphaMax);
-            for (int a = 0; a < kAlphaMax; a++) {
-                row[a] = (row[a] & 0x00FFFFFF) | (a << 24);
-            }
-
-            // Tranform row to dst, then premultiply.
-            fXform->apply(select_xform_format(kN32_SkColorType), pixels,
-                          SkColorSpaceXform::kBGRA_8888_ColorFormat, row, kAlphaMax,
-                          kUnpremul_SkAlphaType);
-            SkOpts::RGBA_to_rgbA(pixels, pixels, kAlphaMax);
-            bitmap.notifyPixelsChanged();
-
-            // Write the dst space premultiplied row to the canvas.
-            for (int j = 0; j < kStripeHeight; j++) {
-                canvas->drawBitmap(bitmap, 0, 2 * i * kStripeHeight + j);
-            }
-
-            // Premultiply, then transform the row to dst.
-            SkOpts::RGBA_to_rgbA(pixels, row, kAlphaMax);
-            fXform->apply(select_xform_format(kN32_SkColorType), pixels,
-                          SkColorSpaceXform::kBGRA_8888_ColorFormat, pixels, kAlphaMax,
-                          kUnpremul_SkAlphaType);
-            clamp_to_alpha(pixels, kAlphaMax);
-            bitmap.notifyPixelsChanged();
-
-            // Write the src space premultiplied row to the canvas.
-            for (int j = 0; j < kStripeHeight; j++) {
-                canvas->drawBitmap(bitmap, 0, (2 * i + 1) * kStripeHeight + j);
-            }
-        }
-    }
-
-private:
-    static constexpr int kColorSteps = 4;
-    static constexpr int kNumColors = kColorSteps * kColorSteps * kColorSteps;
-    static constexpr int kColorScale = 255 / (kColorSteps - 1);
-    static constexpr int kStripeHeight = 10;
-    static constexpr int kAlphaMax = 255;
-
-    sk_sp<SkColorSpace>                fDstSpace;
-    sk_sp<SkColorSpace>                fSrcSpace;
-    std::unique_ptr<SkColorSpaceXform> fXform;
-    SkString                           fName;
-    SkColor                            fColors[kNumColors];
-
-    typedef GM INHERITED;
-};
-
-DEF_GM(return new GammaEncodedPremulGM(SkColorSpace::MakeSRGB(),
-        SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kRec2020_Gamut),
-        "toWideGamut");)
-DEF_GM(return new GammaEncodedPremulGM(SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
-        SkColorSpace::kRec2020_Gamut), SkColorSpace::MakeSRGB(), "fromWideGamut");)
-DEF_GM(return new GammaEncodedPremulGM(SkColorSpace::MakeSRGB(),
-        SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, SkColorSpace::kSRGB_Gamut),
-        "toLinear");)
-DEF_GM(return new GammaEncodedPremulGM(
-        SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, SkColorSpace::kSRGB_Gamut),
-        SkColorSpace::MakeSRGB(), "fromLinear");)
-DEF_GM(return new GammaEncodedPremulGM(
-        SkColorSpace::MakeRGB({ 1.8f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
-        SkColorSpace::kSRGB_Gamut), SkColorSpace::MakeSRGB(), "from1.8");)
diff --git a/gm/readpixels.cpp b/gm/readpixels.cpp
index acb821c..9defff4 100644
--- a/gm/readpixels.cpp
+++ b/gm/readpixels.cpp
@@ -10,36 +10,11 @@
 #include "SkCodec.h"
 #include "SkColorSpace.h"
 #include "SkColorSpacePriv.h"
-#include "SkColorSpaceXform.h"
-#include "SkColorSpaceXformPriv.h"
 #include "SkHalf.h"
 #include "SkImage.h"
 #include "SkImageInfoPriv.h"
 #include "SkPictureRecorder.h"
 
-static void clamp_if_necessary(const SkImageInfo& info, void* pixels) {
-    if (kRGBA_F16_SkColorType != info.colorType()) {
-        return;
-    }
-
-    for (int y = 0; y < info.height(); y++) {
-        for (int x = 0; x < info.width(); x++) {
-            uint64_t pixel = ((uint64_t*) pixels)[y * info.width() + x];
-
-            Sk4f rgba = SkHalfToFloat_finite_ftz(pixel);
-            if (kUnpremul_SkAlphaType == info.alphaType()) {
-                rgba = Sk4f::Max(0.0f, Sk4f::Min(rgba, 1.0f));
-            } else {
-                SkASSERT(kPremul_SkAlphaType == info.alphaType());
-                rgba = Sk4f::Max(0.0f, Sk4f::Min(rgba, rgba[3]));
-            }
-            SkFloatToHalf_finite_ftz(rgba).store(&pixel);
-
-            ((uint64_t*) pixels)[y * info.width() + x] = pixel;
-        }
-    }
-}
-
 static const int kWidth = 64;
 static const int kHeight = 64;
 
@@ -129,20 +104,6 @@
         memset(data->writable_data(), 0, rowBytes * image->height());
     }
 
-    // SkImage must be premul, so manually premul the data if we unpremul'd during readPixels
-    if (kUnpremul_SkAlphaType == dstAlphaType) {
-        auto xform = SkColorSpaceXform::New(dstColorSpace.get(), dstColorSpace.get());
-        if (!xform->apply(select_xform_format(dstColorType), data->writable_data(),
-                          select_xform_format(dstColorType), data->data(),
-                          image->width() * image->height(), kPremul_SkAlphaType)) {
-            memset(data->writable_data(), 0, rowBytes * image->height());
-        }
-        dstInfo = dstInfo.makeAlphaType(kPremul_SkAlphaType);
-    }
-
-    // readPixels() does not always clamp F16.  The drawing code expects pixels in the 0-1 range.
-    clamp_if_necessary(dstInfo, data->writable_data());
-
     // Now that we have called readPixels(), dump the raw pixels into an srgb image.
     sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
     sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorSpace(srgb), data, rowBytes);
diff --git a/gn/core.gni b/gn/core.gni
index 059131a..65d3892 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -70,8 +70,6 @@
   "$_src/core/SkClipStackDevice.h",
   "$_src/core/SkColor.cpp",
   "$_src/core/SkColorFilter.cpp",
-  "$_src/core/SkColorLookUpTable.cpp",
-  "$_src/core/SkColorLookUpTable.h",
   "$_src/core/SkColorMatrixFilterRowMajor255.cpp",
   "$_src/core/SkColorMatrixFilterRowMajor255.h",
   "$_src/core/SkColorSpace.cpp",
diff --git a/gn/gm.gni b/gn/gm.gni
index a3e6938..8eb4aea 100644
--- a/gn/gm.gni
+++ b/gn/gm.gni
@@ -1,7 +1,7 @@
 # Copyright 2016 Google Inc.
 #
 # Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.

+# found in the LICENSE file.
 
 # Things are easiest for everyone if these source paths are absolute.
 _gm = get_path_info("../gm", "abspath")
@@ -144,7 +144,6 @@
   "$_gm/fontscaler.cpp",
   "$_gm/fontscalerdistortable.cpp",
   "$_gm/gamma.cpp",
-  "$_gm/gammaencodedpremul.cpp",
   "$_gm/gammatext.cpp",
   "$_gm/gamut.cpp",
   "$_gm/getpostextpath.cpp",
diff --git a/public.bzl b/public.bzl
index 2c8b6ea..2ce0abf 100644
--- a/public.bzl
+++ b/public.bzl
@@ -263,9 +263,6 @@
         # Atlas text
         "src/atlastext/*",
 
-        # Not time for skcms in Google3 yet.
-        "src/core/SkColorSpaceXform_skcms.cpp",
-
         # Compute backend not yet even hooked into Skia.
         "src/compute/**/*",
     ],
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index b986121..ece8f7b 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -1011,7 +1011,7 @@
     // interlaced scanline decoder may need to rewind.
     fSwizzler.reset(nullptr);
 
-    // If SkColorSpaceXform directly supports the encoded PNG format, we should skip format
+    // If skcms directly supports the encoded PNG format, we should skip format
     // conversion in the swizzler (or skip swizzling altogether).
     bool skipFormatConversion = false;
     switch (this->getEncodedInfo().color()) {
diff --git a/src/core/SkColorLookUpTable.cpp b/src/core/SkColorLookUpTable.cpp
deleted file mode 100644
index f376621..0000000
--- a/src/core/SkColorLookUpTable.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkColorLookUpTable.h"
-#include "SkColorSpaceXformPriv.h"
-#include "SkFloatingPoint.h"
-
-SkColorLookUpTable::SkColorLookUpTable(uint8_t inputChannels, const uint8_t limits[]) {
-    fInputChannels = inputChannels;
-    SkASSERT(inputChannels >= 1 && inputChannels <= kMaxColorChannels);
-    memcpy(fLimits, limits, fInputChannels * sizeof(uint8_t));
-
-    for (int i = 0; i < inputChannels; i++) {
-        SkASSERT(fLimits[i] > 1);
-    }
-}
diff --git a/src/core/SkColorLookUpTable.h b/src/core/SkColorLookUpTable.h
deleted file mode 100644
index f7d6245..0000000
--- a/src/core/SkColorLookUpTable.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkColorLookUpTable_DEFINED
-#define SkColorLookUpTable_DEFINED
-
-#include "SkNx.h"
-#include "SkRefCnt.h"
-#include "SkTemplates.h"
-
-// TODO: scope inside SkColorLookUpTable
-static constexpr uint8_t kMaxColorChannels = 4;
-
-class SkColorLookUpTable : public SkRefCnt {
-public:
-    static constexpr uint8_t kOutputChannels = 3;
-
-    SkColorLookUpTable(uint8_t inputChannels, const uint8_t limits[]);
-
-    int  inputChannels() const { return  fInputChannels; }
-    int outputChannels() const { return kOutputChannels; }
-
-    // TODO: Rename to somethingBetter(int)?
-    int gridPoints(int dimension) const {
-        SkASSERT(dimension >= 0 && dimension < inputChannels());
-        return fLimits[dimension];
-    }
-
-    // Objects of this type are created in a custom fashion using sk_malloc_throw
-    // and therefore must be sk_freed.
-    void* operator new(size_t size) = delete;
-    void* operator new(size_t, void* p) { return p; }
-    void operator delete(void* p) { sk_free(p); }
-
-    const float* table() const {
-        return SkTAddOffset<const float>(this, sizeof(SkColorLookUpTable));
-    }
-
-private:
-    uint8_t fInputChannels;
-    uint8_t fLimits[kMaxColorChannels];
-};
-
-#endif
diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp
index 4781e90..e683294 100644
--- a/src/core/SkColorSpaceXform.cpp
+++ b/src/core/SkColorSpaceXform.cpp
@@ -6,15 +6,10 @@
  */
 
 #include "SkColorSpaceXform.h"
-#include "SkColorSpaceXformPriv.h"
 #include "SkData.h"
 #include "SkMakeUnique.h"
 #include "../../third_party/skcms/skcms.h"
 
-std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* src, SkColorSpace* dst) {
-    return SkMakeColorSpaceXform(src, dst);
-}
-
 bool SkColorSpaceXform::Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst,
                               SkColorSpace* srcCS, ColorFormat srcFormat, const void* src,
                               int len, AlphaOp op) {
@@ -92,7 +87,7 @@
     skcms_SetXYZD50(profile, &m);
 }
 
-std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, SkColorSpace* dst) {
+std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* src, SkColorSpace* dst) {
     if (src && dst && dst->toXYZD50()) {
         // Construct skcms_ICCProfiles from each color space. For now, support A2B and XYZ.
         // Eventually, only need to support XYZ.
diff --git a/src/core/SkColorSpaceXformPriv.h b/src/core/SkColorSpaceXformPriv.h
deleted file mode 100644
index f75ebf4..0000000
--- a/src/core/SkColorSpaceXformPriv.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkColorSpaceXformPriv_DEFINED
-#define SkColorSpaceXformPriv_DEFINED
-
-#include "SkColorSpaceXform.h"
-
-std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, SkColorSpace* dst);
-
-static inline SkColorSpaceXform::ColorFormat select_xform_format(SkColorType colorType) {
-    switch (colorType) {
-        case kRGBA_8888_SkColorType:
-            return SkColorSpaceXform::kRGBA_8888_ColorFormat;
-        case kBGRA_8888_SkColorType:
-            return SkColorSpaceXform::kBGRA_8888_ColorFormat;
-        case kRGBA_F16_SkColorType:
-            return SkColorSpaceXform::kRGBA_F16_ColorFormat;
-        case kRGB_565_SkColorType:
-            return SkColorSpaceXform::kBGR_565_ColorFormat;
-        default:
-            SkASSERT(false);
-            return SkColorSpaceXform::kRGBA_8888_ColorFormat;
-    }
-}
-
-#endif
diff --git a/src/core/SkColorSpaceXform_skcms.cpp b/src/core/SkColorSpaceXform_skcms.cpp
deleted file mode 100644
index 79e372a..0000000
--- a/src/core/SkColorSpaceXform_skcms.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkColorSpaceXform.h"
-
-// Leaving this file around temporarily until client build files no longer refer to it
diff --git a/src/core/SkColorSpaceXformer.cpp b/src/core/SkColorSpaceXformer.cpp
index 1380047..65feaec 100644
--- a/src/core/SkColorSpaceXformer.cpp
+++ b/src/core/SkColorSpaceXformer.cpp
@@ -8,7 +8,6 @@
 #include "SkColorFilter.h"
 #include "SkColorSpacePriv.h"
 #include "SkColorSpaceXformer.h"
-#include "SkColorSpaceXformPriv.h"
 #include "SkDrawLooper.h"
 #include "SkGradientShader.h"
 #include "SkImage.h"
diff --git a/src/core/SkColorSpaceXformer.h b/src/core/SkColorSpaceXformer.h
index d2fd70e..f4b3faf 100644
--- a/src/core/SkColorSpaceXformer.h
+++ b/src/core/SkColorSpaceXformer.h
@@ -19,7 +19,6 @@
 class SkBitmap;
 class SkColorFilter;
 class SkColorSpace;
-class SkColorSpaceXform;
 class SkImage;
 class SkImageFilter;
 class SkPaint;
diff --git a/src/core/SkDraw_vertices.cpp b/src/core/SkDraw_vertices.cpp
index b9bc2e6..33fba60 100644
--- a/src/core/SkDraw_vertices.cpp
+++ b/src/core/SkDraw_vertices.cpp
@@ -8,6 +8,7 @@
 #include "SkArenaAlloc.h"
 #include "SkAutoBlitterChoose.h"
 #include "SkComposeShader.h"
+#include "SkConvertPixels.h"
 #include "SkDraw.h"
 #include "SkNx.h"
 #include "SkPM4f.h"
@@ -19,7 +20,6 @@
 
 #include "SkArenaAlloc.h"
 #include "SkCoreBlitters.h"
-#include "SkColorSpaceXform.h"
 
 struct Matrix43 {
     float fMat[12];    // column major
@@ -137,18 +137,13 @@
 // - apply per-color alpha before interpolation (matches old version of vertices)
 //
 static SkPMColor4f* convert_colors(const SkColor src[], int count, SkColorSpace* deviceCS,
-                                 SkArenaAlloc* alloc) {
+                                   SkArenaAlloc* alloc) {
     SkPMColor4f* dst = alloc->makeArray<SkPMColor4f>(count);
-    if (!deviceCS) {
-        for (int i = 0; i < count; ++i) {
-            dst[i] = SkColor4f::FromColor(src[i]).premul();
-        }
-    } else {
-        auto srcCS = SkColorSpace::MakeSRGB();
-        SkColorSpaceXform::Apply(deviceCS   , SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
-                                 srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
-                                 count, SkColorSpaceXform::kPremul_AlphaOp);
-    }
+    SkImageInfo srcInfo = SkImageInfo::Make(count, 1, kBGRA_8888_SkColorType,
+                                            kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());
+    SkImageInfo dstInfo = SkImageInfo::Make(count, 1, kRGBA_F32_SkColorType,
+                                            kPremul_SkAlphaType, sk_ref_sp(deviceCS));
+    SkConvertPixels(dstInfo, dst, 0, srcInfo, src, 0);
     return dst;
 }
 
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 859014f..36e7d91 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -9,7 +9,6 @@
 #include "SkBitmap.h"
 #include "SkBitmapProcShader.h"
 #include "SkCanvas.h"
-#include "SkColorSpaceXformPriv.h"
 #include "SkColorTable.h"
 #include "SkConvertPixels.h"
 #include "SkData.h"