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.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index 627b6bf01..3a7e355c2 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -30,6 +30,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Point;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.camera2.CameraCharacteristics;
@@ -322,6 +323,7 @@ public class CameraUtil {
}
public static int nextPowerOf2(int n) {
+ // TODO: what happens if n is negative or already a power of 2?
n -= 1;
n |= n >>> 16;
n |= n >>> 8;
@@ -337,6 +339,10 @@ public class CameraUtil {
return (float) Math.sqrt(dx * dx + dy * dy);
}
+ /**
+ * Clamps x to between min and max (inclusive on both ends, x = min --> min,
+ * x = max --> max).
+ */
public static int clamp(int x, int min, int max) {
if (x > max) {
return max;
@@ -347,6 +353,10 @@ public class CameraUtil {
return x;
}
+ /**
+ * Clamps x to between min and max (inclusive on both ends, x = min --> min,
+ * x = max --> max).
+ */
public static float clamp(float x, float min, float max) {
if (x > max) {
return max;
@@ -366,6 +376,31 @@ public class CameraUtil {
}
/**
+ * Given (nx, ny) \in [0, 1]^2, in the display's portrait coordinate system,
+ * returns normalized sensor coordinates \in [0, 1]^2 depending on how
+ * the sensor's orientation \in {0, 90, 180, 270}.
+ *
+ * <p>
+ * Returns null if sensorOrientation is not one of the above.
+ * </p>
+ */
+ public static PointF normalizedSensorCoordsForNormalizedDisplayCoords(
+ float nx, float ny, int sensorOrientation) {
+ switch (sensorOrientation) {
+ case 0:
+ return new PointF(nx, ny);
+ case 90:
+ return new PointF(ny, 1.0f - nx);
+ case 180:
+ return new PointF(1.0f - nx, 1.0f - ny);
+ case 270:
+ return new PointF(1.0f - ny, nx);
+ default:
+ return null;
+ }
+ }
+
+ /**
* Given a size, return the largest size with the given aspectRatio that
* maximally fits into the bounding rectangle of the original Size.
*