2015-02-23 18:04:34 +00:00
|
|
|
#include "SkPMFloat.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
DEF_TEST(SkPMFloat, r) {
|
2015-02-26 18:43:16 +00:00
|
|
|
// Test SkPMColor <-> SkPMFloat
|
2015-02-23 18:04:34 +00:00
|
|
|
SkPMColor c = SkPreMultiplyColor(0xFFCC9933);
|
2015-03-04 19:25:27 +00:00
|
|
|
SkPMFloat pmf(c);
|
2015-03-03 15:46:15 +00:00
|
|
|
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()));
|
2015-03-03 16:57:07 +00:00
|
|
|
REPORTER_ASSERT(r, c == pmf.get());
|
2015-02-23 18:04:34 +00:00
|
|
|
|
2015-03-03 16:57:07 +00:00
|
|
|
// Test rounding. (Don't bother testing .5... we don't care which way it goes.)
|
2015-03-04 19:25:27 +00:00
|
|
|
pmf = SkPMFloat(254.6f, 204.3f, 153.1f, 50.8f);
|
2015-02-23 18:04:34 +00:00
|
|
|
REPORTER_ASSERT(r, c == pmf.get());
|
|
|
|
|
2015-02-26 18:43:16 +00:00
|
|
|
// Test clamping.
|
2015-03-04 19:25:27 +00:00
|
|
|
SkPMFloat clamped(SkPMFloat(510.0f, 153.0f, 1.0f, -0.2f).clamped());
|
2015-03-03 15:46:15 +00:00
|
|
|
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()));
|
2015-02-26 18:43:16 +00:00
|
|
|
|
|
|
|
// Test SkPMFloat <-> Sk4f conversion.
|
|
|
|
Sk4f fs = clamped;
|
2015-03-03 15:46:15 +00:00
|
|
|
SkPMFloat scaled = fs.multiply(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()));
|
2015-03-05 19:31:59 +00:00
|
|
|
|
|
|
|
// Test 4-at-a-time conversions.
|
|
|
|
SkPMColor colors[4] = { 0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF };
|
|
|
|
SkPMFloat floats[4];
|
|
|
|
SkPMFloat::From4PMColors(floats, colors);
|
|
|
|
|
|
|
|
SkPMColor back[4];
|
|
|
|
SkPMFloat::To4PMColors(back, floats);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
REPORTER_ASSERT(r, back[i] == colors[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPMFloat::ClampTo4PMColors(back, floats);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
REPORTER_ASSERT(r, back[i] == colors[i]);
|
|
|
|
}
|
2015-02-23 18:04:34 +00:00
|
|
|
}
|