Rerun C++ SDK
Loading...
Searching...
No Matches
image_format.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_types/definitions/rerun/datatypes/image_format.fbs".
3
4#pragma once
5
6#include "../component_descriptor.hpp"
7#include "../image_utils.hpp"
8#include "../result.hpp"
9#include "channel_datatype.hpp"
10#include "color_model.hpp"
11#include "pixel_format.hpp"
12
13#include <cstdint>
14#include <memory>
15#include <optional>
16
17namespace arrow {
18 class Array;
19 class DataType;
20 class StructBuilder;
21} // namespace arrow
22
23namespace rerun::datatypes {
24 /// **Datatype**: The metadata describing the contents of a `components::ImageBuffer`.
25 struct ImageFormat {
26 /// The width of the image in pixels.
27 uint32_t width;
28
29 /// The height of the image in pixels.
30 uint32_t height;
31
32 /// Used mainly for chroma downsampled formats and differing number of bits per channel.
33 ///
34 /// If specified, this takes precedence over both `datatypes::ColorModel` and `datatypes::ChannelDatatype` (which are ignored).
35 std::optional<rerun::datatypes::PixelFormat> pixel_format;
36
37 /// L, RGB, RGBA, …
38 ///
39 /// Also requires a `datatypes::ChannelDatatype` to fully specify the pixel format.
40 std::optional<rerun::datatypes::ColorModel> color_model;
41
42 /// The data type of each channel (e.g. the red channel) of the image data (U8, F16, …).
43 ///
44 /// Also requires a `datatypes::ColorModel` to fully specify the pixel format.
45 std::optional<rerun::datatypes::ChannelDatatype> channel_datatype;
46
47 public: // START of extensions from image_format_ext.cpp:
48 /// From a specific pixel format.
50 : width(resolution.width), height(resolution.height), pixel_format(pixel_format_) {}
51
52 /// Create a new image format for depth or segmentation images with the given resolution and datatype.
54 : width(resolution.width), height(resolution.height), channel_datatype(datatype_) {}
55
57 rerun::WidthHeight resolution, datatypes::ColorModel color_model_,
59 )
60 : width(resolution.width),
61 height(resolution.height),
62 color_model(color_model_),
63 channel_datatype(datatype_) {}
64
65 /// How many bytes will this image occupy?
66 size_t num_bytes() const {
67 if (pixel_format) {
68 return pixel_format_num_bytes({width, height}, *pixel_format);
69 } else {
70 auto cm = color_model.value_or(datatypes::ColorModel::L);
72 auto bits_per_pixel = color_model_channel_count(cm) * datatype_bits(dt);
73 return (width * height * bits_per_pixel + 7) / 8; // Rounding up
74 }
75 }
76
77 // END of extensions from image_format_ext.cpp, start of generated code:
78
79 public:
80 ImageFormat() = default;
81 };
82} // namespace rerun::datatypes
83
84namespace rerun {
85 template <typename T>
86 struct Loggable;
87
88 /// \private
89 template <>
90 struct Loggable<datatypes::ImageFormat> {
91 static constexpr ComponentDescriptor Descriptor = "rerun.datatypes.ImageFormat";
92
93 /// Returns the arrow data type this type corresponds to.
94 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
95
96 /// Serializes an array of `rerun::datatypes::ImageFormat` into an arrow array.
97 static Result<std::shared_ptr<arrow::Array>> to_arrow(
98 const datatypes::ImageFormat* instances, size_t num_instances
99 );
100
101 /// Fills an arrow array builder with an array of this type.
102 static rerun::Error fill_arrow_array_builder(
103 arrow::StructBuilder* builder, const datatypes::ImageFormat* elements,
104 size_t num_elements
105 );
106 };
107} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:99
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:82
PixelFormat
Datatype: Specifieds a particular format of an archetypes::Image.
Definition pixel_format.hpp:35
ColorModel
Datatype: Specified what color components are present in an archetypes::Image.
Definition color_model.hpp:27
@ L
Grayscale luminance intencity/brightness/value, sometimes called Y
ChannelDatatype
Datatype: The innermost datatype of an image.
Definition channel_datatype.hpp:27
@ U8
8-bit unsigned integer.
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
size_t datatype_bits(datatypes::ChannelDatatype value)
Number of bits used by this element type.
Definition image_utils.hpp:21
size_t color_model_channel_count(datatypes::ColorModel color_model)
Returns the number of channels for a given color model.
Definition image_utils.hpp:139
The width and height of an image.
Definition image_utils.hpp:13
Datatype: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:25
size_t num_bytes() const
How many bytes will this image occupy?
Definition image_format.hpp:66
uint32_t height
The height of the image in pixels.
Definition image_format.hpp:30
ImageFormat(rerun::WidthHeight resolution, datatypes::ChannelDatatype datatype_)
Create a new image format for depth or segmentation images with the given resolution and datatype.
Definition image_format.hpp:53
ImageFormat(rerun::WidthHeight resolution, datatypes::PixelFormat pixel_format_)
From a specific pixel format.
Definition image_format.hpp:49
std::optional< rerun::datatypes::PixelFormat > pixel_format
Used mainly for chroma downsampled formats and differing number of bits per channel.
Definition image_format.hpp:35
std::optional< rerun::datatypes::ChannelDatatype > channel_datatype
The data type of each channel (e.g.
Definition image_format.hpp:45
std::optional< rerun::datatypes::ColorModel > color_model
L, RGB, RGBA, …
Definition image_format.hpp:40
uint32_t width
The width of the image in pixels.
Definition image_format.hpp:27