diff --git a/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt b/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt index db2f049..be04151 100644 --- a/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt +++ b/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt @@ -244,6 +244,9 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase } } + // TODO: Get the pixel format programatically rather than assuming a default of 420v + val pixelFormat = "420v" + val format = Arguments.createMap() format.putDouble("photoHeight", size.height.toDouble()) format.putDouble("photoWidth", size.width.toDouble()) @@ -260,6 +263,7 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase format.putArray("frameRateRanges", frameRateRanges) format.putString("autoFocusSystem", "none") // TODO: Revisit getAvailableCameraDevices (autoFocusSystem) (CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES or CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION) format.putArray("videoStabilizationModes", videoStabilizationModes) + format.putString("pixelFormat", pixelFormat) formats.pushMap(format) } } diff --git a/ios/Extensions/AVCaptureDevice.Format+toDictionary.swift b/ios/Extensions/AVCaptureDevice.Format+toDictionary.swift index dd98528..f256520 100644 --- a/ios/Extensions/AVCaptureDevice.Format+toDictionary.swift +++ b/ios/Extensions/AVCaptureDevice.Format+toDictionary.swift @@ -42,12 +42,13 @@ extension AVCaptureDevice.Format { "maxFrameRate": $0.maxFrameRate, ] }, + "pixelFormat": CMFormatDescriptionGetMediaSubType(formatDescription).toString() ] if #available(iOS 13.0, *) { dict["isHighestPhotoQualitySupported"] = self.isHighestPhotoQualitySupported } - + return dict } } diff --git a/ios/Extensions/FourCharCode+toString.swift b/ios/Extensions/FourCharCode+toString.swift new file mode 100644 index 0000000..fcb4d77 --- /dev/null +++ b/ios/Extensions/FourCharCode+toString.swift @@ -0,0 +1,17 @@ +// +// FourCharCode+toString.swift +// VisionCamera +// +// Created by Thomas Coldwell on 28/10/2021. +// Based off this SO answer: https://stackoverflow.com/a/25625744 +// + +extension FourCharCode { + func toString() -> String { + var s: String = String (UnicodeScalar((self >> 24) & 255)!) + s.append(String(UnicodeScalar((self >> 16) & 255)!)) + s.append(String(UnicodeScalar((self >> 8) & 255)!)) + s.append(String(UnicodeScalar(self & 255)!)) + return (s) + } +} diff --git a/src/CameraDevice.ts b/src/CameraDevice.ts index 7bd73ad..92602e8 100644 --- a/src/CameraDevice.ts +++ b/src/CameraDevice.ts @@ -1,4 +1,5 @@ import type { CameraPosition } from './CameraPosition'; +import type { PixelFormat } from './PixelFormat'; /** * Indentifiers for a physical camera (one that actually exists on the back/front of the device) @@ -171,6 +172,10 @@ export interface CameraDeviceFormat { * All supported video stabilization modes */ videoStabilizationModes: VideoStabilizationMode[]; + /** + * Specifies the pixel format on iOS. e.g. 420v, 420f + */ + pixelFormat: PixelFormat; } /** diff --git a/src/PixelFormat.ts b/src/PixelFormat.ts new file mode 100644 index 0000000..731f3ea --- /dev/null +++ b/src/PixelFormat.ts @@ -0,0 +1,7 @@ +/** + * Represents the pixel format of a `Frame`. + * * `420v`: 420 YpCbCr 8 Bi-Planar Video Range + * * `420f`: 420 YpCbCr 8 Bi-Planar Full Range + * * `x420`: 420 YpCbCr 10 Bi-Planar Video Range + */ +export type PixelFormat = '420f' | '420v' | 'x420';