Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Created February 3, 2019 11:10
Show Gist options
  • Save trilliwon/eb8ff7879457c89b51a27dc794742c86 to your computer and use it in GitHub Desktop.
Save trilliwon/eb8ff7879457c89b51a27dc794742c86 to your computer and use it in GitHub Desktop.
// HDR
@IBOutlet weak var hdrButton: HDRButton!
var currentHDRMode: HDRMode = .auto
@IBAction func HDRButtonTouched(_ sender: HDRButton) {
toggleHDR()
sender.mode = currentHDRMode
}
func toggleHDR() {
switch currentHDRMode {
case .on:
setHDR(.off)
case .off:
setHDR(.auto)
case .auto:
setHDR(.on)
}
}
func setHDR(_ state: HDRMode) {
guard camera.inputCamera.activeFormat.isVideoHDRSupported else {
print("isVideoHDRSupported is false")
return
}
do {
try camera.inputCamera.lockForConfiguration()
switch state {
case .on:
camera.inputCamera.automaticallyAdjustsVideoHDREnabled = false
camera.inputCamera.isVideoHDREnabled = true
case .off:
camera.inputCamera.automaticallyAdjustsVideoHDREnabled = false
camera.inputCamera.isVideoHDREnabled = false
case .auto:
camera.inputCamera.automaticallyAdjustsVideoHDREnabled = true
}
camera.inputCamera.unlockForConfiguration()
} catch {
print("Could not lock configuration")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment