From cfc0ad542bad2d88bc161a704f66ca0e90b7b71c Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 11:43:56 -0400 Subject: [PATCH 1/6] Change Image archetype to use a specific ImageBuffer component --- .../definitions/rerun/archetypes/depth_image.fbs | 2 +- .../definitions/rerun/archetypes/image.fbs | 2 +- .../rerun/archetypes/segmentation_image.fbs | 2 +- .../rerun/components/image_buffer.fbs | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 crates/store/re_types/definitions/rerun/components/image_buffer.fbs diff --git a/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs b/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs index 2d18505ae68e..6ab6cc8fcdfd 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/depth_image.fbs @@ -20,7 +20,7 @@ table DepthImage ( // --- Required --- /// The raw depth image data. - data: rerun.components.Blob ("attr.rerun.component_required", order: 1000); + buffer: rerun.components.ImageBuffer ("attr.rerun.component_required", order: 1000); /// The format of the image. format: rerun.components.ImageFormat ("attr.rerun.component_required", order: 1100); diff --git a/crates/store/re_types/definitions/rerun/archetypes/image.fbs b/crates/store/re_types/definitions/rerun/archetypes/image.fbs index effd61197760..c9a41443260d 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/image.fbs @@ -29,7 +29,7 @@ table Image ( // --- Required --- /// The raw image data. - data: rerun.components.Blob ("attr.rerun.component_required", order: 1000); + buffer: rerun.components.ImageBuffer ("attr.rerun.component_required", order: 1000); /// The format of the image. format: rerun.components.ImageFormat ("attr.rerun.component_required", order: 1100); diff --git a/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs b/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs index 3a28d6591785..5cb4cceda696 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/segmentation_image.fbs @@ -24,7 +24,7 @@ table SegmentationImage ( // --- Required --- /// The raw image data. - data: rerun.components.Blob ("attr.rerun.component_required", order: 1000); + buffer: rerun.components.ImageBuffer ("attr.rerun.component_required", order: 1000); /// The format of the image. format: rerun.components.ImageFormat ("attr.rerun.component_required", order: 1100); diff --git a/crates/store/re_types/definitions/rerun/components/image_buffer.fbs b/crates/store/re_types/definitions/rerun/components/image_buffer.fbs new file mode 100644 index 000000000000..84bf1939213c --- /dev/null +++ b/crates/store/re_types/definitions/rerun/components/image_buffer.fbs @@ -0,0 +1,16 @@ +namespace rerun.components; + +// --- + +/// A buffer that is known to store image data. +/// +/// To interpret the contents of this buffer, see, [rerun.components.ImageFormat]. +table ImageBuffer ( + "attr.arrow.transparent", + "attr.python.aliases": "bytes, npt.NDArray[np.uint8]", + "attr.python.array_aliases": "bytes, npt.NDArray[np.uint8]", + "attr.rust.derive": "Default, PartialEq, Eq", + "attr.rust.repr": "transparent" +) { + buffer: rerun.datatypes.Blob (order: 100); +} From 52c9530167685a9a7fc39d5891930258462a12a3 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 11:47:54 -0400 Subject: [PATCH 2/6] Codegen --- .../re_types/definitions/rerun/components.fbs | 1 + .../re_types/src/archetypes/depth_image.rs | 30 ++--- crates/store/re_types/src/archetypes/image.rs | 30 ++--- .../src/archetypes/segmentation_image.rs | 30 ++--- .../re_types/src/components/.gitattributes | 1 + .../re_types/src/components/image_buffer.rs | 107 ++++++++++++++++++ crates/store/re_types/src/components/mod.rs | 2 + crates/viewer/re_viewer/src/reflection/mod.rs | 7 ++ .../reference/types/archetypes/depth_image.md | 2 +- .../reference/types/archetypes/image.md | 2 +- .../types/archetypes/segmentation_image.md | 2 +- docs/content/reference/types/components.md | 1 + .../reference/types/components/.gitattributes | 1 + .../reference/types/components/blob.md | 3 - .../types/components/image_buffer.md | 24 ++++ .../content/reference/types/datatypes/blob.md | 1 + .../src/rerun/archetypes/depth_image.cpp | 2 +- .../src/rerun/archetypes/depth_image.hpp | 4 +- rerun_cpp/src/rerun/archetypes/image.cpp | 2 +- rerun_cpp/src/rerun/archetypes/image.hpp | 4 +- .../rerun/archetypes/segmentation_image.cpp | 2 +- .../rerun/archetypes/segmentation_image.hpp | 4 +- rerun_cpp/src/rerun/components.hpp | 1 + rerun_cpp/src/rerun/components/.gitattributes | 1 + .../src/rerun/components/image_buffer.hpp | 65 +++++++++++ .../rerun_sdk/rerun/archetypes/depth_image.py | 6 +- rerun_py/rerun_sdk/rerun/archetypes/image.py | 6 +- .../rerun/archetypes/segmentation_image.py | 6 +- .../rerun_sdk/rerun/components/.gitattributes | 1 + .../rerun_sdk/rerun/components/__init__.py | 4 + .../rerun/components/image_buffer.py | 40 +++++++ 31 files changed, 323 insertions(+), 69 deletions(-) create mode 100644 crates/store/re_types/src/components/image_buffer.rs create mode 100644 docs/content/reference/types/components/image_buffer.md create mode 100644 rerun_cpp/src/rerun/components/image_buffer.hpp create mode 100644 rerun_py/rerun_sdk/rerun/components/image_buffer.py diff --git a/crates/store/re_types/definitions/rerun/components.fbs b/crates/store/re_types/definitions/rerun/components.fbs index 51081363b52e..a8e453fb2062 100644 --- a/crates/store/re_types/definitions/rerun/components.fbs +++ b/crates/store/re_types/definitions/rerun/components.fbs @@ -17,6 +17,7 @@ include "./components/fill_ratio.fbs"; include "./components/gamma_correction.fbs"; include "./components/half_size2d.fbs"; include "./components/half_size3d.fbs"; +include "./components/image_buffer.fbs"; include "./components/image_format.fbs"; include "./components/image_plane_distance.fbs"; include "./components/keypoint_id.fbs"; diff --git a/crates/store/re_types/src/archetypes/depth_image.rs b/crates/store/re_types/src/archetypes/depth_image.rs index 0def4477b260..9a7091c862ee 100644 --- a/crates/store/re_types/src/archetypes/depth_image.rs +++ b/crates/store/re_types/src/archetypes/depth_image.rs @@ -67,7 +67,7 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; #[derive(Clone, Debug, PartialEq)] pub struct DepthImage { /// The raw depth image data. - pub data: crate::components::Blob, + pub buffer: crate::components::ImageBuffer, /// The format of the image. pub format: crate::components::ImageFormat, @@ -104,7 +104,7 @@ pub struct DepthImage { impl ::re_types_core::SizeBytes for DepthImage { #[inline] fn heap_size_bytes(&self) -> u64 { - self.data.heap_size_bytes() + self.buffer.heap_size_bytes() + self.format.heap_size_bytes() + self.meter.heap_size_bytes() + self.colormap.heap_size_bytes() @@ -114,7 +114,7 @@ impl ::re_types_core::SizeBytes for DepthImage { #[inline] fn is_pod() -> bool { - ::is_pod() + ::is_pod() && ::is_pod() && >::is_pod() && >::is_pod() @@ -126,7 +126,7 @@ impl ::re_types_core::SizeBytes for DepthImage { static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 2usize]> = once_cell::sync::Lazy::new(|| { [ - "rerun.components.Blob".into(), + "rerun.components.ImageBuffer".into(), "rerun.components.ImageFormat".into(), ] }); @@ -147,7 +147,7 @@ static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 4usize]> = static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 7usize]> = once_cell::sync::Lazy::new(|| { [ - "rerun.components.Blob".into(), + "rerun.components.ImageBuffer".into(), "rerun.components.ImageFormat".into(), "rerun.components.DepthImageIndicator".into(), "rerun.components.DepthMeter".into(), @@ -214,18 +214,18 @@ impl ::re_types_core::Archetype for DepthImage { .into_iter() .map(|(name, array)| (name.full_name(), array)) .collect(); - let data = { + let buffer = { let array = arrays_by_name - .get("rerun.components.Blob") + .get("rerun.components.ImageBuffer") .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.DepthImage#data")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.DepthImage#data")? + .with_context("rerun.archetypes.DepthImage#buffer")?; + ::from_arrow_opt(&**array) + .with_context("rerun.archetypes.DepthImage#buffer")? .into_iter() .next() .flatten() .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.DepthImage#data")? + .with_context("rerun.archetypes.DepthImage#buffer")? }; let format = { let array = arrays_by_name @@ -278,7 +278,7 @@ impl ::re_types_core::Archetype for DepthImage { None }; Ok(Self { - data, + buffer, format, meter, colormap, @@ -294,7 +294,7 @@ impl ::re_types_core::AsComponents for DepthImage { use ::re_types_core::Archetype as _; [ Some(Self::indicator()), - Some((&self.data as &dyn ComponentBatch).into()), + Some((&self.buffer as &dyn ComponentBatch).into()), Some((&self.format as &dyn ComponentBatch).into()), self.meter .as_ref() @@ -319,11 +319,11 @@ impl DepthImage { /// Create a new `DepthImage`. #[inline] pub fn new( - data: impl Into, + buffer: impl Into, format: impl Into, ) -> Self { Self { - data: data.into(), + buffer: buffer.into(), format: format.into(), meter: None, colormap: None, diff --git a/crates/store/re_types/src/archetypes/image.rs b/crates/store/re_types/src/archetypes/image.rs index 03a014f80f1d..7b6d0fbf04eb 100644 --- a/crates/store/re_types/src/archetypes/image.rs +++ b/crates/store/re_types/src/archetypes/image.rs @@ -66,7 +66,7 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; #[derive(Clone, Debug, PartialEq)] pub struct Image { /// The raw image data. - pub data: crate::components::Blob, + pub buffer: crate::components::ImageBuffer, /// The format of the image. pub format: crate::components::ImageFormat, @@ -85,7 +85,7 @@ pub struct Image { impl ::re_types_core::SizeBytes for Image { #[inline] fn heap_size_bytes(&self) -> u64 { - self.data.heap_size_bytes() + self.buffer.heap_size_bytes() + self.format.heap_size_bytes() + self.opacity.heap_size_bytes() + self.draw_order.heap_size_bytes() @@ -93,7 +93,7 @@ impl ::re_types_core::SizeBytes for Image { #[inline] fn is_pod() -> bool { - ::is_pod() + ::is_pod() && ::is_pod() && >::is_pod() && >::is_pod() @@ -103,7 +103,7 @@ impl ::re_types_core::SizeBytes for Image { static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 2usize]> = once_cell::sync::Lazy::new(|| { [ - "rerun.components.Blob".into(), + "rerun.components.ImageBuffer".into(), "rerun.components.ImageFormat".into(), ] }); @@ -122,7 +122,7 @@ static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 2usize]> = static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 5usize]> = once_cell::sync::Lazy::new(|| { [ - "rerun.components.Blob".into(), + "rerun.components.ImageBuffer".into(), "rerun.components.ImageFormat".into(), "rerun.components.ImageIndicator".into(), "rerun.components.Opacity".into(), @@ -187,18 +187,18 @@ impl ::re_types_core::Archetype for Image { .into_iter() .map(|(name, array)| (name.full_name(), array)) .collect(); - let data = { + let buffer = { let array = arrays_by_name - .get("rerun.components.Blob") + .get("rerun.components.ImageBuffer") .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Image#data")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Image#data")? + .with_context("rerun.archetypes.Image#buffer")?; + ::from_arrow_opt(&**array) + .with_context("rerun.archetypes.Image#buffer")? .into_iter() .next() .flatten() .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.Image#data")? + .with_context("rerun.archetypes.Image#buffer")? }; let format = { let array = arrays_by_name @@ -232,7 +232,7 @@ impl ::re_types_core::Archetype for Image { None }; Ok(Self { - data, + buffer, format, opacity, draw_order, @@ -246,7 +246,7 @@ impl ::re_types_core::AsComponents for Image { use ::re_types_core::Archetype as _; [ Some(Self::indicator()), - Some((&self.data as &dyn ComponentBatch).into()), + Some((&self.buffer as &dyn ComponentBatch).into()), Some((&self.format as &dyn ComponentBatch).into()), self.opacity .as_ref() @@ -265,11 +265,11 @@ impl Image { /// Create a new `Image`. #[inline] pub fn new( - data: impl Into, + buffer: impl Into, format: impl Into, ) -> Self { Self { - data: data.into(), + buffer: buffer.into(), format: format.into(), opacity: None, draw_order: None, diff --git a/crates/store/re_types/src/archetypes/segmentation_image.rs b/crates/store/re_types/src/archetypes/segmentation_image.rs index 8d161d486563..dd16d50977bc 100644 --- a/crates/store/re_types/src/archetypes/segmentation_image.rs +++ b/crates/store/re_types/src/archetypes/segmentation_image.rs @@ -67,7 +67,7 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; #[derive(Clone, Debug, PartialEq)] pub struct SegmentationImage { /// The raw image data. - pub data: crate::components::Blob, + pub buffer: crate::components::ImageBuffer, /// The format of the image. pub format: crate::components::ImageFormat, @@ -86,7 +86,7 @@ pub struct SegmentationImage { impl ::re_types_core::SizeBytes for SegmentationImage { #[inline] fn heap_size_bytes(&self) -> u64 { - self.data.heap_size_bytes() + self.buffer.heap_size_bytes() + self.format.heap_size_bytes() + self.opacity.heap_size_bytes() + self.draw_order.heap_size_bytes() @@ -94,7 +94,7 @@ impl ::re_types_core::SizeBytes for SegmentationImage { #[inline] fn is_pod() -> bool { - ::is_pod() + ::is_pod() && ::is_pod() && >::is_pod() && >::is_pod() @@ -104,7 +104,7 @@ impl ::re_types_core::SizeBytes for SegmentationImage { static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 2usize]> = once_cell::sync::Lazy::new(|| { [ - "rerun.components.Blob".into(), + "rerun.components.ImageBuffer".into(), "rerun.components.ImageFormat".into(), ] }); @@ -123,7 +123,7 @@ static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 2usize]> = static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 5usize]> = once_cell::sync::Lazy::new(|| { [ - "rerun.components.Blob".into(), + "rerun.components.ImageBuffer".into(), "rerun.components.ImageFormat".into(), "rerun.components.SegmentationImageIndicator".into(), "rerun.components.Opacity".into(), @@ -188,18 +188,18 @@ impl ::re_types_core::Archetype for SegmentationImage { .into_iter() .map(|(name, array)| (name.full_name(), array)) .collect(); - let data = { + let buffer = { let array = arrays_by_name - .get("rerun.components.Blob") + .get("rerun.components.ImageBuffer") .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.SegmentationImage#data")?; - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.SegmentationImage#data")? + .with_context("rerun.archetypes.SegmentationImage#buffer")?; + ::from_arrow_opt(&**array) + .with_context("rerun.archetypes.SegmentationImage#buffer")? .into_iter() .next() .flatten() .ok_or_else(DeserializationError::missing_data) - .with_context("rerun.archetypes.SegmentationImage#data")? + .with_context("rerun.archetypes.SegmentationImage#buffer")? }; let format = { let array = arrays_by_name @@ -233,7 +233,7 @@ impl ::re_types_core::Archetype for SegmentationImage { None }; Ok(Self { - data, + buffer, format, opacity, draw_order, @@ -247,7 +247,7 @@ impl ::re_types_core::AsComponents for SegmentationImage { use ::re_types_core::Archetype as _; [ Some(Self::indicator()), - Some((&self.data as &dyn ComponentBatch).into()), + Some((&self.buffer as &dyn ComponentBatch).into()), Some((&self.format as &dyn ComponentBatch).into()), self.opacity .as_ref() @@ -266,11 +266,11 @@ impl SegmentationImage { /// Create a new `SegmentationImage`. #[inline] pub fn new( - data: impl Into, + buffer: impl Into, format: impl Into, ) -> Self { Self { - data: data.into(), + buffer: buffer.into(), format: format.into(), opacity: None, draw_order: None, diff --git a/crates/store/re_types/src/components/.gitattributes b/crates/store/re_types/src/components/.gitattributes index 5309b41c0bb9..18d0bf51b731 100644 --- a/crates/store/re_types/src/components/.gitattributes +++ b/crates/store/re_types/src/components/.gitattributes @@ -17,6 +17,7 @@ fill_ratio.rs linguist-generated=true gamma_correction.rs linguist-generated=true half_size2d.rs linguist-generated=true half_size3d.rs linguist-generated=true +image_buffer.rs linguist-generated=true image_format.rs linguist-generated=true image_plane_distance.rs linguist-generated=true keypoint_id.rs linguist-generated=true diff --git a/crates/store/re_types/src/components/image_buffer.rs b/crates/store/re_types/src/components/image_buffer.rs new file mode 100644 index 000000000000..ee4beaa1519e --- /dev/null +++ b/crates/store/re_types/src/components/image_buffer.rs @@ -0,0 +1,107 @@ +// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs +// Based on "crates/store/re_types/definitions/rerun/components/image_buffer.fbs". + +#![allow(unused_imports)] +#![allow(unused_parens)] +#![allow(clippy::clone_on_copy)] +#![allow(clippy::cloned_instead_of_copied)] +#![allow(clippy::map_flatten)] +#![allow(clippy::needless_question_mark)] +#![allow(clippy::new_without_default)] +#![allow(clippy::redundant_closure)] +#![allow(clippy::too_many_arguments)] +#![allow(clippy::too_many_lines)] + +use ::re_types_core::external::arrow2; +use ::re_types_core::ComponentName; +use ::re_types_core::SerializationResult; +use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; +use ::re_types_core::{DeserializationError, DeserializationResult}; + +/// **Component**: A buffer that is known to store image data. +/// +/// To interpret the contents of this buffer, see, [rerun.components.ImageFormat]. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[repr(transparent)] +pub struct ImageBuffer(pub crate::datatypes::Blob); + +impl ::re_types_core::SizeBytes for ImageBuffer { + #[inline] + fn heap_size_bytes(&self) -> u64 { + self.0.heap_size_bytes() + } + + #[inline] + fn is_pod() -> bool { + ::is_pod() + } +} + +impl> From for ImageBuffer { + fn from(v: T) -> Self { + Self(v.into()) + } +} + +impl std::borrow::Borrow for ImageBuffer { + #[inline] + fn borrow(&self) -> &crate::datatypes::Blob { + &self.0 + } +} + +impl std::ops::Deref for ImageBuffer { + type Target = crate::datatypes::Blob; + + #[inline] + fn deref(&self) -> &crate::datatypes::Blob { + &self.0 + } +} + +impl std::ops::DerefMut for ImageBuffer { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Blob { + &mut self.0 + } +} + +::re_types_core::macros::impl_into_cow!(ImageBuffer); + +impl ::re_types_core::Loggable for ImageBuffer { + type Name = ::re_types_core::ComponentName; + + #[inline] + fn name() -> Self::Name { + "rerun.components.ImageBuffer".into() + } + + #[inline] + fn arrow_datatype() -> arrow2::datatypes::DataType { + crate::datatypes::Blob::arrow_datatype() + } + + fn to_arrow_opt<'a>( + data: impl IntoIterator>>>, + ) -> SerializationResult> + where + Self: Clone + 'a, + { + crate::datatypes::Blob::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) + } + + fn from_arrow_opt( + arrow_data: &dyn arrow2::array::Array, + ) -> DeserializationResult>> + where + Self: Sized, + { + crate::datatypes::Blob::from_arrow_opt(arrow_data) + .map(|v| v.into_iter().map(|v| v.map(Self)).collect()) + } +} diff --git a/crates/store/re_types/src/components/mod.rs b/crates/store/re_types/src/components/mod.rs index bb54a24d5e46..bbc3a16f107b 100644 --- a/crates/store/re_types/src/components/mod.rs +++ b/crates/store/re_types/src/components/mod.rs @@ -27,6 +27,7 @@ mod half_size2d; mod half_size2d_ext; mod half_size3d; mod half_size3d_ext; +mod image_buffer; mod image_format; mod image_plane_distance; mod image_plane_distance_ext; @@ -120,6 +121,7 @@ pub use self::fill_ratio::FillRatio; pub use self::gamma_correction::GammaCorrection; pub use self::half_size2d::HalfSize2D; pub use self::half_size3d::HalfSize3D; +pub use self::image_buffer::ImageBuffer; pub use self::image_format::ImageFormat; pub use self::image_plane_distance::ImagePlaneDistance; pub use self::keypoint_id::KeypointId; diff --git a/crates/viewer/re_viewer/src/reflection/mod.rs b/crates/viewer/re_viewer/src/reflection/mod.rs index ae858a9dae54..e9ff8412d18f 100644 --- a/crates/viewer/re_viewer/src/reflection/mod.rs +++ b/crates/viewer/re_viewer/src/reflection/mod.rs @@ -356,6 +356,13 @@ fn generate_component_reflection() -> Result::name(), + ComponentReflection { + docstring_md: "A buffer that is known to store image data.\n\nTo interpret the contents of this buffer, see, [rerun.components.ImageFormat].", + placeholder: Some(ImageBuffer::default().to_arrow()?), + }, + ), ( ::name(), ComponentReflection { diff --git a/docs/content/reference/types/archetypes/depth_image.md b/docs/content/reference/types/archetypes/depth_image.md index a2fdcb632356..badb1a460b8e 100644 --- a/docs/content/reference/types/archetypes/depth_image.md +++ b/docs/content/reference/types/archetypes/depth_image.md @@ -9,7 +9,7 @@ Each pixel corresponds to a depth value in units specified by [`components.Depth ## Components -**Required**: [`Blob`](../components/blob.md), [`ImageFormat`](../components/image_format.md) +**Required**: [`ImageBuffer`](../components/image_buffer.md), [`ImageFormat`](../components/image_format.md) **Optional**: [`DepthMeter`](../components/depth_meter.md), [`Colormap`](../components/colormap.md), [`FillRatio`](../components/fill_ratio.md), [`DrawOrder`](../components/draw_order.md) diff --git a/docs/content/reference/types/archetypes/image.md b/docs/content/reference/types/archetypes/image.md index ee20a8c48d2e..214455b5922e 100644 --- a/docs/content/reference/types/archetypes/image.md +++ b/docs/content/reference/types/archetypes/image.md @@ -19,7 +19,7 @@ Compressing images can save a lot of bandwidth and memory. ## Components -**Required**: [`Blob`](../components/blob.md), [`ImageFormat`](../components/image_format.md) +**Required**: [`ImageBuffer`](../components/image_buffer.md), [`ImageFormat`](../components/image_format.md) **Optional**: [`Opacity`](../components/opacity.md), [`DrawOrder`](../components/draw_order.md) diff --git a/docs/content/reference/types/archetypes/segmentation_image.md b/docs/content/reference/types/archetypes/segmentation_image.md index a401cbbbd112..22426eb985e6 100644 --- a/docs/content/reference/types/archetypes/segmentation_image.md +++ b/docs/content/reference/types/archetypes/segmentation_image.md @@ -14,7 +14,7 @@ See also [`archetypes.AnnotationContext`](https://rerun.io/docs/reference/types/ ## Components -**Required**: [`Blob`](../components/blob.md), [`ImageFormat`](../components/image_format.md) +**Required**: [`ImageBuffer`](../components/image_buffer.md), [`ImageFormat`](../components/image_format.md) **Optional**: [`Opacity`](../components/opacity.md), [`DrawOrder`](../components/draw_order.md) diff --git a/docs/content/reference/types/components.md b/docs/content/reference/types/components.md index 2d21e8b6792d..d3d7814abc1a 100644 --- a/docs/content/reference/types/components.md +++ b/docs/content/reference/types/components.md @@ -30,6 +30,7 @@ on [Entities and Components](../../concepts/entity-component.md). * [`GammaCorrection`](components/gamma_correction.md): A gamma correction value to be used with a scalar value or color. * [`HalfSize2D`](components/half_size2d.md): Half-size (radius) of a 2D box. * [`HalfSize3D`](components/half_size3d.md): Half-size (radius) of a 3D box. +* [`ImageBuffer`](components/image_buffer.md): A buffer that is known to store image data. * [`ImageFormat`](components/image_format.md): The metadata describing the contents of a [rerun.components.ImageBuffer]. * [`ImagePlaneDistance`](components/image_plane_distance.md): The distance from the camera origin to the image plane when the projection is shown in a 3D viewer. * [`KeypointId`](components/keypoint_id.md): A 16-bit ID representing a type of semantic keypoint within a class. diff --git a/docs/content/reference/types/components/.gitattributes b/docs/content/reference/types/components/.gitattributes index 15714edbae74..eaa1cf6d2494 100644 --- a/docs/content/reference/types/components/.gitattributes +++ b/docs/content/reference/types/components/.gitattributes @@ -18,6 +18,7 @@ fill_ratio.md linguist-generated=true gamma_correction.md linguist-generated=true half_size2d.md linguist-generated=true half_size3d.md linguist-generated=true +image_buffer.md linguist-generated=true image_format.md linguist-generated=true image_plane_distance.md linguist-generated=true keypoint_id.md linguist-generated=true diff --git a/docs/content/reference/types/components/blob.md b/docs/content/reference/types/components/blob.md index 54de6296089a..b905276e27ab 100644 --- a/docs/content/reference/types/components/blob.md +++ b/docs/content/reference/types/components/blob.md @@ -18,7 +18,4 @@ A binary blob of data. ## Used by * [`Asset3D`](../archetypes/asset3d.md) -* [`DepthImage`](../archetypes/depth_image.md) * [`EncodedImage`](../archetypes/encoded_image.md?speculative-link) -* [`Image`](../archetypes/image.md) -* [`SegmentationImage`](../archetypes/segmentation_image.md) diff --git a/docs/content/reference/types/components/image_buffer.md b/docs/content/reference/types/components/image_buffer.md new file mode 100644 index 000000000000..843e5b46cfda --- /dev/null +++ b/docs/content/reference/types/components/image_buffer.md @@ -0,0 +1,24 @@ +--- +title: "ImageBuffer" +--- + + +A buffer that is known to store image data. + +To interpret the contents of this buffer, see, [rerun.components.ImageFormat]. + +## Fields + +* buffer: [`Blob`](../datatypes/blob.md) + +## API reference links + * 🌊 [C++ API docs for `ImageBuffer`](https://ref.rerun.io/docs/cpp/stable/structrerun_1_1components_1_1ImageBuffer.html) + * 🐍 [Python API docs for `ImageBuffer`](https://ref.rerun.io/docs/python/stable/common/components#rerun.components.ImageBuffer) + * 🦀 [Rust API docs for `ImageBuffer`](https://docs.rs/rerun/latest/rerun/components/struct.ImageBuffer.html) + + +## Used by + +* [`DepthImage`](../archetypes/depth_image.md) +* [`Image`](../archetypes/image.md) +* [`SegmentationImage`](../archetypes/segmentation_image.md) diff --git a/docs/content/reference/types/datatypes/blob.md b/docs/content/reference/types/datatypes/blob.md index b903cf6de722..14a530a39eb2 100644 --- a/docs/content/reference/types/datatypes/blob.md +++ b/docs/content/reference/types/datatypes/blob.md @@ -18,3 +18,4 @@ A binary blob of data. ## Used by * [`Blob`](../components/blob.md) +* [`ImageBuffer`](../components/image_buffer.md) diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.cpp b/rerun_cpp/src/rerun/archetypes/depth_image.cpp index 1921fc8197f2..b61939437b75 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.cpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.cpp @@ -17,7 +17,7 @@ namespace rerun { cells.reserve(7); { - auto result = DataCell::from_loggable(archetype.data); + auto result = DataCell::from_loggable(archetype.buffer); RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.hpp b/rerun_cpp/src/rerun/archetypes/depth_image.hpp index 717de86fee29..1431c7241b7d 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.hpp @@ -5,11 +5,11 @@ #include "../collection.hpp" #include "../compiler_utils.hpp" -#include "../components/blob.hpp" #include "../components/colormap.hpp" #include "../components/depth_meter.hpp" #include "../components/draw_order.hpp" #include "../components/fill_ratio.hpp" +#include "../components/image_buffer.hpp" #include "../components/image_format.hpp" #include "../data_cell.hpp" #include "../image_utils.hpp" @@ -75,7 +75,7 @@ namespace rerun::archetypes { /// ``` struct DepthImage { /// The raw depth image data. - rerun::components::Blob data; + rerun::components::ImageBuffer buffer; /// The format of the image. rerun::components::ImageFormat format; diff --git a/rerun_cpp/src/rerun/archetypes/image.cpp b/rerun_cpp/src/rerun/archetypes/image.cpp index 725f4f540f34..faf53b7567f8 100644 --- a/rerun_cpp/src/rerun/archetypes/image.cpp +++ b/rerun_cpp/src/rerun/archetypes/image.cpp @@ -17,7 +17,7 @@ namespace rerun { cells.reserve(5); { - auto result = DataCell::from_loggable(archetype.data); + auto result = DataCell::from_loggable(archetype.buffer); RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } diff --git a/rerun_cpp/src/rerun/archetypes/image.hpp b/rerun_cpp/src/rerun/archetypes/image.hpp index d8e2f9408c77..cf0464ce7b3c 100644 --- a/rerun_cpp/src/rerun/archetypes/image.hpp +++ b/rerun_cpp/src/rerun/archetypes/image.hpp @@ -5,8 +5,8 @@ #include "../collection.hpp" #include "../compiler_utils.hpp" -#include "../components/blob.hpp" #include "../components/draw_order.hpp" +#include "../components/image_buffer.hpp" #include "../components/image_format.hpp" #include "../components/opacity.hpp" #include "../data_cell.hpp" @@ -72,7 +72,7 @@ namespace rerun::archetypes { /// ``` struct Image { /// The raw image data. - rerun::components::Blob data; + rerun::components::ImageBuffer buffer; /// The format of the image. rerun::components::ImageFormat format; diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp index a236887e9261..95d68b9b7a9f 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp @@ -17,7 +17,7 @@ namespace rerun { cells.reserve(5); { - auto result = DataCell::from_loggable(archetype.data); + auto result = DataCell::from_loggable(archetype.buffer); RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp index 4aa4e236d4fa..c7370128749b 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp @@ -5,8 +5,8 @@ #include "../collection.hpp" #include "../compiler_utils.hpp" -#include "../components/blob.hpp" #include "../components/draw_order.hpp" +#include "../components/image_buffer.hpp" #include "../components/image_format.hpp" #include "../components/opacity.hpp" #include "../data_cell.hpp" @@ -73,7 +73,7 @@ namespace rerun::archetypes { /// ``` struct SegmentationImage { /// The raw image data. - rerun::components::Blob data; + rerun::components::ImageBuffer buffer; /// The format of the image. rerun::components::ImageFormat format; diff --git a/rerun_cpp/src/rerun/components.hpp b/rerun_cpp/src/rerun/components.hpp index b0c29eb3e722..257032d0c4a9 100644 --- a/rerun_cpp/src/rerun/components.hpp +++ b/rerun_cpp/src/rerun/components.hpp @@ -19,6 +19,7 @@ #include "components/gamma_correction.hpp" #include "components/half_size2d.hpp" #include "components/half_size3d.hpp" +#include "components/image_buffer.hpp" #include "components/image_format.hpp" #include "components/image_plane_distance.hpp" #include "components/keypoint_id.hpp" diff --git a/rerun_cpp/src/rerun/components/.gitattributes b/rerun_cpp/src/rerun/components/.gitattributes index 88bbd1edbba8..385cb4fe101a 100644 --- a/rerun_cpp/src/rerun/components/.gitattributes +++ b/rerun_cpp/src/rerun/components/.gitattributes @@ -22,6 +22,7 @@ fill_ratio.hpp linguist-generated=true gamma_correction.hpp linguist-generated=true half_size2d.hpp linguist-generated=true half_size3d.hpp linguist-generated=true +image_buffer.hpp linguist-generated=true image_format.hpp linguist-generated=true image_plane_distance.hpp linguist-generated=true keypoint_id.hpp linguist-generated=true diff --git a/rerun_cpp/src/rerun/components/image_buffer.hpp b/rerun_cpp/src/rerun/components/image_buffer.hpp new file mode 100644 index 000000000000..f9c0c52f8e4e --- /dev/null +++ b/rerun_cpp/src/rerun/components/image_buffer.hpp @@ -0,0 +1,65 @@ +// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs +// Based on "crates/store/re_types/definitions/rerun/components/image_buffer.fbs". + +#pragma once + +#include "../collection.hpp" +#include "../datatypes/blob.hpp" +#include "../result.hpp" + +#include +#include +#include + +namespace rerun::components { + /// **Component**: A buffer that is known to store image data. + /// + /// To interpret the contents of this buffer, see, [rerun.components.ImageFormat]. + struct ImageBuffer { + rerun::datatypes::Blob buffer; + + public: + ImageBuffer() = default; + + ImageBuffer(rerun::datatypes::Blob buffer_) : buffer(std::move(buffer_)) {} + + ImageBuffer& operator=(rerun::datatypes::Blob buffer_) { + buffer = std::move(buffer_); + return *this; + } + + ImageBuffer(rerun::Collection data_) : buffer(std::move(data_)) {} + + ImageBuffer& operator=(rerun::Collection data_) { + buffer = std::move(data_); + return *this; + } + + /// Cast to the underlying Blob datatype + operator rerun::datatypes::Blob() const { + return buffer; + } + }; +} // namespace rerun::components + +namespace rerun { + static_assert(sizeof(rerun::datatypes::Blob) == sizeof(components::ImageBuffer)); + + /// \private + template <> + struct Loggable { + static constexpr const char Name[] = "rerun.components.ImageBuffer"; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype() { + return Loggable::arrow_datatype(); + } + + /// Serializes an array of `rerun::components::ImageBuffer` into an arrow array. + static Result> to_arrow( + const components::ImageBuffer* instances, size_t num_instances + ) { + return Loggable::to_arrow(&instances->buffer, num_instances); + } + }; +} // namespace rerun diff --git a/rerun_py/rerun_sdk/rerun/archetypes/depth_image.py b/rerun_py/rerun_sdk/rerun/archetypes/depth_image.py index e2080321b41f..14b8da0ac6a9 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/depth_image.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/depth_image.py @@ -66,7 +66,7 @@ class DepthImage(DepthImageExt, Archetype): def __attrs_clear__(self) -> None: """Convenience method for calling `__attrs_init__` with all `None`s.""" self.__attrs_init__( - data=None, # type: ignore[arg-type] + buffer=None, # type: ignore[arg-type] format=None, # type: ignore[arg-type] meter=None, # type: ignore[arg-type] colormap=None, # type: ignore[arg-type] @@ -81,9 +81,9 @@ def _clear(cls) -> DepthImage: inst.__attrs_clear__() return inst - data: components.BlobBatch = field( + buffer: components.ImageBufferBatch = field( metadata={"component": "required"}, - converter=components.BlobBatch._required, # type: ignore[misc] + converter=components.ImageBufferBatch._required, # type: ignore[misc] ) # The raw depth image data. # diff --git a/rerun_py/rerun_sdk/rerun/archetypes/image.py b/rerun_py/rerun_sdk/rerun/archetypes/image.py index d53aa011ef37..f526c8a9300f 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/image.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/image.py @@ -66,7 +66,7 @@ class Image(ImageExt, Archetype): def __attrs_clear__(self) -> None: """Convenience method for calling `__attrs_init__` with all `None`s.""" self.__attrs_init__( - data=None, # type: ignore[arg-type] + buffer=None, # type: ignore[arg-type] format=None, # type: ignore[arg-type] opacity=None, # type: ignore[arg-type] draw_order=None, # type: ignore[arg-type] @@ -79,9 +79,9 @@ def _clear(cls) -> Image: inst.__attrs_clear__() return inst - data: components.BlobBatch = field( + buffer: components.ImageBufferBatch = field( metadata={"component": "required"}, - converter=components.BlobBatch._required, # type: ignore[misc] + converter=components.ImageBufferBatch._required, # type: ignore[misc] ) # The raw image data. # diff --git a/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image.py b/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image.py index 6fc73c808984..a21161c669e6 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image.py @@ -64,7 +64,7 @@ class SegmentationImage(SegmentationImageExt, Archetype): def __attrs_clear__(self) -> None: """Convenience method for calling `__attrs_init__` with all `None`s.""" self.__attrs_init__( - data=None, # type: ignore[arg-type] + buffer=None, # type: ignore[arg-type] format=None, # type: ignore[arg-type] opacity=None, # type: ignore[arg-type] draw_order=None, # type: ignore[arg-type] @@ -77,9 +77,9 @@ def _clear(cls) -> SegmentationImage: inst.__attrs_clear__() return inst - data: components.BlobBatch = field( + buffer: components.ImageBufferBatch = field( metadata={"component": "required"}, - converter=components.BlobBatch._required, # type: ignore[misc] + converter=components.ImageBufferBatch._required, # type: ignore[misc] ) # The raw image data. # diff --git a/rerun_py/rerun_sdk/rerun/components/.gitattributes b/rerun_py/rerun_sdk/rerun/components/.gitattributes index a7141e6dc5a1..6a49d19594fc 100644 --- a/rerun_py/rerun_sdk/rerun/components/.gitattributes +++ b/rerun_py/rerun_sdk/rerun/components/.gitattributes @@ -19,6 +19,7 @@ fill_ratio.py linguist-generated=true gamma_correction.py linguist-generated=true half_size2d.py linguist-generated=true half_size3d.py linguist-generated=true +image_buffer.py linguist-generated=true image_format.py linguist-generated=true image_plane_distance.py linguist-generated=true keypoint_id.py linguist-generated=true diff --git a/rerun_py/rerun_sdk/rerun/components/__init__.py b/rerun_py/rerun_sdk/rerun/components/__init__.py index bd9a40b9c000..88cb7fa7da17 100644 --- a/rerun_py/rerun_sdk/rerun/components/__init__.py +++ b/rerun_py/rerun_sdk/rerun/components/__init__.py @@ -31,6 +31,7 @@ from .gamma_correction import GammaCorrection, GammaCorrectionBatch, GammaCorrectionType from .half_size2d import HalfSize2D, HalfSize2DBatch, HalfSize2DType from .half_size3d import HalfSize3D, HalfSize3DBatch, HalfSize3DType +from .image_buffer import ImageBuffer, ImageBufferBatch, ImageBufferType from .image_format import ImageFormat, ImageFormatBatch, ImageFormatType from .image_plane_distance import ImagePlaneDistance, ImagePlaneDistanceBatch, ImagePlaneDistanceType from .keypoint_id import KeypointId, KeypointIdBatch, KeypointIdType @@ -149,6 +150,9 @@ "HalfSize3D", "HalfSize3DBatch", "HalfSize3DType", + "ImageBuffer", + "ImageBufferBatch", + "ImageBufferType", "ImageFormat", "ImageFormatBatch", "ImageFormatType", diff --git a/rerun_py/rerun_sdk/rerun/components/image_buffer.py b/rerun_py/rerun_sdk/rerun/components/image_buffer.py new file mode 100644 index 000000000000..30cd038b600b --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/components/image_buffer.py @@ -0,0 +1,40 @@ +# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs +# Based on "crates/store/re_types/definitions/rerun/components/image_buffer.fbs". + +# You can extend this class by creating a "ImageBufferExt" class in "image_buffer_ext.py". + +from __future__ import annotations + +from .. import datatypes +from .._baseclasses import ( + ComponentBatchMixin, + ComponentMixin, +) + +__all__ = ["ImageBuffer", "ImageBufferBatch", "ImageBufferType"] + + +class ImageBuffer(datatypes.Blob, ComponentMixin): + """ + **Component**: A buffer that is known to store image data. + + To interpret the contents of this buffer, see, [rerun.components.ImageFormat]. + """ + + _BATCH_TYPE = None + # You can define your own __init__ function as a member of ImageBufferExt in image_buffer_ext.py + + # Note: there are no fields here because ImageBuffer delegates to datatypes.Blob + pass + + +class ImageBufferType(datatypes.BlobType): + _TYPE_NAME: str = "rerun.components.ImageBuffer" + + +class ImageBufferBatch(datatypes.BlobBatch, ComponentBatchMixin): + _ARROW_TYPE = ImageBufferType() + + +# This is patched in late to avoid circular dependencies. +ImageBuffer._BATCH_TYPE = ImageBufferBatch # type: ignore[assignment] From b192e6e997af7cf3d53036dd59efa6b16088c2ad Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 12:02:26 -0400 Subject: [PATCH 3/6] Update rust code for blob -> buffer --- .../src/archetypes/depth_image_ext.rs | 2 +- .../re_types/src/archetypes/image_ext.rs | 30 +++++++-------- .../src/archetypes/segmentation_image_ext.rs | 2 +- crates/store/re_types/tests/depth_image.rs | 2 +- .../re_types/tests/segmentation_image.rs | 2 +- crates/viewer/re_space_view_spatial/src/ui.rs | 12 +++--- .../src/visualizers/depth_images.rs | 19 ++++++---- .../src/visualizers/images.rs | 17 +++++---- .../src/visualizers/segmentation_images.rs | 18 +++++---- .../src/gpu_bridge/image_to_gpu.rs | 14 +++---- .../re_viewer_context/src/image_info.rs | 38 +++++++++---------- .../src/tensor/image_decode_cache.rs | 8 ++-- .../src/tensor/image_stats_cache.rs | 2 +- 13 files changed, 86 insertions(+), 80 deletions(-) diff --git a/crates/store/re_types/src/archetypes/depth_image_ext.rs b/crates/store/re_types/src/archetypes/depth_image_ext.rs index e97d76cff885..a1ab8eac0dde 100644 --- a/crates/store/re_types/src/archetypes/depth_image_ext.rs +++ b/crates/store/re_types/src/archetypes/depth_image_ext.rs @@ -36,7 +36,7 @@ impl DepthImage { let image_format = ImageFormat::depth([width, height], datatype); Ok(Self { - data: blob.into(), + buffer: blob.into(), format: image_format.into(), draw_order: None, meter: None, diff --git a/crates/store/re_types/src/archetypes/image_ext.rs b/crates/store/re_types/src/archetypes/image_ext.rs index 6d8bc16c8e43..bdadc5ccadb3 100644 --- a/crates/store/re_types/src/archetypes/image_ext.rs +++ b/crates/store/re_types/src/archetypes/image_ext.rs @@ -1,5 +1,5 @@ use crate::{ - components::Blob, + components::ImageBuffer, datatypes::{ChannelDatatype, ColorModel, ImageFormat, PixelFormat, TensorData}, image::{ blob_and_datatype_from_tensor, find_non_empty_dim_indices, ImageChannelType, @@ -66,7 +66,7 @@ impl Image { }; Ok(Self { - data: blob.into(), + buffer: blob.into(), format: image_format.into(), opacity: None, draw_order: None, @@ -79,14 +79,14 @@ impl Image { pub fn from_pixel_format( [width, height]: [u32; 2], pixel_format: PixelFormat, - bytes: impl Into, + bytes: impl Into, ) -> Self { - let data = bytes.into(); + let buffer = bytes.into(); - let actual_bytes = data.len(); + let actual_bytes = buffer.len(); let bpp = pixel_format.bits_per_pixel(); let num_expected_bytes = (width as usize * height as usize * bpp + 7) / 8; // rounding upwards - if data.len() != num_expected_bytes { + if buffer.len() != num_expected_bytes { re_log::warn_once!( "Expected {width}x{height} {pixel_format:?} image to be {num_expected_bytes} B, but got {actual_bytes} B", ); @@ -95,7 +95,7 @@ impl Image { let image_format = ImageFormat::from_pixel_format([width, height], pixel_format); Self { - data, + buffer, format: image_format.into(), opacity: None, draw_order: None, @@ -106,18 +106,18 @@ impl Image { /// /// See also [`Self::from_color_model_and_tensor`]. pub fn from_color_model_and_bytes( - bytes: impl Into, + bytes: impl Into, [width, height]: [u32; 2], color_model: ColorModel, datatype: ChannelDatatype, ) -> Self { - let data = bytes.into(); + let buffer = bytes.into(); - let actual_bytes = data.len(); + let actual_bytes = buffer.len(); let num_expected_bytes = (width as usize * height as usize * color_model.num_channels() * datatype.bits() + 7) / 8; // rounding upwards - if data.len() != num_expected_bytes { + if buffer.len() != num_expected_bytes { re_log::warn_once!( "Expected {width}x{height} {color_model:?} {datatype:?} image to be {num_expected_bytes} B, but got {actual_bytes} B", ); @@ -132,7 +132,7 @@ impl Image { }; Self { - data, + buffer, format: image_format.into(), opacity: None, draw_order: None, @@ -157,17 +157,17 @@ impl Image { } /// From an 8-bit grayscale image. - pub fn from_l8(bytes: impl Into, resolution: [u32; 2]) -> Self { + pub fn from_l8(bytes: impl Into, resolution: [u32; 2]) -> Self { Self::from_color_model_and_bytes(bytes, resolution, ColorModel::L, ChannelDatatype::U8) } /// Assumes RGB, 8-bit per channel, interleaved as `RGBRGBRGB`. - pub fn from_rgb24(bytes: impl Into, resolution: [u32; 2]) -> Self { + pub fn from_rgb24(bytes: impl Into, resolution: [u32; 2]) -> Self { Self::from_color_model_and_bytes(bytes, resolution, ColorModel::RGB, ChannelDatatype::U8) } /// Assumes RGBA, 8-bit per channel, with separate alpha. - pub fn from_rgba32(bytes: impl Into, resolution: [u32; 2]) -> Self { + pub fn from_rgba32(bytes: impl Into, resolution: [u32; 2]) -> Self { Self::from_color_model_and_bytes(bytes, resolution, ColorModel::RGBA, ChannelDatatype::U8) } diff --git a/crates/store/re_types/src/archetypes/segmentation_image_ext.rs b/crates/store/re_types/src/archetypes/segmentation_image_ext.rs index 477b0c0339ba..4c2f71375b39 100644 --- a/crates/store/re_types/src/archetypes/segmentation_image_ext.rs +++ b/crates/store/re_types/src/archetypes/segmentation_image_ext.rs @@ -36,7 +36,7 @@ impl SegmentationImage { let image_format = ImageFormat::segmentation([width, height], datatype); Ok(Self { - data: blob.into(), + buffer: blob.into(), format: image_format.into(), draw_order: None, opacity: None, diff --git a/crates/store/re_types/tests/depth_image.rs b/crates/store/re_types/tests/depth_image.rs index 5068e95d0f17..f37bc7f9c16f 100644 --- a/crates/store/re_types/tests/depth_image.rs +++ b/crates/store/re_types/tests/depth_image.rs @@ -20,7 +20,7 @@ fn depth_image_roundtrip() { }; let all_expected = [DepthImage { - data: vec![1, 2, 3, 4, 5, 6].into(), + buffer: vec![1, 2, 3, 4, 5, 6].into(), format: format_expected.into(), meter: Some(DepthMeter::from(1000.0)), draw_order: None, diff --git a/crates/store/re_types/tests/segmentation_image.rs b/crates/store/re_types/tests/segmentation_image.rs index 3d6fb73d303f..4c8ad5841e8d 100644 --- a/crates/store/re_types/tests/segmentation_image.rs +++ b/crates/store/re_types/tests/segmentation_image.rs @@ -19,7 +19,7 @@ fn segmentation_image_roundtrip() { }; let all_expected = [SegmentationImage { - data: vec![1, 2, 3, 4, 5, 6].into(), + buffer: vec![1, 2, 3, 4, 5, 6].into(), format: format_expected.into(), draw_order: None, opacity: None, diff --git a/crates/viewer/re_space_view_spatial/src/ui.rs b/crates/viewer/re_space_view_spatial/src/ui.rs index 1dce9289a525..04aeed9263bb 100644 --- a/crates/viewer/re_space_view_spatial/src/ui.rs +++ b/crates/viewer/re_space_view_spatial/src/ui.rs @@ -16,7 +16,7 @@ use re_space_view::{latest_at_with_blueprint_resolved_data, ScreenshotMode}; use re_types::{ archetypes::Pinhole, blueprint::components::VisualBounds2D, - components::{Blob, Colormap, DepthMeter, ImageFormat, ViewCoordinates}, + components::{Colormap, DepthMeter, ImageBuffer, ImageFormat, ViewCoordinates}, image::ImageKind, Loggable as _, }; @@ -593,7 +593,7 @@ fn picked_image_from_depth_image_query( &query, data_result, [ - Blob::name(), + ImageBuffer::name(), ImageFormat::name(), Colormap::name(), DepthMeter::name(), @@ -603,8 +603,8 @@ fn picked_image_from_depth_image_query( // TODO(andreas): Just calling `results.get_mono::` would be a lot more elegant. // However, we're in the rare case where we really want a RowId to be able to identify the tensor for caching purposes. - let blob_untyped = results.get(Blob::name())?; - let blob = blob_untyped.component_mono::()?.ok()?.0; + let blob_untyped = results.get(ImageBuffer::name())?; + let blob = blob_untyped.component_mono::()?.ok()?.0; let format = results.get_mono::()?; let colormap = results.get_mono::()?; @@ -617,8 +617,8 @@ fn picked_image_from_depth_image_query( .to_2d_image_coordinate(format.width as _); let image = ImageInfo { - blob_row_id, - blob, + buffer_row_id: blob_row_id, + buffer: blob, format: format.0, kind: ImageKind::Depth, colormap: Some(colormap), diff --git a/crates/viewer/re_space_view_spatial/src/visualizers/depth_images.rs b/crates/viewer/re_space_view_spatial/src/visualizers/depth_images.rs index 18a06829cd2d..1fa0d9491891 100644 --- a/crates/viewer/re_space_view_spatial/src/visualizers/depth_images.rs +++ b/crates/viewer/re_space_view_spatial/src/visualizers/depth_images.rs @@ -7,7 +7,7 @@ use re_renderer::renderer::{DepthCloud, DepthClouds}; use re_types::{ archetypes::DepthImage, components::{ - self, Blob, Colormap, DepthMeter, DrawOrder, FillRatio, ImageFormat, ViewCoordinates, + self, Colormap, DepthMeter, DrawOrder, FillRatio, ImageBuffer, ImageFormat, ViewCoordinates, }, image::ImageKind, Loggable as _, @@ -248,7 +248,8 @@ impl VisualizerSystem for DepthImageVisualizer { |ctx, spatial_ctx, results| { use re_space_view::RangeResultsExt as _; - let Some(all_blob_chunks) = results.get_required_chunks(&Blob::name()) else { + let Some(all_buffer_chunks) = results.get_required_chunks(&ImageBuffer::name()) + else { return Ok(()); }; let Some(all_format_chunks) = results.get_required_chunks(&ImageFormat::name()) @@ -257,7 +258,8 @@ impl VisualizerSystem for DepthImageVisualizer { }; let timeline = ctx.query.timeline(); - let all_blobs_indexed = iter_buffer::(&all_blob_chunks, timeline, Blob::name()); + let all_buffers_indexed = + iter_buffer::(&all_buffer_chunks, timeline, ImageBuffer::name()); let all_formats_indexed = iter_component::( &all_format_chunks, timeline, @@ -268,19 +270,20 @@ impl VisualizerSystem for DepthImageVisualizer { let all_fill_ratios = results.iter_as(timeline, FillRatio::name()); let mut data = re_query::range_zip_1x4( - all_blobs_indexed, + all_buffers_indexed, all_formats_indexed, all_colormaps.component::(), all_depth_meters.primitive::(), all_fill_ratios.primitive::(), ) .filter_map( - |(index, blobs, format, colormap, depth_meter, fill_ratio)| { - let blob = blobs.first()?; + |(index, buffers, format, colormap, depth_meter, fill_ratio)| { + let buffer = buffers.first()?; + Some(DepthImageComponentData { image: ImageInfo { - blob_row_id: index.1, - blob: blob.clone().into(), + buffer_row_id: index.1, + buffer: buffer.clone().into(), format: first_copied(format.as_deref())?.0, kind: ImageKind::Depth, colormap: first_copied(colormap.as_deref()), diff --git a/crates/viewer/re_space_view_spatial/src/visualizers/images.rs b/crates/viewer/re_space_view_spatial/src/visualizers/images.rs index 078a6e364fb4..fe5a4d57d008 100644 --- a/crates/viewer/re_space_view_spatial/src/visualizers/images.rs +++ b/crates/viewer/re_space_view_spatial/src/visualizers/images.rs @@ -3,7 +3,7 @@ use itertools::Itertools as _; use re_space_view::HybridResults; use re_types::{ archetypes::Image, - components::{Blob, DrawOrder, ImageFormat, Opacity}, + components::{DrawOrder, ImageBuffer, ImageFormat, Opacity}, image::ImageKind, Loggable as _, }; @@ -141,7 +141,7 @@ impl ImageVisualizer { let entity_path = ctx.target_entity_path; - let Some(all_blob_chunks) = results.get_required_chunks(&Blob::name()) else { + let Some(all_buffer_chunks) = results.get_required_chunks(&ImageBuffer::name()) else { return; }; let Some(all_formats_chunks) = results.get_required_chunks(&ImageFormat::name()) else { @@ -149,23 +149,24 @@ impl ImageVisualizer { }; let timeline = ctx.query.timeline(); - let all_blobs_indexed = iter_buffer::(&all_blob_chunks, timeline, Blob::name()); + let all_buffers_indexed = + iter_buffer::(&all_buffer_chunks, timeline, ImageBuffer::name()); let all_formats_indexed = iter_component::(&all_formats_chunks, timeline, ImageFormat::name()); let all_opacities = results.iter_as(timeline, Opacity::name()); let data = re_query::range_zip_1x2( - all_blobs_indexed, + all_buffers_indexed, all_formats_indexed, all_opacities.primitive::(), ) - .filter_map(|(index, blobs, formats, opacities)| { - let blob = blobs.first()?.0.clone(); + .filter_map(|(index, buffers, formats, opacities)| { + let buffer = buffers.first()?; Some(ImageComponentData { image: ImageInfo { - blob_row_id: index.1, - blob: re_types::datatypes::Blob(blob.into()), + buffer_row_id: index.1, + buffer: buffer.clone().into(), format: first_copied(formats.as_deref())?.0, kind: ImageKind::Color, colormap: None, diff --git a/crates/viewer/re_space_view_spatial/src/visualizers/segmentation_images.rs b/crates/viewer/re_space_view_spatial/src/visualizers/segmentation_images.rs index d13739adfcaf..b87daf70af66 100644 --- a/crates/viewer/re_space_view_spatial/src/visualizers/segmentation_images.rs +++ b/crates/viewer/re_space_view_spatial/src/visualizers/segmentation_images.rs @@ -2,7 +2,7 @@ use itertools::Itertools as _; use re_types::{ archetypes::SegmentationImage, - components::{Blob, DrawOrder, ImageFormat, Opacity}, + components::{DrawOrder, ImageBuffer, ImageFormat, Opacity}, image::ImageKind, Loggable as _, }; @@ -81,7 +81,8 @@ impl VisualizerSystem for SegmentationImageVisualizer { let entity_path = ctx.target_entity_path; - let Some(all_blob_chunks) = results.get_required_chunks(&Blob::name()) else { + let Some(all_buffer_chunks) = results.get_required_chunks(&ImageBuffer::name()) + else { return Ok(()); }; let Some(all_formats_chunks) = results.get_required_chunks(&ImageFormat::name()) @@ -90,7 +91,8 @@ impl VisualizerSystem for SegmentationImageVisualizer { }; let timeline = ctx.query.timeline(); - let all_blobs_indexed = iter_buffer::(&all_blob_chunks, timeline, Blob::name()); + let all_buffers_indexed = + iter_buffer::(&all_buffer_chunks, timeline, ImageBuffer::name()); let all_formats_indexed = iter_component::( &all_formats_chunks, timeline, @@ -99,16 +101,16 @@ impl VisualizerSystem for SegmentationImageVisualizer { let all_opacities = results.iter_as(timeline, Opacity::name()); let data = re_query::range_zip_1x2( - all_blobs_indexed, + all_buffers_indexed, all_formats_indexed, all_opacities.primitive::(), ) - .filter_map(|(index, blobs, formats, opacity)| { - let blob = blobs.first()?; + .filter_map(|(index, buffers, formats, opacity)| { + let buffer = buffers.first()?; Some(SegmentationImageComponentData { image: ImageInfo { - blob_row_id: index.1, - blob: blob.clone().into(), + buffer_row_id: index.1, + buffer: buffer.clone().into(), format: first_copied(formats.as_deref())?.0, kind: ImageKind::Segmentation, colormap: None, diff --git a/crates/viewer/re_viewer_context/src/gpu_bridge/image_to_gpu.rs b/crates/viewer/re_viewer_context/src/gpu_bridge/image_to_gpu.rs index 72c54d8cdd4a..3a178ce56027 100644 --- a/crates/viewer/re_viewer_context/src/gpu_bridge/image_to_gpu.rs +++ b/crates/viewer/re_viewer_context/src/gpu_bridge/image_to_gpu.rs @@ -28,8 +28,8 @@ use super::{get_or_create_texture, RangeError}; fn generate_texture_key(image: &ImageInfo) -> u64 { // We need to inclde anything that, if changes, should result in a new texture being uploaded. let ImageInfo { - blob_row_id, - blob: _, // we hash `blob_row_id` instead; much faster! + buffer_row_id: blob_row_id, + buffer: _, // we hash `blob_row_id` instead; much faster! format, kind, @@ -226,7 +226,7 @@ fn texture_creation_desc_from_color_image<'a>( // Decoded in the shader. return Texture2DCreationDesc { label: debug_name.into(), - data: cast_slice_to_cow(image.blob.as_slice()), + data: cast_slice_to_cow(image.buffer.as_slice()), format: TextureFormat::R8Uint, width: image.width(), height: image.height() + image.height() / 2, // ! @@ -237,7 +237,7 @@ fn texture_creation_desc_from_color_image<'a>( // Decoded in the shader. return Texture2DCreationDesc { label: debug_name.into(), - data: cast_slice_to_cow(image.blob.as_slice()), + data: cast_slice_to_cow(image.buffer.as_slice()), format: TextureFormat::R8Uint, width: 2 * image.width(), // ! height: image.height(), @@ -252,12 +252,12 @@ fn texture_creation_desc_from_color_image<'a>( // Why? Because premul must happen _before_ sRGB decode, so we can't // use a "Srgb-aware" texture like `Rgba8UnormSrgb` for RGBA. (ColorModel::RGB, ChannelDatatype::U8) => ( - pad_rgb_to_rgba(&image.blob, u8::MAX).into(), + pad_rgb_to_rgba(&image.buffer, u8::MAX).into(), TextureFormat::Rgba8Unorm, ), (ColorModel::RGBA, ChannelDatatype::U8) => { - (cast_slice_to_cow(&image.blob), TextureFormat::Rgba8Unorm) + (cast_slice_to_cow(&image.buffer), TextureFormat::Rgba8Unorm) } _ => { @@ -441,7 +441,7 @@ fn general_texture_creation_desc_from_image<'a>( let width = image.width(); let height = image.height(); - let buf: &[u8] = image.blob.as_ref(); + let buf: &[u8] = image.buffer.as_ref(); let (data, format) = match color_model { ColorModel::L => { diff --git a/crates/viewer/re_viewer_context/src/image_info.rs b/crates/viewer/re_viewer_context/src/image_info.rs index fcebbe449b4e..921d58cd4bc6 100644 --- a/crates/viewer/re_viewer_context/src/image_info.rs +++ b/crates/viewer/re_viewer_context/src/image_info.rs @@ -15,11 +15,11 @@ use re_types::{ pub struct ImageInfo { /// The row id that contaoned the blob. /// - /// Can be used instead of hashing [`Self::blob`]. - pub blob_row_id: RowId, + /// Can be used instead of hashing [`Self::buffer`]. + pub buffer_row_id: RowId, /// The image data, row-wise, with stride=width. - pub blob: Blob, + pub buffer: Blob, /// Describes the format of [`Self::blob`]. pub format: ImageFormat, @@ -65,7 +65,7 @@ impl ImageInfo { } if let Some(pixel_format) = self.format.pixel_format { - let buf: &[u8] = &self.blob; + let buf: &[u8] = &self.buffer; // NOTE: the name `y` is already taken for the coordinate, so we use `luma` here. let [luma, u, v] = match pixel_format { @@ -114,19 +114,19 @@ impl ImageInfo { (y as usize * stride as usize + x as usize) * num_channels + channel as usize; match self.format.datatype() { - ChannelDatatype::U8 => self.blob.get(offset).copied().map(TensorElement::U8), - ChannelDatatype::U16 => get(&self.blob, offset).map(TensorElement::U16), - ChannelDatatype::U32 => get(&self.blob, offset).map(TensorElement::U32), - ChannelDatatype::U64 => get(&self.blob, offset).map(TensorElement::U64), - - ChannelDatatype::I8 => get(&self.blob, offset).map(TensorElement::I8), - ChannelDatatype::I16 => get(&self.blob, offset).map(TensorElement::I16), - ChannelDatatype::I32 => get(&self.blob, offset).map(TensorElement::I32), - ChannelDatatype::I64 => get(&self.blob, offset).map(TensorElement::I64), - - ChannelDatatype::F16 => get(&self.blob, offset).map(TensorElement::F16), - ChannelDatatype::F32 => get(&self.blob, offset).map(TensorElement::F32), - ChannelDatatype::F64 => get(&self.blob, offset).map(TensorElement::F64), + ChannelDatatype::U8 => self.buffer.get(offset).copied().map(TensorElement::U8), + ChannelDatatype::U16 => get(&self.buffer, offset).map(TensorElement::U16), + ChannelDatatype::U32 => get(&self.buffer, offset).map(TensorElement::U32), + ChannelDatatype::U64 => get(&self.buffer, offset).map(TensorElement::U64), + + ChannelDatatype::I8 => get(&self.buffer, offset).map(TensorElement::I8), + ChannelDatatype::I16 => get(&self.buffer, offset).map(TensorElement::I16), + ChannelDatatype::I32 => get(&self.buffer, offset).map(TensorElement::I32), + ChannelDatatype::I64 => get(&self.buffer, offset).map(TensorElement::I64), + + ChannelDatatype::F16 => get(&self.buffer, offset).map(TensorElement::F16), + ChannelDatatype::F32 => get(&self.buffer, offset).map(TensorElement::F32), + ChannelDatatype::F64 => get(&self.buffer, offset).map(TensorElement::F64), } } } @@ -140,9 +140,9 @@ impl ImageInfo { /// this function will copy the data. pub fn to_slice(&self) -> Cow<'_, [T]> { let element_size = std::mem::size_of::(); - let num_elements = self.blob.len() / element_size; + let num_elements = self.buffer.len() / element_size; let num_bytes = num_elements * element_size; - let bytes = &self.blob[..num_bytes]; + let bytes = &self.buffer[..num_bytes]; if let Ok(slice) = bytemuck::try_cast_slice(bytes) { Cow::Borrowed(slice) diff --git a/crates/viewer/re_viewer_context/src/tensor/image_decode_cache.rs b/crates/viewer/re_viewer_context/src/tensor/image_decode_cache.rs index cd723b5f3b4f..451c150a10df 100644 --- a/crates/viewer/re_viewer_context/src/tensor/image_decode_cache.rs +++ b/crates/viewer/re_viewer_context/src/tensor/image_decode_cache.rs @@ -46,7 +46,7 @@ impl ImageDecodeCache { let lookup = self.cache.entry(key).or_insert_with(|| { let result = decode_image(row_id, image_bytes, media_type); - let memory_used = result.as_ref().map_or(0, |image| image.blob.len() as u64); + let memory_used = result.as_ref().map_or(0, |image| image.buffer.len() as u64); self.memory_used += memory_used; DecodedImageResult { result, @@ -87,11 +87,11 @@ fn decode_image( let image_arch = Image::from_dynamic_image(dynamic_image)?; - let Image { data, format, .. } = image_arch; + let Image { buffer, format, .. } = image_arch; Ok(ImageInfo { - blob_row_id: row_id, - blob: data.0, + buffer_row_id: row_id, + buffer: buffer.0, format: format.0, kind: ImageKind::Color, colormap: None, diff --git a/crates/viewer/re_viewer_context/src/tensor/image_stats_cache.rs b/crates/viewer/re_viewer_context/src/tensor/image_stats_cache.rs index 8e6bd52b14fd..dd5a795751e7 100644 --- a/crates/viewer/re_viewer_context/src/tensor/image_stats_cache.rs +++ b/crates/viewer/re_viewer_context/src/tensor/image_stats_cache.rs @@ -9,7 +9,7 @@ pub struct ImageStatsCache(ahash::HashMap); impl ImageStatsCache { pub fn entry(&mut self, image: &ImageInfo) -> TensorStats { - let key = hash((image.blob_row_id, image.format)); + let key = hash((image.buffer_row_id, image.format)); *self .0 .entry(key) From ca319b6a8505ac4fe5427f700b3b3ff1b96b9693 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 12:08:35 -0400 Subject: [PATCH 4/6] Update python code --- rerun_py/rerun_sdk/rerun/archetypes/depth_image_ext.py | 2 +- rerun_py/rerun_sdk/rerun/archetypes/image_ext.py | 10 +++++----- .../rerun/archetypes/segmentation_image_ext.py | 2 +- rerun_py/tests/unit/test_image.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rerun_py/rerun_sdk/rerun/archetypes/depth_image_ext.py b/rerun_py/rerun_sdk/rerun/archetypes/depth_image_ext.py index 921aec95f3ce..31416fdc5f79 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/depth_image_ext.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/depth_image_ext.py @@ -66,7 +66,7 @@ def __init__( raise ValueError(f"Unsupported dtype {image.dtype} for DepthImage") self.__attrs_init__( - data=image.tobytes(), + buffer=image.tobytes(), format=ImageFormat( width=width, height=height, diff --git a/rerun_py/rerun_sdk/rerun/archetypes/image_ext.py b/rerun_py/rerun_sdk/rerun/archetypes/image_ext.py index 86710dff5156..568030a6fe9a 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/image_ext.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/image_ext.py @@ -130,7 +130,7 @@ def __init__( # TODO(jleibs): Validate that bytes is the expected size. self.__attrs_init__( - data=bytes, + buffer=bytes, format=ImageFormat(width=width, height=height, pixel_format=pixel_format), opacity=opacity, draw_order=draw_order, @@ -159,7 +159,7 @@ def __init__( # TODO(jleibs): Validate that bytes is the expected size. self.__attrs_init__( - data=bytes, + buffer=bytes, format=ImageFormat( width=width, height=height, @@ -228,7 +228,7 @@ def __init__( _send_warning_or_raise(f"Unsupported dtype {image.dtype} for Image") self.__attrs_init__( - data=image.tobytes(), + buffer=image.tobytes(), format=ImageFormat( width=width, height=height, @@ -292,9 +292,9 @@ def compress(self: Any, jpeg_quality: int = 95) -> EncodedImage | Image: ) buf = None - if self.data is not None: + if self.buffer is not None: buf = ( - self.data.as_arrow_array() + self.buffer.as_arrow_array() .storage.values.to_numpy() .view(image_format.channel_datatype.to_np_dtype()) ) diff --git a/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image_ext.py b/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image_ext.py index 1a672a46ee4f..6629879ac801 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image_ext.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/segmentation_image_ext.py @@ -65,7 +65,7 @@ def __init__( raise ValueError(f"Unsupported dtype {image.dtype} for SegmentationImage") self.__attrs_init__( - data=image.tobytes(), + buffer=image.tobytes(), format=ImageFormat( width=width, height=height, diff --git a/rerun_py/tests/unit/test_image.py b/rerun_py/tests/unit/test_image.py index 328823d03e2b..d7d5645cb3a0 100644 --- a/rerun_py/tests/unit/test_image.py +++ b/rerun_py/tests/unit/test_image.py @@ -55,7 +55,7 @@ def test_image() -> None: for input in IMAGE_INPUTS: arch = rr.Image(**input) - assert arch.data == expected.data + assert arch.buffer == expected.buffer assert arch.format == expected.format From a763292171ce17ddf80845e459fa9741958b2569 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 12:23:47 -0400 Subject: [PATCH 5/6] Switch cpp to use buffer --- rerun_cpp/src/rerun/archetypes/depth_image.hpp | 12 ++++++------ rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp | 12 ++++++------ rerun_cpp/src/rerun/archetypes/image.hpp | 2 +- rerun_cpp/src/rerun/archetypes/image_ext.cpp | 2 +- .../src/rerun/archetypes/segmentation_image.hpp | 12 ++++++------ .../src/rerun/archetypes/segmentation_image_ext.cpp | 12 ++++++------ rerun_cpp/tests/archetypes/image.cpp | 6 +++--- .../archetypes/segmentation_and_depth_image.cpp | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.hpp b/rerun_cpp/src/rerun/archetypes/depth_image.hpp index 1431c7241b7d..ddfe8bc6a9d9 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.hpp @@ -140,27 +140,27 @@ namespace rerun::archetypes { /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!). /// - /// @param data_ The raw image data. + /// @param bytes The raw image data. /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image. /// The byte size of the data is assumed to be `W * H * datatype.size` /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. - DepthImage(const void* data_, WidthHeight resolution, datatypes::ChannelDatatype datatype) - : data{Collection::borrow(data_, num_bytes(resolution, datatype))}, + DepthImage(const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype) + : buffer{Collection::borrow(bytes, num_bytes(resolution, datatype))}, format{datatypes::ImageFormat{resolution, datatype}} {} /// Constructs image from pixel data + resolution + datatype. /// - /// @param data_ The raw image data as bytes. + /// @param bytes The raw image data as bytes. /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection` /// explicitly ahead of time with `rerun::Collection::take_ownership`. /// The length of the data should be `W * H`. /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. DepthImage( - Collection data_, WidthHeight resolution, datatypes::ChannelDatatype datatype + Collection bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{data_}, format{datatypes::ImageFormat{resolution, datatype}} {} + : buffer{bytes}, format{datatypes::ImageFormat{resolution, datatype}} {} // END of extensions from depth_image_ext.cpp, start of generated code: diff --git a/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp b/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp index e980aeaaec21..0f20e71e8120 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp @@ -34,31 +34,31 @@ namespace rerun::archetypes { /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!). /// - /// @param data_ The raw image data. + /// @param bytes The raw image data. /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image. /// The byte size of the data is assumed to be `W * H * datatype.size` /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. DepthImage( - const void* data_, WidthHeight resolution, + const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{Collection::borrow(data_, num_bytes(resolution, datatype))}, + : buffer{Collection::borrow(bytes, num_bytes(resolution, datatype))}, format{datatypes::ImageFormat{resolution, datatype}} {} /// Constructs image from pixel data + resolution + datatype. /// - /// @param data_ The raw image data as bytes. + /// @param bytes The raw image data as bytes. /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection` /// explicitly ahead of time with `rerun::Collection::take_ownership`. /// The length of the data should be `W * H`. /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. DepthImage( - Collection data_, WidthHeight resolution, + Collection bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{data_}, format{datatypes::ImageFormat{resolution, datatype}} {} + : buffer{bytes}, format{datatypes::ImageFormat{resolution, datatype}} {} // diff --git a/rerun_cpp/src/rerun/archetypes/image.hpp b/rerun_cpp/src/rerun/archetypes/image.hpp index cf0464ce7b3c..d85dd629d724 100644 --- a/rerun_cpp/src/rerun/archetypes/image.hpp +++ b/rerun_cpp/src/rerun/archetypes/image.hpp @@ -102,7 +102,7 @@ namespace rerun::archetypes { /// The length of the data should be `W * H * image_format.bytes_per_pixel`. /// @param format_ How the data should be interpreted. Image(Collection bytes, components::ImageFormat format_) - : data(std::move(bytes)), format(format_) {} + : buffer(std::move(bytes)), format(format_) {} /// Construct an image from resolution, pixel format and bytes. /// diff --git a/rerun_cpp/src/rerun/archetypes/image_ext.cpp b/rerun_cpp/src/rerun/archetypes/image_ext.cpp index 36fca1aac6c9..9c057ac6fbec 100644 --- a/rerun_cpp/src/rerun/archetypes/image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/image_ext.cpp @@ -21,7 +21,7 @@ namespace rerun::archetypes { Image( Collection bytes, components::ImageFormat format_ ) - : data(std::move(bytes)), format(format_) {} + : buffer(std::move(bytes)), format(format_) {} /// Construct an image from resolution, pixel format and bytes. /// diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp index c7370128749b..68cb245deb67 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp @@ -120,29 +120,29 @@ namespace rerun::archetypes { /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!). /// - /// @param data_ The raw image data. + /// @param bytes The raw image data. /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image. /// The byte size of the data is assumed to be `W * H * datatype.size` /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. SegmentationImage( - const void* data_, WidthHeight resolution, datatypes::ChannelDatatype datatype + const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{Collection::borrow(data_, num_bytes(resolution, datatype))}, + : buffer{Collection::borrow(bytes, num_bytes(resolution, datatype))}, format{datatypes::ImageFormat{resolution, datatype}} {} /// Constructs image from pixel data + resolution + datatype. /// - /// @param data_ The raw image data as bytes. + /// @param bytes The raw image data as bytes. /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection` /// explicitly ahead of time with `rerun::Collection::take_ownership`. /// The length of the data should be `W * H`. /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. SegmentationImage( - Collection data_, WidthHeight resolution, datatypes::ChannelDatatype datatype + Collection bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{data_}, format{datatypes::ImageFormat{resolution, datatype}} {} + : buffer{bytes}, format{datatypes::ImageFormat{resolution, datatype}} {} // END of extensions from segmentation_image_ext.cpp, start of generated code: diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp b/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp index 64ee6b85b651..ec368e495c1f 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp @@ -34,31 +34,31 @@ namespace rerun::archetypes { /// Constructs image from pixel data + resolution with explicit datatype. Borrows data from a pointer (i.e. data must outlive the image!). /// - /// @param data_ The raw image data. + /// @param bytes The raw image data. /// ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image. /// The byte size of the data is assumed to be `W * H * datatype.size` /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. SegmentationImage( - const void* data_, WidthHeight resolution, + const void* bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{Collection::borrow(data_, num_bytes(resolution, datatype))}, + : buffer{Collection::borrow(bytes, num_bytes(resolution, datatype))}, format{datatypes::ImageFormat{resolution, datatype}} {} /// Constructs image from pixel data + resolution + datatype. /// - /// @param data_ The raw image data as bytes. + /// @param bytes The raw image data as bytes. /// If the data does not outlive the image, use `std::move` or create the `rerun::Collection` /// explicitly ahead of time with `rerun::Collection::take_ownership`. /// The length of the data should be `W * H`. /// @param resolution The resolution of the image as {width, height}. /// @param datatype How the data should be interpreted. SegmentationImage( - Collection data_, WidthHeight resolution, + Collection bytes, WidthHeight resolution, datatypes::ChannelDatatype datatype ) - : data{data_}, format{datatypes::ImageFormat{resolution, datatype}} {} + : buffer{bytes}, format{datatypes::ImageFormat{resolution, datatype}} {} // diff --git a/rerun_cpp/tests/archetypes/image.cpp b/rerun_cpp/tests/archetypes/image.cpp index 1edbdc7d42a5..8dad9a060a7d 100644 --- a/rerun_cpp/tests/archetypes/image.cpp +++ b/rerun_cpp/tests/archetypes/image.cpp @@ -11,7 +11,7 @@ SCENARIO("Image archetype can be created" TEST_TAG) { GIVEN("simple 8bit greyscale image") { std::vector data(10 * 10, 0); Image reference_image; - reference_image.data = rerun::borrow(data); + reference_image.buffer = rerun::borrow(data); reference_image.format = ImageFormat({10, 10}, ColorModel::L, ChannelDatatype::U8); THEN("no error occurs on image construction from a pointer") { @@ -43,7 +43,7 @@ SCENARIO("Image archetype can be created" TEST_TAG) { GIVEN("simple 8bit RGB image") { std::vector data(10 * 10 * 3, 0); Image reference_image; - reference_image.data = rerun::borrow(data); + reference_image.buffer = rerun::borrow(data); reference_image.format = ImageFormat({10, 10}, ColorModel::RGB, ChannelDatatype::U8); THEN("no error occurs on image construction from a pointer") { @@ -75,7 +75,7 @@ SCENARIO("Image archetype can be created" TEST_TAG) { GIVEN("simple 8bit RGBA image") { std::vector data(10 * 10 * 4, 0); Image reference_image; - reference_image.data = rerun::borrow(data); + reference_image.buffer = rerun::borrow(data); reference_image.format = ImageFormat({10, 10}, ColorModel::RGBA, ChannelDatatype::U8); THEN("no error occurs on image construction from a pointer") { diff --git a/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp b/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp index e4e69e2dfa4a..9236bf134988 100644 --- a/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp +++ b/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp @@ -14,7 +14,7 @@ void run_image_tests() { GIVEN("a vector of u8 data") { std::vector data(10 * 10, 0); ImageType reference_image; - reference_image.data = rerun::borrow(data); + reference_image.buffer = rerun::borrow(data); reference_image.format = ImageFormat({10, 10}, ChannelDatatype::U8); THEN("no error occurs on image construction from a pointer") { From 9bcff89cca7c7a03ca202ff066b26a2554e43ef4 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 16:02:03 -0400 Subject: [PATCH 6/6] Missed replace on docstring --- crates/viewer/re_viewer_context/src/image_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/viewer/re_viewer_context/src/image_info.rs b/crates/viewer/re_viewer_context/src/image_info.rs index 921d58cd4bc6..c3ca4f273750 100644 --- a/crates/viewer/re_viewer_context/src/image_info.rs +++ b/crates/viewer/re_viewer_context/src/image_info.rs @@ -21,7 +21,7 @@ pub struct ImageInfo { /// The image data, row-wise, with stride=width. pub buffer: Blob, - /// Describes the format of [`Self::blob`]. + /// Describes the format of [`Self::buffer`]. pub format: ImageFormat, /// Color, Depth, or Segmentation?