Skip to content

Instantly share code, notes, and snippets.

@NikhilManapure
Created July 19, 2017 07:24
Show Gist options
  • Select an option

  • Save NikhilManapure/5c7f88f19e7cd51ea2cb24ebb63ba42c to your computer and use it in GitHub Desktop.

Select an option

Save NikhilManapure/5c7f88f19e7cd51ea2cb24ebb63ba42c 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