-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Restore CameraDevice neutralZoom #4169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /// | ||
| /// AVCaptureDevice+neutralZoom.swift | ||
| /// VisionCamera | ||
| /// Copyright © 2026 Marc Rousavy @ Margelo | ||
| /// | ||
|
|
||
| import AVFoundation | ||
| import Foundation | ||
|
|
||
| extension AVCaptureDevice { | ||
| /** | ||
| * The internal video zoom factor that AVFoundation displays as `1x`. | ||
| * | ||
| * On older iOS versions, derive it from the switchover factor immediately | ||
| * before the standard wide-angle constituent Camera. | ||
| */ | ||
| var neutralZoomFactor: Double { | ||
| if #available(iOS 18.0, *) { | ||
| let multiplier = displayVideoZoomFactorMultiplier | ||
| if multiplier > 0 { | ||
| return 1 / multiplier | ||
| } | ||
| } | ||
|
|
||
| guard | ||
| let wideAngleIndex = constituentDevices.firstIndex(where: { | ||
| $0.deviceType == .builtInWideAngleCamera | ||
| }), | ||
| wideAngleIndex > 0 | ||
| else { | ||
| return 1 | ||
| } | ||
|
|
||
| let switchoverIndex = wideAngleIndex - 1 | ||
| guard virtualDeviceSwitchOverVideoZoomFactors.indices.contains(switchoverIndex) else { | ||
| return 1 | ||
| } | ||
| return virtualDeviceSwitchOverVideoZoomFactors[switchoverIndex].doubleValue | ||
|
Comment on lines
+24
to
+38
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this Plan B and Plan C approach are kinda ugly. I'm not sure if there is a better way, but as it is, its a bit ugly. |
||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value changes as the device starts zooming. So if you zoom in, and then ask
device.neutralZoomFactor, it is no longer1(or2) but might be any arbitrary number.I think.