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

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

Issue 2697863003: color: Clarify default behaviors (Closed)
Patch Set: Incorporate review feedback 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') | no next file » | 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"
(...skipping 21 matching lines...) Expand all
32 ColorSpace::TransferID::IEC61966_2_1, ColorSpace::TransferID::BT2020_10, 32 ColorSpace::TransferID::IEC61966_2_1, ColorSpace::TransferID::BT2020_10,
33 ColorSpace::TransferID::BT2020_12, ColorSpace::TransferID::SMPTEST2084, 33 ColorSpace::TransferID::BT2020_12, ColorSpace::TransferID::SMPTEST2084,
34 ColorSpace::TransferID::ARIB_STD_B67, 34 ColorSpace::TransferID::ARIB_STD_B67,
35 // This one is weird as the non-linear numbers are not between 0 and 1. 35 // This one is weird as the non-linear numbers are not between 0 and 1.
36 // TODO(hubbe): Test this separately. 36 // TODO(hubbe): Test this separately.
37 // ColorSpace::TransferID::SMPTEST428_1, 37 // ColorSpace::TransferID::SMPTEST428_1,
38 }; 38 };
39 39
40 ColorSpace::MatrixID all_matrices[] = { 40 ColorSpace::MatrixID all_matrices[] = {
41 ColorSpace::MatrixID::RGB, ColorSpace::MatrixID::BT709, 41 ColorSpace::MatrixID::RGB, ColorSpace::MatrixID::BT709,
42 ColorSpace::MatrixID::UNSPECIFIED, ColorSpace::MatrixID::RESERVED,
43 ColorSpace::MatrixID::FCC, ColorSpace::MatrixID::BT470BG, 42 ColorSpace::MatrixID::FCC, ColorSpace::MatrixID::BT470BG,
44 ColorSpace::MatrixID::SMPTE170M, ColorSpace::MatrixID::SMPTE240M, 43 ColorSpace::MatrixID::SMPTE170M, ColorSpace::MatrixID::SMPTE240M,
45 44
46 // YCOCG produces lots of negative values which isn't compatible with many 45 // YCOCG produces lots of negative values which isn't compatible with many
47 // transfer functions. 46 // transfer functions.
48 // TODO(hubbe): Test this separately. 47 // TODO(hubbe): Test this separately.
49 // ColorSpace::MatrixID::YCOCG, 48 // ColorSpace::MatrixID::YCOCG,
50 ColorSpace::MatrixID::BT2020_NCL, ColorSpace::MatrixID::BT2020_CL, 49 ColorSpace::MatrixID::BT2020_NCL, ColorSpace::MatrixID::BT2020_CL,
51 ColorSpace::MatrixID::YDZDX, 50 ColorSpace::MatrixID::YDZDX,
52 }; 51 };
53 52
54 ColorSpace::RangeID all_ranges[] = {ColorSpace::RangeID::UNSPECIFIED, 53 ColorSpace::RangeID all_ranges[] = {ColorSpace::RangeID::FULL,
55 ColorSpace::RangeID::FULL,
56 ColorSpace::RangeID::LIMITED, 54 ColorSpace::RangeID::LIMITED,
57 ColorSpace::RangeID::DERIVED}; 55 ColorSpace::RangeID::DERIVED};
58 56
59 ColorTransform::Intent intents[] = {ColorTransform::Intent::INTENT_ABSOLUTE, 57 ColorTransform::Intent intents[] = {ColorTransform::Intent::INTENT_ABSOLUTE,
60 ColorTransform::Intent::TEST_NO_OPT}; 58 ColorTransform::Intent::TEST_NO_OPT};
61 59
62 TEST(SimpleColorSpace, BT709toSRGB) { 60 TEST(SimpleColorSpace, BT709toSRGB) {
63 ColorSpace bt709 = ColorSpace::CreateREC709(); 61 ColorSpace bt709 = ColorSpace::CreateREC709();
64 ColorSpace sRGB = ColorSpace::CreateSRGB(); 62 ColorSpace sRGB = ColorSpace::CreateSRGB();
65 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 63 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon); 185 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon);
188 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon); 186 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon);
189 187
190 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f); 188 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f);
191 t->Transform(&tmp, 1); 189 t->Transform(&tmp, 1);
192 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon); 190 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon);
193 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon); 191 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon);
194 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon); 192 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon);
195 } 193 }
196 194
197 TEST(SimpleColorSpace, UnknownToSRGB) { 195 TEST(SimpleColorSpace, UnknownVideoToSRGB) {
198 ColorSpace unknown; 196 // Invalid video spaces should be BT709.
197 ColorSpace unknown = gfx::ColorSpace::CreateVideo(
198 -1, -1, -1, gfx::ColorSpace::RangeID::LIMITED);
199 ColorSpace sRGB = ColorSpace::CreateSRGB(); 199 ColorSpace sRGB = ColorSpace::CreateSRGB();
200 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 200 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
201 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL)); 201 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL));
202 202
203 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f); 203 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f);
204 t->Transform(&tmp, 1); 204 t->Transform(&tmp, 1);
205 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); 205 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f);
206 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); 206 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f);
207 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); 207 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f);
208 208
209 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); 209 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f);
210 t->Transform(&tmp, 1); 210 t->Transform(&tmp, 1);
211 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); 211 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f);
212 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); 212 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f);
213 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); 213 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f);
214 214
215 // Test a blue color 215 // Test a blue color
216 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); 216 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f);
217 t->Transform(&tmp, 1); 217 t->Transform(&tmp, 1);
218 EXPECT_GT(tmp.z(), tmp.x()); 218 EXPECT_GT(tmp.z(), tmp.x());
219 EXPECT_GT(tmp.z(), tmp.y()); 219 EXPECT_GT(tmp.z(), tmp.y());
220 } 220 }
221 221
222 TEST(SimpleColorSpace, DefaultToSRGB) {
223 // The default value should do no transformation, regardless of destination.
224 ColorSpace unknown;
225 std::unique_ptr<ColorTransform> t1(ColorTransform::NewColorTransform(
226 unknown, ColorSpace::CreateSRGB(),
227 ColorTransform::Intent::INTENT_PERCEPTUAL));
228 EXPECT_EQ(t1->NumberOfStepsForTesting(), 0u);
229 std::unique_ptr<ColorTransform> t2(ColorTransform::NewColorTransform(
230 unknown, ColorSpace::CreateXYZD50(),
231 ColorTransform::Intent::INTENT_PERCEPTUAL));
232 EXPECT_EQ(t2->NumberOfStepsForTesting(), 0u);
233 }
234
222 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; 235 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {};
223 236
224 TEST_P(TransferTest, basicTest) { 237 TEST_P(TransferTest, basicTest) {
225 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), 238 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(),
226 ColorSpace::MatrixID::RGB, 239 ColorSpace::MatrixID::RGB,
227 ColorSpace::RangeID::FULL); 240 ColorSpace::RangeID::FULL);
228 gfx::ColorSpace space_linear( 241 gfx::ColorSpace space_linear(
229 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, 242 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR,
230 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); 243 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL);
231 244
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 333
321 INSTANTIATE_TEST_CASE_P( 334 INSTANTIATE_TEST_CASE_P(
322 C, 335 C,
323 ColorSpaceTest, 336 ColorSpaceTest,
324 testing::Combine(testing::ValuesIn(all_primaries), 337 testing::Combine(testing::ValuesIn(all_primaries),
325 testing::Values(ColorSpace::TransferID::BT709), 338 testing::Values(ColorSpace::TransferID::BT709),
326 testing::ValuesIn(all_matrices), 339 testing::ValuesIn(all_matrices),
327 testing::ValuesIn(all_ranges), 340 testing::ValuesIn(all_ranges),
328 testing::ValuesIn(intents))); 341 testing::ValuesIn(intents)));
329 } // namespace 342 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/color_transform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698