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/transform.h" | 10 #include "ui/gfx/transform.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); | 76 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); |
77 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); | 77 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); |
78 | 78 |
79 // Test a blue color | 79 // Test a blue color |
80 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); | 80 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); |
81 t->transform(&tmp, 1); | 81 t->transform(&tmp, 1); |
82 EXPECT_GT(tmp.z(), tmp.x()); | 82 EXPECT_GT(tmp.z(), tmp.x()); |
83 EXPECT_GT(tmp.z(), tmp.y()); | 83 EXPECT_GT(tmp.z(), tmp.y()); |
84 } | 84 } |
85 | 85 |
| 86 TEST(SimpleColorSpace, GetAffineApproximation) { |
| 87 // Two linear color spaces, result should be a perfect translation. |
| 88 ColorSpace from_colorspace( |
| 89 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, |
| 90 ColorSpace::MatrixID::BT709, ColorSpace::RangeID::FULL); |
| 91 ColorSpace to_colorspace( |
| 92 ColorSpace::PrimaryID::BT2020, ColorSpace::TransferID::LINEAR, |
| 93 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); |
| 94 |
| 95 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( |
| 96 from_colorspace, to_colorspace, ColorTransform::Intent::INTENT_ABSOLUTE)); |
| 97 Transform transform; |
| 98 EXPECT_TRUE(t->GetAffineApproximation(&transform)); |
| 99 |
| 100 for (int x = 0; x <= 2; x++) { |
| 101 for (int y = 0; y <= 2; y++) { |
| 102 for (int z = 0; z <= 2; z++) { |
| 103 ColorTransform::TriStim A(x / 2.0f, y / 2.0f, z / 2.0f); |
| 104 ColorTransform::TriStim B(A); |
| 105 t->transform(&A, 1); |
| 106 transform.TransformPoint(&B); |
| 107 EXPECT_NEAR(A.x(), B.x(), 0.001); |
| 108 EXPECT_NEAR(A.y(), B.y(), 0.001); |
| 109 EXPECT_NEAR(A.z(), B.z(), 0.001); |
| 110 } |
| 111 } |
| 112 } |
| 113 } |
| 114 |
86 unsigned char srgb_icc_data[] = { | 115 unsigned char srgb_icc_data[] = { |
87 0x00, 0x00, 0x0b, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, | 116 0x00, 0x00, 0x0b, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, |
88 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20, | 117 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20, |
89 0x07, 0xd9, 0x00, 0x03, 0x00, 0x1b, 0x00, 0x15, 0x00, 0x24, 0x00, 0x1f, | 118 0x07, 0xd9, 0x00, 0x03, 0x00, 0x1b, 0x00, 0x15, 0x00, 0x24, 0x00, 0x1f, |
90 0x61, 0x63, 0x73, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 119 0x61, 0x63, 0x73, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | 120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, | 121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, |
93 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d, 0x00, 0x00, 0x00, 0x00, | 122 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d, 0x00, 0x00, 0x00, 0x00, |
94 0x12, 0xe2, 0xc7, 0xe9, 0xc6, 0x02, 0x6e, 0x10, 0x5e, 0xdb, 0x15, 0x15, | 123 0x12, 0xe2, 0xc7, 0xe9, 0xc6, 0x02, 0x6e, 0x10, 0x5e, 0xdb, 0x15, 0x15, |
95 0x9c, 0x6f, 0x26, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 124 0x9c, 0x6f, 0x26, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 testing::ValuesIn(all_ranges))); | 556 testing::ValuesIn(all_ranges))); |
528 | 557 |
529 INSTANTIATE_TEST_CASE_P( | 558 INSTANTIATE_TEST_CASE_P( |
530 C, | 559 C, |
531 ColorSpaceTest, | 560 ColorSpaceTest, |
532 testing::Combine(testing::ValuesIn(all_primaries), | 561 testing::Combine(testing::ValuesIn(all_primaries), |
533 testing::Values(ColorSpace::TransferID::BT709), | 562 testing::Values(ColorSpace::TransferID::BT709), |
534 testing::ValuesIn(all_matrices), | 563 testing::ValuesIn(all_matrices), |
535 testing::ValuesIn(all_ranges))); | 564 testing::ValuesIn(all_ranges))); |
536 } // namespace | 565 } // namespace |
OLD | NEW |