diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java index e18bb76e..f6401253 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java @@ -56,7 +56,6 @@ public class CameraOptions { private Set supportedVideoAspectRatio = new HashSet<>(3); private boolean zoomSupported; - private float maxZoomValue; private boolean exposureCorrectionSupported; private float exposureCorrectionMinValue; private float exposureCorrectionMaxValue; @@ -204,8 +203,7 @@ public class CameraOptions { //zoom Float maxZoom = cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); if(maxZoom != null) { - maxZoomValue = maxZoom; - zoomSupported = maxZoomValue > 1; + zoomSupported = maxZoom > 1; } @@ -485,15 +483,4 @@ public class CameraOptions { public float getExposureCorrectionMaxValue() { return exposureCorrectionMaxValue; } - - /** - * The maximum value of digital zoom available by Hardware. - * This is presumably 1 and above than 1 in case zoom is avaible. - * - * @return max zoom value - */ - @SuppressWarnings("WeakerAccess") - public float getMaxZoomValue() { - return maxZoomValue; - } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java index 31f2897c..af55a93d 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java @@ -924,14 +924,22 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv public void run() { if (getEngineState() == STATE_STARTED && mCameraOptions.isZoomSupported()) { - Rect newRect = getZoomRect(zoom * mCameraOptions.getMaxZoomValue()); - mRepeatingRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, newRect); - applyRepeatingRequestBuilder(); - mZoomValue = zoom; + Float maxZoom = mCameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); - if (notify) { - mCallback.dispatchOnZoomChanged(zoom, points); + if (maxZoom != null) { + //converting 0.0f-1.0f zoom scale to the actual camera digital zoom scale + //(which will be for example, 1.0-10.0) + float calculatedZoom = (zoom * (maxZoom - 1.0f)) + 1.0f; + + Rect newRect = getZoomRect(calculatedZoom, maxZoom); + mRepeatingRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, newRect); + applyRepeatingRequestBuilder(); + mZoomValue = zoom; + + if (notify) { + mCallback.dispatchOnZoomChanged(zoom, points); + } } } @@ -941,19 +949,16 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv } @NonNull - private Rect getZoomRect(float zoomLevel) { + private Rect getZoomRect(float zoomLevel, float maxDigitalZoom) { - float maxZoom = mCameraOptions.getMaxZoomValue(); Rect activeRect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); - if ((zoomLevel <= maxZoom) && (zoomLevel > 1) && activeRect != null) { - int minW = (int) (activeRect.width() / maxZoom); - int minH = (int) (activeRect.height() / maxZoom); + if ((zoomLevel <= maxDigitalZoom) && (zoomLevel > 1) && activeRect != null) { + int minW = (int) (activeRect.width() / maxDigitalZoom); + int minH = (int) (activeRect.height() / maxDigitalZoom); int difW = activeRect.width() - minW; int difH = activeRect.height() - minH; - int cropW = difW / 100 * (int) zoomLevel; - int cropH = difH / 100 * (int) zoomLevel; - cropW -= cropW & 3; - cropH -= cropH & 3; + int cropW = difW / 20 * (int) zoomLevel; + int cropH = difH / 20 * (int) zoomLevel; return new Rect(cropW, cropH, activeRect.width() - cropW, activeRect.height() - cropH); } @@ -961,8 +966,23 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv } @Override - public void setExposureCorrection(float EVvalue, @NonNull float[] bounds, @Nullable PointF[] points, boolean notify) { - // TODO + public void setExposureCorrection(final float EVvalue, @NonNull final float[] bounds, @Nullable final PointF[] points, final boolean notify) { + mHandler.run(new Runnable() { + @Override + public void run() { + + if (getEngineState() == STATE_STARTED && mCameraOptions.isExposureCorrectionSupported()) { + mRepeatingRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) EVvalue); + applyRepeatingRequestBuilder(); + + mExposureCorrectionValue = EVvalue; + if (notify) { + mCallback.dispatchOnExposureCorrectionChanged(EVvalue, bounds, points); + } + } + mExposureCorrectionOp.end(null); + } + }); } //endregion @@ -1264,5 +1284,4 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv }; //endregion -} - +} \ No newline at end of file