summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2011-11-02 19:54:11 +0800
committerChih-Chung Chang <chihchung@google.com>2011-11-02 19:55:55 +0800
commit1d965984ecf6c6233967a1f5d5a24f21fd2e450d (patch)
tree9d233489e413f97375076b1a83038c2cf6882d1c /src/com
parent4d55f6cb82c07a6191d2ab8e78fbab8c31e9db89 (diff)
downloadLegacyCamera-1d965984ecf6c6233967a1f5d5a24f21fd2e450d.zip
LegacyCamera-1d965984ecf6c6233967a1f5d5a24f21fd2e450d.tar.gz
LegacyCamera-1d965984ecf6c6233967a1f5d5a24f21fd2e450d.tar.bz2
5554028: Select video snapshot resolution based on the video recording aspect ratio.
Change-Id: I7b01a21271068b9d201e38197e2a61b183f87902
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/Util.java31
-rwxr-xr-xsrc/com/android/camera/VideoCamera.java21
2 files changed, 43 insertions, 9 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index 4c28e56..21bad6f 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -413,6 +413,37 @@ public class Util {
return optimalSize;
}
+ // Returns the largest picture size which matches the given aspect ratio.
+ public static Size getOptimalVideoSnapshotPictureSize(
+ List<Size> sizes, double targetRatio) {
+ // Use a very small tolerance because we want an exact match.
+ final double ASPECT_TOLERANCE = 0.001;
+ if (sizes == null) return null;
+
+ Size optimalSize = null;
+
+ // Try to find a size matches aspect ratio and has the largest width
+ for (Size size : sizes) {
+ double ratio = (double) size.width / size.height;
+ if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
+ if (optimalSize == null || size.width > optimalSize.width) {
+ optimalSize = size;
+ }
+ }
+
+ // Cannot find one that matches the aspect ratio. This should not happen.
+ // Ignore the requirement.
+ if (optimalSize == null) {
+ Log.w(TAG, "No picture size match the aspect ratio");
+ for (Size size : sizes) {
+ if (optimalSize == null || size.width > optimalSize.width) {
+ optimalSize = size;
+ }
+ }
+ }
+ return optimalSize;
+ }
+
public static void dumpParameters(Parameters parameters) {
String flattened = parameters.flatten();
StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 9f47d5c..0f75a53 100755
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -1882,15 +1882,18 @@ public class VideoCamera extends ActivityBase
}
// Set picture size.
- String pictureSize = mPreferences.getString(
- CameraSettings.KEY_PICTURE_SIZE, null);
- if (pictureSize == null) {
- CameraSettings.initialCameraPictureSize(this, mParameters);
- } else {
- List<Size> supported = mParameters.getSupportedPictureSizes();
- CameraSettings.setCameraPictureSize(
- pictureSize, supported, mParameters);
- }
+ // The logic here is different from the logic in still-mode camera.
+ // There we determine the preview size based on the picture size, but
+ // here we determine the picture size based on the preview size.
+ List<Size> supported = mParameters.getSupportedPictureSizes();
+ Size optimalSize = Util.getOptimalVideoSnapshotPictureSize(supported,
+ (double) mDesiredPreviewWidth / mDesiredPreviewHeight);
+ Size original = mParameters.getPictureSize();
+ if (!original.equals(optimalSize)) {
+ mParameters.setPictureSize(optimalSize.width, optimalSize.height);
+ }
+ Log.v(TAG, "Video snapshot size is " + optimalSize.width + "x" +
+ optimalSize.height);
// Set JPEG quality.
int jpegQuality = CameraProfile.getJpegEncodingQualityParameter(mCameraId,