4 #include <bnb/types/config.hpp>
7 #include <bnb/types/base_types.hpp>
8 #include <bnb/types/transformation.hpp>
9 #include <bnb/utils/assert.hpp>
10 #include <bnb/utils/event.hpp>
11 #include <bnb/utils/defs.hpp>
13 #include <type_traits>
42 return static_cast<bool>(
static_cast<int32_t
>(format) & 0x0100);
47 return static_cast<bool>(
static_cast<int32_t
>(format) & 0x0200);
52 return static_cast<bool>(
static_cast<int32_t
>(format) & 0x0400);
57 return static_cast<bool>(
static_cast<int32_t
>(format) & 0x0600);
63 case pixel_buffer_format::bpc8_rgb:
65 case pixel_buffer_format::bpc8_bgr:
67 case pixel_buffer_format::bpc8_rgba:
69 case pixel_buffer_format::bpc8_bgra:
71 case pixel_buffer_format::bpc8_argb:
73 case pixel_buffer_format::nv12:
75 case pixel_buffer_format::i420:
78 BNB_THROW(std::invalid_argument,
"Unknown format.");
92 std::optional<float> fov = std::nullopt;
98 bool require_mirroring =
false;
100 int face_orientation = 0;
105 uint32_t
size() const noexcept;
169 using pixel_format_t = bnb::interfaces::pixel_format;
204 pixel_format_t get_pixel_format()
const noexcept;
209 uint8_t* get_data()
const noexcept;
214 static uint8_t bytes_per_pixel(pixel_format_t fmt);
218 static std::tuple<int, int, int> rgb_offsets(pixel_format_t fmt);
223 std::tuple<uint8_t, uint8_t, uint8_t> rgb_pixel_at(uint32_t x, uint32_t y)
const noexcept;
231 pixel_format_t m_pixel_format;
242 using lock_data_cb = std::function<color_plane()>;
263 bnb::interfaces::pixel_format m_pixel_format;
264 lock_data_cb m_lock_data;
318 template<
size_t index>
329 switch (m_yuv_format.format) {
330 case yuv_format::yuv_nv12: {
331 BNB_THROW(std::invalid_argument,
"yuv nv12 format has only 2 planes");
333 case yuv_format::yuv_i420: {
337 BNB_THROW(std::invalid_argument,
"Incorrect yuv format");
342 BNB_THROW(std::invalid_argument,
"Incorrect index of plane");
359 m_planes[0] = std::move(y_plane);
360 m_planes[1] = std::move(uv_plane);
376 m_planes[0] = std::move(y_plane);
377 m_planes[1] = std::move(u_plane);
378 m_planes[2] = std::move(v_plane);
392 m_yuv_format.format = yuv_format::yuv_nv12;
393 m_yuv_format.standard = color_std::bt601;
395 m_planes[0] = std::move(y_plane);
396 m_planes[1] = std::move(uv_plane);
402 size_t y_size() const noexcept;
406 size_t uv_size() const noexcept;
408 using conversion_matrix = std::array<
float, 16>;
411 virtual conversion_matrix get_yuv_to_rgb_matrix() const;
412 virtual conversion_matrix get_rgb_to_yuv_matrix() const;
417 uint8_t y_pixel_at(uint32_t xi, uint32_t yi) const noexcept;
421 uint8_t uv_pixel_at(uint32_t xi, uint32_t yi, uint32_t offset) const noexcept;
426 uint8_t u_pixel_at(uint32_t xi, uint32_t yi) const noexcept;
430 uint8_t v_pixel_at(uint32_t xi, uint32_t yi) const noexcept;
474 color_plane m_planes[3];
490 static full_image_t load(
const std::string& path,
bool alpha =
false);
543 bool is_landscape()
const;
556 return bnb::transformation(full_roi, full_roi, rot_t::deg_0, get_format().require_mirroring) >> basis_transform;
563 const T& get_data() const noexcept;
569 bool has_data() const noexcept;
576 void set_fov(
float fov);
581 void normalize_orientation();
583 unsigned camera_tex_id = 0;
584 #if BNB_OS_ANDROID || BNB_OS_EMSCRIPTEN
585 unsigned ext_camera_tex_id = 0;
586 unsigned ext_camera_tex_width = 0;
587 unsigned ext_camera_tex_height = 0;
591 using plane_deleter = std::function<void(uint8_t*)>;
594 const uint8_t* rgb_plane,
601 plane_deleter deleter
605 const uint8_t* y_plane,
607 const uint8_t* uv_plane,
615 plane_deleter y_deleter,
616 plane_deleter uv_deleter
620 const uint8_t* y_plane,
622 const uint8_t* u_plane,
624 const uint8_t* v_plane,
632 plane_deleter y_deleter,
633 plane_deleter u_deleter,
634 plane_deleter v_deleter
647 bool get_mirroring()
const;
670 uint32_t get_number_of_planes()
const;
675 uint8_t* get_base_ptr()
const;
681 uint8_t* get_base_ptr_of_plane(uint32_t plane_num)
const;
686 int32_t get_bytes_per_pixel()
const;
692 int32_t get_bytes_per_pixel_of_plane(uint32_t plane_num)
const;
697 int32_t get_bytes_per_row()
const;
703 int32_t get_bytes_per_row_of_plane(uint32_t plane_num)
const;
708 int32_t get_width()
const;
714 int32_t get_width_of_plane(uint32_t plane_num)
const;
719 int32_t get_height()
const;
725 int32_t get_height_of_plane(uint32_t plane_num)
const;
728 void lock_gpu_data();
732 void init_planes_data();
733 void init_plane(uint32_t plane_num, uint8_t* data, int32_t stride, int32_t width, int32_t height, int32_t pixel_size);
734 void validate_plane_number(uint32_t plane_num)
const;
740 int32_t bytes_per_row{0};
743 int32_t pixel_size{0};
746 using image_t = std::variant<
755 plane_data m_planes_info[3];
756 uint32_t m_plane_count{0};
760 const T& _get_data() const noexcept;
763 bool _has_data() const noexcept;
765 void update_basis_transform();
771 static_assert(std::is_base_of<base_image_t, T>::value,
"Type is not image_t");
772 BNB_ASSERT(std::holds_alternative<T>(m_image));
773 return *std::get_if<T>(&m_image);
779 static_assert(std::is_base_of<base_image_t, T>::value,
"Type is not image_t");
780 return std::holds_alternative<T>(m_image);