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

Side by Side Diff: cc/resources/video_resource_updater_unittest.cc

Issue 2444463002: Change half-float conversion to use 1.0 multiplier (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/video_resource_updater.h" 5 #include "cc/resources/video_resource_updater.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } else if (exponent == 0x1F) { 529 } else if (exponent == 0x1F) {
530 return sign * 1000000000000.0; 530 return sign * 1000000000000.0;
531 } else { 531 } else {
532 return pow(2.0, exponent - 25) * (0x400 + fraction); 532 return pow(2.0, exponent - 25) * (0x400 + fraction);
533 } 533 }
534 } 534 }
535 535
536 } // namespace 536 } // namespace
537 537
538 TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) { 538 TEST_F(VideoResourceUpdaterTest, MakeHalfFloatTest) {
539 unsigned short integers[1 << 12]; 539 unsigned short integers[1 << 16];
540 unsigned short half_floats[1 << 12]; 540 unsigned short half_floats[1 << 16];
541 for (int bits = 9; bits <= 12; bits++) { 541 for (int bits = 9; bits <= 16; bits++) {
542 std::unique_ptr<VideoResourceUpdater::HalfFloatMaker> half_float_maker;
543 half_float_maker = VideoResourceUpdater::NewHalfFloatMaker(bits);
542 int num_values = 1 << bits; 544 int num_values = 1 << bits;
543 for (int i = 0; i < num_values; i++) 545 for (int i = 0; i < num_values; i++)
544 integers[i] = i; 546 integers[i] = i;
545 547
546 VideoResourceUpdater::MakeHalfFloats(integers, bits, num_values, 548 half_float_maker->MakeHalfFloats(integers, num_values, half_floats);
547 half_floats);
548
549 // Multiplier to converting integers to 0.0..1.0 range. 549 // Multiplier to converting integers to 0.0..1.0 range.
550 double multiplier = 1.0 / (num_values - 1); 550 double multiplier = 1.0 / (num_values - 1);
551 551
552 for (int i = 0; i < num_values; i++) { 552 for (int i = 0; i < num_values; i++) {
553 // This value is in range 0..1
554 float value = integers[i] * multiplier;
555 // Reverse the effect of offset and multiplier to get the expected
556 // output value from the half-float converter.
557 float expected_value =
558 value / half_float_maker->Multiplier() + half_float_maker->Offset();
559 EXPECT_EQ(integers[i], i);
560
553 // We expect the result to be within +/- one least-significant bit. 561 // We expect the result to be within +/- one least-significant bit.
554 // Within the range we care about, half-floats values and 562 // Within the range we care about, half-floats values and
555 // their representation both sort in the same order, so we 563 // their representation both sort in the same order, so we
556 // can just add one to get the next bigger half-float. 564 // can just add one to get the next bigger half-float.
557 float expected_precision = 565 float expected_precision =
558 FromHalfFloat(half_floats[i] + 1) - FromHalfFloat(half_floats[i]); 566 FromHalfFloat(half_floats[i] + 1) - FromHalfFloat(half_floats[i]);
559 EXPECT_NEAR(FromHalfFloat(half_floats[i]), integers[i] * multiplier, 567 EXPECT_NEAR(FromHalfFloat(half_floats[i]), expected_value,
560 expected_precision) 568 expected_precision)
561 << "i = " << i << " bits = " << bits; 569 << "i = " << i << " bits = " << bits;
562 } 570 }
563 } 571 }
564 } 572 }
565 573
566 } // namespace 574 } // namespace
567 } // namespace cc 575 } // namespace cc
OLDNEW
« cc/resources/video_resource_updater.cc ('K') | « cc/resources/video_resource_updater.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698