Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions examples/capture_dng_to_buffer.py
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 4 additions & 5 deletions picamera2/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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}.")
Expand Down
1 change: 1 addition & 0 deletions tests/test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down