@ -84,20 +84,73 @@ static int xkb_keysym_to_ascii(xkb_keysym_t keysym) {
return static_cast < int > ( keysym & 0xff ) ;
}
static void write_mat_to_xrgb8888 ( cv : : Mat const & img_ , void * data ) {
// Validate destination data.
CV_CheckFalse ( ( data = = nullptr ) , " Destination Address must not be nullptr. " ) ;
// Validate source img parameters.
CV_CheckFalse ( img_ . empty ( ) , " Source Mat must not be empty. " ) ;
const int ncn = img_ . channels ( ) ;
CV_CheckType ( img_ . type ( ) ,
( ( ncn = = 1 ) | | ( ncn = = 3 ) | | ( ncn = = 4 ) ) ,
" Unsupported channels, please convert to 1, 3 or 4 channels "
) ;
static void draw_xrgb8888 ( void * d , uint8_t a , uint8_t r , uint8_t g , uint8_t b ) {
* ( ( uint32_t * ) d ) = ( ( a < < 24 ) | ( r < < 16 ) | ( g < < 8 ) | b ) ;
}
static void write_mat_to_xrgb8888 ( cv : : Mat const & img , void * data ) {
CV_Assert ( data ! = nullptr ) ;
CV_Assert ( img . isContinuous ( ) ) ;
// The supported Mat depth is according to imshow() specification.
const int depth = CV_MAT_DEPTH ( img_ . type ( ) ) ;
CV_CheckDepth ( img_ . type ( ) ,
( ( depth = = CV_8U ) | | ( depth = = CV_8S ) | |
( depth = = CV_16U ) | | ( depth = = CV_16S ) | |
( depth = = CV_32F ) | | ( depth = = CV_64F ) ) ,
" Unsupported depth, please convert to CV_8U "
) ;
for ( int y = 0 ; y < img . rows ; y + + ) {
for ( int x = 0 ; x < img . cols ; x + + ) {
auto p = img . at < cv : : Vec3b > ( y , x ) ;
draw_xrgb8888 ( ( char * ) data + ( y * img . cols + x ) * 4 , 0x00 , p [ 2 ] , p [ 1 ] , p [ 0 ] ) ;
}
// Convert to CV_8U
cv : : Mat img ;
const int mtype = CV_MAKE_TYPE ( CV_8U , ncn ) ;
switch ( CV_MAT_DEPTH ( depth ) )
{
case CV_8U :
img = img_ ; // do nothing.
break ;
case CV_8S :
// [-128,127] -> [0,255]
img_ . convertTo ( img , mtype , 1.0 , 128 ) ;
break ;
case CV_16U :
// [0,65535] -> [0,255]
img_ . convertTo ( img , mtype , 1.0 / 255. ) ;
break ;
case CV_16S :
// [-32768,32767] -> [0,255]
img_ . convertTo ( img , mtype , 1.0 / 255. , 128 ) ;
break ;
case CV_32F :
case CV_64F :
// [0, 1] -> [0,255]
img_ . convertTo ( img , mtype , 255. ) ;
break ;
default :
// it cannot be reachable.
break ;
}
CV_CheckDepthEQ ( CV_MAT_DEPTH ( img . type ( ) ) , CV_8U , " img should be CV_8U " ) ;
// XRGB8888 in Little Endian(Wayland Request) = [B8:G8:R8:X8] in data array.
// X is not used to show. So we can use cvtColor() with GRAY2BGRA or BGR2BGRA or copyTo().
cv : : Mat dst ( img . size ( ) , CV_MAKE_TYPE ( CV_8U , 4 ) , ( uint8_t * ) data ) ;
if ( ncn = = 1 )
{
cvtColor ( img , dst , cv : : COLOR_GRAY2BGRA ) ;
}
else if ( ncn = = 3 )
{
cvtColor ( img , dst , cv : : COLOR_BGR2BGRA ) ;
}
else
{
CV_CheckTrue ( ncn = = 4 , " Unexpected channels " ) ;
img . copyTo ( dst ) ;
}
}
@ -232,10 +285,10 @@ private:
& handle_pointer_axis , & handle_pointer_frame ,
& handle_pointer_axis_source , & handle_pointer_axis_stop ,
& handle_pointer_axis_discrete ,
# if WL_POINTER_AXIS_VALUE120_SINCE_VERSION >= 8
# ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
& handle_axis_value120 ,
# endif
# if WL_POINTER_AXIS_RELATIVE_DIRECTION_SINCE_VERSION >= 9
# ifdef WL_POINTER_AXIS_RELATIVE_DIRECTION_SINCE_VERSION
& handle_axis_relative_direction ,
# endif
} ;
@ -284,7 +337,7 @@ private:
CV_UNUSED ( discrete ) ;
}
# if WL_POINTER_AXIS_VALUE120_SINCE_VERSION >= 8
# ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
static void
handle_axis_value120 ( void * data , struct wl_pointer * wl_pointer , uint32_t axis , int32_t value120 ) {
CV_UNUSED ( data ) ;
@ -294,7 +347,7 @@ private:
}
# endif
# if WL_POINTER_AXIS_RELATIVE_DIRECTION_SINCE_VERSION >= 9
# ifdef WL_POINTER_AXIS_RELATIVE_DIRECTION_SINCE_VERSION
static void
handle_axis_relative_direction ( void * data , struct wl_pointer * wl_pointer , uint32_t axis , uint32_t direction ) {
CV_UNUSED ( data ) ;
@ -686,7 +739,7 @@ public:
void show_image ( cv : : Mat const & image ) ;
void create_trackbar ( std : : string const & name , int * value , int count , CvTrackbarCallback2 on_change , void * userdata ) ;
int create_trackbar ( std : : string const & name , int * value , int count , CvTrackbarCallback2 on_change , void * userdata ) ;
weak_ptr < cv_wl_trackbar > get_trackbar ( std : : string const & ) const ;
@ -723,10 +776,10 @@ private:
struct xdg_toplevel * xdg_toplevel_ ;
struct xdg_toplevel_listener xdgtop_listener_ {
& handle_toplevel_configure , & handle_toplevel_close ,
# if XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION >= 4
# ifdef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION
& handle_toplevel_configure_bounds ,
# endif
# if XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION >= 5
# ifdef XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION
& handle_toplevel_wm_capabilities ,
# endif
} ;
@ -775,7 +828,7 @@ private:
static void handle_toplevel_close ( void * data , struct xdg_toplevel * surface ) ;
# if XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION >= 4
# ifdef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION
static void
handle_toplevel_configure_bounds ( void * data , struct xdg_toplevel * xdg_toplevel , int32_t width , int32_t height )
{
@ -786,7 +839,7 @@ private:
}
# endif
# if XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION >= 5
# ifdef XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION
static void
handle_toplevel_wm_capabilities ( void * data , struct xdg_toplevel * xdg_toplevel , struct wl_array * capabilities )
{
@ -1527,13 +1580,7 @@ cv_wl_viewer::cv_wl_viewer(cv_wl_window *window, int flags)
}
void cv_wl_viewer : : set_image ( cv : : Mat const & image ) {
if ( image . type ( ) = = CV_8UC1 ) {
cv : : Mat bgr ;
cv : : cvtColor ( image , bgr , CV_GRAY2BGR ) ;
image_ = bgr . clone ( ) ;
} else {
image_ = image . clone ( ) ;
}
image_ = image . clone ( ) ;
image_changed_ = true ;
}
@ -1642,6 +1689,11 @@ cv_wl_trackbar::cv_wl_trackbar(cv_wl_window *window, std::string name,
on_change_ . value = value ;
on_change_ . data = data ;
on_change_ . callback = on_change ;
// initilize slider_.value if value is not nullptr.
if ( value ! = nullptr ) {
set_pos ( * value ) ;
}
}
std : : string const & cv_wl_trackbar : : name ( ) const {
@ -1657,6 +1709,12 @@ void cv_wl_trackbar::set_pos(int value) {
slider_ . value = value ;
slider_moved_ = true ;
window_ - > show ( ) ;
// Update user-ptr value and call on_change() function if cv_wl_trackbar::draw() is not called.
if ( slider_moved_ ) {
on_change_ . update ( slider_ . value ) ;
on_change_ . call ( slider_ . value ) ;
}
}
}
@ -1666,6 +1724,12 @@ void cv_wl_trackbar::set_max(int maxval) {
slider_ . value = maxval ;
slider_moved_ = true ;
window_ - > show ( ) ;
// Update user-ptr and call on_change() function if cv_wl_trackbar::draw() is not called.
if ( slider_moved_ ) {
on_change_ . update ( slider_ . value ) ;
on_change_ . call ( slider_ . value ) ;
}
}
}
@ -1836,8 +1900,9 @@ void cv_wl_window::show_image(cv::Mat const &image) {
this - > show ( ) ;
}
void cv_wl_window : : create_trackbar ( std : : string const & name , int * value , int count , CvTrackbarCallback2 on_change ,
int cv_wl_window : : create_trackbar ( std : : string const & name , int * value , int count , CvTrackbarCallback2 on_change ,
void * userdata ) {
int ret = 0 ;
auto exists = this - > get_trackbar ( name ) . lock ( ) ;
if ( ! exists ) {
auto trackbar =
@ -1846,7 +1911,9 @@ void cv_wl_window::create_trackbar(std::string const &name, int *value, int coun
) ;
widgets_ . emplace_back ( trackbar ) ;
widget_geometries_ . emplace_back ( 0 , 0 , 0 , 0 ) ;
ret = 1 ;
}
return ret ;
}
weak_ptr < cv_wl_trackbar > cv_wl_window : : get_trackbar ( std : : string const & trackbar_name ) const {
@ -2324,6 +2391,7 @@ std::string const &cv_wl_core::get_window_name(void *handle) {
}
bool cv_wl_core : : create_window ( std : : string const & name , int flags ) {
CV_CheckTrue ( display_ ! = nullptr , " Display is not connected. " ) ;
auto window = std : : make_shared < cv_wl_window > ( display_ , name , flags ) ;
auto result = windows_ . insert ( std : : make_pair ( name , window ) ) ;
handles_ [ window . get ( ) ] = window - > get_title ( ) ;
@ -2402,6 +2470,13 @@ CV_IMPL void cvResizeWindow(const char *name, int width, int height) {
throw_system_error ( " Could not get window name " , errno )
}
CvRect cvGetWindowRect_WAYLAND ( const char * name )
{
CV_UNUSED ( name ) ;
CV_LOG_ONCE_WARNING ( nullptr , " Function not implemented: User cannot get window rect in Wayland " ) ;
return cvRect ( - 1 , - 1 , - 1 , - 1 ) ;
}
CV_IMPL int cvCreateTrackbar ( const char * name_bar , const char * window_name , int * value , int count ,
CvTrackbarCallback on_change ) {
CV_UNUSED ( name_bar ) ;
@ -2416,10 +2491,11 @@ CV_IMPL int cvCreateTrackbar(const char *name_bar, const char *window_name, int
CV_IMPL int cvCreateTrackbar2 ( const char * trackbar_name , const char * window_name , int * val , int count ,
CvTrackbarCallback2 on_notify , void * userdata ) {
int ret = 0 ;
if ( auto window = CvWlCore : : getInstance ( ) . get_window ( window_name ) )
window - > create_trackbar ( trackbar_name , val , count , on_notify , userdata ) ;
ret = window - > create_trackbar ( trackbar_name , val , count , on_notify , userdata ) ;
return 0 ;
return ret ;
}
CV_IMPL int cvGetTrackbarPos ( const char * trackbar_name , const char * window_name ) {