Skip to content

Commit 8cff1ef

Browse files
pantheraleo-7davidplowman
authored andcommitted
fix logical errors in configure_
Signed-off-by: Asadullah Shaikh <asadshaikh20022002@gmail.com>
1 parent 07cf439 commit 8cff1ef

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

picamera2/picamera2.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ def configure_(self, camera_config):
10391039
:param camera_config: Camera configuration to be set
10401040
:type camera_config: str, dict or CameraConfiguration
10411041
:raises RuntimeError: Failed to configure at runtime
1042+
:raises TypeError: Invalid type for `camera_config` given
10421043
"""
10431044
if self.started:
10441045
raise RuntimeError("Camera must be stopped before configuring")
@@ -1055,18 +1056,20 @@ def configure_(self, camera_config):
10551056
else:
10561057
_log.warning("Invalid name for `camera_config` given, assuming default 'preview' configuration")
10571058
camera_config = self.preview_configuration
1058-
elif isinstance(camera_config, dict):
1059-
camera_config = camera_config.copy()
10601059

1061-
if isinstance(camera_config, CameraConfiguration):
1062-
if camera_config.raw is not None:
1063-
# For raw streams, patch up the format/size now if they haven't been set.
1064-
if camera_config.raw.format is None:
1065-
camera_config.raw.format = self.sensor_format
1066-
if camera_config.raw.size is None:
1067-
camera_config.raw.size = camera_config.main.size
1068-
# We expect values to have been set for any lores/raw streams.
1060+
if isinstance(camera_config, dict):
1061+
camera_config = camera_config.copy()
1062+
elif isinstance(camera_config, CameraConfiguration):
10691063
camera_config = camera_config.make_dict()
1064+
else:
1065+
raise TypeError("Invalid type for `camera_config` given")
1066+
1067+
# For unset raw streams, patch up the format/size.
1068+
if camera_config["raw"] is not None:
1069+
if camera_config["raw"]["format"] is None:
1070+
camera_config["raw"]["format"] = self.sensor_format
1071+
if camera_config["raw"]["size"] is None:
1072+
camera_config["raw"]["size"] = camera_config["main"]["size"]
10701073

10711074
# Be 100% sure that non-Pi cameras aren't asking for a raw stream.
10721075
if not self._is_rpi_camera():
@@ -1079,7 +1082,6 @@ def configure_(self, camera_config):
10791082
# Check the config and turn it into a libcamera config.
10801083
self.check_camera_config(camera_config)
10811084
libcamera_config = self._make_libcamera_config(camera_config)
1082-
self.libcamera_config = libcamera_config
10831085

10841086
# Check that libcamera is happy with it.
10851087
status = libcamera_config.validate()
@@ -1135,12 +1137,12 @@ def configure_(self, camera_config):
11351137
self.camera_config = camera_config
11361138

11371139
# Fill in the embedded configuration structures if those were used.
1138-
if initial_config == "preview":
1139-
self.preview_configuration.update(camera_config)
1140-
elif initial_config == "still":
1140+
if initial_config == "still":
11411141
self.still_configuration.update(camera_config)
1142-
else:
1142+
elif initial_config == "video":
11431143
self.video_configuration.update(camera_config)
1144+
elif isinstance(initial_config, str):
1145+
self.preview_configuration.update(camera_config)
11441146

11451147
# Set the controls directly so as to overwrite whatever is there.
11461148
self.controls = Controls(self, controls=self.camera_config['controls'])

0 commit comments

Comments
 (0)