6 #ifndef IFM3D_FG_ORGANIZER_UTILS_H
7 #define IFM3D_FG_ORGANIZER_UTILS_H
15 #include <ifm3d/device/device.h>
16 #include <ifm3d/fg/buffer.h>
17 #include <ifm3d/fg/frame.h>
18 #include <ifm3d/fg/distance_image_info.h>
22 constexpr std::size_t IMG_BUFF_START = 8;
24 std::map<image_chunk, std::set<std::size_t>> get_image_chunks(
25 const std::vector<std::uint8_t>& data,
26 std::size_t start_idx,
27 std::optional<size_t> end_idx = std::nullopt);
29 std::size_t get_format_size(pixel_format fmt);
30 std::size_t get_format_channels(pixel_format fmt);
32 Buffer create_1d_buffer(
const std::vector<std::uint8_t>& data,
35 Buffer create_buffer(
const std::vector<std::uint8_t>& data,
40 Buffer create_buffer(
const std::vector<std::uint8_t>& data,
45 std::optional<json> metadata = std::nullopt);
47 Buffer create_xyz_buffer(
const std::vector<std::uint8_t>& data,
54 const std::optional<Buffer>& mask);
56 auto find_metadata_chunk(
57 const std::map<image_chunk, std::set<std::size_t>>& chunks)
58 -> decltype(chunks.end());
60 std::tuple<uint32_t, uint32_t> get_image_size(
61 const std::vector<std::uint8_t>& data,
64 pixel_format get_chunk_format(
const std::vector<std::uint8_t>& data,
67 uint32_t get_chunk_frame_count(
const std::vector<std::uint8_t>& data,
70 std::vector<TimePointT> get_chunk_timestamps(
71 const std::vector<uint8_t>& data,
74 std::size_t get_chunk_pixeldata_offset(
const std::vector<std::uint8_t>& data,
77 std::size_t get_chunk_size(
const std::vector<std::uint8_t>& data,
80 std::size_t get_chunk_pixeldata_size(
const std::vector<std::uint8_t>& data,
83 std::size_t get_chunk_header_version(
const std::vector<std::uint8_t>& data,
86 void mask_buffer(Buffer& image,
const Buffer& mask);
88 bool is_probably_blob(
const std::vector<std::uint8_t>& data,
93 Buffer create_pixel_mask(Buffer& confidence);
96 const std::vector<uint8_t>& data,
97 const std::set<buffer_id>& requestedImages,
98 const std::map<ifm3d::image_chunk, std::set<std::size_t>>& chunks,
101 std::map<buffer_id, BufferList>& data_blob,
102 std::map<buffer_id, BufferList>& data_image);
104 void mask_images(std::map<ifm3d::buffer_id, ifm3d::BufferList>& images,
108 bool has_metadata(
const std::vector<std::uint8_t>& data, std::size_t idx);
110 ifm3d::json create_metadata(
const std::vector<std::uint8_t>& data,
125 template <
typename T>
127 mkval(
const unsigned char* buff)
132 unsigned char bytes[
sizeof(T)];
135 #if !defined(_WIN32) && __BYTE_ORDER == __BIG_ENDIAN
136 std::reverse_copy(buff, buff +
sizeof(T), value.bytes);
138 std::copy(buff, buff +
sizeof(T), value.bytes);
146 template <
typename T>
148 create_buffer_from_vector(
const std::vector<T>& vec)
153 ifm3d::FormatType<T>::nchannel,
154 static_cast<ifm3d::pixel_format
>(ifm3d::FormatType<T>::format));
155 std::copy(vec.begin(), vec.end(), buf.begin<T>());
161 template <
typename T>
163 create_buffer_from_struct(
const T& struct_object)
166 Buffer(
sizeof(T), 1, 1, ifm3d::pixel_format::FORMAT_8U);
167 const uint8_t* start =
reinterpret_cast<const uint8_t*
>(&struct_object);
168 auto ptr = buf.
ptr<uint8_t>(0);
169 std::copy(start, start +
sizeof(T), ptr);
175 template <
typename T>
180 auto ptr = buf.
ptr<uint8_t>(0);
183 reinterpret_cast<uint8_t*
>(&struct_object));
184 return struct_object;
189 #endif // IFM3D_FG_ORGANIZER_UTILS_H