Adjust surface aspect ratio

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent f369302ae4
commit c6150ad655

@ -38,6 +38,8 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
private int mSurfaceHeight; private int mSurfaceHeight;
private int mPreviewWidth; private int mPreviewWidth;
private int mPreviewHeight; private int mPreviewHeight;
private float mInputAspectRatio;
private float mOutputAspectRatio;
private float[] mProjectionMatrix = new float[16]; private float[] mProjectionMatrix = new float[16];
private float[] mSurfaceMatrix = new float[16]; private float[] mSurfaceMatrix = new float[16];
private float[] mTransformMatrix = new float[16]; private float[] mTransformMatrix = new float[16];
@ -100,6 +102,14 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
mSurfaceWidth = width; mSurfaceWidth = width;
mSurfaceHeight = height; mSurfaceHeight = height;
magicFilter.onDisplaySizeChanged(width, height); magicFilter.onDisplaySizeChanged(width, height);
mOutputAspectRatio = width > height ? (float) width / height : (float) height / width;
float aspectRatio = mOutputAspectRatio / mInputAspectRatio;
if (width > height) {
Matrix.orthoM(mProjectionMatrix, 0, -1.0f, 1.0f, -aspectRatio, aspectRatio, -1.0f, 1.0f);
} else {
Matrix.orthoM(mProjectionMatrix, 0, -aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
}
} }
@Override @Override
@ -112,6 +122,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
surfaceTexture.getTransformMatrix(mSurfaceMatrix); surfaceTexture.getTransformMatrix(mSurfaceMatrix);
Matrix.multiplyMM(mTransformMatrix, 0, mSurfaceMatrix, 0, mProjectionMatrix, 0); Matrix.multiplyMM(mTransformMatrix, 0, mSurfaceMatrix, 0, mProjectionMatrix, 0);
magicFilter.setTextureTransformMatrix(mTransformMatrix); magicFilter.setTextureTransformMatrix(mTransformMatrix);
magicFilter.onDrawFrame(mOESTextureId); magicFilter.onDrawFrame(mOESTextureId);
mGLIntBufferCache.add(magicFilter.getGLFboBuffer()); mGLIntBufferCache.add(magicFilter.getGLFboBuffer());
synchronized (writeLock) { synchronized (writeLock) {
@ -127,13 +138,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
mPreviewWidth = width; mPreviewWidth = width;
mPreviewHeight = height; mPreviewHeight = height;
mGlPreviewBuffer = ByteBuffer.allocate(mPreviewWidth * mPreviewHeight * 4); mGlPreviewBuffer = ByteBuffer.allocate(mPreviewWidth * mPreviewHeight * 4);
mInputAspectRatio = width > height ? (float) width / height : (float) height / width;
float aspectRatio = width > height ? (float) width / (float) height : (float) height / (float) width;
if (width > height) {
Matrix.orthoM(mProjectionMatrix, 0, -aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
} else {
Matrix.orthoM(mProjectionMatrix, 0, -1.0f, 1.0f, -aspectRatio, aspectRatio, -1.0f, 1.0f);
}
} }
public boolean setFilter(final MagicFilterType type) { public boolean setFilter(final MagicFilterType type) {

Loading…
Cancel
Save