Flip snapshots, add PictureResult.getFacing and VideoResult.getFacing (#360)

* Flip snapshots, add PictureResult.getFacing and VideoResult.getFacing

* Adapt codecov for v2
pull/361/head
Mattia Iavarone 6 years ago committed by GitHub
parent a8a4e09900
commit 894ac46bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/PictureResultTest.java
  2. 4
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java
  3. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  4. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/PictureResult.java
  5. 13
      cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java
  6. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java
  7. 4
      codecov.yml

@ -27,12 +27,14 @@ public class PictureResultTest extends BaseTest {
byte[] jpeg = new byte[]{2, 4, 1, 5, 2}; byte[] jpeg = new byte[]{2, 4, 1, 5, 2};
Location location = Mockito.mock(Location.class); Location location = Mockito.mock(Location.class);
boolean isSnapshot = true; boolean isSnapshot = true;
Facing facing = Facing.FRONT;
result. format = format; result. format = format;
result.rotation = rotation; result.rotation = rotation;
result.size = size; result.size = size;
result.data = jpeg; result.data = jpeg;
result.location = location; result.location = location;
result.facing = facing;
//noinspection ConstantConditions //noinspection ConstantConditions
result.isSnapshot = isSnapshot; result.isSnapshot = isSnapshot;
@ -43,5 +45,6 @@ public class PictureResultTest extends BaseTest {
assertEquals(result.getLocation(), location); assertEquals(result.getLocation(), location);
//noinspection ConstantConditions //noinspection ConstantConditions
assertEquals(result.isSnapshot(), isSnapshot); assertEquals(result.isSnapshot(), isSnapshot);
assertEquals(result.getFacing(), facing);
} }
} }

@ -36,6 +36,7 @@ public class VideoResultTest extends BaseTest {
int videoBitRate = 300000; int videoBitRate = 300000;
int audioBitRate = 30000; int audioBitRate = 30000;
Audio audio = Audio.ON; Audio audio = Audio.ON;
Facing facing = Facing.FRONT;
result.file = file; result.file = file;
result.rotation = rotation; result.rotation = rotation;
@ -50,6 +51,7 @@ public class VideoResultTest extends BaseTest {
result.videoBitRate = videoBitRate; result.videoBitRate = videoBitRate;
result.audioBitRate = audioBitRate; result.audioBitRate = audioBitRate;
result.audio = audio; result.audio = audio;
result.facing = facing;
assertEquals(result.getFile(), file); assertEquals(result.getFile(), file);
assertEquals(result.getRotation(), rotation); assertEquals(result.getRotation(), rotation);
@ -64,5 +66,7 @@ public class VideoResultTest extends BaseTest {
assertEquals(result.getVideoBitRate(), videoBitRate); assertEquals(result.getVideoBitRate(), videoBitRate);
assertEquals(result.getAudioBitRate(), audioBitRate); assertEquals(result.getAudioBitRate(), audioBitRate);
assertEquals(result.getAudio(), audio); assertEquals(result.getAudio(), audio);
assertEquals(result.getFacing(), facing);
} }
} }

