Android camera: Replace custom matrix operations with android.opengl.Matrix

Bug: webrtc:9412, webrtc:9487
Change-Id: I68e5a03026b1ab8236a05ece79690d4a8755c093
Reviewed-on: https://webrtc-review.googlesource.com/86947
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23851}
This commit is contained in:
Magnus Jedvert
2018-07-05 13:34:17 +02:00
committed by Commit Bot
parent 918f50c5d1
commit 783c6e3a72
6 changed files with 86 additions and 85 deletions

View File

@ -84,15 +84,27 @@ public class TextureBufferImpl implements VideoFrame.TextureBuffer {
@Override
public VideoFrame.Buffer cropAndScale(
int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) {
final Matrix newMatrix = new Matrix(transformMatrix);
final Matrix cropAndScaleMatrix = new Matrix();
// In WebRTC, Y=0 is the top row, while in OpenGL Y=0 is the bottom row. This means that the Y
// direction is effectively reversed.
final int cropYFromBottom = height - (cropY + cropHeight);
newMatrix.preTranslate(cropX / (float) width, cropYFromBottom / (float) height);
newMatrix.preScale(cropWidth / (float) width, cropHeight / (float) height);
cropAndScaleMatrix.preTranslate(cropX / (float) width, cropYFromBottom / (float) height);
cropAndScaleMatrix.preScale(cropWidth / (float) width, cropHeight / (float) height);
return applyTransformMatrix(cropAndScaleMatrix, scaleWidth, scaleHeight);
}
/**
* Create a new TextureBufferImpl with an applied transform matrix and a new size. The
* existing buffer is unchanged. The given transform matrix is applied first when texture
* coordinates are still in the unmodified [0, 1] range.
*/
public TextureBufferImpl applyTransformMatrix(
Matrix transformMatrix, int newWidth, int newHeight) {
final Matrix newMatrix = new Matrix(this.transformMatrix);
newMatrix.preConcat(transformMatrix);
retain();
return new TextureBufferImpl(
scaleWidth, scaleHeight, type, id, newMatrix, toI420Handler, yuvConverter, this ::release);
newWidth, newHeight, type, id, newMatrix, toI420Handler, yuvConverter, this ::release);
}
}