Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Image to use ImageBuffer instead of Blob #7102

Merged
merged 6 commits into from
Aug 8, 2024
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
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
Loading