Skip to content

Commit

Permalink
Support ioBytes object when saving DNG
Browse files Browse the repository at this point in the history
Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman committed Jan 15, 2024
1 parent 9b3769b commit 5d7a166
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions picamera2/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def save(self, name, file_output, format=None, exif_data=None):
return self.picam2.helpers.save(self.make_image(name), self.get_metadata(), file_output,
format, exif_data)

def save_dng(self, filename, name="raw"):
def save_dng(self, file_output, name="raw"):
"""Save a DNG RAW image of the raw stream's buffer."""
return self.picam2.helpers.save_dng(self.make_buffer(name), self.get_metadata(), self.config[name], filename)
return self.picam2.helpers.save_dng(self.make_buffer(name), self.get_metadata(), self.config[name], file_output)


class Helpers:
Expand Down Expand Up @@ -303,7 +303,7 @@ def save(self, img, metadata, file_output, format=None, exif_data=None):
_log.info(f"Saved {self} to file {file_output}.")
_log.info(f"Time taken for encode: {(end_time-start_time)*1000} ms.")

def save_dng(self, buffer, metadata, config, filename):
def save_dng(self, buffer, metadata, config, file_output):
"""Save a DNG RAW image of the raw stream's buffer."""
start_time = time.monotonic()
raw = self.make_array(buffer, config)
Expand All @@ -323,10 +323,15 @@ def save_dng(self, buffer, metadata, config, filename):
dng_compress_level = self.picam2.options.get("compress_level", 0)

r.options(compress=dng_compress_level)
r.convert(raw, str(filename))
# 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)
else:
r.convert(raw, str(file_output))

end_time = time.monotonic()
_log.info(f"Saved {self} to file {filename}.")
_log.info(f"Saved {self} to file {file_output}.")
_log.info(f"Time taken for encode: {(end_time-start_time)*1000} ms.")

def decompress(self, array):
Expand Down

0 comments on commit 5d7a166

Please sign in to comment.