Back to Exoplayer

BitmapPixelTestUtil (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/testutil/BitmapPixelTestUtil.html

latest19.7 KB
Original Source

Package com.google.android.exoplayer2.testutil

Class BitmapPixelTestUtil


public classBitmapPixelTestUtilextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")

Utilities for pixel tests.

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static float | MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE | Maximum allowed average pixel difference between bitmaps generated using emulators. | | static float | MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE | Maximum allowed average pixel difference between bitmaps generated using devices. | | static float | MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16 | Maximum allowed average pixel difference between bitmaps with 16-bit primaries generated using devices. |

Method Summary

All Methods Static Methods Concrete Methods | Modifier and Type | Method | Description | | --- | --- | --- | | static Bitmap | createArgb8888BitmapFromCurrentGlFramebuffer​(int width, int height) | Creates a Bitmap.Config.ARGB_8888 bitmap with the values of the current OpenGL framebuffer. | | static Bitmap | createArgb8888BitmapFromRgba8888Image​(Image image) | Returns a bitmap with the same information as the provided alpha/red/green/blue 8-bits per component image. | | static Bitmap | createArgb8888BitmapWithSolidColor​(int width, int height, int color) | Returns a solid Bitmap with every pixel having the same color. | | static Bitmap | createFp16BitmapFromCurrentGlFramebuffer​(int width, int height) | Creates a Bitmap.Config.RGBA_F16 bitmap with the values of the current OpenGL framebuffer. | | static int | createGlTextureFromBitmap​(Bitmap bitmap) | Creates a 2-dimensional OpenGL texture with the bitmap's contents. | | static Bitmap | flipBitmapVertically​(Bitmap bitmap) | | | static float | getBitmapAveragePixelAbsoluteDifferenceArgb8888​(Bitmap expected, Bitmap actual, String testId) | Returns the average difference between the expected and actual bitmaps, calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image, without saving the difference bitmap. | | static float | getBitmapAveragePixelAbsoluteDifferenceArgb8888​(Bitmap expected, Bitmap actual, String testId, String differencesBitmapPath) | Returns the average difference between the expected and actual bitmaps. | | static float | getBitmapAveragePixelAbsoluteDifferenceFp16​(Bitmap expected, Bitmap actual) | Returns the average difference between the expected and actual bitmaps. | | static void | maybeSaveTestBitmap​(String testId, String bitmapLabel, Bitmap bitmap, String path) | Tries to save the Bitmap as a PNG to the <path>, and if not provided, tries to save to the cache directory. | | static Bitmap | readBitmap​(String assetString) | Reads a bitmap from the specified asset location. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

- 

MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE

public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE

Maximum allowed average pixel difference between bitmaps generated using emulators.

This value is for for 8-bit primaries in pixel difference-based tests.

The value is chosen so that differences in decoder behavior across emulator versions don't affect whether the test passes, but substantial distortions introduced by changes in tested components will cause the test to fail.

When the difference is close to the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible this is caused by a difference in the codec or graphics implementation as opposed to an issue in the tested component.

See Also:Constant Field Values

- 

MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE

public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE

Maximum allowed average pixel difference between bitmaps generated using devices.

This value is for for 8-bit primaries in pixel difference-based tests.

The value is chosen so that differences in decoder behavior across devices don't affect whether the test passes, but substantial distortions introduced by changes in tested components will cause the test to fail.

When the difference is close to the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible this is caused by a difference in the codec or graphics implementation as opposed to an issue in the tested component.

This value is larger than MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE to support the larger variance in decoder outputs between different physical devices and emulators.

- 

MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16

public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16

Maximum allowed average pixel difference between bitmaps with 16-bit primaries generated using devices.

The value is chosen so that differences in decoder behavior across devices in pixel difference-based tests don't affect whether the test passes, but substantial distortions introduced by changes in tested components will cause the test to fail.

When the difference is close to the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible this is caused by a difference in the codec or graphics implementation as opposed to an issue in the tested component.

This value is larger than MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE to support the larger variance in decoder outputs between different physical devices and emulators.

See Also:Constant Field Values

Method Detail

- 

readBitmap

public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")readBitmap​([String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")assetString)
                         throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")

Reads a bitmap from the specified asset location. Parameters:assetString - Relative path to the asset within the assets directory.Returns:A Bitmap.Throws:IOException - If the bitmap can't be read.

- 

createArgb8888BitmapFromRgba8888Image

@RequiresApi(19)
public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")createArgb8888BitmapFromRgba8888Image​([Image](https://developer.android.com/reference/android/media/Image.html?is-external=true "class or interface in android.media")image)

Returns a bitmap with the same information as the provided alpha/red/green/blue 8-bits per component image.

