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

Side by Side Diff: tests/PMFloatTest.cpp

Issue 1032243002: SkPMFloat::trunc() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove isValid assert in _none trunc() 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 /* 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
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 }
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