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
3 changes: 3 additions & 0 deletions crates/store/re_data_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ pub const SUPPORTED_IMAGE_EXTENSIONS: &[&str] = &[
"pbm", "pgm", "png", "ppm", "tga", "tif", "tiff", "webp",
];

pub const SUPPORTED_DEPTH_IMAGE_EXTENSIONS: &[&str] = &["rvl", "png"];
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extension png appears in both SUPPORTED_IMAGE_EXTENSIONS and SUPPORTED_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.

Copilot uses AI. Check for mistakes.

pub const SUPPORTED_VIDEO_EXTENSIONS: &[&str] = &["mp4"];

pub const SUPPORTED_MESH_EXTENSIONS: &[&str] = &["glb", "gltf", "obj", "stl"];
Expand All @@ -492,6 +494,7 @@ pub fn supported_extensions() -> impl Iterator<Item = &'static str> {
.iter()
.chain(SUPPORTED_THIRD_PARTY_FORMATS)
.chain(SUPPORTED_IMAGE_EXTENSIONS)
.chain(SUPPORTED_DEPTH_IMAGE_EXTENSIONS)
.chain(SUPPORTED_VIDEO_EXTENSIONS)
.chain(SUPPORTED_MESH_EXTENSIONS)
.chain(SUPPORTED_POINT_CLOUD_EXTENSIONS)
Expand Down
37 changes: 37 additions & 0 deletions crates/store/re_data_loader/src/loader_archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a .png depth image, we should only accept it here if it contains a exactly 1 channel. RGB pngs should be handled by EncodedImage

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that sounds reasonable to me.

note that .rvl is not really an official file extension, and in the current state we only support the ROS specific format. So do we need this?

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,
Expand Down
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)
}
}
1 change: 1 addition & 0 deletions crates/store/re_sdk_types/src/archetypes/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading