Class 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.
    • 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 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()
      Close used resources
      static boolean isPBOSupported()
      Check for PBO supported
      java.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 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 unmapPBO()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 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)
      • 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 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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.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