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
,java.io.Closeable
,java.lang.AutoCloseable
public class GLOrientableTextureReader extends GLFrameSurfaceHandler implements IOrientable, java.io.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
Constructors Constructor Description GLOrientableTextureReader()
Create a new instance of the GLOrientableTextureReaderGLOrientableTextureReader(boolean usePBO)
Create a new instance of the GLOrientableTextureReader
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)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
isPBOSupported()
Check for PBO supportedjava.nio.ByteBuffer
mapOrientedTextureData(int inputTextureId, int width, int height)
void
readOrientedTextureData(int inputTextureId, int width, int height, java.nio.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 Detail
-
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 Detail
-
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
public void setOrientation(Orientation orientation, boolean mirroring)
Set output image orientation- Specified by:
setOrientation
in interfaceIOrientable
- Overrides:
setOrientation
in classGLFrameSurfaceHandler
- Parameters:
orientation
- output image rotationmirroring
- require mirroring
-
mapOrientedTextureData
public java.nio.ByteBuffer mapOrientedTextureData(int inputTextureId, int width, int height)
-
unmapPBO
public void unmapPBO()
-
readOrientedTextureData
public void readOrientedTextureData(int inputTextureId, int width, int height, @NonNull java.nio.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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- 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
-
-