-
Notifications
You must be signed in to change notification settings - Fork 597
Add dataloader for encoded depth image (to allow log_from_file & dragdrop)
#12287
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,14 @@ impl DataLoader for ArchetypeLoader { | |
| entity_path, | ||
| contents.into_owned(), | ||
| )?); | ||
| } else if crate::SUPPORTED_DEPTH_IMAGE_EXTENSIONS.contains(&extension.as_str()) { | ||
| re_log::debug!(?filepath, loader = self.name(), "Loading depth image…",); | ||
| rows.extend(load_depth_image( | ||
| &filepath, | ||
| timepoint, | ||
| entity_path, | ||
| contents.into_owned(), | ||
| )?); | ||
| } else if crate::SUPPORTED_VIDEO_EXTENSIONS.contains(&extension.as_str()) { | ||
| re_log::debug!(?filepath, loader = self.name(), "Loading video…",); | ||
| rows.extend(load_video( | ||
|
|
@@ -191,6 +199,35 @@ fn load_image( | |
| Ok(rows.into_iter()) | ||
| } | ||
|
|
||
| fn load_depth_image( | ||
| filepath: &std::path::Path, | ||
| timepoint: TimePoint, | ||
| entity_path: EntityPath, | ||
| contents: Vec<u8>, | ||
| ) -> Result<impl ExactSizeIterator<Item = Chunk> + use<>, DataLoaderError> { | ||
| re_tracing::profile_function!(); | ||
|
|
||
| let rows = [{ | ||
| let mut arch = re_sdk_types::archetypes::EncodedDepthImage::from_file_contents(contents); | ||
|
|
||
| if let Ok(format) = image::ImageFormat::from_path(filepath) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. Practically we won't get here because pngs are first handled by the image handler. Maybe we should stick to that explicitly, i.e. adding only rvl to the depth image extensions and then here also only handling rvl
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea that sounds reasonable to me. note that |
||
| arch = arch.with_media_type(format.to_mime_type()); | ||
| } else if filepath | ||
| .extension() | ||
| .and_then(|ext| ext.to_str()) | ||
| .is_some_and(|ext| ext.to_lowercase() == "rvl") | ||
| { | ||
| arch = arch.with_media_type(re_sdk_types::components::MediaType::RVL); | ||
| } | ||
|
|
||
| Chunk::builder(entity_path) | ||
| .with_archetype(RowId::new(), timepoint, &arch) | ||
| .build()? | ||
| }]; | ||
|
|
||
| Ok(rows.into_iter()) | ||
| } | ||
|
|
||
| fn load_video( | ||
| filepath: &std::path::Path, | ||
| mut timepoint: TimePoint, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| use super::EncodedDepthImage; | ||
|
|
||
| impl EncodedDepthImage { | ||
| /// Creates a new depth image from the file contents at `path`. | ||
| /// | ||
| /// The [`MediaType`][crate::components::MediaType] will first be guessed from the file contents. | ||
| /// | ||
| /// Returns an error if the file cannot be read. | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| #[inline] | ||
| pub fn from_file(filepath: impl AsRef<std::path::Path>) -> std::io::Result<Self> { | ||
| let filepath = filepath.as_ref(); | ||
| let contents = std::fs::read(filepath)?; | ||
| Ok(Self::from_file_contents(contents)) | ||
| } | ||
|
|
||
| /// Construct a depth image given the encoded content of some image file, e.g. a PNG or RVL. | ||
| /// | ||
| /// [`Self::media_type`] will be guessed from the bytes. | ||
| pub fn from_file_contents(bytes: Vec<u8>) -> Self { | ||
| #[cfg(feature = "image")] | ||
| { | ||
| if let Some(media_type) = image::guess_format(&bytes) | ||
| .ok() | ||
| .map(|format| crate::components::MediaType::from(format.to_mime_type())) | ||
| { | ||
| return Self::new(bytes).with_media_type(media_type); | ||
| } | ||
| } | ||
|
|
||
| Self::new(bytes) | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extension
pngappears in bothSUPPORTED_IMAGE_EXTENSIONSandSUPPORTED_DEPTH_IMAGE_EXTENSIONS. This duplication could lead to ambiguity in file handling logic. Consider documenting why PNG is listed in both arrays or ensure the loader has clear precedence rules when a file extension matches multiple categories.