OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPMFloat.h" | 8 #include "SkPMFloat.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 | 10 |
11 DEF_TEST(SkPMFloat, r) { | 11 DEF_TEST(SkPMFloat, r) { |
12 // Test SkPMColor <-> SkPMFloat | 12 // Test SkPMColor <-> SkPMFloat |
13 SkPMColor c = SkPreMultiplyColor(0xFFCC9933); | 13 SkPMColor c = SkPreMultiplyColor(0xFFCC9933); |
14 SkPMFloat pmf(c); | 14 SkPMFloat pmf(c); |
15 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a())); | 15 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a())); |
16 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r())); | 16 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r())); |
17 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g())); | 17 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g())); |
18 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b())); | 18 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b())); |
19 REPORTER_ASSERT(r, c == pmf.get()); | 19 REPORTER_ASSERT(r, c == pmf.get()); |
20 | 20 |
21 // Test rounding. | 21 // Test rounding. |
22 pmf = SkPMFloat(254.5f, 203.5f, 153.1f, 50.8f); | 22 pmf = SkPMFloat(254.5f, 203.5f, 153.1f, 50.8f); |
23 REPORTER_ASSERT(r, c == pmf.get()); | 23 REPORTER_ASSERT(r, c == pmf.get()); |
24 | 24 |
| 25 pmf = SkPMFloat(255.9f, 204.01f, 153.0f, -0.9f); |
| 26 REPORTER_ASSERT(r, SkPreMultiplyColor(0xFFCC9900) == pmf.trunc()); |
| 27 |
25 // Test clamping. | 28 // Test clamping. |
26 SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).clamped()); | 29 SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).clamped()); |
27 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a())); | 30 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a())); |
28 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r())); | 31 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r())); |
29 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); | 32 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); |
30 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); | 33 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); |
31 | 34 |
32 // Test SkPMFloat <-> Sk4f conversion. | 35 // Test SkPMFloat <-> Sk4f conversion. |
33 Sk4f fs = clamped; | 36 Sk4f fs = clamped; |
34 SkPMFloat scaled = fs * Sk4f(0.25f); | 37 SkPMFloat scaled = fs * Sk4f(0.25f); |
(...skipping 11 matching lines...) Expand all Loading... |
46 SkPMFloat::To4PMColors(floats[0], floats[1], floats[2], floats[3], back); | 49 SkPMFloat::To4PMColors(floats[0], floats[1], floats[2], floats[3], back); |
47 for (int i = 0; i < 4; i++) { | 50 for (int i = 0; i < 4; i++) { |
48 REPORTER_ASSERT(r, back[i] == colors[i]); | 51 REPORTER_ASSERT(r, back[i] == colors[i]); |
49 } | 52 } |
50 | 53 |
51 SkPMFloat::ClampTo4PMColors(floats[0], floats[1], floats[2], floats[3], back
); | 54 SkPMFloat::ClampTo4PMColors(floats[0], floats[1], floats[2], floats[3], back
); |
52 for (int i = 0; i < 4; i++) { | 55 for (int i = 0; i < 4; i++) { |
53 REPORTER_ASSERT(r, back[i] == colors[i]); | 56 REPORTER_ASSERT(r, back[i] == colors[i]); |
54 } | 57 } |
55 } | 58 } |
OLD | NEW |