@ -554,6 +554,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
result.location = mLocation; result.location = mLocation;
result.rotation = offset(REF_SENSOR, REF_OUTPUT); result.rotation = offset(REF_SENSOR, REF_OUTPUT);
result.size = getPictureSize(REF_OUTPUT); result.size = getPictureSize(REF_OUTPUT);
result.facing = mFacing;
mPictureRecorder = new FullPictureRecorder(result, Camera1.this, mCamera); mPictureRecorder = new FullPictureRecorder(result, Camera1.this, mCamera);
mPictureRecorder.take(); mPictureRecorder.take();
} }
@ -573,6 +574,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
PictureResult result = new PictureResult(); PictureResult result = new PictureResult();
result.location = mLocation; result.location = mLocation;
result.isSnapshot = true; result.isSnapshot = true;
result.facing = mFacing;
result.size = getPreviewSize(REF_OUTPUT); // Not the real size: it will be cropped to match the view ratio result.size = getPreviewSize(REF_OUTPUT); // Not the real size: it will be cropped to match the view ratio
result.rotation = offset(REF_SENSOR, REF_OUTPUT); // Actually it will be rotated and set to 0. result.rotation = offset(REF_SENSOR, REF_OUTPUT); // Actually it will be rotated and set to 0.
AspectRatio outputRatio = flip(REF_OUTPUT, REF_VIEW) ? viewAspectRatio.inverse() : viewAspectRatio; AspectRatio outputRatio = flip(REF_OUTPUT, REF_VIEW) ? viewAspectRatio.inverse() : viewAspectRatio;
@ -653,6 +655,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
videoResult.isSnapshot = false; videoResult.isSnapshot = false;
videoResult.codec = mVideoCodec; videoResult.codec = mVideoCodec;
videoResult.location = mLocation; videoResult.location = mLocation;
videoResult.facing = mFacing;
videoResult.rotation = offset(REF_SENSOR, REF_OUTPUT); videoResult.rotation = offset(REF_SENSOR, REF_OUTPUT);
videoResult.size = flip(REF_SENSOR, REF_OUTPUT) ? mCaptureSize.flip() : mCaptureSize; videoResult.size = flip(REF_SENSOR, REF_OUTPUT) ? mCaptureSize.flip() : mCaptureSize;
videoResult.audio = mAudio; videoResult.audio = mAudio;
@ -697,6 +700,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
videoResult.isSnapshot = true; videoResult.isSnapshot = true;
videoResult.codec = mVideoCodec; videoResult.codec = mVideoCodec;
videoResult.location = mLocation; videoResult.location = mLocation;
videoResult.facing = mFacing;
videoResult.videoBitRate = mVideoBitRate; videoResult.videoBitRate = mVideoBitRate;
videoResult.audioBitRate = mAudioBitRate; videoResult.audioBitRate = mAudioBitRate;
videoResult.audio = mAudio; videoResult.audio = mAudio;

@ -21,6 +21,7 @@ public class PictureResult {
Location location; Location location;
int rotation; int rotation;
Size size; Size size;
Facing facing;
byte[] data; byte[] data;
int format; int format;
@ -67,6 +68,16 @@ public class PictureResult {
return size; return size;
} }
/**
* Returns the facing value with which this video was recorded.
*
* @return the Facing of this video
*/
@NonNull
public Facing getFacing() {
return facing;
}
/** /**
* Returns the raw compressed, ready to be saved to file, * Returns the raw compressed, ready to be saved to file,
* in the given format. * in the given format.

@ -113,13 +113,24 @@ class SnapshotPictureRecorder extends PictureRecorder {
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);
// Apply 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;
mResult.rotation = 0; mResult.rotation = 0;
// 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);
// Apply rotation:
Matrix.rotateM(mTransform, 0, rotation, 0, 0, 1); Matrix.rotateM(mTransform, 0, rotation, 0, 0, 1);
// Flip horizontally for front camera:
if (mResult.facing == Facing.FRONT) {
Matrix.scaleM(mTransform, 0, -1, 1, 1);
}
// Go back to old position.
Matrix.translateM(mTransform, 0, -0.5F, -0.5F, 0); Matrix.translateM(mTransform, 0, -0.5F, -0.5F, 0);
// Future note: passing scale values to the viewport? // Future note: passing scale values to the viewport?

@ -25,6 +25,7 @@ public class VideoResult {
int rotation; int rotation;
Size size; Size size;
File file; File file;
Facing facing;
VideoCodec codec; VideoCodec codec;
Audio audio; Audio audio;
long maxSize; long maxSize;
@ -87,6 +88,16 @@ public class VideoResult {
return file; return file;
} }
/**
* Returns the facing value with which this video was recorded.
*
* @return the Facing of this video
*/
@NonNull
public Facing getFacing() {
return facing;
}
/** /**
* Returns the codec that was used to encode the video frames. * Returns the codec that was used to encode the video frames.
* *

@ -1,12 +1,12 @@
coverage: coverage:
precision: 1 precision: 1
round: down round: down
range: "40...100" range: "30...70"
status: status:
project: project:
default: default:
target: 45% target: 40%
patch: patch:
default: default:
target: 70% target: 70%

Loading…
Cancel
Save