diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-07 18:00:17 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-07 18:00:17 +0000 |
commit | 6c1ee2d4e727357451c8a6fcf4a08e75890b5d6d (patch) | |
tree | 144de7ce27c8400a39866d0f53f7be49aa935cda /tests/ColorFilterTest.cpp | |
parent | dd6cde5235d5d36607f4f1df66057d807b432b99 (diff) |
Luminance-to-alpha color filter (SkLumaColorFilter).
Adding a color filter luma implementation. The plan is to convert
existing clients and then deprecate SkLumaXfermode.
R=bsalomon@google.com, reed@google.com, robertphillips@google.com
Author: fmalita@chromium.org
Review URL: https://codereview.chromium.org/25453004
git-svn-id: http://skia.googlecode.com/svn/trunk@11636 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/ColorFilterTest.cpp')
-rw-r--r-- | tests/ColorFilterTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/ColorFilterTest.cpp b/tests/ColorFilterTest.cpp index 4016f2193d..b333ad68f0 100644 --- a/tests/ColorFilterTest.cpp +++ b/tests/ColorFilterTest.cpp @@ -7,7 +7,9 @@ */ #include "Test.h" #include "SkColor.h" +#include "SkColorPriv.h" #include "SkColorFilter.h" +#include "SkLumaColorFilter.h" #include "SkRandom.h" #include "SkXfermode.h" #include "SkOrderedReadBuffer.h" @@ -93,5 +95,38 @@ static void test_asColorMode(skiatest::Reporter* reporter) { } } +/////////////////////////////////////////////////////////////////////////////// + +static void test_lumaColorFilter(skiatest::Reporter* reporter) { + SkPMColor in, out; + SkAutoTUnref<SkColorFilter> lf(SkLumaColorFilter::Create()); + + // Applying luma to white is a nop (luminance(white) == 1.0) + for (unsigned i = 0; i < 256; ++i) { + in = SkPackARGB32(i, i, i, i); + lf->filterSpan(&in, 1, &out); + REPORTER_ASSERT(reporter, out == in); + } + + // Applying luma to black yields transparent black (luminance(black) == 0) + for (unsigned i = 0; i < 256; ++i) { + in = SkPackARGB32(i, 0, 0, 0); + lf->filterSpan(&in, 1, &out); + REPORTER_ASSERT(reporter, out == SK_ColorTRANSPARENT); + } + + // For general colors, a luma filter has an attenuating effect. + for (unsigned i = 1; i < 256; ++i) { + in = SkPackARGB32(i, i, i / 2, i / 3); + lf->filterSpan(&in, 1, &out); + REPORTER_ASSERT(reporter, out != in); + REPORTER_ASSERT(reporter, SkGetPackedA32(out) <= i); + REPORTER_ASSERT(reporter, SkGetPackedR32(out) <= i); + REPORTER_ASSERT(reporter, SkGetPackedG32(out) <= i / 2); + REPORTER_ASSERT(reporter, SkGetPackedB32(out) <= i / 3); + } +} + #include "TestClassDef.h" DEFINE_TESTCLASS("ColorFilter", ColorFilterTestClass, test_asColorMode) +DEFINE_TESTCLASS("LumaColorFilter", LumaColorFilterTestClass, test_lumaColorFilter) |