reed@google.com | 83acbe0 | 2011-04-22 19:18:20 +0000 | [diff] [blame^] | 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 | } |
| 20 | |
| 21 | |
| 22 | static void TestColor(skiatest::Reporter* reporter) { |
| 23 | test_premul(reporter); |
| 24 | } |
| 25 | |
| 26 | #include "TestClassDef.h" |
| 27 | DEFINE_TESTCLASS("Color", ColorTestClass, TestColor) |