Starting to hack up HDR transfer function support
Brings over skcms' encoding scheme, etc.
Change-Id: Ib8abec911acd1c50df3b201b4a9bde01b1cb123b
Bug: chromium:960620
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249000
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index a87d591..7675744 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -112,11 +112,13 @@
// function, one for the (inverse) destination transfer function, and one for the gamut xform.
// Any combination of these may be present, although some configurations are much more likely.
- auto emitTFFunc = [=](const char* name, GrGLSLProgramDataManager::UniformHandle uniform) {
+ auto emitTFFunc = [=](const char* name, GrGLSLProgramDataManager::UniformHandle uniform,
+ TFKind kind) {
const GrShaderVar gTFArgs[] = { GrShaderVar("x", kHalf_GrSLType) };
const char* coeffs = uniformHandler->getUniformCStr(uniform);
SkString body;
- // Temporaries to make evaluation line readable
+ // Temporaries to make evaluation line readable. We always use the sRGBish names, so the
+ // PQ and HLG math is confusing.
body.appendf("half G = %s[0];", coeffs);
body.appendf("half A = %s[1];", coeffs);
body.appendf("half B = %s[2];", coeffs);
@@ -126,7 +128,24 @@
body.appendf("half F = %s[6];", coeffs);
body.append("half s = sign(x);");
body.append("x = abs(x);");
- body.appendf("return s * ((x < D) ? (C * x) + F : pow(A * x + B, G) + E);");
+ switch (kind) {
+ case TFKind::sRGBish_TF:
+ body.append("x = (x < D) ? (C * x) + F : pow(A * x + B, G) + E;");
+ break;
+ case TFKind::PQish_TF:
+ body.append("x = pow(max(A + B * pow(x, C), 0) / (D + E * pow(x, C)), F);");
+ break;
+ case TFKind::HLGish_TF:
+ body.append("x = (x*A <= 1) ? pow(x*A, B) : exp((x-E)*C) + D;");
+ break;
+ case TFKind::HLGinvish_TF:
+ body.append("x = (x <= 1) ? A * pow(x, B) : C * log(x - D) + E;");
+ break;
+ default:
+ SkASSERT(false);
+ break;
+ }
+ body.append("return s * x;");
SkString funcName;
this->emitFunction(kHalf_GrSLType, name, SK_ARRAY_COUNT(gTFArgs), gTFArgs, body.c_str(),
&funcName);
@@ -135,12 +154,14 @@
SkString srcTFFuncName;
if (colorXformHelper->applySrcTF()) {
- srcTFFuncName = emitTFFunc("src_tf", colorXformHelper->srcTFUniform());
+ srcTFFuncName = emitTFFunc("src_tf", colorXformHelper->srcTFUniform(),
+ colorXformHelper->srcTFKind());
}
SkString dstTFFuncName;
if (colorXformHelper->applyDstTF()) {
- dstTFFuncName = emitTFFunc("dst_tf", colorXformHelper->dstTFUniform());
+ dstTFFuncName = emitTFFunc("dst_tf", colorXformHelper->dstTFUniform(),
+ colorXformHelper->dstTFKind());
}
SkString gamutXformFuncName;