mirror of
https://github.com/status-im/react-native-camera.git
synced 2026-08-31 13:41:08 +00:00
Add 1080p, 720p, and 480p capture qualities. (#469)
* Add 1080p, 720p, and 480p capture qualities. * Minor improvements for picture/video sizing. - Minor refactoring for getting supported sizes (DRY). - Add explicit pictureSize setting for 480p/720p/1080p in still/picture mode. * Use util.Size objects for 480p/720p/1080p sizing. - Note using Camera.Size objects would require a camera instance prior to creating the size objects, which would be manageable but not too clean. * Remove 480p for iOS; 16:9/HD aspect ratio for Android 480p - iOS only has a 640x480 480p-like AVCaptureSessionPreset, which is not the typical 16:9/HD aspect ratio desired. Removing this option as a result of this. - Android 480p updated to use 16:9/HD aspect ratio. * Add notes for (in)exact sizing for 1080p/720p/480p * Re-add 480p on iOS, more notes on resolutions. - Add notes on non-HD-aspect-ratio for iOS 480p. - Add more explanation of variable resolution/sizes, especially for 480p on Android. * Use custom Resolution class to hold 480p/720p/1080p resolution sizes - Mistakenly used util.Size class before, which was not added until Android API level 21 (current min is 16).
This commit is contained in:
committed by
Nicolas Charpentier
parent
adb26f4524
commit
a2a6d028a4
@@ -17,6 +17,9 @@ public class RCTCamera {
|
||||
private final HashMap<Integer, CameraInfoWrapper> _cameraInfos;
|
||||
private final HashMap<Integer, Integer> _cameraTypeToIndex;
|
||||
private final Map<Number, Camera> _cameras;
|
||||
private static final Resolution RESOLUTION_480P = new Resolution(853, 480); // 480p shoots for a 16:9 HD aspect ratio, but can otherwise fall back/down to any other supported camera sizes, such as 800x480 or 720x480, if (any) present. See getSupportedPictureSizes/getSupportedVideoSizes below.
|
||||
private static final Resolution RESOLUTION_720P = new Resolution(1280, 720);
|
||||
private static final Resolution RESOLUTION_1080P = new Resolution(1920, 1080);
|
||||
private boolean _barcodeScannerEnabled = false;
|
||||
private List<String> _barCodeTypes = null;
|
||||
private int _orientation = -1;
|
||||
@@ -191,16 +194,26 @@ public class RCTCamera {
|
||||
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
Camera.Size pictureSize = null;
|
||||
List<Camera.Size> supportedSizes = parameters.getSupportedPictureSizes();
|
||||
switch (captureQuality) {
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_LOW:
|
||||
pictureSize = getSmallestSize(parameters.getSupportedPictureSizes());
|
||||
pictureSize = getSmallestSize(supportedSizes);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_MEDIUM:
|
||||
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
|
||||
pictureSize = sizes.get(sizes.size() / 2);
|
||||
pictureSize = supportedSizes.get(supportedSizes.size() / 2);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_HIGH:
|
||||
pictureSize = getBestSize(parameters.getSupportedPictureSizes(), Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pictureSize = getBestSize(supportedSizes, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_480P:
|
||||
pictureSize = getBestSize(supportedSizes, RESOLUTION_480P.width, RESOLUTION_480P.height);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_720P:
|
||||
pictureSize = getBestSize(supportedSizes, RESOLUTION_720P.width, RESOLUTION_720P.height);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_1080P:
|
||||
pictureSize = getBestSize(supportedSizes, RESOLUTION_1080P.width, RESOLUTION_1080P.height);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pictureSize != null) {
|
||||
@@ -216,20 +229,33 @@ public class RCTCamera {
|
||||
}
|
||||
|
||||
Camera.Size videoSize = null;
|
||||
List<Camera.Size> supportedSizes = getSupportedVideoSizes(camera);
|
||||
CamcorderProfile cm = null;
|
||||
switch (captureQuality) {
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_LOW:
|
||||
videoSize = getSmallestSize(getSupportedVideoSizes(camera));
|
||||
videoSize = getSmallestSize(supportedSizes);
|
||||
cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_480P);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_MEDIUM:
|
||||
List<Camera.Size> sizes = getSupportedVideoSizes(camera);
|
||||
videoSize = sizes.get(sizes.size() / 2);
|
||||
videoSize = supportedSizes.get(supportedSizes.size() / 2);
|
||||
cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_720P);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_HIGH:
|
||||
videoSize = getBestSize(getSupportedVideoSizes(camera), Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
videoSize = getBestSize(supportedSizes, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_HIGH);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_480P:
|
||||
videoSize = getBestSize(supportedSizes, RESOLUTION_480P.width, RESOLUTION_480P.height);
|
||||
cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_480P);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_720P:
|
||||
videoSize = getBestSize(supportedSizes, RESOLUTION_720P.width, RESOLUTION_720P.height);
|
||||
cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_720P);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_1080P:
|
||||
videoSize = getBestSize(supportedSizes, RESOLUTION_1080P.width, RESOLUTION_1080P.height);
|
||||
cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_1080P);
|
||||
break;
|
||||
}
|
||||
|
||||
if (cm == null){
|
||||
@@ -402,4 +428,14 @@ public class RCTCamera {
|
||||
this.info = info;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Resolution {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public Resolution(final int width, final int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,9 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_HIGH = "high";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_MEDIUM = "medium";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_LOW = "low";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_1080P = "1080p";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_720P = "720p";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_480P = "480p";
|
||||
public static final int MEDIA_TYPE_IMAGE = 1;
|
||||
public static final int MEDIA_TYPE_VIDEO = 2;
|
||||
|
||||
@@ -193,6 +196,9 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
put("medium", RCT_CAMERA_CAPTURE_QUALITY_MEDIUM);
|
||||
put("high", RCT_CAMERA_CAPTURE_QUALITY_HIGH);
|
||||
put("photo", RCT_CAMERA_CAPTURE_QUALITY_HIGH);
|
||||
put("480p", RCT_CAMERA_CAPTURE_QUALITY_480P);
|
||||
put("720p", RCT_CAMERA_CAPTURE_QUALITY_720P);
|
||||
put("1080p", RCT_CAMERA_CAPTURE_QUALITY_1080P);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user