Chromium Code Reviews| 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.1f, 0.5f, 0.9f); | 97 value_fromicc = value_default = ColorTransform::TriStim(0.1f, 0.5f, 0.9f); |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon); | 187 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon); |
| 188 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon); | 188 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon); |
| 189 | 189 |
| 190 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f); | 190 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f); |
| 191 t->Transform(&tmp, 1); | 191 t->Transform(&tmp, 1); |
| 192 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon); | 192 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon); |
| 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) { |
|
hubbe
2017/02/16 01:28:29
The changes in this test confuse me.
1. They seem
ccameron
2017/02/16 01:58:47
I moved this to the previous color patch and rebas
| |
| 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 ColorTransform::TriStim input; |
| 204 ColorTransform::TriStim tmp; | |
| 205 input = ColorTransform::TriStim(16.0f / 255.0f, 0.5f, 0.5f); | |
| 206 tmp = input; | |
| 204 t->Transform(&tmp, 1); | 207 t->Transform(&tmp, 1); |
| 205 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); | 208 EXPECT_NEAR(tmp.x(), input.x(), 0.001f); |
| 206 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); | 209 EXPECT_NEAR(tmp.y(), input.y(), 0.001f); |
| 207 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); | 210 EXPECT_NEAR(tmp.z(), input.z(), 0.001f); |
| 208 | 211 |
| 209 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); | 212 input = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); |
| 213 tmp = input; | |
| 210 t->Transform(&tmp, 1); | 214 t->Transform(&tmp, 1); |
| 211 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); | 215 EXPECT_NEAR(tmp.x(), input.x(), 0.001f); |
| 212 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); | 216 EXPECT_NEAR(tmp.y(), input.y(), 0.001f); |
| 213 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); | 217 EXPECT_NEAR(tmp.z(), input.z(), 0.001f); |
| 214 | 218 |
| 215 // Test a blue color | 219 // Test a blue color |
| 216 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); | 220 input = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); |
| 221 tmp = input; | |
| 217 t->Transform(&tmp, 1); | 222 t->Transform(&tmp, 1); |
| 218 EXPECT_GT(tmp.z(), tmp.x()); | 223 EXPECT_NEAR(tmp.x(), input.x(), 0.001f); |
| 219 EXPECT_GT(tmp.z(), tmp.y()); | 224 EXPECT_NEAR(tmp.y(), input.y(), 0.001f); |
| 225 EXPECT_NEAR(tmp.z(), input.z(), 0.001f); | |
| 220 } | 226 } |
| 221 | 227 |
| 222 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; | 228 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; |
| 223 | 229 |
| 224 TEST_P(TransferTest, basicTest) { | 230 TEST_P(TransferTest, basicTest) { |
| 225 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), | 231 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), |
| 226 ColorSpace::MatrixID::RGB, | 232 ColorSpace::MatrixID::RGB, |
| 227 ColorSpace::RangeID::FULL); | 233 ColorSpace::RangeID::FULL); |
| 228 gfx::ColorSpace space_linear( | 234 gfx::ColorSpace space_linear( |
| 229 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, | 235 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 326 |
| 321 INSTANTIATE_TEST_CASE_P( | 327 INSTANTIATE_TEST_CASE_P( |
| 322 C, | 328 C, |
| 323 ColorSpaceTest, | 329 ColorSpaceTest, |
| 324 testing::Combine(testing::ValuesIn(all_primaries), | 330 testing::Combine(testing::ValuesIn(all_primaries), |
| 325 testing::Values(ColorSpace::TransferID::BT709), | 331 testing::Values(ColorSpace::TransferID::BT709), |
| 326 testing::ValuesIn(all_matrices), | 332 testing::ValuesIn(all_matrices), |
| 327 testing::ValuesIn(all_ranges), | 333 testing::ValuesIn(all_ranges), |
| 328 testing::ValuesIn(intents))); | 334 testing::ValuesIn(intents))); |
| 329 } // namespace | 335 } // namespace |
| OLD | NEW |