Skip to content

Commit 4ceb531

Browse files
committed
fix: Consider everything between 24mm and 43mm a wide-angle camera lens
cc @AndrewGable
1 parent 2493844 commit 4ceb531

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

android/src/main/java/com/mrousavy/camera/utils/CameraCharacteristicsUtils.kt

+13-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ val Size35mm = Size(36, 24)
2626
* * [Ultra-Wide-Angle Lens (wikipedia)](https://en.wikipedia.org/wiki/Ultra_wide_angle_lens)
2727
*/
2828
fun CameraCharacteristics.getDeviceTypes(): ReadableArray {
29-
// TODO: Check if getDeviceType() works correctly, even for logical multi-cameras
3029
val focalLengths = this.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)!!
3130
val sensorSize = this.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE)!!
3231

@@ -35,17 +34,19 @@ fun CameraCharacteristics.getDeviceTypes(): ReadableArray {
3534

3635
val deviceTypes = Arguments.createArray()
3736

38-
val containsTelephoto = focalLengths.any { l -> (l * cropFactor) > 35 } // TODO: Telephoto lenses are > 85mm, but we don't have anything between that range..
39-
// val containsNormalLens = focalLengths.any { l -> (l * cropFactor) > 35 && (l * cropFactor) <= 55 }
40-
val containsWideAngle = focalLengths.any { l -> (l * cropFactor) >= 24 && (l * cropFactor) <= 35 }
41-
val containsUltraWideAngle = focalLengths.any { l -> (l * cropFactor) < 24 }
42-
43-
if (containsTelephoto)
44-
deviceTypes.pushString("telephoto-camera")
45-
if (containsWideAngle)
46-
deviceTypes.pushString("wide-angle-camera")
47-
if (containsUltraWideAngle)
48-
deviceTypes.pushString("ultra-wide-angle-camera")
37+
focalLengths.forEach { focalLength ->
38+
// scale to the 35mm film standard
39+
val l = focalLength * cropFactor
40+
when {
41+
// https://en.wikipedia.org/wiki/Ultra_wide_angle_lens
42+
l < 24f -> deviceTypes.pushString("ultra-wide-angle-camera")
43+
// https://en.wikipedia.org/wiki/Wide-angle_lens
44+
l in 24f..43f -> deviceTypes.pushString("wide-angle-camera")
45+
// https://en.wikipedia.org/wiki/Telephoto_lens
46+
l > 43f -> deviceTypes.pushString("telephoto-camera")
47+
else -> throw Error("Invalid focal length! (${focalLength}mm)")
48+
}
49+
}
4950

5051
return deviceTypes
5152
}

0 commit comments

Comments
 (0)