Extract function for mapping ColorInfo-related constants

PiperOrigin-RevId: 375705247
This commit is contained in:
aquilescanta 2021-05-25 16:01:53 +01:00 committed by Oliver Woodman
parent 4e5e654eff
commit 2e8d4c9110
2 changed files with 52 additions and 29 deletions

View file

@ -22,10 +22,56 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util;
import java.util.Arrays;
import org.checkerframework.dataflow.qual.Pure;
/** Stores color info. */
public final class ColorInfo implements Parcelable {
/**
* 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
* made.
*/
@Pure
@C.ColorSpace
public static int isoColorPrimariesToColorSpace(int isoColorPrimaries) {
switch (isoColorPrimaries) {
case 1:
return C.COLOR_SPACE_BT709;
case 4: // BT.470M.
case 5: // BT.470BG.
case 6: // SMPTE 170M.
case 7: // SMPTE 240M.
return C.COLOR_SPACE_BT601;
case 9:
return C.COLOR_SPACE_BT2020;
default:
return Format.NO_VALUE;
}
}
/**
* Returns the {@link C.ColorTransfer} corresponding to the given ISO transfer characteristics
* code, as per table A.7.21.2 in Rec. ITU-T T.832 (03/2009), or {@link Format#NO_VALUE} if no
* mapping can be made.
*/
@Pure
@C.ColorTransfer
public static int isoTransferCharacteristicsToColorTransfer(int isoTransferCharacteristics) {
switch (isoTransferCharacteristics) {
case 1: // BT.709.
case 6: // SMPTE 170M.
case 7: // SMPTE 240M.
return C.COLOR_TRANSFER_SDR;
case 16:
return C.COLOR_TRANSFER_ST2084;
case 18:
return C.COLOR_TRANSFER_HLG;
default:
return Format.NO_VALUE;
}
}
/**
* The color space of the video. Valid values are {@link C#COLOR_SPACE_BT601}, {@link
* C#COLOR_SPACE_BT709}, {@link C#COLOR_SPACE_BT2020} or {@link Format#NO_VALUE} if unknown.

View file

@ -931,39 +931,16 @@ public class MatroskaExtractor implements Extractor {
case ID_COLOUR_PRIMARIES:
assertInTrackEntry(id);
currentTrack.hasColorInfo = true;
switch ((int) value) {
case 1:
currentTrack.colorSpace = C.COLOR_SPACE_BT709;
break;
case 4: // BT.470M.
case 5: // BT.470BG.
case 6: // SMPTE 170M.
case 7: // SMPTE 240M.
currentTrack.colorSpace = C.COLOR_SPACE_BT601;
break;
case 9:
currentTrack.colorSpace = C.COLOR_SPACE_BT2020;
break;
default:
break;
int colorSpace = ColorInfo.isoColorPrimariesToColorSpace((int) value);
if (colorSpace != Format.NO_VALUE) {
currentTrack.colorSpace = colorSpace;
}
break;
case ID_COLOUR_TRANSFER:
assertInTrackEntry(id);
switch ((int) value) {
case 1: // BT.709.
case 6: // SMPTE 170M.
case 7: // SMPTE 240M.
currentTrack.colorTransfer = C.COLOR_TRANSFER_SDR;
break;
case 16:
currentTrack.colorTransfer = C.COLOR_TRANSFER_ST2084;
break;
case 18:
currentTrack.colorTransfer = C.COLOR_TRANSFER_HLG;
break;
default:
break;
int colorTransfer = ColorInfo.isoTransferCharacteristicsToColorTransfer((int) value);
if (colorTransfer != Format.NO_VALUE) {
currentTrack.colorTransfer = colorTransfer;
}
break;
case ID_COLOUR_RANGE: