Skip to content

Commit

Permalink
Fix lacking ndarray conversion, fix compile warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Oct 16, 2023
1 parent e542a4e commit 18bf6c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ fn tensor_pixel_value_ui(
if let Some([r, g, b]) = match &tensor.buffer {
TensorBuffer::Nv12(_) => tensor.get_nv12_pixel(x, y),
_ => {
if let (Some(r), Some(g), Some(b)) = (
if let [Some(r), Some(g), Some(b)] = [
tensor.get_with_image_coords(x, y, 0),
tensor.get_with_image_coords(x, y, 1),
tensor.get_with_image_coords(x, y, 2),
) {
] {
Some([r, g, b])
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum TextureFilterMin {
}

/// Describes how the color information is encoded in the texture.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ShaderDecoding {
Nv12,
}
Expand Down
24 changes: 17 additions & 7 deletions crates/re_types/src/datatypes/tensor_data_ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
archetypes::Tensor,
tensor_data::{TensorCastError, TensorDataType, TensorElement},
};
use crate::tensor_data::{TensorCastError, TensorDataType, TensorElement};

#[cfg(feature = "image")]
use crate::tensor_data::{DecodedTensor, TensorImageLoadError, TensorImageSaveError};
Expand Down Expand Up @@ -210,7 +207,7 @@ impl TensorData {
};
match self.image_height_width_channels() {
Some([h, w, _]) => {
let uv_offset = (w * h) as u64;
let uv_offset = w * h;
let luma = ((buf[(y * w + x) as usize] as f64) - 16.0) / 216.0;
let u = ((buf[(uv_offset + (y / 2) * w + x) as usize] as f64) - 128.0) / 224.0;
let v =
Expand Down Expand Up @@ -242,7 +239,7 @@ impl TensorData {

// ----------------------------------------------------------------------------

macro_rules! tensor_type {
macro_rules! ndarray_from_tensor {
($type:ty, $variant:ident) => {
impl<'a> TryFrom<&'a TensorData> for ::ndarray::ArrayViewD<'a, $type> {
type Error = TensorCastError;
Expand All @@ -258,7 +255,11 @@ macro_rules! tensor_type {
}
}
}
};
}

macro_rules! tensor_from_ndarray {
($type:ty, $variant:ident) => {
impl<'a, D: ::ndarray::Dimension> TryFrom<::ndarray::ArrayView<'a, $type, D>>
for TensorData
{
Expand Down Expand Up @@ -323,6 +324,13 @@ macro_rules! tensor_type {
};
}

macro_rules! tensor_type {
($type:ty, $variant:ident) => {
ndarray_from_tensor!($type, $variant);
tensor_from_ndarray!($type, $variant);
};
}

tensor_type!(u16, U16);
tensor_type!(u32, U32);
tensor_type!(u64, U64);
Expand All @@ -337,7 +345,9 @@ tensor_type!(arrow2::types::f16, F16);
tensor_type!(f32, F32);
tensor_type!(f64, F64);

// Manual expension of tensor_type! macro for `u8` types. We need to do this, because u8 can store encoded data
tensor_from_ndarray!(u8, U8);

// Manual expansion of ndarray_from_tensor! macro for `u8` types. We need to do this, because u8 can store encoded data
impl<'a> TryFrom<&'a TensorData> for ::ndarray::ArrayViewD<'a, u8> {
type Error = TensorCastError;

Expand Down

0 comments on commit 18bf6c3

Please sign in to comment.