OSDN Git Service

[ZSL Cam] Use largest supported size if no picture size is already set.
authorPuneet Lall <puneetl@google.com>
Wed, 3 Sep 2014 17:43:35 +0000 (10:43 -0700)
committerPuneet Lall <puneetl@google.com>
Wed, 3 Sep 2014 17:47:43 +0000 (17:47 +0000)
Fixes crash due to null size when zsl is started for the first time on a
fresh device.

Bug: 17322843
Change-Id: I31ef4202c13cee1270af59231f93842fa0e86009

src/com/android/camera/one/v2/OneCameraZslImpl.java

index d078f10..9d6c75e 100644 (file)
@@ -308,6 +308,27 @@ public class OneCameraZslImpl extends AbstractOneCamera {
 
         // Allocate the image reader to store all images received from the
         // camera.
+        if (pictureSize == null) {
+            // If no picture size is specified, use the largest supported size.
+            StreamConfigurationMap configs = characteristics.get(
+                    CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
+            android.util.Size[] supportedSizes = configs.getOutputSizes(sCaptureImageFormat);
+
+            // Find the largest supported size.
+            android.util.Size largestSupportedSize = supportedSizes[0];
+            long largestSupportedSizePixels = largestSupportedSize.getWidth()
+                    * largestSupportedSize.getHeight();
+            for (int i = 0; i < supportedSizes.length; i++) {
+                long numPixels = supportedSizes[i].getWidth() * supportedSizes[i].getHeight();
+                if (numPixels > largestSupportedSizePixels) {
+                    largestSupportedSize = supportedSizes[i];
+                    largestSupportedSizePixels = numPixels;
+                }
+            }
+
+            pictureSize = new Size(largestSupportedSize.getWidth(),
+                    largestSupportedSize.getHeight());
+        }
         mCaptureImageReader = ImageReader.newInstance(pictureSize.getWidth(),
                 pictureSize.getHeight(),
                 sCaptureImageFormat, MAX_CAPTURE_IMAGES);
@@ -935,7 +956,7 @@ public class OneCameraZslImpl extends AbstractOneCamera {
         // Waits Settings3A.getFocusHoldMillis() milliseconds before sending
         // a request for a regular preview stream to resume.
         mCameraHandler.postAtTime(new Runnable() {
-            @Override
+                @Override
             public void run() {
                 mAERegions = ZERO_WEIGHT_3A_REGION;
                 mAFRegions = ZERO_WEIGHT_3A_REGION;