feat(exposure): adjustment support in Camera1(Camera API) (#2163)

This commit is contained in:
Neha Gupta 2019-03-25 20:00:08 +05:30 committed by Sibelius Seraphini
parent ffe5b3744c
commit ca35ac609d
6 changed files with 79 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Build;
import android.support.v4.util.SparseArrayCompat;
import android.util.Log;
import android.view.SurfaceHolder;
import com.facebook.react.bridge.ReadableMap;
@ -96,6 +97,8 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
private int mFlash;
private int mExposure;
private int mDisplayOrientation;
private int mDeviceOrientation;
@ -330,6 +333,22 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
return mFlash;
}
@Override
int getExposureCompensation() {
return mExposure;
}
@Override
void setExposureCompensation(int exposure) {
if (exposure == mExposure) {
return;
}
if (setExposureInternal(exposure)) {
mCamera.setParameters(mCameraParameters);
}
}
@Override
public void setFocusDepth(float value) {
// not supported for Camera1
@ -646,6 +665,7 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
setAutoFocusInternal(mAutoFocus);
setFlashInternal(mFlash);
setExposureInternal(mExposure);
setAspectRatio(mAspectRatio);
setZoomInternal(mZoom);
setWhiteBalanceInternal(mWhiteBalance);
@ -791,6 +811,24 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
}
}
private boolean setExposureInternal(int exposure) {
Log.e("CAMERA_1::", ""+isCameraOpened()+"; Exposure: "+exposure);
if (isCameraOpened()){
mExposure = exposure;
int minExposure = mCameraParameters.getMinExposureCompensation();
int maxExposure = mCameraParameters.getMaxExposureCompensation();
Log.e("CAMERA_1::", ""+minExposure);
Log.e("CAMERA_1::", ""+maxExposure);
if (minExposure != maxExposure) {
mCameraParameters.setExposureCompensation(mExposure);
return true;
}
}
return false;
}
/**
* @return {@code true} if {@link #mCameraParameters} was modified.
*/

View File

@ -231,6 +231,8 @@ class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, Me
private int mFlash;
private int mExposure;
private int mCameraOrientation;
private int mDisplayOrientation;
@ -467,6 +469,17 @@ class Camera2 extends CameraViewImpl implements MediaRecorder.OnInfoListener, Me
return mFlash;
}
@Override
int getExposureCompensation() {
return mExposure;
}
@Override
void setExposureCompensation(int exposure) {
Log.e("CAMERA_2:: ", "Adjusting exposure is not currently supported for Camera2");
}
@Override
void takePicture(ReadableMap options) {
mCaptureCallback.setOptions(options);

View File

@ -220,6 +220,7 @@ public class CameraView extends FrameLayout {
state.ratio = getAspectRatio();
state.autoFocus = getAutoFocus();
state.flash = getFlash();
state.exposure = getExposureCompensation();
state.focusDepth = getFocusDepth();
state.zoom = getZoom();
state.whiteBalance = getWhiteBalance();
@ -240,6 +241,7 @@ public class CameraView extends FrameLayout {
setAspectRatio(ss.ratio);
setAutoFocus(ss.autoFocus);
setFlash(ss.flash);
setExposureCompensation(ss.exposure);
setFocusDepth(ss.focusDepth);
setZoom(ss.zoom);
setWhiteBalance(ss.whiteBalance);
@ -473,6 +475,15 @@ public class CameraView extends FrameLayout {
return mImpl.getFlash();
}
public void setExposureCompensation(int exposure) {
mImpl.setExposureCompensation(exposure);
}
public int getExposureCompensation() {
return mImpl.getExposureCompensation();
}
/**
* Gets the camera orientation relative to the devices native orientation.
*
@ -629,6 +640,8 @@ public class CameraView extends FrameLayout {
@Flash
int flash;
int exposure;
float focusDepth;
float zoom;
@ -646,6 +659,7 @@ public class CameraView extends FrameLayout {
ratio = source.readParcelable(loader);
autoFocus = source.readByte() != 0;
flash = source.readInt();
exposure = source.readInt();
focusDepth = source.readFloat();
zoom = source.readFloat();
whiteBalance = source.readInt();
@ -664,6 +678,7 @@ public class CameraView extends FrameLayout {
out.writeParcelable(ratio, 0);
out.writeByte((byte) (autoFocus ? 1 : 0));
out.writeInt(flash);
out.writeInt(exposure);
out.writeFloat(focusDepth);
out.writeFloat(zoom);
out.writeInt(whiteBalance);

View File

@ -76,6 +76,10 @@ abstract class CameraViewImpl {
abstract int getFlash();
abstract void setExposureCompensation(int exposure);
abstract int getExposureCompensation();
abstract void takePicture(ReadableMap options);
abstract boolean record(String path, int maxDuration, int maxFileSize,

View File

@ -82,6 +82,11 @@ public class CameraViewManager extends ViewGroupManager<RNCameraView> {
view.setFlash(torchMode);
}
@ReactProp(name = "exposure")
public void setExposureCompensation(RNCameraView view, int exposure){
view.setExposureCompensation(exposure);
}
@ReactProp(name = "autoFocus")
public void setAutoFocus(RNCameraView view, boolean autoFocus) {
view.setAutoFocus(autoFocus);

View File

@ -149,6 +149,7 @@ type PropsType = typeof View.props & {
onGoogleVisionBarcodesDetected?: Function,
faceDetectionMode?: number,
flashMode?: number | string,
exposure?: number,
barCodeTypes?: Array<string>,
googleVisionBarcodeType?: number,
googleVisionBarcodeMode?: number,
@ -257,6 +258,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
static ConversionTables = {
type: CameraManager.Type,
flashMode: CameraManager.FlashMode,
exposure: CameraManager.Exposure,
autoFocus: CameraManager.AutoFocus,
whiteBalance: CameraManager.WhiteBalance,
faceDetectionMode: (CameraManager.FaceDetection || {}).Mode,
@ -287,6 +289,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
googleVisionBarcodeMode: PropTypes.number,
type: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
flashMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
exposure: PropTypes.number,
whiteBalance: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
autoFocus: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
autoFocusPointOfInterest: PropTypes.shape({ x: PropTypes.number, y: PropTypes.number }),
@ -310,6 +313,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
type: CameraManager.Type.back,
autoFocus: CameraManager.AutoFocus.on,
flashMode: CameraManager.FlashMode.off,
exposure: 0,
whiteBalance: CameraManager.WhiteBalance.auto,
faceDetectionMode: (CameraManager.FaceDetection || {}).fast,
barCodeTypes: Object.values(CameraManager.BarCodeType),