17 #ifndef ASTRA_IMAGE_HPP
18 #define ASTRA_IMAGE_HPP
23 #include <astra_core/astra_core.hpp>
24 #include <astra/capi/astra_ctypes.h>
25 #include <astra/capi/streams/image_capi.h>
26 #include <astra/capi/streams/stream_types.h>
55 RgbPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b)
57 ::astra_rgb_pixel_t::r = r;
58 ::astra_rgb_pixel_t::g = g;
59 ::astra_rgb_pixel_t::b = b;
83 RgbaPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t alpha)
85 ::astra_rgba_pixel_t::r = r;
86 ::astra_rgba_pixel_t::g = g;
87 ::astra_rgba_pixel_t::b = b;
88 ::astra_rgba_pixel_t::alpha = alpha;
93 typedef RgbaPixel RGBAPixel;
149 operator ::astra_imagestream_mode_t*() {
return this; }
150 operator const ::astra_imagestream_mode_t*()
const {
return this; }
157 std::uint8_t
fps()
const {
return astra_imagestream_mode_t::fps; }
174 astra_pixelformat_get_bytes_per_pixel(
pixel_format(), &bpp);
183 std::uint32_t
width()
const {
return astra_imagestream_mode_t::width; }
197 std::uint32_t
height()
const {
return astra_imagestream_mode_t::height; }
211 astra_pixel_format_t
pixel_format()
const {
return astra_imagestream_mode_t::pixelFormat; }
218 void set_pixel_format(astra_pixel_format_t format) { astra_imagestream_mode_t::pixelFormat = format; }
220 friend std::ostream& operator<<(std::ostream& os,
const ImageStreamMode& ism);
249 return !(lhs == rhs);
252 inline std::ostream& operator<<(std::ostream& os,
const ImageStreamMode& ism)
258 <<
static_cast<int>(ism.bytes_per_pixel())
260 <<
static_cast<int>(ism.fps())
262 << ism.pixel_format();
286 astra_imagestream_get_hfov(imageStream_, &
hFov);
299 astra_imagestream_get_vfov(imageStream_, &
vFov);
312 astra_imagestream_get_usb_info(imageStream_, &usbInfo);
323 bool mirroring =
false;
324 astra_imagestream_get_mirroring(imageStream_, &mirroring);
336 astra_imagestream_set_mirroring(imageStream_, mirroring);
346 astra_result_token_t token;
347 std::uint32_t count = 0;
348 astra_status_t ret = astra_imagestream_request_modes(imageStream_, &token, &count);
349 if (ret != ASTRA_STATUS_SUCCESS)
350 return std::vector<ImageStreamMode>();
352 std::vector<ImageStreamMode> result;
353 result.resize(count);
355 astra_imagestream_get_modes_result(imageStream_,
372 astra_imagestream_get_mode(imageStream_, cMode);
384 astra_imagestream_set_mode(imageStream_, cMode);
395 template<
typename TDataType, astra_stream_type_t TStreamType>
410 if (imageFrame_->metadata.pixelFormat != expected_format)
413 imageFrame_ =
nullptr;
417 astra_imageframe_get_frameindex(imageFrame_, &frameIndex_);
419 void* voidData =
nullptr;
420 astra_imageframe_get_data_ptr(imageFrame_, &voidData, &byteLength_);
421 dataPtr_ =
static_cast<TDataType*
>(voidData);
430 const bool is_valid()
const {
return imageFrame_ !=
nullptr; }
437 const int width()
const { throw_if_invalid_frame();
return imageFrame_->metadata.width; }
444 const int height()
const { throw_if_invalid_frame();
return imageFrame_->metadata.height; }
453 throw_if_invalid_frame();
456 astra_pixelformat_get_bytes_per_pixel(imageFrame_->metadata.pixelFormat, &bpp);
465 const astra_frame_index_t
frame_index()
const { throw_if_invalid_frame();
return frameIndex_; }
486 const TDataType*
data()
const { throw_if_invalid_frame();
return dataPtr_; }
493 const size_t byte_length()
const { throw_if_invalid_frame();
return byteLength_; }
500 const size_t length()
const { throw_if_invalid_frame();
return imageFrame_->metadata.width * imageFrame_->metadata.height; }
509 throw_if_invalid_frame();
510 astra_imageframe_copy_data(imageFrame_, buffer);
518 template<
typename TFrameType>
519 static TFrameType
acquire(astra_reader_frame_t readerFrame,
520 astra_stream_subtype_t subtype)
522 if (readerFrame !=
nullptr)
525 astra_reader_get_imageframe(readerFrame, TStreamType, subtype, &imageFrame);
527 return TFrameType(imageFrame);
530 return TFrameType(
nullptr);
544 void throw_if_invalid_frame()
const
546 if (!imageFrame_) {
throw std::logic_error(
"Cannot operate on an invalid frame"); }
550 astra_frame_index_t frameIndex_;
553 std::uint32_t byteLength_;
Data Stream
Definition: DataStream.hpp:33
Basic Image Frame
Definition: Image.hpp:397
static TFrameType acquire(astra_reader_frame_t readerFrame, astra_stream_subtype_t subtype)
acquire frame
Definition: Image.hpp:519
void rotate(int angle)
Definition: Image.hpp:538
const int height() const
get height
Definition: Image.hpp:444
const std::uint8_t bytes_per_pixel() const
get bytes per pixel
Definition: Image.hpp:451
void copy_to(TDataType *buffer) const
copy to buffer
Definition: Image.hpp:507
const size_t byte_length() const
get byte length
Definition: Image.hpp:493
const astra_frame_index_t frame_index() const
get frame index
Definition: Image.hpp:465
const size_t length() const
get length
Definition: Image.hpp:500
const int width() const
get width
Definition: Image.hpp:437
const astra_imageframe_t handle() const
get handle
Definition: Image.hpp:472
const bool is_valid() const
get is vaild
Definition: Image.hpp:430
const TDataType * data() const
get data pointer
Definition: Image.hpp:486
ImageFrame(astra_imageframe_t frame, astra_pixel_format_t expected_format)
Default constructs
Definition: Image.hpp:405
static astra_stream_type_t stream_type()
get stream type
Definition: Image.hpp:479
basic Image Stream
Definition: Image.hpp:271
ImageStreamMode mode() const
get current image mode
Definition: Image.hpp:368
void enable_mirroring(bool mirroring)
enable mirroring
Definition: Image.hpp:334
bool mirroring_enabled() const
get is mirroring
Definition: Image.hpp:321
float vFov() const
get vertical fov
Definition: Image.hpp:296
astra_usb_info_t usb_info() const
get usb_info
Definition: Image.hpp:309
float hFov() const
get horizontal fov
Definition: Image.hpp:283
void set_mode(const ImageStreamMode &mode)
set current image mode
Definition: Image.hpp:381
std::vector< ImageStreamMode > available_modes() const
get available_modes
Definition: Image.hpp:344
Image Stream Mode
Definition: Image.hpp:99
void set_width(std::uint32_t width)
set width
Definition: Image.hpp:190
std::uint8_t fps() const
get fps
Definition: Image.hpp:157
std::uint32_t width() const
get width
Definition: Image.hpp:183
ImageStreamMode(std::uint32_t width, std::uint32_t height, std::uint8_t fps, astra_pixel_format_t format)
constructs
Definition: Image.hpp:116
ImageStreamMode(const ::astra_imagestream_mode_t &mode)
copy constructs
Definition: Image.hpp:129
void set_height(std::uint32_t height)
set height
Definition: Image.hpp:204
const std::uint8_t bytes_per_pixel() const
get bytes per pixel
Definition: Image.hpp:171
astra_pixel_format_t pixel_format() const
get height
Definition: Image.hpp:211
ImageStreamMode()
Default constructs
Definition: Image.hpp:104
std::uint32_t height() const
get height
Definition: Image.hpp:197
void set_pixel_format(astra_pixel_format_t format)
set fps
Definition: Image.hpp:218
void set_fps(std::uint8_t fps)
set fps
Definition: Image.hpp:164
ImageStreamMode & operator=(const ::astra_imagestream_mode_t &mode)
copy constructs
Definition: Image.hpp:139
bool operator!=(const ImageStreamMode &lhs, const ImageStreamMode &rhs)
compare is ImageStreamMode not equal
Definition: Image.hpp:247
bool operator==(const ImageStreamMode &lhs, const ImageStreamMode &rhs)
compare is ImageStreamMode equal
Definition: Image.hpp:230
ASTRA_API_EX astra_status_t astra_imageframe_rotate(astra_imageframe_t imageFrame, int angle)
Definition: stream_types.h:37
Definition: astra_plugin.h:24
rgb pixel struct
Definition: Image.hpp:40
RgbPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b)
constructs
Definition: Image.hpp:55
RgbPixel()
Default constructs all zero
Definition: Image.hpp:44
rgba pixel struct
Definition: Image.hpp:67
RgbaPixel()
Default constructs all zero
Definition: Image.hpp:71
RgbaPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t alpha)
constructs
Definition: Image.hpp:83
Definition: image_types.h:62
Definition: image_types.h:42
Definition: image_types.h:48
Definition: astra_ctypes.h:44