Flip sizes before passing to selectors

pull/99/head
Mattia Iavarone 8 years ago
parent 08889d59ac
commit 135423f974
  1. 18
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  2. 1
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 17
      cameraview/src/main/java/com/otaliastudios/cameraview/Size.java
  4. 12
      cameraview/src/test/java/com/otaliastudios/cameraview/SizeTest.java

@ -389,6 +389,16 @@ abstract class CameraController implements
*/ */
protected Size computePictureSize(List<Size> captureSizes) { protected Size computePictureSize(List<Size> captureSizes) {
SizeSelector selector; SizeSelector selector;
// The external selector is expecting stuff in the view world, not in the sensor world.
// Flip before starting, and then flip again.
boolean flip = shouldFlipSizes();
if (flip) {
for (Size size : captureSizes) {
size.flip();
}
}
if (mSessionType == SessionType.PICTURE) { if (mSessionType == SessionType.PICTURE) {
selector = SizeSelectors.or( selector = SizeSelectors.or(
mPictureSizeSelector, mPictureSizeSelector,
@ -396,10 +406,11 @@ abstract class CameraController implements
); );
} else { } else {
// The Camcorder internally checks for cameraParameters.getSupportedVideoSizes() etc. // The Camcorder internally checks for cameraParameters.getSupportedVideoSizes() etc.
// We want the picture size to be the max picture consistent with the video aspect ratio. // And we want the picture size to be the max picture consistent with the video aspect ratio.
// -> Use the external picture selector, but enforce the ratio constraint. // -> Use the external picture selector, but enforce the ratio constraint.
CamcorderProfile profile = getCamcorderProfile(); CamcorderProfile profile = getCamcorderProfile();
AspectRatio targetRatio = AspectRatio.of(profile.videoFrameWidth, profile.videoFrameHeight); AspectRatio targetRatio = AspectRatio.of(profile.videoFrameWidth, profile.videoFrameHeight);
if (flip) targetRatio = targetRatio.inverse();
LOG.i("size:", "computeCaptureSize:", "videoQuality:", mVideoQuality, "targetRatio:", targetRatio); LOG.i("size:", "computeCaptureSize:", "videoQuality:", mVideoQuality, "targetRatio:", targetRatio);
SizeSelector matchRatio = SizeSelectors.aspectRatio(targetRatio, 0); SizeSelector matchRatio = SizeSelectors.aspectRatio(targetRatio, 0);
selector = SizeSelectors.or( selector = SizeSelectors.or(
@ -408,7 +419,10 @@ abstract class CameraController implements
mPictureSizeSelector mPictureSizeSelector
); );
} }
return selector.select(captureSizes).get(0);
Size result = selector.select(captureSizes).get(0);
if (flip) result.flip();
return result;
} }
protected Size computePreviewSize(List<Size> previewSizes) { protected Size computePreviewSize(List<Size> previewSizes) {

@ -181,7 +181,6 @@ public class CameraView extends FrameLayout {
// Apply gestures // Apply gestures
mapGesture(Gesture.TAP, tapGesture); mapGesture(Gesture.TAP, tapGesture);
// mapGesture(Gesture.DOUBLE_TAP, doubleTapGesture);
mapGesture(Gesture.LONG_TAP, longTapGesture); mapGesture(Gesture.LONG_TAP, longTapGesture);
mapGesture(Gesture.PINCH, pinchGesture); mapGesture(Gesture.PINCH, pinchGesture);
mapGesture(Gesture.SCROLL_HORIZONTAL, scrollHorizontalGesture); mapGesture(Gesture.SCROLL_HORIZONTAL, scrollHorizontalGesture);

@ -2,10 +2,13 @@ package com.otaliastudios.cameraview;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
/**
* A simple class representing a size, with width and height values.
*/
public class Size implements Comparable<Size> { public class Size implements Comparable<Size> {
private final int mWidth; private int mWidth;
private final int mHeight; private int mHeight;
Size(int width, int height) { Size(int width, int height) {
mWidth = width; mWidth = width;
@ -20,6 +23,16 @@ public class Size implements Comparable<Size> {
return mHeight; return mHeight;
} }
/**
* Flips width and height altogether.
*/
@SuppressWarnings("SuspiciousNameCombination")
public void flip() {
int temp = mWidth;
mWidth = mHeight;
mHeight = temp;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == null) { if (o == null) {

@ -11,11 +11,19 @@ public class SizeTest {
@Test @Test
public void testDimensions() { public void testDimensions() {
Size size = new Size(10, 20); Size size = new Size(10, 20);
assertEquals(size.getWidth(), 10f, 0f); assertEquals(size.getWidth(), 10);
assertEquals(size.getHeight(), 20f, 0f); assertEquals(size.getHeight(), 20);
assertEquals("10x20", size.toString()); assertEquals("10x20", size.toString());
} }
@Test
public void testFlip() {
Size size = new Size(10, 20);
size.flip();
assertEquals(size.getWidth(), 20);
assertEquals(size.getHeight(), 10);
}
@Test @Test
public void testEquals() { public void testEquals() {
Size s1 = new Size(10, 20); Size s1 = new Size(10, 20);

Loading…
Cancel
Save