aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuichi Araki <yaraki@google.com>2016-01-13 10:46:10 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-01-13 10:46:10 +0000
commit26ee87662313234a7109f1be0a7ad8a8a5d5a704 (patch)
treec99803a3aef12e06ff8cbaa77557cfef1f101cec
parenta9f977ca99cbea750572e7288921da42757d046f (diff)
parent33a323efaf50c783e81990c2c51696a33669ed8c (diff)
downloadandroid-26ee87662313234a7109f1be0a7ad8a8a5d5a704.tar.gz
Merge "Camera2Basic: Fix JPEG orientation on some devices" into mnc-docs
-rw-r--r--media/Camera2Basic/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java29
1 files changed, 24 insertions, 5 deletions
diff --git a/media/Camera2Basic/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java b/media/Camera2Basic/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
index 747d8d83..a29fa144 100644
--- a/media/Camera2Basic/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
+++ b/media/Camera2Basic/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
@@ -276,6 +276,11 @@ public class Camera2BasicFragment extends Fragment
private boolean mFlashSupported;
/**
+ * Orientation of the camera sensor
+ */
+ private int mSensorOrientation;
+
+ /**
* A {@link CameraCaptureSession.CaptureCallback} that handles events related to JPEG capture.
*/
private CameraCaptureSession.CaptureCallback mCaptureCallback
@@ -515,19 +520,19 @@ public class Camera2BasicFragment extends Fragment
// Find out if we need to swap dimension to get the preview size relative to sensor
// coordinate.
int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
- int sensorOrientation =
- characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
+ //noinspection ConstantConditions
+ mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
boolean swappedDimensions = false;
switch (displayRotation) {
case Surface.ROTATION_0:
case Surface.ROTATION_180:
- if (sensorOrientation == 90 || sensorOrientation == 270) {
+ if (mSensorOrientation == 90 || mSensorOrientation == 270) {
swappedDimensions = true;
}
break;
case Surface.ROTATION_90:
case Surface.ROTATION_270:
- if (sensorOrientation == 0 || sensorOrientation == 180) {
+ if (mSensorOrientation == 0 || mSensorOrientation == 180) {
swappedDimensions = true;
}
break;
@@ -821,7 +826,7 @@ public class Camera2BasicFragment extends Fragment
// Orientation
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
- captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
+ captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
@@ -844,6 +849,20 @@ public class Camera2BasicFragment extends Fragment
}
/**
+ * Retrieves the JPEG orientation from the specified screen rotation.
+ *
+ * @param rotation The screen rotation.
+ * @return The JPEG orientation (one of 0, 90, 270, and 360)
+ */
+ private int getOrientation(int rotation) {
+ // Sensor orientation is 90 for most devices, or 270 for some devices (eg. Nexus 5X)
+ // We have to take that into account and rotate JPEG properly.
+ // For devices with orientation of 90, we simply return our mapping from ORIENTATIONS.
+ // For devices with orientation of 270, we need to rotate the JPEG 180 degrees.
+ return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
+ }
+
+ /**
* Unlock the focus. This method should be called when still image capture sequence is
* finished.
*/