Rerun C++ SDK
Loading...
Searching...
No Matches
image_utils.hpp
1#pragma once
2
3#include "datatypes/channel_datatype.hpp"
4#include "datatypes/color_model.hpp"
5#include "datatypes/pixel_format.hpp"
6#include "half.hpp"
7
8#include <cstdint>
9
10namespace rerun {
11 /// The width and height of an image.
12 struct WidthHeight {
13 uint32_t width;
14 uint32_t height;
15
16 WidthHeight(uint32_t width_, uint32_t height_) : width{width_}, height{height_} {}
17 };
18
19 /// Number of bits used by this element type
21 switch (value) {
23 return 8;
24 }
26 return 16;
27 }
29 return 32;
30 }
32 return 64;
33 }
35 return 8;
36 }
38 return 16;
39 }
41 return 32;
42 }
44 return 64;
45 }
47 return 16;
48 }
50 return 32;
51 }
53 return 64;
54 }
55 }
56 return 0;
57 }
58
59 inline size_t num_bytes(WidthHeight resolution, datatypes::ChannelDatatype datatype) {
60 // rounding upwards:
61 return (resolution.width * resolution.height * datatype_bits(datatype) + 7) / 8;
62 }
63
64 template <typename TElement>
65 inline datatypes::ChannelDatatype get_datatype(const TElement* _unused);
66
67 template <>
68 inline datatypes::ChannelDatatype get_datatype(const uint8_t* _unused) {
69 (void)(_unused); // Suppress unused warning.
71 }
72
73 template <>
74 inline datatypes::ChannelDatatype get_datatype(const uint16_t* _unused) {
75 (void)(_unused); // Suppress unused warning.
77 }
78
79 template <>
80 inline datatypes::ChannelDatatype get_datatype(const uint32_t* _unused) {
81 (void)(_unused); // Suppress unused warning.
83 }
84
85 template <>
86 inline datatypes::ChannelDatatype get_datatype(const uint64_t* _unused) {
87 (void)(_unused); // Suppress unused warning.
89 }
90
91 template <>
92 inline datatypes::ChannelDatatype get_datatype(const int8_t* _unused) {
93 (void)(_unused); // Suppress unused warning.
95 }
96
97 template <>
98 inline datatypes::ChannelDatatype get_datatype(const int16_t* _unused) {
99 (void)(_unused); // Suppress unused warning.
101 }
102
103 template <>
104 inline datatypes::ChannelDatatype get_datatype(const int32_t* _unused) {
105 (void)(_unused); // Suppress unused warning.
107 }
108
109 template <>
110 inline datatypes::ChannelDatatype get_datatype(const int64_t* _unused) {
111 (void)(_unused); // Suppress unused warning.
113 }
114
115 template <>
116 inline datatypes::ChannelDatatype get_datatype(const rerun::half* _unused) {
117 (void)(_unused); // Suppress unused warning.
119 }
120
121 template <>
122 inline datatypes::ChannelDatatype get_datatype(const float* _unused) {
123 (void)(_unused); // Suppress unused warning.
125 }
126
127 template <>
128 inline datatypes::ChannelDatatype get_datatype(const double* _unused) {
129 (void)(_unused); // Suppress unused warning.
131 }
132
133 /// Returns the number of channels for a given color model.
134 ///
135 /// This is the number of expected elements per pixel.
137 switch (color_model) {
139 return 1;
141 return 3;
143 return 4;
144 }
145 return 0;
146 }
147
148 inline size_t pixel_format_num_bytes(
149 WidthHeight resolution, datatypes::PixelFormat pixel_format
150 ) {
151 auto num_pixels = resolution.width * resolution.height;
152 switch (pixel_format) {
154 return 12 * num_pixels / 8;
156 return 16 * num_pixels / 8;
157 }
158 return 0;
159 }
160} // namespace rerun
PixelFormat
Datatype: Specifieds a particular format of an archetypes::Image.
Definition pixel_format.hpp:34
@ NV12
NV12 (aka Y_UV12) is a YUV 4:2:0 chroma downsampled format with 12 bits per pixel and 8 bits per chan...
@ YUY2
YUY2 (aka YUYV or YUYV16), is a YUV 4:2:2 chroma downsampled format with 16 bits per pixel and 8 bits...
ColorModel
Datatype: Specified what color components are present in an archetypes::Image.
Definition color_model.hpp:26
@ RGB
Red, Green, Blue.
@ L
Grayscale luminance intencity/brightness/value, sometimes called Y
@ RGBA
Red, Green, Blue, Alpha.
ChannelDatatype
Datatype: The innermost datatype of an image.
Definition channel_datatype.hpp:26
@ F64
64-bit IEEE-754 floating point, also known as double.
@ U64
64-bit unsigned integer.
@ F32
32-bit IEEE-754 floating point, also known as float or single.
@ F16
16-bit IEEE-754 floating point, also known as half.
@ I8
8-bit signed integer.
@ U8
8-bit unsigned integer.
@ I16
16-bit signed integer.
@ U32
32-bit unsigned integer.
@ I32
32-bit signed integer.
@ I64
64-bit signed integer.
@ U16
16-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
IEEE 754 16-bit half-precision floating point number.
Definition half.hpp:7