mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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:
parent
00859a78fd
commit
ac0d803027
@ -17,9 +17,8 @@
|
|||||||
// 1. Samples optical linear BT.2020 RGB from a (non-external) texture with
|
// 1. Samples optical linear BT.2020 RGB from a (non-external) texture with
|
||||||
// uTexSampler.
|
// uTexSampler.
|
||||||
// 2. Applies a 4x4 RGB color matrix to change the pixel colors.
|
// 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,
|
// 3. Outputs electrical (HLG or PQ) BT.2020 RGB based on uOutputColorTransfer,
|
||||||
// based on uOetfColorTransfer.
|
// via an OETF.
|
||||||
// 4. Copies this converted texture color to the current output.
|
|
||||||
// The output will be red if an error has occurred.
|
// The output will be red if an error has occurred.
|
||||||
|
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
@ -28,7 +27,7 @@ in vec2 vTexSamplingCoord;
|
|||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
// C.java#ColorTransfer value.
|
// C.java#ColorTransfer value.
|
||||||
// Only COLOR_TRANSFER_ST2084 and COLOR_TRANSFER_HLG are allowed.
|
// Only COLOR_TRANSFER_ST2084 and COLOR_TRANSFER_HLG are allowed.
|
||||||
uniform int uOetfColorTransfer;
|
uniform int uOutputColorTransfer;
|
||||||
uniform mat3 uColorTransform;
|
uniform mat3 uColorTransform;
|
||||||
uniform mat4 uRgbMatrix;
|
uniform mat4 uRgbMatrix;
|
||||||
|
|
||||||
@ -81,9 +80,9 @@ highp vec3 applyOetf(highp vec3 linearColor) {
|
|||||||
// LINT.IfChange(color_transfer)
|
// LINT.IfChange(color_transfer)
|
||||||
const int COLOR_TRANSFER_ST2084 = 6;
|
const int COLOR_TRANSFER_ST2084 = 6;
|
||||||
const int COLOR_TRANSFER_HLG = 7;
|
const int COLOR_TRANSFER_HLG = 7;
|
||||||
if (uOetfColorTransfer == COLOR_TRANSFER_ST2084) {
|
if (uOutputColorTransfer == COLOR_TRANSFER_ST2084) {
|
||||||
return pqOetf(linearColor);
|
return pqOetf(linearColor);
|
||||||
} else if (uOetfColorTransfer == COLOR_TRANSFER_HLG) {
|
} else if (uOutputColorTransfer == COLOR_TRANSFER_HLG) {
|
||||||
return hlgOetf(linearColor);
|
return hlgOetf(linearColor);
|
||||||
} else {
|
} else {
|
||||||
// Output red as an obviously visible error.
|
// Output red as an obviously visible error.
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_YUV_target.txt,
|
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_YUV_target.txt,
|
||||||
// 2. Applies a YUV to RGB conversion using the specified color transform
|
// 2. Applies a YUV to RGB conversion using the specified color transform
|
||||||
// uYuvToRgbColorTransform, yielding electrical (HLG or PQ) BT.2020 RGB,
|
// 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.
|
// BT.2020 RGB.
|
||||||
// 4. Applies a 4x4 RGB color matrix to change the pixel colors.
|
// 4. Applies a 4x4 RGB color matrix to change the pixel colors.
|
||||||
// 5. Output as requested by uOetfColorTransfer. Use COLOR_TRANSFER_LINEAR for
|
// 5. Outputs as requested by uOutputColorTransfer. Use COLOR_TRANSFER_LINEAR
|
||||||
// outputting to intermediate shaders, or COLOR_TRANSFER_ST2084 /
|
// for outputting to intermediate shaders, or COLOR_TRANSFER_ST2084 /
|
||||||
// COLOR_TRANSFER_HLG to output electrical colors via an OETF (e.g. to an
|
// COLOR_TRANSFER_HLG to output electrical colors via an OETF (e.g. to an
|
||||||
// encoder).
|
// encoder).
|
||||||
// The output will be red if an error has occurred.
|
// The output will be red if an error has occurred.
|
||||||
@ -37,11 +37,11 @@ uniform mat3 uYuvToRgbColorTransform;
|
|||||||
uniform mat4 uRgbMatrix;
|
uniform mat4 uRgbMatrix;
|
||||||
// C.java#ColorTransfer value.
|
// C.java#ColorTransfer value.
|
||||||
// Only COLOR_TRANSFER_ST2084 and COLOR_TRANSFER_HLG are allowed.
|
// Only COLOR_TRANSFER_ST2084 and COLOR_TRANSFER_HLG are allowed.
|
||||||
uniform int uEotfColorTransfer;
|
uniform int uInputColorTransfer;
|
||||||
// C.java#ColorTransfer value.
|
// C.java#ColorTransfer value.
|
||||||
// Only COLOR_TRANSFER_LINEAR, COLOR_TRANSFER_ST2084, and COLOR_TRANSFER_HLG are
|
// Only COLOR_TRANSFER_LINEAR, COLOR_TRANSFER_ST2084, and COLOR_TRANSFER_HLG are
|
||||||
// allowed.
|
// allowed.
|
||||||
uniform int uOetfColorTransfer;
|
uniform int uOutputColorTransfer;
|
||||||
in vec2 vTexSamplingCoord;
|
in vec2 vTexSamplingCoord;
|
||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
|
|
||||||
@ -94,9 +94,9 @@ highp vec3 applyEotf(highp vec3 electricalColor) {
|
|||||||
const int COLOR_TRANSFER_ST2084 = 6;
|
const int COLOR_TRANSFER_ST2084 = 6;
|
||||||
const int COLOR_TRANSFER_HLG = 7;
|
const int COLOR_TRANSFER_HLG = 7;
|
||||||
|
|
||||||
if (uEotfColorTransfer == COLOR_TRANSFER_ST2084) {
|
if (uInputColorTransfer == COLOR_TRANSFER_ST2084) {
|
||||||
return pqEotf(electricalColor);
|
return pqEotf(electricalColor);
|
||||||
} else if (uEotfColorTransfer == COLOR_TRANSFER_HLG) {
|
} else if (uInputColorTransfer == COLOR_TRANSFER_HLG) {
|
||||||
return hlgEotf(electricalColor);
|
return hlgEotf(electricalColor);
|
||||||
} else {
|
} else {
|
||||||
// Output red as an obviously visible error.
|
// 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_LINEAR = 1;
|
||||||
const int COLOR_TRANSFER_ST2084 = 6;
|
const int COLOR_TRANSFER_ST2084 = 6;
|
||||||
const int COLOR_TRANSFER_HLG = 7;
|
const int COLOR_TRANSFER_HLG = 7;
|
||||||
if(uOetfColorTransfer == COLOR_TRANSFER_ST2084) {
|
if (uOutputColorTransfer == COLOR_TRANSFER_ST2084) {
|
||||||
return pqOetf(linearColor);
|
return pqOetf(linearColor);
|
||||||
} else if(uOetfColorTransfer == COLOR_TRANSFER_HLG) {
|
} else if (uOutputColorTransfer == COLOR_TRANSFER_HLG) {
|
||||||
return hlgOetf(linearColor);
|
return hlgOetf(linearColor);
|
||||||
} else if (uOetfColorTransfer == COLOR_TRANSFER_LINEAR) {
|
} else if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
|
||||||
return linearColor;
|
return linearColor;
|
||||||
} else {
|
} else {
|
||||||
// Output red as an obviously visible error.
|
// Output red as an obviously visible error.
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
// 2. Transforms the electrical colors to optical colors using the SMPTE 170M
|
// 2. Transforms the electrical colors to optical colors using the SMPTE 170M
|
||||||
// EOTF.
|
// EOTF.
|
||||||
// 3. Applies a 4x4 RGB color matrix to change the pixel colors.
|
// 3. Applies a 4x4 RGB color matrix to change the pixel colors.
|
||||||
// 4. Output as requested by uOetfColorTransfer. Use COLOR_TRANSFER_LINEAR for
|
// 4. Outputs as requested by uOutputColorTransfer. Use COLOR_TRANSFER_LINEAR
|
||||||
// outputting to intermediate shaders, or COLOR_TRANSFER_SDR_VIDEO to output
|
// for outputting to intermediate shaders, or COLOR_TRANSFER_SDR_VIDEO to
|
||||||
// electrical colors via an OETF (e.g. to an encoder).
|
// output electrical colors via an OETF (e.g. to an encoder).
|
||||||
|
|
||||||
#extension GL_OES_EGL_image_external : require
|
#extension GL_OES_EGL_image_external : require
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
@ -31,7 +31,7 @@ uniform mat4 uRgbMatrix;
|
|||||||
varying vec2 vTexSamplingCoord;
|
varying vec2 vTexSamplingCoord;
|
||||||
// C.java#ColorTransfer value.
|
// C.java#ColorTransfer value.
|
||||||
// Only COLOR_TRANSFER_LINEAR and COLOR_TRANSFER_SDR_VIDEO are allowed.
|
// Only COLOR_TRANSFER_LINEAR and COLOR_TRANSFER_SDR_VIDEO are allowed.
|
||||||
uniform int uOetfColorTransfer;
|
uniform int uOutputColorTransfer;
|
||||||
|
|
||||||
const float inverseGamma = 0.4500;
|
const float inverseGamma = 0.4500;
|
||||||
const float gamma = 1.0 / inverseGamma;
|
const float gamma = 1.0 / inverseGamma;
|
||||||
@ -76,9 +76,9 @@ highp vec3 applyOetf(highp vec3 linearColor) {
|
|||||||
// LINT.IfChange(color_transfer_oetf)
|
// LINT.IfChange(color_transfer_oetf)
|
||||||
const int COLOR_TRANSFER_LINEAR = 1;
|
const int COLOR_TRANSFER_LINEAR = 1;
|
||||||
const int COLOR_TRANSFER_SDR_VIDEO = 3;
|
const int COLOR_TRANSFER_SDR_VIDEO = 3;
|
||||||
if (uOetfColorTransfer == COLOR_TRANSFER_LINEAR) {
|
if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
|
||||||
return linearColor;
|
return linearColor;
|
||||||
} else if(uOetfColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
|
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
|
||||||
return sdrOetf(linearColor);
|
return sdrOetf(linearColor);
|
||||||
} else {
|
} else {
|
||||||
// Output red as an obviously visible error.
|
// Output red as an obviously visible error.
|
||||||
|
@ -226,12 +226,12 @@ import java.util.List;
|
|||||||
checkArgument(
|
checkArgument(
|
||||||
inputColorTransfer == C.COLOR_TRANSFER_HLG
|
inputColorTransfer == C.COLOR_TRANSFER_HLG
|
||||||
|| inputColorTransfer == C.COLOR_TRANSFER_ST2084);
|
|| inputColorTransfer == C.COLOR_TRANSFER_ST2084);
|
||||||
glProgram.setIntUniform("uEotfColorTransfer", inputColorTransfer);
|
glProgram.setIntUniform("uInputColorTransfer", inputColorTransfer);
|
||||||
checkArgument(
|
checkArgument(
|
||||||
outputColorTransfer == C.COLOR_TRANSFER_HLG
|
outputColorTransfer == C.COLOR_TRANSFER_HLG
|
||||||
|| outputColorTransfer == C.COLOR_TRANSFER_ST2084
|
|| outputColorTransfer == C.COLOR_TRANSFER_ST2084
|
||||||
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
|
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
|
||||||
glProgram.setIntUniform("uOetfColorTransfer", outputColorTransfer);
|
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
|
||||||
} else {
|
} else {
|
||||||
checkArgument(
|
checkArgument(
|
||||||
outputColorInfo.colorSpace != C.COLOR_SPACE_BT2020,
|
outputColorInfo.colorSpace != C.COLOR_SPACE_BT2020,
|
||||||
@ -243,7 +243,7 @@ import java.util.List;
|
|||||||
outputColorTransfer == C.COLOR_TRANSFER_SDR
|
outputColorTransfer == C.COLOR_TRANSFER_SDR
|
||||||
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
|
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
|
||||||
// The SDR shader automatically applies an COLOR_TRANSFER_SDR EOTF.
|
// The SDR shader automatically applies an COLOR_TRANSFER_SDR EOTF.
|
||||||
glProgram.setIntUniform("uOetfColorTransfer", outputColorTransfer);
|
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MatrixTextureProcessor(
|
return new MatrixTextureProcessor(
|
||||||
@ -291,7 +291,7 @@ import java.util.List;
|
|||||||
@C.ColorTransfer int colorTransfer = outputColorInfo.colorTransfer;
|
@C.ColorTransfer int colorTransfer = outputColorInfo.colorTransfer;
|
||||||
checkArgument(
|
checkArgument(
|
||||||
colorTransfer == C.COLOR_TRANSFER_HLG || colorTransfer == C.COLOR_TRANSFER_ST2084);
|
colorTransfer == C.COLOR_TRANSFER_HLG || colorTransfer == C.COLOR_TRANSFER_ST2084);
|
||||||
glProgram.setIntUniform("uOetfColorTransfer", colorTransfer);
|
glProgram.setIntUniform("uOutputColorTransfer", colorTransfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MatrixTextureProcessor(
|
return new MatrixTextureProcessor(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user