Skip to content

Commit

Permalink
Change Image to use ImageBuffer instead of Blob (#7102)
Browse files Browse the repository at this point in the history
### What
Using a dedicated ImageBuffer component means when we encounter
ImageBuffer we know to look for an ImageFormat. This simplifies some of
the future things related to data previews or eventually component-wise
data-dependencies.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7102?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7102?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/7102)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
jleibs authored Aug 8, 2024
1 parent 47d5331 commit 0a13238
Show file tree
Hide file tree
Showing 57 changed files with 467 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions crates/store/re_types/definitions/rerun/components.fbs

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

Original file line number Diff line number Diff line change
@@ -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);
}
30 changes: 15 additions & 15 deletions crates/store/re_types/src/archetypes/depth_image.rs

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

2 changes: 1 addition & 1 deletion crates/store/re_types/src/archetypes/depth_image_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 15 additions & 15 deletions crates/store/re_types/src/archetypes/image.rs

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

30 changes: 15 additions & 15 deletions crates/store/re_types/src/archetypes/image_ext.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Image {
};

Ok(Self {
data: blob.into(),
buffer: blob.into(),
format: image_format.into(),
opacity: None,
draw_order: None,
Expand All @@ -79,14 +79,14 @@ impl Image {
pub fn from_pixel_format(
[width, height]: [u32; 2],
pixel_format: PixelFormat,
bytes: impl Into<Blob>,
bytes: impl Into<ImageBuffer>,
) -> 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",
);
Expand All @@ -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,
Expand All @@ -106,18 +106,18 @@ impl Image {
///
/// See also [`Self::from_color_model_and_tensor`].
pub fn from_color_model_and_bytes(
bytes: impl Into<Blob>,
bytes: impl Into<ImageBuffer>,
[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",
);
Expand All @@ -132,7 +132,7 @@ impl Image {
};

Self {
data,
buffer,
format: image_format.into(),
opacity: None,
draw_order: None,
Expand All @@ -157,17 +157,17 @@ impl Image {
}

/// From an 8-bit grayscale image.
pub fn from_l8(bytes: impl Into<Blob>, resolution: [u32; 2]) -> Self {
pub fn from_l8(bytes: impl Into<ImageBuffer>, 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<Blob>, resolution: [u32; 2]) -> Self {
pub fn from_rgb24(bytes: impl Into<ImageBuffer>, 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<Blob>, resolution: [u32; 2]) -> Self {
pub fn from_rgba32(bytes: impl Into<ImageBuffer>, resolution: [u32; 2]) -> Self {
Self::from_color_model_and_bytes(bytes, resolution, ColorModel::RGBA, ChannelDatatype::U8)
}

Expand Down
Loading

0 comments on commit 0a13238

Please sign in to comment.