Commit 4c8d22fe by huangdarwin Committed by microkatz

HDR: Use factory for MatrixTransformationProcessor.

Separate MatrixTransformationProcessor constructors by color input and output.

PiperOrigin-RevId: 471034768
(cherry picked from commit a8e814ab)
parent fc8edfcd
......@@ -28,6 +28,7 @@ import android.opengl.EGLSurface;
import androidx.media3.common.FrameProcessingException;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.junit.After;
......@@ -94,11 +95,10 @@ public final class MatrixTransformationProcessorPixelTest {
public void drawFrame_noEdits_producesExpectedOutput() throws Exception {
String testId = "drawFrame_noEdits";
Matrix identityMatrix = new Matrix();
MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix;
matrixTransformationFrameProcessor =
new MatrixTransformationProcessor(
context,
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> identityMatrix);
MatrixTransformationProcessor.create(
context, ImmutableList.of(noEditsTransformation), /* useHdr= */ false);
matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
......@@ -120,11 +120,11 @@ public final class MatrixTransformationProcessorPixelTest {
String testId = "drawFrame_translateRight";
Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
MatrixTransformation translateRightTransformation =
(long presentationTimeUs) -> translateRightMatrix;
matrixTransformationFrameProcessor =
new MatrixTransformationProcessor(
context,
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> translateRightMatrix);
MatrixTransformationProcessor.create(
context, ImmutableList.of(translateRightTransformation), /* useHdr= */ false);
matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH);
......@@ -146,11 +146,10 @@ public final class MatrixTransformationProcessorPixelTest {
String testId = "drawFrame_scaleNarrow";
Matrix scaleNarrowMatrix = new Matrix();
scaleNarrowMatrix.postScale(.5f, 1.2f);
MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix;
matrixTransformationFrameProcessor =
new MatrixTransformationProcessor(
context,
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> scaleNarrowMatrix);
MatrixTransformationProcessor.create(
context, ImmutableList.of(scaleNarrowTransformation), /* useHdr= */ false);
matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(SCALE_NARROW_PNG_ASSET_PATH);
......@@ -172,11 +171,10 @@ public final class MatrixTransformationProcessorPixelTest {
String testId = "drawFrame_rotate90";
Matrix rotate90Matrix = new Matrix();
rotate90Matrix.postRotate(/* degrees= */ 90);
MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix;
matrixTransformationFrameProcessor =
new MatrixTransformationProcessor(
context,
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> rotate90Matrix);
MatrixTransformationProcessor.create(
context, ImmutableList.of(rotate90Transformation), /* useHdr= */ false);
matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ROTATE_90_PNG_ASSET_PATH);
......
......@@ -368,13 +368,19 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Presentation.createForWidthAndHeight(
outputSurfaceInfo.width, outputSurfaceInfo.height, Presentation.LAYOUT_SCALE_TO_FIT));
MatrixTransformationProcessor matrixTransformationProcessor =
new MatrixTransformationProcessor(
context,
matrixTransformationListBuilder.build(),
sampleFromExternalTexture,
colorInfo,
/* outputElectricalColors= */ true);
MatrixTransformationProcessor matrixTransformationProcessor;
ImmutableList<GlMatrixTransformation> expandedMatrixTransformations =
matrixTransformationListBuilder.build();
if (sampleFromExternalTexture) {
matrixTransformationProcessor =
MatrixTransformationProcessor.createWithExternalSamplerApplyingEotfThenOetf(
context, expandedMatrixTransformations, colorInfo);
} else {
matrixTransformationProcessor =
MatrixTransformationProcessor.createApplyingOetf(
context, expandedMatrixTransformations, colorInfo);
}
matrixTransformationProcessor.setTextureTransformMatrix(textureTransformMatrix);
Pair<Integer, Integer> outputSize =
matrixTransformationProcessor.configure(inputWidth, inputHeight);
......
......@@ -204,13 +204,17 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
ImmutableList<GlMatrixTransformation> matrixTransformations =
matrixTransformationListBuilder.build();
if (!matrixTransformations.isEmpty() || sampleFromExternalTexture) {
textureProcessorListBuilder.add(
new MatrixTransformationProcessor(
context,
matrixTransformations,
sampleFromExternalTexture,
colorInfo,
/* outputElectricalColors= */ false));
MatrixTransformationProcessor matrixTransformationProcessor;
if (sampleFromExternalTexture) {
matrixTransformationProcessor =
MatrixTransformationProcessor.createWithExternalSamplerApplyingEotf(
context, matrixTransformations, colorInfo);
} else {
matrixTransformationProcessor =
MatrixTransformationProcessor.create(
context, matrixTransformations, ColorInfo.isTransferHdr(colorInfo));
}
textureProcessorListBuilder.add(matrixTransformationProcessor);
matrixTransformationListBuilder = new ImmutableList.Builder<>();
sampleFromExternalTexture = false;
}
......@@ -235,12 +239,8 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
// TODO(b/239757183): Remove the unnecessary MatrixTransformationProcessor after it got
// merged with RgbMatrixProcessor.
textureProcessorListBuilder.add(
new MatrixTransformationProcessor(
context,
ImmutableList.of(),
sampleFromExternalTexture,
colorInfo,
/* outputElectricalColors= */ false));
MatrixTransformationProcessor.createWithExternalSamplerApplyingEotf(
context, /* matrixTransformations= */ ImmutableList.of(), colorInfo));
sampleFromExternalTexture = false;
}
textureProcessorListBuilder.add(
......
......@@ -19,6 +19,7 @@ import android.content.Context;
import android.opengl.Matrix;
import android.util.Pair;
import androidx.media3.common.FrameProcessingException;
import com.google.common.collect.ImmutableList;
/**
* Specifies a 4x4 transformation {@link Matrix} to apply in the vertex shader for each frame.
......@@ -52,6 +53,7 @@ public interface GlMatrixTransformation extends GlEffect {
@Override
default SingleFrameGlTextureProcessor toGlTextureProcessor(Context context, boolean useHdr)
throws FrameProcessingException {
return new MatrixTransformationProcessor(context, useHdr, /* matrixTransformation= */ this);
return MatrixTransformationProcessor.create(
context, /* matrixTransformations= */ ImmutableList.of(this), useHdr);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment