Exposure correction support

pull/1/head
Mattia Iavarone 7 years ago
parent 3e98daa26b
commit df9d86ce91
  1. 55
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  2. 1
      camerakit/src/main/base/com/flurgle/camerakit/CameraController.java
  3. 45
      camerakit/src/main/base/com/flurgle/camerakit/CameraOptions.java
  4. 21
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -654,23 +654,39 @@ class Camera1 extends CameraController {
} }
// ----------------- // -----------------
// Zoom stuff. // Zoom and simpler stuff.
@Override @Override
boolean setZoom(float zoom) { boolean setZoom(float zoom) {
if (!isCameraOpened()) return false; if (!isCameraOpened()) return false;
if (!mOptions.isZoomSupported()) return false;
synchronized (mLock) { synchronized (mLock) {
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
if (!mOptions.isZoomSupported()) return false;
float max = params.getMaxZoom(); float max = params.getMaxZoom();
params.setZoom((int) (zoom * max)); params.setZoom((int) (zoom * max));
mCamera.setParameters(params); mCamera.setParameters(params);
return true;
} }
return true;
} }
@Override
boolean setExposureCorrection(float EVvalue) {
if (!isCameraOpened()) return false;
if (!mOptions.isExposureCorrectionSupported()) return false;
float max = mOptions.getExposureCorrectionMaxValue();
float min = mOptions.getExposureCorrectionMinValue();
EVvalue = EVvalue < min ? min : EVvalue > max ? max : EVvalue; // cap
synchronized (mLock) {
Camera.Parameters params = mCamera.getParameters();
int indexValue = (int) (EVvalue / params.getExposureCompensationStep());
params.setExposureCompensation(indexValue);
mCamera.setParameters(params);
}
return true;
}
// ----------------- // -----------------
// Tap to focus stuff. // Tap to focus stuff.
@ -681,25 +697,22 @@ class Camera1 extends CameraController {
List<Camera.Area> meteringAreas2 = computeMeteringAreas(x, y); List<Camera.Area> meteringAreas2 = computeMeteringAreas(x, y);
List<Camera.Area> meteringAreas1 = meteringAreas2.subList(0, 1); List<Camera.Area> meteringAreas1 = meteringAreas2.subList(0, 1);
synchronized (mLock) { synchronized (mLock) {
// At this point we are sure that camera supports auto focus... right? Look at CameraView.onTouchEvent().
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
// TODO remove this check once CameraView.setFocus TODO is fixed. int maxAF = params.getMaxNumFocusAreas();
boolean autofocusSupported = mOptions.getSupportedFocus().contains(CameraConstants.FOCUS_TAP); int maxAE = params.getMaxNumMeteringAreas();
if (autofocusSupported) { if (maxAF > 0) params.setFocusAreas(maxAF > 1 ? meteringAreas2 : meteringAreas1);
int maxAF = params.getMaxNumFocusAreas(); if (maxAE > 0) params.setMeteringAreas(maxAE > 1 ? meteringAreas2 : meteringAreas1);
int maxAE = params.getMaxNumMeteringAreas(); params.setFocusMode((String) mMapper.mapFocus(FOCUS_TAP)); // auto
if (maxAF > 0) params.setFocusAreas(maxAF > 1 ? meteringAreas2 : meteringAreas1); mCamera.setParameters(params);
if (maxAE > 0) params.setMeteringAreas(maxAE > 1 ? meteringAreas2 : meteringAreas1); mCameraCallbacks.dispatchOnFocusStart(x, y);
params.setFocusMode((String) mMapper.mapFocus(FOCUS_TAP)); // auto mCamera.autoFocus(new Camera.AutoFocusCallback() {
mCamera.setParameters(params); @Override
mCameraCallbacks.dispatchOnFocusStart(x, y); public void onAutoFocus(boolean success, Camera camera) {
mCamera.autoFocus(new Camera.AutoFocusCallback() { mCameraCallbacks.dispatchOnFocusEnd(success, x, y);
@Override postResetFocus();
public void onAutoFocus(boolean success, Camera camera) { }
mCameraCallbacks.dispatchOnFocusEnd(success, x, y); });
postResetFocus();
}
});
}
} }
} }

