summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/util/CameraUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/util/CameraUtil.java')
-rw-r--r--src/com/android/camera/util/CameraUtil.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index cfddf957e..4cfc211bc 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -567,6 +567,38 @@ public class CameraUtil {
return optimalSize;
}
+
+ // Returns the largest thumbnail size which matches the given aspect ratio.
+ public static Size getOptimalJpegThumbnailSize(
+ List<Size> sizes, double targetRatio) {
+ // Use a very small tolerance because we want an exact match.
+ final double ASPECT_TOLERANCE = 0.001;
+ if (sizes == null) return null;
+
+ Size optimalSize = null;
+
+ // Try to find a size matches aspect ratio and has the largest width
+ for (Size size : sizes) {
+ double ratio = (double) size.width / size.height;
+ if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
+ if (optimalSize == null || size.width > optimalSize.width) {
+ optimalSize = size;
+ }
+ }
+
+ // Cannot find one that matches the aspect ratio. This should not happen.
+ // Ignore the requirement.
+ if (optimalSize == null) {
+ Log.w(TAG, "No thumbnail size match the aspect ratio");
+ for (Size size : sizes) {
+ if (optimalSize == null || size.width > optimalSize.width) {
+ optimalSize = size;
+ }
+ }
+ }
+ return optimalSize;
+ }
+
public static void dumpParameters(Parameters parameters) {
String flattened = parameters.flatten();
StringTokenizer tokenizer = new StringTokenizer(flattened, ";");