From 607e4cb9ec709a0cbdb3d925a020c43aea270241 Mon Sep 17 00:00:00 2001 From: Ruben Brunk Date: Thu, 7 May 2015 10:46:12 -0700 Subject: [PATCH] camera2: Fix crop selection in LEGACY. Bug: 20892101 Change-Id: Ied07096a539452505657e3313d09ea82f747731c --- .../android/hardware/camera2/legacy/ParameterUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/android/hardware/camera2/legacy/ParameterUtils.java b/core/java/android/hardware/camera2/legacy/ParameterUtils.java index 9e9a6fec06c62..32bbc51586a92 100644 --- a/core/java/android/hardware/camera2/legacy/ParameterUtils.java +++ b/core/java/android/hardware/camera2/legacy/ParameterUtils.java @@ -61,6 +61,8 @@ public class ParameterUtils { public static final Rect RECTANGLE_EMPTY = new Rect(/*left*/0, /*top*/0, /*right*/0, /*bottom*/0); + private static final double ASPECT_RATIO_TOLERANCE = 0.05f; + /** * Calculate effective/reported zoom data from a user-specified crop region. */ @@ -498,7 +500,10 @@ public class ParameterUtils { float aspectRatioPreview = previewSize.getWidth() * 1.0f / previewSize.getHeight(); float cropH, cropW; - if (aspectRatioPreview < aspectRatioArray) { + if (Math.abs(aspectRatioPreview - aspectRatioArray) < ASPECT_RATIO_TOLERANCE) { + cropH = activeArray.height(); + cropW = activeArray.width(); + } else if (aspectRatioPreview < aspectRatioArray) { // The new width must be smaller than the height, so scale the width by AR cropH = activeArray.height(); cropW = cropH * aspectRatioPreview;