fix: Expose auto-focus system for Android (#2455)

* fix: Expose auto-focus system for Android

* Add `autoFocusSystem` to filter

* Update CameraDeviceDetails.kt

* Update getCameraFormat.ts
This commit is contained in:
Marc Rousavy
2024-01-30 10:49:28 +01:00
committed by GitHub
parent bdbcf05d14
commit b5eb01bac8
3 changed files with 28 additions and 2 deletions

View File

@@ -76,6 +76,7 @@ class CameraDeviceDetails(val cameraManager: CameraManager, val cameraId: String
characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION) ?: IntArray(0)
val supportsPhotoHdr = extensions.contains(3) // TODO: CameraExtensionCharacteristics.EXTENSION_HDR
val supportsVideoHdr = getHasVideoHdr()
val autoFocusSystem = getAutoFocusSystemMode()
val videoFormat = ImageFormat.YUV_420_888
@@ -132,6 +133,18 @@ class CameraDeviceDetails(val cameraManager: CameraManager, val cameraId: String
return deviceTypes
}
private fun getAutoFocusSystemMode(): AutoFocusSystem {
val supportedAFModes = characteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES)
val supportsAF = supportedAFModes?.contains(CameraCharacteristics.CONTROL_AF_MODE_AUTO) == true
if (!supportsAF) return AutoFocusSystem.NONE
val focusCalibrationSystem = characteristics.get(CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION)
return when (focusCalibrationSystem) {
CameraCharacteristics.LENS_INFO_FOCUS_DISTANCE_CALIBRATION_CALIBRATED -> AutoFocusSystem.PHASE_DETECTION
else -> AutoFocusSystem.CONTRAST_DETECTION
}
}
private fun getFieldOfView(focalLength: Float): Double {
val sensorDiagonal = sqrt((sensorSize.width * sensorSize.width + sensorSize.height * sensorSize.height).toDouble())
val fovRadians = 2.0 * atan2(sensorDiagonal, (2.0 * focalLength))
@@ -190,7 +203,7 @@ class CameraDeviceDetails(val cameraManager: CameraManager, val cameraId: String
map.putBoolean("supportsVideoHdr", supportsVideoHdr)
map.putBoolean("supportsPhotoHdr", supportsPhotoHdr)
map.putBoolean("supportsDepthCapture", supportsDepthCapture)
map.putString("autoFocusSystem", AutoFocusSystem.CONTRAST_DETECTION.unionValue)
map.putString("autoFocusSystem", autoFocusSystem.unionValue)
map.putArray("videoStabilizationModes", createStabilizationModes())
map.putArray("pixelFormats", createPixelFormats())
return map

View File

@@ -1,6 +1,7 @@
package com.mrousavy.camera.types
enum class AutoFocusSystem(override val unionValue: String) : JSUnionValue {
PHASE_DETECTION("phase-detection"),
CONTRAST_DETECTION("contrast-detection"),
NONE("none");