diff --git a/MIGRATION.md b/MIGRATION.md index 14fce068..cfebca10 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -32,4 +32,4 @@ - VideoSizeSelector: added. It is needed to choose the capture size in VIDEO mode. Defaults to SizeSelectors.biggest(), but you can choose by aspect ratio or whatever. - isTakingPicture(): added on top of isTakingVideo(). - \ No newline at end of file + \ No newline at end of file diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java index add6698f..462742a4 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java @@ -216,6 +216,7 @@ public class CameraViewCallbacksTest extends BaseTest { verify(listener, times(1)).onCameraError(error); } + @Test public void testProcessFrame() { Frame mock = mock(Frame.class); completeTask().when(processor).process(mock); diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/YuvHelperTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/YuvHelperTest.java new file mode 100644 index 00000000..0bdc0030 --- /dev/null +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/YuvHelperTest.java @@ -0,0 +1,64 @@ +package com.otaliastudios.cameraview; + + +import android.content.Context; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.graphics.Rect; +import android.graphics.YuvImage; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class YuvHelperTest extends BaseTest { + + @Test + public void testCrop() { + testCrop(new Size(1600, 1600), AspectRatio.of(16, 16)); + testCrop(new Size(1600, 1600), AspectRatio.of(16, 9)); + testCrop(new Size(1600, 1600), AspectRatio.of(9, 16)); + } + + private void testCrop(final Size inSize, final AspectRatio outRatio) { + AspectRatio inRatio = AspectRatio.of(inSize.getWidth(), inSize.getHeight()); + Rect out = YuvHelper.computeCrop(inSize, outRatio); + Size outSize = new Size(out.width(), out.height()); + assertTrue(outRatio.matches(outSize)); + + if (outRatio.matches(inSize)) { + // They are equal. + assertEquals(outSize.getWidth(), inSize.getWidth()); + assertEquals(outSize.getHeight(), inSize.getHeight()); + } else if (outRatio.toFloat() > inRatio.toFloat()) { + // Width must match. + assertEquals(outSize.getWidth(), inSize.getWidth()); + assertNotEquals(outSize.getHeight(), inSize.getHeight()); + } else { + // Height must match. + assertEquals(outSize.getHeight(), inSize.getHeight()); + assertNotEquals(outSize.getWidth(), inSize.getWidth()); + } + } + +} diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java index b65fc9b8..e88650db 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java @@ -87,7 +87,6 @@ class Camera2 extends CameraController { @Override void takePictureSnapshot(AspectRatio viewAspectRatio) { - } @Override