Merge branch 'overlay-layout' into interactive-overlay

pull/421/head
Giacomo Randazzo 7 years ago
commit ed2c8534dd
  1. 12
      cameraview/src/main/gles/com/otaliastudios/cameraview/TextureMediaEncoder.java
  2. 22
      cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java

@ -116,12 +116,17 @@ class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.Config>
// We must scale this matrix like GlCameraPreview does, because it might have some cropping. // We must scale this matrix like GlCameraPreview does, because it might have some cropping.
// Scaling takes place with respect to the (0, 0, 0) point, so we must apply a Translation to compensate. // Scaling takes place with respect to the (0, 0, 0) point, so we must apply a Translation to compensate.
float[] transform = frame.transform; float[] transform = frame.transform;
float[] overlayTransform = frame.overlayTransform;
float scaleX = mConfig.scaleX; float scaleX = mConfig.scaleX;
float scaleY = mConfig.scaleY; float scaleY = mConfig.scaleY;
float scaleTranslX = (1F - scaleX) / 2F; float scaleTranslX = (1F - scaleX) / 2F;
float scaleTranslY = (1F - scaleY) / 2F; float scaleTranslY = (1F - scaleY) / 2F;
Matrix.translateM(transform, 0, scaleTranslX, scaleTranslY, 0); Matrix.translateM(transform, 0, scaleTranslX, scaleTranslY, 0);
Matrix.scaleM(transform, 0, scaleX, scaleY, 1); Matrix.scaleM(transform, 0, scaleX, scaleY, 1);
if (overlayTransform != null) {
Matrix.translateM(overlayTransform, 0, scaleTranslX, scaleTranslY, 0);
Matrix.scaleM(overlayTransform, 0, scaleX, scaleY, 1);
}
// We also must rotate this matrix. In GlCameraPreview it is not needed because it is a live // We also must rotate this matrix. In GlCameraPreview it is not needed because it is a live
// stream, but the output video, must be correctly rotated based on the device rotation at the moment. // stream, but the output video, must be correctly rotated based on the device rotation at the moment.
@ -131,11 +136,16 @@ class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.Config>
Matrix.translateM(transform, 0, 0.5F, 0.5F, 0); Matrix.translateM(transform, 0, 0.5F, 0.5F, 0);
Matrix.rotateM(transform, 0, mConfig.transformRotation, 0, 0, 1); Matrix.rotateM(transform, 0, mConfig.transformRotation, 0, 0, 1);
Matrix.translateM(transform, 0, -0.5F, -0.5F, 0); Matrix.translateM(transform, 0, -0.5F, -0.5F, 0);
if (overlayTransform != null) {
Matrix.translateM(overlayTransform, 0, 0.5F, 0.5F, 0);
Matrix.rotateM(overlayTransform, 0, mConfig.transformRotation, 0, 0, 1);
Matrix.translateM(overlayTransform, 0, -0.5F, -0.5F, 0);
}
drainOutput(false); drainOutput(false);
// Future note: passing scale values to the viewport? They are scaleX and scaleY, // Future note: passing scale values to the viewport? They are scaleX and scaleY,
// but flipped based on the mConfig.scaleFlipped boolean. // but flipped based on the mConfig.scaleFlipped boolean.
mViewport.drawFrame(mConfig.textureId, mConfig.overlayTextureId, transform, frame.overlayTransform); mViewport.drawFrame(mConfig.textureId, mConfig.overlayTextureId, transform, overlayTransform);
mWindow.setPresentationTime(frame.timestamp); mWindow.setPresentationTime(frame.timestamp);
mWindow.swapBuffers(); mWindow.swapBuffers();
mFramePool.recycle(frame); mFramePool.recycle(frame);

@ -136,26 +136,48 @@ class SnapshotPictureRecorder extends PictureRecorder {
float scaleTranslY = (1F - realScaleY) / 2F; float scaleTranslY = (1F - realScaleY) / 2F;
Matrix.translateM(mTransform, 0, scaleTranslX, scaleTranslY, 0); Matrix.translateM(mTransform, 0, scaleTranslX, scaleTranslY, 0);
Matrix.scaleM(mTransform, 0, realScaleX, realScaleY, 1); Matrix.scaleM(mTransform, 0, realScaleX, realScaleY, 1);
if (mOverlayTransform != null) {
Matrix.translateM(mOverlayTransform, 0, scaleTranslX, scaleTranslY, 0);
Matrix.scaleM(mOverlayTransform, 0, realScaleX, realScaleY, 1);
}
// Fix rotation: // Fix rotation:
// TODO Not sure why we need the minus here... It makes no sense to me. // TODO Not sure why we need the minus here... It makes no sense to me.
LOG.w("Recording frame. Rotation:", mResult.rotation, "Actual:", -mResult.rotation); LOG.w("Recording frame. Rotation:", mResult.rotation, "Actual:", -mResult.rotation);
int rotation = -mResult.rotation; int rotation = -mResult.rotation;
int overlayRotation = -mController.offset(CameraController.REF_VIEW, CameraController.REF_OUTPUT);
// apparently with front facing camera with don't need the minus sign
if (mResult.facing == Facing.FRONT) {
overlayRotation = -overlayRotation;
}
mResult.rotation = 0; mResult.rotation = 0;
// Go back to 0,0 so that rotate and flip work well. // Go back to 0,0 so that rotate and flip work well.
Matrix.translateM(mTransform, 0, 0.5F, 0.5F, 0); Matrix.translateM(mTransform, 0, 0.5F, 0.5F, 0);
if (mOverlayTransform != null) {
Matrix.translateM(mOverlayTransform, 0, 0.5F, 0.5F, 0);
}
// Apply rotation: // Apply rotation:
Matrix.rotateM(mTransform, 0, rotation, 0, 0, 1); Matrix.rotateM(mTransform, 0, rotation, 0, 0, 1);
if (mOverlayTransform != null) {
Matrix.rotateM(mOverlayTransform, 0, overlayRotation, 0, 0, 1);
}
// Flip horizontally for front camera: // Flip horizontally for front camera:
if (mResult.facing == Facing.FRONT) { if (mResult.facing == Facing.FRONT) {
Matrix.scaleM(mTransform, 0, -1, 1, 1); Matrix.scaleM(mTransform, 0, -1, 1, 1);
if (mOverlayTransform != null) {
// not sure why we have to flip the mirror the y axis
Matrix.scaleM(mOverlayTransform, 0, -1, -1, 1);
}
} }
// Go back to old position. // Go back to old position.
Matrix.translateM(mTransform, 0, -0.5F, -0.5F, 0); Matrix.translateM(mTransform, 0, -0.5F, -0.5F, 0);
if (mOverlayTransform != null) {
Matrix.translateM(mOverlayTransform, 0, -0.5F, -0.5F, 0);
}
// Future note: passing scale values to the viewport? // Future note: passing scale values to the viewport?
// They are simply realScaleX and realScaleY. // They are simply realScaleX and realScaleY.

Loading…
Cancel
Save