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:
parent
a54ff5782c
commit
c3039c94c6
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,13 @@ extension AVCaptureDevice.Format {
|
|||||||
"maxFrameRate": $0.maxFrameRate,
|
"maxFrameRate": $0.maxFrameRate,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"pixelFormat": CMFormatDescriptionGetMediaSubType(formatDescription).toString()
|
||||||
]
|
]
|
||||||
|
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
dict["isHighestPhotoQualitySupported"] = self.isHighestPhotoQualitySupported
|
dict["isHighestPhotoQualitySupported"] = self.isHighestPhotoQualitySupported
|
||||||
}
|
}
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
ios/Extensions/FourCharCode+toString.swift
Normal file
17
ios/Extensions/FourCharCode+toString.swift
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
@ -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
7
src/PixelFormat.ts
Normal 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';
|
Loading…
Reference in New Issue
Block a user