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

Unified Diff: cc/resources/video_resource_updater_unittest.cc

Issue 2370453003: 12-bit vp9 video support (Closed)
Patch Set: comments addressed + comment added 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..90e1c0320b0cd3567fbba805f683d04b13a12817 100644
--- a/cc/resources/video_resource_updater_unittest.cc
+++ b/cc/resources/video_resource_updater_unittest.cc
@@ -504,5 +504,46 @@ 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];
+ unsigned short out[1 << 12];
+ for (int bits = 9; bits <= 12; bits++) {
+ size_t num_values = 1 << bits;
+ for (size_t i = 0; i < num_values; i++)
+ in[i] = i;
+
+ float mult = 1.0f / (num_values - 1);
danakj 2016/09/26 22:10:39 Why this mult?
hubbe 2016/09/27 00:03:25 Is "multiplier" better? Or did I misunderstand the
danakj 2016/09/27 00:15:58 I was wondering why 1/(n-1)?
hubbe 2016/09/27 00:31:24 Ah. I did add a comment for that.
+
+ VideoResourceUpdater::MakeHalfFloats(in, mult, num_values, out);
+
+ for (size_t i = 0; i < num_values; i++) {
+ EXPECT_NEAR(FromHalfFloat(out[i]), in[i] * mult,
+ FromHalfFloat(out[i] + 1) - FromHalfFloat(out[i]))
danakj 2016/09/26 22:10:39 What does +1 on a half-float do to it? Can you lea
hubbe 2016/09/27 00:03:25 Done.
+ << "i = " << i << " bits = " << bits;
+ }
+ }
+}
+
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698