Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the return value of SurfaceTexture.getTransformMatrix mean, who can explain?

Everyone,

I am working with SurfaceTexture in Android but I am not able to understand Its API: getTransformMatrix(float[] mtx), the API doc is as follows:

/**
 * Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by
 * the most recent call to updateTexImage.
 *
 * This transform matrix maps 2D homogeneous texture coordinates of the form (s, t, 0, 1) with s
 * and t in the inclusive range [0, 1] to the texture coordinate that should be used to sample
 * that location from the texture.  Sampling the texture outside of the range of this transform
 * is undefined.
 *
 * The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via
 * the glLoadMatrixf or glUniformMatrix4fv functions.
 *
 * @param mtx the array into which the 4x4 matrix will be stored.  The array must have exactly
 *     16 elements.
 */

After reading it, I really don't know how to use it. I want to crop texture image in SurfaceTexture and provide the SurfaceTexture obj to a EGLSurface object.

For example, the original image is 320*720(w*h) and I expect the new image to be 320*240(w*h)

What should I do in order to achieve this function? Can the 4*4 matrix help me? What should I do with the 4*4 matrix?

like image 396
dragonfly Avatar asked Jun 02 '15 12:06

dragonfly


1 Answers

It's a GLES-compatible transformation matrix that may be used to rotate or flip an image. Generally speaking you just pass it through to whatever is going to render the GLES texture that SurfaceTexture creates.

You can see examples of it used in Grafika; search for it in ContinuousCaptureActivity.java, CameraCaptureActivity.java, and TextureMovieEncoder.java.

The matrix can be used to perform various affine transformations, such as rotation and scaling, but cannot be used to clip an image.

The matrix is included in the API because there are times when the input source is in the "wrong" orientation. Rather than spending CPU or GPU cycles to rearrange the pixels, the system just sends a matrix along with each frame. If the frame contents are correct as-is, the matrix will be identity. If it's upside-down, a matrix with an appropriate correction will be provided.

like image 183
fadden Avatar answered Oct 26 '22 22:10

fadden