Fixed STILL issues and Portrait flip

pull/1/head
Andrei Diaconu 8 years ago
parent faa5075dbe
commit d89be73f8f
  1. 25
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  2. 7
      camerakit/src/main/api16/com/flurgle/camerakit/ProcessStillTask.java
  3. 1
      demo/src/main/AndroidManifest.xml

@ -216,7 +216,7 @@ public class Camera1 extends CameraImpl {
mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() { mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
@Override @Override
public void onPreviewFrame(byte[] data, Camera camera) { public void onPreviewFrame(byte[] data, Camera camera) {
new Thread(new ProcessStillTask(data, camera, mCameraInfo, new ProcessStillTask.OnStillProcessedListener() { new Thread(new ProcessStillTask(data, camera, calculateCaptureRotation(), new ProcessStillTask.OnStillProcessedListener() {
@Override @Override
public void onStillProcessed(final YuvImage yuv) { public void onStillProcessed(final YuvImage yuv) {
mCameraListener.onPictureTaken(yuv); mCameraListener.onPictureTaken(yuv);
@ -315,9 +315,7 @@ public class Camera1 extends CameraImpl {
mCameraParameters = mCamera.getParameters(); mCameraParameters = mCamera.getParameters();
adjustCameraParameters(); adjustCameraParameters();
mCamera.setDisplayOrientation( mCamera.setDisplayOrientation(calculatePreviewRotation());
calculateCameraRotation(mDisplayOrientation)
);
mCameraListener.onCameraOpened(); mCameraListener.onCameraOpened();
} }
@ -345,11 +343,21 @@ public class Camera1 extends CameraImpl {
} }
} }
private int calculateCameraRotation(int rotation) { private int calculatePreviewRotation() {
if (mCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
return ((mCameraInfo.orientation - mDisplayOrientation) + 360 + 180) % 360;
} else {
return (mCameraInfo.orientation - mDisplayOrientation + 360) % 360;
}
}
private int calculateCaptureRotation() {
int previewRotation = calculatePreviewRotation();
if (mCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { if (mCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
return (360 - (mCameraInfo.orientation + rotation) % 360) % 360; //Front is flipped
return (previewRotation + 180 + 2*mDisplayOrientation + 720) %360;
} else { } else {
return (mCameraInfo.orientation - rotation + 360) % 360; return previewRotation;
} }
} }
@ -369,8 +377,7 @@ public class Camera1 extends CameraImpl {
getCaptureResolution().getWidth(), getCaptureResolution().getWidth(),
getCaptureResolution().getHeight() getCaptureResolution().getHeight()
); );
int rotation = (calculateCameraRotation(mDisplayOrientation) int rotation = calculateCaptureRotation();
+ (mFacing == CameraKit.Constants.FACING_FRONT ? 180 : 0) ) % 360;
mCameraParameters.setRotation(rotation); mCameraParameters.setRotation(rotation);
setFocus(mFocus); setFocus(mFocus);

@ -7,13 +7,13 @@ class ProcessStillTask implements Runnable {
private byte[] data; private byte[] data;
private Camera camera; private Camera camera;
private Camera.CameraInfo cameraInfo; private int rotation;
private OnStillProcessedListener onStillProcessedListener; private OnStillProcessedListener onStillProcessedListener;
public ProcessStillTask(byte[] data, Camera camera, Camera.CameraInfo cameraInfo, OnStillProcessedListener onStillProcessedListener) { public ProcessStillTask(byte[] data, Camera camera, int rotation, OnStillProcessedListener onStillProcessedListener) {
this.data = data; this.data = data;
this.camera = camera; this.camera = camera;
this.cameraInfo = cameraInfo; this.rotation = rotation;
this.onStillProcessedListener = onStillProcessedListener; this.onStillProcessedListener = onStillProcessedListener;
} }
@ -22,7 +22,6 @@ class ProcessStillTask implements Runnable {
Camera.Parameters parameters = camera.getParameters(); Camera.Parameters parameters = camera.getParameters();
int width = parameters.getPreviewSize().width; int width = parameters.getPreviewSize().width;
int height = parameters.getPreviewSize().height; int height = parameters.getPreviewSize().height;
int rotation = cameraInfo.orientation;
byte[] rotatedData = new Rotation(data, width, height, rotation).getYuv(); byte[] rotatedData = new Rotation(data, width, height, rotation).getYuv();
int postWidth; int postWidth;

@ -12,7 +12,6 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.MainActivity"> android:theme="@style/Theme.MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

Loading…
Cancel
Save