HDR: Rename ColorInfo#isHdr to isTransferHdr.

While HDR is most closely tied to the color transfer (ex.
COLOR_TRANSFER_SDR is the only one explicitly mentioning dynamic
range), technically color spaces may be associated with HDR as well,
like BT.2020 commonly being used for HDR rather than BT.709 for SDR.

Therefore, it's more specific to mention just that the transfer is HDR.

PiperOrigin-RevId: 466316960
This commit is contained in:
huangdarwin 2022-08-09 11:28:31 +00:00 committed by Marc Baechinger
parent 7dc05edbab
commit 35161c7489
7 changed files with 18 additions and 17 deletions

View File

@ -90,7 +90,7 @@ 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}. */
public static boolean isHdr(@Nullable ColorInfo colorInfo) { public static boolean isTransferHdr(@Nullable ColorInfo colorInfo) {
return colorInfo != null return colorInfo != null
&& colorInfo.colorTransfer != Format.NO_VALUE && colorInfo.colorTransfer != Format.NO_VALUE
&& colorInfo.colorTransfer != C.COLOR_TRANSFER_SDR; && colorInfo.colorTransfer != C.COLOR_TRANSFER_SDR;

View File

@ -218,7 +218,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
SurfaceInfo outputSurfaceInfo = this.outputSurfaceInfo; SurfaceInfo outputSurfaceInfo = this.outputSurfaceInfo;
@Nullable EGLSurface outputEglSurface = this.outputEglSurface; @Nullable EGLSurface outputEglSurface = this.outputEglSurface;
if (outputEglSurface == null) { if (outputEglSurface == null) {
boolean colorInfoIsHdr = ColorInfo.isHdr(colorInfo); boolean colorInfoIsHdr = ColorInfo.isTransferHdr(colorInfo);
if (colorInfoIsHdr) { if (colorInfoIsHdr) {
outputEglSurface = GlUtil.getEglSurfaceRgba1010102(eglDisplay, outputSurfaceInfo.surface); outputEglSurface = GlUtil.getEglSurfaceRgba1010102(eglDisplay, outputSurfaceInfo.surface);
} else { } else {

View File

@ -119,7 +119,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
// TODO(b/237674316): Delay initialization of things requiring the colorInfo, to // TODO(b/237674316): Delay initialization of things requiring the colorInfo, to
// configure based on the color info from the decoder output media format instead. // configure based on the color info from the decoder output media format instead.
boolean useHdr = ColorInfo.isHdr(colorInfo); boolean useHdr = ColorInfo.isTransferHdr(colorInfo);
EGLDisplay eglDisplay = GlUtil.createEglDisplay(); EGLDisplay eglDisplay = GlUtil.createEglDisplay();
EGLContext eglContext = EGLContext eglContext =
useHdr useHdr
@ -197,7 +197,7 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
sampleFromExternalTexture = false; sampleFromExternalTexture = false;
} }
textureProcessorListBuilder.add( textureProcessorListBuilder.add(
glEffect.toGlTextureProcessor(context, ColorInfo.isHdr(colorInfo))); glEffect.toGlTextureProcessor(context, ColorInfo.isTransferHdr(colorInfo)));
} }
textureProcessorListBuilder.add( textureProcessorListBuilder.add(
new FinalMatrixTransformationProcessorWrapper( new FinalMatrixTransformationProcessorWrapper(

View File

@ -160,12 +160,12 @@ import java.util.Arrays;
* the external texture. * the external texture.
* @param opticalColorInfo The optical {@link ColorInfo}, only used to transform between color * @param opticalColorInfo The optical {@link ColorInfo}, only used to transform between color
* spaces and transfers, when {@code inputOpticalColorsFromExternalTexture} or {@code * spaces and transfers, when {@code inputOpticalColorsFromExternalTexture} or {@code
* outputOpticalColors} are {@code true}. If it {@link ColorInfo#isHdr(ColorInfo)}, * outputOpticalColors} are {@code true}. If it {@link ColorInfo#isTransferHdr(ColorInfo)},
* intermediate {@link GlTextureProcessor} colors will be in linear RGB BT.2020. Otherwise, * intermediate {@link GlTextureProcessor} colors will be in linear RGB BT.2020. Otherwise,
* these colors will be in gamma RGB BT.709. * these colors will be in gamma RGB BT.709.
* @param outputOpticalColors If {@code true}, outputs {@code opticalColorInfo}. If {@code false}, * @param outputOpticalColors If {@code true}, outputs {@code opticalColorInfo}. If {@code false},
* outputs intermediate colors of linear RGB BT.2020 if {@code opticalColorInfo} {@link * outputs intermediate colors of linear RGB BT.2020 if {@code opticalColorInfo} {@link
* ColorInfo#isHdr(ColorInfo)}, and gamma RGB BT.709 otherwise. * ColorInfo#isTransferHdr(ColorInfo)}, and gamma RGB BT.709 otherwise.
* @throws FrameProcessingException If a problem occurs while reading shader files or an OpenGL * @throws FrameProcessingException If a problem occurs while reading shader files or an OpenGL
* operation fails or is unsupported. * operation fails or is unsupported.
*/ */
@ -180,11 +180,11 @@ import java.util.Arrays;
createGlProgram( createGlProgram(
context, context,
inputOpticalColorsFromExternalTexture, inputOpticalColorsFromExternalTexture,
ColorInfo.isHdr(opticalColorInfo), ColorInfo.isTransferHdr(opticalColorInfo),
outputOpticalColors), outputOpticalColors),
matrixTransformations, matrixTransformations,
ColorInfo.isHdr(opticalColorInfo)); ColorInfo.isTransferHdr(opticalColorInfo));
if (!ColorInfo.isHdr(opticalColorInfo) || !inputOpticalColorsFromExternalTexture) { if (!ColorInfo.isTransferHdr(opticalColorInfo) || !inputOpticalColorsFromExternalTexture) {
return; return;
} }
// TODO(b/227624622): Implement YUV to RGB conversions in COLOR_RANGE_LIMITED as well, using // TODO(b/227624622): Implement YUV to RGB conversions in COLOR_RANGE_LIMITED as well, using

View File

@ -283,7 +283,7 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
} }
MediaFormatUtil.maybeSetColorInfo(mediaFormat, encoderSupportedFormat.colorInfo); MediaFormatUtil.maybeSetColorInfo(mediaFormat, encoderSupportedFormat.colorInfo);
if (Util.SDK_INT >= 31 && ColorInfo.isHdr(format.colorInfo)) { if (Util.SDK_INT >= 31 && ColorInfo.isTransferHdr(format.colorInfo)) {
if (EncoderUtil.getSupportedColorFormats(encoderInfo, mimeType) if (EncoderUtil.getSupportedColorFormats(encoderInfo, mimeType)
.contains(MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010)) { .contains(MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010)) {
mediaFormat.setInteger( mediaFormat.setInteger(

View File

@ -99,7 +99,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return false; return false;
} }
Format inputFormat = checkNotNull(formatHolder.format); Format inputFormat = checkNotNull(formatHolder.format);
if (SDK_INT < 31 && ColorInfo.isHdr(inputFormat.colorInfo)) { if (SDK_INT < 31 && ColorInfo.isTransferHdr(inputFormat.colorInfo)) {
throw TransformationException.createForCodec( throw TransformationException.createForCodec(
new IllegalArgumentException("HDR editing not supported under API 31."), new IllegalArgumentException("HDR editing not supported under API 31."),
/* isVideo= */ true, /* isVideo= */ true,

View File

@ -156,8 +156,8 @@ import org.checkerframework.dataflow.qual.Pure;
decodedWidth, decodedHeight, inputFormat.pixelWidthHeightRatio, streamOffsetUs)); decodedWidth, decodedHeight, inputFormat.pixelWidthHeightRatio, streamOffsetUs));
boolean isToneMappingRequired = boolean isToneMappingRequired =
ColorInfo.isHdr(inputFormat.colorInfo) ColorInfo.isTransferHdr(inputFormat.colorInfo)
&& !ColorInfo.isHdr(encoderWrapper.getSupportedInputColor()); && !ColorInfo.isTransferHdr(encoderWrapper.getSupportedInputColor());
decoder = decoder =
decoderFactory.createForVideoDecoding( decoderFactory.createForVideoDecoding(
inputFormat, frameProcessor.getInputSurface(), isToneMappingRequired); inputFormat, frameProcessor.getInputSurface(), isToneMappingRequired);
@ -363,7 +363,8 @@ import org.checkerframework.dataflow.qual.Pure;
transformationRequest.enableHdrEditing transformationRequest.enableHdrEditing
&& !transformationRequest.enableRequestSdrToneMapping && !transformationRequest.enableRequestSdrToneMapping
&& !supportedEncoderNamesForHdrEditing.isEmpty(); && !supportedEncoderNamesForHdrEditing.isEmpty();
boolean isInputToneMapped = !isHdrEditingEnabled && ColorInfo.isHdr(inputFormat.colorInfo); boolean isInputToneMapped =
!isHdrEditingEnabled && ColorInfo.isTransferHdr(inputFormat.colorInfo);
if (isInputToneMapped) { if (isInputToneMapped) {
// When tone-mapping HDR to SDR is enabled, assume we get BT.709 to avoid having the encoder // When tone-mapping HDR to SDR is enabled, assume we get BT.709 to avoid having the encoder
// populate default color info, which depends on the resolution. // populate default color info, which depends on the resolution.
@ -413,7 +414,7 @@ import org.checkerframework.dataflow.qual.Pure;
encoderFactory.createForVideoEncoding(requestedEncoderFormat, allowedOutputMimeTypes); encoderFactory.createForVideoEncoding(requestedEncoderFormat, allowedOutputMimeTypes);
Format encoderSupportedFormat = encoder.getConfigurationFormat(); Format encoderSupportedFormat = encoder.getConfigurationFormat();
if (ColorInfo.isHdr(requestedEncoderFormat.colorInfo)) { if (ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo)) {
if (!requestedOutputMimeType.equals(encoderSupportedFormat.sampleMimeType)) { if (!requestedOutputMimeType.equals(encoderSupportedFormat.sampleMimeType)) {
throw createEncodingException( throw createEncodingException(
new IllegalStateException("MIME type fallback unsupported with HDR editing"), new IllegalStateException("MIME type fallback unsupported with HDR editing"),
@ -425,8 +426,8 @@ import org.checkerframework.dataflow.qual.Pure;
} }
} }
boolean isInputToneMapped = boolean isInputToneMapped =
ColorInfo.isHdr(inputFormat.colorInfo) ColorInfo.isTransferHdr(inputFormat.colorInfo)
&& !ColorInfo.isHdr(requestedEncoderFormat.colorInfo); && !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
fallbackListener.onTransformationRequestFinalized( fallbackListener.onTransformationRequestFinalized(
createFallbackTransformationRequest( createFallbackTransformationRequest(
transformationRequest, transformationRequest,