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

Unified Diff: tests/ColorFilterTest.cpp

Issue 25453004: Luminance-to-alpha color filter (SkLumaColorFilter). (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added test & more docs. Created 7 years, 2 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 | « src/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ColorFilterTest.cpp
diff --git a/tests/ColorFilterTest.cpp b/tests/ColorFilterTest.cpp
index 4016f2193d58a3e14cc3bddf0c33cb2f8b19bfc3..b333ad68f090af838ecf604e829e4fca9bad56db 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)
« no previous file with comments | « src/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698