Class BitmapPixelTestUtil
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.BitmapPixelTestUtil
-
public class BitmapPixelTestUtil extends Object
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 aBitmap.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 solidBitmap
with every pixel having the same color.static Bitmap
createFp16BitmapFromCurrentGlFramebuffer(int width, int height)
Creates aBitmap.Config.RGBA_F16
bitmap with the values of the current OpenGL framebuffer.static int
createGlTextureFromBitmap(Bitmap bitmap)
Creates a2-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 theBitmap
as a PNG to the<path>
, and if not provided, tries to save to thecache directory
.static Bitmap
readBitmap(String assetString)
Reads a bitmap from the specified asset location.
-
-
-
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 readBitmap(String assetString) throws IOException
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 createArgb8888BitmapFromRgba8888Image(Image image)
Returns a bitmap with the same information as the provided alpha/red/green/blue 8-bits per component image.
-
createArgb8888BitmapWithSolidColor
public static Bitmap createArgb8888BitmapWithSolidColor(int width, int height, int color)
Returns a solidBitmap
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 byColor
.
-
getBitmapAveragePixelAbsoluteDifferenceArgb8888
public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888(Bitmap expected, Bitmap actual, @Nullable String testId, @Nullable String 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 expectedBitmap
.actual
- The actualBitmap
produced by the test.testId
- The name of the test that produced theBitmap
, ornull
if the differences bitmap should not be saved to cache.differencesBitmapPath
- Folder path for the produced pixel-wise differenceBitmap
to be saved in ornull
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 expected, Bitmap 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
.
-
getBitmapAveragePixelAbsoluteDifferenceArgb8888
public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888(Bitmap expected, Bitmap actual, @Nullable 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. SeegetBitmapAveragePixelAbsoluteDifferenceArgb8888(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 testId, String bitmapLabel, Bitmap bitmap, @Nullable String path)
Tries to save theBitmap
as a PNG to the<path>
, and if not provided, tries to save to thecache directory
.File name will be
<testId>_<bitmapLabel>.png
. If the file failed to write, anyIOException
will be caught and logged.- Parameters:
testId
- Name of the test that produced theBitmap
.bitmapLabel
- Label to identify the bitmap.bitmap
- TheBitmap
to save.path
- Folder path for the suppliedBitmap
to be saved in ornull
if thecache directory
should be saved in.
-
createArgb8888BitmapFromCurrentGlFramebuffer
public static Bitmap createArgb8888BitmapFromCurrentGlFramebuffer(int width, int height) throws GlUtil.GlException
Creates aBitmap.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 createFp16BitmapFromCurrentGlFramebuffer(int width, int height) throws GlUtil.GlException
Creates aBitmap.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 bitmap) throws GlUtil.GlException
Creates a2-dimensional OpenGL texture
with the bitmap's contents.- Parameters:
bitmap
- ABitmap
.- Returns:
- The identifier of the newly created texture.
- Throws:
GlUtil.GlException
-
-