- 

createArgb8888BitmapWithSolidColor

public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")createArgb8888BitmapWithSolidColor​(int width,
                                                        int height,
                                                        int color)

Returns a solid Bitmap with every pixel having the same color. Parameters:width - The width of image to create, in pixels.height - The height of image to create, in pixels.color - An RGBA color created by Color.

- 

getBitmapAveragePixelAbsoluteDifferenceArgb8888

public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888​([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")expected,[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")actual,
                                                                    @Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")testId,
                                                                    @Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")differencesBitmapPath)

Returns the average difference between the expected and actual bitmaps.

Calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image. Bitmap resolutions must match and must use configuration Bitmap.Config.ARGB_8888.

Tries to save a difference bitmap between expected and actual bitmaps.

Parameters:expected - The expected Bitmap.actual - The actual Bitmap produced by the test.testId - The name of the test that produced the Bitmap, or null if the differences bitmap should not be saved to cache.differencesBitmapPath - Folder path for the produced pixel-wise difference Bitmap to be saved in or null if the assumed default save path should be used.Returns:The average of the maximum absolute pixel-wise differences between the expected and actual bitmaps.

- 

getBitmapAveragePixelAbsoluteDifferenceFp16

@RequiresApi(29)
public static float getBitmapAveragePixelAbsoluteDifferenceFp16​([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")expected,[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")actual)

Returns the average difference between the expected and actual bitmaps.

Calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image. Bitmap resolutions must match and must use configuration Bitmap.Config.RGBA_F16.

Parameters:expected - The expected Bitmap.actual - The actual Bitmap produced by the test.Returns:The average of the maximum absolute pixel-wise differences between the expected and actual bitmaps.

- 

getBitmapAveragePixelAbsoluteDifferenceArgb8888

public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888​([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")expected,[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")actual,
                                                                    @Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")testId)

Returns the average difference between the expected and actual bitmaps, calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image, without saving the difference bitmap. See getBitmapAveragePixelAbsoluteDifferenceArgb8888(Bitmap, Bitmap, String, String).

This method is the overloaded version of getBitmapAveragePixelAbsoluteDifferenceArgb8888(Bitmap, Bitmap, String, String) without a specified saved path.

- 

maybeSaveTestBitmap

public static void maybeSaveTestBitmap​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")testId,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")bitmapLabel,[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")bitmap,
                                       @Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")path)

Tries to save the Bitmap as a PNG to the <path>, and if not provided, tries to save to the cache directory.

File name will be <testId>_<bitmapLabel>.png. If the file failed to write, any IOException will be caught and logged.

Parameters:testId - Name of the test that produced the Bitmap.bitmapLabel - Label to identify the bitmap.bitmap - The Bitmap to save.path - Folder path for the supplied Bitmap to be saved in or null if the cache directory should be saved in.

- 

createArgb8888BitmapFromCurrentGlFramebuffer

public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")createArgb8888BitmapFromCurrentGlFramebuffer​(int width,
                                                                  int height)
                                                           throws[GlUtil.GlException](../util/GlUtil.GlException.html "class in com.google.android.exoplayer2.util")

Creates a Bitmap.Config.ARGB_8888 bitmap with the values of the current OpenGL framebuffer.

This method may block until any previously called OpenGL commands are complete.

Parameters:width - The width of the pixel rectangle to read.height - The height of the pixel rectangle to read.Returns:A Bitmap with the framebuffer's values.Throws:GlUtil.GlException

- 

createFp16BitmapFromCurrentGlFramebuffer

@RequiresApi(26)
public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")createFp16BitmapFromCurrentGlFramebuffer​(int width,
                                                              int height)
                                                       throws[GlUtil.GlException](../util/GlUtil.GlException.html "class in com.google.android.exoplayer2.util")

Creates a Bitmap.Config.RGBA_F16 bitmap with the values of the current OpenGL framebuffer.

This method may block until any previously called OpenGL commands are complete.

Parameters:width - The width of the pixel rectangle to read.height - The height of the pixel rectangle to read.Returns:A Bitmap with the framebuffer's values.Throws:GlUtil.GlException

- 

createGlTextureFromBitmap

public static int createGlTextureFromBitmap​([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")bitmap)
                                     throws[GlUtil.GlException](../util/GlUtil.GlException.html "class in com.google.android.exoplayer2.util")

Creates a 2-dimensional OpenGL texture with the bitmap's contents. Parameters:bitmap - A Bitmap.Returns:The identifier of the newly created texture.Throws:GlUtil.GlException

- 

flipBitmapVertically

public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")flipBitmapVertically​([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html?is-external=true "class or interface in android.graphics")bitmap)