OLD | NEW |
1 #include "SkPMFloat.h" | 1 #include "SkPMFloat.h" |
2 #include "Test.h" | 2 #include "Test.h" |
3 | 3 |
4 DEF_TEST(SkPMFloat, r) { | 4 DEF_TEST(SkPMFloat, r) { |
5 // Test SkPMColor <-> SkPMFloat | 5 // Test SkPMColor <-> SkPMFloat |
6 SkPMColor c = SkPreMultiplyColor(0xFFCC9933); | 6 SkPMColor c = SkPreMultiplyColor(0xFFCC9933); |
7 | 7 |
8 SkPMFloat pmf; | 8 SkPMFloat pmf; |
9 pmf.set(c); | 9 pmf.set(c); |
10 REPORTER_ASSERT(r, SkScalarNearlyEqual(1.0f, pmf.a())); | 10 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a())); |
11 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.8f, pmf.r())); | 11 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r())); |
12 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.6f, pmf.g())); | 12 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g())); |
13 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.2f, pmf.b())); | 13 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b())); |
14 | 14 |
15 REPORTER_ASSERT(r, c == pmf.get()); | 15 REPORTER_ASSERT(r, c == pmf.get()); |
16 | 16 |
17 // Test clamping. | 17 // Test clamping. |
18 SkPMFloat unclamped; | 18 SkPMFloat unclamped; |
19 unclamped.setA(+2.0f); | 19 unclamped.setA(+510.0f); |
20 unclamped.setR(+0.2f); | 20 unclamped.setR(+153.0f); |
21 unclamped.setG(-0.2f); | 21 unclamped.setG( +1.0f); |
22 unclamped.setB(-5.0f); | 22 unclamped.setB( -0.2f); |
23 | 23 |
24 SkPMFloat clamped; | 24 SkPMFloat clamped; |
25 clamped.set(unclamped.clamped()); | 25 clamped.set(unclamped.clamped()); |
26 | 26 |
27 REPORTER_ASSERT(r, SkScalarNearlyEqual(1.0f, clamped.a())); | 27 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a())); |
28 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.2f, clamped.r())); | 28 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r())); |
29 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.0f, clamped.g())); | 29 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); |
30 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.0f, clamped.b())); | 30 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); |
31 | 31 |
32 // Test SkPMFloat <-> Sk4f conversion. | 32 // Test SkPMFloat <-> Sk4f conversion. |
33 Sk4f fs = clamped; | 33 Sk4f fs = clamped; |
34 SkPMFloat scaled = fs.multiply(Sk4f(4,4,4,4)); | 34 SkPMFloat scaled = fs.multiply(0.25f); |
35 | 35 |
36 REPORTER_ASSERT(r, SkScalarNearlyEqual(4.0f, scaled.a())); | 36 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a())); |
37 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.8f, scaled.r())); | 37 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r())); |
38 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.0f, scaled.g())); | 38 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g())); |
39 REPORTER_ASSERT(r, SkScalarNearlyEqual(0.0f, scaled.b())); | 39 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b())); |
40 } | 40 } |
OLD | NEW |