1 #include "Test.h" 2 #include "SkColor.h" 3 #include "SkUnPreMultiply.h" 4 5 static void test_premul(skiatest::Reporter* reporter) { 6 for (int a = 0; a <= 255; a++) { 7 for (int x = 0; x <= 255; x++) { 8 SkColor c0 = SkColorSetARGB(a, x, x, x); 9 SkPMColor p0 = SkPreMultiplyColor(c0); 10 11 SkColor c1 = SkUnPreMultiply::PMColorToColor(p0); 12 SkPMColor p1 = SkPreMultiplyColor(c1); 13 14 // we can't promise that c0 == c1, since c0 -> p0 is a many to one 15 // function, however, we can promise that p0 -> c1 -> p1 : p0 == p1 16 REPORTER_ASSERT(reporter, p0 == p1); 17 18 { 19 int ax = SkMulDiv255Ceiling(x, a); 20 REPORTER_ASSERT(reporter, ax <= a); 21 } 22 } 23 } 24 } 25 26 27 static void TestColor(skiatest::Reporter* reporter) { 28 test_premul(reporter); 29 } 30 31 #include "TestClassDef.h" 32 DEFINE_TESTCLASS("Color", ColorTestClass, TestColor) 33