HDR: Update to use input/output color instead of OETF/EOTF.

These terms are easier to understand, and make sense in the context of
MatrixTextureProcessor now that a MatrixTextureProcessor may have a
different input and output transfer.

PiperOrigin-RevId: 493265980
This commit is contained in:
huangdarwin 2022-12-06 12:18:42 +00:00 committed by Ian Baker
parent 00859a78fd
commit ac0d803027
4 changed files with 25 additions and 26 deletions

View File

@ -17,9 +17,8 @@
// 1. Samples optical linear BT.2020 RGB from a (non-external) texture with
// uTexSampler.
// 2. Applies a 4x4 RGB color matrix to change the pixel colors.
// 3. Applies the HLG or PQ OETF to yield electrical (HLG or PQ) BT.2020 RGB,
// based on uOetfColorTransfer.
// 4. Copies this converted texture color to the current output.
// 3. Outputs electrical (HLG or PQ) BT.2020 RGB based on uOutputColorTransfer,
// via an OETF.
// The output will be red if an error has occurred.
precision mediump float;
@ -28,7 +27,7 @@ in vec2 vTexSamplingCoord;
out vec4 outColor;
// C.java#ColorTransfer value.
// Only COLOR_TRANSFER_ST2084 and COLOR_TRANSFER_HLG are allowed.
uniform int uOetfColorTransfer;
uniform int uOutputColorTransfer;
uniform mat3 uColorTransform;
uniform mat4 uRgbMatrix;
@ -81,9 +80,9 @@ highp vec3 applyOetf(highp vec3 linearColor) {
// LINT.IfChange(color_transfer)
const int COLOR_TRANSFER_ST2084 = 6;
const int COLOR_TRANSFER_HLG = 7;
if (uOetfColorTransfer == COLOR_TRANSFER_ST2084) {
if (uOutputColorTransfer == COLOR_TRANSFER_ST2084) {
return pqOetf(linearColor);
} else if (uOetfColorTransfer == COLOR_TRANSFER_HLG) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_HLG) {
return hlgOetf(linearColor);
} else {
// Output red as an obviously visible error.

View File

@ -20,11 +20,11 @@
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_YUV_target.txt,
// 2. Applies a YUV to RGB conversion using the specified color transform
// uYuvToRgbColorTransform, yielding electrical (HLG or PQ) BT.2020 RGB,
// 3. Applies an EOTF based on uEotfColorTransfer, yielding optical linear
// 3. Applies an EOTF based on uInputColorTransfer, yielding optical linear
// BT.2020 RGB.
// 4. Applies a 4x4 RGB color matrix to change the pixel colors.
// 5. Output as requested by uOetfColorTransfer. Use COLOR_TRANSFER_LINEAR for
// outputting to intermediate shaders, or COLOR_TRANSFER_ST2084 /
// 5. Outputs as requested by uOutputColorTransfer. Use COLOR_TRANSFER_LINEAR
// for outputting to intermediate shaders, or COLOR_TRANSFER_ST2084 /
// COLOR_TRANSFER_HLG to output electrical colors via an OETF (e.g. to an
// encoder).
// The output will be red if an error has occurred.
@ -37,11 +37,11 @@ uniform mat3 uYuvToRgbColorTransform;
uniform mat4 uRgbMatrix;
// C.java#ColorTransfer value.
// Only COLOR_TRANSFER_ST2084 and COLOR_TRANSFER_HLG are allowed.
uniform int uEotfColorTransfer;
uniform int uInputColorTransfer;
// C.java#ColorTransfer value.
// Only COLOR_TRANSFER_LINEAR, COLOR_TRANSFER_ST2084, and COLOR_TRANSFER_HLG are
// allowed.
uniform int uOetfColorTransfer;
uniform int uOutputColorTransfer;
in vec2 vTexSamplingCoord;
out vec4 outColor;
@ -94,9 +94,9 @@ highp vec3 applyEotf(highp vec3 electricalColor) {
const int COLOR_TRANSFER_ST2084 = 6;
const int COLOR_TRANSFER_HLG = 7;
if (uEotfColorTransfer == COLOR_TRANSFER_ST2084) {
if (uInputColorTransfer == COLOR_TRANSFER_ST2084) {
return pqEotf(electricalColor);
} else if (uEotfColorTransfer == COLOR_TRANSFER_HLG) {
} else if (uInputColorTransfer == COLOR_TRANSFER_HLG) {
return hlgEotf(electricalColor);
} else {
// Output red as an obviously visible error.
@ -151,11 +151,11 @@ highp vec3 applyOetf(highp vec3 linearColor) {
const int COLOR_TRANSFER_LINEAR = 1;
const int COLOR_TRANSFER_ST2084 = 6;
const int COLOR_TRANSFER_HLG = 7;
if(uOetfColorTransfer == COLOR_TRANSFER_ST2084) {
if (uOutputColorTransfer == COLOR_TRANSFER_ST2084) {
return pqOetf(linearColor);
} else if(uOetfColorTransfer == COLOR_TRANSFER_HLG) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_HLG) {
return hlgOetf(linearColor);
} else if (uOetfColorTransfer == COLOR_TRANSFER_LINEAR) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
return linearColor;
} else {
// Output red as an obviously visible error.

View File

@ -20,9 +20,9 @@
// 2. Transforms the electrical colors to optical colors using the SMPTE 170M
// EOTF.
// 3. Applies a 4x4 RGB color matrix to change the pixel colors.
// 4. Output as requested by uOetfColorTransfer. Use COLOR_TRANSFER_LINEAR for
// outputting to intermediate shaders, or COLOR_TRANSFER_SDR_VIDEO to output
// electrical colors via an OETF (e.g. to an encoder).
// 4. Outputs as requested by uOutputColorTransfer. Use COLOR_TRANSFER_LINEAR
// for outputting to intermediate shaders, or COLOR_TRANSFER_SDR_VIDEO to
// output electrical colors via an OETF (e.g. to an encoder).
#extension GL_OES_EGL_image_external : require
precision mediump float;
@ -31,7 +31,7 @@ uniform mat4 uRgbMatrix;
varying vec2 vTexSamplingCoord;
// C.java#ColorTransfer value.
// Only COLOR_TRANSFER_LINEAR and COLOR_TRANSFER_SDR_VIDEO are allowed.
uniform int uOetfColorTransfer;
uniform int uOutputColorTransfer;
const float inverseGamma = 0.4500;
const float gamma = 1.0 / inverseGamma;
@ -76,9 +76,9 @@ highp vec3 applyOetf(highp vec3 linearColor) {
// LINT.IfChange(color_transfer_oetf)
const int COLOR_TRANSFER_LINEAR = 1;
const int COLOR_TRANSFER_SDR_VIDEO = 3;
if (uOetfColorTransfer == COLOR_TRANSFER_LINEAR) {
if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
return linearColor;
} else if(uOetfColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return sdrOetf(linearColor);
} else {
// Output red as an obviously visible error.

View File

@ -226,12 +226,12 @@ import java.util.List;
checkArgument(
inputColorTransfer == C.COLOR_TRANSFER_HLG
|| inputColorTransfer == C.COLOR_TRANSFER_ST2084);
glProgram.setIntUniform("uEotfColorTransfer", inputColorTransfer);
glProgram.setIntUniform("uInputColorTransfer", inputColorTransfer);
checkArgument(
outputColorTransfer == C.COLOR_TRANSFER_HLG
|| outputColorTransfer == C.COLOR_TRANSFER_ST2084
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
glProgram.setIntUniform("uOetfColorTransfer", outputColorTransfer);
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
} else {
checkArgument(
outputColorInfo.colorSpace != C.COLOR_SPACE_BT2020,
@ -243,7 +243,7 @@ import java.util.List;
outputColorTransfer == C.COLOR_TRANSFER_SDR
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
// The SDR shader automatically applies an COLOR_TRANSFER_SDR EOTF.
glProgram.setIntUniform("uOetfColorTransfer", outputColorTransfer);
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
}
return new MatrixTextureProcessor(
@ -291,7 +291,7 @@ import java.util.List;
@C.ColorTransfer int colorTransfer = outputColorInfo.colorTransfer;
checkArgument(
colorTransfer == C.COLOR_TRANSFER_HLG || colorTransfer == C.COLOR_TRANSFER_ST2084);
glProgram.setIntUniform("uOetfColorTransfer", colorTransfer);
glProgram.setIntUniform("uOutputColorTransfer", colorTransfer);
}
return new MatrixTextureProcessor(