diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 5aa2e55e..9ff9780c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -20,5 +20,5 @@ jobs: clean: true - name: Test - run: DISPLAY=:0 ASSET_DIR=/home/pi/assets PYTHONPATH=/home/pi/_work/picamera2/picamera2:/home/pi/libcamera/build/src/py:/home/pi/kmsxx/build/py:/home/pi/python-v4l2 python3 ${{github.workspace}}/tools/run_tests.py -p ${{github.workspace}} + run: DISPLAY=:0 ASSET_DIR=/home/pi/assets PYTHONPATH=/home/pi/_work/picamera2/picamera2:/home/pi/libcamera/build/src/py:/home/pi/kmsxx/build/py:/home/pi/python-v4l2:/home/pi/pidng/src python3 ${{github.workspace}}/tools/run_tests.py -p ${{github.workspace}} timeout-minutes: 30 diff --git a/examples/capture_dng_to_buffer.py b/examples/capture_dng_to_buffer.py new file mode 100755 index 00000000..85b6fad5 --- /dev/null +++ b/examples/capture_dng_to_buffer.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +import io +import time + +from picamera2 import Picamera2 + +picam2 = Picamera2() +config = picam2.create_still_configuration() +picam2.configure(config) +picam2.start() + +time.sleep(1) + +buf = io.BytesIO() +picam2.capture_file(buf, name='raw') + +if len(buf.getbuffer()) == 0: + print("ERROR: DNG buffer is empty") diff --git a/picamera2/request.py b/picamera2/request.py index ace8bc5e..46516626 100644 --- a/picamera2/request.py +++ b/picamera2/request.py @@ -438,7 +438,7 @@ def save(self, img: Image.Image, metadata: Dict[str, Any], file_output: Union[st def save_dng(self, buffer: np.ndarray, metadata: Dict[str, Any], config: Dict[str, Any], file_output: Any) -> None: """Save a DNG RAW image of the raw stream's buffer.""" start_time = time.monotonic() - raw = self.make_array(buffer, config) + raw = self._make_array_shared(buffer, config) config = config.copy() fmt = SensorFormat(config['format']) @@ -456,12 +456,11 @@ def save_dng(self, buffer: np.ndarray, metadata: Dict[str, Any], config: Dict[st dng_compress_level = self.picam2.options.get("compress_level", 0) r.options(compress=dng_compress_level) - # PiDNG doesn't accpet a BytesIO, but returns a byte array if the filename is empty. if isinstance(file_output, io.BytesIO): - buf = r.convert(raw, "") - file_output.write(buf) + r.convert(raw, file=file_output) else: - r.convert(raw, str(file_output)) + with open(str(file_output), 'wb') as file: + r.convert(raw, file=file) end_time = time.monotonic() _log.info(f"Saved {self} to file {file_output}.") diff --git a/tests/test_list.txt b/tests/test_list.txt index 19bdb1b7..48b6ff53 100644 --- a/tests/test_list.txt +++ b/tests/test_list.txt @@ -2,6 +2,7 @@ examples/capture_circular_nooutput.py examples/capture_dng.py examples/capture_dng_and_jpeg.py examples/capture_dng_and_jpeg_helpers.py +examples/capture_dng_to_buffer.py examples/capture_full_res.py examples/capture_headless.py examples/capture_helpers.py