Commit da2c6376 by huangdarwin Committed by Marc Baechinger

Tests: Statically import BitmapTestUtil methods.

Per go/java-practices/imports#static

No functional changes intended.

PiperOrigin-RevId: 477974779
parent 97868025
...@@ -129,7 +129,7 @@ public class BitmapTestUtil { ...@@ -129,7 +129,7 @@ public class BitmapTestUtil {
* @return The average of the maximum absolute pixel-wise differences between the expected and * @return The average of the maximum absolute pixel-wise differences between the expected and
* actual bitmaps. * actual bitmaps.
*/ */
public static float getAveragePixelAbsoluteDifferenceArgb8888( public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888(
Bitmap expected, Bitmap actual, @Nullable String testId) { Bitmap expected, Bitmap actual, @Nullable String testId) {
int width = actual.getWidth(); int width = actual.getWidth();
int height = actual.getHeight(); int height = actual.getHeight();
......
...@@ -17,6 +17,12 @@ ...@@ -17,6 +17,12 @@
package androidx.media3.effect; package androidx.media3.effect;
import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE; import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
import static androidx.media3.effect.BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer;
import static androidx.media3.effect.BitmapTestUtil.createArgb8888BitmapWithSolidColor;
import static androidx.media3.effect.BitmapTestUtil.createGlTextureFromBitmap;
import static androidx.media3.effect.BitmapTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888;
import static androidx.media3.effect.BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory;
import static androidx.media3.effect.BitmapTestUtil.readBitmap;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
...@@ -75,13 +81,13 @@ public class ContrastPixelTest { ...@@ -75,13 +81,13 @@ public class ContrastPixelTest {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.createEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap inputBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
inputWidth = inputBitmap.getWidth(); inputWidth = inputBitmap.getWidth();
inputHeight = inputBitmap.getHeight(); inputHeight = inputBitmap.getHeight();
placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay); placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay);
GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight); GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight);
inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@After @After
...@@ -99,18 +105,15 @@ public class ContrastPixelTest { ...@@ -99,18 +105,15 @@ public class ContrastPixelTest {
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); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -122,7 +125,7 @@ public class ContrastPixelTest { ...@@ -122,7 +125,7 @@ public class ContrastPixelTest {
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.createArgb8888BitmapWithSolidColor( createArgb8888BitmapWithSolidColor(
inputWidth, inputWidth,
inputHeight, inputHeight,
Color.rgb( Color.rgb(
...@@ -130,14 +133,11 @@ public class ContrastPixelTest { ...@@ -130,14 +133,11 @@ public class ContrastPixelTest {
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0); contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -149,18 +149,15 @@ public class ContrastPixelTest { ...@@ -149,18 +149,15 @@ public class ContrastPixelTest {
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); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -172,18 +169,15 @@ public class ContrastPixelTest { ...@@ -172,18 +169,15 @@ public class ContrastPixelTest {
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); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -194,18 +188,15 @@ public class ContrastPixelTest { ...@@ -194,18 +188,15 @@ public class ContrastPixelTest {
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); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
......
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
package androidx.media3.effect; package androidx.media3.effect;
import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE; import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
import static androidx.media3.effect.BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer;
import static androidx.media3.effect.BitmapTestUtil.createGlTextureFromBitmap;
import static androidx.media3.effect.BitmapTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888;
import static androidx.media3.effect.BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory;
import static androidx.media3.effect.BitmapTestUtil.readBitmap;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
...@@ -68,12 +73,12 @@ public final class CropPixelTest { ...@@ -68,12 +73,12 @@ public final class CropPixelTest {
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.createEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap inputBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
inputWidth = inputBitmap.getWidth(); inputWidth = inputBitmap.getWidth();
inputHeight = inputBitmap.getHeight(); inputHeight = inputBitmap.getHeight();
placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay); placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay);
GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight); GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight);
inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@After @After
...@@ -94,19 +99,16 @@ public final class CropPixelTest { ...@@ -94,19 +99,16 @@ public final class CropPixelTest {
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -118,19 +120,16 @@ public final class CropPixelTest { ...@@ -118,19 +120,16 @@ public final class CropPixelTest {
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -142,19 +141,16 @@ public final class CropPixelTest { ...@@ -142,19 +141,16 @@ public final class CropPixelTest {
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
......
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
package androidx.media3.effect; package androidx.media3.effect;
import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE; import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
import static androidx.media3.effect.BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer;
import static androidx.media3.effect.BitmapTestUtil.createGlTextureFromBitmap;
import static androidx.media3.effect.BitmapTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888;
import static androidx.media3.effect.BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory;
import static androidx.media3.effect.BitmapTestUtil.readBitmap;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
...@@ -68,12 +73,12 @@ public final class MatrixTextureProcessorPixelTest { ...@@ -68,12 +73,12 @@ public final class MatrixTextureProcessorPixelTest {
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.createEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap inputBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
width = inputBitmap.getWidth(); width = inputBitmap.getWidth();
height = inputBitmap.getHeight(); height = inputBitmap.getHeight();
EGLSurface placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay); EGLSurface placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay);
GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, width, height); GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, width, height);
inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
outputTexId = GlUtil.createTexture(width, height, /* useHighPrecisionColorComponents= */ false); outputTexId = GlUtil.createTexture(width, height, /* useHighPrecisionColorComponents= */ false);
int frameBuffer = GlUtil.createFboForTexture(outputTexId); int frameBuffer = GlUtil.createFboForTexture(outputTexId);
GlUtil.focusFramebuffer( GlUtil.focusFramebuffer(
...@@ -98,18 +103,15 @@ public final class MatrixTextureProcessorPixelTest { ...@@ -98,18 +103,15 @@ public final class MatrixTextureProcessorPixelTest {
matrixTextureProcessor = matrixTextureProcessor =
noEditsTransformation.toGlTextureProcessor(context, /* useHdr= */ false); noEditsTransformation.toGlTextureProcessor(context, /* useHdr= */ false);
matrixTextureProcessor.configure(width, height); matrixTextureProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.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(width, height);
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -123,18 +125,15 @@ public final class MatrixTextureProcessorPixelTest { ...@@ -123,18 +125,15 @@ public final class MatrixTextureProcessorPixelTest {
matrixTextureProcessor = matrixTextureProcessor =
translateRightTransformation.toGlTextureProcessor(context, /* useHdr= */ false); translateRightTransformation.toGlTextureProcessor(context, /* useHdr= */ false);
matrixTextureProcessor.configure(width, height); matrixTextureProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH);
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -147,18 +146,15 @@ public final class MatrixTextureProcessorPixelTest { ...@@ -147,18 +146,15 @@ public final class MatrixTextureProcessorPixelTest {
matrixTextureProcessor = matrixTextureProcessor =
scaleNarrowTransformation.toGlTextureProcessor(context, /* useHdr= */ false); scaleNarrowTransformation.toGlTextureProcessor(context, /* useHdr= */ false);
matrixTextureProcessor.configure(width, height); matrixTextureProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(SCALE_NARROW_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(SCALE_NARROW_PNG_ASSET_PATH);
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -171,18 +167,15 @@ public final class MatrixTextureProcessorPixelTest { ...@@ -171,18 +167,15 @@ public final class MatrixTextureProcessorPixelTest {
matrixTextureProcessor = matrixTextureProcessor =
rotate90Transformation.toGlTextureProcessor(context, /* useHdr= */ false); rotate90Transformation.toGlTextureProcessor(context, /* useHdr= */ false);
matrixTextureProcessor.configure(width, height); matrixTextureProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ROTATE_90_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ROTATE_90_PNG_ASSET_PATH);
matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); matrixTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
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.
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
package androidx.media3.effect; package androidx.media3.effect;
import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE; import static androidx.media3.effect.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
import static androidx.media3.effect.BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer;
import static androidx.media3.effect.BitmapTestUtil.createGlTextureFromBitmap;
import static androidx.media3.effect.BitmapTestUtil.getBitmapAveragePixelAbsoluteDifferenceArgb8888;
import static androidx.media3.effect.BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory;
import static androidx.media3.effect.BitmapTestUtil.readBitmap;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
...@@ -69,12 +74,12 @@ public final class RgbFilterPixelTest { ...@@ -69,12 +74,12 @@ public final class RgbFilterPixelTest {
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.createEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap inputBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
inputWidth = inputBitmap.getWidth(); inputWidth = inputBitmap.getWidth();
inputHeight = inputBitmap.getHeight(); inputHeight = inputBitmap.getHeight();
placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay); placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay);
GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight); GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight);
inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
outputTexId = outputTexId =
GlUtil.createTexture(inputWidth, inputHeight, /* useHighPrecisionColorComponents= */ false); GlUtil.createTexture(inputWidth, inputHeight, /* useHighPrecisionColorComponents= */ false);
...@@ -102,18 +107,15 @@ public final class RgbFilterPixelTest { ...@@ -102,18 +107,15 @@ public final class RgbFilterPixelTest {
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); Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
...@@ -123,18 +125,15 @@ public final class RgbFilterPixelTest { ...@@ -123,18 +125,15 @@ public final class RgbFilterPixelTest {
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); Pair<Integer, Integer> outputSize = matrixTextureProcessor.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = BitmapTestUtil.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 =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.first, outputSize.second);
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
testId, /* bitmapLabel= */ "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888( getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment