fix: Consider everything between 24mm and 43mm a wide-angle lense (#1782)

* fix: Consider everything between 24mm and 43mm a wide-angle lense

* chore: Use Kotlin when API instead

* Use floats

* Catch error
This commit is contained in:
Marc Rousavy 2023-09-11 11:33:02 +02:00 committed by GitHub
parent f69e3dff36
commit a4ace351fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,27 +95,24 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
private val size35mm = Size(36, 24) private val size35mm = Size(36, 24)
private fun getDeviceTypes(): ReadableArray { private fun getDeviceTypes(): ReadableArray {
// TODO: Check if getDeviceType() works correctly, even for logical multi-cameras
// To get valid focal length standards we have to upscale to the 35mm measurement (film standard) // To get valid focal length standards we have to upscale to the 35mm measurement (film standard)
val cropFactor = size35mm.bigger / sensorSize.bigger val cropFactor = size35mm.bigger / sensorSize.bigger
val deviceTypes = Arguments.createArray() val deviceTypes = Arguments.createArray()
// https://en.wikipedia.org/wiki/Telephoto_lens focalLengths.forEach { focalLength ->
val containsTelephoto = focalLengths.any { l -> (l * cropFactor) > 35 } // TODO: Telephoto lenses are > 85mm, but we don't have anything between that range.. // scale to the 35mm film standard
// val containsNormalLens = focalLengths.any { l -> (l * cropFactor) > 35 && (l * cropFactor) <= 55 } val l = focalLength * cropFactor
// https://en.wikipedia.org/wiki/Wide-angle_lens when {
val containsWideAngle = focalLengths.any { l -> (l * cropFactor) >= 24 && (l * cropFactor) <= 35 }
// https://en.wikipedia.org/wiki/Ultra_wide_angle_lens // https://en.wikipedia.org/wiki/Ultra_wide_angle_lens
val containsUltraWideAngle = focalLengths.any { l -> (l * cropFactor) < 24 } l < 24f -> deviceTypes.pushString("ultra-wide-angle-camera")
// https://en.wikipedia.org/wiki/Wide-angle_lens
if (containsTelephoto) l in 24f..43f -> deviceTypes.pushString("wide-angle-camera")
deviceTypes.pushString("telephoto-camera") // https://en.wikipedia.org/wiki/Telephoto_lens
if (containsWideAngle) l > 43f -> deviceTypes.pushString("telephoto-camera")
deviceTypes.pushString("wide-angle-camera") else -> throw Error("Invalid focal length! (${focalLength}mm)")
if (containsUltraWideAngle) }
deviceTypes.pushString("ultra-wide-angle-camera") }
return deviceTypes return deviceTypes
} }