Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1290)

Unified Diff: src/effects/SkColorMatrixFilter.cpp

Issue 1041203004: clamp matrix-translate before converting to pmcolor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkColorMatrixFilter.cpp
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index 7c86e2e046a880d8914590db691f436d6e6de3b3..c2d4e48c7555b17f1f1f531f81388b0480886bb7 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -272,6 +272,10 @@ static Sk4s unpremul(const SkPMFloat& pm) {
return Sk4s(pm) * Sk4s(scale, scale, scale, 1);
}
+static Sk4f clamp_0_255(const Sk4f& value) {
+ return Sk4f::Max(Sk4f::Min(value, Sk4f(255)), Sk4f(0));
+}
+
void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const {
Proc proc = fProc;
if (NULL == proc) {
@@ -294,7 +298,8 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
const Sk4s c3 = Sk4s::Load(fTranspose + 12);
const Sk4s c4 = Sk4s::Load(fTranspose + 16); // translates
- SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(c4)).clamped();
+ // todo: we could cache this in the constructor...
+ SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(clamp_0_255(c4))).clamped();
for (int i = 0; i < count; i++) {
const SkPMColor src_c = src[i];
@@ -317,11 +322,8 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
// apply matrix
Sk4s dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4;
- // pin before re-premul (convention for color-matrix???)
- dst4 = Sk4s::Max(Sk4s(0), Sk4s::Min(Sk4s(255), dst4));
-
- // re-premul and write
- dst[i] = SkPMFloat(premul(dst4)).get();
+ // clamp, re-premul, and write
+ dst[i] = SkPMFloat(premul(clamp_0_255(dst4))).get();
}
} else {
const State& state = fState;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698