Dynamic Range¶
Camera1 provides a single setting to enable or disable High Dynamic Range (HDR), for both photo capture and video recording.
Camera2 provides 2 configuration parameters to configure dynamic range: one for photo capture and another one for video recording.
Camera 1¶
HDR is contolled with the following elements:
Camera.autoHdr(): get setting to enable or disable HDR activation. When enabled, the HDR is activated when available in the current camera configuration.Camera.isHdrActive(): tells if HDR is currently activated.Camera.isHdrAvailable(): tells whether HDR is available in the current camera configuration.CameraPhoto.Setting.isHdrAvailable(): tells whether HDR is available for photo capture in the current mode, format and file format.CameraPhoto.Setting.isHdrAvailable(mode, format, fileFormat): tells whether HDR is available for photo capture with given mode, format and file format.CameraRecording.Setting.hdrAvailable(): tells whether HDR is available for video recording in the current mode, resolution and framerate.CameraRecording.Setting.hdrAvailable(mode, resolution, framerate): tells whether HDR is available for video recording with given mode, resolution and framerate.
Sample code to monitor HDR:
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** Monitors and prints HDR information. */
fun monitorHDR(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.run {
autoHdr().run {
if (isAvailable) {
println("HDR enabled: $isEnabled")
} else {
println("HDR not supported by camera")
return@getPeripheral;
}
}
val activated = isHdrActive
val available = isHdrAvailable
val photoAvailable = photo().isHdrAvailable
val recordingAvailable = recording().isHdrAvailable
println("HDR activated: $activated")
println("HDR available in current configuration: $available")
println("HDR available for photo in current configuration: $photoAvailable")
println("HDR available for recording in current configuration: $recordingAvailable")
}
}
}
Example of output:
HDR enabled: false
HDR activated: false
HDR available in current configuration: true
HDR available for photo in current configuration: true
HDR available for recording in current configuration: true
Sample code to enable or disable HDR:
/** Enables or disables HDR. */
fun enableHDR(drone: Drone, enable: Boolean) {
drone.getPeripheral(MainCamera::class.java)?.run {
autoHdr().isEnabled = enable
}
}
Camera 2¶
Dynamic range for photo capture is configured with parameter Camera.Config.PHOTO_DYNAMIC_RANGE.
Dynamic range for video recording is configured with parameter Camera.Config.VIDEO_RECORDING_DYNAMIC_RANGE.
There are 3 modes for dynamic range:
SDR: standard dynamic range.
HDR_8: high dynamic range, 8-bit color depth.
HDR_10: high dynamic range, 10-bit color depth.
Sample code to monitor photo capture and video recording dynamic ranges:
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** Monitors and prints photo capture and video recording dynamic ranges. */
fun monitorDynamicRanges(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.run {
// get configuration parameter for photo capture dynamic range
config[Camera.Config.PHOTO_DYNAMIC_RANGE].run {
if (supportedValues(onlyCurrent = true).isEmpty()) {
// parameter value is not relevant
// if there is not supported values in current configuration
println("Photo dynamic range: no supported value in current configuration")
} else {
println("Photo dynamic range: $value")
}
}
// get configuration parameter for video recording dynamic range
config[Camera.Config.VIDEO_RECORDING_DYNAMIC_RANGE].run {
if (supportedValues(onlyCurrent = true).isEmpty()) {
// parameter value is not relevant
// if there is not supported values in current configuration
println("Recording dynamic range: no supported value in current configuration")
} else {
println("Recording dynamic range: $value")
}
}
}
}
}
Example of output:
Photo dynamic range: HDR_8
Recording dynamic range: SDR
Sample code to modify photo capture dynamic range:
/** Sets photo capture dynamic range. */
fun setPhotoDynamicRange(drone: Drone, dynamicRange: Camera.DynamicRange) {
drone.getPeripheral(MainCamera::class.java)?.run {
// create configuration editor, starting from current configuration
val editor = config.edit(fromScratch = false)
// get configuration parameter
editor[Camera.Config.PHOTO_DYNAMIC_RANGE].let { configParam ->
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = dynamicRange
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}
Trying to change the parameter value to an unsupported value has no effect.
Values supported by the camera are retrieved by calling configParam.supportedValues(onlyCurrent = false).
Sample code to modify video recording dynamic range:
/** Sets video recording dynamic range. */
fun setVideoRecordingDynamicRange(drone: Drone, dynamicRange: Camera.DynamicRange) {
drone.getPeripheral(MainCamera::class.java)?.run {
// create configuration editor, starting from current configuration
val editor = config.edit(fromScratch = false)
// get configuration parameter
editor[Camera.Config.VIDEO_RECORDING_DYNAMIC_RANGE].let { configParam ->
// change parameter value,
// and unset other parameters conflicting with this new value
configParam.value = dynamicRange
// complete configuration, by setting missing parameters values
editor.autoComplete()
// send new configuration to drone
editor.commit()
}
}
}
Trying to change the parameter value to an unsupported value has no effect.
Values supported by the camera are retrieved by calling configParam.supportedValues(onlyCurrent = false).