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.hdrSetting: enable or disable HDR activation. When enabled, the HDR is activated when available in the current camera configuration.

  • Camera.hdrState: tells if HDR is currently activated.

  • Camera.hdrAvailable: tells whether HDR is available in the current camera configuration.

  • CameraPhotoSettings.hdrAvailable: tells whether HDR is available for photo capture in the current mode, format and file format.

  • CameraPhotoSettings.hdrAvailable(mode, format, fileFormat): tells whether HDR is available for photo capture with given mode, format and file format.

  • CameraRecordingSettings.hdrAvailable: tells whether HDR is available for video recording in the current mode, resolution and framerate.

  • CameraRecordingSettings.hdrAvailable(mode, resolution, framerate): tells whether HDR is available for video recording with given mode, resolution and framerate.

Sample code to monitor HDR:

/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?

/// Monitors and prints HDR information.
func monitorHDR(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {
            if let hdrSetting = camera.hdrSetting?.value {
                print("HDR enabled: \(hdrSetting)")
            } else {
                print("HDR not supported by camera")
                return;
            }
            let activated = camera.hdrState
            print("HDR activated: \(activated)")
            let available = camera.hdrAvailable
            print("HDR available in current configuration: \(available)")
            let photoAvailable = camera.photoSettings.hdrAvailable
            print("HDR available for photo in current configuration: \(photoAvailable)")
            let recordingAvailable = camera.recordingSettings.hdrAvailable
            print("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.
func enableHDR(drone: Drone, enable: Bool) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        // set setting value
        camera.hdrSetting?.value = enable
    }
}

Camera 2#

Dynamic range for photo capture is configured with parameter Camera2Params.photoDynamicRange.

Dynamic range for video recording is configured with parameter Camera2Params.videoRecordingDynamicRange.

There are 3 modes for dynamic range:

  • sdr: standard dynamic range.

  • hdr8: high dynamic range, 8-bit color depth.

  • hdr10: high dynamic range, 10-bit color depth.

Sample code to monitor photo capture and video recording dynamic ranges:

/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?

// Monitors and prints photo capture and video recording dynamic ranges.
func monitorDynamicRanges(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera2) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {

            // get configuration parameter for photo capture dynamic range
            if let configParam = camera.config[Camera2Params.photoDynamicRange] {
                if configParam.currentSupportedValues.isEmpty {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("Photo dynamic range: no supported value in current configuration")
                } else {
                    // get parameter value
                    let dynamicRange = configParam.value
                    print("Photo dynamic range: \(dynamicRange)")
                }
            }

            // get configuration parameter for video recording dynamic range
            if let configParam = camera.config[Camera2Params.videoRecordingDynamicRange] {
                if configParam.currentSupportedValues.isEmpty {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("Recording dynamic range: no supported value in current configuration")
                } else {
                    // get parameter value
                    let dynamicRange = configParam.value
                    print("Recording dynamic range: \(dynamicRange)")
                }
            }
        }
    }
}

Example of output:

Photo dynamic range: hdr8
Recording dynamic range: sdr

Sample code to modify photo capture dynamic range:

/// Sets photo capture dynamic range.
func setPhotoDynamicRange(drone: Drone, dynamicRange: Camera2DynamicRange) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.photoDynamicRange] {
            // 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 provided by the parameter field configParam.overallSupportedValues.

Sample code to modify video recording dynamic range:

/// Sets video recording dynamic range.
func setVideoRecordingDynamicRange(drone: Drone, dynamicRange: Camera2DynamicRange) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.videoRecordingDynamicRange] {
            // 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 provided by the parameter field configParam.overallSupportedValues.