summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/CaptureModule.java76
-rw-r--r--src/com/android/camera/util/CameraUtil.java11
2 files changed, 43 insertions, 44 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index cfb064c07..e21fd3029 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -2286,13 +2286,11 @@ public class CaptureModule extends BaseModule<CaptureUI> implements PhotoControl
private void updatePictureSize() {
String pictureSize = mSettingsManager.getValue(SettingsManager.KEY_PICTURE_SIZE);
mPictureSize = parsePictureSize(pictureSize);
- Point screenSize = new Point();
- mActivity.getWindowManager().getDefaultDisplay().getSize(screenSize);
Size[] prevSizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(),
SurfaceHolder.class);
- mPreviewSize = getOptimalPreviewSize(mPictureSize, prevSizes, screenSize.x, screenSize.y);
+ mPreviewSize = getOptimalPreviewSize(mPictureSize, prevSizes);
Size[] thumbSizes = mSettingsManager.getSupportedThumbnailSizes(getMainCameraId());
- mPictureThumbSize = getOptimalPreviewSize(mPictureSize, thumbSizes, 0, 0); // get largest thumb size
+ mPictureThumbSize = getOptimalPreviewSize(mPictureSize, thumbSizes); // get largest thumb size
}
public boolean isRecordingVideo() {
@@ -2314,20 +2312,18 @@ public class CaptureModule extends BaseModule<CaptureUI> implements PhotoControl
private void updateVideoSize() {
String videoSize = mSettingsManager.getValue(SettingsManager.KEY_VIDEO_QUALITY);
mVideoSize = parsePictureSize(videoSize);
- Point screenSize = new Point();
- mActivity.getWindowManager().getDefaultDisplay().getSize(screenSize);
Size[] prevSizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(),
MediaRecorder.class);
- mVideoPreviewSize = getOptimalPreviewSize(mVideoSize, prevSizes, screenSize.x, screenSize.y);
+ mVideoPreviewSize = getOptimalPreviewSize(mVideoSize, prevSizes);
}
private void updateVideoSnapshotSize() {
- mVideoSnapshotSize = mPictureSize;
+ mVideoSnapshotSize = mVideoSize;
if (is4kSize(mVideoSize) && is4kSize(mVideoSnapshotSize)) {
mVideoSnapshotSize = getMaxPictureSizeLessThan4k();
}
Size[] thumbSizes = mSettingsManager.getSupportedThumbnailSizes(getMainCameraId());
- mVideoSnapshotThumbSize = getOptimalPreviewSize(mVideoSnapshotSize, thumbSizes, 0, 0); // get largest thumb size
+ mVideoSnapshotThumbSize = getOptimalPreviewSize(mVideoSnapshotSize, thumbSizes); // get largest thumb size
}
private boolean is4kSize(Size size) {
@@ -3383,50 +3379,44 @@ public class CaptureModule extends BaseModule<CaptureUI> implements PhotoControl
}
}
- private Size getOptimalPreviewSize(Size pictureSize, Size[] prevSizes, int screenW, int
- screenH) {
- if (pictureSize.getWidth() <= screenH && pictureSize.getHeight() <= screenW) {
- return pictureSize;
- }
- Size optimal = prevSizes[0];
- float ratio = (float) pictureSize.getWidth() / pictureSize.getHeight();
- for (Size prevSize: prevSizes) {
- float prevRatio = (float) prevSize.getWidth() / prevSize.getHeight();
- if (Math.abs(prevRatio - ratio) < 0.01) {
- // flip w and h
- if (prevSize.getWidth() <= screenH && prevSize.getHeight() <= screenW &&
- prevSize.getWidth() <= pictureSize.getWidth() && prevSize.getHeight() <= pictureSize.getHeight()) {
- return prevSize;
- } else {
- optimal = prevSize;
- }
- }
+ private Size getOptimalPreviewSize(Size pictureSize, Size[] prevSizes) {
+ Point[] points = new Point[prevSizes.length];
+
+ double targetRatio = (double) pictureSize.getWidth() / pictureSize.getHeight();
+ int index = 0;
+ for (Size s : prevSizes) {
+ points[index++] = new Point(s.getWidth(), s.getHeight());
}
- return optimal;
+
+ int optimalPickIndex = CameraUtil.getOptimalPreviewSize(mActivity, points, targetRatio);
+ return (optimalPickIndex == -1) ? null : prevSizes[optimalPickIndex];
}
private Size getMaxPictureSizeLessThan4k() {
Size[] sizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(), ImageFormat.JPEG);
float ratio = (float) mVideoSize.getWidth() / mVideoSize.getHeight();
+ Size optimalSize = null;
for (Size size : sizes) {
- if (!is4kSize(size)) {
- float pictureRatio = (float) size.getWidth() / size.getHeight();
- if (Math.abs(pictureRatio - ratio) < 0.01) {
- return size;
+ if (is4kSize(size)) continue;
+ float pictureRatio = (float) size.getWidth() / size.getHeight();
+ if (Math.abs(pictureRatio - ratio) > 0.01) continue;
+ if (optimalSize == null || size.getWidth() > optimalSize.getWidth()) {
+ 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 (is4kSize(size)) continue;
+ if (optimalSize == null || size.getWidth() > optimalSize.getWidth()) {
+ optimalSize = size;
}
}
}
- return sizes[sizes.length - 1];
- }
- private Size getMaxSizeWithRatio(Size[] sizes, Size reference) {
- float ratio = (float) reference.getWidth() / reference.getHeight();
- for (Size size : sizes) {
- float prevRatio = (float) size.getWidth() / size.getHeight();
- if (Math.abs(prevRatio - ratio) < 0.01) {
- return size;
- }
- }
- return sizes[0];
+ return optimalSize;
}
public TrackingFocusRenderer getTrackingForcusRenderer() {
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index 9ae37080e..214e71601 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -624,9 +624,18 @@ public class CameraUtil {
Point size = sizes[i];
double ratio = (double) size.x / size.y;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
- if (Math.abs(size.y - targetHeight) < minDiff) {
+
+ double heightDiff = Math.abs(size.y - targetHeight);
+ if (heightDiff < minDiff) {
optimalSizeIndex = i;
minDiff = Math.abs(size.y - targetHeight);
+ } else if (heightDiff == minDiff) {
+ // Prefer resolutions smaller-than-display when an equally close
+ // larger-than-display resolution is available
+ if (size.y < targetHeight) {
+ optimalSizeIndex = i;
+ minDiff = heightDiff;
+ }
}
}
// Cannot find the one match the aspect ratio. This should not happen.