diff options
author | Eino-Ville Talvala <etalvala@google.com> | 2013-10-14 18:20:43 -0700 |
---|---|---|
committer | Eino-Ville Talvala <etalvala@google.com> | 2013-10-14 18:20:43 -0700 |
commit | 615b75f3351065845f95f6a2339461813f530ae9 (patch) | |
tree | db1321f38869612d8325b3e721d0d43d52162019 /core/java/android | |
parent | 1680cfd803d6a435ce4c809075d052da2723ac07 (diff) | |
download | frameworks_base-615b75f3351065845f95f6a2339461813f530ae9.zip frameworks_base-615b75f3351065845f95f6a2339461813f530ae9.tar.gz frameworks_base-615b75f3351065845f95f6a2339461813f530ae9.tar.bz2 |
Camera2: Fix face rectangle coordinate mapping, and use Key.equals
- Faces are reported differently from other rectangles, so the mapping
has to be specialized for them
- Use Key.equals for key comparison.
Bug: 11206459
Change-Id: I9a2a408dad981c2911048191ec30977020953146
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/hardware/camera2/impl/CameraMetadataNative.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java index adccbc5..e87d387 100644 --- a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java +++ b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java @@ -93,7 +93,7 @@ public class CameraMetadataNative extends CameraMetadata implements Parcelable { @Override public <T> T get(Key<T> key) { - if (key == CaptureResult.STATISTICS_FACES) { + if (key.equals(CaptureResult.STATISTICS_FACES)) { /** * FIXME: Workaround for HAL bug that's missing FACE_DETECT_MODE */ @@ -452,10 +452,12 @@ public class CameraMetadataNative extends CameraMetadata implements Parcelable { // and managed sides. @SuppressWarnings("unchecked") private <T> T getOverride(Key<T> key) { - if (key == CameraCharacteristics.SCALER_AVAILABLE_FORMATS) { + if (key.equals(CameraCharacteristics.SCALER_AVAILABLE_FORMATS)) { return (T) getAvailableFormats(); - } else if (key == CaptureResult.STATISTICS_FACES) { + } else if (key.equals(CaptureResult.STATISTICS_FACES)) { return (T) getFaces(); + } else if (key.equals(CaptureResult.STATISTICS_FACE_RECTANGLES)) { + return (T) fixFaceRectangles(); } // For other keys, get() falls back to getBase() @@ -536,6 +538,25 @@ public class CameraMetadataNative extends CameraMetadata implements Parcelable { return faces; } + // Face rectangles are defined as (left, top, right, bottom) instead of + // (left, top, width, height) at the native level, so the normal Rect + // conversion that does (l, t, w, h) -> (l, t, r, b) is unnecessary. Undo + // that conversion here for just the faces. + private Rect[] fixFaceRectangles() { + Rect[] faceRectangles = getBase(CaptureResult.STATISTICS_FACE_RECTANGLES); + if (faceRectangles == null) return null; + + Rect[] fixedFaceRectangles = new Rect[faceRectangles.length]; + for (int i = 0; i < faceRectangles.length; i++) { + fixedFaceRectangles[i] = new Rect( + faceRectangles[i].left, + faceRectangles[i].top, + faceRectangles[i].right - faceRectangles[i].left, + faceRectangles[i].bottom - faceRectangles[i].top); + } + return fixedFaceRectangles; + } + private <T> void setBase(Key<T> key, T value) { int tag = key.getTag(); @@ -559,7 +580,7 @@ public class CameraMetadataNative extends CameraMetadata implements Parcelable { // Set the camera metadata override. private <T> boolean setOverride(Key<T> key, T value) { - if (key == CameraCharacteristics.SCALER_AVAILABLE_FORMATS) { + if (key.equals(CameraCharacteristics.SCALER_AVAILABLE_FORMATS)) { return setAvailableFormats((int[]) value); } |