Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
fix(picture-size): create None default value
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfidelis committed Jun 7, 2018
1 parent 92e8ece commit ad87c8e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
11 changes: 9 additions & 2 deletions android/src/main/java/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,16 @@ SortedSet<Size> getAvailablePictureSizes(AspectRatio ratio) {

@Override
void setPictureSize(Size size) {
mPictureSize = size;
if (size == null) {
if (mAspectRatio == null) {
return;
}
mPictureSize = mPictureSizes.sizes(mAspectRatio).last();
} else {
mPictureSize = size;
}
if (mCameraParameters != null && mCamera != null) {
mCameraParameters.setPictureSize(size.getWidth(), size.getHeight());
mCameraParameters.setPictureSize(mPictureSize.getWidth(), mPictureSize.getHeight());
mCamera.setParameters(mCameraParameters);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,14 @@ void setPictureSize(Size size) {
if (mStillImageReader != null) {
mStillImageReader.close();
}
mPictureSize = size;
if (size == null) {
if (mAspectRatio == null) {
return;
}
mPictureSizes.sizes(mAspectRatio).last();
} else {
mPictureSize = size;
}
prepareStillImageReader();
startCaptureSession();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void setWhiteBalance(RNCameraView view, int whiteBalance) {

@ReactProp(name = "pictureSize")
public void setPictureSize(RNCameraView view, String size) {
view.setPictureSize(Size.parse(size));
view.setPictureSize(size.equals("None") ? null : Size.parse(size));
}

@ReactProp(name = "barCodeTypes")
Expand Down
22 changes: 15 additions & 7 deletions android/src/main/java/org/reactnative/camera/RNCameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,38 @@ public void onFramePreview(CameraView cameraView, byte[] data, int width, int he
int correctWidth = width;
int correctHeight = height;
byte[] correctData = data;
boolean willCallBarCodeTask = mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate;
boolean willCallFaceTask = mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate;
boolean willCallGoogleBarcodeTask = mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate;
boolean willCallTextTask = mShouldRecognizeText && !textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate;
if (!willCallBarCodeTask && !willCallFaceTask && !willCallGoogleBarcodeTask && !willCallTextTask) {
return;
}

if (correctRotation == 90) {
correctWidth = height;
correctHeight = width;
correctData = rotateImage(data, correctHeight, correctWidth);
correctWidth = height;
correctHeight = width;
correctData = rotateImage(data, correctHeight, correctWidth);
}
if (mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate) {
if (willCallBarCodeTask) {
barCodeScannerTaskLock = true;
BarCodeScannerAsyncTaskDelegate delegate = (BarCodeScannerAsyncTaskDelegate) cameraView;
new BarCodeScannerAsyncTask(delegate, mMultiFormatReader, correctData, correctWidth, correctHeight).execute();
}

if (mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate) {
if (willCallFaceTask) {
faceDetectorTaskLock = true;
FaceDetectorAsyncTaskDelegate delegate = (FaceDetectorAsyncTaskDelegate) cameraView;
new FaceDetectorAsyncTask(delegate, mFaceDetector, correctData, correctWidth, correctHeight, correctRotation).execute();
}

if (mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate) {
if (willCallGoogleBarcodeTask) {
googleBarcodeDetectorTaskLock = true;
BarcodeDetectorAsyncTaskDelegate delegate = (BarcodeDetectorAsyncTaskDelegate) cameraView;
new BarcodeDetectorAsyncTask(delegate, mGoogleBarcodeDetector, correctData, correctWidth, correctHeight, correctRotation).execute();
}

if (mShouldRecognizeText && !textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate) {
if (willCallTextTask) {
textRecognizerTaskLock = true;
TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate) cameraView;
new TextRecognizerAsyncTask(delegate, mTextRecognizer, correctData, correctWidth, correctHeight, correctRotation).execute();
Expand Down
3 changes: 3 additions & 0 deletions ios/RN/RNCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ - (void)initializeCaptureSessionInput
- (void)updateSessionPreset:(AVCaptureSessionPreset)preset
{
#if !(TARGET_IPHONE_SIMULATOR)
if ([preset integerValue] < 0) {
return;
}
if (preset) {
if (self.isDetectingFaces && [preset isEqual:AVCaptureSessionPresetPhoto]) {
RCTLog(@"AVCaptureSessionPresetPhoto not supported during face detection. Falling back to AVCaptureSessionPresetHigh");
Expand Down
3 changes: 2 additions & 1 deletion ios/RN/RNCameraManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ + (NSDictionary *)pictureSizes
@"Photo" : AVCaptureSessionPresetPhoto,
@"High" : AVCaptureSessionPresetHigh,
@"Medium" : AVCaptureSessionPresetMedium,
@"Low" : AVCaptureSessionPresetLow
@"Low" : AVCaptureSessionPresetLow,
@"None": @(-1),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
captureAudio: false,
useCamera2Api: false,
playSoundOnCapture: false,
pictureSize: '1920x1080',
pictureSize: 'None',
videoStabilizationMode: 0,
};

Expand Down

0 comments on commit ad87c8e

Please sign in to comment.