From 615b75f3351065845f95f6a2339461813f530ae9 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Mon, 14 Oct 2013 18:20:43 -0700 Subject: 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 --- .../camera2/impl/CameraMetadataNative.java | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'core/java/android') 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 get(Key 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 getOverride(Key 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 void setBase(Key key, T value) { int tag = key.getTag(); @@ -559,7 +580,7 @@ public class CameraMetadataNative extends CameraMetadata implements Parcelable { // Set the camera metadata override. private boolean setOverride(Key key, T value) { - if (key == CameraCharacteristics.SCALER_AVAILABLE_FORMATS) { + if (key.equals(CameraCharacteristics.SCALER_AVAILABLE_FORMATS)) { return setAvailableFormats((int[]) value); } -- cgit v1.1