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>
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;
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;
286 template<
size_t index>
297 switch (m_yuv_format.format) {
298 case yuv_format::yuv_nv12: {
299 BNB_THROW(std::invalid_argument,
"yuv nv12 format has only 2 planes");
301 case yuv_format::yuv_i420: {
305 BNB_THROW(std::invalid_argument,
"Incorrect yuv format");
310 BNB_THROW(std::invalid_argument,
"Incorrect index of plane");
327 m_planes[0] = std::move(y_plane);
328 m_planes[1] = std::move(uv_plane);
344 m_planes[0] = std::move(y_plane);
345 m_planes[1] = std::move(u_plane);
346 m_planes[2] = std::move(v_plane);
359 m_yuv_format.range = color_range::full;
360 m_yuv_format.format = yuv_format::yuv_nv12;
361 m_yuv_format.standard = color_std::bt601;
363 m_planes[0] = std::move(y_plane);
364 m_planes[1] = std::move(uv_plane);
374 size_t uv_size() const noexcept;
376 using conversion_matrix = std::array<
float, 16>;
379 virtual conversion_matrix get_yuv_to_rgb_matrix() const;
380 virtual conversion_matrix get_rgb_to_yuv_matrix() const;
385 uint8_t y_pixel_at(uint32_t xi, uint32_t yi) const noexcept;
389 uint8_t uv_pixel_at(uint32_t xi, uint32_t yi, uint32_t offset) const noexcept;
394 uint8_t u_pixel_at(uint32_t xi, uint32_t yi) const noexcept;
398 uint8_t v_pixel_at(uint32_t xi, uint32_t yi) const noexcept;
442 color_plane m_planes[3];
502 bool is_landscape() const;
504 bnb::
transformation get_subchannel_basis_transform(
float inv_scale = 1.f)
const
515 return bnb::transformation(full_roi, full_roi, rot_t::deg_0, get_format().require_mirroring) >> basis_transform;
522 const T& get_data() const noexcept;
528 bool has_data() const noexcept;
535 void set_fov(
float fov);
540 void normalize_orientation();
542#if BNB_OS_ANDROID || BNB_OS_EMSCRIPTEN
543 unsigned ext_camera_tex_id = 0;
544 unsigned ext_camera_tex_width = 0;
545 unsigned ext_camera_tex_height = 0;
549 using plane_deleter = std::function<void(uint8_t*)>;
552 const uint8_t* rgb_plane,
559 plane_deleter deleter
563 const uint8_t* y_plane,
565 const uint8_t* uv_plane,
573 plane_deleter y_deleter,
574 plane_deleter uv_deleter
578 const uint8_t* y_plane,
580 const uint8_t* u_plane,
582 const uint8_t* v_plane,
590 plane_deleter y_deleter,
591 plane_deleter u_deleter,
592 plane_deleter v_deleter
686 void init_planes_data();
687 void init_plane(uint32_t plane_num, uint8_t* data, int32_t stride, int32_t width, int32_t height, int32_t pixel_size);
688 void validate_plane_number(uint32_t plane_num)
const;
694 int32_t bytes_per_row{0};
697 int32_t pixel_size{0};
700 using image_t = std::variant<yuv_image_t, bpc8_image_t>;
702 plane_data m_planes_info[3];
703 uint32_t m_plane_count{0};
707 const T& _get_data() const noexcept;
710 bool _has_data() const noexcept;
712 void update_basis_transform();
718 static_assert(std::is_base_of<base_image_t, T>::value,
"Type is not image_t");
719 BNB_ASSERT(std::holds_alternative<T>(m_image));
720 return *std::get_if<T>(&m_image);
724 inline bool full_image_t::has_data() const noexcept
726 static_assert(std::is_base_of<base_image_t, T>::value,
"Type is not image_t");
727 return std::holds_alternative<T>(m_image);
A base class for *_image_t classes.
base_image_t()=default
Construct a new base_image_t object with default values.
void set_fov(float fov)
Set the field of view.
const image_format & get_format() const
A class for representing bpc8 images as C++ object.
bpc8_image_t(color_plane data, pixel_format_t type, const image_format &format)
Construct a new bpc8_image_t object with user's values.
pixel_format_t get_pixel_format() const noexcept
bpc8_image_t(const bpc8_image_t &)=default
Construct a new bpc8_image_t object using copy operation.
bpc8_image_t()=default
enum value represents pixel format (
bpc8_image_t(bpc8_image_t &&)=default
Construct a new bpc8_image_t object using move semantics.
basis is the base basis: for y/rgb basis use .basis or get_subchannel_basis_transform(1); for uv basi...
int32_t get_bytes_per_row() const
Returns the stride of the first plane.
int32_t get_height_of_plane(uint32_t plane_num) const
Returns the height of the specified plane.
full_image_t(full_image_t &&) noexcept
Construct a new full_image_t object using move semantics.
full_image_t()
Construct a new full_image_t object with default params.
uint8_t * get_base_ptr_of_plane(uint32_t plane_num) const
Returns the shared pointer to pixel data of the specified plane.
static full_image_t load(const std::string &path, bool alpha=false)
A method for loading video from path with/whithout alpha.
uint8_t * get_base_ptr() const
Returns the shared pointer of the first plane.
int32_t get_bytes_per_row_of_plane(uint32_t plane_num) const
Returns the stride of the specified plane.
int32_t get_width_of_plane(uint32_t plane_num) const
Returns the width of the specified plane.
int32_t get_width() const
Returns the width of the first plane.
uint32_t get_number_of_planes() const
Returns count of the planes.
int32_t get_bytes_per_pixel() const
Returns the pixel size of the first plane.
full_image_t(yuv_image_t image)
Construct a new full_image_t object from image.
full_image_t(const full_image_t &)
Construct a new full_image_t object using copy operation.
bool get_mirroring() const
Returns the mirroring of the image.
color_range get_color_range() const
Returns yuv color range of the image.
int32_t get_height() const
Returns the height of the first plane.
bnb::transformation image_basis() const
color_std get_color_standard() const
Returns yuv color standard of the image.
full_image_t(bpc8_image_t image)
Construct a new full_image_t object from image.
orientation get_orientation() const
Returns the orientation of the image.
pixel_buffer_format get_pixel_buffer_format() const
Returns format of the image.
int32_t get_bytes_per_pixel_of_plane(uint32_t plane_num) const
Returns the pixel size of the specified plane.
Clas represents yuv image as C++ object.
size_t y_size() const noexcept
yuv_image_t(color_plane y_plane, color_plane uv_plane, const image_format &format, const yuv_format_t &yuv_format)
Construct a new yuv_image_t object with user's values (for yuv_nv12 format).
yuv_image_t(color_plane y_plane, color_plane uv_plane, const image_format &format)
Construct a new yuv image t object wioth user's values but with default yuv image format.
const color_plane get_plane() const
yuv_image_t(color_plane y_plane, color_plane u_plane, color_plane v_plane, const image_format &format, const yuv_format_t &yuv_format)
Construct a new yuv image t object with user's values (for yuv_i420 format).
yuv_format
Enum class represents supported yuv formats.
color_std
Enum class represents suppotred color standarts.
camera_orientation
camera image layout is top-left, 0 orientation is portrait, rotation is counterclockwise
color_range
Enum class represents color range.
pixel_buffer_format
bt601 and bt709 - two standards for representing color space that use the same image encoding/decodin...