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

Side by Side Diff: ui/gfx/color_transform_unittest.cc

Issue 2652503002: Use SkICC in gfx::ICCProfile and gfx::ColorSpace (Closed)
Patch Set: Rebase Created 3 years, 10 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
« no previous file with comments | « ui/gfx/color_transform.cc ('k') | ui/gfx/icc_profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/color_space.h" 7 #include "ui/gfx/color_space.h"
8 #include "ui/gfx/color_transform.h" 8 #include "ui/gfx/color_transform.h"
9 #include "ui/gfx/icc_profile.h" 9 #include "ui/gfx/icc_profile.h"
10 #include "ui/gfx/test/icc_profiles.h" 10 #include "ui/gfx/test/icc_profiles.h"
11 #include "ui/gfx/transform.h" 11 #include "ui/gfx/transform.h"
12 12
13 namespace gfx { 13 namespace gfx {
14 14
15 // Internal functions, exposted for testing. 15 // Internal functions, exposted for testing.
16 GFX_EXPORT Transform GetPrimaryMatrix(ColorSpace::PrimaryID id);
17 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id); 16 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id);
18 GFX_EXPORT float ToLinear(ColorSpace::TransferID id, float v);
19 GFX_EXPORT float FromLinear(ColorSpace::TransferID id, float v);
20 17
21 ColorSpace::PrimaryID all_primaries[] = { 18 ColorSpace::PrimaryID all_primaries[] = {
22 ColorSpace::PrimaryID::BT709, ColorSpace::PrimaryID::BT470M, 19 ColorSpace::PrimaryID::BT709, ColorSpace::PrimaryID::BT470M,
23 ColorSpace::PrimaryID::BT470BG, ColorSpace::PrimaryID::SMPTE170M, 20 ColorSpace::PrimaryID::BT470BG, ColorSpace::PrimaryID::SMPTE170M,
24 ColorSpace::PrimaryID::SMPTE240M, ColorSpace::PrimaryID::FILM, 21 ColorSpace::PrimaryID::SMPTE240M, ColorSpace::PrimaryID::FILM,
25 ColorSpace::PrimaryID::BT2020, ColorSpace::PrimaryID::SMPTEST428_1, 22 ColorSpace::PrimaryID::BT2020, ColorSpace::PrimaryID::SMPTEST428_1,
26 ColorSpace::PrimaryID::SMPTEST431_2, ColorSpace::PrimaryID::SMPTEST432_1, 23 ColorSpace::PrimaryID::SMPTEST431_2, ColorSpace::PrimaryID::SMPTEST432_1,
27 }; 24 };
28 25
29 ColorSpace::TransferID all_transfers[] = { 26 ColorSpace::TransferID all_transfers[] = {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); 107 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f);
111 t->transform(&tmp, 1); 108 t->transform(&tmp, 1);
112 EXPECT_GT(tmp.z(), tmp.x()); 109 EXPECT_GT(tmp.z(), tmp.x());
113 EXPECT_GT(tmp.z(), tmp.y()); 110 EXPECT_GT(tmp.z(), tmp.y());
114 } 111 }
115 112
116 TEST(SimpleColorSpace, GetColorSpace) { 113 TEST(SimpleColorSpace, GetColorSpace) {
117 ICCProfile srgb_icc = ICCProfileForTestingSRGB(); 114 ICCProfile srgb_icc = ICCProfileForTestingSRGB();
118 ColorSpace sRGB = srgb_icc.GetColorSpace(); 115 ColorSpace sRGB = srgb_icc.GetColorSpace();
119 ColorSpace sRGB2 = sRGB; 116 ColorSpace sRGB2 = sRGB;
117 const float kEpsilon = 1.5f / 255.f;
120 118
121 // Prevent sRGB2 from using a cached ICC profile. 119 // Prevent sRGB2 from using a cached ICC profile.
122 sRGB2.icc_profile_id_ = 0; 120 sRGB2.icc_profile_id_ = 0;
123 121
124 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 122 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
125 sRGB, sRGB2, ColorTransform::Intent::INTENT_ABSOLUTE)); 123 sRGB, sRGB2, ColorTransform::Intent::INTENT_ABSOLUTE));
126 124
127 ColorTransform::TriStim tmp(1.0f, 1.0f, 1.0f); 125 ColorTransform::TriStim tmp(1.0f, 1.0f, 1.0f);
128 t->transform(&tmp, 1); 126 t->transform(&tmp, 1);
129 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); 127 EXPECT_NEAR(tmp.x(), 1.0f, kEpsilon);
130 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); 128 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon);
131 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); 129 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon);
132 130
133 tmp = ColorTransform::TriStim(1.0f, 0.0f, 0.0f); 131 tmp = ColorTransform::TriStim(1.0f, 0.0f, 0.0f);
134 t->transform(&tmp, 1); 132 t->transform(&tmp, 1);
135 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); 133 EXPECT_NEAR(tmp.x(), 1.0f, kEpsilon);
136 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); 134 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon);
137 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); 135 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon);
138 136
139 tmp = ColorTransform::TriStim(0.0f, 1.0f, 0.0f); 137 tmp = ColorTransform::TriStim(0.0f, 1.0f, 0.0f);
140 t->transform(&tmp, 1); 138 t->transform(&tmp, 1);
141 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); 139 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon);
142 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); 140 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon);
143 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); 141 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon);
144 142
145 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f); 143 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f);
146 t->transform(&tmp, 1); 144 t->transform(&tmp, 1);
147 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); 145 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon);
148 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); 146 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon);
149 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); 147 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon);
150 } 148 }
151 149
152 TEST(SimpleColorSpace, UnknownToSRGB) { 150 TEST(SimpleColorSpace, UnknownToSRGB) {
153 ColorSpace unknown; 151 ColorSpace unknown;
154 ColorSpace sRGB = ColorSpace::CreateSRGB(); 152 ColorSpace sRGB = ColorSpace::CreateSRGB();
155 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 153 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
156 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL)); 154 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL));
157 155
158 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f); 156 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f);
159 t->transform(&tmp, 1); 157 t->transform(&tmp, 1);
160 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); 158 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f);
161 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); 159 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f);
162 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); 160 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f);
163 161
164 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); 162 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f);
165 t->transform(&tmp, 1); 163 t->transform(&tmp, 1);
166 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); 164 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f);
167 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); 165 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f);
168 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); 166 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f);
169 167
170 // Test a blue color 168 // Test a blue color
171 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); 169 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f);
172 t->transform(&tmp, 1); 170 t->transform(&tmp, 1);
173 EXPECT_GT(tmp.z(), tmp.x()); 171 EXPECT_GT(tmp.z(), tmp.x());
174 EXPECT_GT(tmp.z(), tmp.y()); 172 EXPECT_GT(tmp.z(), tmp.y());
175 } 173 }
176 174
177 class PrimaryTest : public testing::TestWithParam<ColorSpace::PrimaryID> {};
178
179 TEST_P(PrimaryTest, checkInvertible) {
180 EXPECT_EQ(GetPrimaryMatrix(GetParam()).matrix().get(3, 3), 1.0f);
181 // Check that all primary matrices are invertable.
182 EXPECT_TRUE(GetPrimaryMatrix(GetParam()).IsInvertible());
183 }
184
185 INSTANTIATE_TEST_CASE_P(ColorSpace,
186 PrimaryTest,
187 testing::ValuesIn(all_primaries));
188
189 class MatrixTest : public testing::TestWithParam<ColorSpace::MatrixID> {}; 175 class MatrixTest : public testing::TestWithParam<ColorSpace::MatrixID> {};
190 176
191 TEST_P(MatrixTest, checkInvertible) { 177 TEST_P(MatrixTest, checkInvertible) {
192 EXPECT_EQ(GetTransferMatrix(GetParam()).matrix().get(3, 3), 1.0f); 178 EXPECT_EQ(GetTransferMatrix(GetParam()).matrix().get(3, 3), 1.0f);
193 // Check that all transfer matrices are invertable. 179 // Check that all transfer matrices are invertable.
194 EXPECT_TRUE(GetTransferMatrix(GetParam()).IsInvertible()); 180 EXPECT_TRUE(GetTransferMatrix(GetParam()).IsInvertible());
195 }; 181 };
196 182
197 INSTANTIATE_TEST_CASE_P(ColorSpace, 183 INSTANTIATE_TEST_CASE_P(ColorSpace,
198 MatrixTest, 184 MatrixTest,
199 testing::ValuesIn(all_matrices)); 185 testing::ValuesIn(all_matrices));
200 186
201 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; 187 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {};
202 188
203 TEST_P(TransferTest, basicTest) { 189 TEST_P(TransferTest, basicTest) {
204 for (float x = 0.0f; x <= 1.0f; x += 1.0f / 128.0f) { 190 for (float x = 0.0f; x <= 1.0f; x += 1.0f / 128.0f) {
205 float linear = ToLinear(GetParam(), x); 191 float linear = ColorTransform::ToLinearForTesting(GetParam(), x);
206 float x2 = FromLinear(GetParam(), linear); 192 float x2 = ColorTransform::FromLinearForTesting(GetParam(), linear);
207 EXPECT_NEAR(x, x2, 0.001f); 193 EXPECT_NEAR(x, x2, 0.001f);
208 } 194 }
209 } 195 }
210 196
211 INSTANTIATE_TEST_CASE_P(ColorSpace, 197 INSTANTIATE_TEST_CASE_P(ColorSpace,
212 TransferTest, 198 TransferTest,
213 testing::ValuesIn(all_transfers)); 199 testing::ValuesIn(all_transfers));
214 200
215 typedef std::tr1::tuple<ColorSpace::PrimaryID, 201 typedef std::tr1::tuple<ColorSpace::PrimaryID,
216 ColorSpace::TransferID, 202 ColorSpace::TransferID,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 262
277 INSTANTIATE_TEST_CASE_P( 263 INSTANTIATE_TEST_CASE_P(
278 C, 264 C,
279 ColorSpaceTest, 265 ColorSpaceTest,
280 testing::Combine(testing::ValuesIn(all_primaries), 266 testing::Combine(testing::ValuesIn(all_primaries),
281 testing::Values(ColorSpace::TransferID::BT709), 267 testing::Values(ColorSpace::TransferID::BT709),
282 testing::ValuesIn(all_matrices), 268 testing::ValuesIn(all_matrices),
283 testing::ValuesIn(all_ranges), 269 testing::ValuesIn(all_ranges),
284 testing::ValuesIn(intents))); 270 testing::ValuesIn(intents)));
285 } // namespace 271 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/color_transform.cc ('k') | ui/gfx/icc_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698