2021-02-20 09:07:10 -07:00
|
|
|
import type { CameraPosition } from './CameraPosition';
|
2021-12-10 01:44:30 -07:00
|
|
|
import type { PixelFormat } from './PixelFormat';
|
2021-02-19 08:07:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indentifiers for a physical camera (one that actually exists on the back/front of the device)
|
|
|
|
*
|
|
|
|
* * `"ultra-wide-angle-camera"`: A built-in camera with a shorter focal length than that of a wide-angle camera. (focal length between below 24mm)
|
|
|
|
* * `"wide-angle-camera"`: A built-in wide-angle camera. (focal length between 24mm and 35mm)
|
|
|
|
* * `"telephoto-camera"`: A built-in camera device with a longer focal length than a wide-angle camera. (focal length between above 85mm)
|
|
|
|
*/
|
2021-02-20 09:07:10 -07:00
|
|
|
export type PhysicalCameraDeviceType = 'ultra-wide-angle-camera' | 'wide-angle-camera' | 'telephoto-camera';
|
2021-02-19 08:07:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indentifiers for a logical camera (Combinations of multiple physical cameras to create a single logical camera).
|
|
|
|
*
|
|
|
|
* * `"dual-camera"`: A combination of wide-angle and telephoto cameras that creates a capture device.
|
|
|
|
* * `"dual-wide-camera"`: A device that consists of two cameras of fixed focal length, one ultrawide angle and one wide angle.
|
|
|
|
* * `"triple-camera"`: A device that consists of three cameras of fixed focal length, one ultrawide angle, one wide angle, and one telephoto.
|
|
|
|
*/
|
2021-03-17 08:30:17 -06:00
|
|
|
export type LogicalCameraDeviceType = 'dual-camera' | 'dual-wide-camera' | 'triple-camera';
|
2021-02-19 08:07:53 -07:00
|
|
|
|
|
|
|
/**
|
2021-03-08 10:51:53 -07:00
|
|
|
* Parses an array of physical device types into a single {@linkcode PhysicalCameraDeviceType} or {@linkcode LogicalCameraDeviceType}, depending what matches.
|
2021-03-03 04:37:43 -07:00
|
|
|
* @method
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
2021-03-31 07:43:29 -06:00
|
|
|
export const parsePhysicalDeviceTypes = (
|
|
|
|
physicalDeviceTypes: PhysicalCameraDeviceType[],
|
|
|
|
): PhysicalCameraDeviceType | LogicalCameraDeviceType => {
|
2021-02-20 09:11:17 -07:00
|
|
|
if (physicalDeviceTypes.length === 1) {
|
|
|
|
// @ts-expect-error for very obvious reasons
|
|
|
|
return physicalDeviceTypes[0];
|
|
|
|
}
|
2021-02-20 09:07:10 -07:00
|
|
|
|
|
|
|
const hasWide = physicalDeviceTypes.includes('wide-angle-camera');
|
|
|
|
const hasUltra = physicalDeviceTypes.includes('ultra-wide-angle-camera');
|
|
|
|
const hasTele = physicalDeviceTypes.includes('telephoto-camera');
|
|
|
|
|
2021-09-27 06:44:09 -06:00
|
|
|
if (hasTele && hasWide && hasUltra) return 'triple-camera';
|
2021-02-20 09:07:10 -07:00
|
|
|
if (hasWide && hasUltra) return 'dual-wide-camera';
|
|
|
|
if (hasWide && hasTele) return 'dual-camera';
|
|
|
|
|
|
|
|
throw new Error(`Invalid physical device type combination! ${physicalDeviceTypes.join(' + ')}`);
|
2021-02-19 08:07:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates a format's autofocus system.
|
|
|
|
*
|
|
|
|
* * `"none"`: Indicates that autofocus is not available
|
|
|
|
* * `"contrast-detection"`: Indicates that autofocus is achieved by contrast detection. Contrast detection performs a focus scan to find the optimal position
|
|
|
|
* * `"phase-detection"`: Indicates that autofocus is achieved by phase detection. Phase detection has the ability to achieve focus in many cases without a focus scan. Phase detection autofocus is typically less visually intrusive than contrast detection autofocus
|
|
|
|
*/
|
2021-02-20 09:07:10 -07:00
|
|
|
export type AutoFocusSystem = 'contrast-detection' | 'phase-detection' | 'none';
|
2021-02-19 08:07:53 -07:00
|
|
|
|
|
|
|
/**
|
2023-08-21 04:50:14 -06:00
|
|
|
* Indicates a format's supported video stabilization mode. Enabling video stabilization may introduce additional latency into the video capture pipeline.
|
2021-02-19 08:07:53 -07:00
|
|
|
*
|
2023-08-21 04:50:14 -06:00
|
|
|
* * `"off"`: No video stabilization. Indicates that video should not be stabilized
|
|
|
|
* * `"standard"`: Standard software-based video stabilization. Standard video stabilization reduces the field of view by about 10%.
|
|
|
|
* * `"cinematic"`: Advanced software-based video stabilization. This applies more aggressive cropping or transformations than standard.
|
|
|
|
* * `"cinematic-extended"`: Extended software- and hardware-based stabilization that aggressively crops and transforms the video to apply a smooth cinematic stabilization.
|
2021-02-19 08:07:53 -07:00
|
|
|
* * `"auto"`: Indicates that the most appropriate video stabilization mode for the device and format should be chosen automatically
|
|
|
|
*/
|
2021-02-20 09:07:10 -07:00
|
|
|
export type VideoStabilizationMode = 'off' | 'standard' | 'cinematic' | 'cinematic-extended' | 'auto';
|
2021-02-19 08:07:53 -07:00
|
|
|
|
|
|
|
/**
|
2021-03-08 10:51:53 -07:00
|
|
|
* A Camera Device's video format. Do not create instances of this type yourself, only use {@linkcode Camera.getAvailableCameraDevices | Camera.getAvailableCameraDevices()}.
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
2021-03-08 09:51:47 -07:00
|
|
|
export interface CameraDeviceFormat {
|
2021-02-19 08:07:53 -07:00
|
|
|
/**
|
|
|
|
* The height of the highest resolution a still image (photo) can be produced in
|
|
|
|
*/
|
|
|
|
photoHeight: number;
|
|
|
|
/**
|
|
|
|
* The width of the highest resolution a still image (photo) can be produced in
|
|
|
|
*/
|
|
|
|
photoWidth: number;
|
|
|
|
/**
|
|
|
|
* The video resolutions's height
|
|
|
|
*/
|
2021-07-08 02:59:27 -06:00
|
|
|
videoHeight: number;
|
2021-02-19 08:07:53 -07:00
|
|
|
/**
|
|
|
|
* The video resolution's width
|
|
|
|
*/
|
2021-07-08 02:59:27 -06:00
|
|
|
videoWidth: number;
|
2021-02-19 08:07:53 -07:00
|
|
|
/**
|
|
|
|
* Maximum supported ISO value
|
|
|
|
*/
|
|
|
|
maxISO: number;
|
|
|
|
/**
|
|
|
|
* Minimum supported ISO value
|
|
|
|
*/
|
|
|
|
minISO: number;
|
|
|
|
/**
|
|
|
|
* The video field of view in degrees
|
|
|
|
*/
|
|
|
|
fieldOfView: number;
|
|
|
|
/**
|
2021-07-29 03:44:22 -06:00
|
|
|
* The maximum zoom factor (e.g. `128`)
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
|
|
|
maxZoom: number;
|
|
|
|
/**
|
|
|
|
* Specifies whether this format supports HDR mode for video capture
|
|
|
|
*/
|
|
|
|
supportsVideoHDR: boolean;
|
|
|
|
/**
|
|
|
|
* Specifies whether this format supports HDR mode for photo capture
|
|
|
|
*/
|
|
|
|
supportsPhotoHDR: boolean;
|
|
|
|
/**
|
2023-08-21 04:50:14 -06:00
|
|
|
* The minum frame rate this Format needs to run at. High resolution formats often run at lower frame rates.
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
2023-08-21 04:50:14 -06:00
|
|
|
minFps: number;
|
|
|
|
/**
|
|
|
|
* The maximum frame rate this Format is able to run at. High resolution formats often run at lower frame rates.
|
|
|
|
*/
|
|
|
|
maxFps: number;
|
2021-02-19 08:07:53 -07:00
|
|
|
/**
|
|
|
|
* Specifies this format's auto focus system.
|
|
|
|
*/
|
|
|
|
autoFocusSystem: AutoFocusSystem;
|
|
|
|
/**
|
|
|
|
* All supported video stabilization modes
|
|
|
|
*/
|
|
|
|
videoStabilizationModes: VideoStabilizationMode[];
|
2021-12-10 01:44:30 -07:00
|
|
|
/**
|
2023-08-21 04:50:14 -06:00
|
|
|
* Specifies this format's supported pixel-formats.
|
|
|
|
* In most cases, this is `['native', 'yuv']`.
|
2021-12-10 01:44:30 -07:00
|
|
|
*/
|
2023-08-21 04:50:14 -06:00
|
|
|
pixelFormats: PixelFormat[];
|
2021-03-08 09:51:47 -07:00
|
|
|
}
|
2021-02-19 08:07:53 -07:00
|
|
|
|
|
|
|
/**
|
2021-03-08 10:51:53 -07:00
|
|
|
* Represents a camera device discovered by the {@linkcode Camera.getAvailableCameraDevices | Camera.getAvailableCameraDevices()} function
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
2021-03-08 09:51:47 -07:00
|
|
|
export interface CameraDevice {
|
2021-02-19 08:07:53 -07:00
|
|
|
/**
|
|
|
|
* The native ID of the camera device instance.
|
|
|
|
*/
|
|
|
|
id: string;
|
|
|
|
/**
|
|
|
|
* The physical devices this `CameraDevice` contains.
|
|
|
|
*
|
|
|
|
* * If this camera device is a **logical camera** (combination of multiple physical cameras), there are multiple cameras in this array.
|
|
|
|
* * If this camera device is a **physical camera**, there is only a single element in this array.
|
|
|
|
*
|
|
|
|
* You can check if the camera is a logical multi-camera by using the `isMultiCam` property.
|
|
|
|
*/
|
|
|
|
devices: PhysicalCameraDeviceType[];
|
|
|
|
/**
|
|
|
|
* Specifies the physical position of this camera. (back or front)
|
|
|
|
*/
|
|
|
|
position: CameraPosition;
|
|
|
|
/**
|
|
|
|
* A friendly localized name describing the camera.
|
|
|
|
*/
|
|
|
|
name: string;
|
|
|
|
/**
|
|
|
|
* Specifies whether this camera supports enabling flash for photo capture.
|
|
|
|
*/
|
|
|
|
hasFlash: boolean;
|
|
|
|
/**
|
|
|
|
* Specifies whether this camera supports continuously enabling the flash to act like a torch (flash with video capture)
|
|
|
|
*/
|
|
|
|
hasTorch: boolean;
|
|
|
|
/**
|
2021-07-29 02:14:50 -06:00
|
|
|
* A property indicating whether the device is a virtual multi-camera consisting of multiple combined physical cameras.
|
2021-02-19 08:07:53 -07:00
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* * The Dual Camera, which supports seamlessly switching between a wide and telephoto camera while zooming and generating depth data from the disparities between the different points of view of the physical cameras.
|
|
|
|
* * The TrueDepth Camera, which generates depth data from disparities between a YUV camera and an Infrared camera pointed in the same direction.
|
|
|
|
*/
|
|
|
|
isMultiCam: boolean;
|
|
|
|
/**
|
2021-07-29 03:44:22 -06:00
|
|
|
* Minimum available zoom factor (e.g. `1`)
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
|
|
|
minZoom: number;
|
|
|
|
/**
|
2021-07-29 03:44:22 -06:00
|
|
|
* Maximum available zoom factor (e.g. `128`)
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
|
|
|
maxZoom: number;
|
|
|
|
/**
|
2021-06-07 02:46:53 -06:00
|
|
|
* The zoom factor where the camera is "neutral".
|
2021-02-19 08:07:53 -07:00
|
|
|
*
|
2021-06-07 02:46:53 -06:00
|
|
|
* * For single-physical cameras this property is always `1.0`.
|
2021-07-29 03:44:22 -06:00
|
|
|
* * For multi cameras this property is a value between `minZoom` and `maxZoom`, where the camera is in _wide-angle_ mode and hasn't switched to the _ultra-wide-angle_ ("fish-eye") or telephoto camera yet.
|
2021-02-19 08:07:53 -07:00
|
|
|
*
|
|
|
|
* Use this value as an initial value for the zoom property if you implement custom zoom. (e.g. reanimated shared value should be initially set to this value)
|
2021-06-07 02:46:53 -06:00
|
|
|
* @example
|
|
|
|
* const device = ...
|
|
|
|
*
|
2021-07-29 03:44:22 -06:00
|
|
|
* const zoom = useSharedValue(device.neutralZoom) // <-- initial value so it doesn't start at ultra-wide
|
2021-06-07 02:46:53 -06:00
|
|
|
* const cameraProps = useAnimatedProps(() => ({
|
2021-07-29 03:44:22 -06:00
|
|
|
* zoom: zoom.value
|
2021-06-07 02:46:53 -06:00
|
|
|
* }))
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
|
|
|
neutralZoom: number;
|
|
|
|
/**
|
2021-03-23 08:49:58 -06:00
|
|
|
* All available formats for this camera device. Use this to find the best format for your use case and set it to the Camera's {@linkcode CameraProps.format | Camera's .format} property.
|
2021-03-08 10:51:53 -07:00
|
|
|
*
|
2023-03-06 03:03:40 -07:00
|
|
|
* See [the Camera Formats documentation](https://react-native-vision-camera.com/docs/guides/formats) for more information about Camera Formats.
|
2021-02-19 08:07:53 -07:00
|
|
|
*/
|
|
|
|
formats: CameraDeviceFormat[];
|
|
|
|
/**
|
|
|
|
* Whether this camera device supports low light boost.
|
|
|
|
*/
|
|
|
|
supportsLowLightBoost: boolean;
|
2021-03-17 11:07:05 -06:00
|
|
|
/**
|
|
|
|
* Whether this camera supports taking photos with depth data.
|
|
|
|
*
|
|
|
|
* **! Work in Progress !**
|
|
|
|
*/
|
|
|
|
supportsDepthCapture: boolean;
|
|
|
|
/**
|
|
|
|
* Whether this camera supports taking photos in RAW format
|
|
|
|
*
|
|
|
|
* **! Work in Progress !**
|
|
|
|
*/
|
|
|
|
supportsRawCapture: boolean;
|
|
|
|
/**
|
2021-06-07 07:55:20 -06:00
|
|
|
* Specifies whether this device supports focusing ({@linkcode Camera.focus | Camera.focus(...)})
|
2021-03-17 11:07:05 -06:00
|
|
|
*/
|
|
|
|
supportsFocus: boolean;
|
2023-08-21 04:50:14 -06:00
|
|
|
/**
|
|
|
|
* The hardware level of the Camera.
|
|
|
|
* - On Android, some older devices are running at a `legacy` or `limited` level which means they are running in a backwards compatible mode.
|
|
|
|
* - On iOS, all devices are `full`.
|
|
|
|
*/
|
|
|
|
hardwareLevel: 'legacy' | 'limited' | 'full';
|
2021-03-08 09:51:47 -07:00
|
|
|
}
|