Add camera focus distances API.
Applications can use this API to estimate the distance between the subject and the camera. bug:1955650 Change-Id: Ie6c8ea4971759cab6c9bcdda2c5ceb5925791c27
This commit is contained in:
@ -75570,6 +75570,19 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="getFocusDistances"
|
||||||
|
return="void"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="output" type="float[]">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
<method name="getFocusMode"
|
<method name="getFocusMode"
|
||||||
return="java.lang.String"
|
return="java.lang.String"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
@ -76492,6 +76505,39 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="FOCUS_DISTANCE_FAR_INDEX"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="2"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="FOCUS_DISTANCE_NEAR_INDEX"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="0"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="FOCUS_DISTANCE_OPTIMAL_INDEX"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="1"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
<field name="FOCUS_MODE_AUTO"
|
<field name="FOCUS_MODE_AUTO"
|
||||||
type="java.lang.String"
|
type="java.lang.String"
|
||||||
transient="false"
|
transient="false"
|
||||||
|
@ -762,6 +762,8 @@ public class Camera {
|
|||||||
private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
|
private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
|
||||||
private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
|
private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
|
||||||
private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
|
private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
|
||||||
|
private static final String KEY_FOCUS_DISTANCES = "focus-distances";
|
||||||
|
|
||||||
// Parameter key suffix for supported values.
|
// Parameter key suffix for supported values.
|
||||||
private static final String SUPPORTED_VALUES_SUFFIX = "-values";
|
private static final String SUPPORTED_VALUES_SUFFIX = "-values";
|
||||||
|
|
||||||
@ -874,10 +876,30 @@ public class Camera {
|
|||||||
*/
|
*/
|
||||||
public static final String FOCUS_MODE_EDOF = "edof";
|
public static final String FOCUS_MODE_EDOF = "edof";
|
||||||
|
|
||||||
|
// Indices for focus distance array.
|
||||||
|
/**
|
||||||
|
* The array index of near focus distance for use with
|
||||||
|
* {@link #getFocusDistances(float[])}.
|
||||||
|
*/
|
||||||
|
public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The array index of optimal focus distance for use with
|
||||||
|
* {@link #getFocusDistances(float[])}.
|
||||||
|
*/
|
||||||
|
public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The array index of far focus distance for use with
|
||||||
|
* {@link #getFocusDistances(float[])}.
|
||||||
|
*/
|
||||||
|
public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Continuous focus mode. The camera continuously tries to focus. This
|
* Continuous focus mode. The camera continuously tries to focus. This
|
||||||
* is ideal for shooting video or shooting photo of moving object.
|
* is ideal for shooting video or shooting photo of moving object.
|
||||||
* Continuous focus starts when {@link #autoFocus(AutoFocusCallback)} is
|
* Continuous focus starts when {@link #autoFocus(AutoFocusCallback)} is
|
||||||
|
* called. Continuous focus stops when {@link #cancelAutoFocus()} is
|
||||||
* called. AutoFocusCallback will be only called once as soon as the
|
* called. AutoFocusCallback will be only called once as soon as the
|
||||||
* picture is in focus.
|
* picture is in focus.
|
||||||
*/
|
*/
|
||||||
@ -1814,6 +1836,42 @@ public class Camera {
|
|||||||
return TRUE.equals(str);
|
return TRUE.equals(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the distances from the camera to where an object appears to be
|
||||||
|
* in focus. The object is sharpest at the optimal focus distance. The
|
||||||
|
* depth of field is the far focus distance minus near focus distance.
|
||||||
|
*
|
||||||
|
* Focus distances may change after calling {@link
|
||||||
|
* #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
|
||||||
|
* #startPreview()}. Applications can call {@link #getParameters()}
|
||||||
|
* and this method anytime to get the latest focus distances. If the
|
||||||
|
* focus mode is FOCUS_MODE_EDOF, the values may be all 0, which means
|
||||||
|
* focus distance is not applicable. If the focus mode is
|
||||||
|
* FOCUS_MODE_CONTINUOUS and autofocus has started, focus distances may
|
||||||
|
* change from time to time.
|
||||||
|
*
|
||||||
|
* Far focus distance > optimal focus distance > near focus distance. If
|
||||||
|
* the far focus distance is infinity, the value will be
|
||||||
|
* Float.POSITIVE_INFINITY.
|
||||||
|
*
|
||||||
|
* @param output focus distances in meters. output must be a float
|
||||||
|
* array with three elements. Near focus distance, optimal focus
|
||||||
|
* distance, and far focus distance will be filled in the array.
|
||||||
|
* @see #NEAR_FOCUS_DISTANCE_INDEX
|
||||||
|
* @see #OPTIMAL_FOCUS_DISTANCE_INDEX
|
||||||
|
* @see #FAR_FOCUS_DISTANCE_INDEX
|
||||||
|
*/
|
||||||
|
public void getFocusDistances(float[] output) {
|
||||||
|
if (output == null || output.length != 3) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"output must be an float array with three elements.");
|
||||||
|
}
|
||||||
|
List<Float> distances = splitFloat(get(KEY_FOCUS_DISTANCES));
|
||||||
|
output[0] = distances.get(0);
|
||||||
|
output[1] = distances.get(1);
|
||||||
|
output[2] = distances.get(2);
|
||||||
|
}
|
||||||
|
|
||||||
// Splits a comma delimited string to an ArrayList of String.
|
// Splits a comma delimited string to an ArrayList of String.
|
||||||
// Return null if the passing string is null or the size is 0.
|
// Return null if the passing string is null or the size is 0.
|
||||||
private ArrayList<String> split(String str) {
|
private ArrayList<String> split(String str) {
|
||||||
@ -1843,6 +1901,21 @@ public class Camera {
|
|||||||
return substrings;
|
return substrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Splits a comma delimited string to an ArrayList of Float.
|
||||||
|
// Return null if the passing string is null or the size is 0.
|
||||||
|
private ArrayList<Float> splitFloat(String str) {
|
||||||
|
if (str == null) return null;
|
||||||
|
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(str, ",");
|
||||||
|
ArrayList<Float> substrings = new ArrayList<Float>();
|
||||||
|
while (tokenizer.hasMoreElements()) {
|
||||||
|
String token = tokenizer.nextToken();
|
||||||
|
substrings.add(Float.parseFloat(token));
|
||||||
|
}
|
||||||
|
if (substrings.size() == 0) return null;
|
||||||
|
return substrings;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the value of a float parameter.
|
// Returns the value of a float parameter.
|
||||||
private float getFloat(String key, float defaultValue) {
|
private float getFloat(String key, float defaultValue) {
|
||||||
try {
|
try {
|
||||||
|
@ -221,9 +221,30 @@ public:
|
|||||||
// Example value: "true". Read only.
|
// Example value: "true". Read only.
|
||||||
static const char KEY_SMOOTH_ZOOM_SUPPORTED[];
|
static const char KEY_SMOOTH_ZOOM_SUPPORTED[];
|
||||||
|
|
||||||
|
// The distances (in meters) from the camera to where an object appears to
|
||||||
|
// be in focus. The object is sharpest at the optimal focus distance. The
|
||||||
|
// depth of field is the far focus distance minus near focus distance.
|
||||||
|
//
|
||||||
|
// Applications can read this parameter anytime to get the latest focus
|
||||||
|
// distances. If the focus mode is FOCUS_MODE_EDOF, the values may be all
|
||||||
|
// 0, which means focus distance is not applicable. If the focus mode is
|
||||||
|
// FOCUS_MODE_CONTINUOUS and autofocus has started, focus distances may
|
||||||
|
// change from time to time.
|
||||||
|
//
|
||||||
|
// Far focus distance > optimal focus distance > near focus distance. If
|
||||||
|
// the far focus distance is infinity, the value should be "Infinity" (case
|
||||||
|
// sensitive). The format is three float values separated by commas. The
|
||||||
|
// first is near focus distance. The second is optimal focus distance. The
|
||||||
|
// third is far focus distance.
|
||||||
|
// Example value: "0.95,1.9,Infinity" or "0.049,0.05,0.051". Read only.
|
||||||
|
static const char KEY_FOCUS_DISTANCES[];
|
||||||
|
|
||||||
// Value for KEY_ZOOM_SUPPORTED or KEY_SMOOTH_ZOOM_SUPPORTED.
|
// Value for KEY_ZOOM_SUPPORTED or KEY_SMOOTH_ZOOM_SUPPORTED.
|
||||||
static const char TRUE[];
|
static const char TRUE[];
|
||||||
|
|
||||||
|
// Value for KEY_FOCUS_DISTANCES.
|
||||||
|
static const char INFINITY[];
|
||||||
|
|
||||||
// Values for white balance settings.
|
// Values for white balance settings.
|
||||||
static const char WHITE_BALANCE_AUTO[];
|
static const char WHITE_BALANCE_AUTO[];
|
||||||
static const char WHITE_BALANCE_INCANDESCENT[];
|
static const char WHITE_BALANCE_INCANDESCENT[];
|
||||||
|
@ -69,8 +69,10 @@ const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom";
|
|||||||
const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios";
|
const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios";
|
||||||
const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported";
|
const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported";
|
||||||
const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported";
|
const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported";
|
||||||
|
const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances";
|
||||||
|
|
||||||
const char CameraParameters::TRUE[] = "true";
|
const char CameraParameters::TRUE[] = "true";
|
||||||
|
const char CameraParameters::INFINITY[] = "Infinity";
|
||||||
|
|
||||||
// Values for white balance settings.
|
// Values for white balance settings.
|
||||||
const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto";
|
const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto";
|
||||||
|
Reference in New Issue
Block a user