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 "../image_utils.hpp"
7#include "../result.hpp"
8#include "channel_datatype.hpp"
9#include "color_model.hpp"
10#include "pixel_format.hpp"
11
12#include <cstdint>
13#include <memory>
14#include <optional>
15
16namespace arrow {
17 class Array;
18 class DataType;
19 class StructBuilder;
20} // namespace arrow
21
22namespace rerun::datatypes {
23 /// **Datatype**: The metadata describing the contents of a `components::ImageBuffer`.
24 struct ImageFormat {
25 /// The width of the image in pixels.
26 uint32_t width;
27
28 /// The height of the image in pixels.
29 uint32_t height;
30
31 /// Used mainly for chroma downsampled formats and differing number of bits per channel.
32 ///
33 /// If specified, this takes precedence over both `datatypes::ColorModel` and `datatypes::ChannelDatatype` (which are ignored).
34 std::optional<rerun::datatypes::PixelFormat> pixel_format;
35
36 /// L, RGB, RGBA, …
37 ///
38 /// Also requires a `datatypes::ChannelDatatype` to fully specify the pixel format.
39 std::optional<rerun::datatypes::ColorModel> color_model;
40
41 /// The data type of each channel (e.g. the red channel) of the image data (U8, F16, …).
42 ///
43 /// Also requires a `datatypes::ColorModel` to fully specify the pixel format.
44 std::optional<rerun::datatypes::ChannelDatatype> channel_datatype;
45
46 public: // START of extensions from image_format_ext.cpp:
47 /// From a specific pixel format.
49 : width(resolution.width), height(resolution.height), pixel_format(pixel_format_) {}
50
51 /// Create a new image format for depth or segmentation images with the given resolution and datatype.
53 : width(resolution.width), height(resolution.height), channel_datatype(datatype_) {}
54
56 rerun::WidthHeight resolution, datatypes::ColorModel color_model_,
58 )
59 : width(resolution.width),
60 height(resolution.height),
61 color_model(color_model_),
62 channel_datatype(datatype_) {}
63
64 /// How many bytes will this image occupy?
65 size_t num_bytes() const {
66 if (pixel_format) {
67 return pixel_format_num_bytes({width, height}, *pixel_format);
68 } else {
69 auto cm = color_model.value_or(datatypes::ColorModel::L);
71 auto bits_per_pixel = color_model_channel_count(cm) * datatype_bits(dt);
72 return (width * height * bits_per_pixel + 7) / 8; // Rounding up
73 }
74 }
75
76 // END of extensions from image_format_ext.cpp, start of generated code:
77
78 public:
79 ImageFormat() = default;
80 };
81} // namespace rerun::datatypes
82
83namespace rerun {
84 template <typename T>
85 struct Loggable;
86
87 /// \private
88 template <>
89 struct Loggable<datatypes::ImageFormat> {
90 static constexpr const char Name[] = "rerun.datatypes.ImageFormat";
91
92 /// Returns the arrow data type this type corresponds to.
93 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
94
95 /// Serializes an array of `rerun::datatypes::ImageFormat` into an arrow array.
96 static Result<std::shared_ptr<arrow::Array>> to_arrow(
97 const datatypes::ImageFormat* instances, size_t num_instances
98 );
99
100 /// Fills an arrow array builder with an array of this type.
101 static rerun::Error fill_arrow_array_builder(
102 arrow::StructBuilder* builder, const datatypes::ImageFormat* elements,
103 size_t num_elements
104 );
105 };
106} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:91
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:78
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:22
size_t datatype_bits(datatypes::ChannelDatatype value)
Number of bits used by this element type.
Definition image_utils.hpp:20
size_t color_model_channel_count(datatypes::ColorModel color_model)
Returns the number of channels for a given color model.
Definition image_utils.hpp:136
The width and height of an image.
Definition image_utils.hpp:12
Datatype: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:24
size_t num_bytes() const
How many bytes will this image occupy?
Definition image_format.hpp:65
uint32_t height
The height of the image in pixels.
Definition image_format.hpp:29
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:52
ImageFormat(rerun::WidthHeight resolution, datatypes::PixelFormat pixel_format_)
From a specific pixel format.
Definition image_format.hpp:48
std::optional< rerun::datatypes::PixelFormat > pixel_format
Used mainly for chroma downsampled formats and differing number of bits per channel.
Definition image_format.hpp:34
std::optional< rerun::datatypes::ChannelDatatype > channel_datatype
The data type of each channel (e.g.
Definition image_format.hpp:44
std::optional< rerun::datatypes::ColorModel > color_model
L, RGB, RGBA, …
Definition image_format.hpp:39
uint32_t width
The width of the image in pixels.
Definition image_format.hpp:26