summaryrefslogtreecommitdiffstats
path: root/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
diff options
context:
space:
mode:
Diffstat (limited to 'camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java')
-rw-r--r--camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java81
1 files changed, 76 insertions, 5 deletions
diff --git a/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java b/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
index 7f6cffe..0062097 100644
--- a/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
+++ b/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
@@ -18,7 +18,9 @@ package com.android.ex.camera2.portability;
import static android.hardware.camera2.CaptureRequest.*;
+import android.graphics.Matrix;
import android.graphics.Rect;
+import android.graphics.RectF;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.params.MeteringRectangle;
@@ -43,8 +45,12 @@ public class AndroidCamera2Settings extends CameraSettings {
private final Builder mTemplateSettings;
private final Camera2RequestSettingsSet mRequestSettings;
+ /** Sensor's active array bounds. */
private final Rect mActiveArray;
+ /** Crop rectangle for digital zoom (measured WRT the active array). */
private final Rect mCropRectangle;
+ /** Bounds of visible preview portion (measured WRT the active array). */
+ private Rect mVisiblePreviewRectangle;
/**
* Create a settings representation that answers queries of unspecified
@@ -84,6 +90,8 @@ public class AndroidCamera2Settings extends CameraSettings {
mActiveArray = activeArray;
mCropRectangle = new Rect(0, 0, activeArray.width(), activeArray.height());
+ mSizesLocked = false;
+
Range<Integer> previewFpsRange = mTemplateSettings.get(CONTROL_AE_TARGET_FPS_RANGE);
if (previewFpsRange != null) {
setPreviewFpsRange(previewFpsRange.getLower(), previewFpsRange.getUpper());
@@ -177,6 +185,8 @@ public class AndroidCamera2Settings extends CameraSettings {
@Override
public void setZoomRatio(float ratio) {
super.setZoomRatio(ratio);
+
+ // Compute the crop rectangle to be passed to the framework
mCropRectangle.set(0, 0,
toIntConstrained(
mActiveArray.width() / mCurrentZoomRatio, 0, mActiveArray.width()),
@@ -184,6 +194,10 @@ public class AndroidCamera2Settings extends CameraSettings {
mActiveArray.height() / mCurrentZoomRatio, 0, mActiveArray.height()));
mCropRectangle.offsetTo((mActiveArray.width() - mCropRectangle.width()) / 2,
(mActiveArray.height() - mCropRectangle.height()) / 2);
+
+ // Compute the effective crop rectangle to be used for computing focus/metering coordinates
+ mVisiblePreviewRectangle =
+ effectiveCropRectFromRequested(mCropRectangle, mCurrentPreviewSize);
}
private boolean matchesTemplateDefault(Key<?> setting) {
@@ -192,7 +206,7 @@ public class AndroidCamera2Settings extends CameraSettings {
} else if (setting == CONTROL_AF_REGIONS) {
return mFocusAreas.size() == 0;
} else if (setting == CONTROL_AE_TARGET_FPS_RANGE) {
- Range defaultFpsRange = mTemplateSettings.get(CONTROL_AE_TARGET_FPS_RANGE);
+ Range<Integer> defaultFpsRange = mTemplateSettings.get(CONTROL_AE_TARGET_FPS_RANGE);
return (mPreviewFpsRangeMin == 0 && mPreviewFpsRangeMax == 0) ||
(defaultFpsRange != null && mPreviewFpsRangeMin == defaultFpsRange.getLower() &&
mPreviewFpsRangeMax == defaultFpsRange.getUpper());
@@ -214,6 +228,11 @@ public class AndroidCamera2Settings extends CameraSettings {
} else if (setting == CONTROL_AWB_LOCK) {
return Objects.equals(mAutoWhiteBalanceLocked, mTemplateSettings.get(CONTROL_AWB_LOCK));
} else if (setting == JPEG_THUMBNAIL_SIZE) {
+ if (mExifThumbnailSize == null) {
+ // It doesn't matter if this is true or false since setting this
+ // to null in the request settings will use the default anyway.
+ return false;
+ }
android.util.Size defaultThumbnailSize = mTemplateSettings.get(JPEG_THUMBNAIL_SIZE);
return (mExifThumbnailSize.width() == 0 && mExifThumbnailSize.height() == 0) ||
(defaultThumbnailSize != null &&
@@ -259,9 +278,13 @@ public class AndroidCamera2Settings extends CameraSettings {
updateRequestSettingOrForceToDefault(CONTROL_AWB_LOCK, mAutoWhiteBalanceLocked);
// TODO: mRecordingHintEnabled
updateRequestGpsData();
- updateRequestSettingOrForceToDefault(JPEG_THUMBNAIL_SIZE,
- new android.util.Size(
- mExifThumbnailSize.width(), mExifThumbnailSize.height()));
+ if (mExifThumbnailSize != null) {
+ updateRequestSettingOrForceToDefault(JPEG_THUMBNAIL_SIZE,
+ new android.util.Size(
+ mExifThumbnailSize.width(), mExifThumbnailSize.height()));
+ } else {
+ updateRequestSettingOrForceToDefault(JPEG_THUMBNAIL_SIZE, null);
+ }
return mRequestSettings;
}
@@ -405,7 +428,10 @@ public class AndroidCamera2Settings extends CameraSettings {
mode = CONTROL_SCENE_MODE_FIREWORKS;
break;
}
- // TODO: We cannot support HDR
+ case HDR: {
+ mode = LegacyVendorTags.CONTROL_SCENE_MODE_HDR;
+ break;
+ }
case LANDSCAPE: {
mode = CONTROL_SCENE_MODE_LANDSCAPE;
break;
@@ -512,4 +538,49 @@ public class AndroidCamera2Settings extends CameraSettings {
mRequestSettings.set(JPEG_GPS_LOCATION, location);
}
}
+
+ /**
+ * Calculate the effective crop rectangle for this preview viewport;
+ * assumes the preview is centered to the sensor and scaled to fit across one of the dimensions
+ * without skewing.
+ *
+ * <p>Assumes the zoom level of the provided desired crop rectangle.</p>
+ *
+ * @param requestedCrop Desired crop rectangle, in active array space.
+ * @param previewSize Size of the preview buffer render target, in pixels (not in sensor space).
+ * @return A rectangle that serves as the preview stream's effective crop region (unzoomed), in
+ * sensor space.
+ *
+ * @throws NullPointerException
+ * If any of the args were {@code null}.
+ */
+ private static Rect effectiveCropRectFromRequested(Rect requestedCrop, Size previewSize) {
+ float aspectRatioArray = requestedCrop.width() * 1.0f / requestedCrop.height();
+ float aspectRatioPreview = previewSize.width() * 1.0f / previewSize.height();
+
+ float cropHeight, cropWidth;
+ if (aspectRatioPreview < aspectRatioArray) {
+ // The new width must be smaller than the height, so scale the width by AR
+ cropHeight = requestedCrop.height();
+ cropWidth = cropHeight * aspectRatioPreview;
+ } else {
+ // The new height must be smaller (or equal) than the width, so scale the height by AR
+ cropWidth = requestedCrop.width();
+ cropHeight = cropWidth / aspectRatioPreview;
+ }
+
+ Matrix translateMatrix = new Matrix();
+ RectF cropRect = new RectF(/*left*/0, /*top*/0, cropWidth, cropHeight);
+
+ // Now center the crop rectangle so its center is in the center of the active array
+ translateMatrix.setTranslate(requestedCrop.exactCenterX(), requestedCrop.exactCenterY());
+ translateMatrix.postTranslate(-cropRect.centerX(), -cropRect.centerY());
+
+ translateMatrix.mapRect(/*inout*/cropRect);
+
+ // Round the rect corners towards the nearest integer values
+ Rect result = new Rect();
+ cropRect.roundOut(result);
+ return result;
+ }
}