feat: Add pixelFormat field (#559)

* Add `mediaSubType` field to device formats

* Create FourCharCode `toString` extension

* Move pixelFormat -> `AVCaptureDevice.Format+toDictionary`

* `mediaSubType` -> `pixelFormat` + non-optional

* ts pixelFormat `string` -> specific formats

* Add default pixelFormat value of `420v` on Android

Co-authored-by: tcoldwell72 <31568400+tcoldwell72@users.noreply.github.com>
This commit is contained in:
Thomas Coldwell 2021-12-10 08:44:30 +00:00 committed by GitHub
parent a54ff5782c
commit c3039c94c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 1 deletions

View File

@ -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() val format = Arguments.createMap()
format.putDouble("photoHeight", size.height.toDouble()) format.putDouble("photoHeight", size.height.toDouble())
format.putDouble("photoWidth", size.width.toDouble()) format.putDouble("photoWidth", size.width.toDouble())
@ -260,6 +263,7 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
format.putArray("frameRateRanges", frameRateRanges) 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.putString("autoFocusSystem", "none") // TODO: Revisit getAvailableCameraDevices (autoFocusSystem) (CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES or CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION)
format.putArray("videoStabilizationModes", videoStabilizationModes) format.putArray("videoStabilizationModes", videoStabilizationModes)
format.putString("pixelFormat", pixelFormat)
formats.pushMap(format) formats.pushMap(format)
} }
} }

View File

@ -42,6 +42,7 @@ extension AVCaptureDevice.Format {
"maxFrameRate": $0.maxFrameRate, "maxFrameRate": $0.maxFrameRate,
] ]
}, },
"pixelFormat": CMFormatDescriptionGetMediaSubType(formatDescription).toString()
] ]
if #available(iOS 13.0, *) { if #available(iOS 13.0, *) {

View File

@ -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)
}
}

View File

@ -1,4 +1,5 @@
import type { CameraPosition } from './CameraPosition'; 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) * 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 * All supported video stabilization modes
*/ */
videoStabilizationModes: VideoStabilizationMode[]; videoStabilizationModes: VideoStabilizationMode[];
/**
* Specifies the pixel format on iOS. e.g. 420v, 420f
*/
pixelFormat: PixelFormat;
} }
/** /**

7
src/PixelFormat.ts Normal file
View File

@ -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';