diff --git a/crates/store/re_types/src/components/media_type_ext.rs b/crates/store/re_types/src/components/media_type_ext.rs index 4540f17bbb9b..834a004aa865 100644 --- a/crates/store/re_types/src/components/media_type_ext.rs +++ b/crates/store/re_types/src/components/media_type_ext.rs @@ -217,6 +217,11 @@ impl MediaType { } } } + + /// Returns `true` if this is an image media type. + pub fn is_image(&self) -> bool { + self.as_str().starts_with("image/") + } } impl std::fmt::Display for MediaType { diff --git a/crates/viewer/re_space_view_spatial/src/visualizers/encoded_image.rs b/crates/viewer/re_space_view_spatial/src/visualizers/encoded_image.rs index 8fd9ca18028c..7ed8349be4a5 100644 --- a/crates/viewer/re_space_view_spatial/src/visualizers/encoded_image.rs +++ b/crates/viewer/re_space_view_spatial/src/visualizers/encoded_image.rs @@ -1,6 +1,6 @@ use itertools::Itertools as _; -use re_space_view::HybridResults; +use re_space_view::{diff_component_filter, HybridResults}; use re_types::{ archetypes::EncodedImage, components::{Blob, DrawOrder, MediaType, Opacity}, @@ -10,7 +10,7 @@ use re_viewer_context::{ ApplicableEntities, IdentifiedViewSystem, ImageDecodeCache, QueryContext, SpaceViewSystemExecutionError, TypedComponentFallbackProvider, ViewContext, ViewContextCollection, ViewQuery, VisualizableEntities, VisualizableFilterContext, - VisualizerQueryInfo, VisualizerSystem, + VisualizerAdditionalApplicabilityFilter, VisualizerQueryInfo, VisualizerSystem, }; use crate::{ @@ -42,11 +42,32 @@ impl IdentifiedViewSystem for EncodedImageVisualizer { } } +struct ImageMediaTypeFilter; + +impl VisualizerAdditionalApplicabilityFilter for ImageMediaTypeFilter { + /// Marks entities only as applicable for `EncodedImage` if they have an image media type. + /// + /// Otherwise the image encoder might be suggested for other blobs like video. + fn update_applicability(&mut self, event: &re_chunk_store::ChunkStoreEvent) -> bool { + diff_component_filter(event, |media_type: &re_types::components::MediaType| { + media_type.is_image() + }) || diff_component_filter(event, |image: &re_types::components::Blob| { + MediaType::guess_from_data(&image.0).map_or(false, |media| media.is_image()) + }) + } +} + impl VisualizerSystem for EncodedImageVisualizer { fn visualizer_query_info(&self) -> VisualizerQueryInfo { VisualizerQueryInfo::from_archetype::() } + fn applicability_filter( + &self, + ) -> Option> { + Some(Box::new(ImageMediaTypeFilter)) + } + fn filter_visualizable_entities( &self, entities: ApplicableEntities,