diff --git a/picamera_coverage.zip b/picamera_coverage.zip index d1d27c2d..d692e25b 100644 Binary files a/picamera_coverage.zip and b/picamera_coverage.zip differ diff --git a/src/openflexure_microscope_server/things/camera/picamera.py b/src/openflexure_microscope_server/things/camera/picamera.py index 40f28f8b..aa8ca5dd 100644 --- a/src/openflexure_microscope_server/things/camera/picamera.py +++ b/src/openflexure_microscope_server/things/camera/picamera.py @@ -826,6 +826,17 @@ class StreamingPiCamera2(BaseCamera): tf_utils.set_static_geq(self.tuning, offset) self._initialise_picamera() + @lt.thing_action + def set_ce_enable_to_off(self) -> None: + """Set the contrast enhancement to disabled. + + Adaptive contrast enhancement modifies settings to adapt to each field + of view, causing inconsistent settings when capturing. + """ + with self._streaming_picamera(pause_stream=True): + tf_utils.set_ce_to_disabled(self.tuning) + self._initialise_picamera() + @lt.thing_action def full_auto_calibrate(self, portal: lt.deps.BlockingPortal) -> None: """Perform a full auto-calibration. @@ -843,6 +854,7 @@ class StreamingPiCamera2(BaseCamera): self.flat_lens_shading() self.auto_expose_from_minimum() self.set_static_green_equalisation() + self.set_ce_enable_to_off() self.calibrate_lens_shading() self.reset_ccm() self.calibrate_white_balance() diff --git a/src/openflexure_microscope_server/things/camera/picamera_tuning_file_utils.py b/src/openflexure_microscope_server/things/camera/picamera_tuning_file_utils.py index f86753c7..b202616a 100644 --- a/src/openflexure_microscope_server/things/camera/picamera_tuning_file_utils.py +++ b/src/openflexure_microscope_server/things/camera/picamera_tuning_file_utils.py @@ -104,6 +104,24 @@ def geq_is_static(tuning: dict) -> bool: return geq["offset"] == 65535 +def set_ce_to_disabled( + tuning: dict, +) -> None: + """Set ``ce_enable`` in ``rpi.contrast`` to zero to disable adaptive contrast enhancement. + + :param tuning: the raspberry pi tuning file. This will be updated in-place to + set ce_enable to 0. + """ + contrast = Picamera2.find_tuning_algo(tuning, "rpi.contrast") + contrast["ce_enable"] = 0 + + +def ce_enable_is_static(tuning: dict) -> bool: + """Whether the ce_enable flag is disabled.""" + contrast = Picamera2.find_tuning_algo(tuning, "rpi.contrast") + return contrast["ce_enable"] == 0 + + def copy_alsc_section(from_tuning: dict, to_tuning: dict) -> None: """Copy the ``rpi.alsc`` algorithm from one tuning to another. diff --git a/tests/test_cameras.py b/tests/test_cameras.py index 27de7bd4..ffb65df1 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -114,6 +114,7 @@ def test_thing_description_equivalence(mock_picam_thing): picamera_extra_actions = { "flat_lens_shading_chrominance", "set_static_green_equalisation", + "set_ce_enable_to_off", "stop_streaming", "reset_ccm", }