mirror of
https://github.com/samsonjs/media.git
synced 2026-04-13 12:35:48 +00:00
HDR: Add COLOR_TRANSFER_LINEAR in C.java.
This is more clear than using Format.NO_VALUE, when we do actually intend for an output value. Also, fix @see formatting by using summary fragments instead, and add an error output for OETF and EOTF transfer functions. PiperOrigin-RevId: 490910229
This commit is contained in:
parent
7d62943bcd
commit
07d1970f35
5 changed files with 43 additions and 21 deletions
|
|
@ -1048,24 +1048,27 @@ public final class C {
|
|||
// LINT.IfChange(color_transfer)
|
||||
/**
|
||||
* Video color transfer characteristics. One of {@link Format#NO_VALUE}, {@link
|
||||
* #COLOR_TRANSFER_SDR}, {@link #COLOR_TRANSFER_ST2084} or {@link #COLOR_TRANSFER_HLG}.
|
||||
* #COLOR_TRANSFER_LINEAR}, {@link #COLOR_TRANSFER_SDR}, {@link #COLOR_TRANSFER_ST2084} or {@link
|
||||
* #COLOR_TRANSFER_HLG}.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({Format.NO_VALUE, COLOR_TRANSFER_SDR, COLOR_TRANSFER_ST2084, COLOR_TRANSFER_HLG})
|
||||
@IntDef({
|
||||
Format.NO_VALUE,
|
||||
COLOR_TRANSFER_LINEAR,
|
||||
COLOR_TRANSFER_SDR,
|
||||
COLOR_TRANSFER_ST2084,
|
||||
COLOR_TRANSFER_HLG
|
||||
})
|
||||
public @interface ColorTransfer {}
|
||||
/**
|
||||
* @see MediaFormat#COLOR_TRANSFER_SDR_VIDEO
|
||||
*/
|
||||
/** See {@link MediaFormat#COLOR_TRANSFER_LINEAR}. */
|
||||
public static final int COLOR_TRANSFER_LINEAR = MediaFormat.COLOR_TRANSFER_LINEAR;
|
||||
/** See {@link MediaFormat#COLOR_TRANSFER_SDR_VIDEO}. */
|
||||
public static final int COLOR_TRANSFER_SDR = MediaFormat.COLOR_TRANSFER_SDR_VIDEO;
|
||||
/**
|
||||
* @see MediaFormat#COLOR_TRANSFER_ST2084
|
||||
*/
|
||||
/** See {@link MediaFormat#COLOR_TRANSFER_ST2084}. */
|
||||
public static final int COLOR_TRANSFER_ST2084 = MediaFormat.COLOR_TRANSFER_ST2084;
|
||||
/**
|
||||
* @see MediaFormat#COLOR_TRANSFER_HLG
|
||||
*/
|
||||
/** See {@link MediaFormat#COLOR_TRANSFER_HLG}. */
|
||||
public static final int COLOR_TRANSFER_HLG = MediaFormat.COLOR_TRANSFER_HLG;
|
||||
|
||||
// LINT.IfChange(color_range)
|
||||
|
|
|
|||
|
|
@ -321,7 +321,8 @@ public final class MediaFormatUtil {
|
|||
/** Whether this is a valid {@link C.ColorTransfer} instance. */
|
||||
private static boolean isValidColorTransfer(int colorTransfer) {
|
||||
// LINT.IfChange(color_transfer)
|
||||
return colorTransfer == C.COLOR_TRANSFER_SDR
|
||||
return colorTransfer == C.COLOR_TRANSFER_LINEAR
|
||||
|| colorTransfer == C.COLOR_TRANSFER_SDR
|
||||
|| colorTransfer == C.COLOR_TRANSFER_ST2084
|
||||
|| colorTransfer == C.COLOR_TRANSFER_HLG
|
||||
|| colorTransfer == Format.NO_VALUE;
|
||||
|
|
|
|||
|
|
@ -90,11 +90,16 @@ public final class ColorInfo implements Bundleable {
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns whether the {@code ColorInfo} uses an HDR {@link C.ColorTransfer}. */
|
||||
/**
|
||||
* Returns whether the {@code ColorInfo} uses an HDR {@link C.ColorTransfer}.
|
||||
*
|
||||
* <p>{@link C#COLOR_TRANSFER_LINEAR} is not considered to be an HDR {@link C.ColorTransfer},
|
||||
* because it may represent either SDR or HDR contents.
|
||||
*/
|
||||
public static boolean isTransferHdr(@Nullable ColorInfo colorInfo) {
|
||||
return colorInfo != null
|
||||
&& colorInfo.colorTransfer != Format.NO_VALUE
|
||||
&& colorInfo.colorTransfer != C.COLOR_TRANSFER_SDR;
|
||||
&& (colorInfo.colorTransfer == C.COLOR_TRANSFER_HLG
|
||||
|| colorInfo.colorTransfer == C.COLOR_TRANSFER_ST2084);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,9 +115,9 @@ public final class ColorInfo implements Bundleable {
|
|||
public final @C.ColorRange int colorRange;
|
||||
|
||||
/**
|
||||
* The color transfer characteristics of the video. Valid values are {@link C#COLOR_TRANSFER_HLG},
|
||||
* {@link C#COLOR_TRANSFER_ST2084}, {@link C#COLOR_TRANSFER_SDR} or {@link Format#NO_VALUE} if
|
||||
* unknown.
|
||||
* The color transfer characteristics of the video. Valid values are {@link
|
||||
* C#COLOR_TRANSFER_LINEAR}, {@link C#COLOR_TRANSFER_HLG}, {@link C#COLOR_TRANSFER_ST2084}, {@link
|
||||
* C#COLOR_TRANSFER_SDR} or {@link Format#NO_VALUE} if unknown.
|
||||
*/
|
||||
public final @C.ColorTransfer int colorTransfer;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,12 +79,20 @@ highp vec3 pqOetf(highp vec3 linearColor) {
|
|||
highp vec3 getElectricalColor(highp vec3 linearColor) {
|
||||
// LINT.IfChange(color_transfer)
|
||||
const int COLOR_TRANSFER_ST2084 = 6;
|
||||
return (uOetfColorTransfer == COLOR_TRANSFER_ST2084) ?
|
||||
pqOetf(linearColor) : hlgOetf(linearColor);
|
||||
const int COLOR_TRANSFER_HLG = 7;
|
||||
if (uOetfColorTransfer == COLOR_TRANSFER_ST2084) {
|
||||
return pqOetf(linearColor);
|
||||
} else if (uOetfColorTransfer == COLOR_TRANSFER_HLG) {
|
||||
return hlgOetf(linearColor);
|
||||
} else {
|
||||
// Output red as an obviously visible error.
|
||||
return vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 inputColor = texture(uTexSampler, vTexSamplingCoord);
|
||||
// transformedColors is an optical color.
|
||||
vec4 transformedColors = uRgbMatrix * vec4(inputColor.rgb, 1);
|
||||
outColor = vec4(getElectricalColor(transformedColors.rgb), inputColor.a);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,12 +86,17 @@ highp vec3 getOpticalColor(highp vec3 electricalColor) {
|
|||
const int COLOR_TRANSFER_ST2084 = 6;
|
||||
const int COLOR_TRANSFER_HLG = 7;
|
||||
|
||||
const int FORMAT_NO_VALUE = -1;
|
||||
|
||||
if (uEotfColorTransfer == COLOR_TRANSFER_ST2084) {
|
||||
return pqEotf(electricalColor);
|
||||
} else if (uEotfColorTransfer == COLOR_TRANSFER_HLG) {
|
||||
return hlgEotf(electricalColor);
|
||||
} else {
|
||||
} else if (uEotfColorTransfer == FORMAT_NO_VALUE) {
|
||||
return electricalColor;
|
||||
} else {
|
||||
// Output red as an obviously visible error.
|
||||
return vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue