From d89be73f8fb19eaaa07314eb10c4d45eaea95da0 Mon Sep 17 00:00:00 2001 From: Andrei Diaconu Date: Mon, 10 Apr 2017 14:19:29 +0300 Subject: [PATCH] Fixed STILL issues and Portrait flip --- .../api16/com/flurgle/camerakit/Camera1.java | 25 ++++++++++++------- .../flurgle/camerakit/ProcessStillTask.java | 7 +++--- demo/src/main/AndroidManifest.xml | 1 - 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java b/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java index 5a46b351..90d609cf 100644 --- a/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java +++ b/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java @@ -216,7 +216,7 @@ public class Camera1 extends CameraImpl { mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() { @Override 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 public void onStillProcessed(final YuvImage yuv) { mCameraListener.onPictureTaken(yuv); @@ -315,9 +315,7 @@ public class Camera1 extends CameraImpl { mCameraParameters = mCamera.getParameters(); adjustCameraParameters(); - mCamera.setDisplayOrientation( - calculateCameraRotation(mDisplayOrientation) - ); + mCamera.setDisplayOrientation(calculatePreviewRotation()); 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) { - return (360 - (mCameraInfo.orientation + rotation) % 360) % 360; + //Front is flipped + return (previewRotation + 180 + 2*mDisplayOrientation + 720) %360; } else { - return (mCameraInfo.orientation - rotation + 360) % 360; + return previewRotation; } } @@ -369,8 +377,7 @@ public class Camera1 extends CameraImpl { getCaptureResolution().getWidth(), getCaptureResolution().getHeight() ); - int rotation = (calculateCameraRotation(mDisplayOrientation) - + (mFacing == CameraKit.Constants.FACING_FRONT ? 180 : 0) ) % 360; + int rotation = calculateCaptureRotation(); mCameraParameters.setRotation(rotation); setFocus(mFocus); diff --git a/camerakit/src/main/api16/com/flurgle/camerakit/ProcessStillTask.java b/camerakit/src/main/api16/com/flurgle/camerakit/ProcessStillTask.java index 3a6386ce..44a63bb6 100644 --- a/camerakit/src/main/api16/com/flurgle/camerakit/ProcessStillTask.java +++ b/camerakit/src/main/api16/com/flurgle/camerakit/ProcessStillTask.java @@ -7,13 +7,13 @@ class ProcessStillTask implements Runnable { private byte[] data; private Camera camera; - private Camera.CameraInfo cameraInfo; + private int rotation; 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.camera = camera; - this.cameraInfo = cameraInfo; + this.rotation = rotation; this.onStillProcessedListener = onStillProcessedListener; } @@ -22,7 +22,6 @@ class ProcessStillTask implements Runnable { Camera.Parameters parameters = camera.getParameters(); int width = parameters.getPreviewSize().width; int height = parameters.getPreviewSize().height; - int rotation = cameraInfo.orientation; byte[] rotatedData = new Rotation(data, width, height, rotation).getYuv(); int postWidth; diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index d347e804..976e1aa9 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -12,7 +12,6 @@