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

    Constructors
    Constructor
    Description
    Create a new instance of the GLOrientableTextureReader
    GLOrientableTextureReader(boolean usePBO)
    Create a new instance of the GLOrientableTextureReader
  • Method Summary

    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 image
    static int[]
    calculateOffsets(int width, int height)
    The method calculates the offsets for each plane that were used to store the image
    static int
    calculateStrideForPlane(int width, int planeNumber)
    The method counts the strides that were used to store the image
    static int[]
    calculateStrides(int width)
    The method calculates strides for all planes that were used to store the image
    void
    Close used resources
    static boolean
    Check for PBO supported
    mapOrientedTextureData(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 with
    void
    setFormat(com.banuba.sdk.types.PixelFormat format)
    Set output image format as BPC8 with
    void
    setOrientation(Orientation orientation, boolean mirroring)
    Set output image orientation
    void
     

    Methods inherited from class com.banuba.sdk.internal.gl.GLFrameSurfaceHandler

    drawSurface

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 and
      rng - 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 interface IOrientable
      Overrides:
      setOrientation in class GLFrameSurfaceHandler
      Parameters:
      orientation - output image rotation
      mirroring - require mirroring
    • mapOrientedTextureData

      public ByteBuffer mapOrientedTextureData(int inputTextureId, int width, int height)
    • 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 id
      width - required width of the image
      height - required height of the image
      output - 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 interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class GLFrameSurfaceHandler
    • 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(...) method
      planeNumber - 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(...) method
      height - height of the image passed to the readOrientedTextureData(...) method
      planeNumber - 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(...) method
      height - 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(...) method
      height - 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(...) method
      height - height of the image which will be pass to the readOrientedTextureData(...) method
      format - format of pixel
      Returns:
      minimum required memory size in bytes