| 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" |
| 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 GetTransferMatrix(ColorSpace::MatrixID id); | 16 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id); |
| 17 | 17 |
| 18 ColorSpace::PrimaryID all_primaries[] = { | 18 ColorSpace::PrimaryID all_primaries[] = { |
| 19 ColorSpace::PrimaryID::BT709, ColorSpace::PrimaryID::BT470M, | 19 ColorSpace::PrimaryID::BT709, ColorSpace::PrimaryID::BT470M, |
| 20 ColorSpace::PrimaryID::BT470BG, ColorSpace::PrimaryID::SMPTE170M, | 20 ColorSpace::PrimaryID::BT470BG, ColorSpace::PrimaryID::SMPTE170M, |
| 21 ColorSpace::PrimaryID::SMPTE240M, ColorSpace::PrimaryID::FILM, | 21 ColorSpace::PrimaryID::SMPTE240M, ColorSpace::PrimaryID::FILM, |
| 22 ColorSpace::PrimaryID::BT2020, ColorSpace::PrimaryID::SMPTEST428_1, | 22 ColorSpace::PrimaryID::BT2020, ColorSpace::PrimaryID::SMPTEST428_1, |
| 23 ColorSpace::PrimaryID::SMPTEST431_2, ColorSpace::PrimaryID::SMPTEST432_1, | 23 ColorSpace::PrimaryID::SMPTEST431_2, ColorSpace::PrimaryID::SMPTEST432_1, |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 ColorSpace::TransferID all_transfers[] = { | 26 ColorSpace::TransferID all_transfers[] = { |
| 27 ColorSpace::TransferID::BT709, ColorSpace::TransferID::GAMMA22, | 27 ColorSpace::TransferID::BT709, |
| 28 ColorSpace::TransferID::GAMMA28, ColorSpace::TransferID::SMPTE170M, | 28 ColorSpace::TransferID::GAMMA22, |
| 29 ColorSpace::TransferID::SMPTE240M, ColorSpace::TransferID::LINEAR, | 29 ColorSpace::TransferID::GAMMA28, |
| 30 ColorSpace::TransferID::LOG, ColorSpace::TransferID::LOG_SQRT, | 30 ColorSpace::TransferID::SMPTE170M, |
| 31 ColorSpace::TransferID::IEC61966_2_4, ColorSpace::TransferID::BT1361_ECG, | 31 ColorSpace::TransferID::SMPTE240M, |
| 32 ColorSpace::TransferID::IEC61966_2_1, ColorSpace::TransferID::BT2020_10, | 32 ColorSpace::TransferID::LINEAR, |
| 33 ColorSpace::TransferID::BT2020_12, ColorSpace::TransferID::SMPTEST2084, | 33 ColorSpace::TransferID::LOG, |
| 34 ColorSpace::TransferID::LOG_SQRT, |
| 35 ColorSpace::TransferID::IEC61966_2_4, |
| 36 ColorSpace::TransferID::BT1361_ECG, |
| 37 ColorSpace::TransferID::IEC61966_2_1, |
| 38 ColorSpace::TransferID::BT2020_10, |
| 39 ColorSpace::TransferID::BT2020_12, |
| 40 ColorSpace::TransferID::SMPTEST2084, |
| 34 ColorSpace::TransferID::ARIB_STD_B67, | 41 ColorSpace::TransferID::ARIB_STD_B67, |
| 42 ColorSpace::TransferID::IEC61966_2_1_HDR, |
| 35 // This one is weird as the non-linear numbers are not between 0 and 1. | 43 // This one is weird as the non-linear numbers are not between 0 and 1. |
| 36 // TODO(hubbe): Test this separately. | 44 // TODO(hubbe): Test this separately. |
| 37 // ColorSpace::TransferID::SMPTEST428_1, | 45 // ColorSpace::TransferID::SMPTEST428_1, |
| 38 }; | 46 }; |
| 39 | 47 |
| 48 ColorSpace::TransferID extended_transfers[] = { |
| 49 ColorSpace::TransferID::LINEAR_HDR, |
| 50 ColorSpace::TransferID::IEC61966_2_1_HDR, |
| 51 }; |
| 52 |
| 40 ColorSpace::MatrixID all_matrices[] = { | 53 ColorSpace::MatrixID all_matrices[] = { |
| 41 ColorSpace::MatrixID::RGB, ColorSpace::MatrixID::BT709, | 54 ColorSpace::MatrixID::RGB, ColorSpace::MatrixID::BT709, |
| 42 ColorSpace::MatrixID::FCC, ColorSpace::MatrixID::BT470BG, | 55 ColorSpace::MatrixID::FCC, ColorSpace::MatrixID::BT470BG, |
| 43 ColorSpace::MatrixID::SMPTE170M, ColorSpace::MatrixID::SMPTE240M, | 56 ColorSpace::MatrixID::SMPTE170M, ColorSpace::MatrixID::SMPTE240M, |
| 44 | 57 |
| 45 // YCOCG produces lots of negative values which isn't compatible with many | 58 // YCOCG produces lots of negative values which isn't compatible with many |
| 46 // transfer functions. | 59 // transfer functions. |
| 47 // TODO(hubbe): Test this separately. | 60 // TODO(hubbe): Test this separately. |
| 48 // ColorSpace::MatrixID::YCOCG, | 61 // ColorSpace::MatrixID::YCOCG, |
| 49 ColorSpace::MatrixID::BT2020_NCL, ColorSpace::MatrixID::BT2020_CL, | 62 ColorSpace::MatrixID::BT2020_NCL, ColorSpace::MatrixID::BT2020_CL, |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 to_linear->Transform(&tristim, 1); | 463 to_linear->Transform(&tristim, 1); |
| 451 from_linear->Transform(&tristim, 1); | 464 from_linear->Transform(&tristim, 1); |
| 452 EXPECT_NEAR(x, tristim.x(), 0.001f); | 465 EXPECT_NEAR(x, tristim.x(), 0.001f); |
| 453 } | 466 } |
| 454 } | 467 } |
| 455 | 468 |
| 456 INSTANTIATE_TEST_CASE_P(ColorSpace, | 469 INSTANTIATE_TEST_CASE_P(ColorSpace, |
| 457 TransferTest, | 470 TransferTest, |
| 458 testing::ValuesIn(all_transfers)); | 471 testing::ValuesIn(all_transfers)); |
| 459 | 472 |
| 473 class ExtendedTransferTest |
| 474 : public testing::TestWithParam<ColorSpace::TransferID> {}; |
| 475 |
| 476 TEST_P(ExtendedTransferTest, extendedTest) { |
| 477 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), |
| 478 ColorSpace::MatrixID::RGB, |
| 479 ColorSpace::RangeID::FULL); |
| 480 gfx::ColorSpace space_linear( |
| 481 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, |
| 482 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); |
| 483 |
| 484 std::unique_ptr<ColorTransform> to_linear(ColorTransform::NewColorTransform( |
| 485 space_with_transfer, space_linear, |
| 486 ColorTransform::Intent::INTENT_ABSOLUTE)); |
| 487 |
| 488 std::unique_ptr<ColorTransform> from_linear(ColorTransform::NewColorTransform( |
| 489 space_linear, space_with_transfer, |
| 490 ColorTransform::Intent::INTENT_ABSOLUTE)); |
| 491 |
| 492 for (float x = -2.0f; x <= 2.0f; x += 1.0f / 32.0f) { |
| 493 ColorTransform::TriStim tristim(x, x, x); |
| 494 to_linear->Transform(&tristim, 1); |
| 495 from_linear->Transform(&tristim, 1); |
| 496 EXPECT_NEAR(x, tristim.x(), 0.001f); |
| 497 } |
| 498 } |
| 499 |
| 500 INSTANTIATE_TEST_CASE_P(ColorSpace, |
| 501 ExtendedTransferTest, |
| 502 testing::ValuesIn(extended_transfers)); |
| 503 |
| 460 typedef std::tr1::tuple<ColorSpace::PrimaryID, | 504 typedef std::tr1::tuple<ColorSpace::PrimaryID, |
| 461 ColorSpace::TransferID, | 505 ColorSpace::TransferID, |
| 462 ColorSpace::MatrixID, | 506 ColorSpace::MatrixID, |
| 463 ColorSpace::RangeID, | 507 ColorSpace::RangeID, |
| 464 ColorTransform::Intent> | 508 ColorTransform::Intent> |
| 465 ColorSpaceTestData; | 509 ColorSpaceTestData; |
| 466 | 510 |
| 467 class ColorSpaceTest : public testing::TestWithParam<ColorSpaceTestData> { | 511 class ColorSpaceTest : public testing::TestWithParam<ColorSpaceTestData> { |
| 468 public: | 512 public: |
| 469 ColorSpaceTest() | 513 ColorSpaceTest() |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 565 |
| 522 INSTANTIATE_TEST_CASE_P( | 566 INSTANTIATE_TEST_CASE_P( |
| 523 C, | 567 C, |
| 524 ColorSpaceTest, | 568 ColorSpaceTest, |
| 525 testing::Combine(testing::ValuesIn(all_primaries), | 569 testing::Combine(testing::ValuesIn(all_primaries), |
| 526 testing::Values(ColorSpace::TransferID::BT709), | 570 testing::Values(ColorSpace::TransferID::BT709), |
| 527 testing::ValuesIn(all_matrices), | 571 testing::ValuesIn(all_matrices), |
| 528 testing::ValuesIn(all_ranges), | 572 testing::ValuesIn(all_ranges), |
| 529 testing::ValuesIn(intents))); | 573 testing::ValuesIn(intents))); |
| 530 } // namespace | 574 } // namespace |
| OLD | NEW |