diff options
-rw-r--r-- | src/core/SkColorMatrixFilterRowMajor255.cpp | 4 | ||||
-rw-r--r-- | tests/ColorMatrixTest.cpp | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/core/SkColorMatrixFilterRowMajor255.cpp b/src/core/SkColorMatrixFilterRowMajor255.cpp index 4e598aa859..f7d0425dcb 100644 --- a/src/core/SkColorMatrixFilterRowMajor255.cpp +++ b/src/core/SkColorMatrixFilterRowMajor255.cpp @@ -158,9 +158,9 @@ void SkColorMatrixFilterRowMajor255::onAppendStages(SkRasterPipeline* p, if (!shaderIsOpaque) { p->append(SkRasterPipeline::unpremul); } if ( true) { p->append(SkRasterPipeline::matrix_4x5, fTranspose); } - if (!willStayOpaque) { p->append(SkRasterPipeline::premul); } if ( needsClamp0) { p->append(SkRasterPipeline::clamp_0); } - if ( needsClamp1) { p->append(SkRasterPipeline::clamp_a); } + if ( needsClamp1) { p->append(SkRasterPipeline::clamp_1); } + if (!willStayOpaque) { p->append(SkRasterPipeline::premul); } } sk_sp<SkColorFilter> diff --git a/tests/ColorMatrixTest.cpp b/tests/ColorMatrixTest.cpp index 7919b40242..baef52088b 100644 --- a/tests/ColorMatrixTest.cpp +++ b/tests/ColorMatrixTest.cpp @@ -99,3 +99,23 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) { DEF_TEST(ColorMatrix, reporter) { test_colorMatrixCTS(reporter); } + + +DEF_TEST(ColorMatrix_clamp_while_unpremul, r) { + // This matrix does green += 255/255 and alpha += 32/255. We want to test + // that if we pass it opaque alpha and small red and blue values, red and + // blue stay unchanged, not pumped up by that ~1.12 intermediate alpha. + SkScalar m[] = { + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 255, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 32, + }; + auto filter = SkColorFilter::MakeMatrixFilterRowMajor255(m); + + SkColor filtered = filter->filterColor(0xff0a0b0c); + REPORTER_ASSERT(r, SkColorGetA(filtered) == 0xff); + REPORTER_ASSERT(r, SkColorGetR(filtered) == 0x0a); + REPORTER_ASSERT(r, SkColorGetG(filtered) == 0xff); + REPORTER_ASSERT(r, SkColorGetB(filtered) == 0x0c); +} |