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

Unified Diff: cc/resources/video_resource_updater_unittest.cc

Issue 2370453003: 12-bit vp9 video support (Closed)
Patch Set: build fix Created 4 years, 3 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
Index: cc/resources/video_resource_updater_unittest.cc
diff --git a/cc/resources/video_resource_updater_unittest.cc b/cc/resources/video_resource_updater_unittest.cc
index 938c0fc546bdcaef7301b99a822963244e29274a..cc82c4ca9ba08e1b16a7cdb11af983cdb5646941 100644
--- a/cc/resources/video_resource_updater_unittest.cc
+++ b/cc/resources/video_resource_updater_unittest.cc
@@ -504,5 +504,52 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) {
EXPECT_FALSE(context3d_->WasImmutableTextureCreated());
}
+namespace {
+
+// Convert an IEEE 754 half-float to a double value
+// that we can do math on.
+double FromHalfFloat(uint16_t half_float) {
+ if (!half_float)
+ return 0.0;
+ int sign = (half_float & 0x8000) ? -1 : 1;
+ int exponent = (half_float >> 10) & 0x1F;
+ int fraction = half_float & 0x3FF;
+ if (exponent == 0) {
+ return pow(2.0, -24.0) * fraction;
+ } else if (exponent == 0x1F) {
+ return sign * 1000000000000.0;
+ } else {
+ return pow(2.0, exponent - 25) * (0x400 + fraction);
+ }
+}
+
+} // namespace
+
+TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) {
+ unsigned short in[1 << 12];
danakj 2016/09/27 20:49:11 can we name these 2 vars to tell their context a b
hubbe 2016/09/27 22:27:36 Done.
+ unsigned short out[1 << 12];
+ for (int bits = 9; bits <= 12; bits++) {
+ int num_values = 1 << bits;
+ for (int i = 0; i < num_values; i++)
+ in[i] = i;
+
+ VideoResourceUpdater::MakeHalfFloats(in, bits, num_values, out);
+
+ // Multiplier to converting integers to 0.0..1.0 range.
+ float multiplier = 1.0f / (num_values - 1);
danakj 2016/09/27 20:49:11 nit: double (and 1.0 not 1.f) since you're returni
hubbe 2016/09/27 22:27:36 Done.
+
+ for (int i = 0; i < num_values; i++) {
+ // We expect the result to be within +/- one LSB.
danakj 2016/09/27 20:49:11 nit: can you spell out LSB
hubbe 2016/09/27 22:27:36 Done.
+ // Within the range we care about, half-floats values and
+ // their representation both sort in the same order, so we
+ // can just add one to get the next bigger half-float.
+ float expected_precision =
danakj 2016/09/27 20:49:11 Thanks this is helpful
hubbe 2016/09/27 22:27:36 Done.
+ FromHalfFloat(out[i] + 1) - FromHalfFloat(out[i]);
+ EXPECT_NEAR(FromHalfFloat(out[i]), in[i] * multiplier, expected_precision)
+ << "i = " << i << " bits = " << bits;
+ }
+ }
+}
+
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698