Rerun C++ SDK
Loading...
Searching...
No Matches
encoded_image.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/archetypes/encoded_image.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../components/blob.hpp"
10#include "../components/draw_order.hpp"
11#include "../components/media_type.hpp"
12#include "../components/opacity.hpp"
13#include "../indicator_component.hpp"
14#include "../result.hpp"
15
16#include <cstdint>
17#include <filesystem>
18#include <optional>
19#include <utility>
20#include <vector>
21
22namespace rerun::archetypes {
23 /// **Archetype**: An image encoded as e.g. a JPEG or PNG.
24 ///
25 /// Rerun also supports uncompressed images with the `archetypes::Image`.
26 /// For images that refer to video frames see `archetypes::VideoFrameReference`.
27 ///
28 /// ## Example
29 ///
30 /// ### encoded_image:
31 /// ```cpp
32 /// #include <rerun.hpp>
33 ///
34 /// #include <filesystem>
35 /// #include <fstream>
36 /// #include <iostream>
37 /// #include <vector>
38 ///
39 /// namespace fs = std::filesystem;
40 ///
41 /// int main() {
42 /// const auto rec = rerun::RecordingStream("rerun_example_encoded_image");
43 /// rec.spawn().exit_on_failure();
44 ///
45 /// fs::path image_filepath = fs::path(__FILE__).parent_path() / "ferris.png";
46 ///
47 /// rec.log("image", rerun::EncodedImage::from_file(image_filepath).value_or_throw());
48 /// }
49 /// ```
50 struct EncodedImage {
51 /// The encoded content of some image file, e.g. a PNG or JPEG.
53
54 /// The Media Type of the asset.
55 ///
56 /// Supported values:
57 /// * `image/jpeg`
58 /// * `image/png`
59 ///
60 /// If omitted, the viewer will try to guess from the data blob.
61 /// If it cannot guess, it won't be able to render the asset.
62 std::optional<rerun::components::MediaType> media_type;
63
64 /// Opacity of the image, useful for layering several images.
65 ///
66 /// Defaults to 1.0 (fully opaque).
67 std::optional<rerun::components::Opacity> opacity;
68
69 /// An optional floating point value that specifies the 2D drawing order.
70 ///
71 /// Objects with higher values are drawn on top of those with lower values.
72 std::optional<rerun::components::DrawOrder> draw_order;
73
74 public:
75 static constexpr const char IndicatorComponentName[] =
76 "rerun.components.EncodedImageIndicator";
77
78 /// Indicator component, used to identify the archetype when converting to a list of components.
80
81 public: // START of extensions from encoded_image_ext.cpp:
82 /// Create a new `EncodedImage` from the contents of a file on disk, e.g. a PNG or JPEG.
83 static Result<EncodedImage> from_file(const std::filesystem::path& filepath);
84
85 /// Create a new `EncodedImage` from the contents of an image file, like a PNG or JPEG.
86 ///
87 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
88 /// at render-time. If it can't, rendering will fail with an error.
90 rerun::Collection<uint8_t> image_contents,
91 std::optional<rerun::components::MediaType> media_type = {}
92 ) {
93 EncodedImage image;
94 image.blob = image_contents;
95 image.media_type = media_type;
96 return image;
97 }
98
99 // END of extensions from encoded_image_ext.cpp, start of generated code:
100
101 public:
102 EncodedImage() = default;
103 EncodedImage(EncodedImage&& other) = default;
104
105 /// The Media Type of the asset.
106 ///
107 /// Supported values:
108 /// * `image/jpeg`
109 /// * `image/png`
110 ///
111 /// If omitted, the viewer will try to guess from the data blob.
112 /// If it cannot guess, it won't be able to render the asset.
114 media_type = std::move(_media_type);
115 // See: https://github.com/rerun-io/rerun/issues/4027
116 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
117 }
118
119 /// Opacity of the image, useful for layering several images.
120 ///
121 /// Defaults to 1.0 (fully opaque).
123 opacity = std::move(_opacity);
124 // See: https://github.com/rerun-io/rerun/issues/4027
125 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
126 }
127
128 /// An optional floating point value that specifies the 2D drawing order.
129 ///
130 /// Objects with higher values are drawn on top of those with lower values.
132 draw_order = std::move(_draw_order);
133 // See: https://github.com/rerun-io/rerun/issues/4027
134 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
135 }
136 };
137
138} // namespace rerun::archetypes
139
140namespace rerun {
141 /// \private
142 template <typename T>
143 struct AsComponents;
144
145 /// \private
146 template <>
147 struct AsComponents<archetypes::EncodedImage> {
148 /// Serialize all set component batches.
149 static Result<std::vector<ComponentBatch>> serialize(
150 const archetypes::EncodedImage& archetype
151 );
152 };
153} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:77
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Archetype: An image encoded as e.g.
Definition encoded_image.hpp:50
static Result< EncodedImage > from_file(const std::filesystem::path &filepath)
Create a new EncodedImage from the contents of a file on disk, e.g. a PNG or JPEG.
EncodedImage with_opacity(rerun::components::Opacity _opacity) &&
Opacity of the image, useful for layering several images.
Definition encoded_image.hpp:122
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition encoded_image.hpp:62
std::optional< rerun::components::DrawOrder > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition encoded_image.hpp:72
EncodedImage with_media_type(rerun::components::MediaType _media_type) &&
The Media Type of the asset.
Definition encoded_image.hpp:113
EncodedImage with_draw_order(rerun::components::DrawOrder _draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition encoded_image.hpp:131
rerun::components::Blob blob
The encoded content of some image file, e.g. a PNG or JPEG.
Definition encoded_image.hpp:52
static EncodedImage from_bytes(rerun::Collection< uint8_t > image_contents, std::optional< rerun::components::MediaType > media_type={})
Create a new EncodedImage from the contents of an image file, like a PNG or JPEG.
Definition encoded_image.hpp:89
std::optional< rerun::components::Opacity > opacity
Opacity of the image, useful for layering several images.
Definition encoded_image.hpp:67
Component: A binary blob of data.
Definition blob.hpp:17
Component: Draw order of 2D elements.
Definition draw_order.hpp:20
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:21
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:18