summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEino-Ville Talvala <etalvala@google.com>2016-04-28 22:41:11 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-04-28 22:41:11 +0000
commit0c1c16d65196ba0a28b72edb44b7421692881e7a (patch)
treeba24fe1845559ba629832dc38787ed98f5b3a415
parent8ca0af841b5efcc367ed11169fdcccc98268c8d2 (diff)
parent3855bb499fbfc073771fa951babfe1922d90ffc9 (diff)
downloadDevCamera-0c1c16d65196ba0a28b72edb44b7421692881e7a.tar.gz
Fix portrait-orientation assumptionsandroid-cts_7.1_r1android-cts-7.1_r9android-cts-7.1_r8android-cts-7.1_r7android-cts-7.1_r6android-cts-7.1_r5android-cts-7.1_r4android-cts-7.1_r3android-cts-7.1_r29android-cts-7.1_r28android-cts-7.1_r27android-cts-7.1_r26android-cts-7.1_r25android-cts-7.1_r24android-cts-7.1_r23android-cts-7.1_r22android-cts-7.1_r21android-cts-7.1_r20android-cts-7.1_r2android-cts-7.1_r19android-cts-7.1_r18android-cts-7.1_r17android-cts-7.1_r16android-cts-7.1_r15android-cts-7.1_r14android-cts-7.1_r13android-cts-7.1_r12android-cts-7.1_r11android-cts-7.1_r10android-cts-7.1_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-7.1.1_r9android-7.1.1_r8android-7.1.1_r7android-7.1.1_r61android-7.1.1_r60android-7.1.1_r6android-7.1.1_r59android-7.1.1_r58android-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r54android-7.1.1_r53android-7.1.1_r52android-7.1.1_r51android-7.1.1_r50android-7.1.1_r49android-7.1.1_r48android-7.1.1_r47android-7.1.1_r46android-7.1.1_r45android-7.1.1_r44android-7.1.1_r43android-7.1.1_r42android-7.1.1_r41android-7.1.1_r40android-7.1.1_r4android-7.1.1_r39android-7.1.1_r38android-7.1.1_r35android-7.1.1_r33android-7.1.1_r32android-7.1.1_r31android-7.1.1_r3android-7.1.1_r28android-7.1.1_r27android-7.1.1_r26android-7.1.1_r25android-7.1.1_r24android-7.1.1_r23android-7.1.1_r22android-7.1.1_r21android-7.1.1_r20android-7.1.1_r2android-7.1.1_r17android-7.1.1_r16android-7.1.1_r15android-7.1.1_r14android-7.1.1_r13android-7.1.1_r12android-7.1.1_r11android-7.1.1_r10android-7.1.1_r1android-7.1.0_r7android-7.1.0_r6android-7.1.0_r5android-7.1.0_r4android-7.1.0_r3android-7.1.0_r2android-7.1.0_r1nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-mr1.8-releasenougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-releasenougat-mr1.4-releasenougat-mr1.3-releasenougat-mr1.2-releasenougat-mr1.1-releasenougat-mr1-volantis-releasenougat-mr1-security-releasenougat-mr1-releasenougat-mr1-flounder-releasenougat-mr1-devnougat-mr1-cts-releasenougat-dr1-release
am: 3855bb499f * commit '3855bb499fbfc073771fa951babfe1922d90ffc9': Fix portrait-orientation assumptions Change-Id: Iadd126e2d0fc383e17234e9363cb2fc6d8c79380
-rw-r--r--Android.mk1
-rw-r--r--src/com/android/devcamera/Api2Camera.java9
-rw-r--r--src/com/android/devcamera/CameraInfoCache.java16
-rw-r--r--src/com/android/devcamera/CameraInterface.java7
-rw-r--r--src/com/android/devcamera/DevCameraActivity.java5
-rw-r--r--src/com/android/devcamera/PreviewOverlay.java44
6 files changed, 68 insertions, 14 deletions
diff --git a/Android.mk b/Android.mk
index 6433b95..d3deaac 100644
--- a/Android.mk
+++ b/Android.mk
@@ -19,6 +19,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SDK_VERSION := current
+LOCAL_MIN_SDK_VERSION := 21
LOCAL_SRC_FILES := \
$(call all-java-files-under, src)
diff --git a/src/com/android/devcamera/Api2Camera.java b/src/com/android/devcamera/Api2Camera.java
index 65308a5..73e5c87 100644
--- a/src/com/android/devcamera/Api2Camera.java
+++ b/src/com/android/devcamera/Api2Camera.java
@@ -305,6 +305,11 @@ public class Api2Camera implements CameraInterface, SurfaceTexture.OnFrameAvaila
}
@Override
+ public int getOrientation() {
+ return mCameraInfoCache.sensorOrientation();
+ }
+
+ @Override
public void openCamera() {
// If API2 FULL mode is not available, display toast
if (!mCameraInfoCache.isCamera2FullModeAvailable()) {
@@ -556,8 +561,8 @@ public class Api2Camera implements CameraInterface, SurfaceTexture.OnFrameAvaila
Log.v(TAG, " Sent YUV1 image to ImageWriter.queueInputImage()");
try {
CaptureRequest.Builder b1 = mCameraDevice.createReprocessCaptureRequest(mLastTotalCaptureResult);
- // Portrait.
- b1.set(CaptureRequest.JPEG_ORIENTATION, 90);
+ // Todo: Read current orientation instead of just assuming device is in native orientation
+ b1.set(CaptureRequest.JPEG_ORIENTATION, mCameraInfoCache.sensorOrientation());
b1.set(CaptureRequest.JPEG_QUALITY, (byte) 95);
b1.set(CaptureRequest.NOISE_REDUCTION_MODE, mReprocessingNoiseMode);
b1.set(CaptureRequest.EDGE_MODE, mReprocessingEdgeMode);
diff --git a/src/com/android/devcamera/CameraInfoCache.java b/src/com/android/devcamera/CameraInfoCache.java
index 1a5b0b1..699fd97 100644
--- a/src/com/android/devcamera/CameraInfoCache.java
+++ b/src/com/android/devcamera/CameraInfoCache.java
@@ -186,11 +186,21 @@ public class CameraInfoCache {
Log.e(TAG, "No physical sensor dimensions reported by camera device, assuming default "
+ physicalSize);
}
+
+ // Only active array is actually visible, so calculate fraction of physicalSize that it takes up
+ Size pixelArraySize = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
+ Rect activeArraySize = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
+
+ float activeWidthFraction = activeArraySize.width() / (float) pixelArraySize.getWidth();
+ float activeHeightFraction = activeArraySize.height() / (float) pixelArraySize.getHeight();
+
// Simple rectilinear lens field of view formula:
- // angle of view = 2 * arctan ( sensor size / (2 * focal length) )
+ // angle of view = 2 * arctan ( active size / (2 * focal length) )
float[] fieldOfView = new float[2];
- fieldOfView[0] = (float) Math.toDegrees(2 * Math.atan(physicalSize.getWidth() / 2 / focalLength));
- fieldOfView[1] = (float) Math.toDegrees(2 * Math.atan(physicalSize.getHeight() / 2 / focalLength));
+ fieldOfView[0] = (float) Math.toDegrees(
+ 2 * Math.atan(physicalSize.getWidth() * activeWidthFraction / 2 / focalLength));
+ fieldOfView[1] = (float) Math.toDegrees(
+ 2 * Math.atan(physicalSize.getHeight() * activeHeightFraction / 2 / focalLength));
return fieldOfView;
}
diff --git a/src/com/android/devcamera/CameraInterface.java b/src/com/android/devcamera/CameraInterface.java
index e16c9e5..e6df5ce 100644
--- a/src/com/android/devcamera/CameraInterface.java
+++ b/src/com/android/devcamera/CameraInterface.java
@@ -33,6 +33,13 @@ public interface CameraInterface {
float[] getFieldOfView();
/**
+ * Get the camera sensor orientation relative to device native orientation
+ * Typically 90 or 270 for phones, 0 or 180 for tablets, though many tables are also
+ * portrait-native.
+ */
+ int getOrientation();
+
+ /**
* Open the camera. Call startPreview() to actually see something.
*/
void openCamera();
diff --git a/src/com/android/devcamera/DevCameraActivity.java b/src/com/android/devcamera/DevCameraActivity.java
index 6194915..869e065 100644
--- a/src/com/android/devcamera/DevCameraActivity.java
+++ b/src/com/android/devcamera/DevCameraActivity.java
@@ -542,8 +542,9 @@ public class DevCameraActivity extends Activity implements CameraInterface.MyCam
float[] fovs = mCamera.getFieldOfView();
mPreviewOverlay.setFieldOfView(fovs[0], fovs[1]);
- mPreviewOverlay.setFacing(mToggleFrontCam.isChecked() ?
- CameraCharacteristics.LENS_FACING_FRONT : CameraCharacteristics.LENS_FACING_BACK);
+ mPreviewOverlay.setFacingAndOrientation(mToggleFrontCam.isChecked() ?
+ CameraCharacteristics.LENS_FACING_FRONT : CameraCharacteristics.LENS_FACING_BACK,
+ mCamera.getOrientation());
if (mGyroOperations == null) {
SensorManager sensorManager = (SensorManager) getSystemService(this.SENSOR_SERVICE);
mGyroOperations = new GyroOperations(sensorManager);
diff --git a/src/com/android/devcamera/PreviewOverlay.java b/src/com/android/devcamera/PreviewOverlay.java
index 7a4dd02..5909b2d 100644
--- a/src/com/android/devcamera/PreviewOverlay.java
+++ b/src/com/android/devcamera/PreviewOverlay.java
@@ -43,8 +43,11 @@ public class PreviewOverlay extends View {
private float mFovLargeDegrees;
private float mFovSmallDegrees;
private int mFacing = CameraCharacteristics.LENS_FACING_BACK;
+ private int mOrientation = 0; // degrees
+
float[] mAngles = new float[2];
+
public PreviewOverlay(Context context, AttributeSet attrs) {
super(context, attrs);
Resources res = getResources();
@@ -75,8 +78,9 @@ public class PreviewOverlay extends View {
* Set the facing of the current camera, for correct coordinate mapping.
* One of the CameraCharacteristics.LENS_INFO_FACING_* constants
*/
- public void setFacing(int facing) {
+ public void setFacingAndOrientation(int facing, int orientation) {
mFacing = facing;
+ mOrientation = orientation;
}
public void show3AInfo(boolean show) {
@@ -86,13 +90,39 @@ public class PreviewOverlay extends View {
}
public void setGyroAngles(float[] angles) {
- if (mFacing == CameraCharacteristics.LENS_FACING_BACK) {
+ boolean front = (mFacing == CameraCharacteristics.LENS_FACING_BACK);
+ // Rotate gyro coordinates to match camera orientation
+ // Gyro data is always presented in the device native coordinate system, which
+ // is either portrait or landscape depending on device.
+ // (http://developer.android.com/reference/android/hardware/SensorEvent.html)
+ // DevCamera locks itself to portrait, and the camera sensor long edge is always aligned
+ // with the long edge of the device.
+ // mOrientation is the relative orientation of the camera sensor and the device native
+ // orientation, so it can be used to decide if the gyro data is meant to be interpreted
+ // in landscape or portrait and flip coordinates/sign accordingly.
+ // Additionally, front-facing cameras are mirrored, so an additional sign flip is needed.
+ switch (mOrientation) {
+ case 0:
+ mAngles[1] = -angles[0];
+ mAngles[0] = angles[1];
+ break;
+ case 90:
+ mAngles[0] = angles[0];
+ mAngles[1] = angles[1];
+ break;
+ case 180:
+ mAngles[1] = -angles[0];
+ mAngles[0] = angles[1];
+ break;
+ case 270:
+ mAngles[0] = angles[0];
+ mAngles[1] = angles[1];
+ break;
+ }
+ if (mFacing != CameraCharacteristics.LENS_FACING_BACK) {
// Reverse sensor readout for front/external facing cameras
- mAngles[0] = angles[0];
- mAngles[1] = angles[1];
- } else {
- mAngles[0] = -angles[0];
- mAngles[1] = -angles[1];
+ mAngles[0] = -mAngles[0];
+ mAngles[1] = -mAngles[1];
}
}