summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormingwax <mingwax@codeaurora.org>2017-03-09 16:40:22 +0800
committerArne Coucheron <arco68@gmail.com>2017-06-13 07:18:51 +0200
commit0f83363c62dc02a3e350f0ee7e1b63438bccc324 (patch)
treea966adde4c51dd2e4fcdf01e553a76afd23466ce
parent202f50ab965cf3bdb65ca1c236146da8ccda0ed8 (diff)
downloadandroid_packages_apps_Snap-0f83363c62dc02a3e350f0ee7e1b63438bccc324.zip
android_packages_apps_Snap-0f83363c62dc02a3e350f0ee7e1b63438bccc324.tar.gz
android_packages_apps_Snap-0f83363c62dc02a3e350f0ee7e1b63438bccc324.tar.bz2
SnapdragonCamera: Fix ghosting when non-zsl in VGA/QVGA size
(1) Increase the size of the preivewSize according to the ratio of the pictureSize. (2) Change the mVideoSnapshotSize from the mPictureSize to mVideoSize. (3) Reconstruction the getMaxPictureSizeLessThan4K method. CRs-Fixed: 1116242 Change-Id: Ic7dbab23fd0ee083cd38818fa39f4893de7c1d24
-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 cfb064c..e21fd30 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 9ae3708..214e716 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.