OSDN Git Service

Fall back to bounds if provided width/height is 0
authorAlan Newberger <alann@google.com>
Mon, 11 May 2015 17:10:26 +0000 (10:10 -0700)
committerAlan Newberger <alann@google.com>
Mon, 11 May 2015 18:11:08 +0000 (11:11 -0700)
Monkey results show async dimensions can lag behind
automated filmstrip. Protect against this case, should
reduce monkey issues.

Bug: 21023148
Change-Id: I8fef5e8d00f96c4b4c249b3a9daebfcf9991e193

src/com/android/camera/util/CameraUtil.java

index eb4f788..a2a5a7d 100644 (file)
@@ -993,10 +993,18 @@ public class CameraUtil {
         p.x = boundWidth;
         p.y = boundHeight;
 
-        if (imageWidth * boundHeight > boundWidth * imageHeight) {
-            p.y = imageHeight * p.x / imageWidth;
+        // In some cases like automated testing, image height/width may not be
+        // loaded, to avoid divide by zero fall back to provided bounds.
+        if (imageWidth != 0 && imageHeight != 0) {
+            if (imageWidth * boundHeight > boundWidth * imageHeight) {
+                p.y = imageHeight * p.x / imageWidth;
+            } else {
+                p.x = imageWidth * p.y / imageHeight;
+            }
         } else {
-            p.x = imageWidth * p.y / imageHeight;
+            Log.w(TAG, "zero width/height, falling back to bounds (w|h|bw|bh):"
+                    + imageWidth + "|" + imageHeight + "|" + boundWidth + "|"
+                    + boundHeight);
         }
 
         return p;