Chromium Code Reviews| 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 |