Commit a0b90fd7 authored by mcasas's avatar mcasas Committed by Commit bot

ImageCapture - PhotoCapabilities.java: add an inner Builder class

Cleanup: PhotoCapabilities is starting to have too many
parameters, so this CL adds a builder for it.

BUG=518807

Review-Url: https://codereview.chromium.org/2272653004
Cr-Commit-Position: refs/heads/master@{#414438}
parent 6f57e3ef
...@@ -27,7 +27,6 @@ class PhotoCapabilities { ...@@ -27,7 +27,6 @@ class PhotoCapabilities {
public final int focusMode; public final int focusMode;
public final int exposureMode; public final int exposureMode;
// TODO(mcasas): Add a PhotoCapabilitiesBuilder to this class.
PhotoCapabilities(int maxIso, int minIso, int currentIso, int maxHeight, int minHeight, PhotoCapabilities(int maxIso, int minIso, int currentIso, int maxHeight, int minHeight,
int currentHeight, int maxWidth, int minWidth, int currentWidth, int maxZoom, int currentHeight, int maxWidth, int minWidth, int currentWidth, int maxZoom,
int minZoom, int currentZoom, int focusMode, int exposureMode) { int minZoom, int currentZoom, int focusMode, int exposureMode) {
...@@ -116,4 +115,99 @@ class PhotoCapabilities { ...@@ -116,4 +115,99 @@ class PhotoCapabilities {
public int getExposureMode() { public int getExposureMode() {
return exposureMode; return exposureMode;
} }
public static class Builder {
public int maxIso;
public int minIso;
public int currentIso;
public int maxHeight;
public int minHeight;
public int currentHeight;
public int maxWidth;
public int minWidth;
public int currentWidth;
public int maxZoom;
public int minZoom;
public int currentZoom;
public int focusMode;
public int exposureMode;
public Builder() {}
public Builder setMaxIso(int maxIso) {
this.maxIso = maxIso;
return this;
}
public Builder setMinIso(int minIso) {
this.minIso = minIso;
return this;
}
public Builder setCurrentIso(int currentIso) {
this.currentIso = currentIso;
return this;
}
public Builder setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
return this;
}
public Builder setMinHeight(int minHeight) {
this.minHeight = minHeight;
return this;
}
public Builder setCurrentHeight(int currentHeight) {
this.currentHeight = currentHeight;
return this;
}
public Builder setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
return this;
}
public Builder setMinWidth(int minWidth) {
this.minWidth = minWidth;
return this;
}
public Builder setCurrentWidth(int currentWidth) {
this.currentWidth = currentWidth;
return this;
}
public Builder setMaxZoom(int maxZoom) {
this.maxZoom = maxZoom;
return this;
}
public Builder setMinZoom(int minZoom) {
this.minZoom = minZoom;
return this;
}
public Builder setCurrentZoom(int currentZoom) {
this.currentZoom = currentZoom;
return this;
}
public Builder setFocusMode(int focusMode) {
this.focusMode = focusMode;
return this;
}
public Builder setExposureMode(int exposureMode) {
this.exposureMode = exposureMode;
return this;
}
public PhotoCapabilities build() {
return new PhotoCapabilities(maxIso, minIso, currentIso, maxHeight, minHeight,
currentHeight, maxWidth, minWidth, currentWidth, maxZoom, minZoom, currentZoom,
focusMode, exposureMode);
}
}
} }
...@@ -301,14 +301,13 @@ public abstract class VideoCaptureCamera ...@@ -301,14 +301,13 @@ public abstract class VideoCaptureCamera
@Override @Override
public PhotoCapabilities getPhotoCapabilities() { public PhotoCapabilities getPhotoCapabilities() {
final android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera); final android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder();
Log.i(TAG, " CAM params: %s", parameters.flatten()); Log.i(TAG, " CAM params: %s", parameters.flatten());
// Before the Camera2 API there was no official way to retrieve the supported, if any, ISO // Before the Camera2 API there was no official way to retrieve the supported, if any, ISO
// values from |parameters|; some platforms had "iso-values", others "iso-mode-values" etc. // values from |parameters|; some platforms had "iso-values", others "iso-mode-values" etc.
// Ignore them. // Ignore them.
final int maxIso = 0; builder.setMinIso(0).setMaxIso(0).setCurrentIso(0);
final int currentIso = 0;
final int minIso = 0;
List<android.hardware.Camera.Size> supportedSizes = parameters.getSupportedPictureSizes(); List<android.hardware.Camera.Size> supportedSizes = parameters.getSupportedPictureSizes();
int minWidth = Integer.MAX_VALUE; int minWidth = Integer.MAX_VALUE;
...@@ -321,7 +320,11 @@ public abstract class VideoCaptureCamera ...@@ -321,7 +320,11 @@ public abstract class VideoCaptureCamera
if (size.width > maxWidth) maxWidth = size.width; if (size.width > maxWidth) maxWidth = size.width;
if (size.height > maxHeight) maxHeight = size.height; if (size.height > maxHeight) maxHeight = size.height;
} }
builder.setMinHeight(minHeight).setMaxHeight(maxHeight);
builder.setMinWidth(minWidth).setMaxWidth(maxWidth);
final android.hardware.Camera.Size currentSize = parameters.getPreviewSize(); final android.hardware.Camera.Size currentSize = parameters.getPreviewSize();
builder.setCurrentHeight(currentSize.height);
builder.setCurrentWidth(currentSize.width);
int maxZoom = 0; int maxZoom = 0;
int currentZoom = 0; int currentZoom = 0;
...@@ -332,6 +335,7 @@ public abstract class VideoCaptureCamera ...@@ -332,6 +335,7 @@ public abstract class VideoCaptureCamera
currentZoom = 100 + 100 * parameters.getZoom(); currentZoom = 100 + 100 * parameters.getZoom();
minZoom = parameters.getZoomRatios().get(0); minZoom = parameters.getZoomRatios().get(0);
} }
builder.setMinZoom(minZoom).setMaxZoom(maxZoom).setCurrentZoom(currentZoom);
Log.d(TAG, "parameters.getFocusMode(): %s", parameters.getFocusMode()); Log.d(TAG, "parameters.getFocusMode(): %s", parameters.getFocusMode());
final String focusMode = parameters.getFocusMode(); final String focusMode = parameters.getFocusMode();
...@@ -351,6 +355,7 @@ public abstract class VideoCaptureCamera ...@@ -351,6 +355,7 @@ public abstract class VideoCaptureCamera
|| focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_FIXED)) { || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_FIXED)) {
jniFocusMode = AndroidMeteringMode.FIXED; jniFocusMode = AndroidMeteringMode.FIXED;
} }
builder.setFocusMode(jniFocusMode);
// Exposure is usually continuously updated except it not available at all, or if the // Exposure is usually continuously updated except it not available at all, or if the
// exposure compensation is locked, in which case we consider it as FIXED. // exposure compensation is locked, in which case we consider it as FIXED.
...@@ -360,12 +365,12 @@ public abstract class VideoCaptureCamera ...@@ -360,12 +365,12 @@ public abstract class VideoCaptureCamera
if (parameters.isAutoExposureLockSupported() && parameters.getAutoExposureLock()) { if (parameters.isAutoExposureLockSupported() && parameters.getAutoExposureLock()) {
jniExposureMode = AndroidMeteringMode.FIXED; jniExposureMode = AndroidMeteringMode.FIXED;
} }
builder.setExposureMode(jniExposureMode);
// TODO(mcasas): https://crbug.com/518807 read the exposure compensation min and max // TODO(mcasas): https://crbug.com/518807 read the exposure compensation min and max
// values using getMinExposureCompensation() and getMaxExposureCompensation(). // values using getMinExposureCompensation() and getMaxExposureCompensation().
return new PhotoCapabilities(minIso, maxIso, currentIso, maxHeight, minHeight, return builder.build();
currentSize.height, maxWidth, minWidth, currentSize.width, maxZoom, minZoom,
currentZoom, jniFocusMode, jniExposureMode);
} }
@Override @Override
......
...@@ -572,6 +572,7 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -572,6 +572,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
public PhotoCapabilities getPhotoCapabilities() { public PhotoCapabilities getPhotoCapabilities() {
final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mContext, mId); final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mContext, mId);
PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder();
int minIso = 0; int minIso = 0;
int maxIso = 0; int maxIso = 0;
...@@ -581,7 +582,8 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -581,7 +582,8 @@ public class VideoCaptureCamera2 extends VideoCapture {
minIso = iso_range.getLower(); minIso = iso_range.getLower();
maxIso = iso_range.getUpper(); maxIso = iso_range.getUpper();
} }
final int currentIso = mPreviewRequest.get(CaptureRequest.SENSOR_SENSITIVITY); builder.setMinIso(minIso).setMaxIso(maxIso);
builder.setCurrentIso(mPreviewRequest.get(CaptureRequest.SENSOR_SENSITIVITY));
final StreamConfigurationMap streamMap = final StreamConfigurationMap streamMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
...@@ -596,8 +598,10 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -596,8 +598,10 @@ public class VideoCaptureCamera2 extends VideoCapture {
if (size.getWidth() > maxWidth) maxWidth = size.getWidth(); if (size.getWidth() > maxWidth) maxWidth = size.getWidth();
if (size.getHeight() > maxHeight) maxHeight = size.getHeight(); if (size.getHeight() > maxHeight) maxHeight = size.getHeight();
} }
final int currentHeight = (mPhotoHeight > 0) ? mPhotoHeight : mCaptureFormat.getHeight(); builder.setMinHeight(minHeight).setMaxHeight(maxHeight);
final int currentWidth = (mPhotoWidth > 0) ? mPhotoWidth : mCaptureFormat.getWidth(); builder.setMinWidth(minWidth).setMaxWidth(maxWidth);
builder.setCurrentHeight((mPhotoHeight > 0) ? mPhotoHeight : mCaptureFormat.getHeight());
builder.setCurrentWidth((mPhotoWidth > 0) ? mPhotoWidth : mCaptureFormat.getWidth());
// The Min and Max zoom are returned as x100 by the API to avoid using floating point. There // The Min and Max zoom are returned as x100 by the API to avoid using floating point. There
// is no min-zoom per se, so clamp it to always 100 (TODO(mcasas): make const member). // is no min-zoom per se, so clamp it to always 100 (TODO(mcasas): make const member).
...@@ -608,6 +612,7 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -608,6 +612,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
* cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE) * cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
.width() .width()
/ mPreviewRequest.get(CaptureRequest.SCALER_CROP_REGION).width(); / mPreviewRequest.get(CaptureRequest.SCALER_CROP_REGION).width();
builder.setMinZoom(minZoom).setMaxZoom(maxZoom).setCurrentZoom(currentZoom);
final int focusMode = mPreviewRequest.get(CaptureRequest.CONTROL_AF_MODE); final int focusMode = mPreviewRequest.get(CaptureRequest.CONTROL_AF_MODE);
// Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we can call // Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we can call
...@@ -624,6 +629,7 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -624,6 +629,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
} else { } else {
assert jniFocusMode == CameraMetadata.CONTROL_AF_MODE_EDOF; assert jniFocusMode == CameraMetadata.CONTROL_AF_MODE_EDOF;
} }
builder.setFocusMode(jniFocusMode);
int jniExposureMode = AndroidMeteringMode.CONTINUOUS; int jniExposureMode = AndroidMeteringMode.CONTINUOUS;
if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_MODE) if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_MODE)
...@@ -633,12 +639,12 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -633,12 +639,12 @@ public class VideoCaptureCamera2 extends VideoCapture {
if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_LOCK)) { if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_LOCK)) {
jniExposureMode = AndroidMeteringMode.FIXED; jniExposureMode = AndroidMeteringMode.FIXED;
} }
builder.setFocusMode(jniExposureMode);
// TODO(mcasas): https://crbug.com/518807 read the exposure compensation min and max // TODO(mcasas): https://crbug.com/518807 read the exposure compensation min and max
// values using CONTROL_AE_COMPENSATION_RANGE. // values using CONTROL_AE_COMPENSATION_RANGE.
return new PhotoCapabilities(minIso, maxIso, currentIso, maxHeight, minHeight, return builder.build();
currentHeight, maxWidth, minWidth, currentWidth, maxZoom, minZoom, currentZoom,
jniFocusMode, jniExposureMode);
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment