From 1ea460a89823864216b47aae767b0d8f5dceb3ee Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Tue, 6 Jan 2015 16:19:44 -0800 Subject: SnapdragonCamera: Fixed aspect ratio in panormic shoot Fixed aspect ratio of the full screen preview. The camera preview size is chosen based on the aspect ratio of device screen. Change-Id: Ibc7c497a87d8f0cca2701d8709f010caa6f79308 --- .../android/camera/WideAnglePanoramaModule.java | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java index 40878581e..bc9fd8602 100644 --- a/src/com/android/camera/WideAnglePanoramaModule.java +++ b/src/com/android/camera/WideAnglePanoramaModule.java @@ -44,6 +44,7 @@ import android.view.OrientationEventListener; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.Display; import android.widget.Toast; import com.android.camera.PhotoModule; import com.android.camera.CameraManager.CameraProxy; @@ -109,6 +110,8 @@ public class WideAnglePanoramaModule private boolean mUsingFrontCamera; private int mCameraPreviewWidth; private int mCameraPreviewHeight; + private int mScreenWidth; + private int mScreenHeight; private int mCameraState; private int mCaptureState; private PowerManager.WakeLock mPartialWakeLock; @@ -369,14 +372,13 @@ public class WideAnglePanoramaModule return true; } - private boolean findBestPreviewSize(List supportedSizes, boolean need4To3, + private boolean findBestPreviewSize(List supportedSizes, boolean need4To3, boolean need16To9, boolean needSmaller) { int pixelsDiff = DEFAULT_CAPTURE_PIXELS; boolean hasFound = false; for (Size size : supportedSizes) { int h = size.height; int w = size.width; - // we only want 4:3 format. int d = DEFAULT_CAPTURE_PIXELS - h * w; if (needSmaller && d < 0) { // no bigger preview than 960x720. continue; @@ -384,6 +386,9 @@ public class WideAnglePanoramaModule if (need4To3 && (h * 4 != w * 3)) { continue; } + if (need16To9 && (h * 16 != w * 9)) { + continue; + } d = Math.abs(d); if (d < pixelsDiff) { mCameraPreviewWidth = w; @@ -396,12 +401,26 @@ public class WideAnglePanoramaModule } private void setupCaptureParams(Parameters parameters) { + boolean need4To3 = false; + boolean need16To9 = false; List supportedSizes = parameters.getSupportedPreviewSizes(); - if (!findBestPreviewSize(supportedSizes, true, true)) { - Log.w(TAG, "No 4:3 ratio preview size supported."); - if (!findBestPreviewSize(supportedSizes, false, true)) { + Display mDisplay = mActivity.getWindowManager().getDefaultDisplay(); + mScreenWidth = mDisplay.getWidth(); + mScreenHeight = mDisplay.getHeight(); + + if(mScreenHeight * 4 == mScreenWidth * 3) { + need4To3 = true; + } + + if(mScreenHeight * 16 == mScreenWidth * 9) { + need16To9 = true; + } + + if (!findBestPreviewSize(supportedSizes, need4To3, need16To9, true)) { + Log.w(TAG, "No preview size supported matching the screen aspect ratio"); + if (!findBestPreviewSize(supportedSizes, false, false, true)) { Log.w(TAG, "Can't find a supported preview size smaller than 960x720."); - findBestPreviewSize(supportedSizes, false, false); + findBestPreviewSize(supportedSizes, false, false, false); } } Log.d(TAG, "camera preview h = " @@ -492,6 +511,9 @@ public class WideAnglePanoramaModule } mPreviewUIWidth = r - l; mPreviewUIHeight = b - t; + Parameters parameters = mCameraDevice.getParameters(); + setupCaptureParams(parameters); + configureCamera(parameters); configMosaicPreview(); if (capturePending == true){ mMainHandler.post(new Runnable() { -- cgit v1.2.3