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

Unified Diff: ui/gfx/color_transform.cc

Issue 2300813002: First cut at making HDR content viewable on SDR display with color management. (Closed)
Patch Set: comment update Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/color_space.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_transform.cc
diff --git a/ui/gfx/color_transform.cc b/ui/gfx/color_transform.cc
index 4cbb325e3d15d83d751f0a18f403ab4fd08b154d..aeddd4cdb7d1d08cfbfc17a8aaebdd8508844dd6 100644
--- a/ui/gfx/color_transform.cc
+++ b/ui/gfx/color_transform.cc
@@ -398,9 +398,39 @@ GFX_EXPORT float ToLinear(ColorSpace::TransferID id, float v) {
case ColorSpace::TransferID::GAMMA24:
v = fmax(0.0f, v);
return powf(v, 2.4f);
+
+ case ColorSpace::TransferID::SMPTEST2084_NON_HDR:
+ v = fmax(0.0f, v);
+ return fmin(2.3f * pow(v, 2.8f), v / 5.0f + 0.8f);
}
}
+namespace {
+// Assumes bt2020
+float Luma(const ColorTransform::TriStim& c) {
+ return c.x() * 0.2627f + c.y() * 0.6780f + c.z() * 0.0593f;
+}
+};
+
+GFX_EXPORT ColorTransform::TriStim ToLinear(ColorSpace::TransferID id,
+ ColorTransform::TriStim color) {
+ ColorTransform::TriStim ret(ToLinear(id, color.x()), ToLinear(id, color.y()),
+ ToLinear(id, color.z()));
+
+ if (id == ColorSpace::TransferID::SMPTEST2084_NON_HDR) {
+ if (Luma(ret) > 0.0) {
+ ColorTransform::TriStim smpte2084(
+ ToLinear(ColorSpace::TransferID::SMPTEST2084, color.x()),
+ ToLinear(ColorSpace::TransferID::SMPTEST2084, color.y()),
+ ToLinear(ColorSpace::TransferID::SMPTEST2084, color.z()));
+ smpte2084.Scale(Luma(ret) / Luma(smpte2084));
+ ret = smpte2084;
+ }
+ }
+
+ return ret;
+}
+
GFX_EXPORT Transform GetTransferMatrix(ColorSpace::MatrixID id) {
float Kr = 0.0f, Kb = 0.0f;
switch (id) {
@@ -509,6 +539,12 @@ class ColorSpaceToColorSpaceTransform : public ColorTransform {
from_.transfer_ = ColorSpace::TransferID::GAMMA24;
break;
+ case ColorSpace::TransferID::SMPTEST2084:
+ // We don't have an HDR display, so replace SMPTE 2084 with something
+ // that returns ranges more or less suitable for a normal display.
+ from_.transfer_ = ColorSpace::TransferID::SMPTEST2084_NON_HDR;
+ break;
+
default: // Do nothing
break;
}
« no previous file with comments | « ui/gfx/color_space.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698