mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Replace Pair with Size in effects.
PiperOrigin-RevId: 495646341
This commit is contained in:
parent
22dfd4cb32
commit
6376f5f7c7
@ -28,11 +28,11 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.GLUtils;
|
import android.opengl.GLUtils;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.effect.SingleFrameGlTextureProcessor;
|
import androidx.media3.effect.SingleFrameGlTextureProcessor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -111,7 +111,7 @@ import java.util.Locale;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
if (inputWidth > inputHeight) {
|
if (inputWidth > inputHeight) {
|
||||||
bitmapScaleX = inputWidth / (float) inputHeight;
|
bitmapScaleX = inputWidth / (float) inputHeight;
|
||||||
bitmapScaleY = 1f;
|
bitmapScaleY = 1f;
|
||||||
@ -123,7 +123,7 @@ import java.util.Locale;
|
|||||||
glProgram.setFloatUniform("uScaleX", bitmapScaleX);
|
glProgram.setFloatUniform("uScaleX", bitmapScaleX);
|
||||||
glProgram.setFloatUniform("uScaleY", bitmapScaleY);
|
glProgram.setFloatUniform("uScaleY", bitmapScaleY);
|
||||||
|
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,10 +19,10 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.effect.SingleFrameGlTextureProcessor;
|
import androidx.media3.effect.SingleFrameGlTextureProcessor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -90,8 +90,8 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,9 +33,9 @@ import android.graphics.Color;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -100,13 +100,13 @@ public class ContrastPixelTest {
|
|||||||
String testId = "drawFrame_noContrastChange";
|
String testId = "drawFrame_noContrastChange";
|
||||||
contrastProcessor =
|
contrastProcessor =
|
||||||
new Contrast(/* contrast= */ 0.0f).toGlTextureProcessor(context, /* useHdr= */ false);
|
new Contrast(/* contrast= */ 0.0f).toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -119,8 +119,8 @@ public class ContrastPixelTest {
|
|||||||
String testId = "drawFrame_minimumContrast";
|
String testId = "drawFrame_minimumContrast";
|
||||||
contrastProcessor =
|
contrastProcessor =
|
||||||
new Contrast(/* contrast= */ -1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
|
new Contrast(/* contrast= */ -1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap =
|
Bitmap expectedBitmap =
|
||||||
createArgb8888BitmapWithSolidColor(
|
createArgb8888BitmapWithSolidColor(
|
||||||
inputWidth,
|
inputWidth,
|
||||||
@ -130,7 +130,7 @@ public class ContrastPixelTest {
|
|||||||
|
|
||||||
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -144,13 +144,13 @@ public class ContrastPixelTest {
|
|||||||
String testId = "drawFrame_decreaseContrast";
|
String testId = "drawFrame_decreaseContrast";
|
||||||
contrastProcessor =
|
contrastProcessor =
|
||||||
new Contrast(/* contrast= */ -0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
|
new Contrast(/* contrast= */ -0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(DECREASE_CONTRAST_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(DECREASE_CONTRAST_PNG_ASSET_PATH);
|
||||||
|
|
||||||
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -164,13 +164,13 @@ public class ContrastPixelTest {
|
|||||||
String testId = "drawFrame_increaseContrast";
|
String testId = "drawFrame_increaseContrast";
|
||||||
contrastProcessor =
|
contrastProcessor =
|
||||||
new Contrast(/* contrast= */ 0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
|
new Contrast(/* contrast= */ 0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(INCREASE_CONTRAST_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(INCREASE_CONTRAST_PNG_ASSET_PATH);
|
||||||
|
|
||||||
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -183,13 +183,13 @@ public class ContrastPixelTest {
|
|||||||
String testId = "drawFrame_maximumContrast";
|
String testId = "drawFrame_maximumContrast";
|
||||||
contrastProcessor =
|
contrastProcessor =
|
||||||
new Contrast(/* contrast= */ 1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
|
new Contrast(/* contrast= */ 1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(MAXIMUM_CONTRAST_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(MAXIMUM_CONTRAST_PNG_ASSET_PATH);
|
||||||
|
|
||||||
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
|
@ -30,9 +30,9 @@ import android.graphics.Bitmap;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@ -96,13 +96,13 @@ public final class CropPixelTest {
|
|||||||
cropTextureProcessor =
|
cropTextureProcessor =
|
||||||
new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1)
|
new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -117,13 +117,13 @@ public final class CropPixelTest {
|
|||||||
cropTextureProcessor =
|
cropTextureProcessor =
|
||||||
new Crop(/* left= */ -.9f, /* right= */ .1f, /* bottom= */ -1f, /* top= */ .5f)
|
new Crop(/* left= */ -.9f, /* right= */ .1f, /* bottom= */ -1f, /* top= */ .5f)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(CROP_SMALLER_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(CROP_SMALLER_PNG_ASSET_PATH);
|
||||||
|
|
||||||
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -138,13 +138,13 @@ public final class CropPixelTest {
|
|||||||
cropTextureProcessor =
|
cropTextureProcessor =
|
||||||
new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f)
|
new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(CROP_LARGER_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(CROP_LARGER_PNG_ASSET_PATH);
|
||||||
|
|
||||||
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
|
@ -33,7 +33,6 @@ import android.graphics.PixelFormat;
|
|||||||
import android.media.Image;
|
import android.media.Image;
|
||||||
import android.media.ImageReader;
|
import android.media.ImageReader;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.ColorInfo;
|
import androidx.media3.common.ColorInfo;
|
||||||
import androidx.media3.common.DebugViewProvider;
|
import androidx.media3.common.DebugViewProvider;
|
||||||
@ -42,6 +41,7 @@ import androidx.media3.common.FrameInfo;
|
|||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.FrameProcessor;
|
import androidx.media3.common.FrameProcessor;
|
||||||
import androidx.media3.common.SurfaceInfo;
|
import androidx.media3.common.SurfaceInfo;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.test.utils.DecodeOneFrameUtil;
|
import androidx.media3.test.utils.DecodeOneFrameUtil;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@ -547,14 +547,14 @@ public final class GlEffectsFrameProcessorPixelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
adjustedTransformationMatrix = new Matrix();
|
adjustedTransformationMatrix = new Matrix();
|
||||||
adjustedTransformationMatrix.postRotate(degrees);
|
adjustedTransformationMatrix.postRotate(degrees);
|
||||||
float inputAspectRatio = (float) inputWidth / inputHeight;
|
float inputAspectRatio = (float) inputWidth / inputHeight;
|
||||||
adjustedTransformationMatrix.preScale(/* sx= */ inputAspectRatio, /* sy= */ 1f);
|
adjustedTransformationMatrix.preScale(/* sx= */ inputAspectRatio, /* sy= */ 1f);
|
||||||
adjustedTransformationMatrix.postScale(/* sx= */ 1f / inputAspectRatio, /* sy= */ 1f);
|
adjustedTransformationMatrix.postScale(/* sx= */ 1f / inputAspectRatio, /* sy= */ 1f);
|
||||||
|
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,9 +32,9 @@ import android.graphics.Color;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@ -111,12 +111,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_noOpAdjustment";
|
String testId = "drawFrame_noOpAdjustment";
|
||||||
HslAdjustment noOpAdjustment = new HslAdjustment.Builder().build();
|
HslAdjustment noOpAdjustment = new HslAdjustment.Builder().build();
|
||||||
hslProcessor = noOpAdjustment.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = noOpAdjustment.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -129,12 +129,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_minimumSaturation";
|
String testId = "drawFrame_minimumSaturation";
|
||||||
HslAdjustment minimumSaturation = new HslAdjustment.Builder().adjustSaturation(-100).build();
|
HslAdjustment minimumSaturation = new HslAdjustment.Builder().adjustSaturation(-100).build();
|
||||||
hslProcessor = minimumSaturation.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = minimumSaturation.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(MINIMUM_SATURATION_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(MINIMUM_SATURATION_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -147,12 +147,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_maximumSaturation";
|
String testId = "drawFrame_maximumSaturation";
|
||||||
HslAdjustment maximumSaturation = new HslAdjustment.Builder().adjustSaturation(100).build();
|
HslAdjustment maximumSaturation = new HslAdjustment.Builder().adjustSaturation(100).build();
|
||||||
hslProcessor = maximumSaturation.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = maximumSaturation.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(MAXIMUM_SATURATION_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(MAXIMUM_SATURATION_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -165,12 +165,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_rotateHueByNegative90Degrees";
|
String testId = "drawFrame_rotateHueByNegative90Degrees";
|
||||||
HslAdjustment negativeHueRotation90Degrees = new HslAdjustment.Builder().adjustHue(-90).build();
|
HslAdjustment negativeHueRotation90Degrees = new HslAdjustment.Builder().adjustHue(-90).build();
|
||||||
hslProcessor = negativeHueRotation90Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = negativeHueRotation90Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ROTATE_HUE_BY_NEGATIVE_90_DEGREES_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ROTATE_HUE_BY_NEGATIVE_90_DEGREES_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -183,12 +183,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_rotateHueBy60Degrees";
|
String testId = "drawFrame_rotateHueBy60Degrees";
|
||||||
HslAdjustment hueRotation60Degrees = new HslAdjustment.Builder().adjustHue(60).build();
|
HslAdjustment hueRotation60Degrees = new HslAdjustment.Builder().adjustHue(60).build();
|
||||||
hslProcessor = hueRotation60Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = hueRotation60Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ROTATE_HUE_BY_60_DEGREES_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ROTATE_HUE_BY_60_DEGREES_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -202,12 +202,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_rotateHueByNegative300Degrees";
|
String testId = "drawFrame_rotateHueByNegative300Degrees";
|
||||||
HslAdjustment hueRotation420Degrees = new HslAdjustment.Builder().adjustHue(-300).build();
|
HslAdjustment hueRotation420Degrees = new HslAdjustment.Builder().adjustHue(-300).build();
|
||||||
hslProcessor = hueRotation420Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = hueRotation420Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ROTATE_HUE_BY_60_DEGREES_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ROTATE_HUE_BY_60_DEGREES_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -220,12 +220,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_rotateHueBy360Degrees";
|
String testId = "drawFrame_rotateHueBy360Degrees";
|
||||||
HslAdjustment hueRotation360Degrees = new HslAdjustment.Builder().adjustHue(360).build();
|
HslAdjustment hueRotation360Degrees = new HslAdjustment.Builder().adjustHue(360).build();
|
||||||
hslProcessor = hueRotation360Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = hueRotation360Degrees.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -238,13 +238,13 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_minimumLightness";
|
String testId = "drawFrame_minimumLightness";
|
||||||
HslAdjustment minimumLightness = new HslAdjustment.Builder().adjustLightness(-100).build();
|
HslAdjustment minimumLightness = new HslAdjustment.Builder().adjustLightness(-100).build();
|
||||||
hslProcessor = minimumLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = minimumLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap =
|
Bitmap expectedBitmap =
|
||||||
createArgb8888BitmapWithSolidColor(inputWidth, inputHeight, Color.BLACK);
|
createArgb8888BitmapWithSolidColor(inputWidth, inputHeight, Color.BLACK);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -257,12 +257,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_decreaseLightness";
|
String testId = "drawFrame_decreaseLightness";
|
||||||
HslAdjustment decreasedLightness = new HslAdjustment.Builder().adjustLightness(-50).build();
|
HslAdjustment decreasedLightness = new HslAdjustment.Builder().adjustLightness(-50).build();
|
||||||
hslProcessor = decreasedLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = decreasedLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(DECREASE_LIGHTNESS_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(DECREASE_LIGHTNESS_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -275,12 +275,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_increaseLightness";
|
String testId = "drawFrame_increaseLightness";
|
||||||
HslAdjustment increasedLightness = new HslAdjustment.Builder().adjustLightness(50).build();
|
HslAdjustment increasedLightness = new HslAdjustment.Builder().adjustLightness(50).build();
|
||||||
hslProcessor = increasedLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = increasedLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(INCREASE_LIGHTNESS_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(INCREASE_LIGHTNESS_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -293,13 +293,13 @@ public final class HslAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_maximumLightness";
|
String testId = "drawFrame_maximumLightness";
|
||||||
HslAdjustment maximumLightness = new HslAdjustment.Builder().adjustLightness(100).build();
|
HslAdjustment maximumLightness = new HslAdjustment.Builder().adjustLightness(100).build();
|
||||||
hslProcessor = maximumLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = maximumLightness.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap =
|
Bitmap expectedBitmap =
|
||||||
createArgb8888BitmapWithSolidColor(inputWidth, inputHeight, Color.WHITE);
|
createArgb8888BitmapWithSolidColor(inputWidth, inputHeight, Color.WHITE);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -313,12 +313,12 @@ public final class HslAdjustmentPixelTest {
|
|||||||
HslAdjustment allHslSettingsAdjusted =
|
HslAdjustment allHslSettingsAdjusted =
|
||||||
new HslAdjustment.Builder().adjustHue(60).adjustSaturation(30).adjustLightness(50).build();
|
new HslAdjustment.Builder().adjustHue(60).adjustSaturation(30).adjustLightness(50).build();
|
||||||
hslProcessor = allHslSettingsAdjusted.toGlTextureProcessor(context, /* useHdr= */ false);
|
hslProcessor = allHslSettingsAdjusted.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = hslProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ADJUST_ALL_HSL_SETTINGS_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ADJUST_ALL_HSL_SETTINGS_PNG_ASSET_PATH);
|
||||||
|
|
||||||
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
hslProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
|
@ -35,9 +35,9 @@ import android.opengl.Matrix;
|
|||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -107,13 +107,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(/* textureOverlays= */ ImmutableList.of())
|
new OverlayEffect(/* textureOverlays= */ ImmutableList.of())
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -129,13 +129,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(ImmutableList.of(scaledBitmapOverlay))
|
new OverlayEffect(ImmutableList.of(scaledBitmapOverlay))
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(OVERLAY_BITMAP_DEFAULT);
|
Bitmap expectedBitmap = readBitmap(OVERLAY_BITMAP_DEFAULT);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -155,13 +155,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(ImmutableList.of(staticBitmapOverlay))
|
new OverlayEffect(ImmutableList.of(staticBitmapOverlay))
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(OVERLAY_BITMAP_SCALED);
|
Bitmap expectedBitmap = readBitmap(OVERLAY_BITMAP_SCALED);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -179,13 +179,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(ImmutableList.of(translucentBitmapOverlay))
|
new OverlayEffect(ImmutableList.of(translucentBitmapOverlay))
|
||||||
.toGlTextureProcessor(context, false);
|
.toGlTextureProcessor(context, false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(OVERLAY_BITMAP_TRANSLUCENT);
|
Bitmap expectedBitmap = readBitmap(OVERLAY_BITMAP_TRANSLUCENT);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -208,13 +208,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(ImmutableList.of(staticTextOverlay))
|
new OverlayEffect(ImmutableList.of(staticTextOverlay))
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -235,13 +235,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(ImmutableList.of(staticTextOverlay))
|
new OverlayEffect(ImmutableList.of(staticTextOverlay))
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(OVERLAY_TEXT_DEFAULT);
|
Bitmap expectedBitmap = readBitmap(OVERLAY_TEXT_DEFAULT);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -267,13 +267,13 @@ public class OverlayTextureProcessorPixelTest {
|
|||||||
overlayTextureProcessor =
|
overlayTextureProcessor =
|
||||||
new OverlayEffect(ImmutableList.of(staticTextOverlay))
|
new OverlayEffect(ImmutableList.of(staticTextOverlay))
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = overlayTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(OVERLAY_TEXT_TRANSLATE);
|
Bitmap expectedBitmap = readBitmap(OVERLAY_TEXT_TRANSLATE);
|
||||||
|
|
||||||
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
overlayTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
|
@ -30,10 +30,10 @@ import android.graphics.Bitmap;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@ -105,14 +105,13 @@ public final class PresentationPixelTest {
|
|||||||
presentationTextureProcessor =
|
presentationTextureProcessor =
|
||||||
Presentation.createForHeight(C.LENGTH_UNSET)
|
Presentation.createForHeight(C.LENGTH_UNSET)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -128,14 +127,13 @@ public final class PresentationPixelTest {
|
|||||||
presentationTextureProcessor =
|
presentationTextureProcessor =
|
||||||
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT)
|
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -151,14 +149,13 @@ public final class PresentationPixelTest {
|
|||||||
presentationTextureProcessor =
|
presentationTextureProcessor =
|
||||||
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT)
|
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WIDE_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WIDE_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -175,14 +172,13 @@ public final class PresentationPixelTest {
|
|||||||
Presentation.createForAspectRatio(
|
Presentation.createForAspectRatio(
|
||||||
/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
|
/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_NARROW_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_NARROW_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -199,14 +195,13 @@ public final class PresentationPixelTest {
|
|||||||
Presentation.createForAspectRatio(
|
Presentation.createForAspectRatio(
|
||||||
/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
|
/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_WIDE_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_WIDE_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -222,14 +217,13 @@ public final class PresentationPixelTest {
|
|||||||
presentationTextureProcessor =
|
presentationTextureProcessor =
|
||||||
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT)
|
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_NARROW_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_NARROW_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
@ -245,14 +239,13 @@ public final class PresentationPixelTest {
|
|||||||
presentationTextureProcessor =
|
presentationTextureProcessor =
|
||||||
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT)
|
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize =
|
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
presentationTextureProcessor.configure(inputWidth, inputHeight);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
|
||||||
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_WIDE_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_WIDE_PNG_ASSET_PATH);
|
||||||
|
|
||||||
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
|
||||||
|
@ -33,9 +33,9 @@ import android.graphics.Color;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -110,12 +110,12 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_identityMatrix";
|
String testId = "drawFrame_identityMatrix";
|
||||||
RgbMatrix identityMatrix = new RgbAdjustment.Builder().build();
|
RgbMatrix identityMatrix = new RgbAdjustment.Builder().build();
|
||||||
matrixTextureProcessor = identityMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
matrixTextureProcessor = identityMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -129,13 +129,14 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
RgbMatrix removeColorMatrix =
|
RgbMatrix removeColorMatrix =
|
||||||
new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build();
|
new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build();
|
||||||
matrixTextureProcessor = removeColorMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
matrixTextureProcessor = removeColorMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap =
|
Bitmap expectedBitmap =
|
||||||
createArgb8888BitmapWithSolidColor(outputSize.first, outputSize.second, Color.BLACK);
|
createArgb8888BitmapWithSolidColor(
|
||||||
|
outputSize.getWidth(), outputSize.getHeight(), Color.BLACK);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -148,12 +149,12 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_redOnlyFilter";
|
String testId = "drawFrame_redOnlyFilter";
|
||||||
RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build();
|
RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build();
|
||||||
matrixTextureProcessor = redOnlyMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
matrixTextureProcessor = redOnlyMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -166,12 +167,12 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
String testId = "drawFrame_increaseRedChannel";
|
String testId = "drawFrame_increaseRedChannel";
|
||||||
RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build();
|
RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build();
|
||||||
matrixTextureProcessor = increaseRedMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
matrixTextureProcessor = increaseRedMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(INCREASE_RED_CHANNEL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(INCREASE_RED_CHANNEL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -186,12 +187,12 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build();
|
new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build();
|
||||||
matrixTextureProcessor =
|
matrixTextureProcessor =
|
||||||
increaseBrightnessMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
increaseBrightnessMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -211,13 +212,14 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
/* matrixTransformations= */ ImmutableList.of(),
|
/* matrixTransformations= */ ImmutableList.of(),
|
||||||
/* rgbMatrices= */ ImmutableList.of(noRed, noGreen, noBlue),
|
/* rgbMatrices= */ ImmutableList.of(noRed, noGreen, noBlue),
|
||||||
/* useHdr= */ false);
|
/* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap =
|
Bitmap expectedBitmap =
|
||||||
createArgb8888BitmapWithSolidColor(outputSize.first, outputSize.second, Color.BLACK);
|
createArgb8888BitmapWithSolidColor(
|
||||||
|
outputSize.getWidth(), outputSize.getHeight(), Color.BLACK);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -236,12 +238,12 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
/* matrixTransformations= */ ImmutableList.of(),
|
/* matrixTransformations= */ ImmutableList.of(),
|
||||||
/* rgbMatrices= */ ImmutableList.of(noGreen, noBlue),
|
/* rgbMatrices= */ ImmutableList.of(noGreen, noBlue),
|
||||||
/* useHdr= */ false);
|
/* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -262,12 +264,12 @@ public final class RgbAdjustmentPixelTest {
|
|||||||
/* matrixTransformations= */ ImmutableList.of(),
|
/* matrixTransformations= */ ImmutableList.of(),
|
||||||
/* rgbMatrices= */ ImmutableList.of(scaleRedMatrix, scaleRedByInverseMatrix),
|
/* rgbMatrices= */ ImmutableList.of(scaleRedMatrix, scaleRedByInverseMatrix),
|
||||||
/* useHdr= */ false);
|
/* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
|
@ -31,9 +31,9 @@ import android.graphics.Bitmap;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@ -105,12 +105,12 @@ public final class RgbFilterPixelTest {
|
|||||||
String testId = "drawFrame_grayscale";
|
String testId = "drawFrame_grayscale";
|
||||||
RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter();
|
RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter();
|
||||||
matrixTextureProcessor = grayscaleMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
matrixTextureProcessor = grayscaleMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -123,12 +123,12 @@ public final class RgbFilterPixelTest {
|
|||||||
String testId = "drawFrame_inverted";
|
String testId = "drawFrame_inverted";
|
||||||
RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter();
|
RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter();
|
||||||
matrixTextureProcessor = invertedMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
matrixTextureProcessor = invertedMatrix.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH);
|
||||||
|
|
||||||
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
|
@ -32,9 +32,9 @@ import android.graphics.Color;
|
|||||||
import android.opengl.EGLContext;
|
import android.opengl.EGLContext;
|
||||||
import android.opengl.EGLDisplay;
|
import android.opengl.EGLDisplay;
|
||||||
import android.opengl.EGLSurface;
|
import android.opengl.EGLSurface;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -101,13 +101,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromCube(cubeIdentityLut)
|
SingleColorLut.createFromCube(cubeIdentityLut)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -122,13 +122,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromCube(cubeIdentityLut)
|
SingleColorLut.createFromCube(cubeIdentityLut)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -143,13 +143,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromBitmap(bitmapLut)
|
SingleColorLut.createFromBitmap(bitmapLut)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -164,13 +164,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromBitmap(bitmapLut)
|
SingleColorLut.createFromBitmap(bitmapLut)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -185,13 +185,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromBitmap(bitmapLut)
|
SingleColorLut.createFromBitmap(bitmapLut)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -208,13 +208,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromCube(mapWhiteToGreen)
|
SingleColorLut.createFromCube(mapWhiteToGreen)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(LUT_MAP_WHITE_TO_GREEN_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(LUT_MAP_WHITE_TO_GREEN_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -229,13 +229,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromBitmap(invertedLutBitmap)
|
SingleColorLut.createFromBitmap(invertedLutBitmap)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
@ -250,13 +250,13 @@ public class SingleColorLutPixelTest {
|
|||||||
colorLutProcessor =
|
colorLutProcessor =
|
||||||
SingleColorLut.createFromBitmap(grayscaleLutBitmap)
|
SingleColorLut.createFromBitmap(grayscaleLutBitmap)
|
||||||
.toGlTextureProcessor(context, /* useHdr= */ false);
|
.toGlTextureProcessor(context, /* useHdr= */ false);
|
||||||
Pair<Integer, Integer> outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = colorLutProcessor.configure(inputWidth, inputHeight);
|
||||||
setupOutputTexture(outputSize.first, outputSize.second);
|
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
|
||||||
Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH);
|
Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH);
|
||||||
|
|
||||||
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
colorLutProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
|
||||||
Bitmap actualBitmap =
|
Bitmap actualBitmap =
|
||||||
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
|
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
|
||||||
|
|
||||||
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
|
||||||
float averagePixelAbsoluteDifference =
|
float averagePixelAbsoluteDifference =
|
||||||
|
@ -21,9 +21,9 @@ import android.graphics.Bitmap;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.GLUtils;
|
import android.opengl.GLUtils;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@ -55,8 +55,8 @@ public abstract class BitmapOverlay extends TextureOverlay {
|
|||||||
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> getTextureSize(long presentationTimeUs) {
|
public Size getTextureSize(long presentationTimeUs) {
|
||||||
return Pair.create(checkNotNull(lastBitmap).getWidth(), checkNotNull(lastBitmap).getHeight());
|
return new Size(checkNotNull(lastBitmap).getWidth(), checkNotNull(lastBitmap).getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,10 +20,10 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** Applies a {@link ColorLut} to each frame in the fragment shader. */
|
/** Applies a {@link ColorLut} to each frame in the fragment shader. */
|
||||||
@ -68,8 +68,8 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,10 +18,10 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** Applies a {@link Contrast} to each frame in the fragment shader. */
|
/** Applies a {@link Contrast} to each frame in the fragment shader. */
|
||||||
@ -65,8 +65,8 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,8 +19,8 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
|||||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
||||||
|
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
@ -66,14 +66,14 @@ public final class Crop implements MatrixTransformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
||||||
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
||||||
|
|
||||||
transformationMatrix = new Matrix();
|
transformationMatrix = new Matrix();
|
||||||
if (left == -1f && right == 1f && bottom == -1f && top == 1f) {
|
if (left == -1f && right == 1f && bottom == -1f && top == 1f) {
|
||||||
// No crop needed.
|
// No crop needed.
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
float scaleX = (right - left) / GlUtil.LENGTH_NDC;
|
float scaleX = (right - left) / GlUtil.LENGTH_NDC;
|
||||||
@ -86,7 +86,7 @@ public final class Crop implements MatrixTransformation {
|
|||||||
|
|
||||||
int outputWidth = Math.round(inputWidth * scaleX);
|
int outputWidth = Math.round(inputWidth * scaleX);
|
||||||
int outputHeight = Math.round(inputHeight * scaleY);
|
int outputHeight = Math.round(inputHeight * scaleY);
|
||||||
return Pair.create(outputWidth, outputHeight);
|
return new Size(outputWidth, outputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,6 +40,7 @@ import androidx.media3.common.FrameProcessor;
|
|||||||
import androidx.media3.common.SurfaceInfo;
|
import androidx.media3.common.SurfaceInfo;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -84,7 +85,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
@Nullable private MatrixTextureProcessor matrixTextureProcessor;
|
@Nullable private MatrixTextureProcessor matrixTextureProcessor;
|
||||||
@Nullable private SurfaceViewWrapper debugSurfaceViewWrapper;
|
@Nullable private SurfaceViewWrapper debugSurfaceViewWrapper;
|
||||||
private InputListener inputListener;
|
private InputListener inputListener;
|
||||||
private @MonotonicNonNull Pair<Integer, Integer> outputSizeBeforeSurfaceTransformation;
|
private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation;
|
||||||
@Nullable private SurfaceView debugSurfaceView;
|
@Nullable private SurfaceView debugSurfaceView;
|
||||||
|
|
||||||
private volatile boolean outputSizeOrRotationChanged;
|
private volatile boolean outputSizeOrRotationChanged;
|
||||||
@ -313,7 +314,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
|| this.outputSizeBeforeSurfaceTransformation == null) {
|
|| this.outputSizeBeforeSurfaceTransformation == null) {
|
||||||
this.inputWidth = inputWidth;
|
this.inputWidth = inputWidth;
|
||||||
this.inputHeight = inputHeight;
|
this.inputHeight = inputHeight;
|
||||||
Pair<Integer, Integer> outputSizeBeforeSurfaceTransformation =
|
Size outputSizeBeforeSurfaceTransformation =
|
||||||
MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
|
MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
|
||||||
if (!Util.areEqual(
|
if (!Util.areEqual(
|
||||||
this.outputSizeBeforeSurfaceTransformation, outputSizeBeforeSurfaceTransformation)) {
|
this.outputSizeBeforeSurfaceTransformation, outputSizeBeforeSurfaceTransformation)) {
|
||||||
@ -321,8 +322,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
frameProcessorListenerExecutor.execute(
|
frameProcessorListenerExecutor.execute(
|
||||||
() ->
|
() ->
|
||||||
frameProcessorListener.onOutputSizeChanged(
|
frameProcessorListener.onOutputSizeChanged(
|
||||||
outputSizeBeforeSurfaceTransformation.first,
|
outputSizeBeforeSurfaceTransformation.getWidth(),
|
||||||
outputSizeBeforeSurfaceTransformation.second));
|
outputSizeBeforeSurfaceTransformation.getHeight()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,9 +407,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
}
|
}
|
||||||
|
|
||||||
matrixTextureProcessor.setTextureTransformMatrix(textureTransformMatrix);
|
matrixTextureProcessor.setTextureTransformMatrix(textureTransformMatrix);
|
||||||
Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
Size outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
|
||||||
checkState(outputSize.first == outputSurfaceInfo.width);
|
checkState(outputSize.getWidth() == outputSurfaceInfo.width);
|
||||||
checkState(outputSize.second == outputSurfaceInfo.height);
|
checkState(outputSize.getHeight() == outputSurfaceInfo.height);
|
||||||
return matrixTextureProcessor;
|
return matrixTextureProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
@ -43,8 +43,8 @@ public interface GlMatrixTransformation extends GlEffect {
|
|||||||
* @param inputHeight The input frame height, in pixels.
|
* @param inputHeight The input frame height, in pixels.
|
||||||
* @return The output frame width and height, in pixels.
|
* @return The output frame width and height, in pixels.
|
||||||
*/
|
*/
|
||||||
default Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
default Size configure(int inputWidth, int inputHeight) {
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,10 +20,10 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** Applies the {@link HslAdjustment} to each frame in the fragment shader. */
|
/** Applies the {@link HslAdjustment} to each frame in the fragment shader. */
|
||||||
@ -73,8 +73,8 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,13 +21,13 @@ import static androidx.media3.common.util.Assertions.checkState;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.ColorInfo;
|
import androidx.media3.common.ColorInfo;
|
||||||
import androidx.media3.common.Format;
|
import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -356,7 +356,7 @@ import java.util.List;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
return MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
|
return MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ package androidx.media3.effect;
|
|||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
|
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
import android.util.Pair;
|
import androidx.media3.common.util.Size;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -222,16 +222,17 @@ import java.util.Arrays;
|
|||||||
* Returns the output frame size after applying the given list of {@link GlMatrixTransformation
|
* Returns the output frame size after applying the given list of {@link GlMatrixTransformation
|
||||||
* GlMatrixTransformations} to an input frame with the given size.
|
* GlMatrixTransformations} to an input frame with the given size.
|
||||||
*/
|
*/
|
||||||
public static Pair<Integer, Integer> configureAndGetOutputSize(
|
public static Size configureAndGetOutputSize(
|
||||||
int inputWidth,
|
int inputWidth,
|
||||||
int inputHeight,
|
int inputHeight,
|
||||||
ImmutableList<GlMatrixTransformation> matrixTransformations) {
|
ImmutableList<GlMatrixTransformation> matrixTransformations) {
|
||||||
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
||||||
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = Pair.create(inputWidth, inputHeight);
|
Size outputSize = new Size(inputWidth, inputHeight);
|
||||||
for (int i = 0; i < matrixTransformations.size(); i++) {
|
for (int i = 0; i < matrixTransformations.size(); i++) {
|
||||||
outputSize = matrixTransformations.get(i).configure(outputSize.first, outputSize.second);
|
outputSize =
|
||||||
|
matrixTransformations.get(i).configure(outputSize.getWidth(), outputSize.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputSize;
|
return outputSize;
|
||||||
|
@ -20,10 +20,10 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -76,10 +76,10 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
videoWidth = inputWidth;
|
videoWidth = inputWidth;
|
||||||
videoHeight = inputHeight;
|
videoHeight = inputHeight;
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,13 +90,13 @@ import java.io.IOException;
|
|||||||
TextureOverlay overlay = overlays.get(0);
|
TextureOverlay overlay = overlays.get(0);
|
||||||
glProgram.setSamplerTexIdUniform(
|
glProgram.setSamplerTexIdUniform(
|
||||||
"uOverlayTexSampler1", overlay.getTextureId(presentationTimeUs), /* texUnitIndex= */ 1);
|
"uOverlayTexSampler1", overlay.getTextureId(presentationTimeUs), /* texUnitIndex= */ 1);
|
||||||
Pair<Integer, Integer> overlayTextureSize = overlay.getTextureSize(presentationTimeUs);
|
Size overlayTextureSize = overlay.getTextureSize(presentationTimeUs);
|
||||||
GlUtil.setToIdentity(aspectRatioMatrix);
|
GlUtil.setToIdentity(aspectRatioMatrix);
|
||||||
Matrix.scaleM(
|
Matrix.scaleM(
|
||||||
aspectRatioMatrix,
|
aspectRatioMatrix,
|
||||||
MATRIX_OFFSET,
|
MATRIX_OFFSET,
|
||||||
videoWidth / (float) overlayTextureSize.first,
|
videoWidth / (float) overlayTextureSize.getWidth(),
|
||||||
videoHeight / (float) overlayTextureSize.second,
|
videoHeight / (float) overlayTextureSize.getHeight(),
|
||||||
/* z= */ 1);
|
/* z= */ 1);
|
||||||
glProgram.setFloatsUniform("uAspectRatioMatrix", aspectRatioMatrix);
|
glProgram.setFloatsUniform("uAspectRatioMatrix", aspectRatioMatrix);
|
||||||
Matrix.invertM(
|
Matrix.invertM(
|
||||||
|
@ -21,9 +21,9 @@ import static java.lang.annotation.ElementType.TYPE_USE;
|
|||||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||||
|
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -181,7 +181,7 @@ public final class Presentation implements MatrixTransformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
||||||
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ public final class Presentation implements MatrixTransformation {
|
|||||||
}
|
}
|
||||||
outputHeight = requestedHeightPixels;
|
outputHeight = requestedHeightPixels;
|
||||||
}
|
}
|
||||||
return Pair.create(Math.round(outputWidth), Math.round(outputHeight));
|
return new Size(Math.round(outputWidth), Math.round(outputHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,8 +21,8 @@ import static java.lang.Math.max;
|
|||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@ -105,14 +105,14 @@ public final class ScaleToFitTransformation implements MatrixTransformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
|
public Size configure(int inputWidth, int inputHeight) {
|
||||||
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
checkArgument(inputWidth > 0, "inputWidth must be positive");
|
||||||
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
checkArgument(inputHeight > 0, "inputHeight must be positive");
|
||||||
|
|
||||||
adjustedTransformationMatrix = new Matrix(transformationMatrix);
|
adjustedTransformationMatrix = new Matrix(transformationMatrix);
|
||||||
|
|
||||||
if (transformationMatrix.isIdentity()) {
|
if (transformationMatrix.isIdentity()) {
|
||||||
return Pair.create(inputWidth, inputHeight);
|
return new Size(inputWidth, inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
float inputAspectRatio = (float) inputWidth / inputHeight;
|
float inputAspectRatio = (float) inputWidth / inputHeight;
|
||||||
@ -141,7 +141,7 @@ public final class ScaleToFitTransformation implements MatrixTransformation {
|
|||||||
float scaleX = (maxX - minX) / GlUtil.LENGTH_NDC;
|
float scaleX = (maxX - minX) / GlUtil.LENGTH_NDC;
|
||||||
float scaleY = (maxY - minY) / GlUtil.LENGTH_NDC;
|
float scaleY = (maxY - minY) / GlUtil.LENGTH_NDC;
|
||||||
adjustedTransformationMatrix.postScale(1f / scaleX, 1f / scaleY);
|
adjustedTransformationMatrix.postScale(1f / scaleX, 1f / scaleY);
|
||||||
return Pair.create(Math.round(inputWidth * scaleX), Math.round(inputHeight * scaleY));
|
return new Size(Math.round(inputWidth * scaleX), Math.round(inputHeight * scaleY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,10 +17,10 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
|
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@ -75,7 +75,7 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso
|
|||||||
* @param inputHeight The input height, in pixels.
|
* @param inputHeight The input height, in pixels.
|
||||||
* @return The output width and height of frames processed through {@link #drawFrame(int, long)}.
|
* @return The output width and height of frames processed through {@link #drawFrame(int, long)}.
|
||||||
*/
|
*/
|
||||||
public abstract Pair<Integer, Integer> configure(int inputWidth, int inputHeight);
|
public abstract Size configure(int inputWidth, int inputHeight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws one frame.
|
* Draws one frame.
|
||||||
@ -147,17 +147,17 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso
|
|||||||
private void configureOutputTexture(int inputWidth, int inputHeight) throws GlUtil.GlException {
|
private void configureOutputTexture(int inputWidth, int inputHeight) throws GlUtil.GlException {
|
||||||
this.inputWidth = inputWidth;
|
this.inputWidth = inputWidth;
|
||||||
this.inputHeight = inputHeight;
|
this.inputHeight = inputHeight;
|
||||||
Pair<Integer, Integer> outputSize = configure(inputWidth, inputHeight);
|
Size outputSize = configure(inputWidth, inputHeight);
|
||||||
if (outputTexture == null
|
if (outputTexture == null
|
||||||
|| outputSize.first != outputTexture.width
|
|| outputSize.getWidth() != outputTexture.width
|
||||||
|| outputSize.second != outputTexture.height) {
|
|| outputSize.getHeight() != outputTexture.height) {
|
||||||
if (outputTexture != null) {
|
if (outputTexture != null) {
|
||||||
GlUtil.deleteTexture(outputTexture.texId);
|
GlUtil.deleteTexture(outputTexture.texId);
|
||||||
}
|
}
|
||||||
int outputTexId = GlUtil.createTexture(outputSize.first, outputSize.second, useHdr);
|
int outputTexId = GlUtil.createTexture(outputSize.getWidth(), outputSize.getHeight(), useHdr);
|
||||||
int outputFboId = GlUtil.createFboForTexture(outputTexId);
|
int outputFboId = GlUtil.createFboForTexture(outputTexId);
|
||||||
outputTexture =
|
outputTexture =
|
||||||
new TextureInfo(outputTexId, outputFboId, outputSize.first, outputSize.second);
|
new TextureInfo(outputTexId, outputFboId, outputSize.getWidth(), outputSize.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.effect;
|
package androidx.media3.effect;
|
||||||
|
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.FrameProcessingException;
|
import androidx.media3.common.FrameProcessingException;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
|
||||||
/** Creates overlays from OpenGL textures. */
|
/** Creates overlays from OpenGL textures. */
|
||||||
@ -39,7 +39,7 @@ public abstract class TextureOverlay {
|
|||||||
*
|
*
|
||||||
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
||||||
*/
|
*/
|
||||||
public abstract Pair<Integer, Integer> getTextureSize(long presentationTimeUs);
|
public abstract Size getTextureSize(long presentationTimeUs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link OverlaySettings} controlling how the overlay is displayed at the specified
|
* Returns the {@link OverlaySettings} controlling how the overlay is displayed at the specified
|
||||||
|
@ -17,8 +17,8 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -36,10 +36,10 @@ public final class CropTest {
|
|||||||
int inputHeight = 150;
|
int inputHeight = 150;
|
||||||
Crop crop = new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1);
|
Crop crop = new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1);
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = crop.configure(inputWidth, inputHeight);
|
Size outputSize = crop.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(inputWidth);
|
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -52,11 +52,11 @@ public final class CropTest {
|
|||||||
float top = 1f;
|
float top = 1f;
|
||||||
Crop crop = new Crop(left, right, bottom, top);
|
Crop crop = new Crop(left, right, bottom, top);
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = crop.configure(inputWidth, inputHeight);
|
Size outputSize = crop.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
int expectedPostCropWidth = Math.round(inputWidth * (right - left) / GlUtil.LENGTH_NDC);
|
int expectedPostCropWidth = Math.round(inputWidth * (right - left) / GlUtil.LENGTH_NDC);
|
||||||
int expectedPostCropHeight = Math.round(inputHeight * (top - bottom) / GlUtil.LENGTH_NDC);
|
int expectedPostCropHeight = Math.round(inputHeight * (top - bottom) / GlUtil.LENGTH_NDC);
|
||||||
assertThat(outputSize.first).isEqualTo(expectedPostCropWidth);
|
assertThat(outputSize.getWidth()).isEqualTo(expectedPostCropWidth);
|
||||||
assertThat(outputSize.second).isEqualTo(expectedPostCropHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(expectedPostCropHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.util.Pair;
|
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -36,10 +36,10 @@ public final class PresentationTest {
|
|||||||
int inputHeight = 150;
|
int inputHeight = 150;
|
||||||
Presentation presentation = Presentation.createForHeight(C.LENGTH_UNSET);
|
Presentation presentation = Presentation.createForHeight(C.LENGTH_UNSET);
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
|
Size outputSize = presentation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(inputWidth);
|
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -49,10 +49,10 @@ public final class PresentationTest {
|
|||||||
int requestedHeight = 300;
|
int requestedHeight = 300;
|
||||||
Presentation presentation = Presentation.createForHeight(requestedHeight);
|
Presentation presentation = Presentation.createForHeight(requestedHeight);
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
|
Size outputSize = presentation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(requestedHeight * inputWidth / inputHeight);
|
assertThat(outputSize.getWidth()).isEqualTo(requestedHeight * inputWidth / inputHeight);
|
||||||
assertThat(outputSize.second).isEqualTo(requestedHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(requestedHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -63,10 +63,10 @@ public final class PresentationTest {
|
|||||||
Presentation presentation =
|
Presentation presentation =
|
||||||
Presentation.createForAspectRatio(aspectRatio, Presentation.LAYOUT_SCALE_TO_FIT);
|
Presentation.createForAspectRatio(aspectRatio, Presentation.LAYOUT_SCALE_TO_FIT);
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
|
Size outputSize = presentation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(Math.round(aspectRatio * inputHeight));
|
assertThat(outputSize.getWidth()).isEqualTo(Math.round(aspectRatio * inputHeight));
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -79,9 +79,9 @@ public final class PresentationTest {
|
|||||||
Presentation.createForWidthAndHeight(
|
Presentation.createForWidthAndHeight(
|
||||||
requestedWidth, requestedHeight, Presentation.LAYOUT_SCALE_TO_FIT);
|
requestedWidth, requestedHeight, Presentation.LAYOUT_SCALE_TO_FIT);
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
|
Size outputSize = presentation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(requestedWidth);
|
assertThat(outputSize.getWidth()).isEqualTo(requestedWidth);
|
||||||
assertThat(outputSize.second).isEqualTo(requestedHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(requestedHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.util.Pair;
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -38,10 +38,10 @@ public final class ScaleToFitTransformationTest {
|
|||||||
ScaleToFitTransformation scaleToFitTransformation =
|
ScaleToFitTransformation scaleToFitTransformation =
|
||||||
new ScaleToFitTransformation.Builder().build();
|
new ScaleToFitTransformation.Builder().build();
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(inputWidth);
|
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -53,10 +53,10 @@ public final class ScaleToFitTransformationTest {
|
|||||||
.setScale(/* scaleX= */ .5f, /* scaleY= */ 1f)
|
.setScale(/* scaleX= */ .5f, /* scaleY= */ 1f)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(Math.round(inputWidth * .5f));
|
assertThat(outputSize.getWidth()).isEqualTo(Math.round(inputWidth * .5f));
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -66,10 +66,10 @@ public final class ScaleToFitTransformationTest {
|
|||||||
ScaleToFitTransformation scaleToFitTransformation =
|
ScaleToFitTransformation scaleToFitTransformation =
|
||||||
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 2f, /* scaleY= */ 1f).build();
|
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 2f, /* scaleY= */ 1f).build();
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(inputWidth * 2);
|
assertThat(outputSize.getWidth()).isEqualTo(inputWidth * 2);
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -79,10 +79,10 @@ public final class ScaleToFitTransformationTest {
|
|||||||
ScaleToFitTransformation scaleToFitTransformation =
|
ScaleToFitTransformation scaleToFitTransformation =
|
||||||
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 1f, /* scaleY= */ 2f).build();
|
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 1f, /* scaleY= */ 2f).build();
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(inputWidth);
|
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||||
assertThat(outputSize.second).isEqualTo(inputHeight * 2);
|
assertThat(outputSize.getHeight()).isEqualTo(inputHeight * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -92,10 +92,10 @@ public final class ScaleToFitTransformationTest {
|
|||||||
ScaleToFitTransformation scaleToFitTransformation =
|
ScaleToFitTransformation scaleToFitTransformation =
|
||||||
new ScaleToFitTransformation.Builder().setRotationDegrees(90).build();
|
new ScaleToFitTransformation.Builder().setRotationDegrees(90).build();
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(inputHeight);
|
assertThat(outputSize.getWidth()).isEqualTo(inputHeight);
|
||||||
assertThat(outputSize.second).isEqualTo(inputWidth);
|
assertThat(outputSize.getHeight()).isEqualTo(inputWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -106,9 +106,9 @@ public final class ScaleToFitTransformationTest {
|
|||||||
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build();
|
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build();
|
||||||
long expectedOutputWidthHeight = 247;
|
long expectedOutputWidthHeight = 247;
|
||||||
|
|
||||||
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
|
||||||
|
|
||||||
assertThat(outputSize.first).isEqualTo(expectedOutputWidthHeight);
|
assertThat(outputSize.getWidth()).isEqualTo(expectedOutputWidthHeight);
|
||||||
assertThat(outputSize.second).isEqualTo(expectedOutputWidthHeight);
|
assertThat(outputSize.getHeight()).isEqualTo(expectedOutputWidthHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user