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:
parent
f69e3dff36
commit
a4ace351fa
@ -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
|
l < 24f -> deviceTypes.pushString("ultra-wide-angle-camera")
|
||||||
val containsUltraWideAngle = focalLengths.any { l -> (l * cropFactor) < 24 }
|
// https://en.wikipedia.org/wiki/Wide-angle_lens
|
||||||
|
l in 24f..43f -> deviceTypes.pushString("wide-angle-camera")
|
||||||
if (containsTelephoto)
|
// https://en.wikipedia.org/wiki/Telephoto_lens
|
||||||
deviceTypes.pushString("telephoto-camera")
|
l > 43f -> deviceTypes.pushString("telephoto-camera")
|
||||||
if (containsWideAngle)
|
else -> throw Error("Invalid focal length! (${focalLength}mm)")
|
||||||
deviceTypes.pushString("wide-angle-camera")
|
}
|
||||||
if (containsUltraWideAngle)
|
}
|
||||||
deviceTypes.pushString("ultra-wide-angle-camera")
|
|
||||||
|
|
||||||
return deviceTypes
|
return deviceTypes
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user