public class ParameterUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ParameterUtils.MeteringData
Calculate effective/reported metering data from a user-specified metering region.
|
static class |
ParameterUtils.WeightedRectangle
A weighted rectangle is an arbitrary rectangle (the coordinate system is unknown) with an
arbitrary weight.
|
static class |
ParameterUtils.ZoomData
Calculate effective/reported zoom data from a user-specified crop region.
|
Modifier and Type | Field and Description |
---|---|
static Camera.Area |
CAMERA_AREA_DEFAULT
The default normalized area uses the default normalized rectangle with a weight=1
|
static Rect |
NORMALIZED_RECTANGLE_DEFAULT
The default normalized rectangle spans the entire size of the preview viewport
|
static int |
NORMALIZED_RECTANGLE_MAX
Lower/right maximal point of a normalized rectangle
|
static int |
NORMALIZED_RECTANGLE_MIN
Upper/left minimal point of a normalized rectangle
|
static Rect |
RECTANGLE_EMPTY
Empty rectangle
0x0+0,0 |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsSize(List<Camera.Size> sizeList,
int width,
int height)
Check if the camera API1 list of sizes contains a size with the given dimens.
|
static ParameterUtils.WeightedRectangle |
convertCameraAreaToActiveArrayRectangle(Rect activeArray,
ParameterUtils.ZoomData zoomData,
Camera.Area area)
Convert the normalized camera area from [-1000, 1000] coordinate space
into the active array-based coordinate space.
|
static Face |
convertFaceFromLegacy(Camera.Face face,
Rect activeArray,
ParameterUtils.ZoomData zoomData)
Convert an api1 face into an active-array based api2 face.
|
static ParameterUtils.MeteringData |
convertMeteringRectangleToLegacy(Rect activeArray,
MeteringRectangle meteringRect,
ParameterUtils.ZoomData zoomData)
Calculate the actual/effective/reported normalized rectangle data from a metering
rectangle.
|
static ParameterUtils.ZoomData |
convertScalerCropRegion(Rect activeArraySize,
Rect cropRegion,
Size previewSize,
Camera.Parameters params)
Convert the user-specified crop region into zoom data; which can be used
to set the parameters to a specific zoom index, or to report back to the user what the
actual zoom was, or for other calculations requiring the current preview crop region.
|
static Size |
convertSize(Camera.Size size)
Convert a camera API1 size into a util size
|
static List<Size> |
convertSizeList(List<Camera.Size> sizeList)
Convert a camera API1 list of sizes into a util list of sizes
|
static Size[] |
convertSizeListToArray(List<Camera.Size> sizeList)
Convert a camera API1 list of sizes into an array of sizes
|
static List<Rect> |
getAvailablePreviewZoomCropRectangles(Camera.Parameters params,
Rect activeArray,
Size previewSize)
Get the available 'crop' (zoom) rectangles for this camera.
|
static List<Rect> |
getAvailableZoomCropRectangles(Camera.Parameters params,
Rect activeArray)
Get the available 'crop' (zoom) rectangles for this camera that will be reported
via a
CaptureResult when a zoom is requested. |
static int |
getClosestAvailableZoomCrop(Camera.Parameters params,
Rect activeArray,
Size streamSize,
Rect cropRegion,
Rect reportedCropRegion,
Rect previewCropRegion)
Calculate the closest zoom index for the user-requested crop region by rounding
up to the closest (largest or equal) possible zoom crop.
|
static Size |
getLargestSupportedJpegSizeByArea(Camera.Parameters params)
Returns the largest supported picture size, as compared by its area.
|
static float |
getMaxZoomRatio(Camera.Parameters params)
Get the largest possible zoom ratio (normalized to
1.0f and higher)
that the camera can support. |
static String |
stringFromArea(Camera.Area area)
Convert a camera area into a human-readable string.
|
static String |
stringFromAreaList(List<Camera.Area> areaList)
Convert a camera area list into a human-readable string
|
public static final int NORMALIZED_RECTANGLE_MIN
public static final int NORMALIZED_RECTANGLE_MAX
public static final Rect NORMALIZED_RECTANGLE_DEFAULT
public static final Camera.Area CAMERA_AREA_DEFAULT
public static final Rect RECTANGLE_EMPTY
0x0+0,0
public static Size convertSize(Camera.Size size)
public static List<Size> convertSizeList(List<Camera.Size> sizeList)
public static Size[] convertSizeListToArray(List<Camera.Size> sizeList)
public static boolean containsSize(List<Camera.Size> sizeList, int width, int height)
public static Size getLargestSupportedJpegSizeByArea(Camera.Parameters params)
public static String stringFromArea(Camera.Area area)
public static String stringFromAreaList(List<Camera.Area> areaList)
areaList
- a list of areas (null is ok)public static int getClosestAvailableZoomCrop(Camera.Parameters params, Rect activeArray, Size streamSize, Rect cropRegion, Rect reportedCropRegion, Rect previewCropRegion)
If the requested crop region exceeds the size of the active array, it is shrunk to fit inside of the active array first.
Since all api1 camera devices only support a discrete set of zooms, we have to translate the per-pixel-granularity requested crop region into a per-zoom-index granularity.
Furthermore, since the zoom index and zoom levels also depends on the field-of-view
of the preview, the current preview streamSize
is also used.
The calculated crop regions are then written to in-place to reportedCropRegion
and previewCropRegion
, in coordinates relative to the active array.
params
- non-null
camera api1 parametersactiveArray
- active array dimensions, in sensor spacestreamSize
- stream size dimensions, in pixelscropRegion
- user-specified crop region, in active array coordinatesreportedCropRegion
- (out parameter) what the result for cropRegion
looks likepreviewCropRegion
- (out parameter) what the visual preview crop isParameters#getMaxZoom
,
where 0 means the camera is not zoomedNullPointerException
- if any of the args were null
public static List<Rect> getAvailableZoomCropRectangles(Camera.Parameters params, Rect activeArray)
CaptureResult
when a zoom is requested.
These crops ignores the underlying preview buffer size, and will always be reported the same values regardless of what configuration of outputs is used.
When zoom is supported, this will return a list of 1 + #getMaxZoom
size,
where each crop rectangle corresponds to a zoom ratio (and is centered at the middle).
Each crop rectangle is changed to have the same aspect ratio as streamSize
,
by shrinking the rectangle if necessary.
To get the reported crop region when applying a zoom to the sensor, use streamSize
= activeArray size
.
params
- non-null
camera api1 parametersactiveArray
- active array dimensions, in sensor spacestreamSize
- stream size dimensions, in pixelspublic static List<Rect> getAvailablePreviewZoomCropRectangles(Camera.Parameters params, Rect activeArray, Size previewSize)
This is the effective (real) crop that is applied by the camera api1 device when projecting the zoom onto the intermediate preview buffer. Use this when deciding which zoom ratio to apply.
When zoom is supported, this will return a list of 1 + #getMaxZoom
size,
where each crop rectangle corresponds to a zoom ratio (and is centered at the middle).
Each crop rectangle is changed to have the same aspect ratio as streamSize
,
by shrinking the rectangle if necessary.
To get the reported crop region when applying a zoom to the sensor, use streamSize
= activeArray size
.
params
- non-null
camera api1 parametersactiveArray
- active array dimensions, in sensor spacestreamSize
- stream size dimensions, in pixelspublic static float getMaxZoomRatio(Camera.Parameters params)
1.0f
and higher)
that the camera can support.
If the camera does not support zoom, it always returns 1.0f
.
params
- non-null
camera api1 parameters1.0f
public static ParameterUtils.ZoomData convertScalerCropRegion(Rect activeArraySize, Rect cropRegion, Size previewSize, Camera.Parameters params)
None of the parameters are mutated.
activeArraySize
- active array size of the sensor (e.g. max jpeg size)cropRegion
- the user-specified crop regionpreviewSize
- the current preview size (in pixels)params
- the current camera parameters (not mutated)public static ParameterUtils.MeteringData convertMeteringRectangleToLegacy(Rect activeArray, MeteringRectangle meteringRect, ParameterUtils.ZoomData zoomData)
If any of the rectangles are out-of-range of their intended bounding box,
the empty rectangle
is substituted instead
(with a weight of 0
).
The metering rectangle is bound by the crop region (effective/reported respectively).
The metering area
is bound by [-1000, 1000]
.
No parameters are mutated; returns the new metering data.
activeArraySize
- active array size of the sensor (e.g. max jpeg size)meteringRect
- the user-specified metering rectanglezoomData
- the calculated zoom data corresponding to this requestpublic static ParameterUtils.WeightedRectangle convertCameraAreaToActiveArrayRectangle(Rect activeArray, ParameterUtils.ZoomData zoomData, Camera.Area area)
Values out of range are clipped to be within the resulting (reported) crop region. It is possible to have values larger than the preview crop.
Weights out of range of [0, 1000] are clipped to be within the range.
activeArraySize
- active array size of the sensor (e.g. max jpeg size)zoomData
- the calculated zoom data corresponding to this requestarea
- the normalized camera areapublic static Face convertFaceFromLegacy(Camera.Face face, Rect activeArray, ParameterUtils.ZoomData zoomData)
Out-of-ranges scores and ids will be clipped to be within range (with a warning).
face
- a non-null
api1 faceactiveArraySize
- active array size of the sensor (e.g. max jpeg size)zoomData
- the calculated zoom data corresponding to this requestnull
api2 faceNullPointerException
- if the face
was null