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

Unified Diff: tests/ColorFilterTest.cpp

Issue 1069463002: add test for opaque-preserving colormatrixfilters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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: tests/ColorFilterTest.cpp
diff --git a/tests/ColorFilterTest.cpp b/tests/ColorFilterTest.cpp
index b2e37183b5e7b223cf1d545ee8138a5311e68b64..d0b0d77ed43a8a1547b07f501c49850194d65e0e 100644
--- a/tests/ColorFilterTest.cpp
+++ b/tests/ColorFilterTest.cpp
@@ -147,3 +147,89 @@ DEF_TEST(LumaColorFilter, reporter) {
REPORTER_ASSERT(reporter, SkGetPackedB32(out) == 0);
}
}
+
+///////////////////////////////////////////////////////////////////////////////
+
+#include "SkColorMatrixFilter.h"
+
+static void get_brightness_matrix(float amount, float matrix[20]) {
+ // Spec implementation
+ // (http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#brightnessEquivalent)
+ // <feFunc[R|G|B] type="linear" slope="[amount]">
+ memset(matrix, 0, 20 * sizeof(SkScalar));
+ matrix[0] = matrix[6] = matrix[12] = amount;
+ matrix[18] = 1.f;
+}
+
+static void get_grayscale_matrix(float amount, float matrix[20]) {
+ // Note, these values are computed to ensure MatrixNeedsClamping is false
+ // for amount in [0..1]
+ matrix[0] = 0.2126f + 0.7874f * amount;
+ matrix[1] = 0.7152f - 0.7152f * amount;
+ matrix[2] = 1.f - (matrix[0] + matrix[1]);
+ matrix[3] = matrix[4] = 0.f;
+
+ matrix[5] = 0.2126f - 0.2126f * amount;
+ matrix[6] = 0.7152f + 0.2848f * amount;
+ matrix[7] = 1.f - (matrix[5] + matrix[6]);
+ matrix[8] = matrix[9] = 0.f;
+
+ matrix[10] = 0.2126f - 0.2126f * amount;
+ matrix[11] = 0.7152f - 0.7152f * amount;
+ matrix[12] = 1.f - (matrix[10] + matrix[11]);
+ matrix[13] = matrix[14] = 0.f;
+
+ matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0.f;
+ matrix[18] = 1.f;
+}
+
+static SkColorFilter* make_cf0() {
+ SkScalar matrix[20];
+ get_brightness_matrix(0.5f, matrix);
+ return SkColorMatrixFilter::Create(matrix);
+}
+static SkColorFilter* make_cf1() {
+ SkScalar matrix[20];
+ get_grayscale_matrix(1, matrix);
+ return SkColorMatrixFilter::Create(matrix);
+}
+static SkColorFilter* make_cf2() {
+ SkColorMatrix m0, m1;
+ get_brightness_matrix(0.5f, m0.fMat);
+ get_grayscale_matrix(1, m1.fMat);
+ m0.preConcat(m1);
+ return SkColorMatrixFilter::Create(m0);
+}
+static SkColorFilter* make_cf3() {
+ SkColorMatrix m0, m1;
+ get_brightness_matrix(0.5f, m0.fMat);
+ get_grayscale_matrix(1, m1.fMat);
+ m0.postConcat(m1);
+ return SkColorMatrixFilter::Create(m0);
+}
+typedef SkColorFilter* (*CFProc)();
+
+// Test that a colormatrix that "should" preserve opaquness actually does.
+DEF_TEST(ColorMatrixFilter, reporter) {
+ const CFProc procs[] = {
+ make_cf0, make_cf1, make_cf2, make_cf3,
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
+ SkAutoTUnref<SkColorFilter> cf(procs[i]());
+
+ // generate all possible r,g,b triples
+ for (int r = 0; r < 256; ++r) {
+ for (int g = 0; g < 256; ++g) {
+ SkPMColor storage[256];
+ for (int b = 0; b < 256; ++b) {
+ storage[b] = SkPackARGB32(0xFF, r, g, b);
+ }
+ cf->filterSpan(storage, 256, storage);
+ for (int b = 0; b < 256; ++b) {
+ REPORTER_ASSERT(reporter, 0xFF == SkGetPackedA32(storage[b]));
+ }
+ }
+ }
+ }
+}
« 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