Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ioBytes object when saving DNG #923

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
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
Loading