Skip to content

Commit

Permalink
HDR: Add COLOR_TRANSFER_LINEAR in C.java.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dway123 authored and rohitjoins committed Nov 29, 2022
1 parent 7d62943 commit 07d1970
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
25 changes: 14 additions & 11 deletions library/common/src/main/java/com/google/android/exoplayer2/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -1048,24 +1048,27 @@ private 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ private static boolean isValidColorRange(int colorRange) {
/** 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -110,9 +115,9 @@ public static boolean isTransferHdr(@Nullable ColorInfo colorInfo) {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 07d1970

Please sign in to comment.