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 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)
val cropFactor = size35mm.bigger / sensorSize.bigger
val deviceTypes = Arguments.createArray()
// https://en.wikipedia.org/wiki/Telephoto_lens
val containsTelephoto = focalLengths.any { l -> (l * cropFactor) > 35 } // TODO: Telephoto lenses are > 85mm, but we don't have anything between that range..
// val containsNormalLens = focalLengths.any { l -> (l * cropFactor) > 35 && (l * cropFactor) <= 55 }
// https://en.wikipedia.org/wiki/Wide-angle_lens
val containsWideAngle = focalLengths.any { l -> (l * cropFactor) >= 24 && (l * cropFactor) <= 35 }
focalLengths.forEach { focalLength ->
// scale to the 35mm film standard
val l = focalLength * cropFactor
when {
// https://en.wikipedia.org/wiki/Ultra_wide_angle_lens
val containsUltraWideAngle = focalLengths.any { l -> (l * cropFactor) < 24 }
if (containsTelephoto)
deviceTypes.pushString("telephoto-camera")
if (containsWideAngle)
deviceTypes.pushString("wide-angle-camera")
if (containsUltraWideAngle)
deviceTypes.pushString("ultra-wide-angle-camera")
l < 24f -> deviceTypes.pushString("ultra-wide-angle-camera")
// https://en.wikipedia.org/wiki/Wide-angle_lens
l in 24f..43f -> deviceTypes.pushString("wide-angle-camera")
// https://en.wikipedia.org/wiki/Telephoto_lens
l > 43f -> deviceTypes.pushString("telephoto-camera")
else -> throw Error("Invalid focal length! (${focalLength}mm)")
}
}
return deviceTypes
}