force all colorfilters to implement 4f

high-contrast gms differ at most by 1 bit

Bug: skia:
Change-Id: I1308bd105020ea3cd5a30fd3dd322ed134fb5ed5
Reviewed-on: https://skia-review.googlesource.com/15249
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 0253e60..d9ce98a 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -1,12 +1,12 @@
 /*
-* Copyright 2015 Google Inc.
-*
-* Use of this source code is governed by a BSD-style license that can be
-* found in the LICENSE file.
-*/
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
 
 #include "SkTableColorFilter.h"
-
+#include "SkPM4f.h"
 #include "SkArenaAlloc.h"
 #include "SkBitmap.h"
 #include "SkColorPriv.h"
@@ -90,6 +90,7 @@
 #endif
 
     void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override;
+    void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const override;
 
     SK_TO_STRING_OVERRIDE()
 
@@ -185,6 +186,41 @@
     }
 }
 
+void SkTable_ColorFilter::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
+    const uint8_t* table = fStorage;
+    const uint8_t* tableA = gIdentityTable;
+    const uint8_t* tableR = gIdentityTable;
+    const uint8_t* tableG = gIdentityTable;
+    const uint8_t* tableB = gIdentityTable;
+    if (fFlags & kA_Flag) {
+        tableA = table; table += 256;
+    }
+    if (fFlags & kR_Flag) {
+        tableR = table; table += 256;
+    }
+    if (fFlags & kG_Flag) {
+        tableG = table; table += 256;
+    }
+    if (fFlags & kB_Flag) {
+        tableB = table;
+    }
+
+    const float oneOver255 = 1.0f / 255;
+    for (int i = 0; i < count; ++i) {
+        SkColor4f c = src[i].unpremul();
+        int r = (int)(c.fR * 255.999) & 0xFF;
+        int g = (int)(c.fG * 255.999) & 0xFF;
+        int b = (int)(c.fB * 255.999) & 0xFF;
+        int a = (int)(c.fA * 255.999) & 0xFF;
+
+        SkColor4f d {
+            tableR[r] * oneOver255, tableG[g] * oneOver255,
+            tableB[b] * oneOver255, tableA[a] * oneOver255,
+        };
+        dst[i] = d.premul();
+    }
+}
+
 #ifndef SK_IGNORE_TO_STRING
 void SkTable_ColorFilter::toString(SkString* str) const {
     const uint8_t* table = fStorage;