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

Side by Side Diff: tests/PMFloatTest.cpp

Issue 1048593002: Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: This is actually faster Created 5 years, 8 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') | 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 /* 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
(...skipping 14 matching lines...) Expand all
25 pmf = SkPMFloat(255.9f, 204.01f, 153.0f, -0.9f); 25 pmf = SkPMFloat(255.9f, 204.01f, 153.0f, -0.9f);
26 REPORTER_ASSERT(r, SkPreMultiplyColor(0xFFCC9900) == pmf.trunc()); 26 REPORTER_ASSERT(r, SkPreMultiplyColor(0xFFCC9900) == pmf.trunc());
27 27
28 // Test clamping. 28 // Test clamping.
29 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());
30 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a())); 30 REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a()));
31 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r())); 31 REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r()));
32 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); 32 REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g()));
33 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); 33 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b()));
34 34
35 // Test SkPMFloat <-> Sk4f conversion. 35 // Test SkPMFloat <-> Sk4s conversion.
36 Sk4f fs = clamped; 36 Sk4s fs = clamped;
37 SkPMFloat scaled = fs * Sk4f(0.25f); 37 SkPMFloat scaled = fs * Sk4s(0.25f);
38 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a())); 38 REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a()));
39 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r())); 39 REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r()));
40 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g())); 40 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g()));
41 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b())); 41 REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b()));
42 42
43 // Test 4-at-a-time conversions. 43 // Test 4-at-a-time conversions.
44 SkPMColor colors[4] = { 0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF }; 44 SkPMColor colors[4] = { 0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF };
45 SkPMFloat floats[4]; 45 SkPMFloat floats[4];
46 SkPMFloat::From4PMColors(colors, floats+0, floats+1, floats+2, floats+3); 46 SkPMFloat::From4PMColors(colors, floats+0, floats+1, floats+2, floats+3);
47 47
48 SkPMColor back[4]; 48 SkPMColor back[4];
49 SkPMFloat::To4PMColors(floats[0], floats[1], floats[2], floats[3], back); 49 SkPMFloat::To4PMColors(floats[0], floats[1], floats[2], floats[3], back);
50 for (int i = 0; i < 4; i++) { 50 for (int i = 0; i < 4; i++) {
51 REPORTER_ASSERT(r, back[i] == colors[i]); 51 REPORTER_ASSERT(r, back[i] == colors[i]);
52 } 52 }
53 53
54 SkPMFloat::ClampTo4PMColors(floats[0], floats[1], floats[2], floats[3], back ); 54 SkPMFloat::ClampTo4PMColors(floats[0], floats[1], floats[2], floats[3], back );
55 for (int i = 0; i < 4; i++) { 55 for (int i = 0; i < 4; i++) {
56 REPORTER_ASSERT(r, back[i] == colors[i]); 56 REPORTER_ASSERT(r, back[i] == colors[i]);
57 } 57 }
58 } 58 }
OLDNEW
« no previous file with comments | « src/opts/SkPMFloat_none.h ('k') | tests/Sk2xTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698