OLD | NEW |
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); | 75 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); |
76 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); | 76 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); |
77 | 77 |
78 // Test a blue color | 78 // Test a blue color |
79 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); | 79 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); |
80 t->Transform(&tmp, 1); | 80 t->Transform(&tmp, 1); |
81 EXPECT_GT(tmp.z(), tmp.x()); | 81 EXPECT_GT(tmp.z(), tmp.x()); |
82 EXPECT_GT(tmp.z(), tmp.y()); | 82 EXPECT_GT(tmp.z(), tmp.y()); |
83 } | 83 } |
84 | 84 |
| 85 TEST(SimpleColorSpace, TransferFnCancel) { |
| 86 ColorSpace::PrimaryID primary = ColorSpace::PrimaryID::BT709; |
| 87 ColorSpace::MatrixID matrix = ColorSpace::MatrixID::RGB; |
| 88 ColorSpace::RangeID range = ColorSpace::RangeID::FULL; |
| 89 |
| 90 // BT709 has a gamma of 2.2222 (with some adjustments) |
| 91 ColorSpace bt709(primary, ColorSpace::TransferID::BT709, matrix, range); |
| 92 |
| 93 // IEC61966_2_1 has the sRGB gamma of 2.4 (with some adjustments) |
| 94 ColorSpace srgb(primary, ColorSpace::TransferID::IEC61966_2_1, matrix, range); |
| 95 |
| 96 // gamma28 is a simple exponential |
| 97 ColorSpace gamma28(primary, ColorSpace::TransferID::GAMMA28, matrix, range); |
| 98 |
| 99 // gamma24 is a simple exponential |
| 100 ColorSpace gamma24(primary, ColorSpace::TransferID::GAMMA24, matrix, range); |
| 101 |
| 102 // BT709 source is common for video and sRGB destination is common for |
| 103 // monitors. The two transfer functions are very close, and should cancel |
| 104 // out (so the transfer between them should be the identity). This particular |
| 105 // case is important for power reasons. |
| 106 std::unique_ptr<ColorTransform> bt709_to_srgb( |
| 107 ColorTransform::NewColorTransform( |
| 108 bt709, srgb, ColorTransform::Intent::INTENT_PERCEPTUAL)); |
| 109 EXPECT_EQ(bt709_to_srgb->NumberOfStepsForTesting(), 0u); |
| 110 |
| 111 // Gamma 2.8 isn't even close to BT709 and won't cancel out (so we will have |
| 112 // two steps in the transform -- to-linear and from-linear). |
| 113 std::unique_ptr<ColorTransform> bt709_to_gamma28( |
| 114 ColorTransform::NewColorTransform( |
| 115 bt709, gamma28, ColorTransform::Intent::INTENT_PERCEPTUAL)); |
| 116 EXPECT_EQ(bt709_to_gamma28->NumberOfStepsForTesting(), 2u); |
| 117 |
| 118 // Gamma 2.4 is closer to BT709, but not close enough to actually cancel out. |
| 119 std::unique_ptr<ColorTransform> bt709_to_gamma24( |
| 120 ColorTransform::NewColorTransform( |
| 121 bt709, gamma24, ColorTransform::Intent::INTENT_PERCEPTUAL)); |
| 122 EXPECT_EQ(bt709_to_gamma24->NumberOfStepsForTesting(), 2u); |
| 123 } |
| 124 |
85 TEST(SimpleColorSpace, SRGBFromICCAndNotICC) { | 125 TEST(SimpleColorSpace, SRGBFromICCAndNotICC) { |
86 float kEpsilon = 0.001f; | 126 float kEpsilon = 0.001f; |
87 ColorTransform::TriStim value_fromicc; | 127 ColorTransform::TriStim value_fromicc; |
88 ColorTransform::TriStim value_default; | 128 ColorTransform::TriStim value_default; |
89 | 129 |
90 ICCProfile srgb_icc_profile = ICCProfileForTestingSRGB(); | 130 ICCProfile srgb_icc_profile = ICCProfileForTestingSRGB(); |
91 ColorSpace srgb_fromicc = srgb_icc_profile.GetColorSpace(); | 131 ColorSpace srgb_fromicc = srgb_icc_profile.GetColorSpace(); |
92 ColorSpace srgb_default = gfx::ColorSpace::CreateSRGB(); | 132 ColorSpace srgb_default = gfx::ColorSpace::CreateSRGB(); |
93 ColorSpace xyzd50 = gfx::ColorSpace::CreateXYZD50(); | 133 ColorSpace xyzd50 = gfx::ColorSpace::CreateXYZD50(); |
94 | 134 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 373 |
334 INSTANTIATE_TEST_CASE_P( | 374 INSTANTIATE_TEST_CASE_P( |
335 C, | 375 C, |
336 ColorSpaceTest, | 376 ColorSpaceTest, |
337 testing::Combine(testing::ValuesIn(all_primaries), | 377 testing::Combine(testing::ValuesIn(all_primaries), |
338 testing::Values(ColorSpace::TransferID::BT709), | 378 testing::Values(ColorSpace::TransferID::BT709), |
339 testing::ValuesIn(all_matrices), | 379 testing::ValuesIn(all_matrices), |
340 testing::ValuesIn(all_ranges), | 380 testing::ValuesIn(all_ranges), |
341 testing::ValuesIn(intents))); | 381 testing::ValuesIn(intents))); |
342 } // namespace | 382 } // namespace |
OLD | NEW |