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

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

Issue 2697863003: color: Clarify default behaviors (Closed)
Patch Set: Do less 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
« ui/gfx/color_space.h ('K') | « ui/gfx/color_transform.cc ('k') | no next file » | 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"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, UnknownVideoToSRGB) {
198 ColorSpace unknown; 198 // Invalid video spaces should be BT709.
199 ColorSpace unknown = gfx::ColorSpace::CreateVideo(
200 -1, -1, -1, gfx::ColorSpace::RangeID::LIMITED);
199 ColorSpace sRGB = ColorSpace::CreateSRGB(); 201 ColorSpace sRGB = ColorSpace::CreateSRGB();
200 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform( 202 std::unique_ptr<ColorTransform> t(ColorTransform::NewColorTransform(
201 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL)); 203 unknown, sRGB, ColorTransform::Intent::INTENT_PERCEPTUAL));
202 204
203 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f); 205 ColorTransform::TriStim tmp(16.0f / 255.0f, 0.5f, 0.5f);
204 t->Transform(&tmp, 1); 206 t->Transform(&tmp, 1);
205 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f); 207 EXPECT_NEAR(tmp.x(), 0.0f, 0.001f);
206 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f); 208 EXPECT_NEAR(tmp.y(), 0.0f, 0.001f);
207 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f); 209 EXPECT_NEAR(tmp.z(), 0.0f, 0.001f);
208 210
209 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f); 211 tmp = ColorTransform::TriStim(235.0f / 255.0f, 0.5f, 0.5f);
210 t->Transform(&tmp, 1); 212 t->Transform(&tmp, 1);
211 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f); 213 EXPECT_NEAR(tmp.x(), 1.0f, 0.001f);
212 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f); 214 EXPECT_NEAR(tmp.y(), 1.0f, 0.001f);
213 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f); 215 EXPECT_NEAR(tmp.z(), 1.0f, 0.001f);
214 216
215 // Test a blue color 217 // Test a blue color
216 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f); 218 tmp = ColorTransform::TriStim(128.0f / 255.0f, 240.0f / 255.0f, 0.5f);
217 t->Transform(&tmp, 1); 219 t->Transform(&tmp, 1);
218 EXPECT_GT(tmp.z(), tmp.x()); 220 EXPECT_GT(tmp.z(), tmp.x());
219 EXPECT_GT(tmp.z(), tmp.y()); 221 EXPECT_GT(tmp.z(), tmp.y());
220 } 222 }
221 223
224 TEST(SimpleColorSpace, DefaultToSRGB) {
225 // The default value should do no transformation, regardless of destination.
226 ColorSpace unknown;
227 std::unique_ptr<ColorTransform> t1(ColorTransform::NewColorTransform(
228 unknown, ColorSpace::CreateSRGB(),
229 ColorTransform::Intent::INTENT_PERCEPTUAL));
230 EXPECT_EQ(t1->NumberOfStepsForTesting(), 0u);
231 std::unique_ptr<ColorTransform> t2(ColorTransform::NewColorTransform(
232 unknown, ColorSpace::CreateXYZD50(),
233 ColorTransform::Intent::INTENT_PERCEPTUAL));
234 EXPECT_EQ(t2->NumberOfStepsForTesting(), 0u);
235 }
236
222 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {}; 237 class TransferTest : public testing::TestWithParam<ColorSpace::TransferID> {};
223 238
224 TEST_P(TransferTest, basicTest) { 239 TEST_P(TransferTest, basicTest) {
225 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(), 240 gfx::ColorSpace space_with_transfer(ColorSpace::PrimaryID::BT709, GetParam(),
226 ColorSpace::MatrixID::RGB, 241 ColorSpace::MatrixID::RGB,
227 ColorSpace::RangeID::FULL); 242 ColorSpace::RangeID::FULL);
228 gfx::ColorSpace space_linear( 243 gfx::ColorSpace space_linear(
229 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR, 244 ColorSpace::PrimaryID::BT709, ColorSpace::TransferID::LINEAR,
230 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); 245 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL);
231 246
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 335
321 INSTANTIATE_TEST_CASE_P( 336 INSTANTIATE_TEST_CASE_P(
322 C, 337 C,
323 ColorSpaceTest, 338 ColorSpaceTest,
324 testing::Combine(testing::ValuesIn(all_primaries), 339 testing::Combine(testing::ValuesIn(all_primaries),
325 testing::Values(ColorSpace::TransferID::BT709), 340 testing::Values(ColorSpace::TransferID::BT709),
326 testing::ValuesIn(all_matrices), 341 testing::ValuesIn(all_matrices),
327 testing::ValuesIn(all_ranges), 342 testing::ValuesIn(all_ranges),
328 testing::ValuesIn(intents))); 343 testing::ValuesIn(intents)));
329 } // namespace 344 } // namespace
OLDNEW
« ui/gfx/color_space.h ('K') | « ui/gfx/color_transform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698