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