aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/SkTableColorFilter.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-05-04 10:57:40 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-04 15:21:39 +0000
commitb9641bd55a8f63757a63d9302755feb55d2e9502 (patch)
tree21cf4570aea3d430e9e5ef721d7e19f1b700dc5d /src/effects/SkTableColorFilter.cpp
parent342a9fa8e1c0bccff0d2d1569042bce29f2bbe85 (diff)
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>
Diffstat (limited to 'src/effects/SkTableColorFilter.cpp')
-rw-r--r--src/effects/SkTableColorFilter.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 0253e60b59..d9ce98a7d8 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 @@ public:
#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::filterSpan(const SkPMColor src[], int count, SkPMColor
}
}
+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;