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

Fill gaps in image encoding documentation, fix how python documents union variants #4988

Merged
merged 12 commits into from
Feb 1, 2024
1 change: 1 addition & 0 deletions crates/re_types/definitions/rerun/archetypes/image.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace rerun.archetypes;
/// \cpp Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
/// \cpp data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
/// \cpp If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
/// \python For an easy way to pass in image formats or encoded images, see [`rerun.ImageEncoded`][].
///
/// \example image_simple image="https://static.rerun.io/image_simple/06ba7f8582acc1ffb42a7fd0006fad7816f3e4e4/1200w.png"
table Image (
Expand Down
14 changes: 13 additions & 1 deletion crates/re_types/definitions/rerun/components/tensor_data.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ namespace rerun.components;

// ---

/// A multi-dimensional `Tensor` with optionally named arguments.
/// A multi-dimensional `Tensor` of data.
///
/// The number of dimensions and their respective lengths is specified by the `shape` field.
/// The dimensions are ordered from outermost to innermost. For example, in the common case of
/// a 2D RGB Image, the shape would be `[height, width, channel]`.
///
/// These dimensions are combined with an index to look up values from the `buffer` field,
/// which stores a contiguous array of typed values.
///
/// Note that the buffer may be encoded in a compressed format such as `jpeg` or
/// in a chroma downsampled.
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
/// For file formats, the shape is used as a hint, for chroma downsampled format
/// the shape has to be the shape of the decoded image.
table TensorData (
"attr.arrow.transparent",
"attr.rust.derive": "PartialEq",
Expand Down
34 changes: 34 additions & 0 deletions crates/re_types/definitions/rerun/datatypes/tensor_buffer.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ table F64Buffer(order: 100, transparent) {
data: [double] (order: 100);
}

/// Raw bytes of a JPEG file.
table JPEGBuffer(order: 100, transparent) {
data: [ubyte] (order: 100);
}

table NV12Buffer(order: 100, transparent) {
data: [ubyte] (order: 100);
}

table YUY2Buffer(order: 100, transparent) {
data: [ubyte] (order: 100);
}
Expand All @@ -66,18 +69,49 @@ table YUY2Buffer(order: 100, transparent) {
union TensorBuffer (
"attr.rust.derive_only": "Clone, PartialEq"
) {
/// 8bit unsigned integer.
U8: U8Buffer (transparent, order:100),

/// 16bit unsigned integer.
U16: U16Buffer (transparent, order:200),

/// 32bit unsigned integer.
U32: U32Buffer (transparent, order:300),

/// 64bit unsigned integer.
U64: U64Buffer (transparent, order:400),

/// 8bit signed integer.
I8: I8Buffer (transparent, order:500),

/// 16bit signed integer.
I16: I16Buffer (transparent, order:600),

/// 32bit signed integer.
I32: I32Buffer (transparent, order:700),

/// 64bit signed integer.
I64: I64Buffer (transparent, order:800),

/// 16bit IEEE-754 floating point, also known as `half`.
F16: F16Buffer (transparent, order:900),

/// 32bit IEEE-754 floating point, also known as `float` or `single`.
F32: F32Buffer (transparent, order:1000),

/// 64bit IEEE-754 floating point, also known as `double`.
F64: F64Buffer (transparent, order:1200),

/// Raw bytes of a JPEG file.
JPEG: JPEGBuffer (transparent, order:1300),

/// NV12 is a YUV 4:2:0 chroma downsamples format with 8 bits per channel.
///
/// First comes entire image in Y, followed by interleaved lines ordered as U0, V0, U1, V1, etc.
NV12: NV12Buffer (transparent, order:1400),

/// YUY2, also known as YUYV is a YUV 4:2:2 chrome downsampled format with 8 bits per channel.
///
/// The order of the channels is Y0, U0, Y1, V0.
YUY2: YUY2Buffer (transparent, order:1500),
}
5 changes: 5 additions & 0 deletions crates/re_types/definitions/rerun/datatypes/tensor_data.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace rerun.datatypes;
///
/// These dimensions are combined with an index to look up values from the `buffer` field,
/// which stores a contiguous array of typed values.
///
/// Note that the buffer may be encoded in a compressed format such as `jpeg` or
/// in a chroma downsampled.
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
/// For file formats, the shape is used as a hint, for chroma downsampled format
/// the shape has to be the shape of the decoded image.
table TensorData (
"attr.python.aliases": "npt.ArrayLike",
"attr.python.array_aliases": "npt.ArrayLike",
Expand Down
14 changes: 13 additions & 1 deletion crates/re_types/src/components/tensor_data.rs

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

31 changes: 31 additions & 0 deletions crates/re_types/src/datatypes/tensor_buffer.rs

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

5 changes: 5 additions & 0 deletions crates/re_types/src/datatypes/tensor_data.rs

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

38 changes: 36 additions & 2 deletions crates/re_types_builder/src/codegen/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ fn code_for_union(
1,
4,
);

code.push_text(quote_union_kind_from_fields(fields), 0, 4);
}

code.push_unindented_text(quote_union_aliases_from_object(obj, field_types.iter()), 1);
Expand Down Expand Up @@ -1021,7 +1023,7 @@ fn quote_doc_lines(lines: Vec<String>) -> String {
}

fn quote_doc_from_fields(objects: &Objects, fields: &Vec<ObjectField>) -> String {
let mut lines = vec![];
let mut lines = vec!["Must be one of:".to_owned(), String::new()];

for field in fields {
let mut content = crate::codegen::get_documentation(&field.docs, &["py", "python"]);
Expand All @@ -1037,7 +1039,7 @@ fn quote_doc_from_fields(objects: &Objects, fields: &Vec<ObjectField>) -> String
quote_examples(examples, &mut lines);
}
lines.push(format!(
"{} ({}):",
"* {} ({}):",
field.name,
quote_field_type_from_field(objects, field, false).0
));
Expand All @@ -1062,6 +1064,38 @@ fn quote_doc_from_fields(objects: &Objects, fields: &Vec<ObjectField>) -> String
format!("\"\"\"\n{doc}\n\"\"\"\n\n")
}

fn quote_union_kind_from_fields(fields: &Vec<ObjectField>) -> String {
let mut lines = vec!["Possible values:".to_owned(), String::new()];

for field in fields {
let mut content = crate::codegen::get_documentation(&field.docs, &["py", "python"]);
for line in &mut content {
if line.starts_with(char::is_whitespace) {
line.remove(0);
}
}
lines.push(format!("* {:?}:", field.name));
lines.extend(content.into_iter().map(|line| format!(" {line}")));
lines.push(String::new());
}

if lines.is_empty() {
return String::new();
} else {
// remove last empty line
lines.pop();
}

// NOTE: Filter out docstrings within docstrings, it just gets crazy otherwise…
let doc = lines
.into_iter()
.filter(|line| !line.starts_with(r#"""""#))
.collect_vec()
.join("\n");

format!("\"\"\"\n{doc}\n\"\"\"\n\n")
}

/// Automatically implement `__array__` if the object is a single
/// `npt.ArrayLike`/integer/floating-point field.
///
Expand Down
14 changes: 13 additions & 1 deletion docs/content/reference/types/components/tensor_data.md

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

5 changes: 5 additions & 0 deletions docs/content/reference/types/datatypes/tensor_data.md

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

1 change: 1 addition & 0 deletions docs/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"docstring",
"docstrings",
"dont",
"downsampled",
"downscaled",
"downscaling",
"drawables",
Expand Down
14 changes: 13 additions & 1 deletion rerun_cpp/src/rerun/components/tensor_data.hpp

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

Loading
Loading