Index: ui/gfx/color_transform_unittest.cc |
diff --git a/ui/gfx/color_transform_unittest.cc b/ui/gfx/color_transform_unittest.cc |
index 36e3ab21e958862b229fd21559793cb1c818f4f3..56d806a8e5af9ce4b57081004f31cfe0e3aefdad 100644 |
--- a/ui/gfx/color_transform_unittest.cc |
+++ b/ui/gfx/color_transform_unittest.cc |
@@ -82,6 +82,46 @@ TEST(SimpleColorSpace, BT709toSRGB) { |
EXPECT_GT(tmp.z(), tmp.y()); |
} |
+TEST(SimpleColorSpace, TransferFnCancel) { |
+ ColorSpace::PrimaryID primary = ColorSpace::PrimaryID::BT709; |
+ ColorSpace::MatrixID matrix = ColorSpace::MatrixID::RGB; |
+ ColorSpace::RangeID range = ColorSpace::RangeID::FULL; |
+ |
+ // BT709 has a gamma of 2.2222 (with some adjustments) |
+ ColorSpace bt709(primary, ColorSpace::TransferID::BT709, matrix, range); |
+ |
+ // IEC61966_2_1 has the sRGB gamma of 2.4 (with some adjustments) |
+ ColorSpace srgb(primary, ColorSpace::TransferID::IEC61966_2_1, matrix, range); |
+ |
+ // gamma28 is a simple exponential |
+ ColorSpace gamma28(primary, ColorSpace::TransferID::GAMMA28, matrix, range); |
+ |
+ // gamma24 is a simple exponential |
+ ColorSpace gamma24(primary, ColorSpace::TransferID::GAMMA24, matrix, range); |
+ |
+ // BT709 source is common for video and sRGB destination is common for |
+ // monitors. The two transfer functions are very close, and should cancel |
+ // out (so the transfer between them should be the identity). This particular |
+ // case is important for power reasons. |
+ std::unique_ptr<ColorTransform> bt709_to_srgb( |
+ ColorTransform::NewColorTransform( |
+ bt709, srgb, ColorTransform::Intent::INTENT_PERCEPTUAL)); |
+ EXPECT_EQ(bt709_to_srgb->NumberOfStepsForTesting(), 0u); |
+ |
+ // Gamma 2.8 isn't even close to BT709 and won't cancel out (so we will have |
+ // two steps in the transform -- to-linear and from-linear). |
+ std::unique_ptr<ColorTransform> bt709_to_gamma28( |
+ ColorTransform::NewColorTransform( |
+ bt709, gamma28, ColorTransform::Intent::INTENT_PERCEPTUAL)); |
+ EXPECT_EQ(bt709_to_gamma28->NumberOfStepsForTesting(), 2u); |
+ |
+ // Gamma 2.4 is closer to BT709, but not close enough to actually cancel out. |
+ std::unique_ptr<ColorTransform> bt709_to_gamma24( |
+ ColorTransform::NewColorTransform( |
+ bt709, gamma24, ColorTransform::Intent::INTENT_PERCEPTUAL)); |
+ EXPECT_EQ(bt709_to_gamma24->NumberOfStepsForTesting(), 2u); |
+} |
+ |
TEST(SimpleColorSpace, SRGBFromICCAndNotICC) { |
float kEpsilon = 0.001f; |
ColorTransform::TriStim value_fromicc; |