OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/color_space.h" | 9 #include "ui/gfx/color_space.h" |
10 #include "ui/gfx/skia_color_space_util.h" | |
10 | 11 |
11 namespace gfx { | 12 namespace gfx { |
12 namespace { | 13 namespace { |
13 | 14 |
14 const float kEpsilon = 1.0e-3f; | 15 const float kEpsilon = 1.0e-3f; |
15 | 16 |
16 // Returns the L-infty difference of u and v. | 17 // Returns the L-infty difference of u and v. |
17 float Diff(const SkVector4& u, const SkVector4& v) { | 18 float Diff(const SkVector4& u, const SkVector4& v) { |
18 float result = 0; | 19 float result = 0; |
19 for (size_t i = 0; i < 4; ++i) | 20 for (size_t i = 0; i < 4; ++i) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 SkMatrix44 range_adjust_inv; | 73 SkMatrix44 range_adjust_inv; |
73 range_adjust.invert(&range_adjust_inv); | 74 range_adjust.invert(&range_adjust_inv); |
74 | 75 |
75 for (size_t j = 0; j < kNumTestRGBs; ++j) { | 76 for (size_t j = 0; j < kNumTestRGBs; ++j) { |
76 SkVector4 yuv = range_adjust_inv * transfer * test_rgbs[j]; | 77 SkVector4 yuv = range_adjust_inv * transfer * test_rgbs[j]; |
77 EXPECT_LT(Diff(yuv, expected_yuvs[i][j]), kEpsilon); | 78 EXPECT_LT(Diff(yuv, expected_yuvs[i][j]), kEpsilon); |
78 } | 79 } |
79 } | 80 } |
80 } | 81 } |
81 | 82 |
83 typedef std::tr1::tuple<ColorSpace::TransferID, size_t> TableTestData; | |
84 | |
85 class ColorSpaceTableTest : public testing::TestWithParam<TableTestData> {}; | |
86 | |
87 TEST_P(ColorSpaceTableTest, ApproximateTransferFn) { | |
88 ColorSpace::TransferID transfer_id = std::tr1::get<0>(GetParam()); | |
89 const size_t table_size = std::tr1::get<1>(GetParam()); | |
90 | |
91 gfx::ColorSpace color_space(ColorSpace::PrimaryID::BT709, transfer_id); | |
92 SkColorSpaceTransferFn tr_fn; | |
93 SkColorSpaceTransferFn tr_fn_inv; | |
94 bool result = color_space.GetTransferFunction(&tr_fn); | |
95 CHECK(result); | |
96 color_space.GetInverseTransferFunction(&tr_fn_inv); | |
97 | |
98 std::vector<float> x; | |
99 std::vector<float> t; | |
100 for (float v = 0; v <= 1.f; v += 1.f / table_size) { | |
101 x.push_back(v); | |
102 t.push_back(SkTransferFnEval(tr_fn, v)); | |
103 } | |
104 | |
105 SkColorSpaceTransferFn fn_approx; | |
106 SkApproximateTransferFn(x.data(), t.data(), x.size(), &fn_approx); | |
107 | |
108 for (size_t i = 0; i < x.size(); ++i) { | |
109 float fn_approx_of_x = SkTransferFnEval(fn_approx, x[i]); | |
110 EXPECT_NEAR(t[i], fn_approx_of_x, 2.f / 256.f); | |
msarett1
2017/02/22 19:53:18
Really encouraging that we pass this test :).
| |
111 if (std::abs(t[i] - fn_approx_of_x) > 2.f / 256.f) | |
112 break; | |
113 } | |
114 } | |
115 | |
116 ColorSpace::TransferID all_transfers[] = { | |
117 ColorSpace::TransferID::GAMMA22, ColorSpace::TransferID::GAMMA24, | |
118 ColorSpace::TransferID::GAMMA28, ColorSpace::TransferID::BT709, | |
119 ColorSpace::TransferID::SMPTE240M, ColorSpace::TransferID::IEC61966_2_1, | |
120 ColorSpace::TransferID::SMPTEST428_1, ColorSpace::TransferID::LINEAR}; | |
121 | |
122 size_t all_table_sizes[] = {512, 256, 128, 64, 16, 11, 8, 7, 6, 5, 4}; | |
123 | |
124 INSTANTIATE_TEST_CASE_P(A, | |
125 ColorSpaceTableTest, | |
126 testing::Combine(testing::ValuesIn(all_transfers), | |
127 testing::ValuesIn(all_table_sizes))); | |
128 | |
82 } // namespace | 129 } // namespace |
83 } // namespace gfx | 130 } // namespace gfx |
OLD | NEW |