| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ICCProfile srgb_icc_profile = ICCProfileForTestingSRGB(); | 92 ICCProfile srgb_icc_profile = ICCProfileForTestingSRGB(); |
| 93 ColorSpace srgb_fromicc = srgb_icc_profile.GetColorSpace(); | 93 ColorSpace srgb_fromicc = srgb_icc_profile.GetColorSpace(); |
| 94 ColorSpace srgb_default = gfx::ColorSpace::CreateSRGB(); | 94 ColorSpace srgb_default = gfx::ColorSpace::CreateSRGB(); |
| 95 ColorSpace xyzd50 = gfx::ColorSpace::CreateXYZD50(); | 95 ColorSpace xyzd50 = gfx::ColorSpace::CreateXYZD50(); |
| 96 | 96 |
| 97 value_fromicc = value_default = ColorTransform::TriStim(0.1, 0.5, 0.9); | 97 value_fromicc = value_default = ColorTransform::TriStim(0.1, 0.5, 0.9); |
| 98 | 98 |
| 99 std::unique_ptr<ColorTransform> toxyzd50_fromicc( | 99 std::unique_ptr<ColorTransform> toxyzd50_fromicc( |
| 100 ColorTransform::NewColorTransform( | 100 ColorTransform::NewColorTransform( |
| 101 srgb_fromicc, xyzd50, ColorTransform::Intent::INTENT_ABSOLUTE)); | 101 srgb_fromicc, xyzd50, ColorTransform::Intent::INTENT_ABSOLUTE)); |
| 102 // This will have 1 step, namely, the QCMS transform. | 102 // This will be converted to a transfer function and then linear transform. |
| 103 EXPECT_EQ(toxyzd50_fromicc->NumberOfStepsForTesting(), 1u); | 103 EXPECT_EQ(toxyzd50_fromicc->NumberOfStepsForTesting(), 2u); |
| 104 toxyzd50_fromicc->Transform(&value_fromicc, 1); | 104 toxyzd50_fromicc->Transform(&value_fromicc, 1); |
| 105 | 105 |
| 106 std::unique_ptr<ColorTransform> toxyzd50_default( | 106 std::unique_ptr<ColorTransform> toxyzd50_default( |
| 107 ColorTransform::NewColorTransform( | 107 ColorTransform::NewColorTransform( |
| 108 srgb_default, xyzd50, ColorTransform::Intent::INTENT_ABSOLUTE)); | 108 srgb_default, xyzd50, ColorTransform::Intent::INTENT_ABSOLUTE)); |
| 109 // This will have a transfer function and then linear transform. | 109 // This will have a transfer function and then linear transform. |
| 110 EXPECT_EQ(toxyzd50_default->NumberOfStepsForTesting(), 2u); | 110 EXPECT_EQ(toxyzd50_default->NumberOfStepsForTesting(), 2u); |
| 111 toxyzd50_default->Transform(&value_default, 1); | 111 toxyzd50_default->Transform(&value_default, 1); |
| 112 | 112 |
| 113 EXPECT_NEAR(value_fromicc.x(), value_default.x(), kEpsilon); | 113 EXPECT_NEAR(value_fromicc.x(), value_default.x(), kEpsilon); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon); | 193 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon); |
| 194 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon); | 194 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon); |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST(SimpleColorSpace, UnknownToSRGB) { | 197 TEST(SimpleColorSpace, UnknownToSRGB) { |
| 198 ColorSpace unknown; | 198 ColorSpace unknown; |
| 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 EXPECT_EQ(t->NumberOfStepsForTesting(), 0u); |
| 204 |
| 205 ColorTransform::TriStim input; |
| 206 ColorTransform::TriStim tmp; |
| 207 input = ColorTransform::TriStim(16.0f / 255.0f, 0.5f, 0.5f); |
| 208 tmp = input; |
| 204 t->Transform(&tmp, 1); | 209 t->Transform(&tmp, 1); |
| 205 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); | 210 EXPECT_NEAR(tmp.x(), input.x(), 0.001f); |
| 206 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); | 211 EXPECT_NEAR(tmp.y(), input.y(), 0.001f); |
| 207 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); | 212 EXPECT_NEAR(tmp.z(), input.z(), 0.001f); |
| 208 | 213 |
| 209 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); | 214 input = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); |
| 215 tmp = input; |
| 210 t->Transform(&tmp, 1); | 216 t->Transform(&tmp, 1); |
| 211 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); | 217 EXPECT_NEAR(tmp.x(), input.x(), 0.001f); |
| 212 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); | 218 EXPECT_NEAR(tmp.y(), input.y(), 0.001f); |
| 213 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); | 219 EXPECT_NEAR(tmp.z(), input.z(), 0.001f); |
| 214 | 220 |
| 215 // Test a blue color | 221 // Test a blue color |
| 216 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); | 222 input = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); |
| 223 tmp = input; |
| 217 t->Transform(&tmp, 1); | 224 t->Transform(&tmp, 1); |
| 218 EXPECT_GT(tmp.z(), tmp.x()); | 225 EXPECT_NEAR(tmp.x(), input.x(), 0.001f); |
| 219 EXPECT_GT(tmp.z(), tmp.y()); | 226 EXPECT_NEAR(tmp.y(), input.y(), 0.001f); |
| 227 EXPECT_NEAR(tmp.z(), input.z(), 0.001f); |
| 220 } | 228 } |
| 221 | 229 |
| 222 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; | 230 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; |
| 223 | 231 |
| 224 TEST_P(TransferTest, basicTest) { | 232 TEST_P(TransferTest, basicTest) { |
| 225 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), | 233 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), |
| 226 ColorSpace::MatrixID::RGB, | 234 ColorSpace::MatrixID::RGB, |
| 227 ColorSpace::RangeID::FULL); | 235 ColorSpace::RangeID::FULL); |
| 228 gfx::ColorSpace space_linear( | 236 gfx::ColorSpace space_linear( |
| 229 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, | 237 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 328 |
| 321 INSTANTIATE_TEST_CASE_P( | 329 INSTANTIATE_TEST_CASE_P( |
| 322 C, | 330 C, |
| 323 ColorSpaceTest, | 331 ColorSpaceTest, |
| 324 testing::Combine(testing::ValuesIn(all_primaries), | 332 testing::Combine(testing::ValuesIn(all_primaries), |
| 325 testing::Values(ColorSpace::TransferID::BT709), | 333 testing::Values(ColorSpace::TransferID::BT709), |
| 326 testing::ValuesIn(all_matrices), | 334 testing::ValuesIn(all_matrices), |
| 327 testing::ValuesIn(all_ranges), | 335 testing::ValuesIn(all_ranges), |
| 328 testing::ValuesIn(intents))); | 336 testing::ValuesIn(intents))); |
| 329 } // namespace | 337 } // namespace |
| OLD | NEW |