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

Side by Side Diff: tests/PMFloatTest.cpp

Issue 977773002: Update SkPMFloat API a bit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 32 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/opts/SkPMFloat_none.h ('k') | no next file » | 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 7 SkPMFloat pmf(c);
8 SkPMFloat pmf;
9 pmf.set(c);
10 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a())); 8 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a()));
11 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r())); 9 REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r()));
12 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g())); 10 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g()));
13 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b())); 11 REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b()));
14 REPORTER_ASSERT(r, c == pmf.get()); 12 REPORTER_ASSERT(r, c == pmf.get());
15 13
16 // 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.)
17 pmf.setA(254.6f); 15 pmf = SkPMFloat(254.6f, 204.3f, 153.1f, 50.8f);
18 pmf.setR(204.3f);
19 pmf.setG(153.1f);
20 pmf.setB( 50.8f);
21 REPORTER_ASSERT(r, c == pmf.get()); 16 REPORTER_ASSERT(r, c == pmf.get());
22 17
23 // Test clamping. 18 // Test clamping.
24 SkPMFloat unclamped; 19 SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).clamped());
25 unclamped.setA(+510.0f);
26 unclamped.setR(+153.0f);
27 unclamped.setG( +1.0f);
28 unclamped.setB( -0.2f);
29
30 SkPMFloat clamped;
31 clamped.set(unclamped.clamped());
32
33 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a())); 20 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a()));
34 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r())); 21 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r()));
35 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); 22 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g()));
36 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); 23 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b()));
37 24
38 // Test SkPMFloat <-> Sk4f conversion. 25 // Test SkPMFloat <-> Sk4f conversion.
39 Sk4f fs = clamped; 26 Sk4f fs = clamped;
40 SkPMFloat scaled = fs.multiply(0.25f); 27 SkPMFloat scaled = fs.multiply(0.25f);
41
42 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a())); 28 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a()));
43 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r())); 29 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r()));
44 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g())); 30 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g()));
45 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b())); 31 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b()));
46 } 32 }
OLDNEW
« no previous file with comments | « src/opts/SkPMFloat_none.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698