@ -30,6 +30,7 @@ abstract class CameraController implements Preview.SurfaceCallback {
abstract void onDeviceOrientation(int deviceOrientation); abstract void onDeviceOrientation(int deviceOrientation);
abstract boolean setZoom(float zoom); abstract boolean setZoom(float zoom);
abstract boolean setExposureCorrection(float EVvalue);
abstract void setFacing(@Facing int facing); abstract void setFacing(@Facing int facing);
abstract void setFlash(@Flash int flash); abstract void setFlash(@Flash int flash);
abstract void setFocus(@Focus int focus); abstract void setFocus(@Focus int focus);

@ -23,6 +23,9 @@ public class CameraOptions {
private boolean zoomSupported; private boolean zoomSupported;
private boolean videoSnapshotSupported; private boolean videoSnapshotSupported;
private boolean exposureCorrectionSupported;
private float exposureCorrectionMinValue;
private float exposureCorrectionMaxValue;
// Camera1 constructor. // Camera1 constructor.
@ -62,6 +65,13 @@ public class CameraOptions {
zoomSupported = params.isZoomSupported(); zoomSupported = params.isZoomSupported();
videoSnapshotSupported = params.isVideoSnapshotSupported(); videoSnapshotSupported = params.isVideoSnapshotSupported();
// Exposure correction
float step = params.getExposureCompensationStep();
exposureCorrectionMinValue = (float) params.getMinExposureCompensation() * step;
exposureCorrectionMaxValue = (float) params.getMaxExposureCompensation() * step;
exposureCorrectionSupported = params.getMinExposureCompensation() != 0
|| params.getMaxExposureCompensation() != 0;
} }
@ -149,4 +159,39 @@ public class CameraOptions {
public boolean isVideoSnapshotSupported() { public boolean isVideoSnapshotSupported() {
return videoSnapshotSupported; return videoSnapshotSupported;
} }
/**
* Whether exposure correction is supported. If this is false, calling
* {@link CameraView#setExposureCorrection(float)} has no effect.
*
* @see #getExposureCorrectionMinValue()
* @see #getExposureCorrectionMaxValue()
* @return whether exposure correction is supported.
*/
public boolean isExposureCorrectionSupported() {
return exposureCorrectionSupported;
}
/**
* The minimum value of negative exposure correction, in EV stops.
* This is presumably negative or 0 if not supported.
*
* @return min EV value
*/
public float getExposureCorrectionMinValue() {
return exposureCorrectionMinValue;
}
/**
* The maximum value of positive exposure correction, in EV stops.
* This is presumably positive or 0 if not supported.
*
* @return max EV value
*/
public float getExposureCorrectionMaxValue() {
return exposureCorrectionMaxValue;
}
} }

@ -509,6 +509,24 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
} }
/**
* Sets exposure adjustment, in EV stops. A positive value will mean brighter picture.
*
* If camera is not opened, this will have no effect.
* If {@link CameraOptions#isExposureCorrectionSupported()} is false, this will have no effect.
* The provided value should be between the bounds returned by {@link CameraOptions}, or it will
* be capped.
*
* @see CameraOptions#getExposureCorrectionMinValue()
* @see CameraOptions#getExposureCorrectionMaxValue()
*
* @param EVvalue exposure correction value.
*/
public void setExposureCorrection(float EVvalue) {
mCameraController.setExposureCorrection(EVvalue);
}
/** /**
* Sets a zoom value. This is not guaranteed to be supported by the current device, * Sets a zoom value. This is not guaranteed to be supported by the current device,
* but you can take a look at {@link CameraOptions#isZoomSupported()}. * but you can take a look at {@link CameraOptions#isZoomSupported()}.
@ -523,8 +541,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
throw new IllegalArgumentException("Zoom value should be >= 0 and <= 1"); throw new IllegalArgumentException("Zoom value should be >= 0 and <= 1");
} }
if (mCameraController.setZoom(zoom)) { if (mCameraController.setZoom(zoom)) {
// Notify PinchToZoomLayout, just in case the call came from outside. mPinchToZoomLayout.onExternalZoom(zoom); // Notify PinchToZoomLayout
mPinchToZoomLayout.onExternalZoom(zoom);
} }
} }

Loading…
Cancel
Save