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

Side by Side Diff: tests/PMFloatTest.cpp

Issue 1024633003: operator overloads for Sk4x, use them all where possible (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: weird, msvc doesnt like operator~() Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « src/core/Sk4x.h ('k') | tests/Sk2xTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 SkPMFloat pmf(c); 7 SkPMFloat pmf(c);
8 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a())); 8 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a()));
9 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r())); 9 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r()));
10 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g())); 10 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g()));
11 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b())); 11 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b()));
12 REPORTER_ASSERT(r, c == pmf.get()); 12 REPORTER_ASSERT(r, c == pmf.get());
13 13
14 // Test rounding. (Don't bother testing .5... we don't care which way it go es.) 14 // Test rounding. (Don't bother testing .5... we don't care which way it go es.)
15 pmf = SkPMFloat(254.6f, 204.3f, 153.1f, 50.8f); 15 pmf = SkPMFloat(254.6f, 204.3f, 153.1f, 50.8f);
16 REPORTER_ASSERT(r, c == pmf.get()); 16 REPORTER_ASSERT(r, c == pmf.get());
17 17
18 // Test clamping. 18 // Test clamping.
19 SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).clamped()); 19 SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).clamped());
20 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a())); 20 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a()));
21 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r())); 21 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r()));
22 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); 22 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g()));
23 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); 23 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b()));
24 24
25 // Test SkPMFloat <-> Sk4f conversion. 25 // Test SkPMFloat <-> Sk4f conversion.
26 Sk4f fs = clamped; 26 Sk4f fs = clamped;
27 SkPMFloat scaled = fs.multiply(Sk4f(0.25f)); 27 SkPMFloat scaled = fs * Sk4f(0.25f);
28 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a())); 28 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a()));
29 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r())); 29 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r()));
30 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g())); 30 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g()));
31 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b())); 31 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b()));
32 32
33 // Test 4-at-a-time conversions. 33 // Test 4-at-a-time conversions.
34 SkPMColor colors[4] = { 0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF }; 34 SkPMColor colors[4] = { 0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF };
35 SkPMFloat floats[4]; 35 SkPMFloat floats[4];
36 SkPMFloat::From4PMColors(floats, colors); 36 SkPMFloat::From4PMColors(floats, colors);
37 37
38 SkPMColor back[4]; 38 SkPMColor back[4];
39 SkPMFloat::To4PMColors(back, floats); 39 SkPMFloat::To4PMColors(back, floats);
40 for (int i = 0; i < 4; i++) { 40 for (int i = 0; i < 4; i++) {
41 REPORTER_ASSERT(r, back[i] == colors[i]); 41 REPORTER_ASSERT(r, back[i] == colors[i]);
42 } 42 }
43 43
44 SkPMFloat::ClampTo4PMColors(back, floats); 44 SkPMFloat::ClampTo4PMColors(back, floats);
45 for (int i = 0; i < 4; i++) { 45 for (int i = 0; i < 4; i++) {
46 REPORTER_ASSERT(r, back[i] == colors[i]); 46 REPORTER_ASSERT(r, back[i] == colors[i]);
47 } 47 }
48 } 48 }
OLDNEW
« no previous file with comments | « src/core/Sk4x.h ('k') | tests/Sk2xTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698