Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: ui/gfx/color_transform_unittest.cc

Issue 2663453002: Revert of Use SkICC in gfx::ICCProfile and gfx::ColorSpace (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_transform.cc ('k') | ui/gfx/icc_profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GetPrimaryMatrix(ColorSpace::PrimaryID id);
16 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id); 17 GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id);
18 GFX_EXPORT float ToLinear(ColorSpace::TransferID id, float v);
19 GFX_EXPORT float FromLinear(ColorSpace::TransferID id, float v);
17 20
18 ColorSpace::PrimaryID all_primaries[] = { 21 ColorSpace::PrimaryID all_primaries[] = {
19 ColorSpace::PrimaryID::BT709, ColorSpace::PrimaryID::BT470M, 22 ColorSpace::PrimaryID::BT709, ColorSpace::PrimaryID::BT470M,
20 ColorSpace::PrimaryID::BT470BG, ColorSpace::PrimaryID::SMPTE170M, 23 ColorSpace::PrimaryID::BT470BG, ColorSpace::PrimaryID::SMPTE170M,
21 ColorSpace::PrimaryID::SMPTE240M, ColorSpace::PrimaryID::FILM, 24 ColorSpace::PrimaryID::SMPTE240M, ColorSpace::PrimaryID::FILM,
22 ColorSpace::PrimaryID::BT2020, ColorSpace::PrimaryID::SMPTEST428_1, 25 ColorSpace::PrimaryID::BT2020, ColorSpace::PrimaryID::SMPTEST428_1,
23 ColorSpace::PrimaryID::SMPTEST431_2, ColorSpace::PrimaryID::SMPTEST432_1, 26 ColorSpace::PrimaryID::SMPTEST431_2, ColorSpace::PrimaryID::SMPTEST432_1,
24 }; 27 };
25 28
26 ColorSpace::TransferID all_transfers[] = { 29 ColorSpace::TransferID all_transfers[] = {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); 110 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f);
108 t->transform(&tmp, 1); 111 t->transform(&tmp, 1);
109 EXPECT_GT(tmp.z(), tmp.x()); 112 EXPECT_GT(tmp.z(), tmp.x());
110 EXPECT_GT(tmp.z(), tmp.y()); 113 EXPECT_GT(tmp.z(), tmp.y());
111 } 114 }
112 115
113 TEST(SimpleColorSpace, GetColorSpace) { 116 TEST(SimpleColorSpace, GetColorSpace) {
114 ICCProfile srgb_icc = ICCProfileForTestingSRGB(); 117 ICCProfile srgb_icc = ICCProfileForTestingSRGB();
115 ColorSpace sRGB = srgb_icc.GetColorSpace(); 118 ColorSpace sRGB = srgb_icc.GetColorSpace();
116 ColorSpace sRGB2 = sRGB; 119 ColorSpace sRGB2 = sRGB;
117 const float kEpsilon = 1.5f / 255.f;
118 120
119 // Prevent sRGB2 from using a cached ICC profile. 121 // Prevent sRGB2 from using a cached ICC profile.
120 sRGB2.icc_profile_id_ = 0; 122 sRGB2.icc_profile_id_ = 0;
121 123
122 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 124 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
123 sRGB, sRGB2, ColorTransform::Intent::INTENT_ABSOLUTE)); 125 sRGB, sRGB2, ColorTransform::Intent::INTENT_ABSOLUTE));
124 126
125 ColorTransform::TriStim tmp(1.0f, 1.0f, 1.0f); 127 ColorTransform::TriStim tmp(1.0f, 1.0f, 1.0f);
126 t->transform(&tmp, 1); 128 t->transform(&tmp, 1);
127 EXPECT_NEAR(tmp.x(), 1.0f, kEpsilon); 129 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f);
128 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon); 130 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f);
129 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon); 131 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f);
130 132
131 tmp = ColorTransform::TriStim(1.0f, 0.0f, 0.0f); 133 tmp = ColorTransform::TriStim(1.0f, 0.0f, 0.0f);
132 t->transform(&tmp, 1); 134 t->transform(&tmp, 1);
133 EXPECT_NEAR(tmp.x(), 1.0f, kEpsilon); 135 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f);
134 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon); 136 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f);
135 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon); 137 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f);
136 138
137 tmp = ColorTransform::TriStim(0.0f, 1.0f, 0.0f); 139 tmp = ColorTransform::TriStim(0.0f, 1.0f, 0.0f);
138 t->transform(&tmp, 1); 140 t->transform(&tmp, 1);
139 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon); 141 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f);
140 EXPECT_NEAR(tmp.y(), 1.0f, kEpsilon); 142 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f);
141 EXPECT_NEAR(tmp.z(), 0.0f, kEpsilon); 143 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f);
142 144
143 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f); 145 tmp = ColorTransform::TriStim(0.0f, 0.0f, 1.0f);
144 t->transform(&tmp, 1); 146 t->transform(&tmp, 1);
145 EXPECT_NEAR(tmp.x(), 0.0f, kEpsilon); 147 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f);
146 EXPECT_NEAR(tmp.y(), 0.0f, kEpsilon); 148 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f);
147 EXPECT_NEAR(tmp.z(), 1.0f, kEpsilon); 149 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f);
148 } 150 }
149 151
150 TEST(SimpleColorSpace, UnknownToSRGB) { 152 TEST(SimpleColorSpace, UnknownToSRGB) {
151 ColorSpace unknown; 153 ColorSpace unknown;
152 ColorSpace sRGB = ColorSpace::CreateSRGB(); 154 ColorSpace sRGB = ColorSpace::CreateSRGB();
153 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 155 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
154 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL)); 156 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL));
155 157
156 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f); 158 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f);
157 t->transform(&tmp, 1); 159 t->transform(&tmp, 1);
158 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); 160 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f);
159 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); 161 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f);
160 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); 162 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f);
161 163
162 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); 164 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f);
163 t->transform(&tmp, 1); 165 t->transform(&tmp, 1);
164 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); 166 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f);
165 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); 167 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f);
166 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); 168 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f);
167 169
168 // Test a blue color 170 // Test a blue color
169 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); 171 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f);
170 t->transform(&tmp, 1); 172 t->transform(&tmp, 1);
171 EXPECT_GT(tmp.z(), tmp.x()); 173 EXPECT_GT(tmp.z(), tmp.x());
172 EXPECT_GT(tmp.z(), tmp.y()); 174 EXPECT_GT(tmp.z(), tmp.y());
173 } 175 }
174 176
177 class PrimaryTest : public testing::TestWithParam<ColorSpace::PrimaryID> {};
178
179 TEST_P(PrimaryTest, checkInvertible) {
180 EXPECT_EQ(GetPrimaryMatrix(GetParam()).matrix().get(3, 3), 1.0f);
181 // Check that all primary matrices are invertable.
182 EXPECT_TRUE(GetPrimaryMatrix(GetParam()).IsInvertible());
183 }
184
185 INSTANTIATE_TEST_CASE_P(ColorSpace,
186 PrimaryTest,
187 testing::ValuesIn(all_primaries));
188
175 class MatrixTest : public testing::TestWithParam<ColorSpace::MatrixID> {}; 189 class MatrixTest : public testing::TestWithParam<ColorSpace::MatrixID> {};
176 190
177 TEST_P(MatrixTest, checkInvertible) { 191 TEST_P(MatrixTest, checkInvertible) {
178 EXPECT_EQ(GetTransferMatrix(GetParam()).matrix().get(3, 3), 1.0f); 192 EXPECT_EQ(GetTransferMatrix(GetParam()).matrix().get(3, 3), 1.0f);
179 // Check that all transfer matrices are invertable. 193 // Check that all transfer matrices are invertable.
180 EXPECT_TRUE(GetTransferMatrix(GetParam()).IsInvertible()); 194 EXPECT_TRUE(GetTransferMatrix(GetParam()).IsInvertible());
181 }; 195 };
182 196
183 INSTANTIATE_TEST_CASE_P(ColorSpace, 197 INSTANTIATE_TEST_CASE_P(ColorSpace,
184 MatrixTest, 198 MatrixTest,
185 testing::ValuesIn(all_matrices)); 199 testing::ValuesIn(all_matrices));
186 200
187 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; 201 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {};
188 202
189 TEST_P(TransferTest, basicTest) { 203 TEST_P(TransferTest, basicTest) {
190 for (float x = 0.0f; x <= 1.0f; x += 1.0f / 128.0f) { 204 for (float x = 0.0f; x <= 1.0f; x += 1.0f / 128.0f) {
191 float linear = ColorTransform::ToLinearForTesting(GetParam(), x); 205 float linear = ToLinear(GetParam(), x);
192 float x2 = ColorTransform::FromLinearForTesting(GetParam(), linear); 206 float x2 = FromLinear(GetParam(), linear);
193 EXPECT_NEAR(x, x2, 0.001f); 207 EXPECT_NEAR(x, x2, 0.001f);
194 } 208 }
195 } 209 }
196 210
197 INSTANTIATE_TEST_CASE_P(ColorSpace, 211 INSTANTIATE_TEST_CASE_P(ColorSpace,
198 TransferTest, 212 TransferTest,
199 testing::ValuesIn(all_transfers)); 213 testing::ValuesIn(all_transfers));
200 214
201 typedef std::tr1::tuple<ColorSpace::PrimaryID, 215 typedef std::tr1::tuple<ColorSpace::PrimaryID,
202 ColorSpace::TransferID, 216 ColorSpace::TransferID,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 276
263 INSTANTIATE_TEST_CASE_P( 277 INSTANTIATE_TEST_CASE_P(
264 C, 278 C,
265 ColorSpaceTest, 279 ColorSpaceTest,
266 testing::Combine(testing::ValuesIn(all_primaries), 280 testing::Combine(testing::ValuesIn(all_primaries),
267 testing::Values(ColorSpace::TransferID::BT709), 281 testing::Values(ColorSpace::TransferID::BT709),
268 testing::ValuesIn(all_matrices), 282 testing::ValuesIn(all_matrices),
269 testing::ValuesIn(all_ranges), 283 testing::ValuesIn(all_ranges),
270 testing::ValuesIn(intents))); 284 testing::ValuesIn(intents)));
271 } // namespace 285 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/color_transform.cc ('k') | ui/gfx/icc_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698