Package com.banuba.sdk.internal.gl
Class GLOrientableTextureReader
java.lang.Object
com.banuba.sdk.internal.gl.GLFrameSurfaceHandler
com.banuba.sdk.internal.gl.GLOrientableTextureReader
- All Implemented Interfaces:
IOrientable
,Closeable
,AutoCloseable
public class GLOrientableTextureReader
extends GLFrameSurfaceHandler
implements IOrientable, Closeable
Helps to read from memory a rendered, on-demand OpenGL oriented and reflected texture,
in the requested format.
IMPORTANT:
For this class to work, you need to initialize OpenGL, create a context, create an instance of
this class in the OpenGL context.
-
Field Summary
Fields inherited from class com.banuba.sdk.internal.gl.GLFrameSurfaceHandler
SIMPLE_VERTEX_SHADER_PROGRAM
-
Constructor Summary
ConstructorDescriptionCreate a new instance of the GLOrientableTextureReaderGLOrientableTextureReader
(boolean usePBO) Create a new instance of the GLOrientableTextureReader -
Method Summary
Modifier and TypeMethodDescriptionstatic int
calculateMinBufferSize
(int width, int height, com.banuba.sdk.types.PixelFormat format) The method helps to calculate the minimum amount of memory required to store images with the specified dimensions and format (for BPC8 only)static int
calculateMinYuvBufferSize
(int width, int height) The method helps to calculate the minimum amount of memory required to store images with the specified dimensions (for YUV only)static int
calculateOffsetForPlane
(int width, int height, int planeNumber) The method calculates the offset for plane that were used to store the imagestatic int[]
calculateOffsets
(int width, int height) The method calculates the offsets for each plane that were used to store the imagestatic int
calculateStrideForPlane
(int width, int planeNumber) The method counts the strides that were used to store the imagestatic int[]
calculateStrides
(int width) The method calculates strides for all planes that were used to store the imagevoid
close()
Close used resourcesstatic boolean
Check for PBO supportedmapOrientedTextureData
(int inputTextureId, int width, int height) void
readOrientedTextureData
(int inputTextureId, int width, int height, ByteBuffer output) Render texture and read data in required format.void
setFormat
(com.banuba.sdk.effect_player.ColorStd std, com.banuba.sdk.effect_player.ColorRange rng) Set output image format as YUV withvoid
setFormat
(com.banuba.sdk.types.PixelFormat format) Set output image format as BPC8 withvoid
setOrientation
(Orientation orientation, boolean mirroring) Set output image orientationvoid
unmapPBO()
Methods inherited from class com.banuba.sdk.internal.gl.GLFrameSurfaceHandler
drawSurface
-
Constructor Details
-
GLOrientableTextureReader
public GLOrientableTextureReader()Create a new instance of the GLOrientableTextureReader -
GLOrientableTextureReader
public GLOrientableTextureReader(boolean usePBO) Create a new instance of the GLOrientableTextureReader- Parameters:
usePBO
- true if need to use PixelBufferObject. Allows to asynchronously read texture data from a buffer.
-
-
Method Details
-
isPBOSupported
@ChecksSdkIntAtLeast(api=24) public static boolean isPBOSupported()Check for PBO supported- Returns:
- true if PixelBufferObject is supported on this device
-
setFormat
public void setFormat(com.banuba.sdk.effect_player.ColorStd std, com.banuba.sdk.effect_player.ColorRange rng) Set output image format as YUV with- Parameters:
std
- color standard andrng
- color range
-
setFormat
public void setFormat(com.banuba.sdk.types.PixelFormat format) Set output image format as BPC8 with- Parameters:
format
- format of pixel (available only RGBA format)
-
setOrientation
Set output image orientation- Specified by:
setOrientation
in interfaceIOrientable
- Overrides:
setOrientation
in classGLFrameSurfaceHandler
- Parameters:
orientation
- output image rotationmirroring
- require mirroring
-
mapOrientedTextureData
-
unmapPBO
public void unmapPBO() -
readOrientedTextureData
public void readOrientedTextureData(int inputTextureId, int width, int height, @NonNull ByteBuffer output) Render texture and read data in required format.- Parameters:
inputTextureId
- OpenGL texture idwidth
- required width of the imageheight
- required height of the imageoutput
- image will saved to this buffer Memory layout for the YUV I420 'output' to get the minimum required memory size call function 'calculateMinBufferSize(width, height, std, rng)' representation in memory: +---------------+ | | | Y | | plane | | | +-------+-------+ | U | V | | plane | plane | +-------+-------+
-
close
public void close()Close used resources- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classGLFrameSurfaceHandler
-
calculateStrideForPlane
public static int calculateStrideForPlane(int width, int planeNumber) The method counts the strides that were used to store the image- Parameters:
width
- width of the image passed to the readOrientedTextureData(...) methodplaneNumber
- number of the plane- Returns:
- stride of the image
-
calculateOffsetForPlane
public static int calculateOffsetForPlane(int width, int height, int planeNumber) The method calculates the offset for plane that were used to store the image- Parameters:
width
- width of the image passed to the readOrientedTextureData(...) methodheight
- height of the image passed to the readOrientedTextureData(...) methodplaneNumber
- number of the plane- Returns:
- plane offset
-
calculateStrides
public static int[] calculateStrides(int width) The method calculates strides for all planes that were used to store the image- Parameters:
width
- width of the image passed to the readOrientedTextureData(...) method- Returns:
- array of strides for each plane
-
calculateOffsets
public static int[] calculateOffsets(int width, int height) The method calculates the offsets for each plane that were used to store the image- Parameters:
width
- width of the image passed to the readOrientedTextureData(...) methodheight
- height of the image passed to the readOrientedTextureData(...) method- Returns:
- array of foosets for each plane
-
calculateMinYuvBufferSize
public static int calculateMinYuvBufferSize(int width, int height) The method helps to calculate the minimum amount of memory required to store images with the specified dimensions (for YUV only)- Parameters:
width
- width of the image which will be pass to the readOrientedTextureData(...) methodheight
- height of the image which will be pass to the readOrientedTextureData(...) method- Returns:
- minimum required memory size in bytes
-
calculateMinBufferSize
public static int calculateMinBufferSize(int width, int height, com.banuba.sdk.types.PixelFormat format) The method helps to calculate the minimum amount of memory required to store images with the specified dimensions and format (for BPC8 only)- Parameters:
width
- width of the image which will be pass to the readOrientedTextureData(...) methodheight
- height of the image which will be pass to the readOrientedTextureData(...) methodformat
- format of pixel- Returns:
- minimum required memory size in bytes
-