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/build/re_type_definitions/rerun/datatypes/image_format.def.rs".
3
4#pragma once
5
6#include "../compiler_utils.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 // GCC 14.4 incorrectly reports disengaged std::optional payloads as maybe-uninitialized.
66 RR_DISABLE_MAYBE_UNINITIALIZED_PUSH
67
68 /// How many bytes will this image occupy?
69 size_t num_bytes() const {
70 if (pixel_format) {
71 return pixel_format_num_bytes({width, height}, *pixel_format);
72 } else {
73 auto cm = color_model.value_or(datatypes::ColorModel::L);
75 auto bits_per_pixel = color_model_channel_count(cm) * datatype_bits(dt);
76 // Widen first: `uint32_t` overflows here, and the result is a buffer length.
77 const auto num_pixels = static_cast<size_t>(width) * static_cast<size_t>(height);
78 return (num_pixels * bits_per_pixel + 7) / 8; // Rounding up
79 }
80 }
81
82 RR_DISABLE_MAYBE_UNINITIALIZED_POP
83
84 // END of extensions from image_format_ext.cpp, start of generated code:
85
86 public:
87 ImageFormat() = default;
88 };
89} // namespace rerun::datatypes
90
91namespace rerun {
92 template <typename T>
93 struct Loggable;
94
95 /// \private
96 template <>
97 struct Loggable<datatypes::ImageFormat> {
98 static constexpr std::string_view ComponentType = "rerun.datatypes.ImageFormat";
99
100 /// Returns the arrow data type this type corresponds to.
101 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
102
103 /// Serializes an array of `rerun::datatypes::ImageFormat` into an arrow array.
104 static Result<std::shared_ptr<arrow::Array>> to_arrow(
105 const datatypes::ImageFormat* instances, size_t num_instances
106 );
107
108 /// Fills an arrow array builder with an array of this type.
109 static rerun::Error fill_arrow_array_builder(
110 arrow::StructBuilder* builder, const datatypes::ImageFormat* elements,
111 size_t num_elements
112 );
113 };
114} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:103
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:93
PixelFormat
Datatype: Specifieds a particular format of an archetypes::Image.
Definition pixel_format.hpp:34
ColorModel
Datatype: Specified what color components are present in an archetypes::Image.
Definition color_model.hpp:26
@ L
Grayscale luminance intencity/brightness/value, sometimes called Y
ChannelDatatype
Datatype: The innermost datatype of an image.
Definition channel_datatype.hpp:26
@ 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:142
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
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
RR_DISABLE_MAYBE_UNINITIALIZED_PUSH size_t num_bytes() const
How many bytes will this image occupy?
Definition image_format.hpp:69