7 #ifndef IFM3D_FG_Buffer_H
8 #define IFM3D_FG_Buffer_H
12 #include <ifm3d/common/json.hpp>
13 #include <ifm3d/device/device.h>
14 #include <ifm3d/fg/buffer_id.h>
15 #include <ifm3d/fg/module_frame_grabber.h>
104 std::uint32_t _cols{};
106 std::uint32_t _rows{};
108 std::uint32_t _nchannel{};
110 ifm3d::PixelFormat _data_format{};
112 std::size_t _data_size_in_bytes{};
116 size_t _bytes_per_pixel{};
118 size_t _bytes_per_row{};
124 class BufferAllocator;
125 std::shared_ptr<BufferAllocator> _buffer_allocator;
145 Buffer(std::uint32_t cols,
147 std::uint32_t nchannel,
148 ifm3d::PixelFormat format,
149 const std::optional<ifm3d::json>& metadata = std::nullopt,
152 virtual ~
Buffer() =
default;
170 void Create(std::uint32_t cols,
172 std::uint32_t nchannel,
173 ifm3d::PixelFormat format,
178 [[nodiscard]]
Buffer Clone()
const;
181 [[nodiscard]] std::uint32_t Height()
const;
182 [[nodiscard]] std::uint32_t Width()
const;
183 [[nodiscard]] std::uint32_t NumChannels()
const;
184 [[nodiscard]] ifm3d::PixelFormat DataFormat()
const;
191 [[nodiscard]]
size_t Size()
const;
195 template <
typename T = std::u
int8_t>
196 T* Ptr(std::uint32_t row);
201 template <
typename T = std::u
int8_t>
202 T
const* Ptr(std::uint32_t row)
const;
209 template <
typename T = std::u
int8_t>
210 T* Ptr(std::uint32_t row, std::uint32_t col);
217 template <
typename T = std::u
int8_t>
218 T
const* Ptr(std::uint32_t row, std::uint32_t col)
const;
224 template <
typename T>
225 T& At(std::size_t index);
230 template <
typename T>
231 T& At(std::uint32_t row, std::uint32_t col);
237 template <
typename T>
238 T
const& At(std::size_t index)
const;
243 template <
typename T>
244 T
const& At(std::uint32_t row, std::uint32_t col)
const;
252 template <
typename T>
258 template <
typename T>
261 using iterator_category = std::random_access_iterator_tag;
262 using difference_type = std::ptrdiff_t;
263 using value_type = T;
265 using reference = T&;
268 reference operator*()
const;
269 pointer operator->();
276 return a._ptr == b._ptr;
282 return a._ptr != b._ptr;
286 operator-(
const Iterator& rhs)
const noexcept
289 return this->_ptr - rhs._ptr;
298 template <
typename T>
301 template <
typename T>
315 template <
typename T>
329 template <
typename TP>
341 std::optional<ifm3d::json> metadata = std::nullopt);
358 void Create(std::uint32_t cols,
367 [[nodiscard]] std::uint32_t Height()
const;
368 [[nodiscard]] std::uint32_t Width()
const;
369 [[nodiscard]] std::uint32_t Nchannels()
const;
370 [[nodiscard]] ifm3d::PixelFormat DataFormat()
const;
376 TP*
Ptr(std::uint32_t row);
383 TP*
Ptr(std::uint32_t row, std::uint32_t col);
389 TP& At(std::size_t index);
394 TP& At(std::uint32_t row, std::uint32_t col);
413 template <
typename T,
int N>
416 std::array<T, N> val;
420 template <
typename T>
423 template <
typename T>
430 static_assert(CHAR_BIT *
sizeof(
float) == 32,
"32 bit float required");
439 #include <ifm3d/fg/detail/buffer.hpp>
440 #endif // IFM3D_FG_Buffer_H