Add srgb color transfer

PiperOrigin-RevId: 525467798
This commit is contained in:
tofunmi 2023-04-19 17:22:09 +01:00 committed by Rohit Singh
parent 9406410c48
commit aa0d7d7339
3 changed files with 30 additions and 5 deletions

View File

@ -1111,9 +1111,9 @@ public final class C {
// LINT.IfChange(color_transfer) // LINT.IfChange(color_transfer)
/** /**
* Video color transfer characteristics. One of {@link Format#NO_VALUE}, {@link * Video/image color transfer characteristics. One of {@link Format#NO_VALUE}, {@link
* #COLOR_TRANSFER_LINEAR}, {@link #COLOR_TRANSFER_SDR}, {@link #COLOR_TRANSFER_GAMMA_2_2} {@link * #COLOR_TRANSFER_LINEAR}, {@link #COLOR_TRANSFER_SDR}, {@link #COLOR_TRANSFER_SRGB}, {@link
* #COLOR_TRANSFER_ST2084} or {@link #COLOR_TRANSFER_HLG}. * #COLOR_TRANSFER_GAMMA_2_2}, {@link #COLOR_TRANSFER_ST2084} or {@link #COLOR_TRANSFER_HLG}.
*/ */
@UnstableApi @UnstableApi
@Documented @Documented
@ -1123,6 +1123,7 @@ public final class C {
Format.NO_VALUE, Format.NO_VALUE,
COLOR_TRANSFER_LINEAR, COLOR_TRANSFER_LINEAR,
COLOR_TRANSFER_SDR, COLOR_TRANSFER_SDR,
COLOR_TRANSFER_SRGB,
COLOR_TRANSFER_GAMMA_2_2, COLOR_TRANSFER_GAMMA_2_2,
COLOR_TRANSFER_ST2084, COLOR_TRANSFER_ST2084,
COLOR_TRANSFER_HLG COLOR_TRANSFER_HLG
@ -1132,6 +1133,13 @@ public final class C {
@UnstableApi public static final int COLOR_TRANSFER_LINEAR = MediaFormat.COLOR_TRANSFER_LINEAR; @UnstableApi public static final int COLOR_TRANSFER_LINEAR = MediaFormat.COLOR_TRANSFER_LINEAR;
/** See {@link MediaFormat#COLOR_TRANSFER_SDR_VIDEO}. The SMPTE 170M transfer function. */ /** See {@link MediaFormat#COLOR_TRANSFER_SDR_VIDEO}. The SMPTE 170M transfer function. */
@UnstableApi public static final int COLOR_TRANSFER_SDR = MediaFormat.COLOR_TRANSFER_SDR_VIDEO; @UnstableApi public static final int COLOR_TRANSFER_SDR = MediaFormat.COLOR_TRANSFER_SDR_VIDEO;
/**
* See {@link android.hardware.DataSpace#TRANSFER_SRGB}. The standard RGB transfer function, used
* for some SDR use-cases like image input.
*/
// Value sourced from ordering here:
// https://cs.android.com/android/platform/superproject/+/master:frameworks/native/headers/media_plugin/media/hardware/VideoAPI.h;drc=55e9bd7c487ee235631f302ab8626776547ac913;l=138.
@UnstableApi public static final int COLOR_TRANSFER_SRGB = 2;
/** /**
* See {@link android.hardware.DataSpace#TRANSFER_GAMMA2_2}. The Gamma 2.2 transfer function, used * See {@link android.hardware.DataSpace#TRANSFER_GAMMA2_2}. The Gamma 2.2 transfer function, used
* for some SDR use-cases like tone-mapping. * for some SDR use-cases like tone-mapping.

View File

@ -130,6 +130,17 @@ public final class ColorInfo implements Bundleable {
C.COLOR_TRANSFER_SDR, C.COLOR_TRANSFER_SDR,
/* hdrStaticInfo= */ null); /* hdrStaticInfo= */ null);
/**
* Color info representing SDR sRGB in accordance with {@link
* android.hardware.DataSpace#DATASPACE_SRGB}, which is a common SDR image color format.
*/
public static final ColorInfo SRGB_FULL =
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT709)
.setColorRange(C.COLOR_RANGE_FULL)
.setColorTransfer(C.COLOR_TRANSFER_SRGB)
.build();
/** /**
* Returns the {@link C.ColorSpace} corresponding to the given ISO color primary code, as per * Returns the {@link C.ColorSpace} corresponding to the given ISO color primary code, as per
* table A.7.21.1 in Rec. ITU-T T.832 (03/2009), or {@link Format#NO_VALUE} if no mapping can be * table A.7.21.1 in Rec. ITU-T T.832 (03/2009), or {@link Format#NO_VALUE} if no mapping can be
@ -165,6 +176,10 @@ public final class ColorInfo implements Bundleable {
case 6: // SMPTE 170M. case 6: // SMPTE 170M.
case 7: // SMPTE 240M. case 7: // SMPTE 240M.
return C.COLOR_TRANSFER_SDR; return C.COLOR_TRANSFER_SDR;
case 4:
return C.COLOR_TRANSFER_GAMMA_2_2;
case 13:
return C.COLOR_TRANSFER_SRGB;
case 16: case 16:
return C.COLOR_TRANSFER_ST2084; return C.COLOR_TRANSFER_ST2084;
case 18: case 18:
@ -308,6 +323,8 @@ public final class ColorInfo implements Bundleable {
return "Linear"; return "Linear";
case C.COLOR_TRANSFER_SDR: case C.COLOR_TRANSFER_SDR:
return "SDR SMPTE 170M"; return "SDR SMPTE 170M";
case C.COLOR_TRANSFER_SRGB:
return "sRGB";
case C.COLOR_TRANSFER_GAMMA_2_2: case C.COLOR_TRANSFER_GAMMA_2_2:
return "Gamma 2.2"; return "Gamma 2.2";
case C.COLOR_TRANSFER_ST2084: case C.COLOR_TRANSFER_ST2084:

View File

@ -366,8 +366,8 @@ public final class MediaFormatUtil {
/** Whether this is a valid {@link C.ColorTransfer} instance. */ /** Whether this is a valid {@link C.ColorTransfer} instance. */
private static boolean isValidColorTransfer(int colorTransfer) { private static boolean isValidColorTransfer(int colorTransfer) {
// LINT.IfChange(color_transfer) // LINT.IfChange(color_transfer)
// C.COLOR_TRANSFER_GAMMA_2_2 isn't valid because MediaCodec, and hence MediaFormat, does not // C.COLOR_TRANSFER_GAMMA_2_2 & C.COLOR_TRANSFER_SRGB aren't valid because MediaCodec, and
// support it. // hence MediaFormat, do not support them.
return colorTransfer == C.COLOR_TRANSFER_LINEAR return colorTransfer == C.COLOR_TRANSFER_LINEAR
|| colorTransfer == C.COLOR_TRANSFER_SDR || colorTransfer == C.COLOR_TRANSFER_SDR
|| colorTransfer == C.COLOR_TRANSFER_ST2084 || colorTransfer == C.COLOR_TRANSFER_ST2084