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

Unified Diff: tests/PMFloatTest.cpp

Issue 1201343004: Convert SkPMFloat to [0,1] range and prune its API. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/opts/SkPMFloat_sse.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PMFloatTest.cpp
diff --git a/tests/PMFloatTest.cpp b/tests/PMFloatTest.cpp
index 1c53081571232c3e6f0413964d9cd5a2964a9d14..b7b39411d16f51242640c23873dcda77b357612b 100644
--- a/tests/PMFloatTest.cpp
+++ b/tests/PMFloatTest.cpp
@@ -12,47 +12,27 @@ DEF_TEST(SkPMFloat, r) {
// Test SkPMColor <-> SkPMFloat
SkPMColor c = SkPreMultiplyColor(0xFFCC9933);
SkPMFloat pmf(c);
- REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, pmf.a()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, pmf.r()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, pmf.g()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, pmf.b()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, 255*pmf.a()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(204.0f, 255*pmf.r()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, 255*pmf.g()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual( 51.0f, 255*pmf.b()));
REPORTER_ASSERT(r, c == pmf.round());
// Test rounding.
- pmf = SkPMFloat(254.5f, 203.5f, 153.1f, 50.8f);
+ pmf = SkPMFloat(254.5f/255, 203.5f/255, 153.1f/255, 50.8f/255);
REPORTER_ASSERT(r, c == pmf.round());
- pmf = SkPMFloat(255.9f, 204.01f, 153.0f, -0.9f);
- REPORTER_ASSERT(r, SkPreMultiplyColor(0xFFCC9900) == pmf.trunc());
-
- // Test clamping.
- SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).roundClamp());
- REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, clamped.a()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, clamped.r()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b()));
+ SkPMFloat clamped(SkPMFloat(510.0f/255, 153.0f/255, 1.0f/255, -0.2f/255).round());
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(255.0f, 255*clamped.a()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(153.0f, 255*clamped.r()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, 255*clamped.g()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, 255*clamped.b()));
// Test SkPMFloat <-> Sk4f conversion.
Sk4f fs = clamped;
SkPMFloat scaled = fs * Sk4f(0.25f);
- REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g()));
- REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, scaled.b()));
-
- // Test 4-at-a-time conversions.
- SkPMColor colors[4] = { 0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF };
- SkPMFloat floats[4];
- SkPMFloat::From4PMColors(colors, floats+0, floats+1, floats+2, floats+3);
-
- SkPMColor back[4];
- SkPMFloat::RoundTo4PMColors(floats[0], floats[1], floats[2], floats[3], back);
- for (int i = 0; i < 4; i++) {
- REPORTER_ASSERT(r, back[i] == colors[i]);
- }
-
- SkPMFloat::RoundClampTo4PMColors(floats[0], floats[1], floats[2], floats[3], back);
- for (int i = 0; i < 4; i++) {
- REPORTER_ASSERT(r, back[i] == colors[i]);
- }
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, 255*scaled.a()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, 255*scaled.r()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, 255*scaled.g()));
+ REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.00f, 255*scaled.b()));
}
« no previous file with comments | « src/opts/SkPMFloat_sse.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698