Commit 73ec9851 authored by Sol Boucher's avatar Sol Boucher
Browse files

Move display orientation calculations out of app code

Because they're needed by every app, these are being relocated into the
portability layer. As such, the CameraUtil#getDisplayOrientation() and
CameraUtil#getJpegRotation() methods are being replaced by the API-agnostic
CameraDeviceInfo.Characteristics#getPreviewOrientation() and
CameraDeviceInfo.Characteristics#getJpegOrientation() calls, respectively.

Change-Id: I5048e6f1a5ff655e4ea260b109e7c104bbe790b0
parent 00d8bbc9
......@@ -847,10 +847,8 @@ public class CaptureModule extends CameraModule implements ModuleController,
}
private int getOrientation() {
// We need to be consistent with the framework orientation (i.e. the
// orientation of the UI.) when the auto-rotate screen setting is on.
if (mAppController.isAutoRotateScreen()) {
return (360 - mDisplayRotation) % 360;
return mDisplayRotation;
} else {
return mOrientation;
}
......
......@@ -1275,17 +1275,14 @@ public class PhotoModule
// Set rotation and gps data.
int orientation;
// We need to be consistent with the framework orientation (i.e. the
// orientation of the UI.) when the auto-rotate screen setting is on.
if (mActivity.isAutoRotateScreen()) {
orientation = (360 - mDisplayRotation) % 360;
orientation = mDisplayRotation;
} else {
orientation = mOrientation;
}
Characteristics info =
mActivity.getCameraProvider().getCharacteristics(mCameraId);
mJpegRotation = CameraUtil.getJpegRotation(info, orientation);
mCameraSettings.setPhotoRotationDegrees(mJpegRotation);
mJpegRotation = info.getJpegOrientation(orientation);
Location loc = mActivity.getLocationManager().getCurrentLocation();
CameraUtil.setGpsParameters(mCameraSettings, loc);
mCameraDevice.applySettings(mCameraSettings);
......@@ -1860,7 +1857,7 @@ public class PhotoModule
mDisplayRotation = CameraUtil.getDisplayRotation(mActivity);
Characteristics info =
mActivity.getCameraProvider().getCharacteristics(mCameraId);
mDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, info);
mDisplayOrientation = info.getPreviewOrientation(mDisplayRotation);
mCameraDisplayOrientation = mDisplayOrientation;
mUI.setDisplayOrientation(mDisplayOrientation);
if (mFocusManager != null) {
......@@ -1868,7 +1865,7 @@ public class PhotoModule
}
// Change the camera display orientation
if (mCameraDevice != null) {
mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation);
mCameraDevice.setDisplayOrientation(mDisplayRotation);
}
}
......
......@@ -416,11 +416,6 @@ public class VideoModule extends CameraModule
return;
}
// Set rotation and gps data.
Characteristics info =
mActivity.getCameraProvider().getCharacteristics(mCameraId);
int rotation = CameraUtil.getJpegRotation(info, mOrientation);
mCameraSettings.setPhotoRotationDegrees(rotation);
Location loc = mLocationManager.getCurrentLocation();
CameraUtil.setGpsParameters(mCameraSettings, loc);
mCameraDevice.applySettings(mCameraSettings);
......@@ -844,10 +839,10 @@ public class VideoModule extends CameraModule
mDisplayRotation = CameraUtil.getDisplayRotation(mActivity);
Characteristics info =
mActivity.getCameraProvider().getCharacteristics(mCameraId);
mCameraDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, info);
mCameraDisplayOrientation = info.getPreviewOrientation(mDisplayRotation);
// Change the camera display orientation
if (mCameraDevice != null) {
mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation);
mCameraDevice.setDisplayOrientation(mDisplayRotation);
}
if (mFocusManager != null) {
mFocusManager.setDisplayOrientation(mCameraDisplayOrientation);
......@@ -919,7 +914,7 @@ public class VideoModule extends CameraModule
}
setDisplayOrientation();
mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation);
mCameraDevice.setDisplayOrientation(mDisplayRotation);
setCameraParameters();
if (mFocusManager != null) {
......
......@@ -386,21 +386,6 @@ public class CameraUtil {
return naturalWidth < naturalHeight;
}
public static int getDisplayOrientation(int degrees, Characteristics info) {
// See android.hardware.Camera.setDisplayOrientation for
// documentation.
int result = 0;
if (info.isFacingFront()) {
result = (info.getSensorOrientation() + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else if (info.isFacingBack()) {
result = (info.getSensorOrientation() - degrees + 360) % 360;
} else {
Log.e(TAG, "Camera is facing unhandled direction");
}
return result;
}
public static int roundOrientation(int orientation, int orientationHistory) {
boolean changeOrientation = false;
if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
......@@ -682,22 +667,6 @@ public class CameraUtil {
view.startAnimation(animation);
}
public static int getJpegRotation(Characteristics info, int orientation) {
// See android.hardware.Camera.Parameters.setRotation for
// documentation.
int rotation = 0;
if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
if (info.isFacingFront()) {
rotation = (info.getSensorOrientation() - orientation + 360) % 360;
} else if (info.isFacingBack()) {
rotation = (info.getSensorOrientation() + orientation) % 360;
} else {
Log.e(TAG, "Camera is facing unhandled direction");
}
}
return rotation;
}
/**
* Down-samples a jpeg byte array.
* @param data a byte array of jpeg data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment