Simplify SkCodecs' call to SkColorSpaceXform::apply

Most SkCodec subclasses did the following to apply their
SkColorSpaceXform:
  dstFormat = select_xform_format(dstInfo.colorType());
  srcFormat = select_xform_format(<something that doesn't change>);
  xformAlphaType = select_xform_alpha(dstInfo.alphaType(),
                                      this->getInfo().alphaType());
  this->colorXform()->apply(dstFormat, dst, srcFormat, src, width,
                            xformAlphaType);

Consolidate the computation of these parameters into SkCodec and add a
new method to SkCodec that calls apply() with those parameters.

Add a SkColorSpaceXform::ColorFormat to SkCodec. This allows the new
method SkCodec::applyColorXform to supply the ColorFormat.

TBR=reed@google.com
(No change to public API.)

Change-Id: I8ea7ba4c0024be827a9f9359796c778744330f6e
Reviewed-on: https://skia-review.googlesource.com/18523
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp
index c223678..959e75b 100644
--- a/src/codec/SkBmpStandardCodec.cpp
+++ b/src/codec/SkBmpStandardCodec.cpp
@@ -28,7 +28,6 @@
     , fIsOpaque(isOpaque)
     , fInIco(inIco)
     , fAndMaskRowBytes(fInIco ? SkAlign4(compute_row_bytes(this->getInfo().width(), 1)) : 0)
-    , fXformOnDecode(false)
 {}
 
 /*
@@ -123,13 +122,8 @@
             colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0);
         }
 
-        if (this->colorXform() && !fXformOnDecode) {
-            SkColorSpaceXform::ColorFormat dstFormat = select_xform_format_ct(dstColorType);
-            SkColorSpaceXform::ColorFormat srcFormat = SkColorSpaceXform::kBGRA_8888_ColorFormat;
-            SkAlphaType xformAlphaType = select_xform_alpha(dstAlphaType,
-                                                            this->getInfo().alphaType());
-            SkAssertResult(this->colorXform()->apply(dstFormat, colorTable, srcFormat, colorTable,
-                                                     maxColors, xformAlphaType));
+        if (this->colorXform() && !this->xformOnDecode()) {
+            this->applyColorXform(colorTable, colorTable, maxColors);
         }
 
         // Set the color table
@@ -198,12 +192,8 @@
 
 SkCodec::Result SkBmpStandardCodec::onPrepareToDecode(const SkImageInfo& dstInfo,
         const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) {
-    fXformOnDecode = false;
-    if (this->colorXform()) {
-        fXformOnDecode = apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color());
-        if (fXformOnDecode) {
-            this->resetXformBuffer(dstInfo.width());
-        }
+    if (this->xformOnDecode()) {
+        this->resetXformBuffer(dstInfo.width());
     }
 
     // Create the color table if necessary and prepare the stream for decode
@@ -240,11 +230,10 @@
 
         void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
 
-        if (fXformOnDecode) {
+        if (this->xformOnDecode()) {
             SkASSERT(this->colorXform());
-            SkImageInfo xformInfo = dstInfo.makeWH(fSwizzler->swizzleWidth(), dstInfo.height());
             fSwizzler->swizzle(this->xformBuffer(), this->srcBuffer());
-            this->applyColorXform(xformInfo, dstRow, this->xformBuffer());
+            this->applyColorXform(dstRow, this->xformBuffer(), fSwizzler->swizzleWidth());
         } else {
             fSwizzler->swizzle(dstRow, this->srcBuffer());
         }