From 7ca8527b440d4088e5bd62320b3219a5a40bd0c1 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 2 Apr 2024 18:15:03 +0000 Subject: [PATCH 01/81] template for framebuffer highgui --- CMakeLists.txt | 4 + modules/highgui/CMakeLists.txt | 14 ++++ modules/highgui/src/backend.hpp | 5 ++ modules/highgui/src/registry.impl.hpp | 5 ++ modules/highgui/src/window_framebuffer.cpp | 96 ++++++++++++++++++++++ modules/highgui/src/window_framebuffer.hpp | 68 +++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 modules/highgui/src/window_framebuffer.cpp create mode 100644 modules/highgui/src/window_framebuffer.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e20f68cca0b6..eca47cdd1ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,6 +297,10 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_GTK AND NOT HAVE_GTK3) + +OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF + VISIBLE_IF UNIX VERIFY HAVE_FRAMEBUFFER) + OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_WAYLAND) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index d8a7bb050ab2..82cb44bbdf0f 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -39,6 +39,17 @@ if(HAVE_WEBP) add_definitions(-DHAVE_WEBP) endif() + +if(WITH_FRAMEBUFFER) + message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") + add_definitions(-DHAVE_FRAMEBUFFER) + list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) +else() + message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") +endif() + + file(GLOB highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp" "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp" @@ -180,6 +191,9 @@ elseif(HAVE_COCOA) list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa") endif() + + + if(TARGET ocv.3rdparty.win32ui) if("win32ui" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all") ocv_create_builtin_highgui_plugin(opencv_highgui_win32 ocv.3rdparty.win32ui "window_w32.cpp") diff --git a/modules/highgui/src/backend.hpp b/modules/highgui/src/backend.hpp index 7c32846ce4a3..c5b3be73a1f4 100644 --- a/modules/highgui/src/backend.hpp +++ b/modules/highgui/src/backend.hpp @@ -126,6 +126,11 @@ std::shared_ptr createUIBackendGTK(); std::shared_ptr createUIBackendQT(); #endif +#ifdef HAVE_FRAMEBUFFER +std::shared_ptr createUIBackendFramebuffer(); +#endif + + #endif // BUILD_PLUGIN } // namespace highgui_backend diff --git a/modules/highgui/src/registry.impl.hpp b/modules/highgui/src/registry.impl.hpp index 23f4e9f4e1a0..956cb969c901 100644 --- a/modules/highgui/src/registry.impl.hpp +++ b/modules/highgui/src/registry.impl.hpp @@ -44,6 +44,11 @@ std::vector& getBuiltinBackendsInfo() DECLARE_DYNAMIC_BACKEND("GTK2") #endif +#ifdef HAVE_FRAMEBUFFER + DECLARE_STATIC_BACKEND("Framebuffer", createUIBackendFramebuffer) +#endif + + #if 0 // TODO #ifdef HAVE_QT DECLARE_STATIC_BACKEND("QT", createUIBackendQT) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp new file mode 100644 index 000000000000..4cf1093d2d98 --- /dev/null +++ b/modules/highgui/src/window_framebuffer.cpp @@ -0,0 +1,96 @@ +#include "window_framebuffer.hpp" + +#include "opencv2/core/utils/logger.hpp" + +namespace cv { namespace highgui_backend { + + std::shared_ptr createUIBackendFramebuffer() + { + return std::make_shared(); + } + + + void FramebufferWindow::imshow(InputArray image){ + std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; + } + + double FramebufferWindow::getProperty(int prop) const{ + std::cout << "FramebufferWindow::getProperty(int prop:" << prop <<")"<< std::endl; + return 0.0; + } + bool FramebufferWindow::setProperty(int prop, double value) { + std::cout << "FramebufferWindow::setProperty(int prop "<< prop <<", double value "< FramebufferWindow::createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange, + void* userdata + ){ + return nullptr; + } + + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name){ + return nullptr; + } + + const std::string& FramebufferWindow::getID() const { + std::cout << "getID())" << std::endl; return FB_ID; + } + + bool FramebufferWindow::isActive() const { + std::cout << "isActive()" << std::endl; + return true; + } + + void FramebufferWindow::destroy() { + std::cout << "destroy()" << std::endl; + } + + void FramebufferBackend::destroyAllWindows() { + std::cout << "destroyAllWindows()" << std::endl; + } + + // namedWindow + std::shared_ptr FramebufferBackend::createWindow( + const std::string& winname, + int flags + ){ + std::cout << "FramebufferBackend::createWindow("<< winname <<", "<(); + } + + int FramebufferBackend::waitKeyEx(int delay) { + std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; + return 0; + } + int FramebufferBackend::pollKey() { + std::cout << "FramebufferBackend::pollKey()" << std::endl; + return 0; + } + + +} +} diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp new file mode 100644 index 000000000000..c56e772b2e9d --- /dev/null +++ b/modules/highgui/src/window_framebuffer.hpp @@ -0,0 +1,68 @@ +#ifndef OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP +#define OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP + +#include "precomp.hpp" +#include "backend.hpp" + +namespace cv { namespace highgui_backend { + +class CV_EXPORTS FramebufferWindow : public UIWindow +{ + std::string FB_ID; +public: + FramebufferWindow(){FB_ID = "FramebufferWindow";} + virtual ~FramebufferWindow(){} + + virtual void imshow(InputArray image)override; + + virtual double getProperty(int prop) const override; + virtual bool setProperty(int prop, double value)override; + + virtual void resize(int width, int height)override; + virtual void move(int x, int y)override; + + virtual Rect getImageRect() const override; + + virtual void setTitle(const std::string& title)override; + + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + + virtual std::shared_ptr createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange /*= 0*/, + void* userdata /*= 0*/ + )override; + + virtual std::shared_ptr findTrackbar(const std::string& name)override; + + virtual const std::string& getID() const override; + + virtual bool isActive() const override; + + virtual void destroy() override; +}; // FramebufferWindow + +class CV_EXPORTS FramebufferBackend: public UIBackend +{ +public: + virtual ~FramebufferBackend(){} + + virtual void destroyAllWindows()override; + + // namedWindow + virtual std::shared_ptr createWindow( + const std::string& winname, + int flags + ); + + virtual int waitKeyEx(int delay /*= 0*/)override; + virtual int pollKey() override; +}; + +} + +} + + +#endif From fbafa76813b6dc9015559307d21686099a59b28e Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 16 Apr 2024 20:05:14 +0300 Subject: [PATCH 02/81] add imshow --- modules/highgui/src/window_framebuffer.cpp | 127 +++++++++++++++++++++ modules/highgui/src/window_framebuffer.hpp | 82 ++++++++----- 2 files changed, 179 insertions(+), 30 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 4cf1093d2d98..bc1dca4051e6 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -2,6 +2,18 @@ #include "opencv2/core/utils/logger.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opencv2/imgproc.hpp" + + namespace cv { namespace highgui_backend { std::shared_ptr createUIBackendFramebuffer() @@ -9,9 +21,124 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } + int FramebufferWindow::fb_open_and_get_info() + { + int fb_fd = open("/dev/fb0", O_RDWR); + if (fb_fd == -1) + { + std::cerr << "ERROR_OPENING_FB\n"; + return -1; + } + + // Get fixed screen information + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { + std::cerr << "ERROR_READING_FIX_INFO\n"; + return -1; + } + + // Get variable screen information + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { + std::cerr << "EERROR_READING_VAR_INFO\n"; + return -1; + } + + return fb_fd; + } + + FramebufferWindow::FramebufferWindow() + { + std::cout << "FramebufferWindow()" << std::endl; + FB_ID = "FramebufferWindow"; + framebuffrer_id = fb_open_and_get_info(); + std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + if(framebuffrer_id == -1) return; + + fb_w = var_info.xres; + fb_h = var_info.yres; + y_offset = var_info.yoffset; + x_offset = var_info.xoffset; + bpp = var_info.bits_per_pixel; + line_length = fix_info.line_length; + + std::cout << "= Framebuffer's width, height, bits per pix:\n" + << fb_w << " " << fb_h << " " << bpp << "\n\n"; + std::cout << "= Framebuffer's offsets, line length:\n" + << y_offset << " " << x_offset << " " << line_length << "\n\n"; + + // MAP FB TO MEMORY + screensize = fb_w * fb_h * bpp / 8; + fbPointer = (unsigned char*) + mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, + framebuffrer_id, 0); + if (fbPointer == MAP_FAILED) { + std::cerr << "ERROR_MAP\n"; + return; + } + + backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(backgroundBuff.ptr(y - y_offset), + fbPointer + y * line_length, + backgroundBuff.cols * cnt_channel); + } + + + } void FramebufferWindow::imshow(InputArray image){ std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; + std::cout << "InputArray image:: size" << image.size() << std::endl; + if (fbPointer == MAP_FAILED) { + return; + } + + Mat img; + cvtColor(image, img, COLOR_RGB2RGBA); + // changing the image size to match the entered width + double aspect_ratio = static_cast(img.cols) / img.rows; + int new_width = fb_w; + int new_height = static_cast(fb_w / aspect_ratio); + int cnt_channel = img.channels(); + + std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; + std::cout << "= Image count of channels:\n" << img.channels() << "\n"; + + // RECIZE IMAGE TO MATCH THE FB SIZE + if (new_width > fb_w || new_height > fb_h) { + if (aspect_ratio > static_cast(fb_w) / fb_h) { + new_width = fb_w; + new_height = static_cast(fb_w / aspect_ratio); + } else { + new_height = fb_h; + new_width = static_cast(fb_h * aspect_ratio); + } + } + cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); + + std::cout << "= Recized image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + + // RESTORE BACKGROUNG + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length, + backgroundBuff.ptr(y - y_offset), + backgroundBuff.cols*cnt_channel); + } + + + + // SHOW IMAGE + for (int y = y_offset; y < img.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length, + img.ptr(y - y_offset), + img.cols*cnt_channel); + } + + } double FramebufferWindow::getProperty(int prop) const{ diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index c56e772b2e9d..3b1a81628692 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -4,60 +4,82 @@ #include "precomp.hpp" #include "backend.hpp" +#include +#include + + namespace cv { namespace highgui_backend { class CV_EXPORTS FramebufferWindow : public UIWindow { + fb_var_screeninfo var_info; + fb_fix_screeninfo fix_info; + std::string FB_ID; + + int fb_open_and_get_info(); + int framebuffrer_id; + + int fb_w; + int fb_h; + int y_offset; + int x_offset; + int bpp; + int line_length; + long int screensize; + unsigned char* fbPointer; + + Mat backgroundBuff; + public: - FramebufferWindow(){FB_ID = "FramebufferWindow";} - virtual ~FramebufferWindow(){} + FramebufferWindow(); + virtual ~FramebufferWindow(){} - virtual void imshow(InputArray image)override; + virtual void imshow(InputArray image)override; - virtual double getProperty(int prop) const override; - virtual bool setProperty(int prop, double value)override; + virtual double getProperty(int prop) const override; + virtual bool setProperty(int prop, double value)override; - virtual void resize(int width, int height)override; - virtual void move(int x, int y)override; + virtual void resize(int width, int height)override; + virtual void move(int x, int y)override; - virtual Rect getImageRect() const override; + virtual Rect getImageRect() const override; - virtual void setTitle(const std::string& title)override; + virtual void setTitle(const std::string& title)override; - virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; - virtual std::shared_ptr createTrackbar( - const std::string& name, - int count, - TrackbarCallback onChange /*= 0*/, - void* userdata /*= 0*/ - )override; + virtual std::shared_ptr createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange /*= 0*/, + void* userdata /*= 0*/ + )override; - virtual std::shared_ptr findTrackbar(const std::string& name)override; - - virtual const std::string& getID() const override; + virtual std::shared_ptr findTrackbar(const std::string& name)override; + + virtual const std::string& getID() const override; - virtual bool isActive() const override; + virtual bool isActive() const override; - virtual void destroy() override; + virtual void destroy() override; }; // FramebufferWindow class CV_EXPORTS FramebufferBackend: public UIBackend { public: - virtual ~FramebufferBackend(){} + virtual ~FramebufferBackend(){} - virtual void destroyAllWindows()override; + virtual void destroyAllWindows()override; - // namedWindow - virtual std::shared_ptr createWindow( - const std::string& winname, - int flags - ); + // namedWindow + virtual std::shared_ptr createWindow( + const std::string& winname, + int flags + ); - virtual int waitKeyEx(int delay /*= 0*/)override; - virtual int pollKey() override; + virtual int waitKeyEx(int delay /*= 0*/)override; + virtual int pollKey() override; }; } From 462a0e0fdd20c17149e05266b97f796e1e8235cf Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 16 Apr 2024 23:13:20 +0300 Subject: [PATCH 03/81] temporary implementation of waitKey --- modules/highgui/src/window_framebuffer.cpp | 126 ++++++++++++++++++++- modules/highgui/src/window_framebuffer.hpp | 16 ++- 2 files changed, 139 insertions(+), 3 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index bc1dca4051e6..067e3e40b069 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ namespace cv { namespace highgui_backend { return fb_fd; } + FramebufferWindow::FramebufferWindow() { @@ -51,6 +53,7 @@ namespace cv { namespace highgui_backend { FB_ID = "FramebufferWindow"; framebuffrer_id = fb_open_and_get_info(); std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + if(framebuffrer_id == -1) return; fb_w = var_info.xres; @@ -86,6 +89,25 @@ namespace cv { namespace highgui_backend { } + + FramebufferWindow::~FramebufferWindow(){ + + if(framebuffrer_id == -1) return; + + // RESTORE BACKGROUNG + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length, + backgroundBuff.ptr(y - y_offset), + backgroundBuff.cols*cnt_channel); + } + + if (fbPointer != MAP_FAILED) { + munmap(fbPointer, screensize); + } + close(framebuffrer_id); + } void FramebufferWindow::imshow(InputArray image){ std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; @@ -196,6 +218,32 @@ namespace cv { namespace highgui_backend { std::cout << "destroy()" << std::endl; } + int FramebufferBackend::OpenInputEvent() + { + int fd; + fd = open("/dev/input/event1", O_RDONLY); + if (fd == -1) { + std::cerr << "ERROR_OPENING_INPUT\n"; + return -1; + } + return fd; + } + + + FramebufferBackend::FramebufferBackend() + { + eventKey = OpenInputEvent(); + std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; + } + + FramebufferBackend::~FramebufferBackend() + { + if(eventKey != -1) + { + close(eventKey); + } + } + void FramebufferBackend::destroyAllWindows() { std::cout << "destroyAllWindows()" << std::endl; } @@ -209,9 +257,85 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } + void FramebufferBackend::initTermios(int echo) + { + tcgetattr(0, &old); /* grab old terminal i/o settings */ + current = old; /* make new settings same as old settings */ + current.c_lflag &= ~ICANON; /* disable buffered i/o */ + if (echo) { + current.c_lflag |= ECHO; /* set echo mode */ + } else { + current.c_lflag &= ~ECHO; /* set no echo mode */ + } + tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ + } + + /* Restore old terminal i/o settings */ + void FramebufferBackend::resetTermios(void) + { + tcsetattr(0, TCSANOW, &old); + } + + char FramebufferBackend::getch_(int echo) + { + char ch; + initTermios(echo); + ch = getchar(); + resetTermios(); + return ch; + } + int FramebufferBackend::waitKeyEx(int delay) { std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; - return 0; + + int code = 0; + + char ch = getch_(0); + std::cout << "ch 1 " << (int)ch << std::endl; + code = ch; + + if(code == 27) + { + ch = getch_(0); + std::cout << "ch 2 " << (int)ch << std::endl; + // code = ch * 1000; + ch = getch_(0); + std::cout << "ch 2 " << (int)ch << std::endl; + // code += ch * 1000000; + code = ch; + } + +// struct input_event events; +// +// +// ssize_t r = 1; +// while(r > 0) +// { +// std::cout << "while 1 " << std::endl; +// r = read(eventKey, &events, sizeof(input_event)); +// std::cout << "while 1 " << std::endl; +// } +// +// +// +// while((r == 0)&& ((delay > 1) || (delay == 0)) ) +// { +// delay--; +// usleep(1); +// r = read(eventKey, &events, sizeof(input_event)); +// std::cout << "while 2 " << std::endl; +// +// if(r != 0){ +// code = (events.code); +// } +// } +// + std::cout << "waitKeyEx:: code "<< code << std::endl; +// +// if(r == 0) +// return -1; +// + return code; } int FramebufferBackend::pollKey() { std::cout << "FramebufferBackend::pollKey()" << std::endl; diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 3b1a81628692..e450f85afd66 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace cv { namespace highgui_backend { @@ -33,7 +34,7 @@ class CV_EXPORTS FramebufferWindow : public UIWindow public: FramebufferWindow(); - virtual ~FramebufferWindow(){} + virtual ~FramebufferWindow(); virtual void imshow(InputArray image)override; @@ -67,8 +68,19 @@ class CV_EXPORTS FramebufferWindow : public UIWindow class CV_EXPORTS FramebufferBackend: public UIBackend { + int OpenInputEvent(); + int eventKey; + + struct termios old, current; + + void initTermios(int echo); + void resetTermios(void); + char getch_(int echo); + public: - virtual ~FramebufferBackend(){} + FramebufferBackend(); + + virtual ~FramebufferBackend(); virtual void destroyAllWindows()override; From 30da28550c73caa5235d4438c3d3ae8e6ce0ad82 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 17 Apr 2024 10:47:48 +0300 Subject: [PATCH 04/81] add if for bits_per_pixel and apply dos2unix --- modules/highgui/src/window_framebuffer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 067e3e40b069..e9be57426411 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -67,7 +67,7 @@ namespace cv { namespace highgui_backend { << fb_w << " " << fb_h << " " << bpp << "\n\n"; std::cout << "= Framebuffer's offsets, line length:\n" << y_offset << " " << x_offset << " " << line_length << "\n\n"; - + // MAP FB TO MEMORY screensize = fb_w * fb_h * bpp / 8; fbPointer = (unsigned char*) @@ -78,6 +78,11 @@ namespace cv { namespace highgui_backend { return; } + if(bpp != 32) { + std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + return; + } + backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); int cnt_channel = 4; for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) @@ -115,6 +120,11 @@ namespace cv { namespace highgui_backend { if (fbPointer == MAP_FAILED) { return; } + + if(bpp != 32) { + std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + return; + } Mat img; cvtColor(image, img, COLOR_RGB2RGBA); From b9efae6fd1983db4a8569adf4b9c64368e6ebc6a Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 18 Apr 2024 15:35:23 +0300 Subject: [PATCH 05/81] fix call mmap for FB --- modules/highgui/src/window_framebuffer.cpp | 38 ++++++++++++++-------- modules/highgui/src/window_framebuffer.hpp | 3 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index e9be57426411..ada190de3c33 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -69,7 +69,8 @@ namespace cv { namespace highgui_backend { << y_offset << " " << x_offset << " " << line_length << "\n\n"; // MAP FB TO MEMORY - screensize = fb_w * fb_h * bpp / 8; + screensize = max((__u32)fb_w, var_info.xres_virtual) * + max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; fbPointer = (unsigned char*) mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, framebuffrer_id, 0); @@ -134,9 +135,9 @@ namespace cv { namespace highgui_backend { int new_height = static_cast(fb_w / aspect_ratio); int cnt_channel = img.channels(); - std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; - std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; - std::cout << "= Image count of channels:\n" << img.channels() << "\n"; + //std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + //std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; + //std::cout << "= Image count of channels:\n" << img.channels() << "\n"; // RECIZE IMAGE TO MATCH THE FB SIZE if (new_width > fb_w || new_height > fb_h) { @@ -272,6 +273,8 @@ namespace cv { namespace highgui_backend { tcgetattr(0, &old); /* grab old terminal i/o settings */ current = old; /* make new settings same as old settings */ current.c_lflag &= ~ICANON; /* disable buffered i/o */ + current.c_lflag &= ~ISIG; + current.c_cc[VMIN]=1; if (echo) { current.c_lflag |= ECHO; /* set echo mode */ } else { @@ -286,38 +289,45 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, &old); } - char FramebufferBackend::getch_(int echo) + int FramebufferBackend::getch_(int echo) { - char ch; + int ch; initTermios(echo); ch = getchar(); resetTermios(); return ch; } + bool FramebufferBackend::kbhit() + { + int byteswaiting=0; + initTermios(0); + if ( ioctl(0, FIONREAD, &byteswaiting) < 0) + { + std::cout << " ERR byteswaiting " << std::endl; + } + resetTermios(); + std::cout << " byteswaiting " << byteswaiting << std::endl; + + return byteswaiting > 0; + } int FramebufferBackend::waitKeyEx(int delay) { std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; int code = 0; - char ch = getch_(0); + int ch = getch_(0); std::cout << "ch 1 " << (int)ch << std::endl; code = ch; - if(code == 27) + while(kbhit()) { ch = getch_(0); std::cout << "ch 2 " << (int)ch << std::endl; - // code = ch * 1000; - ch = getch_(0); - std::cout << "ch 2 " << (int)ch << std::endl; - // code += ch * 1000000; code = ch; } // struct input_event events; -// -// // ssize_t r = 1; // while(r > 0) // { diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index e450f85afd66..fdab797bc269 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -75,7 +75,8 @@ class CV_EXPORTS FramebufferBackend: public UIBackend void initTermios(int echo); void resetTermios(void); - char getch_(int echo); + int getch_(int echo); + bool kbhit(); public: FramebufferBackend(); From 516f2a6dbe5a3580a94b96ec5aaad4bdc8e525ac Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 18 Apr 2024 18:35:11 +0300 Subject: [PATCH 06/81] add x_offset --- modules/highgui/src/window_framebuffer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index ada190de3c33..1696768925b2 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -89,7 +89,7 @@ namespace cv { namespace highgui_backend { for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { std::memcpy(backgroundBuff.ptr(y - y_offset), - fbPointer + y * line_length, + fbPointer + y * line_length + x_offset, backgroundBuff.cols * cnt_channel); } @@ -104,7 +104,7 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length, + std::memcpy(fbPointer + y * line_length + x_offset, backgroundBuff.ptr(y - y_offset), backgroundBuff.cols*cnt_channel); } @@ -156,7 +156,7 @@ namespace cv { namespace highgui_backend { // RESTORE BACKGROUNG for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length, + std::memcpy(fbPointer + y * line_length + x_offset, backgroundBuff.ptr(y - y_offset), backgroundBuff.cols*cnt_channel); } @@ -166,7 +166,7 @@ namespace cv { namespace highgui_backend { // SHOW IMAGE for (int y = y_offset; y < img.rows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length, + std::memcpy(fbPointer + y * line_length + x_offset, img.ptr(y - y_offset), img.cols*cnt_channel); } From b1cfb7c0797dda5d6be77267688d8d35b441cb41 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 18 Apr 2024 19:28:09 +0300 Subject: [PATCH 07/81] comment temp code --- modules/highgui/src/window_framebuffer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 1696768925b2..c098097afc88 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -243,16 +243,16 @@ namespace cv { namespace highgui_backend { FramebufferBackend::FramebufferBackend() { - eventKey = OpenInputEvent(); - std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; + //eventKey = OpenInputEvent(); + //std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; } FramebufferBackend::~FramebufferBackend() { - if(eventKey != -1) - { - close(eventKey); - } + //if(eventKey != -1) + //{ + // close(eventKey); + //} } void FramebufferBackend::destroyAllWindows() { From d54fad685a170b37927897b1d33c18a49bea07c1 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 19 Apr 2024 19:15:33 +0300 Subject: [PATCH 08/81] fix arrow event add delay support --- modules/highgui/src/window_framebuffer.cpp | 97 ++++++++++++---------- modules/highgui/src/window_framebuffer.hpp | 4 +- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index c098097afc88..10ab3c304eb1 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -54,7 +54,16 @@ namespace cv { namespace highgui_backend { framebuffrer_id = fb_open_and_get_info(); std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; - if(framebuffrer_id == -1) return; + if(framebuffrer_id == -1){ + fb_w = 0; + fb_h = 0; + y_offset = 0; + x_offset = 0; + bpp = 0; + line_length = 0; + + return; + } fb_w = var_info.xres; fb_h = var_info.yres; @@ -268,13 +277,13 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } - void FramebufferBackend::initTermios(int echo) + void FramebufferBackend::initTermios(int echo, int wait) { tcgetattr(0, &old); /* grab old terminal i/o settings */ current = old; /* make new settings same as old settings */ current.c_lflag &= ~ICANON; /* disable buffered i/o */ current.c_lflag &= ~ISIG; - current.c_cc[VMIN]=1; + current.c_cc[VMIN]=wait; if (echo) { current.c_lflag |= ECHO; /* set echo mode */ } else { @@ -289,24 +298,25 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, &old); } - int FramebufferBackend::getch_(int echo) + int FramebufferBackend::getch_(int echo, int wait) { int ch; - initTermios(echo); + initTermios(echo, wait); ch = getchar(); + rewind(stdin); resetTermios(); return ch; } bool FramebufferBackend::kbhit() { int byteswaiting=0; - initTermios(0); + initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { std::cout << " ERR byteswaiting " << std::endl; } resetTermios(); - std::cout << " byteswaiting " << byteswaiting << std::endl; +// std::cout << " byteswaiting " << byteswaiting << std::endl; return byteswaiting > 0; } @@ -314,47 +324,48 @@ namespace cv { namespace highgui_backend { int FramebufferBackend::waitKeyEx(int delay) { std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; - int code = 0; - - int ch = getch_(0); - std::cout << "ch 1 " << (int)ch << std::endl; - code = ch; - - while(kbhit()) + int code = -1; + + if(delay == 0) { - ch = getch_(0); - std::cout << "ch 2 " << (int)ch << std::endl; + int ch = getch_(0, 1); + std::cout << "ch 1 " << (int)ch << std::endl; code = ch; + + while((ch = getch_(0, 0))>=0) + { + std::cout << "ch 2 " << (int)ch << std::endl; + code = ch; + } + } else { + if(delay > 0) + { + bool f_kbhit = false; + while(!(f_kbhit = kbhit()) && (delay > 0)) + { + delay -= 10; + usleep(10000); + } + if(f_kbhit) + { + std::cout << "f_kbhit " << true << std::endl; + + int ch = getch_(0, 1); + std::cout << "d ch 1 " << (int)ch << std::endl; + code = ch; + + while((ch = getch_(0, 0))>=0) + { + std::cout << "d ch 2 " << (int)ch << std::endl; + code = ch; + } + } + + } } + -// struct input_event events; -// ssize_t r = 1; -// while(r > 0) -// { -// std::cout << "while 1 " << std::endl; -// r = read(eventKey, &events, sizeof(input_event)); -// std::cout << "while 1 " << std::endl; -// } -// -// -// -// while((r == 0)&& ((delay > 1) || (delay == 0)) ) -// { -// delay--; -// usleep(1); -// r = read(eventKey, &events, sizeof(input_event)); -// std::cout << "while 2 " << std::endl; -// -// if(r != 0){ -// code = (events.code); -// } -// } -// std::cout << "waitKeyEx:: code "<< code << std::endl; -// -// if(r == 0) -// return -1; -// return code; } int FramebufferBackend::pollKey() { diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index fdab797bc269..5af1d55a7e44 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -73,9 +73,9 @@ class CV_EXPORTS FramebufferBackend: public UIBackend struct termios old, current; - void initTermios(int echo); + void initTermios(int echo, int wait); void resetTermios(void); - int getch_(int echo); + int getch_(int echo, int wait); bool kbhit(); public: From 78b8be6a354743570368bae34e306f68d74d1235 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 6 May 2024 09:18:05 +0300 Subject: [PATCH 09/81] fix create FB location and multiwindows support --- modules/highgui/src/window_framebuffer.cpp | 304 ++++++++++++--------- modules/highgui/src/window_framebuffer.hpp | 54 ++-- 2 files changed, 203 insertions(+), 155 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 10ab3c304eb1..a05c930e1b7c 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -22,162 +22,53 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } - int FramebufferWindow::fb_open_and_get_info() + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend): backend(_backend) { - int fb_fd = open("/dev/fb0", O_RDWR); - if (fb_fd == -1) - { - std::cerr << "ERROR_OPENING_FB\n"; - return -1; - } - - // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { - std::cerr << "ERROR_READING_FIX_INFO\n"; - return -1; - } - - // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { - std::cerr << "EERROR_READING_VAR_INFO\n"; - return -1; - } - - return fb_fd; - } - - - FramebufferWindow::FramebufferWindow() - { - std::cout << "FramebufferWindow()" << std::endl; FB_ID = "FramebufferWindow"; - framebuffrer_id = fb_open_and_get_info(); - std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; - - if(framebuffrer_id == -1){ - fb_w = 0; - fb_h = 0; - y_offset = 0; - x_offset = 0; - bpp = 0; - line_length = 0; - - return; - } - - fb_w = var_info.xres; - fb_h = var_info.yres; - y_offset = var_info.yoffset; - x_offset = var_info.xoffset; - bpp = var_info.bits_per_pixel; - line_length = fix_info.line_length; - std::cout << "= Framebuffer's width, height, bits per pix:\n" - << fb_w << " " << fb_h << " " << bpp << "\n\n"; - std::cout << "= Framebuffer's offsets, line length:\n" - << y_offset << " " << x_offset << " " << line_length << "\n\n"; - - // MAP FB TO MEMORY - screensize = max((__u32)fb_w, var_info.xres_virtual) * - max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; - fbPointer = (unsigned char*) - mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, - framebuffrer_id, 0); - if (fbPointer == MAP_FAILED) { - std::cerr << "ERROR_MAP\n"; - return; - } - - if(bpp != 32) { - std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; - return; - } - - backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); - int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) - { - std::memcpy(backgroundBuff.ptr(y - y_offset), - fbPointer + y * line_length + x_offset, - backgroundBuff.cols * cnt_channel); - } - + WindowRest = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); } FramebufferWindow::~FramebufferWindow(){ - - if(framebuffrer_id == -1) return; - - // RESTORE BACKGROUNG - int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) - { - std::memcpy(fbPointer + y * line_length + x_offset, - backgroundBuff.ptr(y - y_offset), - backgroundBuff.cols*cnt_channel); - } - - if (fbPointer != MAP_FAILED) { - munmap(fbPointer, screensize); - } - close(framebuffrer_id); } void FramebufferWindow::imshow(InputArray image){ std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; std::cout << "InputArray image:: size" << image.size() << std::endl; - if (fbPointer == MAP_FAILED) { + if (backend.getFBPointer() == MAP_FAILED) { return; } - if(bpp != 32) { - std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + if(backend.getFBbpp() != 32) { + std::cerr << "Bits per pixel " << backend.getFBbpp() << " is not supported" << std::endl; return; } Mat img; cvtColor(image, img, COLOR_RGB2RGBA); - // changing the image size to match the entered width - double aspect_ratio = static_cast(img.cols) / img.rows; - int new_width = fb_w; - int new_height = static_cast(fb_w / aspect_ratio); + int new_width = WindowRest.width; + int new_height = WindowRest.height; int cnt_channel = img.channels(); - //std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; - //std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; - //std::cout << "= Image count of channels:\n" << img.channels() << "\n"; - - // RECIZE IMAGE TO MATCH THE FB SIZE - if (new_width > fb_w || new_height > fb_h) { - if (aspect_ratio > static_cast(fb_w) / fb_h) { - new_width = fb_w; - new_height = static_cast(fb_w / aspect_ratio); - } else { - new_height = fb_h; - new_width = static_cast(fb_h * aspect_ratio); - } - } cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); std::cout << "= Recized image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + + // SHOW IMAGE + int x_offset = backend.getFBXOffset(); + int y_offset = backend.getFBYOffset(); + int line_length = backend.getFBLineLength(); - // RESTORE BACKGROUNG - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) - { - std::memcpy(fbPointer + y * line_length + x_offset, - backgroundBuff.ptr(y - y_offset), - backgroundBuff.cols*cnt_channel); - } - - + int showRows = min((WindowRest.y + img.rows), backend.getFBheight()) - WindowRest.y; + int showCols = min((WindowRest.x + img.cols), backend.getFBwidth()) - WindowRest.x; - // SHOW IMAGE - for (int y = y_offset; y < img.rows + y_offset; y++) + for (int y = y_offset; y < showRows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length + x_offset, + std::memcpy(backend.getFBPointer() + (y + WindowRest.y) * line_length + + x_offset + WindowRest.x, img.ptr(y - y_offset), - img.cols*cnt_channel); + showCols*cnt_channel); } @@ -194,14 +85,18 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height){ std::cout << "FramebufferWindow::resize(int width "<< width <<", int height "<< height <<")" << std::endl; + WindowRest.width = width; + WindowRest.height = height; } void FramebufferWindow::move(int x, int y) { std::cout << "FramebufferWindow::move(int x "<< x <<", int y "<< y <<")" << std::endl; + WindowRest.x = x; + WindowRest.y = y; } Rect FramebufferWindow::getImageRect() const { std::cout << "FramebufferWindow::getImageRect()" << std::endl; - return Rect(10,10,100,100); + return WindowRest; } void FramebufferWindow::setTitle(const std::string& title) { @@ -250,18 +145,156 @@ namespace cv { namespace highgui_backend { } +// !!##FramebufferBackend + + int FramebufferBackend::fb_open_and_get_info() + { + int fb_fd = open("/dev/fb0", O_RDWR); + if (fb_fd == -1) + { + std::cerr << "ERROR_OPENING_FB\n"; + return -1; + } + + // Get fixed screen information + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { + std::cerr << "ERROR_READING_FIX_INFO\n"; + return -1; + } + + // Get variable screen information + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { + std::cerr << "EERROR_READING_VAR_INFO\n"; + return -1; + } + + return fb_fd; + } + + fb_var_screeninfo &FramebufferBackend::getVarInfo() + { + return var_info; + } + fb_fix_screeninfo &FramebufferBackend::getFixInfo() + { + return fix_info; + } + int FramebufferBackend::getFramebuffrerID() + { + return framebuffrer_id; + } + int FramebufferBackend::getFBwidth() + { + return fb_w; + } + int FramebufferBackend::getFBheight() + { + return fb_h; + } + int FramebufferBackend::getFBXOffset() + { + return x_offset; + } + int FramebufferBackend::getFBYOffset() + { + return y_offset; + } + int FramebufferBackend::getFBbpp() + { + return bpp; + } + int FramebufferBackend::getFBLineLength() + { + return line_length; + } + unsigned char* FramebufferBackend::getFBPointer() + { + return fbPointer; + } + Mat& FramebufferBackend::getBackgroundBuff() + { + return backgroundBuff; + } + + + + + FramebufferBackend::FramebufferBackend() { - //eventKey = OpenInputEvent(); - //std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; + std::cout << "FramebufferBackend()" << std::endl; + framebuffrer_id = fb_open_and_get_info(); + std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + + if(framebuffrer_id == -1){ + fb_w = 0; + fb_h = 0; + y_offset = 0; + x_offset = 0; + bpp = 0; + line_length = 0; + + return; + } + + fb_w = var_info.xres; + fb_h = var_info.yres; + y_offset = var_info.yoffset; + x_offset = var_info.xoffset; + bpp = var_info.bits_per_pixel; + line_length = fix_info.line_length; + + std::cout << "= Framebuffer's width, height, bits per pix:\n" + << fb_w << " " << fb_h << " " << bpp << "\n\n"; + std::cout << "= Framebuffer's offsets, line length:\n" + << y_offset << " " << x_offset << " " << line_length << "\n\n"; + + // MAP FB TO MEMORY + screensize = max((__u32)fb_w, var_info.xres_virtual) * + max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; + fbPointer = (unsigned char*) + mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, + framebuffrer_id, 0); + if (fbPointer == MAP_FAILED) { + std::cerr << "ERROR_MAP\n"; + return; + } + + if(bpp != 32) { + std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + return; + } + + backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(backgroundBuff.ptr(y - y_offset), + fbPointer + y * line_length + x_offset, + backgroundBuff.cols * cnt_channel); + } + + } FramebufferBackend::~FramebufferBackend() { - //if(eventKey != -1) - //{ - // close(eventKey); - //} + if(framebuffrer_id == -1) return; + + // RESTORE BACKGROUNG + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length + x_offset, + backgroundBuff.ptr(y - y_offset), + backgroundBuff.cols*cnt_channel); + } + + if (fbPointer != MAP_FAILED) { + munmap(fbPointer, screensize); + } + close(framebuffrer_id); + } void FramebufferBackend::destroyAllWindows() { @@ -274,7 +307,7 @@ namespace cv { namespace highgui_backend { int flags ){ std::cout << "FramebufferBackend::createWindow("<< winname <<", "<(); + return std::make_shared(*this); } void FramebufferBackend::initTermios(int echo, int wait) @@ -316,7 +349,6 @@ namespace cv { namespace highgui_backend { std::cout << " ERR byteswaiting " << std::endl; } resetTermios(); -// std::cout << " byteswaiting " << byteswaiting << std::endl; return byteswaiting > 0; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 5af1d55a7e44..ba7aa2699388 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -11,29 +11,15 @@ namespace cv { namespace highgui_backend { +class FramebufferBackend; class CV_EXPORTS FramebufferWindow : public UIWindow { - fb_var_screeninfo var_info; - fb_fix_screeninfo fix_info; - + FramebufferBackend &backend; std::string FB_ID; - - int fb_open_and_get_info(); - int framebuffrer_id; - - int fb_w; - int fb_h; - int y_offset; - int x_offset; - int bpp; - int line_length; - long int screensize; - unsigned char* fbPointer; - - Mat backgroundBuff; - + Rect WindowRest; + public: - FramebufferWindow(); + FramebufferWindow(FramebufferBackend &backend); virtual ~FramebufferWindow(); virtual void imshow(InputArray image)override; @@ -77,8 +63,38 @@ class CV_EXPORTS FramebufferBackend: public UIBackend void resetTermios(void); int getch_(int echo, int wait); bool kbhit(); + + fb_var_screeninfo var_info; + fb_fix_screeninfo fix_info; + int fb_w; + int fb_h; + int y_offset; + int x_offset; + int bpp; + int line_length; + long int screensize; + unsigned char* fbPointer; + Mat backgroundBuff; + + + int fb_open_and_get_info(); + int framebuffrer_id; + public: + + fb_var_screeninfo &getVarInfo(); + fb_fix_screeninfo &getFixInfo(); + int getFramebuffrerID(); + int getFBwidth(); + int getFBheight(); + int getFBXOffset(); + int getFBYOffset(); + int getFBbpp(); + int getFBLineLength(); + unsigned char* getFBPointer(); + Mat& getBackgroundBuff(); + FramebufferBackend(); virtual ~FramebufferBackend(); From 49468ff36df1c22e1809125ace35ebb09dd32f68 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 6 May 2024 19:23:08 +0300 Subject: [PATCH 10/81] fix name --- modules/highgui/src/window_framebuffer.cpp | 28 +++++++++++----------- modules/highgui/src/window_framebuffer.hpp | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index a05c930e1b7c..d5f37e2ed5e9 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -26,7 +26,7 @@ namespace cv { namespace highgui_backend { { FB_ID = "FramebufferWindow"; - WindowRest = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); + windowRect = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); } @@ -47,8 +47,8 @@ namespace cv { namespace highgui_backend { Mat img; cvtColor(image, img, COLOR_RGB2RGBA); - int new_width = WindowRest.width; - int new_height = WindowRest.height; + int new_width = windowRect.width; + int new_height = windowRect.height; int cnt_channel = img.channels(); cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); @@ -60,13 +60,13 @@ namespace cv { namespace highgui_backend { int y_offset = backend.getFBYOffset(); int line_length = backend.getFBLineLength(); - int showRows = min((WindowRest.y + img.rows), backend.getFBheight()) - WindowRest.y; - int showCols = min((WindowRest.x + img.cols), backend.getFBwidth()) - WindowRest.x; + int showRows = min((windowRect.y + img.rows), backend.getFBheight()) - windowRect.y; + int showCols = min((windowRect.x + img.cols), backend.getFBwidth()) - windowRect.x; for (int y = y_offset; y < showRows + y_offset; y++) { - std::memcpy(backend.getFBPointer() + (y + WindowRest.y) * line_length + - x_offset + WindowRest.x, + std::memcpy(backend.getFBPointer() + (y + windowRect.y) * line_length + + x_offset + windowRect.x, img.ptr(y - y_offset), showCols*cnt_channel); } @@ -85,18 +85,18 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height){ std::cout << "FramebufferWindow::resize(int width "<< width <<", int height "<< height <<")" << std::endl; - WindowRest.width = width; - WindowRest.height = height; + windowRect.width = width; + windowRect.height = height; } void FramebufferWindow::move(int x, int y) { std::cout << "FramebufferWindow::move(int x "<< x <<", int y "<< y <<")" << std::endl; - WindowRest.x = x; - WindowRest.y = y; + windowRect.x = x; + windowRect.y = y; } Rect FramebufferWindow::getImageRect() const { std::cout << "FramebufferWindow::getImageRect()" << std::endl; - return WindowRest; + return windowRect; } void FramebufferWindow::setTitle(const std::string& title) { @@ -281,7 +281,7 @@ namespace cv { namespace highgui_backend { { if(framebuffrer_id == -1) return; - // RESTORE BACKGROUNG + // RectORE BACKGROUNG int cnt_channel = 4; for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { @@ -325,7 +325,7 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ } - /* Restore old terminal i/o settings */ + /* Rectore old terminal i/o settings */ void FramebufferBackend::resetTermios(void) { tcsetattr(0, TCSANOW, &old); diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index ba7aa2699388..65f1d8d0916a 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -16,7 +16,7 @@ class CV_EXPORTS FramebufferWindow : public UIWindow { FramebufferBackend &backend; std::string FB_ID; - Rect WindowRest; + Rect windowRect; public: FramebufferWindow(FramebufferBackend &backend); From fb1b36bacbad54124e9096dfad0c581a9611142b Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 15:31:19 +0300 Subject: [PATCH 11/81] code refactoring: renaming variables, stdout -> OpenCV LOG system --- CMakeLists.txt | 9 +- modules/highgui/CMakeLists.txt | 3 - modules/highgui/src/window_framebuffer.cpp | 308 +++++++++++---------- modules/highgui/src/window_framebuffer.hpp | 28 +- 4 files changed, 187 insertions(+), 161 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eca47cdd1ee2..b7c34f30b1e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,10 +297,9 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_GTK AND NOT HAVE_GTK3) - OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF - VISIBLE_IF UNIX VERIFY HAVE_FRAMEBUFFER) - + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID + VERIFY HAVE_FRAMEBUFFER) OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_WAYLAND) @@ -1426,6 +1425,10 @@ if(WITH_GTK OR HAVE_GTK) endif() endif() +if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER) + status(" Framebuffer UI:" "YES") +endif() + if(WITH_OPENGL OR HAVE_OPENGL) status(" OpenGL support:" HAVE_OPENGL THEN "YES (${OPENGL_LIBRARIES})" ELSE NO) endif() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 82cb44bbdf0f..d4b0a7ff0548 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -41,12 +41,9 @@ endif() if(WITH_FRAMEBUFFER) - message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") add_definitions(-DHAVE_FRAMEBUFFER) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) -else() - message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") endif() diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index d5f37e2ed5e9..4fddfabc8fa4 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -24,24 +24,30 @@ namespace cv { namespace highgui_backend { FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend): backend(_backend) { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; - - windowRect = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); - + windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); } - FramebufferWindow::~FramebufferWindow(){ + FramebufferWindow::~FramebufferWindow() + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); } - void FramebufferWindow::imshow(InputArray image){ - std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; - std::cout << "InputArray image:: size" << image.size() << std::endl; + void FramebufferWindow::imshow(InputArray image) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); + CV_LOG_INFO(NULL, "UI: InputArray image: " + << cv::typeToString(image.type()) << " size " << image.size()); + if (backend.getFBPointer() == MAP_FAILED) { - return; + CV_LOG_WARNING(NULL, "UI: Framebuffer is not mapped"); + return; } - if(backend.getFBbpp() != 32) { - std::cerr << "Bits per pixel " << backend.getFBbpp() << " is not supported" << std::endl; + if(backend.getFBBitsPerPixel() != 32) { + CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " + << backend.getFBBitsPerPixel() << " is not supported" ); return; } @@ -53,86 +59,106 @@ namespace cv { namespace highgui_backend { cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); - std::cout << "= Recized image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + CV_LOG_INFO(NULL, "UI: Formated image: " + << cv::typeToString(img.type()) << " size " << img.size()); // SHOW IMAGE - int x_offset = backend.getFBXOffset(); - int y_offset = backend.getFBYOffset(); - int line_length = backend.getFBLineLength(); + int xOffset = backend.getFBXOffset(); + int yOffset = backend.getFBYOffset(); + int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBheight()) - windowRect.y; - int showCols = min((windowRect.x + img.cols), backend.getFBwidth()) - windowRect.x; + int showRows = min((windowRect.y + img.rows), backend.getFBHeight()) - windowRect.y; + int showCols = min((windowRect.x + img.cols), backend.getFBWidth()) - windowRect.x; - for (int y = y_offset; y < showRows + y_offset; y++) + for (int y = yOffset; y < showRows + yOffset; y++) { - std::memcpy(backend.getFBPointer() + (y + windowRect.y) * line_length + - x_offset + windowRect.x, - img.ptr(y - y_offset), - showCols*cnt_channel); + std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + + xOffset + windowRect.x, + img.ptr(y - yOffset), + showCols * cnt_channel); } - - } - double FramebufferWindow::getProperty(int prop) const{ - std::cout << "FramebufferWindow::getProperty(int prop:" << prop <<")"<< std::endl; + double FramebufferWindow::getProperty(int prop) const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); return 0.0; } - bool FramebufferWindow::setProperty(int prop, double value) { - std::cout << "FramebufferWindow::setProperty(int prop "<< prop <<", double value "< FramebufferWindow::createTrackbar( const std::string& name, int count, TrackbarCallback onChange, - void* userdata - ){ + void* userdata) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); return nullptr; } - std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name){ + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); return nullptr; } - const std::string& FramebufferWindow::getID() const { - std::cout << "getID())" << std::endl; return FB_ID; + const std::string& FramebufferWindow::getID() const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); + return FB_ID; } - bool FramebufferWindow::isActive() const { - std::cout << "isActive()" << std::endl; + bool FramebufferWindow::isActive() const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); return true; } - void FramebufferWindow::destroy() { - std::cout << "destroy()" << std::endl; + void FramebufferWindow::destroy() + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } +// !!##FramebufferBackend + int FramebufferBackend::OpenInputEvent() { int fd; @@ -144,27 +170,24 @@ namespace cv { namespace highgui_backend { return fd; } - -// !!##FramebufferBackend - - int FramebufferBackend::fb_open_and_get_info() + int FramebufferBackend::fbOpenAndGetInfo() { int fb_fd = open("/dev/fb0", O_RDWR); if (fb_fd == -1) { - std::cerr << "ERROR_OPENING_FB\n"; + CV_LOG_WARNING(NULL, "UI: can't open framebuffer"); return -1; } // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { - std::cerr << "ERROR_READING_FIX_INFO\n"; - return -1; + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { + CV_LOG_WARNING(NULL, "UI: can't read fix info for framebuffer"); + return -1; } // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { - std::cerr << "EERROR_READING_VAR_INFO\n"; + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { + CV_LOG_WARNING(NULL, "UI: can't read var info for framebuffer"); return -1; } @@ -173,39 +196,39 @@ namespace cv { namespace highgui_backend { fb_var_screeninfo &FramebufferBackend::getVarInfo() { - return var_info; + return varInfo; } fb_fix_screeninfo &FramebufferBackend::getFixInfo() { - return fix_info; + return fixInfo; } int FramebufferBackend::getFramebuffrerID() { - return framebuffrer_id; + return fbID; } - int FramebufferBackend::getFBwidth() + int FramebufferBackend::getFBWidth() { - return fb_w; + return fbWidth; } - int FramebufferBackend::getFBheight() + int FramebufferBackend::getFBHeight() { - return fb_h; + return fbHeight; } int FramebufferBackend::getFBXOffset() { - return x_offset; + return fbXOffset; } int FramebufferBackend::getFBYOffset() { - return y_offset; + return fbYOffset; } - int FramebufferBackend::getFBbpp() + int FramebufferBackend::getFBBitsPerPixel() { - return bpp; + return fbBitsPerPixel; } int FramebufferBackend::getFBLineLength() { - return line_length; + return fbLineLength; } unsigned char* FramebufferBackend::getFBPointer() { @@ -216,116 +239,115 @@ namespace cv { namespace highgui_backend { return backgroundBuff; } - - - - FramebufferBackend::FramebufferBackend() { - std::cout << "FramebufferBackend()" << std::endl; - framebuffrer_id = fb_open_and_get_info(); - std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); + fbID = fbOpenAndGetInfo(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - if(framebuffrer_id == -1){ - fb_w = 0; - fb_h = 0; - y_offset = 0; - x_offset = 0; - bpp = 0; - line_length = 0; - + if(fbID == -1){ + fbWidth = 0; + fbHeight = 0; + fbXOffset = 0; + fbYOffset = 0; + fbBitsPerPixel = 0; + fbLineLength = 0; return; } - fb_w = var_info.xres; - fb_h = var_info.yres; - y_offset = var_info.yoffset; - x_offset = var_info.xoffset; - bpp = var_info.bits_per_pixel; - line_length = fix_info.line_length; + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.yoffset; + fbYOffset = varInfo.xoffset; + fbBitsPerPixel = varInfo.bits_per_pixel; + fbLineLength = fixInfo.line_length; - std::cout << "= Framebuffer's width, height, bits per pix:\n" - << fb_w << " " << fb_h << " " << bpp << "\n\n"; - std::cout << "= Framebuffer's offsets, line length:\n" - << y_offset << " " << x_offset << " " << line_length << "\n\n"; + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + << fbXOffset << " " << fbYOffset << " " << fbLineLength); // MAP FB TO MEMORY - screensize = max((__u32)fb_w, var_info.xres_virtual) * - max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; + fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * + max((__u32)fbHeight, varInfo.yres_virtual) * + fbBitsPerPixel / 8; + fbPointer = (unsigned char*) - mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, - framebuffrer_id, 0); + mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, + fbID, 0); + if (fbPointer == MAP_FAILED) { - std::cerr << "ERROR_MAP\n"; - return; + CV_LOG_WARNING(NULL, "UI: can't mmap framebuffer"); + return; } - if(bpp != 32) { - std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + if(fbBitsPerPixel != 32) { + CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " + << fbBitsPerPixel << " is not supported" ); return; } - backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); + backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - y_offset), - fbPointer + y * line_length + x_offset, - backgroundBuff.cols * cnt_channel); + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + fbPointer + y * fbLineLength + fbXOffset, + backgroundBuff.cols * cnt_channel); } - - } FramebufferBackend::~FramebufferBackend() { - if(framebuffrer_id == -1) return; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); + if(fbID == -1) return; - // RectORE BACKGROUNG + // RESTORE BACKGROUNG int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(fbPointer + y * line_length + x_offset, - backgroundBuff.ptr(y - y_offset), - backgroundBuff.cols*cnt_channel); + std::memcpy(fbPointer + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); } if (fbPointer != MAP_FAILED) { - munmap(fbPointer, screensize); + munmap(fbPointer, fbScreenSize); } - close(framebuffrer_id); + close(fbID); } void FramebufferBackend::destroyAllWindows() { - std::cout << "destroyAllWindows()" << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); } // namedWindow std::shared_ptr FramebufferBackend::createWindow( const std::string& winname, - int flags - ){ - std::cout << "FramebufferBackend::createWindow("<< winname <<", "<(*this); } void FramebufferBackend::initTermios(int echo, int wait) { - tcgetattr(0, &old); /* grab old terminal i/o settings */ - current = old; /* make new settings same as old settings */ - current.c_lflag &= ~ICANON; /* disable buffered i/o */ + tcgetattr(0, &old); // grab old terminal i/o settings + current = old; // make new settings same as old settings + current.c_lflag &= ~ICANON; // disable buffered i/o current.c_lflag &= ~ISIG; current.c_cc[VMIN]=wait; if (echo) { - current.c_lflag |= ECHO; /* set echo mode */ + current.c_lflag |= ECHO; // set echo mode } else { - current.c_lflag &= ~ECHO; /* set no echo mode */ + current.c_lflag &= ~ECHO; // set no echo mode } - tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ + tcsetattr(0, TCSANOW, ¤t); // use these new terminal i/o settings now } - /* Rectore old terminal i/o settings */ void FramebufferBackend::resetTermios(void) { tcsetattr(0, TCSANOW, &old); @@ -336,7 +358,7 @@ namespace cv { namespace highgui_backend { int ch; initTermios(echo, wait); ch = getchar(); - rewind(stdin); + if(ch < 0) rewind(stdin); resetTermios(); return ch; } @@ -346,27 +368,29 @@ namespace cv { namespace highgui_backend { initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { - std::cout << " ERR byteswaiting " << std::endl; + CV_LOG_WARNING(NULL, "UI: Framebuffer ERR byteswaiting" ); } resetTermios(); return byteswaiting > 0; } - int FramebufferBackend::waitKeyEx(int delay) { - std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; + int FramebufferBackend::waitKeyEx(int delay) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); int code = -1; if(delay == 0) { int ch = getch_(0, 1); - std::cout << "ch 1 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; while((ch = getch_(0, 0))>=0) { - std::cout << "ch 2 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; } } else { @@ -380,15 +404,16 @@ namespace cv { namespace highgui_backend { } if(f_kbhit) { - std::cout << "f_kbhit " << true << std::endl; - + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + int ch = getch_(0, 1); - std::cout << "d ch 1 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; while((ch = getch_(0, 0))>=0) { - std::cout << "d ch 2 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; } } @@ -396,12 +421,13 @@ namespace cv { namespace highgui_backend { } } - - std::cout << "waitKeyEx:: code "<< code << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); return code; } - int FramebufferBackend::pollKey() { - std::cout << "FramebufferBackend::pollKey()" << std::endl; + + int FramebufferBackend::pollKey() + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); return 0; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 65f1d8d0916a..3a34ea2f54e3 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -65,32 +65,32 @@ class CV_EXPORTS FramebufferBackend: public UIBackend bool kbhit(); - fb_var_screeninfo var_info; - fb_fix_screeninfo fix_info; - int fb_w; - int fb_h; - int y_offset; - int x_offset; - int bpp; - int line_length; - long int screensize; + fb_var_screeninfo varInfo; + fb_fix_screeninfo fixInfo; + int fbWidth; + int fbHeight; + int fbXOffset; + int fbYOffset; + int fbBitsPerPixel; + int fbLineLength; + long int fbScreenSize; unsigned char* fbPointer; Mat backgroundBuff; - int fb_open_and_get_info(); - int framebuffrer_id; + int fbOpenAndGetInfo(); + int fbID; public: fb_var_screeninfo &getVarInfo(); fb_fix_screeninfo &getFixInfo(); int getFramebuffrerID(); - int getFBwidth(); - int getFBheight(); + int getFBWidth(); + int getFBHeight(); int getFBXOffset(); int getFBYOffset(); - int getFBbpp(); + int getFBBitsPerPixel(); int getFBLineLength(); unsigned char* getFBPointer(); Mat& getBackgroundBuff(); From e3c702a679a3244e7b9c0b260f4c92a3aee96894 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 18:19:27 +0300 Subject: [PATCH 12/81] add env varibale for FB dev --- modules/highgui/src/window_framebuffer.cpp | 47 +++++++++++++++++----- modules/highgui/src/window_framebuffer.hpp | 4 +- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 4fddfabc8fa4..bf159bfed4ba 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -1,6 +1,13 @@ #include "window_framebuffer.hpp" -#include "opencv2/core/utils/logger.hpp" +#include +#include +#ifdef NDEBUG +#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG + 1 +#else +#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE + 1 +#endif +#include #include #include @@ -159,20 +166,38 @@ namespace cv { namespace highgui_backend { // !!##FramebufferBackend - int FramebufferBackend::OpenInputEvent() - { - int fd; - fd = open("/dev/input/event1", O_RDONLY); - if (fd == -1) { - std::cerr << "ERROR_OPENING_INPUT\n"; - return -1; - } - return fd; +// int FramebufferBackend::OpenInputEvent() +// { +// int fd; +// fd = open("/dev/input/event1", O_RDONLY); +// if (fd == -1) { +// std::cerr << "ERROR_OPENING_INPUT\n"; +// return -1; +// } +// return fd; +// } + + static + std::string& getFBFileName() + { + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FRAMEBUFFER", ""); + static std::string fbFileNameDef = "/dev/fb0"; + + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if(!fbFileNameFB.empty()) return fbFileNameFB; + return fbFileNameDef; } + int FramebufferBackend::fbOpenAndGetInfo() { - int fb_fd = open("/dev/fb0", O_RDWR); + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { CV_LOG_WARNING(NULL, "UI: can't open framebuffer"); diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 3a34ea2f54e3..ffa422814e8b 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -54,8 +54,8 @@ class CV_EXPORTS FramebufferWindow : public UIWindow class CV_EXPORTS FramebufferBackend: public UIBackend { - int OpenInputEvent(); - int eventKey; +// int OpenInputEvent(); +// int eventKey; struct termios old, current; From 9b5489876973fc7636023f816d465d15b32fa10d Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 18:37:02 +0300 Subject: [PATCH 13/81] imp. log --- modules/highgui/src/window_framebuffer.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index bf159bfed4ba..a5bba09b06a6 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -48,12 +48,12 @@ namespace cv { namespace highgui_backend { << cv::typeToString(image.type()) << " size " << image.size()); if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_WARNING(NULL, "UI: Framebuffer is not mapped"); + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } if(backend.getFBBitsPerPixel() != 32) { - CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " + CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " << backend.getFBBitsPerPixel() << " is not supported" ); return; } @@ -89,12 +89,16 @@ namespace cv { namespace highgui_backend { double FramebufferWindow::getProperty(int prop) const { CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); + CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + return 0.0; } bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " << prop << ", value " << value << ")"); + CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + return false; } @@ -121,6 +125,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::setTitle(const std::string& title) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); + CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } void FramebufferWindow::setMouseCallback(MouseCallback onMouse, void* userdata ) @@ -200,19 +205,19 @@ namespace cv { namespace highgui_backend { int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { - CV_LOG_WARNING(NULL, "UI: can't open framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); return -1; } // Get fixed screen information if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { - CV_LOG_WARNING(NULL, "UI: can't read fix info for framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; } // Get variable screen information if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { - CV_LOG_WARNING(NULL, "UI: can't read var info for framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } @@ -303,7 +308,7 @@ namespace cv { namespace highgui_backend { fbID, 0); if (fbPointer == MAP_FAILED) { - CV_LOG_WARNING(NULL, "UI: can't mmap framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); return; } @@ -393,7 +398,7 @@ namespace cv { namespace highgui_backend { initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { - CV_LOG_WARNING(NULL, "UI: Framebuffer ERR byteswaiting" ); + CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); } resetTermios(); From 346a30110401ff6dd6e66a70c7c3fdf6721cf6a7 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 20:44:38 +0300 Subject: [PATCH 14/81] Added conditions for FB format. Added image reformatting functionality --- modules/highgui/src/window_framebuffer.cpp | 51 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index a5bba09b06a6..196611908659 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -57,14 +57,34 @@ namespace cv { namespace highgui_backend { << backend.getFBBitsPerPixel() << " is not supported" ); return; } + + Mat img(image.getMat()); + switch(img.channels()){ + case 1: + if(img.type() == CV_8UC1) + { + cvtColor(img, img, cv::COLOR_GRAY2RGB); + } + else + { + CV_LOG_ERROR(NULL, "UI: Image type " + << cv::typeToString(image.type()) << " is not supported" ); + } + break; + case 3: + convertToShow(img, img); + break; + case 4: + convertToShow(img, img, true); + break; + } + cvtColor(img, img, COLOR_RGB2BGRA); - Mat img; - cvtColor(image, img, COLOR_RGB2RGBA); - int new_width = windowRect.width; - int new_height = windowRect.height; - int cnt_channel = img.channels(); + int newWidth = windowRect.width; + int newHeight = windowRect.height; + int cntChannel = img.channels(); - cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -82,7 +102,7 @@ namespace cv { namespace highgui_backend { std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + xOffset + windowRect.x, img.ptr(y - yOffset), - showCols * cnt_channel); + showCols * cntChannel); } } @@ -220,6 +240,23 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } + + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" + << " green offset " << varInfo.green.offset << " length " << varInfo.green.length << "\n" + << " blue offset " << varInfo.blue.offset << " length " << varInfo.blue.length << "\n" + << "transp offset " << varInfo.transp.offset << " length " < Date: Sun, 12 May 2024 09:43:17 +0000 Subject: [PATCH 15/81] fix test --- modules/highgui/src/window_framebuffer.cpp | 1 + modules/highgui/test/test_gui.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 196611908659..c781311cce54 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -69,6 +69,7 @@ namespace cv { namespace highgui_backend { { CV_LOG_ERROR(NULL, "UI: Image type " << cv::typeToString(image.type()) << " is not supported" ); + return; } break; case 3: diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index de40e80ede7d..6580cf1c92cb 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -70,6 +70,9 @@ TEST(Highgui_GUI, regression) EXPECT_NO_THROW(destroyAllWindows()); ASSERT_NO_THROW(namedWindow(window_name)); +#if defined HAVE_FRAMEBUFFER + ASSERT_NO_THROW(resizeWindow(window_name, 800, 600)); +#endif const vector channels = {1, 3, 4}; const vector depths = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32F, CV_64F}; for(int cn : channels) @@ -138,7 +141,8 @@ static void Foo(int, void* counter) && !defined HAVE_WIN32UI \ && !defined HAVE_WAYLAND \ ) \ - || defined(__APPLE__) // test fails on Mac (cocoa) + || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar_unsafe) #else TEST(Highgui_GUI, trackbar_unsafe) @@ -178,7 +182,8 @@ void testTrackbarCallback(int pos, void* param) && !defined HAVE_WIN32UI \ && !defined HAVE_WAYLAND \ ) \ - || defined(__APPLE__) // test fails on Mac (cocoa) + || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar) #else TEST(Highgui_GUI, trackbar) From 439581b5ac85e2804d238cc8c86d538ea18dc781 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 20 May 2024 14:16:54 +0300 Subject: [PATCH 16/81] add Window flags support. add gs format for img. fix register FB name. --- modules/highgui/src/registry.impl.hpp | 2 +- modules/highgui/src/window_framebuffer.cpp | 162 ++++++++++++++++----- modules/highgui/src/window_framebuffer.hpp | 7 +- modules/highgui/test/test_gui.cpp | 3 - 4 files changed, 135 insertions(+), 39 deletions(-) diff --git a/modules/highgui/src/registry.impl.hpp b/modules/highgui/src/registry.impl.hpp index 956cb969c901..94ee9e9cde4b 100644 --- a/modules/highgui/src/registry.impl.hpp +++ b/modules/highgui/src/registry.impl.hpp @@ -45,7 +45,7 @@ std::vector& getBuiltinBackendsInfo() #endif #ifdef HAVE_FRAMEBUFFER - DECLARE_STATIC_BACKEND("Framebuffer", createUIBackendFramebuffer) + DECLARE_STATIC_BACKEND("FB", createUIBackendFramebuffer) #endif diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index c781311cce54..deb663dbd5e2 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -29,7 +29,8 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend): backend(_backend) + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + backend(_backend), flags(_flags) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; @@ -43,9 +44,16 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::imshow(InputArray image) { + currentImg = image.getMat(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " << cv::typeToString(image.type()) << " size " << image.size()); + + if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) + { + return; + } if (backend.getFBPointer() == MAP_FAILED) { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); @@ -61,16 +69,23 @@ namespace cv { namespace highgui_backend { Mat img(image.getMat()); switch(img.channels()){ case 1: - if(img.type() == CV_8UC1) + switch(img.type()) { - cvtColor(img, img, cv::COLOR_GRAY2RGB); - } - else - { - CV_LOG_ERROR(NULL, "UI: Image type " - << cv::typeToString(image.type()) << " is not supported" ); - return; + case CV_8S: + cv::convertScaleAbs(img, img, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, img, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, img, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(img, CV_8U, 255., 0.); + break; } + cvtColor(img, img, cv::COLOR_GRAY2RGB); break; case 3: convertToShow(img, img); @@ -84,8 +99,47 @@ namespace cv { namespace highgui_backend { int newWidth = windowRect.width; int newHeight = windowRect.height; int cntChannel = img.channels(); + cv::Size imgSize = currentImg.size(); + + switch(flags) + { + case WINDOW_FREERATIO: + { + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + break; + case WINDOW_AUTOSIZE: // WINDOW_FULLSCREEN + { + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + } + break; +// case WINDOW_FULLSCREEN: +// windowRect.width = backend.getFBWidth(); +// windowRect.height = backend.getFBHeight(); +// newWidth = windowRect.width; +// newHeight = windowRect.height; +// cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); +// break; + case WINDOW_NORMAL: // WINDOW_KEEPRATIO + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); + + if (newHeight > windowRect.height) { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; + } + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + break; + + default: + CV_LOG_ERROR(NULL, "UI: FB window flag not supported"); + CV_Assert(0); + } - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -95,14 +149,30 @@ namespace cv { namespace highgui_backend { int yOffset = backend.getFBYOffset(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight()) - windowRect.y; - int showCols = min((windowRect.x + img.cols), backend.getFBWidth()) - windowRect.x; + int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); + int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); + + int dx_w = windowRect.x; + int dy_w = windowRect.y; + + int start_y_w = 0; + int start_x_w = 0; + + if(dy_w < 0) start_y_w = -dy_w; + if(dx_w < 0) start_x_w = -dx_w; + + if(dy_w < 0) dy_w = 0; + if(dx_w < 0) dx_w = 0; + + showRows -= dy_w; + showCols -= dx_w; + for (int y = yOffset; y < showRows + yOffset; y++) { std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + xOffset + windowRect.x, - img.ptr(y - yOffset), + img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, showCols * cntChannel); } } @@ -127,14 +197,32 @@ namespace cv { namespace highgui_backend { { CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " << width <<", height " << height << ")"); - windowRect.width = width; - windowRect.height = height; + + CV_Assert(width > 0); + CV_Assert(height > 0); + + if(flags != WINDOW_AUTOSIZE) + { + windowRect.width = width; + windowRect.height = height; + + if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + { + imshow(currentImg); + } + } } void FramebufferWindow::move(int x, int y) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); + windowRect.x = x; windowRect.y = y; + + if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + { + imshow(currentImg); + } } Rect FramebufferWindow::getImageRect() const @@ -192,19 +280,7 @@ namespace cv { namespace highgui_backend { // !!##FramebufferBackend -// int FramebufferBackend::OpenInputEvent() -// { -// int fd; -// fd = open("/dev/input/event1", O_RDONLY); -// if (fd == -1) { -// std::cerr << "ERROR_OPENING_INPUT\n"; -// return -1; -// } -// return fd; -// } - - static - std::string& getFBFileName() + static std::string& getFBFileName() { static std::string fbFileNameFB = cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); @@ -398,7 +474,7 @@ namespace cv { namespace highgui_backend { { CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" << winname << ", " << flags << ")"); - return std::make_shared(*this); + return std::make_shared(*this, flags); } void FramebufferBackend::initTermios(int echo, int wait) @@ -449,7 +525,7 @@ namespace cv { namespace highgui_backend { int code = -1; - if(delay == 0) + if(delay <= 0) { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); @@ -467,8 +543,8 @@ namespace cv { namespace highgui_backend { bool f_kbhit = false; while(!(f_kbhit = kbhit()) && (delay > 0)) { - delay -= 10; - usleep(10000); + delay -= 1; + usleep(1000); } if(f_kbhit) { @@ -496,7 +572,27 @@ namespace cv { namespace highgui_backend { int FramebufferBackend::pollKey() { CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); - return 0; + int code = -1; + bool f_kbhit = false; + f_kbhit = kbhit(); + + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } + + return code; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index ffa422814e8b..a076f4e97ed4 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -17,9 +17,12 @@ class CV_EXPORTS FramebufferWindow : public UIWindow FramebufferBackend &backend; std::string FB_ID; Rect windowRect; + + int flags; + Mat currentImg; public: - FramebufferWindow(FramebufferBackend &backend); + FramebufferWindow(FramebufferBackend &backend, int flags); virtual ~FramebufferWindow(); virtual void imshow(InputArray image)override; @@ -105,7 +108,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend virtual std::shared_ptr createWindow( const std::string& winname, int flags - ); + )override; virtual int waitKeyEx(int delay /*= 0*/)override; virtual int pollKey() override; diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index 6580cf1c92cb..eed4e202ae17 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -70,9 +70,6 @@ TEST(Highgui_GUI, regression) EXPECT_NO_THROW(destroyAllWindows()); ASSERT_NO_THROW(namedWindow(window_name)); -#if defined HAVE_FRAMEBUFFER - ASSERT_NO_THROW(resizeWindow(window_name, 800, 600)); -#endif const vector channels = {1, 3, 4}; const vector depths = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32F, CV_64F}; for(int cn : channels) From ee0b70ae109057d10b1b006d743313c833ece5b4 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 20 May 2024 22:31:17 +0300 Subject: [PATCH 17/81] add FB mode --- modules/highgui/src/window_framebuffer.cpp | 137 +++++++++++++-------- modules/highgui/src/window_framebuffer.hpp | 9 ++ 2 files changed, 97 insertions(+), 49 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index deb663dbd5e2..7b6e35fc329c 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -29,6 +29,30 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } + static std::string& getFBMode() + { + static std::string fbModeOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); + static std::string fbModeDef = "FB"; + + if(!fbModeOpenCV.empty()) return fbModeOpenCV; + return fbModeDef; + } + + static std::string& getFBFileName() + { + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); + static std::string fbFileNameDef = "/dev/fb0"; + + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if(!fbFileNameFB.empty()) return fbFileNameFB; + return fbFileNameDef; + } + + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): backend(_backend), flags(_flags) { @@ -55,17 +79,6 @@ namespace cv { namespace highgui_backend { return; } - if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); - return; - } - - if(backend.getFBBitsPerPixel() != 32) { - CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " - << backend.getFBBitsPerPixel() << " is not supported" ); - return; - } - Mat img(image.getMat()); switch(img.channels()){ case 1: @@ -140,9 +153,25 @@ namespace cv { namespace highgui_backend { CV_Assert(0); } - CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); + + if(backend.getMode() == FB_MODE_EMU) + { + CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); + return; + } + + if (backend.getFBPointer() == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); + return; + } + + if(backend.getFBBitsPerPixel() != 32) { + CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " + << backend.getFBBitsPerPixel() << " is not supported" ); + return; + } // SHOW IMAGE int xOffset = backend.getFBXOffset(); @@ -280,20 +309,6 @@ namespace cv { namespace highgui_backend { // !!##FramebufferBackend - static std::string& getFBFileName() - { - static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); - static std::string fbFileNameOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FRAMEBUFFER", ""); - static std::string fbFileNameDef = "/dev/fb0"; - - if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - if(!fbFileNameFB.empty()) return fbFileNameFB; - return fbFileNameDef; - } - - int FramebufferBackend::fbOpenAndGetInfo() { std::string fbFileName = getFBFileName(); @@ -382,20 +397,48 @@ namespace cv { namespace highgui_backend { { return backgroundBuff; } + OpenCVFBMode FramebufferBackend::getMode() + { + return mode; + } - FramebufferBackend::FramebufferBackend() + FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - fbID = fbOpenAndGetInfo(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); + std::string fbModeStr = getFBMode(); + + if(fbModeStr == "EMU") + { + mode = FB_MODE_EMU; + } + if(fbModeStr == "FB") + { + mode = FB_MODE_FB; + } + if(fbModeStr == "XVFB") + { + mode = FB_MODE_XVFB; + } + + fbID = -1; + if(mode == FB_MODE_FB) + { + fbID = fbOpenAndGetInfo(); + } + + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); + if(fbID == -1){ + mode = FB_MODE_EMU; fbWidth = 0; fbHeight = 0; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; fbLineLength = 0; + + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); return; } @@ -538,30 +581,26 @@ namespace cv { namespace highgui_backend { code = ch; } } else { - if(delay > 0) + bool f_kbhit = false; + while(!(f_kbhit = kbhit()) && (delay > 0)) { - bool f_kbhit = false; - while(!(f_kbhit = kbhit()) && (delay > 0)) - { - delay -= 1; - usleep(1000); - } - if(f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + delay -= 1; + usleep(1000); + } + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; - - while((ch = getch_(0, 0))>=0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } } - } } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index a076f4e97ed4..db6611b53007 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -11,6 +11,12 @@ namespace cv { namespace highgui_backend { +enum OpenCVFBMode{ + FB_MODE_EMU, + FB_MODE_FB, + FB_MODE_XVFB +}; + class FramebufferBackend; class CV_EXPORTS FramebufferWindow : public UIWindow { @@ -60,6 +66,8 @@ class CV_EXPORTS FramebufferBackend: public UIBackend // int OpenInputEvent(); // int eventKey; + OpenCVFBMode mode; + struct termios old, current; void initTermios(int echo, int wait); @@ -97,6 +105,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend int getFBLineLength(); unsigned char* getFBPointer(); Mat& getBackgroundBuff(); + OpenCVFBMode getMode(); FramebufferBackend(); From 7a2f830ec9f39f3a38836fe45073dc021e4964b7 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 20 May 2024 23:09:08 +0300 Subject: [PATCH 18/81] fix warning --- modules/highgui/src/window_framebuffer.cpp | 17 +++++++++-------- modules/highgui/src/window_framebuffer.hpp | 3 --- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 7b6e35fc329c..5b455edf9b94 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -201,7 +201,7 @@ namespace cv { namespace highgui_backend { { std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + xOffset + windowRect.x, - img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, + img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, showCols * cntChannel); } } @@ -266,24 +266,24 @@ namespace cv { namespace highgui_backend { CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } - void FramebufferWindow::setMouseCallback(MouseCallback onMouse, void* userdata ) + void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/ ) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); } std::shared_ptr FramebufferWindow::createTrackbar( - const std::string& name, - int count, - TrackbarCallback onChange, - void* userdata) + const std::string& /*name*/, + int /*count*/, + TrackbarCallback /*onChange*/, + void* /*userdata*/) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); return nullptr; } - std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name) + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); @@ -479,7 +479,8 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), + unsigned char* backgroundPtr = backgroundBuff.ptr(y - fbYOffset); + std::memcpy(backgroundPtr, fbPointer + y * fbLineLength + fbXOffset, backgroundBuff.cols * cnt_channel); } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index db6611b53007..a5128b715d27 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -63,9 +63,6 @@ class CV_EXPORTS FramebufferWindow : public UIWindow class CV_EXPORTS FramebufferBackend: public UIBackend { -// int OpenInputEvent(); -// int eventKey; - OpenCVFBMode mode; struct termios old, current; From 9ad906cb8d6976d5c3b20851db779a3ca4251647 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 21 May 2024 16:03:03 +0300 Subject: [PATCH 19/81] add XVFB mode support --- modules/highgui/CMakeLists.txt | 2 + modules/highgui/src/XWDFile.h | 125 ++++++++++++++++++ modules/highgui/src/Xmd.h | 146 +++++++++++++++++++++ modules/highgui/src/window_framebuffer.cpp | 134 ++++++++++++++----- modules/highgui/src/window_framebuffer.hpp | 6 + 5 files changed, 382 insertions(+), 31 deletions(-) create mode 100644 modules/highgui/src/XWDFile.h create mode 100644 modules/highgui/src/Xmd.h diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index d4b0a7ff0548..23486149aa1e 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -44,6 +44,8 @@ if(WITH_FRAMEBUFFER) add_definitions(-DHAVE_FRAMEBUFFER) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/XWDFile.h) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/Xmd.h) endif() diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h new file mode 100644 index 000000000000..eddb4eed2196 --- /dev/null +++ b/modules/highgui/src/XWDFile.h @@ -0,0 +1,125 @@ +/* + +Copyright 1985, 1986, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * XWDFile.h MIT Project Athena, X Window system window raster + * image dumper, dump file format header file. + * + * Author: Tony Della Fera, DEC + * 27-Jun-85 + * + * Modifier: William F. Wyatt, SAO + * 18-Nov-86 - version 6 for saving/restoring color maps + */ + +#ifndef XWDFILE_H +#define XWDFILE_H + +#include "Xmd.h" + +#define XWD_FILE_VERSION 7 +#define sz_XWDheader 100 +#define sz_XWDColor 12 + +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) + +/***************************************************************** + * IMAGING + *****************************************************************/ + +/* ImageFormat -- PutImage, GetImage */ + +#define XYBitmap 0 /* depth 1, XYFormat */ +#define XYPixmap 1 /* depth == drawable depth */ +#define ZPixmap 2 /* depth == drawable depth */ + +typedef CARD32 xwdval; /* for old broken programs */ + +/* Values in the file are most significant byte first. */ + +typedef struct _xwd_file_header { + /* header_size = SIZEOF(XWDheader) + length of null-terminated + * window name. */ + CARD32 header_size; + + CARD32 file_version; /* = XWD_FILE_VERSION above */ + CARD32 pixmap_format; /* ZPixmap or XYPixmap */ + CARD32 pixmap_depth; /* Pixmap depth */ + CARD32 pixmap_width; /* Pixmap width */ + CARD32 pixmap_height; /* Pixmap height */ + CARD32 xoffset; /* Bitmap x offset, normally 0 */ + CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ + + /* bitmap_unit applies to bitmaps (depth 1 format XY) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_unit; + + CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ + + /* bitmap_pad applies to pixmaps (non-bitmaps) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_pad; + + CARD32 bits_per_pixel; /* Bits per pixel */ + + /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) + * or bitmap_pad (pixmaps). It is the delta (in bytes) to get + * to the same x position on an adjacent row. */ + CARD32 bytes_per_line; + CARD32 visual_class; /* Class of colormap */ + CARD32 red_mask; /* Z red mask */ + CARD32 green_mask; /* Z green mask */ + CARD32 blue_mask; /* Z blue mask */ + CARD32 bits_per_rgb; /* Log2 of distinct color values */ + CARD32 colormap_entries; /* Number of entries in colormap; not used? */ + CARD32 ncolors; /* Number of XWDColor structures */ + CARD32 window_width; /* Window width */ + CARD32 window_height; /* Window height */ + CARD32 window_x; /* Window upper left X coordinate */ + CARD32 window_y; /* Window upper left Y coordinate */ + CARD32 window_bdrwidth; /* Window border width */ +} XWDFileHeader; + +/* Null-terminated window name follows the above structure. */ + +/* Next comes XWDColor structures, at offset XWDFileHeader.header_size in + * the file. XWDFileHeader.ncolors tells how many XWDColor structures + * there are. + */ + +typedef struct { + CARD32 pixel; + CARD16 red; + CARD16 green; + CARD16 blue; + CARD8 flags; + CARD8 pad; +} XWDColor; + +/* Last comes the image data in the format described by XWDFileHeader. */ + +#endif /* XWDFILE_H */ + diff --git a/modules/highgui/src/Xmd.h b/modules/highgui/src/Xmd.h new file mode 100644 index 000000000000..68c45dbec0ee --- /dev/null +++ b/modules/highgui/src/Xmd.h @@ -0,0 +1,146 @@ +/*********************************************************** + +Copyright 1987, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ +#ifndef XMD_H +# define XMD_H 1 +/* + * Xmd.h: MACHINE DEPENDENT DECLARATIONS. + */ + +/* + * Special per-machine configuration flags. + */ +# if defined(__sun) && defined(__SVR4) +# include /* Solaris: defines _LP64 if necessary */ +# endif + +#if defined(__SIZEOF_LONG__) +# if __SIZEOF_LONG__ == 8 +# define LONG64 /* 32/64-bit architecture */ +# endif +# elif defined (_LP64) || defined(__LP64__) || \ + defined(__alpha) || defined(__alpha__) || \ + defined(__ia64__) || defined(ia64) || \ + defined(__sparc64__) || \ + defined(__s390x__) || \ + defined(__amd64__) || defined(amd64) || \ + defined(__powerpc64__) +# if !defined(__ILP32__) /* amd64-x32 is 32bit */ +# define LONG64 /* 32/64-bit architecture */ +# endif /* !__ILP32__ */ +# endif + +/* + * Definition of macro used to set constants for size of network structures; + * machines with preprocessors that can't handle all of the sz_ symbols + * can define this macro to be sizeof(x) if and only if their compiler doesn't + * pad out structures (esp. the xTextElt structure which contains only two + * one-byte fields). Network structures should always define sz_symbols. + * + * The sz_ prefix is used instead of something more descriptive so that the + * symbols are no more than 32 characters long (which causes problems for some + * compilers and preprocessors). + * + * The extra indirection is to get macro arguments to expand correctly before + * the concatenation, rather than afterward. + */ +# define _SIZEOF(x) sz_##x +# define SIZEOF(x) _SIZEOF(x) + +/* + * Bitfield suffixes for the protocol structure elements, if you + * need them. Note that bitfields are not guaranteed to be signed + * (or even unsigned) according to ANSI C. + */ +# define B32 /* bitfield not needed on architectures with native 32-bit type */ +# define B16 /* bitfield not needed on architectures with native 16-bit type */ +# ifdef LONG64 +typedef long INT64; +typedef int INT32; +# else +typedef long INT32; +# endif +typedef short INT16; + +typedef signed char INT8; + +# ifdef LONG64 +typedef unsigned long CARD64; +typedef unsigned int CARD32; +# else +typedef unsigned long long CARD64; +typedef unsigned long CARD32; +# endif +typedef unsigned short CARD16; +typedef unsigned char CARD8; + +typedef CARD32 BITS32; +typedef CARD16 BITS16; + +typedef CARD8 BYTE; +typedef CARD8 BOOL; + +/* + * was definitions for sign-extending bitfields on architectures without + * native types smaller than 64-bit, now just backwards compatibility + */ +# define cvtINT8toInt(val) (val) +# define cvtINT16toInt(val) (val) +# define cvtINT32toInt(val) (val) +# define cvtINT8toShort(val) (val) +# define cvtINT16toShort(val) (val) +# define cvtINT32toShort(val) (val) +# define cvtINT8toLong(val) (val) +# define cvtINT16toLong(val) (val) +# define cvtINT32toLong(val) (val) + +/* + * this version should leave result of type (t *), but that should only be + * used when not in MUSTCOPY + */ +# define NEXTPTR(p,t) (((t *)(p)) + 1) + +#endif /* XMD_H */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 5b455edf9b94..7404f85065f5 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -21,6 +21,7 @@ #include "opencv2/imgproc.hpp" +#include "XWDFile.h" namespace cv { namespace highgui_backend { @@ -68,7 +69,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::imshow(InputArray image) { - currentImg = image.getMat(); + currentImg = image.getMat().clone(); CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " @@ -79,7 +80,7 @@ namespace cv { namespace highgui_backend { return; } - Mat img(image.getMat()); + Mat img(image.getMat().clone()); switch(img.channels()){ case 1: switch(img.type()) @@ -350,6 +351,94 @@ namespace cv { namespace highgui_backend { return -1; } + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.yoffset; + fbYOffset = varInfo.xoffset; + fbBitsPerPixel = varInfo.bits_per_pixel; + fbLineLength = fixInfo.line_length; + + // MAP FB TO MEMORY + fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * + max((__u32)fbHeight, varInfo.yres_virtual) * + fbBitsPerPixel / 8; + + fbPointer = (unsigned char*) + mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, + fbID, 0); + + if (fbPointer == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); + return -1; + } + + return fb_fd; + } + + int FramebufferBackend::XvfbOpenAndGetInfo() + { + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) + { + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; + } + + XWDFileHeader *xwd_header; + + xwd_header = (XWDFileHeader*) mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); + + if (xwd_header == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); + return -1; + } + + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ){ + CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); + return -1; + } + + if( xwd_header->xoffset != 0 ){ + CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); + return -1; + } + + unsigned int r = C32INT(&(xwd_header-> red_mask)); + unsigned int g = C32INT(&(xwd_header->green_mask)); + unsigned int b = C32INT(&(xwd_header-> blue_mask)); + + fbWidth = C32INT(&(xwd_header->pixmap_width)); + fbHeight = C32INT(&(xwd_header->pixmap_height)); + fbXOffset = 0; + fbYOffset = 0; + fbLineLength = C32INT(&(xwd_header->bytes_per_line)); + fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); + + CV_LOG_INFO(NULL, "UI: XVFB info: \n" + << " red_mask " << r << "\n" + << " green_mask " << g << "\n" + << " blue_mask " << b << "\n" + << "bits_per_pixel " << fbBitsPerPixel); + + if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32) ){ + CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported (use BGRA format with bits_per_pixel = 32)"); + return -1; + } + + xvfb_len_header = C32INT(&(xwd_header->header_size)); + xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * C32INT(&(xwd_header->pixmap_height)); + munmap(xwd_header, sizeof(XWDFileHeader)); + + fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; + xwd_header = (XWDFileHeader*) mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header ; + fbPointer_dist = xvfb_len_header + xvfb_len_colors; + return fb_fd; } @@ -391,7 +480,7 @@ namespace cv { namespace highgui_backend { } unsigned char* FramebufferBackend::getFBPointer() { - return fbPointer; + return fbPointer + fbPointer_dist; } Mat& FramebufferBackend::getBackgroundBuff() { @@ -402,7 +491,7 @@ namespace cv { namespace highgui_backend { return mode; } - FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU) + FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU), fbPointer_dist(0) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); @@ -411,14 +500,17 @@ namespace cv { namespace highgui_backend { if(fbModeStr == "EMU") { mode = FB_MODE_EMU; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); } if(fbModeStr == "FB") { mode = FB_MODE_FB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); } if(fbModeStr == "XVFB") { mode = FB_MODE_XVFB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); } fbID = -1; @@ -426,13 +518,17 @@ namespace cv { namespace highgui_backend { { fbID = fbOpenAndGetInfo(); } + if(mode == FB_MODE_XVFB) + { + fbID = XvfbOpenAndGetInfo(); + } CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); if(fbID == -1){ mode = FB_MODE_EMU; - fbWidth = 0; - fbHeight = 0; + fbWidth = 10; + fbHeight = 10; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; @@ -442,12 +538,6 @@ namespace cv { namespace highgui_backend { return; } - fbWidth = varInfo.xres; - fbHeight = varInfo.yres; - fbXOffset = varInfo.yoffset; - fbYOffset = varInfo.xoffset; - fbBitsPerPixel = varInfo.bits_per_pixel; - fbLineLength = fixInfo.line_length; CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); @@ -455,25 +545,6 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " << fbXOffset << " " << fbYOffset << " " << fbLineLength); - // MAP FB TO MEMORY - fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * - max((__u32)fbHeight, varInfo.yres_virtual) * - fbBitsPerPixel / 8; - - fbPointer = (unsigned char*) - mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, - fbID, 0); - - if (fbPointer == MAP_FAILED) { - CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); - return; - } - - if(fbBitsPerPixel != 32) { - CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " - << fbBitsPerPixel << " is not supported" ); - return; - } backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; @@ -500,6 +571,7 @@ namespace cv { namespace highgui_backend { backgroundBuff.cols * cnt_channel); } + if (fbPointer != MAP_FAILED) { munmap(fbPointer, fbScreenSize); } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index a5128b715d27..c589fd12ea94 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -83,11 +83,17 @@ class CV_EXPORTS FramebufferBackend: public UIBackend int fbLineLength; long int fbScreenSize; unsigned char* fbPointer; + unsigned int fbPointer_dist; Mat backgroundBuff; int fbOpenAndGetInfo(); int fbID; + + unsigned int xvfb_len_header; + unsigned int xvfb_len_colors; + unsigned int xvfb_len_pixmap; + int XvfbOpenAndGetInfo(); public: From ceed48391793754449c4c22f712b706e473abf69 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 21 May 2024 22:59:12 +0300 Subject: [PATCH 20/81] fix style --- modules/highgui/src/window_framebuffer.cpp | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 7404f85065f5..eccd97a15cf3 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -128,13 +128,6 @@ namespace cv { namespace highgui_backend { windowRect.height = imgSize.height; } break; -// case WINDOW_FULLSCREEN: -// windowRect.width = backend.getFBWidth(); -// windowRect.height = backend.getFBHeight(); -// newWidth = windowRect.width; -// newHeight = windowRect.height; -// cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); -// break; case WINDOW_NORMAL: // WINDOW_KEEPRATIO { double aspect_ratio = ((double)img.cols) / img.rows; @@ -167,12 +160,6 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } - - if(backend.getFBBitsPerPixel() != 32) { - CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " - << backend.getFBBitsPerPixel() << " is not supported" ); - return; - } // SHOW IMAGE int xOffset = backend.getFBXOffset(); @@ -214,6 +201,7 @@ namespace cv { namespace highgui_backend { return 0.0; } + bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " @@ -308,7 +296,7 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } -// !!##FramebufferBackend +//FramebufferBackend int FramebufferBackend::fbOpenAndGetInfo() { @@ -446,46 +434,57 @@ namespace cv { namespace highgui_backend { { return varInfo; } + fb_fix_screeninfo &FramebufferBackend::getFixInfo() { return fixInfo; } + int FramebufferBackend::getFramebuffrerID() { return fbID; } + int FramebufferBackend::getFBWidth() { return fbWidth; } + int FramebufferBackend::getFBHeight() { return fbHeight; } + int FramebufferBackend::getFBXOffset() { return fbXOffset; } + int FramebufferBackend::getFBYOffset() { return fbYOffset; } + int FramebufferBackend::getFBBitsPerPixel() { return fbBitsPerPixel; } + int FramebufferBackend::getFBLineLength() { return fbLineLength; } + unsigned char* FramebufferBackend::getFBPointer() { return fbPointer + fbPointer_dist; } + Mat& FramebufferBackend::getBackgroundBuff() { return backgroundBuff; } + OpenCVFBMode FramebufferBackend::getMode() { return mode; @@ -576,7 +575,6 @@ namespace cv { namespace highgui_backend { munmap(fbPointer, fbScreenSize); } close(fbID); - } void FramebufferBackend::destroyAllWindows() { @@ -622,6 +620,7 @@ namespace cv { namespace highgui_backend { resetTermios(); return ch; } + bool FramebufferBackend::kbhit() { int byteswaiting=0; @@ -653,7 +652,9 @@ namespace cv { namespace highgui_backend { << (int)ch << " (additional code on )"); code = ch; } - } else { + } + else + { bool f_kbhit = false; while(!(f_kbhit = kbhit()) && (delay > 0)) { @@ -707,6 +708,5 @@ namespace cv { namespace highgui_backend { return code; } - } } From 1fef6a51beb631cd507aea5ced406d7edb93cb8c Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 23 May 2024 18:35:05 +0300 Subject: [PATCH 21/81] fix error FB mode --- modules/highgui/src/window_framebuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index eccd97a15cf3..ee5ee3abbac6 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -353,7 +353,7 @@ namespace cv { namespace highgui_backend { fbPointer = (unsigned char*) mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, - fbID, 0); + fb_fd, 0); if (fbPointer == MAP_FAILED) { CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); From 8c457ae152cdc7302966f083f38aadc3836911e6 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 08:41:25 +0300 Subject: [PATCH 22/81] comment added. destructor fixed --- modules/highgui/src/XWDFile.h | 12 +++++++++--- modules/highgui/src/window_framebuffer.cpp | 18 +++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index eddb4eed2196..513fa6083114 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -38,24 +38,30 @@ in this Software without prior written authorization from The Open Group. #ifndef XWDFILE_H #define XWDFILE_H +// replaced "#include " with "#include "Xmd.h"" #include "Xmd.h" #define XWD_FILE_VERSION 7 #define sz_XWDheader 100 #define sz_XWDColor 12 -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) - /***************************************************************** - * IMAGING + * Start. Added from *****************************************************************/ +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) + /* ImageFormat -- PutImage, GetImage */ #define XYBitmap 0 /* depth 1, XYFormat */ #define XYPixmap 1 /* depth == drawable depth */ #define ZPixmap 2 /* depth == drawable depth */ +/***************************************************************** + * End. Added from + *****************************************************************/ + + typedef CARD32 xwdval; /* for old broken programs */ /* Values in the file are most significant byte first. */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index ee5ee3abbac6..2ee074607077 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -562,16 +562,16 @@ namespace cv { namespace highgui_backend { if(fbID == -1) return; // RESTORE BACKGROUNG - int cnt_channel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) - { - std::memcpy(fbPointer + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cnt_channel); - } - - if (fbPointer != MAP_FAILED) { + + int cnt_channel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + { + std::memcpy(fbPointer + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); + } + munmap(fbPointer, fbScreenSize); } close(fbID); From e5b387117ddea795af481e66a637568e3c565530 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 10:13:54 +0300 Subject: [PATCH 23/81] fixed handling of window processing flags --- modules/highgui/src/window_framebuffer.cpp | 56 +++++++++++----------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 2ee074607077..73f0aa4c55a7 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -115,38 +115,36 @@ namespace cv { namespace highgui_backend { int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - switch(flags) + + if(flags & WINDOW_AUTOSIZE) { - case WINDOW_FREERATIO: - { - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); - } - break; - case WINDOW_AUTOSIZE: // WINDOW_FULLSCREEN - { windowRect.width = imgSize.width; windowRect.height = imgSize.height; - } - break; - case WINDOW_NORMAL: // WINDOW_KEEPRATIO - { - double aspect_ratio = ((double)img.cols) / img.rows; - newWidth = windowRect.width; - newHeight = (int)(windowRect.width / aspect_ratio); + } + + if(flags & WINDOW_FREERATIO) + { + newWidth = windowRect.width; + newHeight = windowRect.height; + } + + if(flags & WINDOW_KEEPRATIO) + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); - if (newHeight > windowRect.height) { - newWidth = (int)(windowRect.height * aspect_ratio); - newHeight = windowRect.height; - } - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + if (newHeight > windowRect.height) { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; } - break; - - default: - CV_LOG_ERROR(NULL, "UI: FB window flag not supported"); - CV_Assert(0); } - + + if((newWidth != img.cols) && (newHeight != img.rows)) + { + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -219,7 +217,7 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - if(flags != WINDOW_AUTOSIZE) + if(flags & WINDOW_AUTOSIZE) { windowRect.width = width; windowRect.height = height; @@ -526,8 +524,8 @@ namespace cv { namespace highgui_backend { if(fbID == -1){ mode = FB_MODE_EMU; - fbWidth = 10; - fbHeight = 10; + fbWidth = 1024; + fbHeight = 768; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; From b3a1b6d0b9ac07250a21ebbc0970228b0432afd0 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 10:38:07 +0300 Subject: [PATCH 24/81] fix WINDOW_AUTOSIZE --- modules/highgui/src/window_framebuffer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 73f0aa4c55a7..86e73ce68be5 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -118,8 +118,10 @@ namespace cv { namespace highgui_backend { if(flags & WINDOW_AUTOSIZE) { - windowRect.width = imgSize.width; - windowRect.height = imgSize.height; + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + newWidth = windowRect.width; + newHeight = windowRect.height; } if(flags & WINDOW_FREERATIO) From 5339c2655484b2ed224a0e5c785e1594c1fa4547 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 21:57:28 +0300 Subject: [PATCH 25/81] fix show size --- modules/highgui/src/window_framebuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 86e73ce68be5..48d7fb06f9d4 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -166,8 +166,8 @@ namespace cv { namespace highgui_backend { int yOffset = backend.getFBYOffset(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); - int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); + int showRows = min((windowRect.y + img.rows), backend.getFBHeight() - yOffset); + int showCols = min((windowRect.x + img.cols), backend.getFBWidth() - xOffset); int dx_w = windowRect.x; int dy_w = windowRect.y; From 6194366220c09728cf11f8496e3da91427de5e9c Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 27 May 2024 19:42:22 +0300 Subject: [PATCH 26/81] fixed some bugs and comments --- modules/highgui/src/XWDFile.h | 7 +++---- modules/highgui/src/window_framebuffer.cpp | 22 +++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index 513fa6083114..cd11d802aca2 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -45,14 +45,13 @@ in this Software without prior written authorization from The Open Group. #define sz_XWDheader 100 #define sz_XWDColor 12 +// Added macro to convert big-endian numbers to local representation +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) + /***************************************************************** * Start. Added from *****************************************************************/ -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) - -/* ImageFormat -- PutImage, GetImage */ - #define XYBitmap 0 /* depth 1, XYFormat */ #define XYPixmap 1 /* depth == drawable depth */ #define ZPixmap 2 /* depth == drawable depth */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 48d7fb06f9d4..2fae73a88a88 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -115,7 +115,6 @@ namespace cv { namespace highgui_backend { int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - if(flags & WINDOW_AUTOSIZE) { windowRect.width = imgSize.width; @@ -129,8 +128,7 @@ namespace cv { namespace highgui_backend { newWidth = windowRect.width; newHeight = windowRect.height; } - - if(flags & WINDOW_KEEPRATIO) + else //WINDOW_KEEPRATIO { double aspect_ratio = ((double)img.cols) / img.rows; newWidth = windowRect.width; @@ -166,8 +164,8 @@ namespace cv { namespace highgui_backend { int yOffset = backend.getFBYOffset(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight() - yOffset); - int showCols = min((windowRect.x + img.cols), backend.getFBWidth() - xOffset); + int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); + int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); int dx_w = windowRect.x; int dy_w = windowRect.y; @@ -184,11 +182,9 @@ namespace cv { namespace highgui_backend { showRows -= dy_w; showCols -= dx_w; - for (int y = yOffset; y < showRows + yOffset; y++) { - std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + - xOffset + windowRect.x, + std::memcpy(backend.getFBPointer() + (y + dy_w) * lineLength + xOffset + dx_w, img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, showCols * cntChannel); } @@ -219,7 +215,7 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - if(flags & WINDOW_AUTOSIZE) + if(!(flags & WINDOW_AUTOSIZE)) { windowRect.width = width; windowRect.height = height; @@ -339,16 +335,16 @@ namespace cv { namespace highgui_backend { return -1; } - fbWidth = varInfo.xres; - fbHeight = varInfo.yres; + fbWidth = varInfo.xres_virtual; + fbHeight = varInfo.yres_virtual; fbXOffset = varInfo.yoffset; fbYOffset = varInfo.xoffset; fbBitsPerPixel = varInfo.bits_per_pixel; fbLineLength = fixInfo.line_length; // MAP FB TO MEMORY - fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * - max((__u32)fbHeight, varInfo.yres_virtual) * + fbScreenSize = max(varInfo.xres, varInfo.xres_virtual) * + max(varInfo.yres, varInfo.yres_virtual) * fbBitsPerPixel / 8; fbPointer = (unsigned char*) From 5b85c52c083fba1a798eeaaedf1fc45b2644bcf7 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 10:10:06 +0300 Subject: [PATCH 27/81] The window display algorithm has been replaced. several bugs fixed --- modules/highgui/src/window_framebuffer.cpp | 129 ++++++++++++++------- 1 file changed, 90 insertions(+), 39 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 2fae73a88a88..258001501906 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -162,31 +162,74 @@ namespace cv { namespace highgui_backend { // SHOW IMAGE int xOffset = backend.getFBXOffset(); int yOffset = backend.getFBYOffset(); + int fbHeight = backend.getFBHeight(); + int fbWidth = backend.getFBWidth(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); - int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); - - int dx_w = windowRect.x; - int dy_w = windowRect.y; + int img_start_x; + int img_start_y; + int img_end_x; + int img_end_y; + int fb_start_x; + int fb_start_y; - int start_y_w = 0; - int start_x_w = 0; - - if(dy_w < 0) start_y_w = -dy_w; - if(dx_w < 0) start_x_w = -dx_w; + if(windowRect.y - yOffset < 0) + { + img_start_y = - (windowRect.y - yOffset); + } + else + { + img_start_y = 0; + } + if( windowRect.x - xOffset < 0 ) + { + img_start_x = - (windowRect.x - xOffset); + } + else + { + img_start_x = 0; + } - if(dy_w < 0) dy_w = 0; - if(dx_w < 0) dx_w = 0; + if( windowRect.y + yOffset + img.rows > fbHeight ) + { + img_end_y = fbHeight - windowRect.y - yOffset; + } + else + { + img_end_y = img.rows; + } + if( windowRect.x + xOffset + img.cols > fbWidth ) + { + img_end_x = fbWidth - windowRect.x - xOffset; + } + else + { + img_end_x = img.cols; + } - showRows -= dy_w; - showCols -= dx_w; + if( windowRect.y + yOffset >= 0 ) + { + fb_start_y = windowRect.y + yOffset; + } + else + { + fb_start_y = 0; + } + if( windowRect.x + xOffset >= 0 ) + { + fb_start_x = windowRect.x + xOffset; + } + else + { + fb_start_x = 0; + } - for (int y = yOffset; y < showRows + yOffset; y++) + for (int y = img_start_y; y < img_end_y; y++) { - std::memcpy(backend.getFBPointer() + (y + dy_w) * lineLength + xOffset + dx_w, - img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, - showCols * cntChannel); + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, + (img_end_x - img_start_x) * cntChannel); } } @@ -220,7 +263,7 @@ namespace cv { namespace highgui_backend { windowRect.width = width; windowRect.height = height; - if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + if((currentImg.cols > 0) && (currentImg.rows > 0)) { imshow(currentImg); } @@ -233,7 +276,7 @@ namespace cv { namespace highgui_backend { windowRect.x = x; windowRect.y = y; - if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + if((currentImg.cols > 0) && (currentImg.rows > 0)) { imshow(currentImg); } @@ -307,13 +350,15 @@ namespace cv { namespace highgui_backend { } // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; } // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } @@ -335,10 +380,10 @@ namespace cv { namespace highgui_backend { return -1; } - fbWidth = varInfo.xres_virtual; - fbHeight = varInfo.yres_virtual; - fbXOffset = varInfo.yoffset; - fbYOffset = varInfo.xoffset; + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.xoffset; + fbYOffset = varInfo.yoffset; fbBitsPerPixel = varInfo.bits_per_pixel; fbLineLength = fixInfo.line_length; @@ -375,17 +420,20 @@ namespace cv { namespace highgui_backend { xwd_header = (XWDFileHeader*) mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); - if (xwd_header == MAP_FAILED) { + if (xwd_header == MAP_FAILED) + { CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); return -1; } - if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ){ + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ) + { CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); return -1; } - if( xwd_header->xoffset != 0 ){ + if( xwd_header->xoffset != 0 ) + { CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); return -1; } @@ -408,7 +456,8 @@ namespace cv { namespace highgui_backend { << "bits_per_pixel " << fbBitsPerPixel); if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32) ){ + (fbBitsPerPixel != 32) ) + { CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported (use BGRA format with bits_per_pixel = 32)"); return -1; } @@ -486,7 +535,7 @@ namespace cv { namespace highgui_backend { return mode; } - FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU), fbPointer_dist(0) + FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); @@ -545,9 +594,8 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - unsigned char* backgroundPtr = backgroundBuff.ptr(y - fbYOffset); - std::memcpy(backgroundPtr, - fbPointer + y * fbLineLength + fbXOffset, + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset, backgroundBuff.cols * cnt_channel); } } @@ -563,7 +611,7 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(fbPointer + y * fbLineLength + fbXOffset, + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, backgroundBuff.ptr(y - fbYOffset), backgroundBuff.cols * cnt_channel); } @@ -594,10 +642,13 @@ namespace cv { namespace highgui_backend { current.c_lflag &= ~ICANON; // disable buffered i/o current.c_lflag &= ~ISIG; current.c_cc[VMIN]=wait; - if (echo) { - current.c_lflag |= ECHO; // set echo mode - } else { - current.c_lflag &= ~ECHO; // set no echo mode + if (echo) + { + current.c_lflag |= ECHO; // set echo mode + } + else + { + current.c_lflag &= ~ECHO; // set no echo mode } tcsetattr(0, TCSANOW, ¤t); // use these new terminal i/o settings now } From 7b3cadbb6d46167155969b81558c13ee6227db70 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 11:22:12 +0300 Subject: [PATCH 28/81] fix style --- modules/highgui/src/window_framebuffer.cpp | 1291 ++++++++++---------- modules/highgui/src/window_framebuffer.hpp | 180 +-- 2 files changed, 739 insertions(+), 732 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 258001501906..eebe24c34d36 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -24,736 +24,743 @@ #include "XWDFile.h" namespace cv { namespace highgui_backend { - - std::shared_ptr createUIBackendFramebuffer() - { - return std::make_shared(); - } - - static std::string& getFBMode() - { - static std::string fbModeOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); - static std::string fbModeDef = "FB"; - - if(!fbModeOpenCV.empty()) return fbModeOpenCV; - return fbModeDef; - } - - static std::string& getFBFileName() - { - static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); - static std::string fbFileNameOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); - static std::string fbFileNameDef = "/dev/fb0"; - - if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - if(!fbFileNameFB.empty()) return fbFileNameFB; - return fbFileNameDef; - } - - - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): - backend(_backend), flags(_flags) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); - FB_ID = "FramebufferWindow"; - windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); - } - - FramebufferWindow::~FramebufferWindow() - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); - } - - void FramebufferWindow::imshow(InputArray image) - { - currentImg = image.getMat().clone(); - - CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); - CV_LOG_INFO(NULL, "UI: InputArray image: " - << cv::typeToString(image.type()) << " size " << image.size()); - - if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) - { - return; - } - - Mat img(image.getMat().clone()); - switch(img.channels()){ - case 1: - switch(img.type()) - { - case CV_8S: - cv::convertScaleAbs(img, img, 1, 127); - break; - case CV_16S: - cv::convertScaleAbs(img, img, 1/255., 127); - break; - case CV_16U: - cv::convertScaleAbs(img, img, 1/255.); - break; - case CV_32F: - case CV_64F: // assuming image has values in range [0, 1) - img.convertTo(img, CV_8U, 255., 0.); - break; - } - cvtColor(img, img, cv::COLOR_GRAY2RGB); - break; - case 3: - convertToShow(img, img); - break; - case 4: - convertToShow(img, img, true); - break; - } - cvtColor(img, img, COLOR_RGB2BGRA); - - int newWidth = windowRect.width; - int newHeight = windowRect.height; - int cntChannel = img.channels(); - cv::Size imgSize = currentImg.size(); - - if(flags & WINDOW_AUTOSIZE) + + std::shared_ptr createUIBackendFramebuffer() { - windowRect.width = imgSize.width; - windowRect.height = imgSize.height; - newWidth = windowRect.width; - newHeight = windowRect.height; + return std::make_shared(); } - - if(flags & WINDOW_FREERATIO) + + static std::string& getFBMode() { - newWidth = windowRect.width; - newHeight = windowRect.height; + static std::string fbModeOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); + static std::string fbModeDef = "FB"; + + if(!fbModeOpenCV.empty()) return fbModeOpenCV; + return fbModeDef; } - else //WINDOW_KEEPRATIO + + static std::string& getFBFileName() { - double aspect_ratio = ((double)img.cols) / img.rows; - newWidth = windowRect.width; - newHeight = (int)(windowRect.width / aspect_ratio); + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); + static std::string fbFileNameDef = "/dev/fb0"; + + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if(!fbFileNameFB.empty()) return fbFileNameFB; + return fbFileNameDef; + } - if (newHeight > windowRect.height) { - newWidth = (int)(windowRect.height * aspect_ratio); - newHeight = windowRect.height; - } + + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + backend(_backend), flags(_flags) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); + FB_ID = "FramebufferWindow"; + windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); + } + + FramebufferWindow::~FramebufferWindow() + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); } - if((newWidth != img.cols) && (newHeight != img.rows)) + void FramebufferWindow::imshow(InputArray image) { - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); - } + currentImg = image.getMat().clone(); - CV_LOG_INFO(NULL, "UI: Formated image: " - << cv::typeToString(img.type()) << " size " << img.size()); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); + CV_LOG_INFO(NULL, "UI: InputArray image: " + << cv::typeToString(image.type()) << " size " << image.size()); + + if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) + { + return; + } - if(backend.getMode() == FB_MODE_EMU) - { - CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); - return; + Mat img(image.getMat().clone()); + switch(img.channels()){ + case 1: + switch(img.type()) + { + case CV_8S: + cv::convertScaleAbs(img, img, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, img, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, img, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(img, CV_8U, 255., 0.); + break; + } + cvtColor(img, img, cv::COLOR_GRAY2RGB); + break; + case 3: + convertToShow(img, img); + break; + case 4: + convertToShow(img, img, true); + break; + } + cvtColor(img, img, COLOR_RGB2BGRA); + + int newWidth = windowRect.width; + int newHeight = windowRect.height; + int cntChannel = img.channels(); + cv::Size imgSize = currentImg.size(); + + if(flags & WINDOW_AUTOSIZE) + { + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + newWidth = windowRect.width; + newHeight = windowRect.height; + } + + if(flags & WINDOW_FREERATIO) + { + newWidth = windowRect.width; + newHeight = windowRect.height; + } + else //WINDOW_KEEPRATIO + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); + + if (newHeight > windowRect.height) { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; + } + } + + if((newWidth != img.cols) && (newHeight != img.rows)) + { + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + + CV_LOG_INFO(NULL, "UI: Formated image: " + << cv::typeToString(img.type()) << " size " << img.size()); + + if(backend.getMode() == FB_MODE_EMU) + { + CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); + return; + } + + if (backend.getFBPointer() == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); + return; + } + + // SHOW IMAGE + int xOffset = backend.getFBXOffset(); + int yOffset = backend.getFBYOffset(); + int fbHeight = backend.getFBHeight(); + int fbWidth = backend.getFBWidth(); + int lineLength = backend.getFBLineLength(); + + int img_start_x; + int img_start_y; + int img_end_x; + int img_end_y; + int fb_start_x; + int fb_start_y; + + if(windowRect.y - yOffset < 0) + { + img_start_y = - (windowRect.y - yOffset); + } + else + { + img_start_y = 0; + } + if(windowRect.x - xOffset < 0) + { + img_start_x = - (windowRect.x - xOffset); + } + else + { + img_start_x = 0; + } + + if(windowRect.y + yOffset + img.rows > fbHeight) + { + img_end_y = fbHeight - windowRect.y - yOffset; + } + else + { + img_end_y = img.rows; + } + if(windowRect.x + xOffset + img.cols > fbWidth) + { + img_end_x = fbWidth - windowRect.x - xOffset; + } + else + { + img_end_x = img.cols; + } + + if(windowRect.y + yOffset >= 0) + { + fb_start_y = windowRect.y + yOffset; + } + else + { + fb_start_y = 0; + } + if(windowRect.x + xOffset >= 0) + { + fb_start_x = windowRect.x + xOffset; + } + else + { + fb_start_x = 0; + } + + for (int y = img_start_y; y < img_end_y; y++) + { + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, + (img_end_x - img_start_x) * cntChannel); + } } - if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); - return; + double FramebufferWindow::getProperty(int prop) const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); + CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + + return 0.0; } - - // SHOW IMAGE - int xOffset = backend.getFBXOffset(); - int yOffset = backend.getFBYOffset(); - int fbHeight = backend.getFBHeight(); - int fbWidth = backend.getFBWidth(); - int lineLength = backend.getFBLineLength(); - - int img_start_x; - int img_start_y; - int img_end_x; - int img_end_y; - int fb_start_x; - int fb_start_y; - if(windowRect.y - yOffset < 0) - { - img_start_y = - (windowRect.y - yOffset); + bool FramebufferWindow::setProperty(int prop, double value) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " + << prop << ", value " << value << ")"); + CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + + return false; } - else - { - img_start_y = 0; + + void FramebufferWindow::resize(int width, int height) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " + << width <<", height " << height << ")"); + + CV_Assert(width > 0); + CV_Assert(height > 0); + + if(!(flags & WINDOW_AUTOSIZE)) + { + windowRect.width = width; + windowRect.height = height; + + if((currentImg.cols > 0) && (currentImg.rows > 0)) + { + imshow(currentImg); + } + } } - if( windowRect.x - xOffset < 0 ) - { - img_start_x = - (windowRect.x - xOffset); + void FramebufferWindow::move(int x, int y) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); + + windowRect.x = x; + windowRect.y = y; + + if((currentImg.cols > 0) && (currentImg.rows > 0)) + { + imshow(currentImg); + } } - else + + Rect FramebufferWindow::getImageRect() const { - img_start_x = 0; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); + return windowRect; } - - if( windowRect.y + yOffset + img.rows > fbHeight ) + + void FramebufferWindow::setTitle(const std::string& title) { - img_end_y = fbHeight - windowRect.y - yOffset; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); + CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } - else + + void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/) { - img_end_y = img.rows; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); + CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); } - if( windowRect.x + xOffset + img.cols > fbWidth ) + + std::shared_ptr FramebufferWindow::createTrackbar( + const std::string& /*name*/, + int /*count*/, + TrackbarCallback /*onChange*/, + void* /*userdata*/) { - img_end_x = fbWidth - windowRect.x - xOffset; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); + return nullptr; } - else + + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) { - img_end_x = img.cols; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); + return nullptr; } - if( windowRect.y + yOffset >= 0 ) - { - fb_start_y = windowRect.y + yOffset; + const std::string& FramebufferWindow::getID() const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); + return FB_ID; } - else + + bool FramebufferWindow::isActive() const { - fb_start_y = 0; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); + return true; } - if( windowRect.x + xOffset >= 0 ) + + void FramebufferWindow::destroy() { - fb_start_x = windowRect.x + xOffset; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } - else + +//FramebufferBackend + + int FramebufferBackend::fbOpenAndGetInfo() { - fb_start_x = 0; + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" + << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) + { + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; + } + + // Get fixed screen information + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + { + CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); + return -1; + } + + // Get variable screen information + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + { + CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); + return -1; + } + + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" + << " green offset " <(y) + img_start_x * cntChannel, - (img_end_x - img_start_x) * cntChannel); - } - } + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" + << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) + { + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; + } - double FramebufferWindow::getProperty(int prop) const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); - CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + XWDFileHeader *xwd_header; + + xwd_header = (XWDFileHeader*) + mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); - return 0.0; - } + if (xwd_header == MAP_FAILED) + { + CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); + return -1; + } + + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ) + { + CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); + return -1; + } - bool FramebufferWindow::setProperty(int prop, double value) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " - << prop << ", value " << value << ")"); - CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + if( xwd_header->xoffset != 0 ) + { + CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); + return -1; + } + + unsigned int r = C32INT(&(xwd_header-> red_mask)); + unsigned int g = C32INT(&(xwd_header->green_mask)); + unsigned int b = C32INT(&(xwd_header-> blue_mask)); + + fbWidth = C32INT(&(xwd_header->pixmap_width)); + fbHeight = C32INT(&(xwd_header->pixmap_height)); + fbXOffset = 0; + fbYOffset = 0; + fbLineLength = C32INT(&(xwd_header->bytes_per_line)); + fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); + + CV_LOG_INFO(NULL, "UI: XVFB info: \n" + << " red_mask " << r << "\n" + << " green_mask " << g << "\n" + << " blue_mask " << b << "\n" + << "bits_per_pixel " << fbBitsPerPixel); + + if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32) ) + { + CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " + << "(use BGRA format with bits_per_pixel = 32)"); + return -1; + } - return false; - } + xvfb_len_header = C32INT(&(xwd_header->header_size)); + xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * + C32INT(&(xwd_header->pixmap_height)); + munmap(xwd_header, sizeof(XWDFileHeader)); - void FramebufferWindow::resize(int width, int height) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " - << width <<", height " << height << ")"); - - CV_Assert(width > 0); - CV_Assert(height > 0); - - if(!(flags & WINDOW_AUTOSIZE)) - { - windowRect.width = width; - windowRect.height = height; - - if((currentImg.cols > 0) && (currentImg.rows > 0)) - { - imshow(currentImg); - } - } - } - void FramebufferWindow::move(int x, int y) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); - - windowRect.x = x; - windowRect.y = y; - - if((currentImg.cols > 0) && (currentImg.rows > 0)) - { - imshow(currentImg); - } - } - - Rect FramebufferWindow::getImageRect() const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); - return windowRect; - } - - void FramebufferWindow::setTitle(const std::string& title) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); - CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); - } - - void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/ ) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); - CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); - } - - std::shared_ptr FramebufferWindow::createTrackbar( - const std::string& /*name*/, - int /*count*/, - TrackbarCallback /*onChange*/, - void* /*userdata*/) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); - CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); - return nullptr; - } - - std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); - CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); - return nullptr; - } - - const std::string& FramebufferWindow::getID() const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); - return FB_ID; - } - - bool FramebufferWindow::isActive() const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); - return true; - } - - void FramebufferWindow::destroy() - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); - } + fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; + xwd_header = (XWDFileHeader*) + mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header ; + fbPointer_dist = xvfb_len_header + xvfb_len_colors; -//FramebufferBackend + return fb_fd; + } - int FramebufferBackend::fbOpenAndGetInfo() - { - std::string fbFileName = getFBFileName(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); - - int fb_fd = open(fbFileName.c_str(), O_RDWR); - if (fb_fd == -1) + fb_var_screeninfo &FramebufferBackend::getVarInfo() { - CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); - return -1; + return varInfo; } - // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + fb_fix_screeninfo &FramebufferBackend::getFixInfo() { - CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); - return -1; + return fixInfo; } - // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + int FramebufferBackend::getFramebuffrerID() { - CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); - return -1; + return fbID; } - - CV_LOG_INFO(NULL, "UI: framebuffer info: \n" - << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" - << " green offset " << varInfo.green.offset << " length " << varInfo.green.length << "\n" - << " blue offset " << varInfo.blue.offset << " length " << varInfo.blue.length << "\n" - << "transp offset " << varInfo.transp.offset << " length " <pixmap_format)) != ZPixmap ) + + int FramebufferBackend::getFBXOffset() { - CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); - return -1; + return fbXOffset; } - if( xwd_header->xoffset != 0 ) + int FramebufferBackend::getFBYOffset() { - CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); - return -1; + return fbYOffset; } - - unsigned int r = C32INT(&(xwd_header-> red_mask)); - unsigned int g = C32INT(&(xwd_header->green_mask)); - unsigned int b = C32INT(&(xwd_header-> blue_mask)); - - fbWidth = C32INT(&(xwd_header->pixmap_width)); - fbHeight = C32INT(&(xwd_header->pixmap_height)); - fbXOffset = 0; - fbYOffset = 0; - fbLineLength = C32INT(&(xwd_header->bytes_per_line)); - fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); - - CV_LOG_INFO(NULL, "UI: XVFB info: \n" - << " red_mask " << r << "\n" - << " green_mask " << g << "\n" - << " blue_mask " << b << "\n" - << "bits_per_pixel " << fbBitsPerPixel); - - if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32) ) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported (use BGRA format with bits_per_pixel = 32)"); - return -1; - } - - xvfb_len_header = C32INT(&(xwd_header->header_size)); - xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); - xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * C32INT(&(xwd_header->pixmap_height)); - munmap(xwd_header, sizeof(XWDFileHeader)); - - fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; - xwd_header = (XWDFileHeader*) mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); - fbPointer = (unsigned char*)xwd_header ; - fbPointer_dist = xvfb_len_header + xvfb_len_colors; - - return fb_fd; - } - - fb_var_screeninfo &FramebufferBackend::getVarInfo() - { - return varInfo; - } - - fb_fix_screeninfo &FramebufferBackend::getFixInfo() - { - return fixInfo; - } - - int FramebufferBackend::getFramebuffrerID() - { - return fbID; - } - - int FramebufferBackend::getFBWidth() - { - return fbWidth; - } - - int FramebufferBackend::getFBHeight() - { - return fbHeight; - } - - int FramebufferBackend::getFBXOffset() - { - return fbXOffset; - } - - int FramebufferBackend::getFBYOffset() - { - return fbYOffset; - } - - int FramebufferBackend::getFBBitsPerPixel() - { - return fbBitsPerPixel; - } - - int FramebufferBackend::getFBLineLength() - { - return fbLineLength; - } - - unsigned char* FramebufferBackend::getFBPointer() - { - return fbPointer + fbPointer_dist; - } - - Mat& FramebufferBackend::getBackgroundBuff() - { - return backgroundBuff; - } - - OpenCVFBMode FramebufferBackend::getMode() - { - return mode; - } - - FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - - std::string fbModeStr = getFBMode(); - - if(fbModeStr == "EMU") + + int FramebufferBackend::getFBBitsPerPixel() { - mode = FB_MODE_EMU; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); + return fbBitsPerPixel; } - if(fbModeStr == "FB") + + int FramebufferBackend::getFBLineLength() { - mode = FB_MODE_FB; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); + return fbLineLength; } - if(fbModeStr == "XVFB") + + unsigned char* FramebufferBackend::getFBPointer() { - mode = FB_MODE_XVFB; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); + return fbPointer + fbPointer_dist; } - fbID = -1; - if(mode == FB_MODE_FB) + Mat& FramebufferBackend::getBackgroundBuff() { - fbID = fbOpenAndGetInfo(); + return backgroundBuff; } - if(mode == FB_MODE_XVFB) + + OpenCVFBMode FramebufferBackend::getMode() { - fbID = XvfbOpenAndGetInfo(); + return mode; } + + FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); + + std::string fbModeStr = getFBMode(); + + if(fbModeStr == "EMU") + { + mode = FB_MODE_EMU; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); + } + if(fbModeStr == "FB") + { + mode = FB_MODE_FB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); + } + if(fbModeStr == "XVFB") + { + mode = FB_MODE_XVFB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); + } + + fbID = -1; + if(mode == FB_MODE_FB) + { + fbID = fbOpenAndGetInfo(); + } + if(mode == FB_MODE_XVFB) + { + fbID = XvfbOpenAndGetInfo(); + } + + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - - if(fbID == -1){ - mode = FB_MODE_EMU; - fbWidth = 1024; - fbHeight = 768; - fbXOffset = 0; - fbYOffset = 0; - fbBitsPerPixel = 0; - fbLineLength = 0; - - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); - return; + if(fbID == -1){ + mode = FB_MODE_EMU; + fbWidth = 1024; + fbHeight = 768; + fbXOffset = 0; + fbYOffset = 0; + fbBitsPerPixel = 0; + fbLineLength = 0; + + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); + return; + } + + + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + << fbXOffset << " " << fbYOffset << " " << fbLineLength); + + + backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); + int cnt_channel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + { + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.cols * cnt_channel); + } } - - CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " - << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + FramebufferBackend::~FramebufferBackend() + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); + if(fbID == -1) return; + + // RESTORE BACKGROUNG + if (fbPointer != MAP_FAILED) { + + int cnt_channel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + { + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); + } + + munmap(fbPointer, fbScreenSize); + } + close(fbID); + } - CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " - << fbXOffset << " " << fbYOffset << " " << fbLineLength); - + void FramebufferBackend::destroyAllWindows() { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); + } - backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); - int cnt_channel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + // namedWindow + std::shared_ptr FramebufferBackend::createWindow( + const std::string& winname, + int flags) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.cols * cnt_channel); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" + << winname << ", " << flags << ")"); + return std::make_shared(*this, flags); + } + + void FramebufferBackend::initTermios(int echo, int wait) + { + tcgetattr(0, &old); + current = old; + current.c_lflag &= ~ICANON; + current.c_lflag &= ~ISIG; + current.c_cc[VMIN]=wait; + if (echo) + { + current.c_lflag |= ECHO; + } + else + { + current.c_lflag &= ~ECHO; + } + tcsetattr(0, TCSANOW, ¤t); + } + + void FramebufferBackend::resetTermios(void) + { + tcsetattr(0, TCSANOW, &old); + } + + int FramebufferBackend::getch_(int echo, int wait) + { + int ch; + initTermios(echo, wait); + ch = getchar(); + if(ch < 0) rewind(stdin); + resetTermios(); + return ch; } - } - - FramebufferBackend::~FramebufferBackend() - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); - if(fbID == -1) return; - - // RESTORE BACKGROUNG - if (fbPointer != MAP_FAILED) { - - int cnt_channel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) - { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cnt_channel); - } - - munmap(fbPointer, fbScreenSize); - } - close(fbID); - } - - void FramebufferBackend::destroyAllWindows() { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); - } - - // namedWindow - std::shared_ptr FramebufferBackend::createWindow( - const std::string& winname, - int flags) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" - << winname << ", " << flags << ")"); - return std::make_shared(*this, flags); - } - - void FramebufferBackend::initTermios(int echo, int wait) - { - tcgetattr(0, &old); // grab old terminal i/o settings - current = old; // make new settings same as old settings - current.c_lflag &= ~ICANON; // disable buffered i/o - current.c_lflag &= ~ISIG; - current.c_cc[VMIN]=wait; - if (echo) - { - current.c_lflag |= ECHO; // set echo mode - } - else - { - current.c_lflag &= ~ECHO; // set no echo mode - } - tcsetattr(0, TCSANOW, ¤t); // use these new terminal i/o settings now - } - - void FramebufferBackend::resetTermios(void) - { - tcsetattr(0, TCSANOW, &old); - } - - int FramebufferBackend::getch_(int echo, int wait) - { - int ch; - initTermios(echo, wait); - ch = getchar(); - if(ch < 0) rewind(stdin); - resetTermios(); - return ch; - } - - bool FramebufferBackend::kbhit() - { - int byteswaiting=0; - initTermios(0, 1); - if ( ioctl(0, FIONREAD, &byteswaiting) < 0) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); - } - resetTermios(); - return byteswaiting > 0; - } - - int FramebufferBackend::waitKeyEx(int delay) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); - - int code = -1; - - if(delay <= 0) - { - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; - - while((ch = getch_(0, 0))>=0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } - } - else - { - bool f_kbhit = false; - while(!(f_kbhit = kbhit()) && (delay > 0)) - { - delay -= 1; - usleep(1000); - } - if(f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; + bool FramebufferBackend::kbhit() + { + int byteswaiting=0; + initTermios(0, 1); + if ( ioctl(0, FIONREAD, &byteswaiting) < 0) + { + CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); + } + resetTermios(); - while((ch = getch_(0, 0))>=0) + return byteswaiting > 0; + } + + int FramebufferBackend::waitKeyEx(int delay) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); + + int code = -1; + + if(delay <= 0) + { + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } + else { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; + bool f_kbhit = false; + while(!(f_kbhit = kbhit()) && (delay > 0)) + { + delay -= 1; + usleep(1000); + } + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } } - } + + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); + return code; } - CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); - return code; - } - - int FramebufferBackend::pollKey() - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); - int code = -1; - bool f_kbhit = false; - f_kbhit = kbhit(); - - if(f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; - - while((ch = getch_(0, 0))>=0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } + int FramebufferBackend::pollKey() + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); + int code = -1; + bool f_kbhit = false; + f_kbhit = kbhit(); + + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } + + return code; } - - return code; - } } } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index c589fd12ea94..acdbb6db8f87 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -12,118 +12,118 @@ namespace cv { namespace highgui_backend { enum OpenCVFBMode{ - FB_MODE_EMU, - FB_MODE_FB, - FB_MODE_XVFB + FB_MODE_EMU, + FB_MODE_FB, + FB_MODE_XVFB }; class FramebufferBackend; class CV_EXPORTS FramebufferWindow : public UIWindow { - FramebufferBackend &backend; - std::string FB_ID; - Rect windowRect; - - int flags; - Mat currentImg; + FramebufferBackend &backend; + std::string FB_ID; + Rect windowRect; + + int flags; + Mat currentImg; public: - FramebufferWindow(FramebufferBackend &backend, int flags); - virtual ~FramebufferWindow(); + FramebufferWindow(FramebufferBackend &backend, int flags); + virtual ~FramebufferWindow(); - virtual void imshow(InputArray image)override; + virtual void imshow(InputArray image)override; - virtual double getProperty(int prop) const override; - virtual bool setProperty(int prop, double value)override; + virtual double getProperty(int prop) const override; + virtual bool setProperty(int prop, double value)override; - virtual void resize(int width, int height)override; - virtual void move(int x, int y)override; + virtual void resize(int width, int height)override; + virtual void move(int x, int y)override; - virtual Rect getImageRect() const override; + virtual Rect getImageRect() const override; - virtual void setTitle(const std::string& title)override; + virtual void setTitle(const std::string& title)override; - virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; - virtual std::shared_ptr createTrackbar( - const std::string& name, - int count, - TrackbarCallback onChange /*= 0*/, - void* userdata /*= 0*/ - )override; + virtual std::shared_ptr createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange /*= 0*/, + void* userdata /*= 0*/ + )override; - virtual std::shared_ptr findTrackbar(const std::string& name)override; - - virtual const std::string& getID() const override; + virtual std::shared_ptr findTrackbar(const std::string& name)override; + + virtual const std::string& getID() const override; - virtual bool isActive() const override; + virtual bool isActive() const override; - virtual void destroy() override; -}; // FramebufferWindow + virtual void destroy() override; +}; // FramebufferWindow class CV_EXPORTS FramebufferBackend: public UIBackend { - OpenCVFBMode mode; - - struct termios old, current; - - void initTermios(int echo, int wait); - void resetTermios(void); - int getch_(int echo, int wait); - bool kbhit(); - - - fb_var_screeninfo varInfo; - fb_fix_screeninfo fixInfo; - int fbWidth; - int fbHeight; - int fbXOffset; - int fbYOffset; - int fbBitsPerPixel; - int fbLineLength; - long int fbScreenSize; - unsigned char* fbPointer; - unsigned int fbPointer_dist; - Mat backgroundBuff; - - - int fbOpenAndGetInfo(); - int fbID; - - unsigned int xvfb_len_header; - unsigned int xvfb_len_colors; - unsigned int xvfb_len_pixmap; - int XvfbOpenAndGetInfo(); - + OpenCVFBMode mode; + + struct termios old, current; + + void initTermios(int echo, int wait); + void resetTermios(void); + int getch_(int echo, int wait); + bool kbhit(); + + + fb_var_screeninfo varInfo; + fb_fix_screeninfo fixInfo; + int fbWidth; + int fbHeight; + int fbXOffset; + int fbYOffset; + int fbBitsPerPixel; + int fbLineLength; + long int fbScreenSize; + unsigned char* fbPointer; + unsigned int fbPointer_dist; + Mat backgroundBuff; + + + int fbOpenAndGetInfo(); + int fbID; + + unsigned int xvfb_len_header; + unsigned int xvfb_len_colors; + unsigned int xvfb_len_pixmap; + int XvfbOpenAndGetInfo(); + public: - fb_var_screeninfo &getVarInfo(); - fb_fix_screeninfo &getFixInfo(); - int getFramebuffrerID(); - int getFBWidth(); - int getFBHeight(); - int getFBXOffset(); - int getFBYOffset(); - int getFBBitsPerPixel(); - int getFBLineLength(); - unsigned char* getFBPointer(); - Mat& getBackgroundBuff(); - OpenCVFBMode getMode(); - - FramebufferBackend(); - - virtual ~FramebufferBackend(); - - virtual void destroyAllWindows()override; - - // namedWindow - virtual std::shared_ptr createWindow( - const std::string& winname, - int flags - )override; - - virtual int waitKeyEx(int delay /*= 0*/)override; - virtual int pollKey() override; + fb_var_screeninfo &getVarInfo(); + fb_fix_screeninfo &getFixInfo(); + int getFramebuffrerID(); + int getFBWidth(); + int getFBHeight(); + int getFBXOffset(); + int getFBYOffset(); + int getFBBitsPerPixel(); + int getFBLineLength(); + unsigned char* getFBPointer(); + Mat& getBackgroundBuff(); + OpenCVFBMode getMode(); + + FramebufferBackend(); + + virtual ~FramebufferBackend(); + + virtual void destroyAllWindows()override; + + // namedWindow + virtual std::shared_ptr createWindow( + const std::string& winname, + int flags + )override; + + virtual int waitKeyEx(int delay /*= 0*/)override; + virtual int pollKey() override; }; } From 2c8d7978f02c3fb88805409733bf99667f25a943 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 15:35:40 +0300 Subject: [PATCH 29/81] fix trailing whitespace. --- modules/highgui/src/XWDFile.h | 109 +++++---- modules/highgui/src/Xmd.h | 16 +- modules/highgui/src/window_framebuffer.cpp | 247 ++++++++++----------- modules/highgui/src/window_framebuffer.hpp | 26 +-- 4 files changed, 197 insertions(+), 201 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index cd11d802aca2..0d5f38a09aef 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -25,11 +25,11 @@ in this Software without prior written authorization from The Open Group. */ /* - * XWDFile.h MIT Project Athena, X Window system window raster - * image dumper, dump file format header file. + * XWDFile.h MIT Project Athena, X Window system window raster + * image dumper, dump file format header file. * - * Author: Tony Della Fera, DEC - * 27-Jun-85 + * Author: Tony Della Fera, DEC + * 27-Jun-85 * * Modifier: William F. Wyatt, SAO * 18-Nov-86 - version 6 for saving/restoring color maps @@ -52,60 +52,60 @@ in this Software without prior written authorization from The Open Group. * Start. Added from *****************************************************************/ -#define XYBitmap 0 /* depth 1, XYFormat */ -#define XYPixmap 1 /* depth == drawable depth */ -#define ZPixmap 2 /* depth == drawable depth */ +#define XYBitmap 0 /* depth 1, XYFormat */ +#define XYPixmap 1 /* depth == drawable depth */ +#define ZPixmap 2 /* depth == drawable depth */ /***************************************************************** * End. Added from *****************************************************************/ -typedef CARD32 xwdval; /* for old broken programs */ +typedef CARD32 xwdval; /* for old broken programs */ /* Values in the file are most significant byte first. */ typedef struct _xwd_file_header { - /* header_size = SIZEOF(XWDheader) + length of null-terminated - * window name. */ - CARD32 header_size; - - CARD32 file_version; /* = XWD_FILE_VERSION above */ - CARD32 pixmap_format; /* ZPixmap or XYPixmap */ - CARD32 pixmap_depth; /* Pixmap depth */ - CARD32 pixmap_width; /* Pixmap width */ - CARD32 pixmap_height; /* Pixmap height */ - CARD32 xoffset; /* Bitmap x offset, normally 0 */ - CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ - - /* bitmap_unit applies to bitmaps (depth 1 format XY) only. - * It is the number of bits that each scanline is padded to. */ - CARD32 bitmap_unit; - - CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ - - /* bitmap_pad applies to pixmaps (non-bitmaps) only. - * It is the number of bits that each scanline is padded to. */ - CARD32 bitmap_pad; - - CARD32 bits_per_pixel; /* Bits per pixel */ - - /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) - * or bitmap_pad (pixmaps). It is the delta (in bytes) to get - * to the same x position on an adjacent row. */ - CARD32 bytes_per_line; - CARD32 visual_class; /* Class of colormap */ - CARD32 red_mask; /* Z red mask */ - CARD32 green_mask; /* Z green mask */ - CARD32 blue_mask; /* Z blue mask */ - CARD32 bits_per_rgb; /* Log2 of distinct color values */ - CARD32 colormap_entries; /* Number of entries in colormap; not used? */ - CARD32 ncolors; /* Number of XWDColor structures */ - CARD32 window_width; /* Window width */ - CARD32 window_height; /* Window height */ - CARD32 window_x; /* Window upper left X coordinate */ - CARD32 window_y; /* Window upper left Y coordinate */ - CARD32 window_bdrwidth; /* Window border width */ + /* header_size = SIZEOF(XWDheader) + length of null-terminated + * window name. */ + CARD32 header_size; + + CARD32 file_version; /* = XWD_FILE_VERSION above */ + CARD32 pixmap_format; /* ZPixmap or XYPixmap */ + CARD32 pixmap_depth; /* Pixmap depth */ + CARD32 pixmap_width; /* Pixmap width */ + CARD32 pixmap_height; /* Pixmap height */ + CARD32 xoffset; /* Bitmap x offset, normally 0 */ + CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ + + /* bitmap_unit applies to bitmaps (depth 1 format XY) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_unit; + + CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ + + /* bitmap_pad applies to pixmaps (non-bitmaps) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_pad; + + CARD32 bits_per_pixel; /* Bits per pixel */ + + /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) + * or bitmap_pad (pixmaps). It is the delta (in bytes) to get + * to the same x position on an adjacent row. */ + CARD32 bytes_per_line; + CARD32 visual_class; /* Class of colormap */ + CARD32 red_mask; /* Z red mask */ + CARD32 green_mask; /* Z green mask */ + CARD32 blue_mask; /* Z blue mask */ + CARD32 bits_per_rgb; /* Log2 of distinct color values */ + CARD32 colormap_entries; /* Number of entries in colormap; not used? */ + CARD32 ncolors; /* Number of XWDColor structures */ + CARD32 window_width; /* Window width */ + CARD32 window_height; /* Window height */ + CARD32 window_x; /* Window upper left X coordinate */ + CARD32 window_y; /* Window upper left Y coordinate */ + CARD32 window_bdrwidth; /* Window border width */ } XWDFileHeader; /* Null-terminated window name follows the above structure. */ @@ -116,15 +116,14 @@ typedef struct _xwd_file_header { */ typedef struct { - CARD32 pixel; - CARD16 red; - CARD16 green; - CARD16 blue; - CARD8 flags; - CARD8 pad; + CARD32 pixel; + CARD16 red; + CARD16 green; + CARD16 blue; + CARD8 flags; + CARD8 pad; } XWDColor; /* Last comes the image data in the format described by XWDFileHeader. */ #endif /* XWDFILE_H */ - diff --git a/modules/highgui/src/Xmd.h b/modules/highgui/src/Xmd.h index 68c45dbec0ee..431d36de9618 100644 --- a/modules/highgui/src/Xmd.h +++ b/modules/highgui/src/Xmd.h @@ -59,7 +59,7 @@ SOFTWARE. #if defined(__SIZEOF_LONG__) # if __SIZEOF_LONG__ == 8 -# define LONG64 /* 32/64-bit architecture */ +# define LONG64 /* 32/64-bit architecture */ # endif # elif defined (_LP64) || defined(__LP64__) || \ defined(__alpha) || defined(__alpha__) || \ @@ -68,8 +68,8 @@ SOFTWARE. defined(__s390x__) || \ defined(__amd64__) || defined(amd64) || \ defined(__powerpc64__) -# if !defined(__ILP32__) /* amd64-x32 is 32bit */ -# define LONG64 /* 32/64-bit architecture */ +# if !defined(__ILP32__) /* amd64-x32 is 32bit */ +# define LONG64 /* 32/64-bit architecture */ # endif /* !__ILP32__ */ # endif @@ -105,7 +105,7 @@ typedef long INT32; # endif typedef short INT16; -typedef signed char INT8; +typedef signed char INT8; # ifdef LONG64 typedef unsigned long CARD64; @@ -117,11 +117,11 @@ typedef unsigned long CARD32; typedef unsigned short CARD16; typedef unsigned char CARD8; -typedef CARD32 BITS32; -typedef CARD16 BITS16; +typedef CARD32 BITS32; +typedef CARD16 BITS16; -typedef CARD8 BYTE; -typedef CARD8 BOOL; +typedef CARD8 BYTE; +typedef CARD8 BOOL; /* * was definitions for sign-extending bitfields on architectures without diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index eebe24c34d36..873e4fbbb0c1 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -32,36 +32,36 @@ namespace cv { namespace highgui_backend { static std::string& getFBMode() { - static std::string fbModeOpenCV = + static std::string fbModeOpenCV = cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); static std::string fbModeDef = "FB"; - + if(!fbModeOpenCV.empty()) return fbModeOpenCV; return fbModeDef; } static std::string& getFBFileName() { - static std::string fbFileNameFB = + static std::string fbFileNameFB = cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); - static std::string fbFileNameOpenCV = + static std::string fbFileNameOpenCV = cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); static std::string fbFileNameDef = "/dev/fb0"; - + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; if(!fbFileNameFB.empty()) return fbFileNameFB; return fbFileNameDef; } - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): backend(_backend), flags(_flags) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); } - + FramebufferWindow::~FramebufferWindow() { CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); @@ -70,13 +70,13 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::imshow(InputArray image) { currentImg = image.getMat().clone(); - + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " << cv::typeToString(image.type()) << " size " << image.size()); - + if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) - { + { return; } @@ -109,12 +109,12 @@ namespace cv { namespace highgui_backend { break; } cvtColor(img, img, COLOR_RGB2BGRA); - + int newWidth = windowRect.width; int newHeight = windowRect.height; int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - + if(flags & WINDOW_AUTOSIZE) { windowRect.width = imgSize.width; @@ -122,7 +122,7 @@ namespace cv { namespace highgui_backend { newWidth = windowRect.width; newHeight = windowRect.height; } - + if(flags & WINDOW_FREERATIO) { newWidth = windowRect.width; @@ -143,8 +143,8 @@ namespace cv { namespace highgui_backend { if((newWidth != img.cols) && (newHeight != img.rows)) { cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); - } - + } + CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -158,14 +158,14 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } - + // SHOW IMAGE int xOffset = backend.getFBXOffset(); int yOffset = backend.getFBYOffset(); int fbHeight = backend.getFBHeight(); int fbWidth = backend.getFBWidth(); int lineLength = backend.getFBLineLength(); - + int img_start_x; int img_start_y; int img_end_x; @@ -173,62 +173,62 @@ namespace cv { namespace highgui_backend { int fb_start_x; int fb_start_y; - if(windowRect.y - yOffset < 0) - { + if(windowRect.y - yOffset < 0) + { img_start_y = - (windowRect.y - yOffset); } - else - { + else + { img_start_y = 0; } - if(windowRect.x - xOffset < 0) - { + if(windowRect.x - xOffset < 0) + { img_start_x = - (windowRect.x - xOffset); } - else + else { img_start_x = 0; } - - if(windowRect.y + yOffset + img.rows > fbHeight) + + if(windowRect.y + yOffset + img.rows > fbHeight) { - img_end_y = fbHeight - windowRect.y - yOffset; + img_end_y = fbHeight - windowRect.y - yOffset; } else { img_end_y = img.rows; } - if(windowRect.x + xOffset + img.cols > fbWidth) + if(windowRect.x + xOffset + img.cols > fbWidth) { - img_end_x = fbWidth - windowRect.x - xOffset; + img_end_x = fbWidth - windowRect.x - xOffset; } - else + else { img_end_x = img.cols; } - - if(windowRect.y + yOffset >= 0) + + if(windowRect.y + yOffset >= 0) { - fb_start_y = windowRect.y + yOffset; + fb_start_y = windowRect.y + yOffset; } - else + else { fb_start_y = 0; } - if(windowRect.x + xOffset >= 0) + if(windowRect.x + xOffset >= 0) { - fb_start_x = windowRect.x + xOffset; + fb_start_x = windowRect.x + xOffset; } - else + else { fb_start_x = 0; } - + for (int y = img_start_y; y < img_end_y; y++) { - std::memcpy(backend.getFBPointer() + - (fb_start_y + y - img_start_y) * lineLength + fb_start_x, - img.ptr(y) + img_start_x * cntChannel, + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, (img_end_x - img_start_x) * cntChannel); } } @@ -241,7 +241,7 @@ namespace cv { namespace highgui_backend { return 0.0; } - bool FramebufferWindow::setProperty(int prop, double value) + bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " << prop << ", value " << value << ")"); @@ -252,9 +252,9 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " + CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " << width <<", height " << height << ")"); - + CV_Assert(width > 0); CV_Assert(height > 0); @@ -262,14 +262,15 @@ namespace cv { namespace highgui_backend { { windowRect.width = width; windowRect.height = height; - + if((currentImg.cols > 0) && (currentImg.rows > 0)) - { + { imshow(currentImg); } } } - void FramebufferWindow::move(int x, int y) + + void FramebufferWindow::move(int x, int y) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); @@ -277,18 +278,18 @@ namespace cv { namespace highgui_backend { windowRect.y = y; if((currentImg.cols > 0) && (currentImg.rows > 0)) - { + { imshow(currentImg); } } - Rect FramebufferWindow::getImageRect() const + Rect FramebufferWindow::getImageRect() const { CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); return windowRect; } - void FramebufferWindow::setTitle(const std::string& title) + void FramebufferWindow::setTitle(const std::string& title) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); @@ -317,20 +318,20 @@ namespace cv { namespace highgui_backend { CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); return nullptr; } - - const std::string& FramebufferWindow::getID() const - { + + const std::string& FramebufferWindow::getID() const + { CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); return FB_ID; } - bool FramebufferWindow::isActive() const + bool FramebufferWindow::isActive() const { CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); return true; } - void FramebufferWindow::destroy() + void FramebufferWindow::destroy() { CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } @@ -342,7 +343,7 @@ namespace cv { namespace highgui_backend { std::string fbFileName = getFBFileName(); CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); - + int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { @@ -354,30 +355,30 @@ namespace cv { namespace highgui_backend { if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); - return -1; + return -1; } // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } - - CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" << " green offset " <xoffset ); return -1; } - - unsigned int r = C32INT(&(xwd_header-> red_mask)); + + unsigned int r = C32INT(&(xwd_header-> red_mask)); unsigned int g = C32INT(&(xwd_header->green_mask)); unsigned int b = C32INT(&(xwd_header-> blue_mask)); @@ -452,15 +453,15 @@ namespace cv { namespace highgui_backend { fbYOffset = 0; fbLineLength = C32INT(&(xwd_header->bytes_per_line)); fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); - - CV_LOG_INFO(NULL, "UI: XVFB info: \n" + + CV_LOG_INFO(NULL, "UI: XVFB info: \n" << " red_mask " << r << "\n" << " green_mask " << g << "\n" << " blue_mask " << b << "\n" << "bits_per_pixel " << fbBitsPerPixel); - - if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32) ) + + if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32)) { CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " << "(use BGRA format with bits_per_pixel = 32)"); @@ -469,14 +470,14 @@ namespace cv { namespace highgui_backend { xvfb_len_header = C32INT(&(xwd_header->header_size)); xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); - xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * C32INT(&(xwd_header->pixmap_height)); munmap(xwd_header, sizeof(XWDFileHeader)); fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; - xwd_header = (XWDFileHeader*) - mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); - fbPointer = (unsigned char*)xwd_header ; + xwd_header = (XWDFileHeader*) + mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header; fbPointer_dist = xvfb_len_header + xvfb_len_colors; return fb_fd; @@ -484,7 +485,7 @@ namespace cv { namespace highgui_backend { fb_var_screeninfo &FramebufferBackend::getVarInfo() { - return varInfo; + return varInfo; } fb_fix_screeninfo &FramebufferBackend::getFixInfo() @@ -545,9 +546,9 @@ namespace cv { namespace highgui_backend { FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - + std::string fbModeStr = getFBMode(); - + if(fbModeStr == "EMU") { mode = FB_MODE_EMU; @@ -573,9 +574,9 @@ namespace cv { namespace highgui_backend { { fbID = XvfbOpenAndGetInfo(); } - + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - + if(fbID == -1){ mode = FB_MODE_EMU; fbWidth = 1024; @@ -584,42 +585,40 @@ namespace cv { namespace highgui_backend { fbYOffset = 0; fbBitsPerPixel = 0; fbLineLength = 0; - + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); return; } - - - CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); - CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " << fbXOffset << " " << fbYOffset << " " << fbLineLength); - backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset, + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset, backgroundBuff.cols * cnt_channel); } } - + FramebufferBackend::~FramebufferBackend() { CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); if(fbID == -1) return; - + // RESTORE BACKGROUNG if (fbPointer != MAP_FAILED) { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), backgroundBuff.cols * cnt_channel); } @@ -637,12 +636,12 @@ namespace cv { namespace highgui_backend { const std::string& winname, int flags) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" + CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" << winname << ", " << flags << ")"); return std::make_shared(*this, flags); } - void FramebufferBackend::initTermios(int echo, int wait) + void FramebufferBackend::initTermios(int echo, int wait) { tcgetattr(0, &old); current = old; @@ -660,12 +659,12 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, ¤t); } - void FramebufferBackend::resetTermios(void) + void FramebufferBackend::resetTermios(void) { tcsetattr(0, TCSANOW, &old); } - int FramebufferBackend::getch_(int echo, int wait) + int FramebufferBackend::getch_(int echo, int wait) { int ch; initTermios(echo, wait); @@ -674,7 +673,7 @@ namespace cv { namespace highgui_backend { resetTermios(); return ch; } - + bool FramebufferBackend::kbhit() { int byteswaiting=0; @@ -684,11 +683,11 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); } resetTermios(); - + return byteswaiting > 0; } - int FramebufferBackend::waitKeyEx(int delay) + int FramebufferBackend::waitKeyEx(int delay) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); @@ -699,22 +698,22 @@ namespace cv { namespace highgui_backend { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - + while((ch = getch_(0, 0))>=0) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); code = ch; } - } - else + } + else { bool f_kbhit = false; while(!(f_kbhit = kbhit()) && (delay > 0)) { delay -= 1; usleep(1000); - } + } if(f_kbhit) { CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); @@ -722,20 +721,20 @@ namespace cv { namespace highgui_backend { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - + while((ch = getch_(0, 0))>=0) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); code = ch; } } } - + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); - return code; + return code; } - + int FramebufferBackend::pollKey() { CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); @@ -750,15 +749,15 @@ namespace cv { namespace highgui_backend { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - + while((ch = getch_(0, 0))>=0) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); code = ch; } } - + return code; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index acdbb6db8f87..3307ccb5eb87 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -23,7 +23,7 @@ class CV_EXPORTS FramebufferWindow : public UIWindow FramebufferBackend &backend; std::string FB_ID; Rect windowRect; - + int flags; Mat currentImg; @@ -31,35 +31,35 @@ class CV_EXPORTS FramebufferWindow : public UIWindow FramebufferWindow(FramebufferBackend &backend, int flags); virtual ~FramebufferWindow(); - virtual void imshow(InputArray image)override; + virtual void imshow(InputArray image) override; virtual double getProperty(int prop) const override; - virtual bool setProperty(int prop, double value)override; + virtual bool setProperty(int prop, double value) override; - virtual void resize(int width, int height)override; - virtual void move(int x, int y)override; + virtual void resize(int width, int height) override; + virtual void move(int x, int y) override; virtual Rect getImageRect() const override; - virtual void setTitle(const std::string& title)override; + virtual void setTitle(const std::string& title) override; - virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override; virtual std::shared_ptr createTrackbar( const std::string& name, int count, TrackbarCallback onChange /*= 0*/, void* userdata /*= 0*/ - )override; + ) override; + + virtual std::shared_ptr findTrackbar(const std::string& name) override; - virtual std::shared_ptr findTrackbar(const std::string& name)override; - virtual const std::string& getID() const override; virtual bool isActive() const override; virtual void destroy() override; -}; // FramebufferWindow +}; // FramebufferWindow class CV_EXPORTS FramebufferBackend: public UIBackend { @@ -71,7 +71,6 @@ class CV_EXPORTS FramebufferBackend: public UIBackend void resetTermios(void); int getch_(int echo, int wait); bool kbhit(); - fb_var_screeninfo varInfo; fb_fix_screeninfo fixInfo; @@ -86,7 +85,6 @@ class CV_EXPORTS FramebufferBackend: public UIBackend unsigned int fbPointer_dist; Mat backgroundBuff; - int fbOpenAndGetInfo(); int fbID; @@ -94,7 +92,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend unsigned int xvfb_len_colors; unsigned int xvfb_len_pixmap; int XvfbOpenAndGetInfo(); - + public: fb_var_screeninfo &getVarInfo(); From a29ebab8194c1c25f633be5062491241885f8f64 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 17:26:48 +0300 Subject: [PATCH 30/81] fix trailing whitespace. --- modules/highgui/src/XWDFile.h | 3 ++- modules/highgui/src/window_framebuffer.cpp | 6 +++--- modules/highgui/src/window_framebuffer.hpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index 0d5f38a09aef..20ebf568e8e3 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -46,7 +46,8 @@ in this Software without prior written authorization from The Open Group. #define sz_XWDColor 12 // Added macro to convert big-endian numbers to local representation -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | \ + (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) /***************************************************************** * Start. Added from diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 873e4fbbb0c1..0236fd5ac5fd 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -257,7 +257,7 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - + if(!(flags & WINDOW_AUTOSIZE)) { windowRect.width = width; @@ -648,10 +648,10 @@ namespace cv { namespace highgui_backend { current.c_lflag &= ~ICANON; current.c_lflag &= ~ISIG; current.c_cc[VMIN]=wait; - if (echo) + if (echo) { current.c_lflag |= ECHO; - } + } else { current.c_lflag &= ~ECHO; diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 3307ccb5eb87..6156c552995c 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -121,7 +121,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend )override; virtual int waitKeyEx(int delay /*= 0*/)override; - virtual int pollKey() override; + virtual int pollKey() override; }; } From 1a8e00f5beb1fcc65999b9fce94b89534af324e8 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 17:52:51 +0300 Subject: [PATCH 31/81] fix trailing whitespace. --- modules/highgui/src/window_framebuffer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 0236fd5ac5fd..fe149ee8f072 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -99,7 +99,7 @@ namespace cv { namespace highgui_backend { img.convertTo(img, CV_8U, 255., 0.); break; } - cvtColor(img, img, cv::COLOR_GRAY2RGB); + cvtColor(img, img, cv::COLOR_GRAY2RGB); break; case 3: convertToShow(img, img); @@ -175,7 +175,7 @@ namespace cv { namespace highgui_backend { if(windowRect.y - yOffset < 0) { - img_start_y = - (windowRect.y - yOffset); + img_start_y = - (windowRect.y - yOffset); } else { @@ -183,7 +183,7 @@ namespace cv { namespace highgui_backend { } if(windowRect.x - xOffset < 0) { - img_start_x = - (windowRect.x - xOffset); + img_start_x = - (windowRect.x - xOffset); } else { @@ -194,7 +194,7 @@ namespace cv { namespace highgui_backend { { img_end_y = fbHeight - windowRect.y - yOffset; } - else + else { img_end_y = img.rows; } @@ -243,7 +243,7 @@ namespace cv { namespace highgui_backend { bool FramebufferWindow::setProperty(int prop, double value) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " << prop << ", value " << value << ")"); CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); @@ -352,7 +352,7 @@ namespace cv { namespace highgui_backend { } // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; @@ -430,7 +430,7 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); return -1; } - + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ) { CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); @@ -652,7 +652,7 @@ namespace cv { namespace highgui_backend { { current.c_lflag |= ECHO; } - else + else { current.c_lflag &= ~ECHO; } From 35a6c9c590cccaecc5972e5f62ac5d4fd8eb5d5f Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 2 Apr 2024 18:15:03 +0000 Subject: [PATCH 32/81] template for framebuffer highgui --- CMakeLists.txt | 4 + modules/highgui/CMakeLists.txt | 14 ++++ modules/highgui/src/backend.hpp | 5 ++ modules/highgui/src/registry.impl.hpp | 5 ++ modules/highgui/src/window_framebuffer.cpp | 96 ++++++++++++++++++++++ modules/highgui/src/window_framebuffer.hpp | 68 +++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 modules/highgui/src/window_framebuffer.cpp create mode 100644 modules/highgui/src/window_framebuffer.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f5e39b4c71be..0e7b0336e69d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,6 +304,10 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_GTK AND NOT HAVE_GTK3) + +OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF + VISIBLE_IF UNIX VERIFY HAVE_FRAMEBUFFER) + OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_WAYLAND) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index d8a7bb050ab2..82cb44bbdf0f 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -39,6 +39,17 @@ if(HAVE_WEBP) add_definitions(-DHAVE_WEBP) endif() + +if(WITH_FRAMEBUFFER) + message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") + add_definitions(-DHAVE_FRAMEBUFFER) + list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) +else() + message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") +endif() + + file(GLOB highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp" "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp" @@ -180,6 +191,9 @@ elseif(HAVE_COCOA) list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa") endif() + + + if(TARGET ocv.3rdparty.win32ui) if("win32ui" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all") ocv_create_builtin_highgui_plugin(opencv_highgui_win32 ocv.3rdparty.win32ui "window_w32.cpp") diff --git a/modules/highgui/src/backend.hpp b/modules/highgui/src/backend.hpp index 93d51da11966..6174a2c3611d 100644 --- a/modules/highgui/src/backend.hpp +++ b/modules/highgui/src/backend.hpp @@ -127,6 +127,11 @@ std::shared_ptr createUIBackendGTK(); std::shared_ptr createUIBackendQT(); #endif +#ifdef HAVE_FRAMEBUFFER +std::shared_ptr createUIBackendFramebuffer(); +#endif + + #endif // BUILD_PLUGIN } // namespace highgui_backend diff --git a/modules/highgui/src/registry.impl.hpp b/modules/highgui/src/registry.impl.hpp index 23f4e9f4e1a0..956cb969c901 100644 --- a/modules/highgui/src/registry.impl.hpp +++ b/modules/highgui/src/registry.impl.hpp @@ -44,6 +44,11 @@ std::vector& getBuiltinBackendsInfo() DECLARE_DYNAMIC_BACKEND("GTK2") #endif +#ifdef HAVE_FRAMEBUFFER + DECLARE_STATIC_BACKEND("Framebuffer", createUIBackendFramebuffer) +#endif + + #if 0 // TODO #ifdef HAVE_QT DECLARE_STATIC_BACKEND("QT", createUIBackendQT) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp new file mode 100644 index 000000000000..4cf1093d2d98 --- /dev/null +++ b/modules/highgui/src/window_framebuffer.cpp @@ -0,0 +1,96 @@ +#include "window_framebuffer.hpp" + +#include "opencv2/core/utils/logger.hpp" + +namespace cv { namespace highgui_backend { + + std::shared_ptr createUIBackendFramebuffer() + { + return std::make_shared(); + } + + + void FramebufferWindow::imshow(InputArray image){ + std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; + } + + double FramebufferWindow::getProperty(int prop) const{ + std::cout << "FramebufferWindow::getProperty(int prop:" << prop <<")"<< std::endl; + return 0.0; + } + bool FramebufferWindow::setProperty(int prop, double value) { + std::cout << "FramebufferWindow::setProperty(int prop "<< prop <<", double value "< FramebufferWindow::createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange, + void* userdata + ){ + return nullptr; + } + + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name){ + return nullptr; + } + + const std::string& FramebufferWindow::getID() const { + std::cout << "getID())" << std::endl; return FB_ID; + } + + bool FramebufferWindow::isActive() const { + std::cout << "isActive()" << std::endl; + return true; + } + + void FramebufferWindow::destroy() { + std::cout << "destroy()" << std::endl; + } + + void FramebufferBackend::destroyAllWindows() { + std::cout << "destroyAllWindows()" << std::endl; + } + + // namedWindow + std::shared_ptr FramebufferBackend::createWindow( + const std::string& winname, + int flags + ){ + std::cout << "FramebufferBackend::createWindow("<< winname <<", "<(); + } + + int FramebufferBackend::waitKeyEx(int delay) { + std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; + return 0; + } + int FramebufferBackend::pollKey() { + std::cout << "FramebufferBackend::pollKey()" << std::endl; + return 0; + } + + +} +} diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp new file mode 100644 index 000000000000..c56e772b2e9d --- /dev/null +++ b/modules/highgui/src/window_framebuffer.hpp @@ -0,0 +1,68 @@ +#ifndef OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP +#define OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP + +#include "precomp.hpp" +#include "backend.hpp" + +namespace cv { namespace highgui_backend { + +class CV_EXPORTS FramebufferWindow : public UIWindow +{ + std::string FB_ID; +public: + FramebufferWindow(){FB_ID = "FramebufferWindow";} + virtual ~FramebufferWindow(){} + + virtual void imshow(InputArray image)override; + + virtual double getProperty(int prop) const override; + virtual bool setProperty(int prop, double value)override; + + virtual void resize(int width, int height)override; + virtual void move(int x, int y)override; + + virtual Rect getImageRect() const override; + + virtual void setTitle(const std::string& title)override; + + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + + virtual std::shared_ptr createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange /*= 0*/, + void* userdata /*= 0*/ + )override; + + virtual std::shared_ptr findTrackbar(const std::string& name)override; + + virtual const std::string& getID() const override; + + virtual bool isActive() const override; + + virtual void destroy() override; +}; // FramebufferWindow + +class CV_EXPORTS FramebufferBackend: public UIBackend +{ +public: + virtual ~FramebufferBackend(){} + + virtual void destroyAllWindows()override; + + // namedWindow + virtual std::shared_ptr createWindow( + const std::string& winname, + int flags + ); + + virtual int waitKeyEx(int delay /*= 0*/)override; + virtual int pollKey() override; +}; + +} + +} + + +#endif From 872594d59b98dc99d542b94ebf6cda1404e76de7 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 16 Apr 2024 20:05:14 +0300 Subject: [PATCH 33/81] add imshow --- modules/highgui/src/window_framebuffer.cpp | 127 +++++++++++++++++++++ modules/highgui/src/window_framebuffer.hpp | 82 ++++++++----- 2 files changed, 179 insertions(+), 30 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 4cf1093d2d98..bc1dca4051e6 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -2,6 +2,18 @@ #include "opencv2/core/utils/logger.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opencv2/imgproc.hpp" + + namespace cv { namespace highgui_backend { std::shared_ptr createUIBackendFramebuffer() @@ -9,9 +21,124 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } + int FramebufferWindow::fb_open_and_get_info() + { + int fb_fd = open("/dev/fb0", O_RDWR); + if (fb_fd == -1) + { + std::cerr << "ERROR_OPENING_FB\n"; + return -1; + } + + // Get fixed screen information + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { + std::cerr << "ERROR_READING_FIX_INFO\n"; + return -1; + } + + // Get variable screen information + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { + std::cerr << "EERROR_READING_VAR_INFO\n"; + return -1; + } + + return fb_fd; + } + + FramebufferWindow::FramebufferWindow() + { + std::cout << "FramebufferWindow()" << std::endl; + FB_ID = "FramebufferWindow"; + framebuffrer_id = fb_open_and_get_info(); + std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + if(framebuffrer_id == -1) return; + + fb_w = var_info.xres; + fb_h = var_info.yres; + y_offset = var_info.yoffset; + x_offset = var_info.xoffset; + bpp = var_info.bits_per_pixel; + line_length = fix_info.line_length; + + std::cout << "= Framebuffer's width, height, bits per pix:\n" + << fb_w << " " << fb_h << " " << bpp << "\n\n"; + std::cout << "= Framebuffer's offsets, line length:\n" + << y_offset << " " << x_offset << " " << line_length << "\n\n"; + + // MAP FB TO MEMORY + screensize = fb_w * fb_h * bpp / 8; + fbPointer = (unsigned char*) + mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, + framebuffrer_id, 0); + if (fbPointer == MAP_FAILED) { + std::cerr << "ERROR_MAP\n"; + return; + } + + backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(backgroundBuff.ptr(y - y_offset), + fbPointer + y * line_length, + backgroundBuff.cols * cnt_channel); + } + + + } void FramebufferWindow::imshow(InputArray image){ std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; + std::cout << "InputArray image:: size" << image.size() << std::endl; + if (fbPointer == MAP_FAILED) { + return; + } + + Mat img; + cvtColor(image, img, COLOR_RGB2RGBA); + // changing the image size to match the entered width + double aspect_ratio = static_cast(img.cols) / img.rows; + int new_width = fb_w; + int new_height = static_cast(fb_w / aspect_ratio); + int cnt_channel = img.channels(); + + std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; + std::cout << "= Image count of channels:\n" << img.channels() << "\n"; + + // RECIZE IMAGE TO MATCH THE FB SIZE + if (new_width > fb_w || new_height > fb_h) { + if (aspect_ratio > static_cast(fb_w) / fb_h) { + new_width = fb_w; + new_height = static_cast(fb_w / aspect_ratio); + } else { + new_height = fb_h; + new_width = static_cast(fb_h * aspect_ratio); + } + } + cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); + + std::cout << "= Recized image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + + // RESTORE BACKGROUNG + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length, + backgroundBuff.ptr(y - y_offset), + backgroundBuff.cols*cnt_channel); + } + + + + // SHOW IMAGE + for (int y = y_offset; y < img.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length, + img.ptr(y - y_offset), + img.cols*cnt_channel); + } + + } double FramebufferWindow::getProperty(int prop) const{ diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index c56e772b2e9d..3b1a81628692 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -4,60 +4,82 @@ #include "precomp.hpp" #include "backend.hpp" +#include +#include + + namespace cv { namespace highgui_backend { class CV_EXPORTS FramebufferWindow : public UIWindow { + fb_var_screeninfo var_info; + fb_fix_screeninfo fix_info; + std::string FB_ID; + + int fb_open_and_get_info(); + int framebuffrer_id; + + int fb_w; + int fb_h; + int y_offset; + int x_offset; + int bpp; + int line_length; + long int screensize; + unsigned char* fbPointer; + + Mat backgroundBuff; + public: - FramebufferWindow(){FB_ID = "FramebufferWindow";} - virtual ~FramebufferWindow(){} + FramebufferWindow(); + virtual ~FramebufferWindow(){} - virtual void imshow(InputArray image)override; + virtual void imshow(InputArray image)override; - virtual double getProperty(int prop) const override; - virtual bool setProperty(int prop, double value)override; + virtual double getProperty(int prop) const override; + virtual bool setProperty(int prop, double value)override; - virtual void resize(int width, int height)override; - virtual void move(int x, int y)override; + virtual void resize(int width, int height)override; + virtual void move(int x, int y)override; - virtual Rect getImageRect() const override; + virtual Rect getImageRect() const override; - virtual void setTitle(const std::string& title)override; + virtual void setTitle(const std::string& title)override; - virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; - virtual std::shared_ptr createTrackbar( - const std::string& name, - int count, - TrackbarCallback onChange /*= 0*/, - void* userdata /*= 0*/ - )override; + virtual std::shared_ptr createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange /*= 0*/, + void* userdata /*= 0*/ + )override; - virtual std::shared_ptr findTrackbar(const std::string& name)override; - - virtual const std::string& getID() const override; + virtual std::shared_ptr findTrackbar(const std::string& name)override; + + virtual const std::string& getID() const override; - virtual bool isActive() const override; + virtual bool isActive() const override; - virtual void destroy() override; + virtual void destroy() override; }; // FramebufferWindow class CV_EXPORTS FramebufferBackend: public UIBackend { public: - virtual ~FramebufferBackend(){} + virtual ~FramebufferBackend(){} - virtual void destroyAllWindows()override; + virtual void destroyAllWindows()override; - // namedWindow - virtual std::shared_ptr createWindow( - const std::string& winname, - int flags - ); + // namedWindow + virtual std::shared_ptr createWindow( + const std::string& winname, + int flags + ); - virtual int waitKeyEx(int delay /*= 0*/)override; - virtual int pollKey() override; + virtual int waitKeyEx(int delay /*= 0*/)override; + virtual int pollKey() override; }; } From b241ef04eccf63767ddfed1a8a5c1b57c3e11316 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 16 Apr 2024 23:13:20 +0300 Subject: [PATCH 34/81] temporary implementation of waitKey --- modules/highgui/src/window_framebuffer.cpp | 126 ++++++++++++++++++++- modules/highgui/src/window_framebuffer.hpp | 16 ++- 2 files changed, 139 insertions(+), 3 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index bc1dca4051e6..067e3e40b069 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ namespace cv { namespace highgui_backend { return fb_fd; } + FramebufferWindow::FramebufferWindow() { @@ -51,6 +53,7 @@ namespace cv { namespace highgui_backend { FB_ID = "FramebufferWindow"; framebuffrer_id = fb_open_and_get_info(); std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + if(framebuffrer_id == -1) return; fb_w = var_info.xres; @@ -86,6 +89,25 @@ namespace cv { namespace highgui_backend { } + + FramebufferWindow::~FramebufferWindow(){ + + if(framebuffrer_id == -1) return; + + // RESTORE BACKGROUNG + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length, + backgroundBuff.ptr(y - y_offset), + backgroundBuff.cols*cnt_channel); + } + + if (fbPointer != MAP_FAILED) { + munmap(fbPointer, screensize); + } + close(framebuffrer_id); + } void FramebufferWindow::imshow(InputArray image){ std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; @@ -196,6 +218,32 @@ namespace cv { namespace highgui_backend { std::cout << "destroy()" << std::endl; } + int FramebufferBackend::OpenInputEvent() + { + int fd; + fd = open("/dev/input/event1", O_RDONLY); + if (fd == -1) { + std::cerr << "ERROR_OPENING_INPUT\n"; + return -1; + } + return fd; + } + + + FramebufferBackend::FramebufferBackend() + { + eventKey = OpenInputEvent(); + std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; + } + + FramebufferBackend::~FramebufferBackend() + { + if(eventKey != -1) + { + close(eventKey); + } + } + void FramebufferBackend::destroyAllWindows() { std::cout << "destroyAllWindows()" << std::endl; } @@ -209,9 +257,85 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } + void FramebufferBackend::initTermios(int echo) + { + tcgetattr(0, &old); /* grab old terminal i/o settings */ + current = old; /* make new settings same as old settings */ + current.c_lflag &= ~ICANON; /* disable buffered i/o */ + if (echo) { + current.c_lflag |= ECHO; /* set echo mode */ + } else { + current.c_lflag &= ~ECHO; /* set no echo mode */ + } + tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ + } + + /* Restore old terminal i/o settings */ + void FramebufferBackend::resetTermios(void) + { + tcsetattr(0, TCSANOW, &old); + } + + char FramebufferBackend::getch_(int echo) + { + char ch; + initTermios(echo); + ch = getchar(); + resetTermios(); + return ch; + } + int FramebufferBackend::waitKeyEx(int delay) { std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; - return 0; + + int code = 0; + + char ch = getch_(0); + std::cout << "ch 1 " << (int)ch << std::endl; + code = ch; + + if(code == 27) + { + ch = getch_(0); + std::cout << "ch 2 " << (int)ch << std::endl; + // code = ch * 1000; + ch = getch_(0); + std::cout << "ch 2 " << (int)ch << std::endl; + // code += ch * 1000000; + code = ch; + } + +// struct input_event events; +// +// +// ssize_t r = 1; +// while(r > 0) +// { +// std::cout << "while 1 " << std::endl; +// r = read(eventKey, &events, sizeof(input_event)); +// std::cout << "while 1 " << std::endl; +// } +// +// +// +// while((r == 0)&& ((delay > 1) || (delay == 0)) ) +// { +// delay--; +// usleep(1); +// r = read(eventKey, &events, sizeof(input_event)); +// std::cout << "while 2 " << std::endl; +// +// if(r != 0){ +// code = (events.code); +// } +// } +// + std::cout << "waitKeyEx:: code "<< code << std::endl; +// +// if(r == 0) +// return -1; +// + return code; } int FramebufferBackend::pollKey() { std::cout << "FramebufferBackend::pollKey()" << std::endl; diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 3b1a81628692..e450f85afd66 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace cv { namespace highgui_backend { @@ -33,7 +34,7 @@ class CV_EXPORTS FramebufferWindow : public UIWindow public: FramebufferWindow(); - virtual ~FramebufferWindow(){} + virtual ~FramebufferWindow(); virtual void imshow(InputArray image)override; @@ -67,8 +68,19 @@ class CV_EXPORTS FramebufferWindow : public UIWindow class CV_EXPORTS FramebufferBackend: public UIBackend { + int OpenInputEvent(); + int eventKey; + + struct termios old, current; + + void initTermios(int echo); + void resetTermios(void); + char getch_(int echo); + public: - virtual ~FramebufferBackend(){} + FramebufferBackend(); + + virtual ~FramebufferBackend(); virtual void destroyAllWindows()override; From d5cce2ae94a9ca5dcafc396722923733938c78aa Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 17 Apr 2024 10:47:48 +0300 Subject: [PATCH 35/81] add if for bits_per_pixel and apply dos2unix --- modules/highgui/src/window_framebuffer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 067e3e40b069..e9be57426411 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -67,7 +67,7 @@ namespace cv { namespace highgui_backend { << fb_w << " " << fb_h << " " << bpp << "\n\n"; std::cout << "= Framebuffer's offsets, line length:\n" << y_offset << " " << x_offset << " " << line_length << "\n\n"; - + // MAP FB TO MEMORY screensize = fb_w * fb_h * bpp / 8; fbPointer = (unsigned char*) @@ -78,6 +78,11 @@ namespace cv { namespace highgui_backend { return; } + if(bpp != 32) { + std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + return; + } + backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); int cnt_channel = 4; for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) @@ -115,6 +120,11 @@ namespace cv { namespace highgui_backend { if (fbPointer == MAP_FAILED) { return; } + + if(bpp != 32) { + std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + return; + } Mat img; cvtColor(image, img, COLOR_RGB2RGBA); From e9d15c872f8ba1e0095df8007fb4b2d52aa0c6e9 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 18 Apr 2024 15:35:23 +0300 Subject: [PATCH 36/81] fix call mmap for FB --- modules/highgui/src/window_framebuffer.cpp | 38 ++++++++++++++-------- modules/highgui/src/window_framebuffer.hpp | 3 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index e9be57426411..ada190de3c33 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -69,7 +69,8 @@ namespace cv { namespace highgui_backend { << y_offset << " " << x_offset << " " << line_length << "\n\n"; // MAP FB TO MEMORY - screensize = fb_w * fb_h * bpp / 8; + screensize = max((__u32)fb_w, var_info.xres_virtual) * + max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; fbPointer = (unsigned char*) mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, framebuffrer_id, 0); @@ -134,9 +135,9 @@ namespace cv { namespace highgui_backend { int new_height = static_cast(fb_w / aspect_ratio); int cnt_channel = img.channels(); - std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; - std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; - std::cout << "= Image count of channels:\n" << img.channels() << "\n"; + //std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + //std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; + //std::cout << "= Image count of channels:\n" << img.channels() << "\n"; // RECIZE IMAGE TO MATCH THE FB SIZE if (new_width > fb_w || new_height > fb_h) { @@ -272,6 +273,8 @@ namespace cv { namespace highgui_backend { tcgetattr(0, &old); /* grab old terminal i/o settings */ current = old; /* make new settings same as old settings */ current.c_lflag &= ~ICANON; /* disable buffered i/o */ + current.c_lflag &= ~ISIG; + current.c_cc[VMIN]=1; if (echo) { current.c_lflag |= ECHO; /* set echo mode */ } else { @@ -286,38 +289,45 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, &old); } - char FramebufferBackend::getch_(int echo) + int FramebufferBackend::getch_(int echo) { - char ch; + int ch; initTermios(echo); ch = getchar(); resetTermios(); return ch; } + bool FramebufferBackend::kbhit() + { + int byteswaiting=0; + initTermios(0); + if ( ioctl(0, FIONREAD, &byteswaiting) < 0) + { + std::cout << " ERR byteswaiting " << std::endl; + } + resetTermios(); + std::cout << " byteswaiting " << byteswaiting << std::endl; + + return byteswaiting > 0; + } int FramebufferBackend::waitKeyEx(int delay) { std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; int code = 0; - char ch = getch_(0); + int ch = getch_(0); std::cout << "ch 1 " << (int)ch << std::endl; code = ch; - if(code == 27) + while(kbhit()) { ch = getch_(0); std::cout << "ch 2 " << (int)ch << std::endl; - // code = ch * 1000; - ch = getch_(0); - std::cout << "ch 2 " << (int)ch << std::endl; - // code += ch * 1000000; code = ch; } // struct input_event events; -// -// // ssize_t r = 1; // while(r > 0) // { diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index e450f85afd66..fdab797bc269 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -75,7 +75,8 @@ class CV_EXPORTS FramebufferBackend: public UIBackend void initTermios(int echo); void resetTermios(void); - char getch_(int echo); + int getch_(int echo); + bool kbhit(); public: FramebufferBackend(); From b9377cd7fc2abd38141dab7548fb2d72a17b8a90 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 18 Apr 2024 18:35:11 +0300 Subject: [PATCH 37/81] add x_offset --- modules/highgui/src/window_framebuffer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index ada190de3c33..1696768925b2 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -89,7 +89,7 @@ namespace cv { namespace highgui_backend { for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { std::memcpy(backgroundBuff.ptr(y - y_offset), - fbPointer + y * line_length, + fbPointer + y * line_length + x_offset, backgroundBuff.cols * cnt_channel); } @@ -104,7 +104,7 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length, + std::memcpy(fbPointer + y * line_length + x_offset, backgroundBuff.ptr(y - y_offset), backgroundBuff.cols*cnt_channel); } @@ -156,7 +156,7 @@ namespace cv { namespace highgui_backend { // RESTORE BACKGROUNG for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length, + std::memcpy(fbPointer + y * line_length + x_offset, backgroundBuff.ptr(y - y_offset), backgroundBuff.cols*cnt_channel); } @@ -166,7 +166,7 @@ namespace cv { namespace highgui_backend { // SHOW IMAGE for (int y = y_offset; y < img.rows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length, + std::memcpy(fbPointer + y * line_length + x_offset, img.ptr(y - y_offset), img.cols*cnt_channel); } From 293872d1eb65b475f0abe03ab27e40e4614ff9ea Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 18 Apr 2024 19:28:09 +0300 Subject: [PATCH 38/81] comment temp code --- modules/highgui/src/window_framebuffer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 1696768925b2..c098097afc88 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -243,16 +243,16 @@ namespace cv { namespace highgui_backend { FramebufferBackend::FramebufferBackend() { - eventKey = OpenInputEvent(); - std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; + //eventKey = OpenInputEvent(); + //std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; } FramebufferBackend::~FramebufferBackend() { - if(eventKey != -1) - { - close(eventKey); - } + //if(eventKey != -1) + //{ + // close(eventKey); + //} } void FramebufferBackend::destroyAllWindows() { From c6055b64b40cbafebd288138eb833350d5374e7f Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 19 Apr 2024 19:15:33 +0300 Subject: [PATCH 39/81] fix arrow event add delay support --- modules/highgui/src/window_framebuffer.cpp | 97 ++++++++++++---------- modules/highgui/src/window_framebuffer.hpp | 4 +- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index c098097afc88..10ab3c304eb1 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -54,7 +54,16 @@ namespace cv { namespace highgui_backend { framebuffrer_id = fb_open_and_get_info(); std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; - if(framebuffrer_id == -1) return; + if(framebuffrer_id == -1){ + fb_w = 0; + fb_h = 0; + y_offset = 0; + x_offset = 0; + bpp = 0; + line_length = 0; + + return; + } fb_w = var_info.xres; fb_h = var_info.yres; @@ -268,13 +277,13 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } - void FramebufferBackend::initTermios(int echo) + void FramebufferBackend::initTermios(int echo, int wait) { tcgetattr(0, &old); /* grab old terminal i/o settings */ current = old; /* make new settings same as old settings */ current.c_lflag &= ~ICANON; /* disable buffered i/o */ current.c_lflag &= ~ISIG; - current.c_cc[VMIN]=1; + current.c_cc[VMIN]=wait; if (echo) { current.c_lflag |= ECHO; /* set echo mode */ } else { @@ -289,24 +298,25 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, &old); } - int FramebufferBackend::getch_(int echo) + int FramebufferBackend::getch_(int echo, int wait) { int ch; - initTermios(echo); + initTermios(echo, wait); ch = getchar(); + rewind(stdin); resetTermios(); return ch; } bool FramebufferBackend::kbhit() { int byteswaiting=0; - initTermios(0); + initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { std::cout << " ERR byteswaiting " << std::endl; } resetTermios(); - std::cout << " byteswaiting " << byteswaiting << std::endl; +// std::cout << " byteswaiting " << byteswaiting << std::endl; return byteswaiting > 0; } @@ -314,47 +324,48 @@ namespace cv { namespace highgui_backend { int FramebufferBackend::waitKeyEx(int delay) { std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; - int code = 0; - - int ch = getch_(0); - std::cout << "ch 1 " << (int)ch << std::endl; - code = ch; - - while(kbhit()) + int code = -1; + + if(delay == 0) { - ch = getch_(0); - std::cout << "ch 2 " << (int)ch << std::endl; + int ch = getch_(0, 1); + std::cout << "ch 1 " << (int)ch << std::endl; code = ch; + + while((ch = getch_(0, 0))>=0) + { + std::cout << "ch 2 " << (int)ch << std::endl; + code = ch; + } + } else { + if(delay > 0) + { + bool f_kbhit = false; + while(!(f_kbhit = kbhit()) && (delay > 0)) + { + delay -= 10; + usleep(10000); + } + if(f_kbhit) + { + std::cout << "f_kbhit " << true << std::endl; + + int ch = getch_(0, 1); + std::cout << "d ch 1 " << (int)ch << std::endl; + code = ch; + + while((ch = getch_(0, 0))>=0) + { + std::cout << "d ch 2 " << (int)ch << std::endl; + code = ch; + } + } + + } } + -// struct input_event events; -// ssize_t r = 1; -// while(r > 0) -// { -// std::cout << "while 1 " << std::endl; -// r = read(eventKey, &events, sizeof(input_event)); -// std::cout << "while 1 " << std::endl; -// } -// -// -// -// while((r == 0)&& ((delay > 1) || (delay == 0)) ) -// { -// delay--; -// usleep(1); -// r = read(eventKey, &events, sizeof(input_event)); -// std::cout << "while 2 " << std::endl; -// -// if(r != 0){ -// code = (events.code); -// } -// } -// std::cout << "waitKeyEx:: code "<< code << std::endl; -// -// if(r == 0) -// return -1; -// return code; } int FramebufferBackend::pollKey() { diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index fdab797bc269..5af1d55a7e44 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -73,9 +73,9 @@ class CV_EXPORTS FramebufferBackend: public UIBackend struct termios old, current; - void initTermios(int echo); + void initTermios(int echo, int wait); void resetTermios(void); - int getch_(int echo); + int getch_(int echo, int wait); bool kbhit(); public: From 6cc910d07eeb0904f2c2bffab5ecb3a23c721412 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 6 May 2024 09:18:05 +0300 Subject: [PATCH 40/81] fix create FB location and multiwindows support --- modules/highgui/src/window_framebuffer.cpp | 304 ++++++++++++--------- modules/highgui/src/window_framebuffer.hpp | 54 ++-- 2 files changed, 203 insertions(+), 155 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 10ab3c304eb1..a05c930e1b7c 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -22,162 +22,53 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } - int FramebufferWindow::fb_open_and_get_info() + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend): backend(_backend) { - int fb_fd = open("/dev/fb0", O_RDWR); - if (fb_fd == -1) - { - std::cerr << "ERROR_OPENING_FB\n"; - return -1; - } - - // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { - std::cerr << "ERROR_READING_FIX_INFO\n"; - return -1; - } - - // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { - std::cerr << "EERROR_READING_VAR_INFO\n"; - return -1; - } - - return fb_fd; - } - - - FramebufferWindow::FramebufferWindow() - { - std::cout << "FramebufferWindow()" << std::endl; FB_ID = "FramebufferWindow"; - framebuffrer_id = fb_open_and_get_info(); - std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; - - if(framebuffrer_id == -1){ - fb_w = 0; - fb_h = 0; - y_offset = 0; - x_offset = 0; - bpp = 0; - line_length = 0; - - return; - } - - fb_w = var_info.xres; - fb_h = var_info.yres; - y_offset = var_info.yoffset; - x_offset = var_info.xoffset; - bpp = var_info.bits_per_pixel; - line_length = fix_info.line_length; - std::cout << "= Framebuffer's width, height, bits per pix:\n" - << fb_w << " " << fb_h << " " << bpp << "\n\n"; - std::cout << "= Framebuffer's offsets, line length:\n" - << y_offset << " " << x_offset << " " << line_length << "\n\n"; - - // MAP FB TO MEMORY - screensize = max((__u32)fb_w, var_info.xres_virtual) * - max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; - fbPointer = (unsigned char*) - mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, - framebuffrer_id, 0); - if (fbPointer == MAP_FAILED) { - std::cerr << "ERROR_MAP\n"; - return; - } - - if(bpp != 32) { - std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; - return; - } - - backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); - int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) - { - std::memcpy(backgroundBuff.ptr(y - y_offset), - fbPointer + y * line_length + x_offset, - backgroundBuff.cols * cnt_channel); - } - + WindowRest = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); } FramebufferWindow::~FramebufferWindow(){ - - if(framebuffrer_id == -1) return; - - // RESTORE BACKGROUNG - int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) - { - std::memcpy(fbPointer + y * line_length + x_offset, - backgroundBuff.ptr(y - y_offset), - backgroundBuff.cols*cnt_channel); - } - - if (fbPointer != MAP_FAILED) { - munmap(fbPointer, screensize); - } - close(framebuffrer_id); } void FramebufferWindow::imshow(InputArray image){ std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; std::cout << "InputArray image:: size" << image.size() << std::endl; - if (fbPointer == MAP_FAILED) { + if (backend.getFBPointer() == MAP_FAILED) { return; } - if(bpp != 32) { - std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + if(backend.getFBbpp() != 32) { + std::cerr << "Bits per pixel " << backend.getFBbpp() << " is not supported" << std::endl; return; } Mat img; cvtColor(image, img, COLOR_RGB2RGBA); - // changing the image size to match the entered width - double aspect_ratio = static_cast(img.cols) / img.rows; - int new_width = fb_w; - int new_height = static_cast(fb_w / aspect_ratio); + int new_width = WindowRest.width; + int new_height = WindowRest.height; int cnt_channel = img.channels(); - //std::cout << "= Initial image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; - //std::cout << "= Image width / heigth:\n" << aspect_ratio << "\n"; - //std::cout << "= Image count of channels:\n" << img.channels() << "\n"; - - // RECIZE IMAGE TO MATCH THE FB SIZE - if (new_width > fb_w || new_height > fb_h) { - if (aspect_ratio > static_cast(fb_w) / fb_h) { - new_width = fb_w; - new_height = static_cast(fb_w / aspect_ratio); - } else { - new_height = fb_h; - new_width = static_cast(fb_h * aspect_ratio); - } - } cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); std::cout << "= Recized image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + + // SHOW IMAGE + int x_offset = backend.getFBXOffset(); + int y_offset = backend.getFBYOffset(); + int line_length = backend.getFBLineLength(); - // RESTORE BACKGROUNG - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) - { - std::memcpy(fbPointer + y * line_length + x_offset, - backgroundBuff.ptr(y - y_offset), - backgroundBuff.cols*cnt_channel); - } - - + int showRows = min((WindowRest.y + img.rows), backend.getFBheight()) - WindowRest.y; + int showCols = min((WindowRest.x + img.cols), backend.getFBwidth()) - WindowRest.x; - // SHOW IMAGE - for (int y = y_offset; y < img.rows + y_offset; y++) + for (int y = y_offset; y < showRows + y_offset; y++) { - std::memcpy(fbPointer + y * line_length + x_offset, + std::memcpy(backend.getFBPointer() + (y + WindowRest.y) * line_length + + x_offset + WindowRest.x, img.ptr(y - y_offset), - img.cols*cnt_channel); + showCols*cnt_channel); } @@ -194,14 +85,18 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height){ std::cout << "FramebufferWindow::resize(int width "<< width <<", int height "<< height <<")" << std::endl; + WindowRest.width = width; + WindowRest.height = height; } void FramebufferWindow::move(int x, int y) { std::cout << "FramebufferWindow::move(int x "<< x <<", int y "<< y <<")" << std::endl; + WindowRest.x = x; + WindowRest.y = y; } Rect FramebufferWindow::getImageRect() const { std::cout << "FramebufferWindow::getImageRect()" << std::endl; - return Rect(10,10,100,100); + return WindowRest; } void FramebufferWindow::setTitle(const std::string& title) { @@ -250,18 +145,156 @@ namespace cv { namespace highgui_backend { } +// !!##FramebufferBackend + + int FramebufferBackend::fb_open_and_get_info() + { + int fb_fd = open("/dev/fb0", O_RDWR); + if (fb_fd == -1) + { + std::cerr << "ERROR_OPENING_FB\n"; + return -1; + } + + // Get fixed screen information + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { + std::cerr << "ERROR_READING_FIX_INFO\n"; + return -1; + } + + // Get variable screen information + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { + std::cerr << "EERROR_READING_VAR_INFO\n"; + return -1; + } + + return fb_fd; + } + + fb_var_screeninfo &FramebufferBackend::getVarInfo() + { + return var_info; + } + fb_fix_screeninfo &FramebufferBackend::getFixInfo() + { + return fix_info; + } + int FramebufferBackend::getFramebuffrerID() + { + return framebuffrer_id; + } + int FramebufferBackend::getFBwidth() + { + return fb_w; + } + int FramebufferBackend::getFBheight() + { + return fb_h; + } + int FramebufferBackend::getFBXOffset() + { + return x_offset; + } + int FramebufferBackend::getFBYOffset() + { + return y_offset; + } + int FramebufferBackend::getFBbpp() + { + return bpp; + } + int FramebufferBackend::getFBLineLength() + { + return line_length; + } + unsigned char* FramebufferBackend::getFBPointer() + { + return fbPointer; + } + Mat& FramebufferBackend::getBackgroundBuff() + { + return backgroundBuff; + } + + + + + FramebufferBackend::FramebufferBackend() { - //eventKey = OpenInputEvent(); - //std::cout << "FramebufferBackend():: event id " << eventKey << std::endl; + std::cout << "FramebufferBackend()" << std::endl; + framebuffrer_id = fb_open_and_get_info(); + std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + + if(framebuffrer_id == -1){ + fb_w = 0; + fb_h = 0; + y_offset = 0; + x_offset = 0; + bpp = 0; + line_length = 0; + + return; + } + + fb_w = var_info.xres; + fb_h = var_info.yres; + y_offset = var_info.yoffset; + x_offset = var_info.xoffset; + bpp = var_info.bits_per_pixel; + line_length = fix_info.line_length; + + std::cout << "= Framebuffer's width, height, bits per pix:\n" + << fb_w << " " << fb_h << " " << bpp << "\n\n"; + std::cout << "= Framebuffer's offsets, line length:\n" + << y_offset << " " << x_offset << " " << line_length << "\n\n"; + + // MAP FB TO MEMORY + screensize = max((__u32)fb_w, var_info.xres_virtual) * + max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; + fbPointer = (unsigned char*) + mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, + framebuffrer_id, 0); + if (fbPointer == MAP_FAILED) { + std::cerr << "ERROR_MAP\n"; + return; + } + + if(bpp != 32) { + std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + return; + } + + backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(backgroundBuff.ptr(y - y_offset), + fbPointer + y * line_length + x_offset, + backgroundBuff.cols * cnt_channel); + } + + } FramebufferBackend::~FramebufferBackend() { - //if(eventKey != -1) - //{ - // close(eventKey); - //} + if(framebuffrer_id == -1) return; + + // RESTORE BACKGROUNG + int cnt_channel = 4; + for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + { + std::memcpy(fbPointer + y * line_length + x_offset, + backgroundBuff.ptr(y - y_offset), + backgroundBuff.cols*cnt_channel); + } + + if (fbPointer != MAP_FAILED) { + munmap(fbPointer, screensize); + } + close(framebuffrer_id); + } void FramebufferBackend::destroyAllWindows() { @@ -274,7 +307,7 @@ namespace cv { namespace highgui_backend { int flags ){ std::cout << "FramebufferBackend::createWindow("<< winname <<", "<(); + return std::make_shared(*this); } void FramebufferBackend::initTermios(int echo, int wait) @@ -316,7 +349,6 @@ namespace cv { namespace highgui_backend { std::cout << " ERR byteswaiting " << std::endl; } resetTermios(); -// std::cout << " byteswaiting " << byteswaiting << std::endl; return byteswaiting > 0; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 5af1d55a7e44..ba7aa2699388 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -11,29 +11,15 @@ namespace cv { namespace highgui_backend { +class FramebufferBackend; class CV_EXPORTS FramebufferWindow : public UIWindow { - fb_var_screeninfo var_info; - fb_fix_screeninfo fix_info; - + FramebufferBackend &backend; std::string FB_ID; - - int fb_open_and_get_info(); - int framebuffrer_id; - - int fb_w; - int fb_h; - int y_offset; - int x_offset; - int bpp; - int line_length; - long int screensize; - unsigned char* fbPointer; - - Mat backgroundBuff; - + Rect WindowRest; + public: - FramebufferWindow(); + FramebufferWindow(FramebufferBackend &backend); virtual ~FramebufferWindow(); virtual void imshow(InputArray image)override; @@ -77,8 +63,38 @@ class CV_EXPORTS FramebufferBackend: public UIBackend void resetTermios(void); int getch_(int echo, int wait); bool kbhit(); + + fb_var_screeninfo var_info; + fb_fix_screeninfo fix_info; + int fb_w; + int fb_h; + int y_offset; + int x_offset; + int bpp; + int line_length; + long int screensize; + unsigned char* fbPointer; + Mat backgroundBuff; + + + int fb_open_and_get_info(); + int framebuffrer_id; + public: + + fb_var_screeninfo &getVarInfo(); + fb_fix_screeninfo &getFixInfo(); + int getFramebuffrerID(); + int getFBwidth(); + int getFBheight(); + int getFBXOffset(); + int getFBYOffset(); + int getFBbpp(); + int getFBLineLength(); + unsigned char* getFBPointer(); + Mat& getBackgroundBuff(); + FramebufferBackend(); virtual ~FramebufferBackend(); From a9a8b7a21d8bd111a0ca5861aff3ba56ec5605dd Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 6 May 2024 19:23:08 +0300 Subject: [PATCH 41/81] fix name --- modules/highgui/src/window_framebuffer.cpp | 28 +++++++++++----------- modules/highgui/src/window_framebuffer.hpp | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index a05c930e1b7c..d5f37e2ed5e9 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -26,7 +26,7 @@ namespace cv { namespace highgui_backend { { FB_ID = "FramebufferWindow"; - WindowRest = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); + windowRect = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); } @@ -47,8 +47,8 @@ namespace cv { namespace highgui_backend { Mat img; cvtColor(image, img, COLOR_RGB2RGBA); - int new_width = WindowRest.width; - int new_height = WindowRest.height; + int new_width = windowRect.width; + int new_height = windowRect.height; int cnt_channel = img.channels(); cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); @@ -60,13 +60,13 @@ namespace cv { namespace highgui_backend { int y_offset = backend.getFBYOffset(); int line_length = backend.getFBLineLength(); - int showRows = min((WindowRest.y + img.rows), backend.getFBheight()) - WindowRest.y; - int showCols = min((WindowRest.x + img.cols), backend.getFBwidth()) - WindowRest.x; + int showRows = min((windowRect.y + img.rows), backend.getFBheight()) - windowRect.y; + int showCols = min((windowRect.x + img.cols), backend.getFBwidth()) - windowRect.x; for (int y = y_offset; y < showRows + y_offset; y++) { - std::memcpy(backend.getFBPointer() + (y + WindowRest.y) * line_length + - x_offset + WindowRest.x, + std::memcpy(backend.getFBPointer() + (y + windowRect.y) * line_length + + x_offset + windowRect.x, img.ptr(y - y_offset), showCols*cnt_channel); } @@ -85,18 +85,18 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height){ std::cout << "FramebufferWindow::resize(int width "<< width <<", int height "<< height <<")" << std::endl; - WindowRest.width = width; - WindowRest.height = height; + windowRect.width = width; + windowRect.height = height; } void FramebufferWindow::move(int x, int y) { std::cout << "FramebufferWindow::move(int x "<< x <<", int y "<< y <<")" << std::endl; - WindowRest.x = x; - WindowRest.y = y; + windowRect.x = x; + windowRect.y = y; } Rect FramebufferWindow::getImageRect() const { std::cout << "FramebufferWindow::getImageRect()" << std::endl; - return WindowRest; + return windowRect; } void FramebufferWindow::setTitle(const std::string& title) { @@ -281,7 +281,7 @@ namespace cv { namespace highgui_backend { { if(framebuffrer_id == -1) return; - // RESTORE BACKGROUNG + // RectORE BACKGROUNG int cnt_channel = 4; for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) { @@ -325,7 +325,7 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ } - /* Restore old terminal i/o settings */ + /* Rectore old terminal i/o settings */ void FramebufferBackend::resetTermios(void) { tcsetattr(0, TCSANOW, &old); diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index ba7aa2699388..65f1d8d0916a 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -16,7 +16,7 @@ class CV_EXPORTS FramebufferWindow : public UIWindow { FramebufferBackend &backend; std::string FB_ID; - Rect WindowRest; + Rect windowRect; public: FramebufferWindow(FramebufferBackend &backend); From 5164ffc7c7275f2b52b1ee6a5090ba18aa663681 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 15:31:19 +0300 Subject: [PATCH 42/81] code refactoring: renaming variables, stdout -> OpenCV LOG system --- CMakeLists.txt | 9 +- modules/highgui/CMakeLists.txt | 3 - modules/highgui/src/window_framebuffer.cpp | 308 +++++++++++---------- modules/highgui/src/window_framebuffer.hpp | 28 +- 4 files changed, 187 insertions(+), 161 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e7b0336e69d..baaed10369ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,10 +304,9 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_GTK AND NOT HAVE_GTK3) - OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF - VISIBLE_IF UNIX VERIFY HAVE_FRAMEBUFFER) - + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID + VERIFY HAVE_FRAMEBUFFER) OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_WAYLAND) @@ -1453,6 +1452,10 @@ if(WITH_GTK OR HAVE_GTK) endif() endif() +if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER) + status(" Framebuffer UI:" "YES") +endif() + if(WITH_OPENGL OR HAVE_OPENGL) status(" OpenGL support:" HAVE_OPENGL THEN "YES (${OPENGL_LIBRARIES})" ELSE NO) endif() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 82cb44bbdf0f..d4b0a7ff0548 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -41,12 +41,9 @@ endif() if(WITH_FRAMEBUFFER) - message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") add_definitions(-DHAVE_FRAMEBUFFER) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) -else() - message(WITH_FRAMEBUFFER="${WITH_FRAMEBUFFER}") endif() diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index d5f37e2ed5e9..4fddfabc8fa4 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -24,24 +24,30 @@ namespace cv { namespace highgui_backend { FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend): backend(_backend) { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; - - windowRect = Rect(0,0, backend.getFBwidth(), backend.getFBheight()); - + windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); } - FramebufferWindow::~FramebufferWindow(){ + FramebufferWindow::~FramebufferWindow() + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); } - void FramebufferWindow::imshow(InputArray image){ - std::cout << "FramebufferWindow::imshow(InputArray image)" << std::endl; - std::cout << "InputArray image:: size" << image.size() << std::endl; + void FramebufferWindow::imshow(InputArray image) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); + CV_LOG_INFO(NULL, "UI: InputArray image: " + << cv::typeToString(image.type()) << " size " << image.size()); + if (backend.getFBPointer() == MAP_FAILED) { - return; + CV_LOG_WARNING(NULL, "UI: Framebuffer is not mapped"); + return; } - if(backend.getFBbpp() != 32) { - std::cerr << "Bits per pixel " << backend.getFBbpp() << " is not supported" << std::endl; + if(backend.getFBBitsPerPixel() != 32) { + CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " + << backend.getFBBitsPerPixel() << " is not supported" ); return; } @@ -53,86 +59,106 @@ namespace cv { namespace highgui_backend { cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); - std::cout << "= Recized image width and heigth:\n" << img.cols << " " << img.rows << "\n\n"; + CV_LOG_INFO(NULL, "UI: Formated image: " + << cv::typeToString(img.type()) << " size " << img.size()); // SHOW IMAGE - int x_offset = backend.getFBXOffset(); - int y_offset = backend.getFBYOffset(); - int line_length = backend.getFBLineLength(); + int xOffset = backend.getFBXOffset(); + int yOffset = backend.getFBYOffset(); + int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBheight()) - windowRect.y; - int showCols = min((windowRect.x + img.cols), backend.getFBwidth()) - windowRect.x; + int showRows = min((windowRect.y + img.rows), backend.getFBHeight()) - windowRect.y; + int showCols = min((windowRect.x + img.cols), backend.getFBWidth()) - windowRect.x; - for (int y = y_offset; y < showRows + y_offset; y++) + for (int y = yOffset; y < showRows + yOffset; y++) { - std::memcpy(backend.getFBPointer() + (y + windowRect.y) * line_length + - x_offset + windowRect.x, - img.ptr(y - y_offset), - showCols*cnt_channel); + std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + + xOffset + windowRect.x, + img.ptr(y - yOffset), + showCols * cnt_channel); } - - } - double FramebufferWindow::getProperty(int prop) const{ - std::cout << "FramebufferWindow::getProperty(int prop:" << prop <<")"<< std::endl; + double FramebufferWindow::getProperty(int prop) const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); return 0.0; } - bool FramebufferWindow::setProperty(int prop, double value) { - std::cout << "FramebufferWindow::setProperty(int prop "<< prop <<", double value "< FramebufferWindow::createTrackbar( const std::string& name, int count, TrackbarCallback onChange, - void* userdata - ){ + void* userdata) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); return nullptr; } - std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name){ + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); return nullptr; } - const std::string& FramebufferWindow::getID() const { - std::cout << "getID())" << std::endl; return FB_ID; + const std::string& FramebufferWindow::getID() const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); + return FB_ID; } - bool FramebufferWindow::isActive() const { - std::cout << "isActive()" << std::endl; + bool FramebufferWindow::isActive() const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); return true; } - void FramebufferWindow::destroy() { - std::cout << "destroy()" << std::endl; + void FramebufferWindow::destroy() + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } +// !!##FramebufferBackend + int FramebufferBackend::OpenInputEvent() { int fd; @@ -144,27 +170,24 @@ namespace cv { namespace highgui_backend { return fd; } - -// !!##FramebufferBackend - - int FramebufferBackend::fb_open_and_get_info() + int FramebufferBackend::fbOpenAndGetInfo() { int fb_fd = open("/dev/fb0", O_RDWR); if (fb_fd == -1) { - std::cerr << "ERROR_OPENING_FB\n"; + CV_LOG_WARNING(NULL, "UI: can't open framebuffer"); return -1; } // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix_info)) { - std::cerr << "ERROR_READING_FIX_INFO\n"; - return -1; + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { + CV_LOG_WARNING(NULL, "UI: can't read fix info for framebuffer"); + return -1; } // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var_info)) { - std::cerr << "EERROR_READING_VAR_INFO\n"; + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { + CV_LOG_WARNING(NULL, "UI: can't read var info for framebuffer"); return -1; } @@ -173,39 +196,39 @@ namespace cv { namespace highgui_backend { fb_var_screeninfo &FramebufferBackend::getVarInfo() { - return var_info; + return varInfo; } fb_fix_screeninfo &FramebufferBackend::getFixInfo() { - return fix_info; + return fixInfo; } int FramebufferBackend::getFramebuffrerID() { - return framebuffrer_id; + return fbID; } - int FramebufferBackend::getFBwidth() + int FramebufferBackend::getFBWidth() { - return fb_w; + return fbWidth; } - int FramebufferBackend::getFBheight() + int FramebufferBackend::getFBHeight() { - return fb_h; + return fbHeight; } int FramebufferBackend::getFBXOffset() { - return x_offset; + return fbXOffset; } int FramebufferBackend::getFBYOffset() { - return y_offset; + return fbYOffset; } - int FramebufferBackend::getFBbpp() + int FramebufferBackend::getFBBitsPerPixel() { - return bpp; + return fbBitsPerPixel; } int FramebufferBackend::getFBLineLength() { - return line_length; + return fbLineLength; } unsigned char* FramebufferBackend::getFBPointer() { @@ -216,116 +239,115 @@ namespace cv { namespace highgui_backend { return backgroundBuff; } - - - - FramebufferBackend::FramebufferBackend() { - std::cout << "FramebufferBackend()" << std::endl; - framebuffrer_id = fb_open_and_get_info(); - std::cout << "FramebufferWindow():: id " << framebuffrer_id << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); + fbID = fbOpenAndGetInfo(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - if(framebuffrer_id == -1){ - fb_w = 0; - fb_h = 0; - y_offset = 0; - x_offset = 0; - bpp = 0; - line_length = 0; - + if(fbID == -1){ + fbWidth = 0; + fbHeight = 0; + fbXOffset = 0; + fbYOffset = 0; + fbBitsPerPixel = 0; + fbLineLength = 0; return; } - fb_w = var_info.xres; - fb_h = var_info.yres; - y_offset = var_info.yoffset; - x_offset = var_info.xoffset; - bpp = var_info.bits_per_pixel; - line_length = fix_info.line_length; + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.yoffset; + fbYOffset = varInfo.xoffset; + fbBitsPerPixel = varInfo.bits_per_pixel; + fbLineLength = fixInfo.line_length; - std::cout << "= Framebuffer's width, height, bits per pix:\n" - << fb_w << " " << fb_h << " " << bpp << "\n\n"; - std::cout << "= Framebuffer's offsets, line length:\n" - << y_offset << " " << x_offset << " " << line_length << "\n\n"; + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + << fbXOffset << " " << fbYOffset << " " << fbLineLength); // MAP FB TO MEMORY - screensize = max((__u32)fb_w, var_info.xres_virtual) * - max((__u32)fb_h, var_info.yres_virtual) * bpp / 8; + fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * + max((__u32)fbHeight, varInfo.yres_virtual) * + fbBitsPerPixel / 8; + fbPointer = (unsigned char*) - mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, - framebuffrer_id, 0); + mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, + fbID, 0); + if (fbPointer == MAP_FAILED) { - std::cerr << "ERROR_MAP\n"; - return; + CV_LOG_WARNING(NULL, "UI: can't mmap framebuffer"); + return; } - if(bpp != 32) { - std::cerr << "Bits per pixel " << bpp << " is not supported" << std::endl; + if(fbBitsPerPixel != 32) { + CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " + << fbBitsPerPixel << " is not supported" ); return; } - backgroundBuff = Mat(fb_h, fb_w, CV_8UC4); + backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - y_offset), - fbPointer + y * line_length + x_offset, - backgroundBuff.cols * cnt_channel); + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + fbPointer + y * fbLineLength + fbXOffset, + backgroundBuff.cols * cnt_channel); } - - } FramebufferBackend::~FramebufferBackend() { - if(framebuffrer_id == -1) return; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); + if(fbID == -1) return; - // RectORE BACKGROUNG + // RESTORE BACKGROUNG int cnt_channel = 4; - for (int y = y_offset; y < backgroundBuff.rows + y_offset; y++) + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(fbPointer + y * line_length + x_offset, - backgroundBuff.ptr(y - y_offset), - backgroundBuff.cols*cnt_channel); + std::memcpy(fbPointer + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); } if (fbPointer != MAP_FAILED) { - munmap(fbPointer, screensize); + munmap(fbPointer, fbScreenSize); } - close(framebuffrer_id); + close(fbID); } void FramebufferBackend::destroyAllWindows() { - std::cout << "destroyAllWindows()" << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); } // namedWindow std::shared_ptr FramebufferBackend::createWindow( const std::string& winname, - int flags - ){ - std::cout << "FramebufferBackend::createWindow("<< winname <<", "<(*this); } void FramebufferBackend::initTermios(int echo, int wait) { - tcgetattr(0, &old); /* grab old terminal i/o settings */ - current = old; /* make new settings same as old settings */ - current.c_lflag &= ~ICANON; /* disable buffered i/o */ + tcgetattr(0, &old); // grab old terminal i/o settings + current = old; // make new settings same as old settings + current.c_lflag &= ~ICANON; // disable buffered i/o current.c_lflag &= ~ISIG; current.c_cc[VMIN]=wait; if (echo) { - current.c_lflag |= ECHO; /* set echo mode */ + current.c_lflag |= ECHO; // set echo mode } else { - current.c_lflag &= ~ECHO; /* set no echo mode */ + current.c_lflag &= ~ECHO; // set no echo mode } - tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */ + tcsetattr(0, TCSANOW, ¤t); // use these new terminal i/o settings now } - /* Rectore old terminal i/o settings */ void FramebufferBackend::resetTermios(void) { tcsetattr(0, TCSANOW, &old); @@ -336,7 +358,7 @@ namespace cv { namespace highgui_backend { int ch; initTermios(echo, wait); ch = getchar(); - rewind(stdin); + if(ch < 0) rewind(stdin); resetTermios(); return ch; } @@ -346,27 +368,29 @@ namespace cv { namespace highgui_backend { initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { - std::cout << " ERR byteswaiting " << std::endl; + CV_LOG_WARNING(NULL, "UI: Framebuffer ERR byteswaiting" ); } resetTermios(); return byteswaiting > 0; } - int FramebufferBackend::waitKeyEx(int delay) { - std::cout << "FramebufferBackend::waitKeyEx(int delay "<< delay <<")" << std::endl; + int FramebufferBackend::waitKeyEx(int delay) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); int code = -1; if(delay == 0) { int ch = getch_(0, 1); - std::cout << "ch 1 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; while((ch = getch_(0, 0))>=0) { - std::cout << "ch 2 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; } } else { @@ -380,15 +404,16 @@ namespace cv { namespace highgui_backend { } if(f_kbhit) { - std::cout << "f_kbhit " << true << std::endl; - + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + int ch = getch_(0, 1); - std::cout << "d ch 1 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; while((ch = getch_(0, 0))>=0) { - std::cout << "d ch 2 " << (int)ch << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; } } @@ -396,12 +421,13 @@ namespace cv { namespace highgui_backend { } } - - std::cout << "waitKeyEx:: code "<< code << std::endl; + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); return code; } - int FramebufferBackend::pollKey() { - std::cout << "FramebufferBackend::pollKey()" << std::endl; + + int FramebufferBackend::pollKey() + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); return 0; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 65f1d8d0916a..3a34ea2f54e3 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -65,32 +65,32 @@ class CV_EXPORTS FramebufferBackend: public UIBackend bool kbhit(); - fb_var_screeninfo var_info; - fb_fix_screeninfo fix_info; - int fb_w; - int fb_h; - int y_offset; - int x_offset; - int bpp; - int line_length; - long int screensize; + fb_var_screeninfo varInfo; + fb_fix_screeninfo fixInfo; + int fbWidth; + int fbHeight; + int fbXOffset; + int fbYOffset; + int fbBitsPerPixel; + int fbLineLength; + long int fbScreenSize; unsigned char* fbPointer; Mat backgroundBuff; - int fb_open_and_get_info(); - int framebuffrer_id; + int fbOpenAndGetInfo(); + int fbID; public: fb_var_screeninfo &getVarInfo(); fb_fix_screeninfo &getFixInfo(); int getFramebuffrerID(); - int getFBwidth(); - int getFBheight(); + int getFBWidth(); + int getFBHeight(); int getFBXOffset(); int getFBYOffset(); - int getFBbpp(); + int getFBBitsPerPixel(); int getFBLineLength(); unsigned char* getFBPointer(); Mat& getBackgroundBuff(); From d5d80bc671f6994e67013ff9c7330e9700da39ae Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 18:19:27 +0300 Subject: [PATCH 43/81] add env varibale for FB dev --- modules/highgui/src/window_framebuffer.cpp | 47 +++++++++++++++++----- modules/highgui/src/window_framebuffer.hpp | 4 +- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 4fddfabc8fa4..bf159bfed4ba 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -1,6 +1,13 @@ #include "window_framebuffer.hpp" -#include "opencv2/core/utils/logger.hpp" +#include +#include +#ifdef NDEBUG +#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG + 1 +#else +#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE + 1 +#endif +#include #include #include @@ -159,20 +166,38 @@ namespace cv { namespace highgui_backend { // !!##FramebufferBackend - int FramebufferBackend::OpenInputEvent() - { - int fd; - fd = open("/dev/input/event1", O_RDONLY); - if (fd == -1) { - std::cerr << "ERROR_OPENING_INPUT\n"; - return -1; - } - return fd; +// int FramebufferBackend::OpenInputEvent() +// { +// int fd; +// fd = open("/dev/input/event1", O_RDONLY); +// if (fd == -1) { +// std::cerr << "ERROR_OPENING_INPUT\n"; +// return -1; +// } +// return fd; +// } + + static + std::string& getFBFileName() + { + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FRAMEBUFFER", ""); + static std::string fbFileNameDef = "/dev/fb0"; + + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if(!fbFileNameFB.empty()) return fbFileNameFB; + return fbFileNameDef; } + int FramebufferBackend::fbOpenAndGetInfo() { - int fb_fd = open("/dev/fb0", O_RDWR); + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { CV_LOG_WARNING(NULL, "UI: can't open framebuffer"); diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 3a34ea2f54e3..ffa422814e8b 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -54,8 +54,8 @@ class CV_EXPORTS FramebufferWindow : public UIWindow class CV_EXPORTS FramebufferBackend: public UIBackend { - int OpenInputEvent(); - int eventKey; +// int OpenInputEvent(); +// int eventKey; struct termios old, current; From 4c2d2e639cd2488ec47584473dd8fd9fd6fe0137 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 18:37:02 +0300 Subject: [PATCH 44/81] imp. log --- modules/highgui/src/window_framebuffer.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index bf159bfed4ba..a5bba09b06a6 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -48,12 +48,12 @@ namespace cv { namespace highgui_backend { << cv::typeToString(image.type()) << " size " << image.size()); if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_WARNING(NULL, "UI: Framebuffer is not mapped"); + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } if(backend.getFBBitsPerPixel() != 32) { - CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " + CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " << backend.getFBBitsPerPixel() << " is not supported" ); return; } @@ -89,12 +89,16 @@ namespace cv { namespace highgui_backend { double FramebufferWindow::getProperty(int prop) const { CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); + CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + return 0.0; } bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " << prop << ", value " << value << ")"); + CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + return false; } @@ -121,6 +125,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::setTitle(const std::string& title) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); + CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } void FramebufferWindow::setMouseCallback(MouseCallback onMouse, void* userdata ) @@ -200,19 +205,19 @@ namespace cv { namespace highgui_backend { int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { - CV_LOG_WARNING(NULL, "UI: can't open framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); return -1; } // Get fixed screen information if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { - CV_LOG_WARNING(NULL, "UI: can't read fix info for framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; } // Get variable screen information if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { - CV_LOG_WARNING(NULL, "UI: can't read var info for framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } @@ -303,7 +308,7 @@ namespace cv { namespace highgui_backend { fbID, 0); if (fbPointer == MAP_FAILED) { - CV_LOG_WARNING(NULL, "UI: can't mmap framebuffer"); + CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); return; } @@ -393,7 +398,7 @@ namespace cv { namespace highgui_backend { initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { - CV_LOG_WARNING(NULL, "UI: Framebuffer ERR byteswaiting" ); + CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); } resetTermios(); From 6706b8ad9ed010a258a0ec0f69cd6d5fc77c78ef Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 8 May 2024 20:44:38 +0300 Subject: [PATCH 45/81] Added conditions for FB format. Added image reformatting functionality --- modules/highgui/src/window_framebuffer.cpp | 51 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index a5bba09b06a6..196611908659 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -57,14 +57,34 @@ namespace cv { namespace highgui_backend { << backend.getFBBitsPerPixel() << " is not supported" ); return; } + + Mat img(image.getMat()); + switch(img.channels()){ + case 1: + if(img.type() == CV_8UC1) + { + cvtColor(img, img, cv::COLOR_GRAY2RGB); + } + else + { + CV_LOG_ERROR(NULL, "UI: Image type " + << cv::typeToString(image.type()) << " is not supported" ); + } + break; + case 3: + convertToShow(img, img); + break; + case 4: + convertToShow(img, img, true); + break; + } + cvtColor(img, img, COLOR_RGB2BGRA); - Mat img; - cvtColor(image, img, COLOR_RGB2RGBA); - int new_width = windowRect.width; - int new_height = windowRect.height; - int cnt_channel = img.channels(); + int newWidth = windowRect.width; + int newHeight = windowRect.height; + int cntChannel = img.channels(); - cv::resize(img, img, cv::Size(new_width, new_height), INTER_LINEAR); + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -82,7 +102,7 @@ namespace cv { namespace highgui_backend { std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + xOffset + windowRect.x, img.ptr(y - yOffset), - showCols * cnt_channel); + showCols * cntChannel); } } @@ -220,6 +240,23 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } + + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" + << " green offset " << varInfo.green.offset << " length " << varInfo.green.length << "\n" + << " blue offset " << varInfo.blue.offset << " length " << varInfo.blue.length << "\n" + << "transp offset " << varInfo.transp.offset << " length " < Date: Sun, 12 May 2024 09:43:17 +0000 Subject: [PATCH 46/81] fix test --- modules/highgui/src/window_framebuffer.cpp | 1 + modules/highgui/test/test_gui.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 196611908659..c781311cce54 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -69,6 +69,7 @@ namespace cv { namespace highgui_backend { { CV_LOG_ERROR(NULL, "UI: Image type " << cv::typeToString(image.type()) << " is not supported" ); + return; } break; case 3: diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index 5b72545faf5f..99726c078b22 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -80,6 +80,9 @@ TEST(Highgui_GUI, regression) EXPECT_NO_THROW(destroyAllWindows()); ASSERT_NO_THROW(namedWindow(window_name)); +#if defined HAVE_FRAMEBUFFER + ASSERT_NO_THROW(resizeWindow(window_name, 800, 600)); +#endif const vector channels = {1, 3, 4}; const vector depths = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32F, CV_64F}; for(int cn : channels) @@ -148,7 +151,8 @@ static void Foo(int, void* counter) && !defined HAVE_WIN32UI \ && !defined HAVE_WAYLAND \ ) \ - || defined(__APPLE__) // test fails on Mac (cocoa) + || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar_unsafe) #else TEST(Highgui_GUI, trackbar_unsafe) @@ -188,7 +192,8 @@ void testTrackbarCallback(int pos, void* param) && !defined HAVE_WIN32UI \ && !defined HAVE_WAYLAND \ ) \ - || defined(__APPLE__) // test fails on Mac (cocoa) + || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar) #else TEST(Highgui_GUI, trackbar) From 741bbfff2247677301c76ba2ee88fffeacbbbdde Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 20 May 2024 14:16:54 +0300 Subject: [PATCH 47/81] add Window flags support. add gs format for img. fix register FB name. --- modules/highgui/src/registry.impl.hpp | 2 +- modules/highgui/src/window_framebuffer.cpp | 162 ++++++++++++++++----- modules/highgui/src/window_framebuffer.hpp | 7 +- modules/highgui/test/test_gui.cpp | 3 - 4 files changed, 135 insertions(+), 39 deletions(-) diff --git a/modules/highgui/src/registry.impl.hpp b/modules/highgui/src/registry.impl.hpp index 956cb969c901..94ee9e9cde4b 100644 --- a/modules/highgui/src/registry.impl.hpp +++ b/modules/highgui/src/registry.impl.hpp @@ -45,7 +45,7 @@ std::vector& getBuiltinBackendsInfo() #endif #ifdef HAVE_FRAMEBUFFER - DECLARE_STATIC_BACKEND("Framebuffer", createUIBackendFramebuffer) + DECLARE_STATIC_BACKEND("FB", createUIBackendFramebuffer) #endif diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index c781311cce54..deb663dbd5e2 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -29,7 +29,8 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend): backend(_backend) + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + backend(_backend), flags(_flags) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; @@ -43,9 +44,16 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::imshow(InputArray image) { + currentImg = image.getMat(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " << cv::typeToString(image.type()) << " size " << image.size()); + + if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) + { + return; + } if (backend.getFBPointer() == MAP_FAILED) { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); @@ -61,16 +69,23 @@ namespace cv { namespace highgui_backend { Mat img(image.getMat()); switch(img.channels()){ case 1: - if(img.type() == CV_8UC1) + switch(img.type()) { - cvtColor(img, img, cv::COLOR_GRAY2RGB); - } - else - { - CV_LOG_ERROR(NULL, "UI: Image type " - << cv::typeToString(image.type()) << " is not supported" ); - return; + case CV_8S: + cv::convertScaleAbs(img, img, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, img, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, img, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(img, CV_8U, 255., 0.); + break; } + cvtColor(img, img, cv::COLOR_GRAY2RGB); break; case 3: convertToShow(img, img); @@ -84,8 +99,47 @@ namespace cv { namespace highgui_backend { int newWidth = windowRect.width; int newHeight = windowRect.height; int cntChannel = img.channels(); + cv::Size imgSize = currentImg.size(); + + switch(flags) + { + case WINDOW_FREERATIO: + { + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + break; + case WINDOW_AUTOSIZE: // WINDOW_FULLSCREEN + { + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + } + break; +// case WINDOW_FULLSCREEN: +// windowRect.width = backend.getFBWidth(); +// windowRect.height = backend.getFBHeight(); +// newWidth = windowRect.width; +// newHeight = windowRect.height; +// cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); +// break; + case WINDOW_NORMAL: // WINDOW_KEEPRATIO + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); + + if (newHeight > windowRect.height) { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; + } + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + break; + + default: + CV_LOG_ERROR(NULL, "UI: FB window flag not supported"); + CV_Assert(0); + } - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -95,14 +149,30 @@ namespace cv { namespace highgui_backend { int yOffset = backend.getFBYOffset(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight()) - windowRect.y; - int showCols = min((windowRect.x + img.cols), backend.getFBWidth()) - windowRect.x; + int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); + int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); + + int dx_w = windowRect.x; + int dy_w = windowRect.y; + + int start_y_w = 0; + int start_x_w = 0; + + if(dy_w < 0) start_y_w = -dy_w; + if(dx_w < 0) start_x_w = -dx_w; + + if(dy_w < 0) dy_w = 0; + if(dx_w < 0) dx_w = 0; + + showRows -= dy_w; + showCols -= dx_w; + for (int y = yOffset; y < showRows + yOffset; y++) { std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + xOffset + windowRect.x, - img.ptr(y - yOffset), + img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, showCols * cntChannel); } } @@ -127,14 +197,32 @@ namespace cv { namespace highgui_backend { { CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " << width <<", height " << height << ")"); - windowRect.width = width; - windowRect.height = height; + + CV_Assert(width > 0); + CV_Assert(height > 0); + + if(flags != WINDOW_AUTOSIZE) + { + windowRect.width = width; + windowRect.height = height; + + if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + { + imshow(currentImg); + } + } } void FramebufferWindow::move(int x, int y) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); + windowRect.x = x; windowRect.y = y; + + if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + { + imshow(currentImg); + } } Rect FramebufferWindow::getImageRect() const @@ -192,19 +280,7 @@ namespace cv { namespace highgui_backend { // !!##FramebufferBackend -// int FramebufferBackend::OpenInputEvent() -// { -// int fd; -// fd = open("/dev/input/event1", O_RDONLY); -// if (fd == -1) { -// std::cerr << "ERROR_OPENING_INPUT\n"; -// return -1; -// } -// return fd; -// } - - static - std::string& getFBFileName() + static std::string& getFBFileName() { static std::string fbFileNameFB = cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); @@ -398,7 +474,7 @@ namespace cv { namespace highgui_backend { { CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" << winname << ", " << flags << ")"); - return std::make_shared(*this); + return std::make_shared(*this, flags); } void FramebufferBackend::initTermios(int echo, int wait) @@ -449,7 +525,7 @@ namespace cv { namespace highgui_backend { int code = -1; - if(delay == 0) + if(delay <= 0) { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); @@ -467,8 +543,8 @@ namespace cv { namespace highgui_backend { bool f_kbhit = false; while(!(f_kbhit = kbhit()) && (delay > 0)) { - delay -= 10; - usleep(10000); + delay -= 1; + usleep(1000); } if(f_kbhit) { @@ -496,7 +572,27 @@ namespace cv { namespace highgui_backend { int FramebufferBackend::pollKey() { CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); - return 0; + int code = -1; + bool f_kbhit = false; + f_kbhit = kbhit(); + + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } + + return code; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index ffa422814e8b..a076f4e97ed4 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -17,9 +17,12 @@ class CV_EXPORTS FramebufferWindow : public UIWindow FramebufferBackend &backend; std::string FB_ID; Rect windowRect; + + int flags; + Mat currentImg; public: - FramebufferWindow(FramebufferBackend &backend); + FramebufferWindow(FramebufferBackend &backend, int flags); virtual ~FramebufferWindow(); virtual void imshow(InputArray image)override; @@ -105,7 +108,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend virtual std::shared_ptr createWindow( const std::string& winname, int flags - ); + )override; virtual int waitKeyEx(int delay /*= 0*/)override; virtual int pollKey() override; diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index 99726c078b22..b8093e07ecec 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -80,9 +80,6 @@ TEST(Highgui_GUI, regression) EXPECT_NO_THROW(destroyAllWindows()); ASSERT_NO_THROW(namedWindow(window_name)); -#if defined HAVE_FRAMEBUFFER - ASSERT_NO_THROW(resizeWindow(window_name, 800, 600)); -#endif const vector channels = {1, 3, 4}; const vector depths = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32F, CV_64F}; for(int cn : channels) From 66cc5a1c29acc513d850eff2dd7446ab3becb79c Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 20 May 2024 22:31:17 +0300 Subject: [PATCH 48/81] add FB mode --- modules/highgui/src/window_framebuffer.cpp | 137 +++++++++++++-------- modules/highgui/src/window_framebuffer.hpp | 9 ++ 2 files changed, 97 insertions(+), 49 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index deb663dbd5e2..7b6e35fc329c 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -29,6 +29,30 @@ namespace cv { namespace highgui_backend { return std::make_shared(); } + static std::string& getFBMode() + { + static std::string fbModeOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); + static std::string fbModeDef = "FB"; + + if(!fbModeOpenCV.empty()) return fbModeOpenCV; + return fbModeDef; + } + + static std::string& getFBFileName() + { + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); + static std::string fbFileNameDef = "/dev/fb0"; + + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if(!fbFileNameFB.empty()) return fbFileNameFB; + return fbFileNameDef; + } + + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): backend(_backend), flags(_flags) { @@ -55,17 +79,6 @@ namespace cv { namespace highgui_backend { return; } - if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); - return; - } - - if(backend.getFBBitsPerPixel() != 32) { - CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " - << backend.getFBBitsPerPixel() << " is not supported" ); - return; - } - Mat img(image.getMat()); switch(img.channels()){ case 1: @@ -140,9 +153,25 @@ namespace cv { namespace highgui_backend { CV_Assert(0); } - CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); + + if(backend.getMode() == FB_MODE_EMU) + { + CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); + return; + } + + if (backend.getFBPointer() == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); + return; + } + + if(backend.getFBBitsPerPixel() != 32) { + CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " + << backend.getFBBitsPerPixel() << " is not supported" ); + return; + } // SHOW IMAGE int xOffset = backend.getFBXOffset(); @@ -280,20 +309,6 @@ namespace cv { namespace highgui_backend { // !!##FramebufferBackend - static std::string& getFBFileName() - { - static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); - static std::string fbFileNameOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FRAMEBUFFER", ""); - static std::string fbFileNameDef = "/dev/fb0"; - - if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - if(!fbFileNameFB.empty()) return fbFileNameFB; - return fbFileNameDef; - } - - int FramebufferBackend::fbOpenAndGetInfo() { std::string fbFileName = getFBFileName(); @@ -382,20 +397,48 @@ namespace cv { namespace highgui_backend { { return backgroundBuff; } + OpenCVFBMode FramebufferBackend::getMode() + { + return mode; + } - FramebufferBackend::FramebufferBackend() + FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - fbID = fbOpenAndGetInfo(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); + std::string fbModeStr = getFBMode(); + + if(fbModeStr == "EMU") + { + mode = FB_MODE_EMU; + } + if(fbModeStr == "FB") + { + mode = FB_MODE_FB; + } + if(fbModeStr == "XVFB") + { + mode = FB_MODE_XVFB; + } + + fbID = -1; + if(mode == FB_MODE_FB) + { + fbID = fbOpenAndGetInfo(); + } + + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); + if(fbID == -1){ + mode = FB_MODE_EMU; fbWidth = 0; fbHeight = 0; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; fbLineLength = 0; + + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); return; } @@ -538,30 +581,26 @@ namespace cv { namespace highgui_backend { code = ch; } } else { - if(delay > 0) + bool f_kbhit = false; + while(!(f_kbhit = kbhit()) && (delay > 0)) { - bool f_kbhit = false; - while(!(f_kbhit = kbhit()) && (delay > 0)) - { - delay -= 1; - usleep(1000); - } - if(f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + delay -= 1; + usleep(1000); + } + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; - - while((ch = getch_(0, 0))>=0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } } - } } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index a076f4e97ed4..db6611b53007 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -11,6 +11,12 @@ namespace cv { namespace highgui_backend { +enum OpenCVFBMode{ + FB_MODE_EMU, + FB_MODE_FB, + FB_MODE_XVFB +}; + class FramebufferBackend; class CV_EXPORTS FramebufferWindow : public UIWindow { @@ -60,6 +66,8 @@ class CV_EXPORTS FramebufferBackend: public UIBackend // int OpenInputEvent(); // int eventKey; + OpenCVFBMode mode; + struct termios old, current; void initTermios(int echo, int wait); @@ -97,6 +105,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend int getFBLineLength(); unsigned char* getFBPointer(); Mat& getBackgroundBuff(); + OpenCVFBMode getMode(); FramebufferBackend(); From c110050425e21ebb168312ccce671ea5c3a3d8a3 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 20 May 2024 23:09:08 +0300 Subject: [PATCH 49/81] fix warning --- modules/highgui/src/window_framebuffer.cpp | 17 +++++++++-------- modules/highgui/src/window_framebuffer.hpp | 3 --- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 7b6e35fc329c..5b455edf9b94 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -201,7 +201,7 @@ namespace cv { namespace highgui_backend { { std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + xOffset + windowRect.x, - img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, + img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, showCols * cntChannel); } } @@ -266,24 +266,24 @@ namespace cv { namespace highgui_backend { CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } - void FramebufferWindow::setMouseCallback(MouseCallback onMouse, void* userdata ) + void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/ ) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); } std::shared_ptr FramebufferWindow::createTrackbar( - const std::string& name, - int count, - TrackbarCallback onChange, - void* userdata) + const std::string& /*name*/, + int /*count*/, + TrackbarCallback /*onChange*/, + void* /*userdata*/) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); return nullptr; } - std::shared_ptr FramebufferWindow::findTrackbar(const std::string& name) + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); @@ -479,7 +479,8 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), + unsigned char* backgroundPtr = backgroundBuff.ptr(y - fbYOffset); + std::memcpy(backgroundPtr, fbPointer + y * fbLineLength + fbXOffset, backgroundBuff.cols * cnt_channel); } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index db6611b53007..a5128b715d27 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -63,9 +63,6 @@ class CV_EXPORTS FramebufferWindow : public UIWindow class CV_EXPORTS FramebufferBackend: public UIBackend { -// int OpenInputEvent(); -// int eventKey; - OpenCVFBMode mode; struct termios old, current; From 6aa4d400a7db599f77a41728085da38863b6ef58 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 21 May 2024 16:03:03 +0300 Subject: [PATCH 50/81] add XVFB mode support --- modules/highgui/CMakeLists.txt | 2 + modules/highgui/src/XWDFile.h | 125 ++++++++++++++++++ modules/highgui/src/Xmd.h | 146 +++++++++++++++++++++ modules/highgui/src/window_framebuffer.cpp | 134 ++++++++++++++----- modules/highgui/src/window_framebuffer.hpp | 6 + 5 files changed, 382 insertions(+), 31 deletions(-) create mode 100644 modules/highgui/src/XWDFile.h create mode 100644 modules/highgui/src/Xmd.h diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index d4b0a7ff0548..23486149aa1e 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -44,6 +44,8 @@ if(WITH_FRAMEBUFFER) add_definitions(-DHAVE_FRAMEBUFFER) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/XWDFile.h) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/Xmd.h) endif() diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h new file mode 100644 index 000000000000..eddb4eed2196 --- /dev/null +++ b/modules/highgui/src/XWDFile.h @@ -0,0 +1,125 @@ +/* + +Copyright 1985, 1986, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * XWDFile.h MIT Project Athena, X Window system window raster + * image dumper, dump file format header file. + * + * Author: Tony Della Fera, DEC + * 27-Jun-85 + * + * Modifier: William F. Wyatt, SAO + * 18-Nov-86 - version 6 for saving/restoring color maps + */ + +#ifndef XWDFILE_H +#define XWDFILE_H + +#include "Xmd.h" + +#define XWD_FILE_VERSION 7 +#define sz_XWDheader 100 +#define sz_XWDColor 12 + +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) + +/***************************************************************** + * IMAGING + *****************************************************************/ + +/* ImageFormat -- PutImage, GetImage */ + +#define XYBitmap 0 /* depth 1, XYFormat */ +#define XYPixmap 1 /* depth == drawable depth */ +#define ZPixmap 2 /* depth == drawable depth */ + +typedef CARD32 xwdval; /* for old broken programs */ + +/* Values in the file are most significant byte first. */ + +typedef struct _xwd_file_header { + /* header_size = SIZEOF(XWDheader) + length of null-terminated + * window name. */ + CARD32 header_size; + + CARD32 file_version; /* = XWD_FILE_VERSION above */ + CARD32 pixmap_format; /* ZPixmap or XYPixmap */ + CARD32 pixmap_depth; /* Pixmap depth */ + CARD32 pixmap_width; /* Pixmap width */ + CARD32 pixmap_height; /* Pixmap height */ + CARD32 xoffset; /* Bitmap x offset, normally 0 */ + CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ + + /* bitmap_unit applies to bitmaps (depth 1 format XY) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_unit; + + CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ + + /* bitmap_pad applies to pixmaps (non-bitmaps) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_pad; + + CARD32 bits_per_pixel; /* Bits per pixel */ + + /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) + * or bitmap_pad (pixmaps). It is the delta (in bytes) to get + * to the same x position on an adjacent row. */ + CARD32 bytes_per_line; + CARD32 visual_class; /* Class of colormap */ + CARD32 red_mask; /* Z red mask */ + CARD32 green_mask; /* Z green mask */ + CARD32 blue_mask; /* Z blue mask */ + CARD32 bits_per_rgb; /* Log2 of distinct color values */ + CARD32 colormap_entries; /* Number of entries in colormap; not used? */ + CARD32 ncolors; /* Number of XWDColor structures */ + CARD32 window_width; /* Window width */ + CARD32 window_height; /* Window height */ + CARD32 window_x; /* Window upper left X coordinate */ + CARD32 window_y; /* Window upper left Y coordinate */ + CARD32 window_bdrwidth; /* Window border width */ +} XWDFileHeader; + +/* Null-terminated window name follows the above structure. */ + +/* Next comes XWDColor structures, at offset XWDFileHeader.header_size in + * the file. XWDFileHeader.ncolors tells how many XWDColor structures + * there are. + */ + +typedef struct { + CARD32 pixel; + CARD16 red; + CARD16 green; + CARD16 blue; + CARD8 flags; + CARD8 pad; +} XWDColor; + +/* Last comes the image data in the format described by XWDFileHeader. */ + +#endif /* XWDFILE_H */ + diff --git a/modules/highgui/src/Xmd.h b/modules/highgui/src/Xmd.h new file mode 100644 index 000000000000..68c45dbec0ee --- /dev/null +++ b/modules/highgui/src/Xmd.h @@ -0,0 +1,146 @@ +/*********************************************************** + +Copyright 1987, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ +#ifndef XMD_H +# define XMD_H 1 +/* + * Xmd.h: MACHINE DEPENDENT DECLARATIONS. + */ + +/* + * Special per-machine configuration flags. + */ +# if defined(__sun) && defined(__SVR4) +# include /* Solaris: defines _LP64 if necessary */ +# endif + +#if defined(__SIZEOF_LONG__) +# if __SIZEOF_LONG__ == 8 +# define LONG64 /* 32/64-bit architecture */ +# endif +# elif defined (_LP64) || defined(__LP64__) || \ + defined(__alpha) || defined(__alpha__) || \ + defined(__ia64__) || defined(ia64) || \ + defined(__sparc64__) || \ + defined(__s390x__) || \ + defined(__amd64__) || defined(amd64) || \ + defined(__powerpc64__) +# if !defined(__ILP32__) /* amd64-x32 is 32bit */ +# define LONG64 /* 32/64-bit architecture */ +# endif /* !__ILP32__ */ +# endif + +/* + * Definition of macro used to set constants for size of network structures; + * machines with preprocessors that can't handle all of the sz_ symbols + * can define this macro to be sizeof(x) if and only if their compiler doesn't + * pad out structures (esp. the xTextElt structure which contains only two + * one-byte fields). Network structures should always define sz_symbols. + * + * The sz_ prefix is used instead of something more descriptive so that the + * symbols are no more than 32 characters long (which causes problems for some + * compilers and preprocessors). + * + * The extra indirection is to get macro arguments to expand correctly before + * the concatenation, rather than afterward. + */ +# define _SIZEOF(x) sz_##x +# define SIZEOF(x) _SIZEOF(x) + +/* + * Bitfield suffixes for the protocol structure elements, if you + * need them. Note that bitfields are not guaranteed to be signed + * (or even unsigned) according to ANSI C. + */ +# define B32 /* bitfield not needed on architectures with native 32-bit type */ +# define B16 /* bitfield not needed on architectures with native 16-bit type */ +# ifdef LONG64 +typedef long INT64; +typedef int INT32; +# else +typedef long INT32; +# endif +typedef short INT16; + +typedef signed char INT8; + +# ifdef LONG64 +typedef unsigned long CARD64; +typedef unsigned int CARD32; +# else +typedef unsigned long long CARD64; +typedef unsigned long CARD32; +# endif +typedef unsigned short CARD16; +typedef unsigned char CARD8; + +typedef CARD32 BITS32; +typedef CARD16 BITS16; + +typedef CARD8 BYTE; +typedef CARD8 BOOL; + +/* + * was definitions for sign-extending bitfields on architectures without + * native types smaller than 64-bit, now just backwards compatibility + */ +# define cvtINT8toInt(val) (val) +# define cvtINT16toInt(val) (val) +# define cvtINT32toInt(val) (val) +# define cvtINT8toShort(val) (val) +# define cvtINT16toShort(val) (val) +# define cvtINT32toShort(val) (val) +# define cvtINT8toLong(val) (val) +# define cvtINT16toLong(val) (val) +# define cvtINT32toLong(val) (val) + +/* + * this version should leave result of type (t *), but that should only be + * used when not in MUSTCOPY + */ +# define NEXTPTR(p,t) (((t *)(p)) + 1) + +#endif /* XMD_H */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 5b455edf9b94..7404f85065f5 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -21,6 +21,7 @@ #include "opencv2/imgproc.hpp" +#include "XWDFile.h" namespace cv { namespace highgui_backend { @@ -68,7 +69,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::imshow(InputArray image) { - currentImg = image.getMat(); + currentImg = image.getMat().clone(); CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " @@ -79,7 +80,7 @@ namespace cv { namespace highgui_backend { return; } - Mat img(image.getMat()); + Mat img(image.getMat().clone()); switch(img.channels()){ case 1: switch(img.type()) @@ -350,6 +351,94 @@ namespace cv { namespace highgui_backend { return -1; } + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.yoffset; + fbYOffset = varInfo.xoffset; + fbBitsPerPixel = varInfo.bits_per_pixel; + fbLineLength = fixInfo.line_length; + + // MAP FB TO MEMORY + fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * + max((__u32)fbHeight, varInfo.yres_virtual) * + fbBitsPerPixel / 8; + + fbPointer = (unsigned char*) + mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, + fbID, 0); + + if (fbPointer == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); + return -1; + } + + return fb_fd; + } + + int FramebufferBackend::XvfbOpenAndGetInfo() + { + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) + { + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; + } + + XWDFileHeader *xwd_header; + + xwd_header = (XWDFileHeader*) mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); + + if (xwd_header == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); + return -1; + } + + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ){ + CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); + return -1; + } + + if( xwd_header->xoffset != 0 ){ + CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); + return -1; + } + + unsigned int r = C32INT(&(xwd_header-> red_mask)); + unsigned int g = C32INT(&(xwd_header->green_mask)); + unsigned int b = C32INT(&(xwd_header-> blue_mask)); + + fbWidth = C32INT(&(xwd_header->pixmap_width)); + fbHeight = C32INT(&(xwd_header->pixmap_height)); + fbXOffset = 0; + fbYOffset = 0; + fbLineLength = C32INT(&(xwd_header->bytes_per_line)); + fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); + + CV_LOG_INFO(NULL, "UI: XVFB info: \n" + << " red_mask " << r << "\n" + << " green_mask " << g << "\n" + << " blue_mask " << b << "\n" + << "bits_per_pixel " << fbBitsPerPixel); + + if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32) ){ + CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported (use BGRA format with bits_per_pixel = 32)"); + return -1; + } + + xvfb_len_header = C32INT(&(xwd_header->header_size)); + xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * C32INT(&(xwd_header->pixmap_height)); + munmap(xwd_header, sizeof(XWDFileHeader)); + + fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; + xwd_header = (XWDFileHeader*) mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header ; + fbPointer_dist = xvfb_len_header + xvfb_len_colors; + return fb_fd; } @@ -391,7 +480,7 @@ namespace cv { namespace highgui_backend { } unsigned char* FramebufferBackend::getFBPointer() { - return fbPointer; + return fbPointer + fbPointer_dist; } Mat& FramebufferBackend::getBackgroundBuff() { @@ -402,7 +491,7 @@ namespace cv { namespace highgui_backend { return mode; } - FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU) + FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU), fbPointer_dist(0) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); @@ -411,14 +500,17 @@ namespace cv { namespace highgui_backend { if(fbModeStr == "EMU") { mode = FB_MODE_EMU; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); } if(fbModeStr == "FB") { mode = FB_MODE_FB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); } if(fbModeStr == "XVFB") { mode = FB_MODE_XVFB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); } fbID = -1; @@ -426,13 +518,17 @@ namespace cv { namespace highgui_backend { { fbID = fbOpenAndGetInfo(); } + if(mode == FB_MODE_XVFB) + { + fbID = XvfbOpenAndGetInfo(); + } CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); if(fbID == -1){ mode = FB_MODE_EMU; - fbWidth = 0; - fbHeight = 0; + fbWidth = 10; + fbHeight = 10; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; @@ -442,12 +538,6 @@ namespace cv { namespace highgui_backend { return; } - fbWidth = varInfo.xres; - fbHeight = varInfo.yres; - fbXOffset = varInfo.yoffset; - fbYOffset = varInfo.xoffset; - fbBitsPerPixel = varInfo.bits_per_pixel; - fbLineLength = fixInfo.line_length; CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); @@ -455,25 +545,6 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " << fbXOffset << " " << fbYOffset << " " << fbLineLength); - // MAP FB TO MEMORY - fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * - max((__u32)fbHeight, varInfo.yres_virtual) * - fbBitsPerPixel / 8; - - fbPointer = (unsigned char*) - mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, - fbID, 0); - - if (fbPointer == MAP_FAILED) { - CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); - return; - } - - if(fbBitsPerPixel != 32) { - CV_LOG_WARNING(NULL, "UI: Framebuffer with bits per pixel = " - << fbBitsPerPixel << " is not supported" ); - return; - } backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; @@ -500,6 +571,7 @@ namespace cv { namespace highgui_backend { backgroundBuff.cols * cnt_channel); } + if (fbPointer != MAP_FAILED) { munmap(fbPointer, fbScreenSize); } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index a5128b715d27..c589fd12ea94 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -83,11 +83,17 @@ class CV_EXPORTS FramebufferBackend: public UIBackend int fbLineLength; long int fbScreenSize; unsigned char* fbPointer; + unsigned int fbPointer_dist; Mat backgroundBuff; int fbOpenAndGetInfo(); int fbID; + + unsigned int xvfb_len_header; + unsigned int xvfb_len_colors; + unsigned int xvfb_len_pixmap; + int XvfbOpenAndGetInfo(); public: From c353065d6669cd61ab0fbf737de60cdcdc25ea06 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 21 May 2024 22:59:12 +0300 Subject: [PATCH 51/81] fix style --- modules/highgui/src/window_framebuffer.cpp | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 7404f85065f5..eccd97a15cf3 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -128,13 +128,6 @@ namespace cv { namespace highgui_backend { windowRect.height = imgSize.height; } break; -// case WINDOW_FULLSCREEN: -// windowRect.width = backend.getFBWidth(); -// windowRect.height = backend.getFBHeight(); -// newWidth = windowRect.width; -// newHeight = windowRect.height; -// cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); -// break; case WINDOW_NORMAL: // WINDOW_KEEPRATIO { double aspect_ratio = ((double)img.cols) / img.rows; @@ -167,12 +160,6 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } - - if(backend.getFBBitsPerPixel() != 32) { - CV_LOG_ERROR(NULL, "UI: Framebuffer with bits per pixel = " - << backend.getFBBitsPerPixel() << " is not supported" ); - return; - } // SHOW IMAGE int xOffset = backend.getFBXOffset(); @@ -214,6 +201,7 @@ namespace cv { namespace highgui_backend { return 0.0; } + bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " @@ -308,7 +296,7 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } -// !!##FramebufferBackend +//FramebufferBackend int FramebufferBackend::fbOpenAndGetInfo() { @@ -446,46 +434,57 @@ namespace cv { namespace highgui_backend { { return varInfo; } + fb_fix_screeninfo &FramebufferBackend::getFixInfo() { return fixInfo; } + int FramebufferBackend::getFramebuffrerID() { return fbID; } + int FramebufferBackend::getFBWidth() { return fbWidth; } + int FramebufferBackend::getFBHeight() { return fbHeight; } + int FramebufferBackend::getFBXOffset() { return fbXOffset; } + int FramebufferBackend::getFBYOffset() { return fbYOffset; } + int FramebufferBackend::getFBBitsPerPixel() { return fbBitsPerPixel; } + int FramebufferBackend::getFBLineLength() { return fbLineLength; } + unsigned char* FramebufferBackend::getFBPointer() { return fbPointer + fbPointer_dist; } + Mat& FramebufferBackend::getBackgroundBuff() { return backgroundBuff; } + OpenCVFBMode FramebufferBackend::getMode() { return mode; @@ -576,7 +575,6 @@ namespace cv { namespace highgui_backend { munmap(fbPointer, fbScreenSize); } close(fbID); - } void FramebufferBackend::destroyAllWindows() { @@ -622,6 +620,7 @@ namespace cv { namespace highgui_backend { resetTermios(); return ch; } + bool FramebufferBackend::kbhit() { int byteswaiting=0; @@ -653,7 +652,9 @@ namespace cv { namespace highgui_backend { << (int)ch << " (additional code on )"); code = ch; } - } else { + } + else + { bool f_kbhit = false; while(!(f_kbhit = kbhit()) && (delay > 0)) { @@ -707,6 +708,5 @@ namespace cv { namespace highgui_backend { return code; } - } } From 01f95fa990193a338373dd78bf1f3469953ae245 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Thu, 23 May 2024 18:35:05 +0300 Subject: [PATCH 52/81] fix error FB mode --- modules/highgui/src/window_framebuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index eccd97a15cf3..ee5ee3abbac6 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -353,7 +353,7 @@ namespace cv { namespace highgui_backend { fbPointer = (unsigned char*) mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, - fbID, 0); + fb_fd, 0); if (fbPointer == MAP_FAILED) { CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); From 43aa713091734042e04e601bfcfb64bc138d722a Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 08:41:25 +0300 Subject: [PATCH 53/81] comment added. destructor fixed --- modules/highgui/src/XWDFile.h | 12 +++++++++--- modules/highgui/src/window_framebuffer.cpp | 18 +++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index eddb4eed2196..513fa6083114 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -38,24 +38,30 @@ in this Software without prior written authorization from The Open Group. #ifndef XWDFILE_H #define XWDFILE_H +// replaced "#include " with "#include "Xmd.h"" #include "Xmd.h" #define XWD_FILE_VERSION 7 #define sz_XWDheader 100 #define sz_XWDColor 12 -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) - /***************************************************************** - * IMAGING + * Start. Added from *****************************************************************/ +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) + /* ImageFormat -- PutImage, GetImage */ #define XYBitmap 0 /* depth 1, XYFormat */ #define XYPixmap 1 /* depth == drawable depth */ #define ZPixmap 2 /* depth == drawable depth */ +/***************************************************************** + * End. Added from + *****************************************************************/ + + typedef CARD32 xwdval; /* for old broken programs */ /* Values in the file are most significant byte first. */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index ee5ee3abbac6..2ee074607077 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -562,16 +562,16 @@ namespace cv { namespace highgui_backend { if(fbID == -1) return; // RESTORE BACKGROUNG - int cnt_channel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) - { - std::memcpy(fbPointer + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cnt_channel); - } - - if (fbPointer != MAP_FAILED) { + + int cnt_channel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + { + std::memcpy(fbPointer + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); + } + munmap(fbPointer, fbScreenSize); } close(fbID); From 81afac4d694269cb0b30f60ec6085fb631b63dd4 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 10:13:54 +0300 Subject: [PATCH 54/81] fixed handling of window processing flags --- modules/highgui/src/window_framebuffer.cpp | 56 +++++++++++----------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 2ee074607077..73f0aa4c55a7 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -115,38 +115,36 @@ namespace cv { namespace highgui_backend { int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - switch(flags) + + if(flags & WINDOW_AUTOSIZE) { - case WINDOW_FREERATIO: - { - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); - } - break; - case WINDOW_AUTOSIZE: // WINDOW_FULLSCREEN - { windowRect.width = imgSize.width; windowRect.height = imgSize.height; - } - break; - case WINDOW_NORMAL: // WINDOW_KEEPRATIO - { - double aspect_ratio = ((double)img.cols) / img.rows; - newWidth = windowRect.width; - newHeight = (int)(windowRect.width / aspect_ratio); + } + + if(flags & WINDOW_FREERATIO) + { + newWidth = windowRect.width; + newHeight = windowRect.height; + } + + if(flags & WINDOW_KEEPRATIO) + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); - if (newHeight > windowRect.height) { - newWidth = (int)(windowRect.height * aspect_ratio); - newHeight = windowRect.height; - } - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + if (newHeight > windowRect.height) { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; } - break; - - default: - CV_LOG_ERROR(NULL, "UI: FB window flag not supported"); - CV_Assert(0); } - + + if((newWidth != img.cols) && (newHeight != img.rows)) + { + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -219,7 +217,7 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - if(flags != WINDOW_AUTOSIZE) + if(flags & WINDOW_AUTOSIZE) { windowRect.width = width; windowRect.height = height; @@ -526,8 +524,8 @@ namespace cv { namespace highgui_backend { if(fbID == -1){ mode = FB_MODE_EMU; - fbWidth = 10; - fbHeight = 10; + fbWidth = 1024; + fbHeight = 768; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; From c0bc02f92097f3dda46cfcdbd5f56311ad991df0 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 10:38:07 +0300 Subject: [PATCH 55/81] fix WINDOW_AUTOSIZE --- modules/highgui/src/window_framebuffer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 73f0aa4c55a7..86e73ce68be5 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -118,8 +118,10 @@ namespace cv { namespace highgui_backend { if(flags & WINDOW_AUTOSIZE) { - windowRect.width = imgSize.width; - windowRect.height = imgSize.height; + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + newWidth = windowRect.width; + newHeight = windowRect.height; } if(flags & WINDOW_FREERATIO) From 9f0dccd34ea410994ccb7946168affe0ab2e0f01 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 24 May 2024 21:57:28 +0300 Subject: [PATCH 56/81] fix show size --- modules/highgui/src/window_framebuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 86e73ce68be5..48d7fb06f9d4 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -166,8 +166,8 @@ namespace cv { namespace highgui_backend { int yOffset = backend.getFBYOffset(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); - int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); + int showRows = min((windowRect.y + img.rows), backend.getFBHeight() - yOffset); + int showCols = min((windowRect.x + img.cols), backend.getFBWidth() - xOffset); int dx_w = windowRect.x; int dy_w = windowRect.y; From 6531b7552caca0dc4ec6a7b957d2a01253e2a2af Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 27 May 2024 19:42:22 +0300 Subject: [PATCH 57/81] fixed some bugs and comments --- modules/highgui/src/XWDFile.h | 7 +++---- modules/highgui/src/window_framebuffer.cpp | 22 +++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index 513fa6083114..cd11d802aca2 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -45,14 +45,13 @@ in this Software without prior written authorization from The Open Group. #define sz_XWDheader 100 #define sz_XWDColor 12 +// Added macro to convert big-endian numbers to local representation +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) + /***************************************************************** * Start. Added from *****************************************************************/ -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) - -/* ImageFormat -- PutImage, GetImage */ - #define XYBitmap 0 /* depth 1, XYFormat */ #define XYPixmap 1 /* depth == drawable depth */ #define ZPixmap 2 /* depth == drawable depth */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 48d7fb06f9d4..2fae73a88a88 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -115,7 +115,6 @@ namespace cv { namespace highgui_backend { int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - if(flags & WINDOW_AUTOSIZE) { windowRect.width = imgSize.width; @@ -129,8 +128,7 @@ namespace cv { namespace highgui_backend { newWidth = windowRect.width; newHeight = windowRect.height; } - - if(flags & WINDOW_KEEPRATIO) + else //WINDOW_KEEPRATIO { double aspect_ratio = ((double)img.cols) / img.rows; newWidth = windowRect.width; @@ -166,8 +164,8 @@ namespace cv { namespace highgui_backend { int yOffset = backend.getFBYOffset(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight() - yOffset); - int showCols = min((windowRect.x + img.cols), backend.getFBWidth() - xOffset); + int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); + int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); int dx_w = windowRect.x; int dy_w = windowRect.y; @@ -184,11 +182,9 @@ namespace cv { namespace highgui_backend { showRows -= dy_w; showCols -= dx_w; - for (int y = yOffset; y < showRows + yOffset; y++) { - std::memcpy(backend.getFBPointer() + (y + windowRect.y) * lineLength + - xOffset + windowRect.x, + std::memcpy(backend.getFBPointer() + (y + dy_w) * lineLength + xOffset + dx_w, img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, showCols * cntChannel); } @@ -219,7 +215,7 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - if(flags & WINDOW_AUTOSIZE) + if(!(flags & WINDOW_AUTOSIZE)) { windowRect.width = width; windowRect.height = height; @@ -339,16 +335,16 @@ namespace cv { namespace highgui_backend { return -1; } - fbWidth = varInfo.xres; - fbHeight = varInfo.yres; + fbWidth = varInfo.xres_virtual; + fbHeight = varInfo.yres_virtual; fbXOffset = varInfo.yoffset; fbYOffset = varInfo.xoffset; fbBitsPerPixel = varInfo.bits_per_pixel; fbLineLength = fixInfo.line_length; // MAP FB TO MEMORY - fbScreenSize = max((__u32)fbWidth , varInfo.xres_virtual) * - max((__u32)fbHeight, varInfo.yres_virtual) * + fbScreenSize = max(varInfo.xres, varInfo.xres_virtual) * + max(varInfo.yres, varInfo.yres_virtual) * fbBitsPerPixel / 8; fbPointer = (unsigned char*) From db848a782c65c8ccd4767743633e097d710326f4 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 10:10:06 +0300 Subject: [PATCH 58/81] The window display algorithm has been replaced. several bugs fixed --- modules/highgui/src/window_framebuffer.cpp | 129 ++++++++++++++------- 1 file changed, 90 insertions(+), 39 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 2fae73a88a88..258001501906 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -162,31 +162,74 @@ namespace cv { namespace highgui_backend { // SHOW IMAGE int xOffset = backend.getFBXOffset(); int yOffset = backend.getFBYOffset(); + int fbHeight = backend.getFBHeight(); + int fbWidth = backend.getFBWidth(); int lineLength = backend.getFBLineLength(); - int showRows = min((windowRect.y + img.rows), backend.getFBHeight()); - int showCols = min((windowRect.x + img.cols), backend.getFBWidth()); - - int dx_w = windowRect.x; - int dy_w = windowRect.y; + int img_start_x; + int img_start_y; + int img_end_x; + int img_end_y; + int fb_start_x; + int fb_start_y; - int start_y_w = 0; - int start_x_w = 0; - - if(dy_w < 0) start_y_w = -dy_w; - if(dx_w < 0) start_x_w = -dx_w; + if(windowRect.y - yOffset < 0) + { + img_start_y = - (windowRect.y - yOffset); + } + else + { + img_start_y = 0; + } + if( windowRect.x - xOffset < 0 ) + { + img_start_x = - (windowRect.x - xOffset); + } + else + { + img_start_x = 0; + } - if(dy_w < 0) dy_w = 0; - if(dx_w < 0) dx_w = 0; + if( windowRect.y + yOffset + img.rows > fbHeight ) + { + img_end_y = fbHeight - windowRect.y - yOffset; + } + else + { + img_end_y = img.rows; + } + if( windowRect.x + xOffset + img.cols > fbWidth ) + { + img_end_x = fbWidth - windowRect.x - xOffset; + } + else + { + img_end_x = img.cols; + } - showRows -= dy_w; - showCols -= dx_w; + if( windowRect.y + yOffset >= 0 ) + { + fb_start_y = windowRect.y + yOffset; + } + else + { + fb_start_y = 0; + } + if( windowRect.x + xOffset >= 0 ) + { + fb_start_x = windowRect.x + xOffset; + } + else + { + fb_start_x = 0; + } - for (int y = yOffset; y < showRows + yOffset; y++) + for (int y = img_start_y; y < img_end_y; y++) { - std::memcpy(backend.getFBPointer() + (y + dy_w) * lineLength + xOffset + dx_w, - img.ptr(y - yOffset + start_y_w) + start_x_w * cntChannel, - showCols * cntChannel); + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, + (img_end_x - img_start_x) * cntChannel); } } @@ -220,7 +263,7 @@ namespace cv { namespace highgui_backend { windowRect.width = width; windowRect.height = height; - if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + if((currentImg.cols > 0) && (currentImg.rows > 0)) { imshow(currentImg); } @@ -233,7 +276,7 @@ namespace cv { namespace highgui_backend { windowRect.x = x; windowRect.y = y; - if((currentImg.size().width > 0) && (currentImg.size().height > 0)) + if((currentImg.cols > 0) && (currentImg.rows > 0)) { imshow(currentImg); } @@ -307,13 +350,15 @@ namespace cv { namespace highgui_backend { } // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; } // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } @@ -335,10 +380,10 @@ namespace cv { namespace highgui_backend { return -1; } - fbWidth = varInfo.xres_virtual; - fbHeight = varInfo.yres_virtual; - fbXOffset = varInfo.yoffset; - fbYOffset = varInfo.xoffset; + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.xoffset; + fbYOffset = varInfo.yoffset; fbBitsPerPixel = varInfo.bits_per_pixel; fbLineLength = fixInfo.line_length; @@ -375,17 +420,20 @@ namespace cv { namespace highgui_backend { xwd_header = (XWDFileHeader*) mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); - if (xwd_header == MAP_FAILED) { + if (xwd_header == MAP_FAILED) + { CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); return -1; } - if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ){ + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ) + { CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); return -1; } - if( xwd_header->xoffset != 0 ){ + if( xwd_header->xoffset != 0 ) + { CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); return -1; } @@ -408,7 +456,8 @@ namespace cv { namespace highgui_backend { << "bits_per_pixel " << fbBitsPerPixel); if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32) ){ + (fbBitsPerPixel != 32) ) + { CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported (use BGRA format with bits_per_pixel = 32)"); return -1; } @@ -486,7 +535,7 @@ namespace cv { namespace highgui_backend { return mode; } - FramebufferBackend::FramebufferBackend():mode(FB_MODE_EMU), fbPointer_dist(0) + FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); @@ -545,9 +594,8 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - unsigned char* backgroundPtr = backgroundBuff.ptr(y - fbYOffset); - std::memcpy(backgroundPtr, - fbPointer + y * fbLineLength + fbXOffset, + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset, backgroundBuff.cols * cnt_channel); } } @@ -563,7 +611,7 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(fbPointer + y * fbLineLength + fbXOffset, + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, backgroundBuff.ptr(y - fbYOffset), backgroundBuff.cols * cnt_channel); } @@ -594,10 +642,13 @@ namespace cv { namespace highgui_backend { current.c_lflag &= ~ICANON; // disable buffered i/o current.c_lflag &= ~ISIG; current.c_cc[VMIN]=wait; - if (echo) { - current.c_lflag |= ECHO; // set echo mode - } else { - current.c_lflag &= ~ECHO; // set no echo mode + if (echo) + { + current.c_lflag |= ECHO; // set echo mode + } + else + { + current.c_lflag &= ~ECHO; // set no echo mode } tcsetattr(0, TCSANOW, ¤t); // use these new terminal i/o settings now } From bbf587401b5ccf86c6ce1e6e805a3fe8d5ec0293 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 11:22:12 +0300 Subject: [PATCH 59/81] fix style --- modules/highgui/src/window_framebuffer.cpp | 1291 ++++++++++---------- modules/highgui/src/window_framebuffer.hpp | 180 +-- 2 files changed, 739 insertions(+), 732 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 258001501906..eebe24c34d36 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -24,736 +24,743 @@ #include "XWDFile.h" namespace cv { namespace highgui_backend { - - std::shared_ptr createUIBackendFramebuffer() - { - return std::make_shared(); - } - - static std::string& getFBMode() - { - static std::string fbModeOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); - static std::string fbModeDef = "FB"; - - if(!fbModeOpenCV.empty()) return fbModeOpenCV; - return fbModeDef; - } - - static std::string& getFBFileName() - { - static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); - static std::string fbFileNameOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); - static std::string fbFileNameDef = "/dev/fb0"; - - if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - if(!fbFileNameFB.empty()) return fbFileNameFB; - return fbFileNameDef; - } - - - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): - backend(_backend), flags(_flags) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); - FB_ID = "FramebufferWindow"; - windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); - } - - FramebufferWindow::~FramebufferWindow() - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); - } - - void FramebufferWindow::imshow(InputArray image) - { - currentImg = image.getMat().clone(); - - CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); - CV_LOG_INFO(NULL, "UI: InputArray image: " - << cv::typeToString(image.type()) << " size " << image.size()); - - if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) - { - return; - } - - Mat img(image.getMat().clone()); - switch(img.channels()){ - case 1: - switch(img.type()) - { - case CV_8S: - cv::convertScaleAbs(img, img, 1, 127); - break; - case CV_16S: - cv::convertScaleAbs(img, img, 1/255., 127); - break; - case CV_16U: - cv::convertScaleAbs(img, img, 1/255.); - break; - case CV_32F: - case CV_64F: // assuming image has values in range [0, 1) - img.convertTo(img, CV_8U, 255., 0.); - break; - } - cvtColor(img, img, cv::COLOR_GRAY2RGB); - break; - case 3: - convertToShow(img, img); - break; - case 4: - convertToShow(img, img, true); - break; - } - cvtColor(img, img, COLOR_RGB2BGRA); - - int newWidth = windowRect.width; - int newHeight = windowRect.height; - int cntChannel = img.channels(); - cv::Size imgSize = currentImg.size(); - - if(flags & WINDOW_AUTOSIZE) + + std::shared_ptr createUIBackendFramebuffer() { - windowRect.width = imgSize.width; - windowRect.height = imgSize.height; - newWidth = windowRect.width; - newHeight = windowRect.height; + return std::make_shared(); } - - if(flags & WINDOW_FREERATIO) + + static std::string& getFBMode() { - newWidth = windowRect.width; - newHeight = windowRect.height; + static std::string fbModeOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); + static std::string fbModeDef = "FB"; + + if(!fbModeOpenCV.empty()) return fbModeOpenCV; + return fbModeDef; } - else //WINDOW_KEEPRATIO + + static std::string& getFBFileName() { - double aspect_ratio = ((double)img.cols) / img.rows; - newWidth = windowRect.width; - newHeight = (int)(windowRect.width / aspect_ratio); + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); + static std::string fbFileNameDef = "/dev/fb0"; + + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if(!fbFileNameFB.empty()) return fbFileNameFB; + return fbFileNameDef; + } - if (newHeight > windowRect.height) { - newWidth = (int)(windowRect.height * aspect_ratio); - newHeight = windowRect.height; - } + + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + backend(_backend), flags(_flags) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); + FB_ID = "FramebufferWindow"; + windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); + } + + FramebufferWindow::~FramebufferWindow() + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); } - if((newWidth != img.cols) && (newHeight != img.rows)) + void FramebufferWindow::imshow(InputArray image) { - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); - } + currentImg = image.getMat().clone(); - CV_LOG_INFO(NULL, "UI: Formated image: " - << cv::typeToString(img.type()) << " size " << img.size()); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); + CV_LOG_INFO(NULL, "UI: InputArray image: " + << cv::typeToString(image.type()) << " size " << image.size()); + + if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) + { + return; + } - if(backend.getMode() == FB_MODE_EMU) - { - CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); - return; + Mat img(image.getMat().clone()); + switch(img.channels()){ + case 1: + switch(img.type()) + { + case CV_8S: + cv::convertScaleAbs(img, img, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, img, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, img, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(img, CV_8U, 255., 0.); + break; + } + cvtColor(img, img, cv::COLOR_GRAY2RGB); + break; + case 3: + convertToShow(img, img); + break; + case 4: + convertToShow(img, img, true); + break; + } + cvtColor(img, img, COLOR_RGB2BGRA); + + int newWidth = windowRect.width; + int newHeight = windowRect.height; + int cntChannel = img.channels(); + cv::Size imgSize = currentImg.size(); + + if(flags & WINDOW_AUTOSIZE) + { + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + newWidth = windowRect.width; + newHeight = windowRect.height; + } + + if(flags & WINDOW_FREERATIO) + { + newWidth = windowRect.width; + newHeight = windowRect.height; + } + else //WINDOW_KEEPRATIO + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); + + if (newHeight > windowRect.height) { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; + } + } + + if((newWidth != img.cols) && (newHeight != img.rows)) + { + cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + } + + CV_LOG_INFO(NULL, "UI: Formated image: " + << cv::typeToString(img.type()) << " size " << img.size()); + + if(backend.getMode() == FB_MODE_EMU) + { + CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); + return; + } + + if (backend.getFBPointer() == MAP_FAILED) { + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); + return; + } + + // SHOW IMAGE + int xOffset = backend.getFBXOffset(); + int yOffset = backend.getFBYOffset(); + int fbHeight = backend.getFBHeight(); + int fbWidth = backend.getFBWidth(); + int lineLength = backend.getFBLineLength(); + + int img_start_x; + int img_start_y; + int img_end_x; + int img_end_y; + int fb_start_x; + int fb_start_y; + + if(windowRect.y - yOffset < 0) + { + img_start_y = - (windowRect.y - yOffset); + } + else + { + img_start_y = 0; + } + if(windowRect.x - xOffset < 0) + { + img_start_x = - (windowRect.x - xOffset); + } + else + { + img_start_x = 0; + } + + if(windowRect.y + yOffset + img.rows > fbHeight) + { + img_end_y = fbHeight - windowRect.y - yOffset; + } + else + { + img_end_y = img.rows; + } + if(windowRect.x + xOffset + img.cols > fbWidth) + { + img_end_x = fbWidth - windowRect.x - xOffset; + } + else + { + img_end_x = img.cols; + } + + if(windowRect.y + yOffset >= 0) + { + fb_start_y = windowRect.y + yOffset; + } + else + { + fb_start_y = 0; + } + if(windowRect.x + xOffset >= 0) + { + fb_start_x = windowRect.x + xOffset; + } + else + { + fb_start_x = 0; + } + + for (int y = img_start_y; y < img_end_y; y++) + { + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, + (img_end_x - img_start_x) * cntChannel); + } } - if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); - return; + double FramebufferWindow::getProperty(int prop) const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); + CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + + return 0.0; } - - // SHOW IMAGE - int xOffset = backend.getFBXOffset(); - int yOffset = backend.getFBYOffset(); - int fbHeight = backend.getFBHeight(); - int fbWidth = backend.getFBWidth(); - int lineLength = backend.getFBLineLength(); - - int img_start_x; - int img_start_y; - int img_end_x; - int img_end_y; - int fb_start_x; - int fb_start_y; - if(windowRect.y - yOffset < 0) - { - img_start_y = - (windowRect.y - yOffset); + bool FramebufferWindow::setProperty(int prop, double value) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " + << prop << ", value " << value << ")"); + CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + + return false; } - else - { - img_start_y = 0; + + void FramebufferWindow::resize(int width, int height) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " + << width <<", height " << height << ")"); + + CV_Assert(width > 0); + CV_Assert(height > 0); + + if(!(flags & WINDOW_AUTOSIZE)) + { + windowRect.width = width; + windowRect.height = height; + + if((currentImg.cols > 0) && (currentImg.rows > 0)) + { + imshow(currentImg); + } + } } - if( windowRect.x - xOffset < 0 ) - { - img_start_x = - (windowRect.x - xOffset); + void FramebufferWindow::move(int x, int y) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); + + windowRect.x = x; + windowRect.y = y; + + if((currentImg.cols > 0) && (currentImg.rows > 0)) + { + imshow(currentImg); + } } - else + + Rect FramebufferWindow::getImageRect() const { - img_start_x = 0; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); + return windowRect; } - - if( windowRect.y + yOffset + img.rows > fbHeight ) + + void FramebufferWindow::setTitle(const std::string& title) { - img_end_y = fbHeight - windowRect.y - yOffset; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); + CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } - else + + void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/) { - img_end_y = img.rows; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); + CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); } - if( windowRect.x + xOffset + img.cols > fbWidth ) + + std::shared_ptr FramebufferWindow::createTrackbar( + const std::string& /*name*/, + int /*count*/, + TrackbarCallback /*onChange*/, + void* /*userdata*/) { - img_end_x = fbWidth - windowRect.x - xOffset; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); + return nullptr; } - else + + std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) { - img_end_x = img.cols; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); + CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); + return nullptr; } - if( windowRect.y + yOffset >= 0 ) - { - fb_start_y = windowRect.y + yOffset; + const std::string& FramebufferWindow::getID() const + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); + return FB_ID; } - else + + bool FramebufferWindow::isActive() const { - fb_start_y = 0; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); + return true; } - if( windowRect.x + xOffset >= 0 ) + + void FramebufferWindow::destroy() { - fb_start_x = windowRect.x + xOffset; + CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } - else + +//FramebufferBackend + + int FramebufferBackend::fbOpenAndGetInfo() { - fb_start_x = 0; + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" + << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) + { + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; + } + + // Get fixed screen information + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + { + CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); + return -1; + } + + // Get variable screen information + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + { + CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); + return -1; + } + + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" + << " green offset " <(y) + img_start_x * cntChannel, - (img_end_x - img_start_x) * cntChannel); - } - } + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" + << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) + { + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; + } - double FramebufferWindow::getProperty(int prop) const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); - CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + XWDFileHeader *xwd_header; + + xwd_header = (XWDFileHeader*) + mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); - return 0.0; - } + if (xwd_header == MAP_FAILED) + { + CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); + return -1; + } + + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ) + { + CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); + return -1; + } - bool FramebufferWindow::setProperty(int prop, double value) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " - << prop << ", value " << value << ")"); - CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + if( xwd_header->xoffset != 0 ) + { + CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); + return -1; + } + + unsigned int r = C32INT(&(xwd_header-> red_mask)); + unsigned int g = C32INT(&(xwd_header->green_mask)); + unsigned int b = C32INT(&(xwd_header-> blue_mask)); + + fbWidth = C32INT(&(xwd_header->pixmap_width)); + fbHeight = C32INT(&(xwd_header->pixmap_height)); + fbXOffset = 0; + fbYOffset = 0; + fbLineLength = C32INT(&(xwd_header->bytes_per_line)); + fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); + + CV_LOG_INFO(NULL, "UI: XVFB info: \n" + << " red_mask " << r << "\n" + << " green_mask " << g << "\n" + << " blue_mask " << b << "\n" + << "bits_per_pixel " << fbBitsPerPixel); + + if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32) ) + { + CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " + << "(use BGRA format with bits_per_pixel = 32)"); + return -1; + } - return false; - } + xvfb_len_header = C32INT(&(xwd_header->header_size)); + xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * + C32INT(&(xwd_header->pixmap_height)); + munmap(xwd_header, sizeof(XWDFileHeader)); - void FramebufferWindow::resize(int width, int height) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " - << width <<", height " << height << ")"); - - CV_Assert(width > 0); - CV_Assert(height > 0); - - if(!(flags & WINDOW_AUTOSIZE)) - { - windowRect.width = width; - windowRect.height = height; - - if((currentImg.cols > 0) && (currentImg.rows > 0)) - { - imshow(currentImg); - } - } - } - void FramebufferWindow::move(int x, int y) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); - - windowRect.x = x; - windowRect.y = y; - - if((currentImg.cols > 0) && (currentImg.rows > 0)) - { - imshow(currentImg); - } - } - - Rect FramebufferWindow::getImageRect() const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); - return windowRect; - } - - void FramebufferWindow::setTitle(const std::string& title) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); - CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); - } - - void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/ ) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); - CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); - } - - std::shared_ptr FramebufferWindow::createTrackbar( - const std::string& /*name*/, - int /*count*/, - TrackbarCallback /*onChange*/, - void* /*userdata*/) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); - CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); - return nullptr; - } - - std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); - CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); - return nullptr; - } - - const std::string& FramebufferWindow::getID() const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); - return FB_ID; - } - - bool FramebufferWindow::isActive() const - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); - return true; - } - - void FramebufferWindow::destroy() - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); - } + fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; + xwd_header = (XWDFileHeader*) + mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header ; + fbPointer_dist = xvfb_len_header + xvfb_len_colors; -//FramebufferBackend + return fb_fd; + } - int FramebufferBackend::fbOpenAndGetInfo() - { - std::string fbFileName = getFBFileName(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); - - int fb_fd = open(fbFileName.c_str(), O_RDWR); - if (fb_fd == -1) + fb_var_screeninfo &FramebufferBackend::getVarInfo() { - CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); - return -1; + return varInfo; } - // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + fb_fix_screeninfo &FramebufferBackend::getFixInfo() { - CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); - return -1; + return fixInfo; } - // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + int FramebufferBackend::getFramebuffrerID() { - CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); - return -1; + return fbID; } - - CV_LOG_INFO(NULL, "UI: framebuffer info: \n" - << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" - << " green offset " << varInfo.green.offset << " length " << varInfo.green.length << "\n" - << " blue offset " << varInfo.blue.offset << " length " << varInfo.blue.length << "\n" - << "transp offset " << varInfo.transp.offset << " length " <pixmap_format)) != ZPixmap ) + + int FramebufferBackend::getFBXOffset() { - CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); - return -1; + return fbXOffset; } - if( xwd_header->xoffset != 0 ) + int FramebufferBackend::getFBYOffset() { - CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); - return -1; + return fbYOffset; } - - unsigned int r = C32INT(&(xwd_header-> red_mask)); - unsigned int g = C32INT(&(xwd_header->green_mask)); - unsigned int b = C32INT(&(xwd_header-> blue_mask)); - - fbWidth = C32INT(&(xwd_header->pixmap_width)); - fbHeight = C32INT(&(xwd_header->pixmap_height)); - fbXOffset = 0; - fbYOffset = 0; - fbLineLength = C32INT(&(xwd_header->bytes_per_line)); - fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); - - CV_LOG_INFO(NULL, "UI: XVFB info: \n" - << " red_mask " << r << "\n" - << " green_mask " << g << "\n" - << " blue_mask " << b << "\n" - << "bits_per_pixel " << fbBitsPerPixel); - - if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32) ) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported (use BGRA format with bits_per_pixel = 32)"); - return -1; - } - - xvfb_len_header = C32INT(&(xwd_header->header_size)); - xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); - xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * C32INT(&(xwd_header->pixmap_height)); - munmap(xwd_header, sizeof(XWDFileHeader)); - - fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; - xwd_header = (XWDFileHeader*) mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); - fbPointer = (unsigned char*)xwd_header ; - fbPointer_dist = xvfb_len_header + xvfb_len_colors; - - return fb_fd; - } - - fb_var_screeninfo &FramebufferBackend::getVarInfo() - { - return varInfo; - } - - fb_fix_screeninfo &FramebufferBackend::getFixInfo() - { - return fixInfo; - } - - int FramebufferBackend::getFramebuffrerID() - { - return fbID; - } - - int FramebufferBackend::getFBWidth() - { - return fbWidth; - } - - int FramebufferBackend::getFBHeight() - { - return fbHeight; - } - - int FramebufferBackend::getFBXOffset() - { - return fbXOffset; - } - - int FramebufferBackend::getFBYOffset() - { - return fbYOffset; - } - - int FramebufferBackend::getFBBitsPerPixel() - { - return fbBitsPerPixel; - } - - int FramebufferBackend::getFBLineLength() - { - return fbLineLength; - } - - unsigned char* FramebufferBackend::getFBPointer() - { - return fbPointer + fbPointer_dist; - } - - Mat& FramebufferBackend::getBackgroundBuff() - { - return backgroundBuff; - } - - OpenCVFBMode FramebufferBackend::getMode() - { - return mode; - } - - FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) - { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - - std::string fbModeStr = getFBMode(); - - if(fbModeStr == "EMU") + + int FramebufferBackend::getFBBitsPerPixel() { - mode = FB_MODE_EMU; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); + return fbBitsPerPixel; } - if(fbModeStr == "FB") + + int FramebufferBackend::getFBLineLength() { - mode = FB_MODE_FB; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); + return fbLineLength; } - if(fbModeStr == "XVFB") + + unsigned char* FramebufferBackend::getFBPointer() { - mode = FB_MODE_XVFB; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); + return fbPointer + fbPointer_dist; } - fbID = -1; - if(mode == FB_MODE_FB) + Mat& FramebufferBackend::getBackgroundBuff() { - fbID = fbOpenAndGetInfo(); + return backgroundBuff; } - if(mode == FB_MODE_XVFB) + + OpenCVFBMode FramebufferBackend::getMode() { - fbID = XvfbOpenAndGetInfo(); + return mode; } + + FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) + { + CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); + + std::string fbModeStr = getFBMode(); + + if(fbModeStr == "EMU") + { + mode = FB_MODE_EMU; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); + } + if(fbModeStr == "FB") + { + mode = FB_MODE_FB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); + } + if(fbModeStr == "XVFB") + { + mode = FB_MODE_XVFB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); + } + + fbID = -1; + if(mode == FB_MODE_FB) + { + fbID = fbOpenAndGetInfo(); + } + if(mode == FB_MODE_XVFB) + { + fbID = XvfbOpenAndGetInfo(); + } + + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - - if(fbID == -1){ - mode = FB_MODE_EMU; - fbWidth = 1024; - fbHeight = 768; - fbXOffset = 0; - fbYOffset = 0; - fbBitsPerPixel = 0; - fbLineLength = 0; - - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); - return; + if(fbID == -1){ + mode = FB_MODE_EMU; + fbWidth = 1024; + fbHeight = 768; + fbXOffset = 0; + fbYOffset = 0; + fbBitsPerPixel = 0; + fbLineLength = 0; + + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); + return; + } + + + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + << fbXOffset << " " << fbYOffset << " " << fbLineLength); + + + backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); + int cnt_channel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + { + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.cols * cnt_channel); + } } - - CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " - << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + FramebufferBackend::~FramebufferBackend() + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); + if(fbID == -1) return; + + // RESTORE BACKGROUNG + if (fbPointer != MAP_FAILED) { + + int cnt_channel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + { + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); + } + + munmap(fbPointer, fbScreenSize); + } + close(fbID); + } - CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " - << fbXOffset << " " << fbYOffset << " " << fbLineLength); - + void FramebufferBackend::destroyAllWindows() { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); + } - backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); - int cnt_channel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) + // namedWindow + std::shared_ptr FramebufferBackend::createWindow( + const std::string& winname, + int flags) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.cols * cnt_channel); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" + << winname << ", " << flags << ")"); + return std::make_shared(*this, flags); + } + + void FramebufferBackend::initTermios(int echo, int wait) + { + tcgetattr(0, &old); + current = old; + current.c_lflag &= ~ICANON; + current.c_lflag &= ~ISIG; + current.c_cc[VMIN]=wait; + if (echo) + { + current.c_lflag |= ECHO; + } + else + { + current.c_lflag &= ~ECHO; + } + tcsetattr(0, TCSANOW, ¤t); + } + + void FramebufferBackend::resetTermios(void) + { + tcsetattr(0, TCSANOW, &old); + } + + int FramebufferBackend::getch_(int echo, int wait) + { + int ch; + initTermios(echo, wait); + ch = getchar(); + if(ch < 0) rewind(stdin); + resetTermios(); + return ch; } - } - - FramebufferBackend::~FramebufferBackend() - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); - if(fbID == -1) return; - - // RESTORE BACKGROUNG - if (fbPointer != MAP_FAILED) { - - int cnt_channel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) - { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cnt_channel); - } - - munmap(fbPointer, fbScreenSize); - } - close(fbID); - } - - void FramebufferBackend::destroyAllWindows() { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); - } - - // namedWindow - std::shared_ptr FramebufferBackend::createWindow( - const std::string& winname, - int flags) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" - << winname << ", " << flags << ")"); - return std::make_shared(*this, flags); - } - - void FramebufferBackend::initTermios(int echo, int wait) - { - tcgetattr(0, &old); // grab old terminal i/o settings - current = old; // make new settings same as old settings - current.c_lflag &= ~ICANON; // disable buffered i/o - current.c_lflag &= ~ISIG; - current.c_cc[VMIN]=wait; - if (echo) - { - current.c_lflag |= ECHO; // set echo mode - } - else - { - current.c_lflag &= ~ECHO; // set no echo mode - } - tcsetattr(0, TCSANOW, ¤t); // use these new terminal i/o settings now - } - - void FramebufferBackend::resetTermios(void) - { - tcsetattr(0, TCSANOW, &old); - } - - int FramebufferBackend::getch_(int echo, int wait) - { - int ch; - initTermios(echo, wait); - ch = getchar(); - if(ch < 0) rewind(stdin); - resetTermios(); - return ch; - } - - bool FramebufferBackend::kbhit() - { - int byteswaiting=0; - initTermios(0, 1); - if ( ioctl(0, FIONREAD, &byteswaiting) < 0) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); - } - resetTermios(); - return byteswaiting > 0; - } - - int FramebufferBackend::waitKeyEx(int delay) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); - - int code = -1; - - if(delay <= 0) - { - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; - - while((ch = getch_(0, 0))>=0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } - } - else - { - bool f_kbhit = false; - while(!(f_kbhit = kbhit()) && (delay > 0)) - { - delay -= 1; - usleep(1000); - } - if(f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; + bool FramebufferBackend::kbhit() + { + int byteswaiting=0; + initTermios(0, 1); + if ( ioctl(0, FIONREAD, &byteswaiting) < 0) + { + CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); + } + resetTermios(); - while((ch = getch_(0, 0))>=0) + return byteswaiting > 0; + } + + int FramebufferBackend::waitKeyEx(int delay) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); + + int code = -1; + + if(delay <= 0) + { + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } + else { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; + bool f_kbhit = false; + while(!(f_kbhit = kbhit()) && (delay > 0)) + { + delay -= 1; + usleep(1000); + } + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } } - } + + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); + return code; } - CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); - return code; - } - - int FramebufferBackend::pollKey() - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); - int code = -1; - bool f_kbhit = false; - f_kbhit = kbhit(); - - if(f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; - - while((ch = getch_(0, 0))>=0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } + int FramebufferBackend::pollKey() + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); + int code = -1; + bool f_kbhit = false; + f_kbhit = kbhit(); + + if(f_kbhit) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while((ch = getch_(0, 0))>=0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } + } + + return code; } - - return code; - } } } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index c589fd12ea94..acdbb6db8f87 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -12,118 +12,118 @@ namespace cv { namespace highgui_backend { enum OpenCVFBMode{ - FB_MODE_EMU, - FB_MODE_FB, - FB_MODE_XVFB + FB_MODE_EMU, + FB_MODE_FB, + FB_MODE_XVFB }; class FramebufferBackend; class CV_EXPORTS FramebufferWindow : public UIWindow { - FramebufferBackend &backend; - std::string FB_ID; - Rect windowRect; - - int flags; - Mat currentImg; + FramebufferBackend &backend; + std::string FB_ID; + Rect windowRect; + + int flags; + Mat currentImg; public: - FramebufferWindow(FramebufferBackend &backend, int flags); - virtual ~FramebufferWindow(); + FramebufferWindow(FramebufferBackend &backend, int flags); + virtual ~FramebufferWindow(); - virtual void imshow(InputArray image)override; + virtual void imshow(InputArray image)override; - virtual double getProperty(int prop) const override; - virtual bool setProperty(int prop, double value)override; + virtual double getProperty(int prop) const override; + virtual bool setProperty(int prop, double value)override; - virtual void resize(int width, int height)override; - virtual void move(int x, int y)override; + virtual void resize(int width, int height)override; + virtual void move(int x, int y)override; - virtual Rect getImageRect() const override; + virtual Rect getImageRect() const override; - virtual void setTitle(const std::string& title)override; + virtual void setTitle(const std::string& title)override; - virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; - virtual std::shared_ptr createTrackbar( - const std::string& name, - int count, - TrackbarCallback onChange /*= 0*/, - void* userdata /*= 0*/ - )override; + virtual std::shared_ptr createTrackbar( + const std::string& name, + int count, + TrackbarCallback onChange /*= 0*/, + void* userdata /*= 0*/ + )override; - virtual std::shared_ptr findTrackbar(const std::string& name)override; - - virtual const std::string& getID() const override; + virtual std::shared_ptr findTrackbar(const std::string& name)override; + + virtual const std::string& getID() const override; - virtual bool isActive() const override; + virtual bool isActive() const override; - virtual void destroy() override; -}; // FramebufferWindow + virtual void destroy() override; +}; // FramebufferWindow class CV_EXPORTS FramebufferBackend: public UIBackend { - OpenCVFBMode mode; - - struct termios old, current; - - void initTermios(int echo, int wait); - void resetTermios(void); - int getch_(int echo, int wait); - bool kbhit(); - - - fb_var_screeninfo varInfo; - fb_fix_screeninfo fixInfo; - int fbWidth; - int fbHeight; - int fbXOffset; - int fbYOffset; - int fbBitsPerPixel; - int fbLineLength; - long int fbScreenSize; - unsigned char* fbPointer; - unsigned int fbPointer_dist; - Mat backgroundBuff; - - - int fbOpenAndGetInfo(); - int fbID; - - unsigned int xvfb_len_header; - unsigned int xvfb_len_colors; - unsigned int xvfb_len_pixmap; - int XvfbOpenAndGetInfo(); - + OpenCVFBMode mode; + + struct termios old, current; + + void initTermios(int echo, int wait); + void resetTermios(void); + int getch_(int echo, int wait); + bool kbhit(); + + + fb_var_screeninfo varInfo; + fb_fix_screeninfo fixInfo; + int fbWidth; + int fbHeight; + int fbXOffset; + int fbYOffset; + int fbBitsPerPixel; + int fbLineLength; + long int fbScreenSize; + unsigned char* fbPointer; + unsigned int fbPointer_dist; + Mat backgroundBuff; + + + int fbOpenAndGetInfo(); + int fbID; + + unsigned int xvfb_len_header; + unsigned int xvfb_len_colors; + unsigned int xvfb_len_pixmap; + int XvfbOpenAndGetInfo(); + public: - fb_var_screeninfo &getVarInfo(); - fb_fix_screeninfo &getFixInfo(); - int getFramebuffrerID(); - int getFBWidth(); - int getFBHeight(); - int getFBXOffset(); - int getFBYOffset(); - int getFBBitsPerPixel(); - int getFBLineLength(); - unsigned char* getFBPointer(); - Mat& getBackgroundBuff(); - OpenCVFBMode getMode(); - - FramebufferBackend(); - - virtual ~FramebufferBackend(); - - virtual void destroyAllWindows()override; - - // namedWindow - virtual std::shared_ptr createWindow( - const std::string& winname, - int flags - )override; - - virtual int waitKeyEx(int delay /*= 0*/)override; - virtual int pollKey() override; + fb_var_screeninfo &getVarInfo(); + fb_fix_screeninfo &getFixInfo(); + int getFramebuffrerID(); + int getFBWidth(); + int getFBHeight(); + int getFBXOffset(); + int getFBYOffset(); + int getFBBitsPerPixel(); + int getFBLineLength(); + unsigned char* getFBPointer(); + Mat& getBackgroundBuff(); + OpenCVFBMode getMode(); + + FramebufferBackend(); + + virtual ~FramebufferBackend(); + + virtual void destroyAllWindows()override; + + // namedWindow + virtual std::shared_ptr createWindow( + const std::string& winname, + int flags + )override; + + virtual int waitKeyEx(int delay /*= 0*/)override; + virtual int pollKey() override; }; } From ba5828d663d4ae659c54ba2e1b016cc4c628216a Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 15:35:40 +0300 Subject: [PATCH 60/81] fix trailing whitespace. --- modules/highgui/src/XWDFile.h | 109 +++++---- modules/highgui/src/Xmd.h | 16 +- modules/highgui/src/window_framebuffer.cpp | 247 ++++++++++----------- modules/highgui/src/window_framebuffer.hpp | 26 +-- 4 files changed, 197 insertions(+), 201 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index cd11d802aca2..0d5f38a09aef 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -25,11 +25,11 @@ in this Software without prior written authorization from The Open Group. */ /* - * XWDFile.h MIT Project Athena, X Window system window raster - * image dumper, dump file format header file. + * XWDFile.h MIT Project Athena, X Window system window raster + * image dumper, dump file format header file. * - * Author: Tony Della Fera, DEC - * 27-Jun-85 + * Author: Tony Della Fera, DEC + * 27-Jun-85 * * Modifier: William F. Wyatt, SAO * 18-Nov-86 - version 6 for saving/restoring color maps @@ -52,60 +52,60 @@ in this Software without prior written authorization from The Open Group. * Start. Added from *****************************************************************/ -#define XYBitmap 0 /* depth 1, XYFormat */ -#define XYPixmap 1 /* depth == drawable depth */ -#define ZPixmap 2 /* depth == drawable depth */ +#define XYBitmap 0 /* depth 1, XYFormat */ +#define XYPixmap 1 /* depth == drawable depth */ +#define ZPixmap 2 /* depth == drawable depth */ /***************************************************************** * End. Added from *****************************************************************/ -typedef CARD32 xwdval; /* for old broken programs */ +typedef CARD32 xwdval; /* for old broken programs */ /* Values in the file are most significant byte first. */ typedef struct _xwd_file_header { - /* header_size = SIZEOF(XWDheader) + length of null-terminated - * window name. */ - CARD32 header_size; - - CARD32 file_version; /* = XWD_FILE_VERSION above */ - CARD32 pixmap_format; /* ZPixmap or XYPixmap */ - CARD32 pixmap_depth; /* Pixmap depth */ - CARD32 pixmap_width; /* Pixmap width */ - CARD32 pixmap_height; /* Pixmap height */ - CARD32 xoffset; /* Bitmap x offset, normally 0 */ - CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ - - /* bitmap_unit applies to bitmaps (depth 1 format XY) only. - * It is the number of bits that each scanline is padded to. */ - CARD32 bitmap_unit; - - CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ - - /* bitmap_pad applies to pixmaps (non-bitmaps) only. - * It is the number of bits that each scanline is padded to. */ - CARD32 bitmap_pad; - - CARD32 bits_per_pixel; /* Bits per pixel */ - - /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) - * or bitmap_pad (pixmaps). It is the delta (in bytes) to get - * to the same x position on an adjacent row. */ - CARD32 bytes_per_line; - CARD32 visual_class; /* Class of colormap */ - CARD32 red_mask; /* Z red mask */ - CARD32 green_mask; /* Z green mask */ - CARD32 blue_mask; /* Z blue mask */ - CARD32 bits_per_rgb; /* Log2 of distinct color values */ - CARD32 colormap_entries; /* Number of entries in colormap; not used? */ - CARD32 ncolors; /* Number of XWDColor structures */ - CARD32 window_width; /* Window width */ - CARD32 window_height; /* Window height */ - CARD32 window_x; /* Window upper left X coordinate */ - CARD32 window_y; /* Window upper left Y coordinate */ - CARD32 window_bdrwidth; /* Window border width */ + /* header_size = SIZEOF(XWDheader) + length of null-terminated + * window name. */ + CARD32 header_size; + + CARD32 file_version; /* = XWD_FILE_VERSION above */ + CARD32 pixmap_format; /* ZPixmap or XYPixmap */ + CARD32 pixmap_depth; /* Pixmap depth */ + CARD32 pixmap_width; /* Pixmap width */ + CARD32 pixmap_height; /* Pixmap height */ + CARD32 xoffset; /* Bitmap x offset, normally 0 */ + CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ + + /* bitmap_unit applies to bitmaps (depth 1 format XY) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_unit; + + CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ + + /* bitmap_pad applies to pixmaps (non-bitmaps) only. + * It is the number of bits that each scanline is padded to. */ + CARD32 bitmap_pad; + + CARD32 bits_per_pixel; /* Bits per pixel */ + + /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) + * or bitmap_pad (pixmaps). It is the delta (in bytes) to get + * to the same x position on an adjacent row. */ + CARD32 bytes_per_line; + CARD32 visual_class; /* Class of colormap */ + CARD32 red_mask; /* Z red mask */ + CARD32 green_mask; /* Z green mask */ + CARD32 blue_mask; /* Z blue mask */ + CARD32 bits_per_rgb; /* Log2 of distinct color values */ + CARD32 colormap_entries; /* Number of entries in colormap; not used? */ + CARD32 ncolors; /* Number of XWDColor structures */ + CARD32 window_width; /* Window width */ + CARD32 window_height; /* Window height */ + CARD32 window_x; /* Window upper left X coordinate */ + CARD32 window_y; /* Window upper left Y coordinate */ + CARD32 window_bdrwidth; /* Window border width */ } XWDFileHeader; /* Null-terminated window name follows the above structure. */ @@ -116,15 +116,14 @@ typedef struct _xwd_file_header { */ typedef struct { - CARD32 pixel; - CARD16 red; - CARD16 green; - CARD16 blue; - CARD8 flags; - CARD8 pad; + CARD32 pixel; + CARD16 red; + CARD16 green; + CARD16 blue; + CARD8 flags; + CARD8 pad; } XWDColor; /* Last comes the image data in the format described by XWDFileHeader. */ #endif /* XWDFILE_H */ - diff --git a/modules/highgui/src/Xmd.h b/modules/highgui/src/Xmd.h index 68c45dbec0ee..431d36de9618 100644 --- a/modules/highgui/src/Xmd.h +++ b/modules/highgui/src/Xmd.h @@ -59,7 +59,7 @@ SOFTWARE. #if defined(__SIZEOF_LONG__) # if __SIZEOF_LONG__ == 8 -# define LONG64 /* 32/64-bit architecture */ +# define LONG64 /* 32/64-bit architecture */ # endif # elif defined (_LP64) || defined(__LP64__) || \ defined(__alpha) || defined(__alpha__) || \ @@ -68,8 +68,8 @@ SOFTWARE. defined(__s390x__) || \ defined(__amd64__) || defined(amd64) || \ defined(__powerpc64__) -# if !defined(__ILP32__) /* amd64-x32 is 32bit */ -# define LONG64 /* 32/64-bit architecture */ +# if !defined(__ILP32__) /* amd64-x32 is 32bit */ +# define LONG64 /* 32/64-bit architecture */ # endif /* !__ILP32__ */ # endif @@ -105,7 +105,7 @@ typedef long INT32; # endif typedef short INT16; -typedef signed char INT8; +typedef signed char INT8; # ifdef LONG64 typedef unsigned long CARD64; @@ -117,11 +117,11 @@ typedef unsigned long CARD32; typedef unsigned short CARD16; typedef unsigned char CARD8; -typedef CARD32 BITS32; -typedef CARD16 BITS16; +typedef CARD32 BITS32; +typedef CARD16 BITS16; -typedef CARD8 BYTE; -typedef CARD8 BOOL; +typedef CARD8 BYTE; +typedef CARD8 BOOL; /* * was definitions for sign-extending bitfields on architectures without diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index eebe24c34d36..873e4fbbb0c1 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -32,36 +32,36 @@ namespace cv { namespace highgui_backend { static std::string& getFBMode() { - static std::string fbModeOpenCV = + static std::string fbModeOpenCV = cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); static std::string fbModeDef = "FB"; - + if(!fbModeOpenCV.empty()) return fbModeOpenCV; return fbModeDef; } static std::string& getFBFileName() { - static std::string fbFileNameFB = + static std::string fbFileNameFB = cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); - static std::string fbFileNameOpenCV = + static std::string fbFileNameOpenCV = cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); static std::string fbFileNameDef = "/dev/fb0"; - + if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; if(!fbFileNameFB.empty()) return fbFileNameFB; return fbFileNameDef; } - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): backend(_backend), flags(_flags) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); } - + FramebufferWindow::~FramebufferWindow() { CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); @@ -70,13 +70,13 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::imshow(InputArray image) { currentImg = image.getMat().clone(); - + CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " << cv::typeToString(image.type()) << " size " << image.size()); - + if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) - { + { return; } @@ -109,12 +109,12 @@ namespace cv { namespace highgui_backend { break; } cvtColor(img, img, COLOR_RGB2BGRA); - + int newWidth = windowRect.width; int newHeight = windowRect.height; int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - + if(flags & WINDOW_AUTOSIZE) { windowRect.width = imgSize.width; @@ -122,7 +122,7 @@ namespace cv { namespace highgui_backend { newWidth = windowRect.width; newHeight = windowRect.height; } - + if(flags & WINDOW_FREERATIO) { newWidth = windowRect.width; @@ -143,8 +143,8 @@ namespace cv { namespace highgui_backend { if((newWidth != img.cols) && (newHeight != img.rows)) { cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); - } - + } + CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); @@ -158,14 +158,14 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } - + // SHOW IMAGE int xOffset = backend.getFBXOffset(); int yOffset = backend.getFBYOffset(); int fbHeight = backend.getFBHeight(); int fbWidth = backend.getFBWidth(); int lineLength = backend.getFBLineLength(); - + int img_start_x; int img_start_y; int img_end_x; @@ -173,62 +173,62 @@ namespace cv { namespace highgui_backend { int fb_start_x; int fb_start_y; - if(windowRect.y - yOffset < 0) - { + if(windowRect.y - yOffset < 0) + { img_start_y = - (windowRect.y - yOffset); } - else - { + else + { img_start_y = 0; } - if(windowRect.x - xOffset < 0) - { + if(windowRect.x - xOffset < 0) + { img_start_x = - (windowRect.x - xOffset); } - else + else { img_start_x = 0; } - - if(windowRect.y + yOffset + img.rows > fbHeight) + + if(windowRect.y + yOffset + img.rows > fbHeight) { - img_end_y = fbHeight - windowRect.y - yOffset; + img_end_y = fbHeight - windowRect.y - yOffset; } else { img_end_y = img.rows; } - if(windowRect.x + xOffset + img.cols > fbWidth) + if(windowRect.x + xOffset + img.cols > fbWidth) { - img_end_x = fbWidth - windowRect.x - xOffset; + img_end_x = fbWidth - windowRect.x - xOffset; } - else + else { img_end_x = img.cols; } - - if(windowRect.y + yOffset >= 0) + + if(windowRect.y + yOffset >= 0) { - fb_start_y = windowRect.y + yOffset; + fb_start_y = windowRect.y + yOffset; } - else + else { fb_start_y = 0; } - if(windowRect.x + xOffset >= 0) + if(windowRect.x + xOffset >= 0) { - fb_start_x = windowRect.x + xOffset; + fb_start_x = windowRect.x + xOffset; } - else + else { fb_start_x = 0; } - + for (int y = img_start_y; y < img_end_y; y++) { - std::memcpy(backend.getFBPointer() + - (fb_start_y + y - img_start_y) * lineLength + fb_start_x, - img.ptr(y) + img_start_x * cntChannel, + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, (img_end_x - img_start_x) * cntChannel); } } @@ -241,7 +241,7 @@ namespace cv { namespace highgui_backend { return 0.0; } - bool FramebufferWindow::setProperty(int prop, double value) + bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " << prop << ", value " << value << ")"); @@ -252,9 +252,9 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " + CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " << width <<", height " << height << ")"); - + CV_Assert(width > 0); CV_Assert(height > 0); @@ -262,14 +262,15 @@ namespace cv { namespace highgui_backend { { windowRect.width = width; windowRect.height = height; - + if((currentImg.cols > 0) && (currentImg.rows > 0)) - { + { imshow(currentImg); } } } - void FramebufferWindow::move(int x, int y) + + void FramebufferWindow::move(int x, int y) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); @@ -277,18 +278,18 @@ namespace cv { namespace highgui_backend { windowRect.y = y; if((currentImg.cols > 0) && (currentImg.rows > 0)) - { + { imshow(currentImg); } } - Rect FramebufferWindow::getImageRect() const + Rect FramebufferWindow::getImageRect() const { CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); return windowRect; } - void FramebufferWindow::setTitle(const std::string& title) + void FramebufferWindow::setTitle(const std::string& title) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); @@ -317,20 +318,20 @@ namespace cv { namespace highgui_backend { CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); return nullptr; } - - const std::string& FramebufferWindow::getID() const - { + + const std::string& FramebufferWindow::getID() const + { CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); return FB_ID; } - bool FramebufferWindow::isActive() const + bool FramebufferWindow::isActive() const { CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); return true; } - void FramebufferWindow::destroy() + void FramebufferWindow::destroy() { CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } @@ -342,7 +343,7 @@ namespace cv { namespace highgui_backend { std::string fbFileName = getFBFileName(); CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); - + int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { @@ -354,30 +355,30 @@ namespace cv { namespace highgui_backend { if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); - return -1; + return -1; } // Get variable screen information - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); return -1; } - - CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" << " green offset " <xoffset ); return -1; } - - unsigned int r = C32INT(&(xwd_header-> red_mask)); + + unsigned int r = C32INT(&(xwd_header-> red_mask)); unsigned int g = C32INT(&(xwd_header->green_mask)); unsigned int b = C32INT(&(xwd_header-> blue_mask)); @@ -452,15 +453,15 @@ namespace cv { namespace highgui_backend { fbYOffset = 0; fbLineLength = C32INT(&(xwd_header->bytes_per_line)); fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); - - CV_LOG_INFO(NULL, "UI: XVFB info: \n" + + CV_LOG_INFO(NULL, "UI: XVFB info: \n" << " red_mask " << r << "\n" << " green_mask " << g << "\n" << " blue_mask " << b << "\n" << "bits_per_pixel " << fbBitsPerPixel); - - if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32) ) + + if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32)) { CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " << "(use BGRA format with bits_per_pixel = 32)"); @@ -469,14 +470,14 @@ namespace cv { namespace highgui_backend { xvfb_len_header = C32INT(&(xwd_header->header_size)); xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); - xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * C32INT(&(xwd_header->pixmap_height)); munmap(xwd_header, sizeof(XWDFileHeader)); fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; - xwd_header = (XWDFileHeader*) - mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); - fbPointer = (unsigned char*)xwd_header ; + xwd_header = (XWDFileHeader*) + mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header; fbPointer_dist = xvfb_len_header + xvfb_len_colors; return fb_fd; @@ -484,7 +485,7 @@ namespace cv { namespace highgui_backend { fb_var_screeninfo &FramebufferBackend::getVarInfo() { - return varInfo; + return varInfo; } fb_fix_screeninfo &FramebufferBackend::getFixInfo() @@ -545,9 +546,9 @@ namespace cv { namespace highgui_backend { FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - + std::string fbModeStr = getFBMode(); - + if(fbModeStr == "EMU") { mode = FB_MODE_EMU; @@ -573,9 +574,9 @@ namespace cv { namespace highgui_backend { { fbID = XvfbOpenAndGetInfo(); } - + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - + if(fbID == -1){ mode = FB_MODE_EMU; fbWidth = 1024; @@ -584,42 +585,40 @@ namespace cv { namespace highgui_backend { fbYOffset = 0; fbBitsPerPixel = 0; fbLineLength = 0; - + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); return; } - - - CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); - CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " << fbXOffset << " " << fbYOffset << " " << fbLineLength); - backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset, + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset, backgroundBuff.cols * cnt_channel); } } - + FramebufferBackend::~FramebufferBackend() { CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); if(fbID == -1) return; - + // RESTORE BACKGROUNG if (fbPointer != MAP_FAILED) { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.ptr(y - fbYOffset), backgroundBuff.cols * cnt_channel); } @@ -637,12 +636,12 @@ namespace cv { namespace highgui_backend { const std::string& winname, int flags) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" + CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" << winname << ", " << flags << ")"); return std::make_shared(*this, flags); } - void FramebufferBackend::initTermios(int echo, int wait) + void FramebufferBackend::initTermios(int echo, int wait) { tcgetattr(0, &old); current = old; @@ -660,12 +659,12 @@ namespace cv { namespace highgui_backend { tcsetattr(0, TCSANOW, ¤t); } - void FramebufferBackend::resetTermios(void) + void FramebufferBackend::resetTermios(void) { tcsetattr(0, TCSANOW, &old); } - int FramebufferBackend::getch_(int echo, int wait) + int FramebufferBackend::getch_(int echo, int wait) { int ch; initTermios(echo, wait); @@ -674,7 +673,7 @@ namespace cv { namespace highgui_backend { resetTermios(); return ch; } - + bool FramebufferBackend::kbhit() { int byteswaiting=0; @@ -684,11 +683,11 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); } resetTermios(); - + return byteswaiting > 0; } - int FramebufferBackend::waitKeyEx(int delay) + int FramebufferBackend::waitKeyEx(int delay) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); @@ -699,22 +698,22 @@ namespace cv { namespace highgui_backend { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - + while((ch = getch_(0, 0))>=0) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); code = ch; } - } - else + } + else { bool f_kbhit = false; while(!(f_kbhit = kbhit()) && (delay > 0)) { delay -= 1; usleep(1000); - } + } if(f_kbhit) { CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); @@ -722,20 +721,20 @@ namespace cv { namespace highgui_backend { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - + while((ch = getch_(0, 0))>=0) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); code = ch; } } } - + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); - return code; + return code; } - + int FramebufferBackend::pollKey() { CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); @@ -750,15 +749,15 @@ namespace cv { namespace highgui_backend { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - + while((ch = getch_(0, 0))>=0) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); code = ch; } } - + return code; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index acdbb6db8f87..3307ccb5eb87 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -23,7 +23,7 @@ class CV_EXPORTS FramebufferWindow : public UIWindow FramebufferBackend &backend; std::string FB_ID; Rect windowRect; - + int flags; Mat currentImg; @@ -31,35 +31,35 @@ class CV_EXPORTS FramebufferWindow : public UIWindow FramebufferWindow(FramebufferBackend &backend, int flags); virtual ~FramebufferWindow(); - virtual void imshow(InputArray image)override; + virtual void imshow(InputArray image) override; virtual double getProperty(int prop) const override; - virtual bool setProperty(int prop, double value)override; + virtual bool setProperty(int prop, double value) override; - virtual void resize(int width, int height)override; - virtual void move(int x, int y)override; + virtual void resize(int width, int height) override; + virtual void move(int x, int y) override; virtual Rect getImageRect() const override; - virtual void setTitle(const std::string& title)override; + virtual void setTitle(const std::string& title) override; - virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override ; + virtual void setMouseCallback(MouseCallback onMouse, void* userdata /*= 0*/) override; virtual std::shared_ptr createTrackbar( const std::string& name, int count, TrackbarCallback onChange /*= 0*/, void* userdata /*= 0*/ - )override; + ) override; + + virtual std::shared_ptr findTrackbar(const std::string& name) override; - virtual std::shared_ptr findTrackbar(const std::string& name)override; - virtual const std::string& getID() const override; virtual bool isActive() const override; virtual void destroy() override; -}; // FramebufferWindow +}; // FramebufferWindow class CV_EXPORTS FramebufferBackend: public UIBackend { @@ -71,7 +71,6 @@ class CV_EXPORTS FramebufferBackend: public UIBackend void resetTermios(void); int getch_(int echo, int wait); bool kbhit(); - fb_var_screeninfo varInfo; fb_fix_screeninfo fixInfo; @@ -86,7 +85,6 @@ class CV_EXPORTS FramebufferBackend: public UIBackend unsigned int fbPointer_dist; Mat backgroundBuff; - int fbOpenAndGetInfo(); int fbID; @@ -94,7 +92,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend unsigned int xvfb_len_colors; unsigned int xvfb_len_pixmap; int XvfbOpenAndGetInfo(); - + public: fb_var_screeninfo &getVarInfo(); From 48f5ec79adb48c97efd89e68721f51db8a01f220 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 17:26:48 +0300 Subject: [PATCH 61/81] fix trailing whitespace. --- modules/highgui/src/XWDFile.h | 3 ++- modules/highgui/src/window_framebuffer.cpp | 6 +++--- modules/highgui/src/window_framebuffer.hpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h index 0d5f38a09aef..20ebf568e8e3 100644 --- a/modules/highgui/src/XWDFile.h +++ b/modules/highgui/src/XWDFile.h @@ -46,7 +46,8 @@ in this Software without prior written authorization from The Open Group. #define sz_XWDColor 12 // Added macro to convert big-endian numbers to local representation -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | \ + (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) /***************************************************************** * Start. Added from diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 873e4fbbb0c1..0236fd5ac5fd 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -257,7 +257,7 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - + if(!(flags & WINDOW_AUTOSIZE)) { windowRect.width = width; @@ -648,10 +648,10 @@ namespace cv { namespace highgui_backend { current.c_lflag &= ~ICANON; current.c_lflag &= ~ISIG; current.c_cc[VMIN]=wait; - if (echo) + if (echo) { current.c_lflag |= ECHO; - } + } else { current.c_lflag &= ~ECHO; diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 3307ccb5eb87..6156c552995c 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -121,7 +121,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend )override; virtual int waitKeyEx(int delay /*= 0*/)override; - virtual int pollKey() override; + virtual int pollKey() override; }; } From dc98bd1da51b1ac43910cf86a722f770aefac211 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 28 May 2024 17:52:51 +0300 Subject: [PATCH 62/81] fix trailing whitespace. --- modules/highgui/src/window_framebuffer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 0236fd5ac5fd..fe149ee8f072 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -99,7 +99,7 @@ namespace cv { namespace highgui_backend { img.convertTo(img, CV_8U, 255., 0.); break; } - cvtColor(img, img, cv::COLOR_GRAY2RGB); + cvtColor(img, img, cv::COLOR_GRAY2RGB); break; case 3: convertToShow(img, img); @@ -175,7 +175,7 @@ namespace cv { namespace highgui_backend { if(windowRect.y - yOffset < 0) { - img_start_y = - (windowRect.y - yOffset); + img_start_y = - (windowRect.y - yOffset); } else { @@ -183,7 +183,7 @@ namespace cv { namespace highgui_backend { } if(windowRect.x - xOffset < 0) { - img_start_x = - (windowRect.x - xOffset); + img_start_x = - (windowRect.x - xOffset); } else { @@ -194,7 +194,7 @@ namespace cv { namespace highgui_backend { { img_end_y = fbHeight - windowRect.y - yOffset; } - else + else { img_end_y = img.rows; } @@ -243,7 +243,7 @@ namespace cv { namespace highgui_backend { bool FramebufferWindow::setProperty(int prop, double value) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " + CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " << prop << ", value " << value << ")"); CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); @@ -352,7 +352,7 @@ namespace cv { namespace highgui_backend { } // Get fixed screen information - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; @@ -430,7 +430,7 @@ namespace cv { namespace highgui_backend { CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); return -1; } - + if( C32INT(&(xwd_header->pixmap_format)) != ZPixmap ) { CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); @@ -652,7 +652,7 @@ namespace cv { namespace highgui_backend { { current.c_lflag |= ECHO; } - else + else { current.c_lflag &= ~ECHO; } From 92b3a8491ca0ee038ce4e9494f2c2761d20e2ee6 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 4 Jun 2024 14:51:35 +0300 Subject: [PATCH 63/81] added getName method for FB --- CMakeLists.txt | 2 +- modules/highgui/src/window_framebuffer.cpp | 4 ++++ modules/highgui/src/window_framebuffer.hpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index baaed10369ea..f6497c1c4d5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,7 +304,7 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_GTK AND NOT HAVE_GTK3) -OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF +OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" ON VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_FRAMEBUFFER) OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index fe149ee8f072..c92f060ccc07 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -761,5 +761,9 @@ namespace cv { namespace highgui_backend { return code; } + const std::string FramebufferBackend::getName() const + { + return "FB"; + } } } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 6156c552995c..5a90928366ef 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -122,6 +122,8 @@ class CV_EXPORTS FramebufferBackend: public UIBackend virtual int waitKeyEx(int delay /*= 0*/)override; virtual int pollKey() override; + + virtual const std::string getName() const override; }; } From ff8b9d9576b706590c37bee3c80d98dc361674a0 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 4 Jun 2024 15:37:11 +0300 Subject: [PATCH 64/81] fix code style --- modules/highgui/CMakeLists.txt | 5 - modules/highgui/src/window_framebuffer.cpp | 103 +++++++++++---------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 23486149aa1e..8c3f538a8ba9 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -39,7 +39,6 @@ if(HAVE_WEBP) add_definitions(-DHAVE_WEBP) endif() - if(WITH_FRAMEBUFFER) add_definitions(-DHAVE_FRAMEBUFFER) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) @@ -48,7 +47,6 @@ if(WITH_FRAMEBUFFER) list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/Xmd.h) endif() - file(GLOB highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp" "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp" @@ -190,9 +188,6 @@ elseif(HAVE_COCOA) list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa") endif() - - - if(TARGET ocv.3rdparty.win32ui) if("win32ui" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all") ocv_create_builtin_highgui_plugin(opencv_highgui_win32 ocv.3rdparty.win32ui "window_w32.cpp") diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 9aaae56aeb5e..d125d296ec14 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -33,7 +33,7 @@ namespace cv { namespace highgui_backend { static std::string& getFBMode() { static std::string fbModeOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); static std::string fbModeDef = "FB"; if(!fbModeOpenCV.empty()) return fbModeOpenCV; @@ -43,9 +43,9 @@ namespace cv { namespace highgui_backend { static std::string& getFBFileName() { static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); static std::string fbFileNameOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); static std::string fbFileNameDef = "/dev/fb0"; if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; @@ -73,7 +73,7 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " - << cv::typeToString(image.type()) << " size " << image.size()); + << cv::typeToString(image.type()) << " size " << image.size()); if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) { @@ -107,6 +107,10 @@ namespace cv { namespace highgui_backend { case 4: convertToShow(img, img, true); break; + default: + CV_LOG_ERROR(NULL, "UI: imshow can't convert image to show"); + CV_Assert(img.channels() < 1); + CV_Assert(img.channels() > 4); } cvtColor(img, img, COLOR_RGB2BGRA); @@ -117,7 +121,7 @@ namespace cv { namespace highgui_backend { if(flags & WINDOW_AUTOSIZE) { - windowRect.width = imgSize.width; + windowRect.width = imgSize.width; windowRect.height = imgSize.height; newWidth = windowRect.width; newHeight = windowRect.height; @@ -146,7 +150,7 @@ namespace cv { namespace highgui_backend { } CV_LOG_INFO(NULL, "UI: Formated image: " - << cv::typeToString(img.type()) << " size " << img.size()); + << cv::typeToString(img.type()) << " size " << img.size()); if(backend.getMode() == FB_MODE_EMU) { @@ -227,9 +231,9 @@ namespace cv { namespace highgui_backend { for (int y = img_start_y; y < img_end_y; y++) { std::memcpy(backend.getFBPointer() + - (fb_start_y + y - img_start_y) * lineLength + fb_start_x, - img.ptr(y) + img_start_x * cntChannel, - (img_end_x - img_start_x) * cntChannel); + (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + img.ptr(y) + img_start_x * cntChannel, + (img_end_x - img_start_x) * cntChannel); } } @@ -244,7 +248,7 @@ namespace cv { namespace highgui_backend { bool FramebufferWindow::setProperty(int prop, double value) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " - << prop << ", value " << value << ")"); + << prop << ", value " << value << ")"); CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); return false; @@ -253,7 +257,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height) { CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " - << width <<", height " << height << ")"); + << width <<", height " << height << ")"); CV_Assert(width > 0); CV_Assert(height > 0); @@ -342,7 +346,7 @@ namespace cv { namespace highgui_backend { { std::string fbFileName = getFBFileName(); CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" - << fbFileName); + << fbFileName); int fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) @@ -366,11 +370,11 @@ namespace cv { namespace highgui_backend { } CV_LOG_INFO(NULL, "UI: framebuffer info: \n" - << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" - << " green offset " <green_mask)); unsigned int b = C32INT(&(xwd_header-> blue_mask)); - fbWidth = C32INT(&(xwd_header->pixmap_width)); - fbHeight = C32INT(&(xwd_header->pixmap_height)); - fbXOffset = 0; - fbYOffset = 0; - fbLineLength = C32INT(&(xwd_header->bytes_per_line)); + fbWidth = C32INT(&(xwd_header->pixmap_width)); + fbHeight = C32INT(&(xwd_header->pixmap_height)); + fbXOffset = 0; + fbYOffset = 0; + fbLineLength = C32INT(&(xwd_header->bytes_per_line)); fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); CV_LOG_INFO(NULL, "UI: XVFB info: \n" - << " red_mask " << r << "\n" - << " green_mask " << g << "\n" - << " blue_mask " << b << "\n" - << "bits_per_pixel " << fbBitsPerPixel); + << " red_mask " << r << "\n" + << " green_mask " << g << "\n" + << " blue_mask " << b << "\n" + << "bits_per_pixel " << fbBitsPerPixel); if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && (fbBitsPerPixel != 32)) { CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " - << "(use BGRA format with bits_per_pixel = 32)"); + << "(use BGRA format with bits_per_pixel = 32)"); return -1; } xvfb_len_header = C32INT(&(xwd_header->header_size)); xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * - C32INT(&(xwd_header->pixmap_height)); + C32INT(&(xwd_header->pixmap_height)); + munmap(xwd_header, sizeof(XWDFileHeader)); fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; xwd_header = (XWDFileHeader*) - mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + fbPointer = (unsigned char*)xwd_header; fbPointer_dist = xvfb_len_header + xvfb_len_colors; @@ -591,18 +596,18 @@ namespace cv { namespace highgui_backend { } CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " - << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); + << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " - << fbXOffset << " " << fbYOffset << " " << fbLineLength); + << fbXOffset << " " << fbYOffset << " " << fbLineLength); backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.cols * cnt_channel); + getFBPointer() + y * fbLineLength + fbXOffset, + backgroundBuff.cols * cnt_channel); } } @@ -618,8 +623,8 @@ namespace cv { namespace highgui_backend { for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, - backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cnt_channel); + backgroundBuff.ptr(y - fbYOffset), + backgroundBuff.cols * cnt_channel); } munmap(fbPointer, fbScreenSize); @@ -633,11 +638,11 @@ namespace cv { namespace highgui_backend { // namedWindow std::shared_ptr FramebufferBackend::createWindow( - const std::string& winname, - int flags) + const std::string& winname, + int flags) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" - << winname << ", " << flags << ")"); + << winname << ", " << flags << ")"); return std::make_shared(*this, flags); } @@ -702,7 +707,7 @@ namespace cv { namespace highgui_backend { while((ch = getch_(0, 0))>=0) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); + << (int)ch << " (additional code on )"); code = ch; } } @@ -725,7 +730,7 @@ namespace cv { namespace highgui_backend { while((ch = getch_(0, 0))>=0) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); + << (int)ch << " (additional code on )"); code = ch; } } @@ -753,7 +758,7 @@ namespace cv { namespace highgui_backend { while((ch = getch_(0, 0))>=0) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); + << (int)ch << " (additional code on )"); code = ch; } } From afdb44884e3d127c88ea3958f90730718d6d5e92 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 4 Jun 2024 15:58:37 +0300 Subject: [PATCH 65/81] fix status of OPENCV_HIGHGUI_BUILTIN_BACKEND --- modules/highgui/CMakeLists.txt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 8c3f538a8ba9..d81a8beb9ece 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -39,14 +39,6 @@ if(HAVE_WEBP) add_definitions(-DHAVE_WEBP) endif() -if(WITH_FRAMEBUFFER) - add_definitions(-DHAVE_FRAMEBUFFER) - list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/XWDFile.h) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/Xmd.h) -endif() - file(GLOB highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp" "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp" @@ -57,6 +49,15 @@ list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${n set(OPENCV_HIGHGUI_BUILTIN_BACKEND "") +if(WITH_FRAMEBUFFER) + set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") + add_definitions(-DHAVE_FRAMEBUFFER) + list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/XWDFile.h) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/Xmd.h) +endif() + if(WITH_WAYLAND AND HAVE_WAYLAND) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "Wayland") add_definitions(-DHAVE_WAYLAND) From 08ba3f2bfbd523bdd4c7032a8ba246672dd27a83 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 5 Jun 2024 17:59:47 +0300 Subject: [PATCH 66/81] offset bug fixed --- modules/highgui/src/window_framebuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index d125d296ec14..51f30d99c9cd 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -231,7 +231,7 @@ namespace cv { namespace highgui_backend { for (int y = img_start_y; y < img_end_y; y++) { std::memcpy(backend.getFBPointer() + - (fb_start_y + y - img_start_y) * lineLength + fb_start_x, + (fb_start_y + y - img_start_y) * lineLength + fb_start_x * cntChannel, img.ptr(y) + img_start_x * cntChannel, (img_end_x - img_start_x) * cntChannel); } @@ -606,7 +606,7 @@ namespace cv { namespace highgui_backend { for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset, + getFBPointer() + y * fbLineLength + fbXOffset * 4, backgroundBuff.cols * cnt_channel); } } @@ -622,7 +622,7 @@ namespace cv { namespace highgui_backend { int cnt_channel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset, + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset * 4, backgroundBuff.ptr(y - fbYOffset), backgroundBuff.cols * cnt_channel); } From 2e9cbf6886b5fe68c5ca0cb2068c9dd7e7a25926 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 5 Jun 2024 18:14:19 +0300 Subject: [PATCH 67/81] fix style --- modules/highgui/src/window_framebuffer.cpp | 56 +++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 51f30d99c9cd..a37101e23ea7 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -135,11 +135,11 @@ namespace cv { namespace highgui_backend { else //WINDOW_KEEPRATIO { double aspect_ratio = ((double)img.cols) / img.rows; - newWidth = windowRect.width; + newWidth = windowRect.width; newHeight = (int)(windowRect.width / aspect_ratio); if (newHeight > windowRect.height) { - newWidth = (int)(windowRect.height * aspect_ratio); + newWidth = (int)(windowRect.height * aspect_ratio); newHeight = windowRect.height; } } @@ -167,7 +167,7 @@ namespace cv { namespace highgui_backend { int xOffset = backend.getFBXOffset(); int yOffset = backend.getFBYOffset(); int fbHeight = backend.getFBHeight(); - int fbWidth = backend.getFBWidth(); + int fbWidth = backend.getFBWidth(); int lineLength = backend.getFBLineLength(); int img_start_x; @@ -204,7 +204,7 @@ namespace cv { namespace highgui_backend { } if(windowRect.x + xOffset + img.cols > fbWidth) { - img_end_x = fbWidth - windowRect.x - xOffset; + img_end_x = fbWidth - windowRect.x - xOffset; } else { @@ -370,15 +370,15 @@ namespace cv { namespace highgui_backend { } CV_LOG_INFO(NULL, "UI: framebuffer info: \n" - << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" - << " green offset " < red_mask)); + unsigned int r = C32INT(&(xwd_header->red_mask)); unsigned int g = C32INT(&(xwd_header->green_mask)); - unsigned int b = C32INT(&(xwd_header-> blue_mask)); + unsigned int b = C32INT(&(xwd_header->blue_mask)); fbWidth = C32INT(&(xwd_header->pixmap_width)); fbHeight = C32INT(&(xwd_header->pixmap_height)); @@ -602,12 +602,12 @@ namespace cv { namespace highgui_backend { << fbXOffset << " " << fbYOffset << " " << fbLineLength); backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); - int cnt_channel = 4; + int cntChannel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset * 4, - backgroundBuff.cols * cnt_channel); + getFBPointer() + y * fbLineLength + fbXOffset * cntChannel, + backgroundBuff.cols * cntChannel); } } @@ -619,12 +619,12 @@ namespace cv { namespace highgui_backend { // RESTORE BACKGROUNG if (fbPointer != MAP_FAILED) { - int cnt_channel = 4; + int cntChannel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset * 4, + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset * cntChannel, backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cnt_channel); + backgroundBuff.cols * cntChannel); } munmap(fbPointer, fbScreenSize); @@ -652,7 +652,7 @@ namespace cv { namespace highgui_backend { current = old; current.c_lflag &= ~ICANON; current.c_lflag &= ~ISIG; - current.c_cc[VMIN]=wait; + current.c_cc[VMIN] = wait; if (echo) { current.c_lflag |= ECHO; @@ -681,7 +681,7 @@ namespace cv { namespace highgui_backend { bool FramebufferBackend::kbhit() { - int byteswaiting=0; + int byteswaiting = 0; initTermios(0, 1); if ( ioctl(0, FIONREAD, &byteswaiting) < 0) { From fb01d3b5cdc27570c40050a829bb338844c8b952 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 10 Jun 2024 20:47:08 +0300 Subject: [PATCH 68/81] fix coding style --- modules/highgui/src/backend.hpp | 1 - modules/highgui/src/registry.impl.hpp | 1 - modules/highgui/src/window_framebuffer.cpp | 126 +++++++++++---------- 3 files changed, 67 insertions(+), 61 deletions(-) diff --git a/modules/highgui/src/backend.hpp b/modules/highgui/src/backend.hpp index 6174a2c3611d..49878baefc2d 100644 --- a/modules/highgui/src/backend.hpp +++ b/modules/highgui/src/backend.hpp @@ -131,7 +131,6 @@ std::shared_ptr createUIBackendQT(); std::shared_ptr createUIBackendFramebuffer(); #endif - #endif // BUILD_PLUGIN } // namespace highgui_backend diff --git a/modules/highgui/src/registry.impl.hpp b/modules/highgui/src/registry.impl.hpp index 94ee9e9cde4b..782738a82063 100644 --- a/modules/highgui/src/registry.impl.hpp +++ b/modules/highgui/src/registry.impl.hpp @@ -48,7 +48,6 @@ std::vector& getBuiltinBackendsInfo() DECLARE_STATIC_BACKEND("FB", createUIBackendFramebuffer) #endif - #if 0 // TODO #ifdef HAVE_QT DECLARE_STATIC_BACKEND("QT", createUIBackendQT) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index a37101e23ea7..695fa9b7374c 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -36,7 +36,7 @@ namespace cv { namespace highgui_backend { cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); static std::string fbModeDef = "FB"; - if(!fbModeOpenCV.empty()) return fbModeOpenCV; + if (!fbModeOpenCV.empty()) return fbModeOpenCV; return fbModeDef; } @@ -48,8 +48,8 @@ namespace cv { namespace highgui_backend { cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); static std::string fbFileNameDef = "/dev/fb0"; - if(!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - if(!fbFileNameFB.empty()) return fbFileNameFB; + if (!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + if (!fbFileNameFB.empty()) return fbFileNameFB; return fbFileNameDef; } @@ -75,29 +75,30 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: InputArray image: " << cv::typeToString(image.type()) << " size " << image.size()); - if((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) + if ((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) { return; } Mat img(image.getMat().clone()); - switch(img.channels()){ + switch (img.channels()) + { case 1: switch(img.type()) { - case CV_8S: - cv::convertScaleAbs(img, img, 1, 127); - break; - case CV_16S: - cv::convertScaleAbs(img, img, 1/255., 127); - break; - case CV_16U: - cv::convertScaleAbs(img, img, 1/255.); - break; - case CV_32F: - case CV_64F: // assuming image has values in range [0, 1) - img.convertTo(img, CV_8U, 255., 0.); - break; + case CV_8S: + cv::convertScaleAbs(img, img, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, img, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, img, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(img, CV_8U, 255., 0.); + break; } cvtColor(img, img, cv::COLOR_GRAY2RGB); break; @@ -119,7 +120,7 @@ namespace cv { namespace highgui_backend { int cntChannel = img.channels(); cv::Size imgSize = currentImg.size(); - if(flags & WINDOW_AUTOSIZE) + if (flags & WINDOW_AUTOSIZE) { windowRect.width = imgSize.width; windowRect.height = imgSize.height; @@ -127,7 +128,7 @@ namespace cv { namespace highgui_backend { newHeight = windowRect.height; } - if(flags & WINDOW_FREERATIO) + if (flags & WINDOW_FREERATIO) { newWidth = windowRect.width; newHeight = windowRect.height; @@ -138,13 +139,14 @@ namespace cv { namespace highgui_backend { newWidth = windowRect.width; newHeight = (int)(windowRect.width / aspect_ratio); - if (newHeight > windowRect.height) { + if (newHeight > windowRect.height) + { newWidth = (int)(windowRect.height * aspect_ratio); newHeight = windowRect.height; } } - if((newWidth != img.cols) && (newHeight != img.rows)) + if ((newWidth != img.cols) && (newHeight != img.rows)) { cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); } @@ -152,13 +154,14 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: Formated image: " << cv::typeToString(img.type()) << " size " << img.size()); - if(backend.getMode() == FB_MODE_EMU) + if (backend.getMode() == FB_MODE_EMU) { CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); return; } - if (backend.getFBPointer() == MAP_FAILED) { + if (backend.getFBPointer() == MAP_FAILED) + { CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); return; } @@ -177,7 +180,7 @@ namespace cv { namespace highgui_backend { int fb_start_x; int fb_start_y; - if(windowRect.y - yOffset < 0) + if (windowRect.y - yOffset < 0) { img_start_y = - (windowRect.y - yOffset); } @@ -185,7 +188,7 @@ namespace cv { namespace highgui_backend { { img_start_y = 0; } - if(windowRect.x - xOffset < 0) + if (windowRect.x - xOffset < 0) { img_start_x = - (windowRect.x - xOffset); } @@ -194,7 +197,7 @@ namespace cv { namespace highgui_backend { img_start_x = 0; } - if(windowRect.y + yOffset + img.rows > fbHeight) + if (windowRect.y + yOffset + img.rows > fbHeight) { img_end_y = fbHeight - windowRect.y - yOffset; } @@ -202,7 +205,7 @@ namespace cv { namespace highgui_backend { { img_end_y = img.rows; } - if(windowRect.x + xOffset + img.cols > fbWidth) + if (windowRect.x + xOffset + img.cols > fbWidth) { img_end_x = fbWidth - windowRect.x - xOffset; } @@ -211,7 +214,7 @@ namespace cv { namespace highgui_backend { img_end_x = img.cols; } - if(windowRect.y + yOffset >= 0) + if (windowRect.y + yOffset >= 0) { fb_start_y = windowRect.y + yOffset; } @@ -219,7 +222,7 @@ namespace cv { namespace highgui_backend { { fb_start_y = 0; } - if(windowRect.x + xOffset >= 0) + if (windowRect.x + xOffset >= 0) { fb_start_x = windowRect.x + xOffset; } @@ -262,12 +265,12 @@ namespace cv { namespace highgui_backend { CV_Assert(width > 0); CV_Assert(height > 0); - if(!(flags & WINDOW_AUTOSIZE)) + if (!(flags & WINDOW_AUTOSIZE)) { windowRect.width = width; windowRect.height = height; - if((currentImg.cols > 0) && (currentImg.rows > 0)) + if ((currentImg.cols > 0) && (currentImg.rows > 0)) { imshow(currentImg); } @@ -281,7 +284,7 @@ namespace cv { namespace highgui_backend { windowRect.x = x; windowRect.y = y; - if((currentImg.cols > 0) && (currentImg.rows > 0)) + if ((currentImg.cols > 0) && (currentImg.rows > 0)) { imshow(currentImg); } @@ -376,10 +379,10 @@ namespace cv { namespace highgui_backend { << "transp offset " << varInfo.transp.offset << " length " <pixmap_format)) != ZPixmap ) + if (C32INT(&(xwd_header->pixmap_format)) != ZPixmap) { CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); return -1; } - if( xwd_header->xoffset != 0 ) + if (xwd_header->xoffset != 0) { CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); return -1; @@ -463,8 +467,8 @@ namespace cv { namespace highgui_backend { << " blue_mask " << b << "\n" << "bits_per_pixel " << fbBitsPerPixel); - if((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32)) + if ((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && + (fbBitsPerPixel != 32)) { CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " << "(use BGRA format with bits_per_pixel = 32)"); @@ -554,35 +558,36 @@ namespace cv { namespace highgui_backend { std::string fbModeStr = getFBMode(); - if(fbModeStr == "EMU") + if (fbModeStr == "EMU") { mode = FB_MODE_EMU; CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); } - if(fbModeStr == "FB") + if (fbModeStr == "FB") { mode = FB_MODE_FB; CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); } - if(fbModeStr == "XVFB") + if (fbModeStr == "XVFB") { mode = FB_MODE_XVFB; CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); } fbID = -1; - if(mode == FB_MODE_FB) + if (mode == FB_MODE_FB) { fbID = fbOpenAndGetInfo(); } - if(mode == FB_MODE_XVFB) + if (mode == FB_MODE_XVFB) { fbID = XvfbOpenAndGetInfo(); } CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - if(fbID == -1){ + if (fbID == -1) + { mode = FB_MODE_EMU; fbWidth = 1024; fbHeight = 768; @@ -617,8 +622,8 @@ namespace cv { namespace highgui_backend { if(fbID == -1) return; // RESTORE BACKGROUNG - if (fbPointer != MAP_FAILED) { - + if (fbPointer != MAP_FAILED) + { int cntChannel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { @@ -674,7 +679,10 @@ namespace cv { namespace highgui_backend { int ch; initTermios(echo, wait); ch = getchar(); - if(ch < 0) rewind(stdin); + if (ch < 0) + { + rewind(stdin); + } resetTermios(); return ch; } @@ -683,7 +691,7 @@ namespace cv { namespace highgui_backend { { int byteswaiting = 0; initTermios(0, 1); - if ( ioctl(0, FIONREAD, &byteswaiting) < 0) + if (ioctl(0, FIONREAD, &byteswaiting) < 0) { CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); } @@ -698,13 +706,13 @@ namespace cv { namespace highgui_backend { int code = -1; - if(delay <= 0) + if (delay <= 0) { int ch = getch_(0, 1); CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - while((ch = getch_(0, 0))>=0) + while ((ch = getch_(0, 0)) >= 0) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); @@ -714,12 +722,12 @@ namespace cv { namespace highgui_backend { else { bool f_kbhit = false; - while(!(f_kbhit = kbhit()) && (delay > 0)) + while (!(f_kbhit = kbhit()) && (delay > 0)) { delay -= 1; usleep(1000); } - if(f_kbhit) + if (f_kbhit) { CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); @@ -727,7 +735,7 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - while((ch = getch_(0, 0))>=0) + while ((ch = getch_(0, 0)) >= 0) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); @@ -747,7 +755,7 @@ namespace cv { namespace highgui_backend { bool f_kbhit = false; f_kbhit = kbhit(); - if(f_kbhit) + if (f_kbhit) { CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); @@ -755,7 +763,7 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); code = ch; - while((ch = getch_(0, 0))>=0) + while ((ch = getch_(0, 0)) >= 0) { CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch << " (additional code on )"); From 875f4397ec648845ffa9355564e34c561f9e335b Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 11 Jun 2024 16:56:23 +0300 Subject: [PATCH 69/81] redundant code removed --- modules/highgui/src/window_framebuffer.cpp | 26 +++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 695fa9b7374c..4eb239cbb089 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -166,7 +166,6 @@ namespace cv { namespace highgui_backend { return; } - // SHOW IMAGE int xOffset = backend.getFBXOffset(); int yOffset = backend.getFBYOffset(); int fbHeight = backend.getFBHeight(); @@ -240,20 +239,15 @@ namespace cv { namespace highgui_backend { } } - double FramebufferWindow::getProperty(int prop) const + double FramebufferWindow::getProperty(int /*prop*/) const { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getProperty(int prop: " << prop << ")"); CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); - return 0.0; } - bool FramebufferWindow::setProperty(int prop, double value) + bool FramebufferWindow::setProperty(int /*prop*/, double /*value*/) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setProperty(int prop " - << prop << ", value " << value << ")"); CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); - return false; } @@ -296,15 +290,13 @@ namespace cv { namespace highgui_backend { return windowRect; } - void FramebufferWindow::setTitle(const std::string& title) + void FramebufferWindow::setTitle(const std::string& /*title*/) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setTitle(" << title << ")"); CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); } void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::setMouseCallback(...)"); CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); } @@ -314,14 +306,12 @@ namespace cv { namespace highgui_backend { TrackbarCallback /*onChange*/, void* /*userdata*/) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::createTrackbar(...)"); CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); return nullptr; } std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::findTrackbar(...)"); CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); return nullptr; } @@ -343,8 +333,6 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); } -//FramebufferBackend - int FramebufferBackend::fbOpenAndGetInfo() { std::string fbFileName = getFBFileName(); @@ -358,14 +346,12 @@ namespace cv { namespace highgui_backend { return -1; } - // Get fixed screen information if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); return -1; } - // Get variable screen information if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); @@ -397,7 +383,6 @@ namespace cv { namespace highgui_backend { fbBitsPerPixel = varInfo.bits_per_pixel; fbLineLength = fixInfo.line_length; - // MAP FB TO MEMORY fbScreenSize = max(varInfo.xres, varInfo.xres_virtual) * max(varInfo.yres, varInfo.yres_virtual) * fbBitsPerPixel / 8; @@ -589,8 +574,8 @@ namespace cv { namespace highgui_backend { if (fbID == -1) { mode = FB_MODE_EMU; - fbWidth = 1024; - fbHeight = 768; + fbWidth = 640; + fbHeight = 480; fbXOffset = 0; fbYOffset = 0; fbBitsPerPixel = 0; @@ -621,7 +606,6 @@ namespace cv { namespace highgui_backend { CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); if(fbID == -1) return; - // RESTORE BACKGROUNG if (fbPointer != MAP_FAILED) { int cntChannel = 4; From 9b4f16d8c65500b6ec925618f97ef2a6583d0ba6 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Tue, 11 Jun 2024 18:49:40 +0300 Subject: [PATCH 70/81] fixes in cmake option --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6497c1c4d5a..41a68bbf6742 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,9 +304,8 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_GTK AND NOT HAVE_GTK3) -OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" ON - VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID - VERIFY HAVE_FRAMEBUFFER) +OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID) OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_WAYLAND) From 3a61f3319503c8c88a40b6c87db81fd4d0750a85 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 12 Jun 2024 09:15:40 +0300 Subject: [PATCH 71/81] some comments corrected --- modules/highgui/src/window_framebuffer.cpp | 120 ++++++++++++--------- modules/highgui/src/window_framebuffer.hpp | 13 +-- 2 files changed, 76 insertions(+), 57 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 4eb239cbb089..deaab91e7049 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -1,3 +1,8 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#include "precomp.hpp" + #include "window_framebuffer.hpp" #include @@ -23,7 +28,8 @@ #include "XWDFile.h" -namespace cv { namespace highgui_backend { +namespace cv { +namespace highgui_backend { std::shared_ptr createUIBackendFramebuffer() { @@ -33,87 +39,98 @@ namespace cv { namespace highgui_backend { static std::string& getFBMode() { static std::string fbModeOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", ""); - static std::string fbModeDef = "FB"; - - if (!fbModeOpenCV.empty()) return fbModeOpenCV; - return fbModeDef; + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", "FB"); + return fbModeOpenCV; } static std::string& getFBFileName() { static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", ""); + cv::utils::getConfigurationParameterString("FRAMEBUFFER", "/dev/fb0"); static std::string fbFileNameOpenCV = cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); - static std::string fbFileNameDef = "/dev/fb0"; if (!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - if (!fbFileNameFB.empty()) return fbFileNameFB; - return fbFileNameDef; + return fbFileNameFB; } FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): backend(_backend), flags(_flags) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferWindow()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::FramebufferWindow()"); FB_ID = "FramebufferWindow"; windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); } FramebufferWindow::~FramebufferWindow() { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); } void FramebufferWindow::imshow(InputArray image) { + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); currentImg = image.getMat().clone(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); CV_LOG_INFO(NULL, "UI: InputArray image: " << cv::typeToString(image.type()) << " size " << image.size()); - if ((currentImg.size().width <= 0) && (currentImg.size().height <= 0)) + if (currentImg.empty()) { + CV_LOG_WARNING(NULL, "UI: image is empty"); return; } + CV_CheckEQ(currentImg.dims, 2, "UI: dims != 2"); - Mat img(image.getMat().clone()); + Mat img = image.getMat(); switch (img.channels()) { case 1: - switch(img.type()) { - case CV_8S: - cv::convertScaleAbs(img, img, 1, 127); - break; - case CV_16S: - cv::convertScaleAbs(img, img, 1/255., 127); - break; - case CV_16U: - cv::convertScaleAbs(img, img, 1/255.); - break; - case CV_32F: - case CV_64F: // assuming image has values in range [0, 1) - img.convertTo(img, CV_8U, 255., 0.); - break; + Mat tmp; + switch(img.type()) + { + case CV_8U: + tmp = img; + break; + case CV_8S: + cv::convertScaleAbs(img, tmp, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, tmp, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, tmp, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(tmp, CV_8U, 255., 0.); + break; + } + Mat rgb(img.rows, img.cols, CV_8UC3); + cvtColor(tmp, rgb, COLOR_GRAY2RGB); + img = rgb; } - cvtColor(img, img, cv::COLOR_GRAY2RGB); - break; + break; case 3: - convertToShow(img, img); - break; case 4: - convertToShow(img, img, true); - break; + { + Mat tmp(img.rows, img.cols, CV_8UC3); + convertToShow(img, tmp, true); + img = tmp; + } + break; default: CV_LOG_ERROR(NULL, "UI: imshow can't convert image to show"); CV_Assert(img.channels() < 1); CV_Assert(img.channels() > 4); } - cvtColor(img, img, COLOR_RGB2BGRA); + { + Mat bgra(img.rows, img.cols, CV_8UC4); + cvtColor(img, bgra, COLOR_RGB2BGRA, bgra.channels()); + img = bgra; + } int newWidth = windowRect.width; int newHeight = windowRect.height; @@ -148,7 +165,9 @@ namespace cv { namespace highgui_backend { if ((newWidth != img.cols) && (newHeight != img.rows)) { - cv::resize(img, img, cv::Size(newWidth, newHeight), INTER_LINEAR); + Mat imResize; + cv::resize(img, imResize, cv::Size(newWidth, newHeight), INTER_LINEAR); + img = imResize; } CV_LOG_INFO(NULL, "UI: Formated image: " @@ -253,7 +272,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::resize(int width, int height) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::resize(int width " + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::resize(int width " << width <<", height " << height << ")"); CV_Assert(width > 0); @@ -273,7 +292,7 @@ namespace cv { namespace highgui_backend { void FramebufferWindow::move(int x, int y) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); windowRect.x = x; windowRect.y = y; @@ -286,7 +305,7 @@ namespace cv { namespace highgui_backend { Rect FramebufferWindow::getImageRect() const { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getImageRect()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::getImageRect()"); return windowRect; } @@ -318,19 +337,19 @@ namespace cv { namespace highgui_backend { const std::string& FramebufferWindow::getID() const { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::getID()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::getID()"); return FB_ID; } bool FramebufferWindow::isActive() const { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::isActive()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::isActive()"); return true; } void FramebufferWindow::destroy() { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::destroy()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::destroy()"); } int FramebufferBackend::fbOpenAndGetInfo() @@ -539,7 +558,7 @@ namespace cv { namespace highgui_backend { FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) { - CV_LOG_INFO(NULL, "UI: FramebufferWindow::FramebufferBackend()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::FramebufferBackend()"); std::string fbModeStr = getFBMode(); @@ -603,7 +622,7 @@ namespace cv { namespace highgui_backend { FramebufferBackend::~FramebufferBackend() { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); if(fbID == -1) return; if (fbPointer != MAP_FAILED) @@ -622,7 +641,7 @@ namespace cv { namespace highgui_backend { } void FramebufferBackend::destroyAllWindows() { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::destroyAllWindows()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::destroyAllWindows()"); } // namedWindow @@ -630,7 +649,7 @@ namespace cv { namespace highgui_backend { const std::string& winname, int flags) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::createWindow(" + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::createWindow(" << winname << ", " << flags << ")"); return std::make_shared(*this, flags); } @@ -686,7 +705,7 @@ namespace cv { namespace highgui_backend { int FramebufferBackend::waitKeyEx(int delay) { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); int code = -1; @@ -734,7 +753,7 @@ namespace cv { namespace highgui_backend { int FramebufferBackend::pollKey() { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::pollKey()"); + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::pollKey()"); int code = -1; bool f_kbhit = false; f_kbhit = kbhit(); @@ -763,5 +782,4 @@ namespace cv { namespace highgui_backend { return "FB"; } -} -} +}} // cv::highgui_backend:: diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 5a90928366ef..4e975b0afa99 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -1,7 +1,9 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. #ifndef OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP #define OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP -#include "precomp.hpp" #include "backend.hpp" #include @@ -9,7 +11,8 @@ #include -namespace cv { namespace highgui_backend { +namespace cv { +namespace highgui_backend { enum OpenCVFBMode{ FB_MODE_EMU, @@ -18,7 +21,7 @@ enum OpenCVFBMode{ }; class FramebufferBackend; -class CV_EXPORTS FramebufferWindow : public UIWindow +class FramebufferWindow : public UIWindow { FramebufferBackend &backend; std::string FB_ID; @@ -126,9 +129,7 @@ class CV_EXPORTS FramebufferBackend: public UIBackend virtual const std::string getName() const override; }; -} - -} +}} // cv::highgui_backend:: #endif From 8ece6be00d714c2ec0b264ca4615f99a694a8f08 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 12 Jun 2024 09:31:57 +0300 Subject: [PATCH 72/81] Indentation in namespaces has been fixed. --- modules/highgui/src/window_framebuffer.cpp | 1165 ++++++++++---------- 1 file changed, 582 insertions(+), 583 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index deaab91e7049..5ecc5e435564 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -31,733 +31,704 @@ namespace cv { namespace highgui_backend { - std::shared_ptr createUIBackendFramebuffer() +std::shared_ptr createUIBackendFramebuffer() +{ + return std::make_shared(); +} + +static std::string& getFBMode() +{ + static std::string fbModeOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", "FB"); + return fbModeOpenCV; +} + +static std::string& getFBFileName() +{ + static std::string fbFileNameFB = + cv::utils::getConfigurationParameterString("FRAMEBUFFER", "/dev/fb0"); + static std::string fbFileNameOpenCV = + cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); + + if (!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; + return fbFileNameFB; +} + +FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): + backend(_backend), flags(_flags) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::FramebufferWindow()"); + FB_ID = "FramebufferWindow"; + windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); +} + +FramebufferWindow::~FramebufferWindow() +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); +} + +void FramebufferWindow::imshow(InputArray image) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); + currentImg = image.getMat().clone(); + + CV_LOG_INFO(NULL, "UI: InputArray image: " + << cv::typeToString(image.type()) << " size " << image.size()); + + if (currentImg.empty()) + { + CV_LOG_WARNING(NULL, "UI: image is empty"); + return; + } + CV_CheckEQ(currentImg.dims, 2, "UI: dims != 2"); + + Mat img = image.getMat(); + switch (img.channels()) + { + case 1: + { + Mat tmp; + switch(img.type()) + { + case CV_8U: + tmp = img; + break; + case CV_8S: + cv::convertScaleAbs(img, tmp, 1, 127); + break; + case CV_16S: + cv::convertScaleAbs(img, tmp, 1/255., 127); + break; + case CV_16U: + cv::convertScaleAbs(img, tmp, 1/255.); + break; + case CV_32F: + case CV_64F: // assuming image has values in range [0, 1) + img.convertTo(tmp, CV_8U, 255., 0.); + break; + } + Mat rgb(img.rows, img.cols, CV_8UC3); + cvtColor(tmp, rgb, COLOR_GRAY2RGB); + img = rgb; + } + break; + case 3: + case 4: + { + Mat tmp(img.rows, img.cols, CV_8UC3); + convertToShow(img, tmp, true); + img = tmp; + } + break; + default: + CV_LOG_ERROR(NULL, "UI: imshow can't convert image to show"); + CV_Assert(img.channels() < 1); + CV_Assert(img.channels() > 4); + } { - return std::make_shared(); + Mat bgra(img.rows, img.cols, CV_8UC4); + cvtColor(img, bgra, COLOR_RGB2BGRA, bgra.channels()); + img = bgra; } - static std::string& getFBMode() + int newWidth = windowRect.width; + int newHeight = windowRect.height; + int cntChannel = img.channels(); + cv::Size imgSize = currentImg.size(); + + if (flags & WINDOW_AUTOSIZE) { - static std::string fbModeOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_MODE", "FB"); - return fbModeOpenCV; + windowRect.width = imgSize.width; + windowRect.height = imgSize.height; + newWidth = windowRect.width; + newHeight = windowRect.height; } - static std::string& getFBFileName() + if (flags & WINDOW_FREERATIO) { - static std::string fbFileNameFB = - cv::utils::getConfigurationParameterString("FRAMEBUFFER", "/dev/fb0"); - static std::string fbFileNameOpenCV = - cv::utils::getConfigurationParameterString("OPENCV_HIGHGUI_FB_DEVICE", ""); - - if (!fbFileNameOpenCV.empty()) return fbFileNameOpenCV; - return fbFileNameFB; + newWidth = windowRect.width; + newHeight = windowRect.height; } + else //WINDOW_KEEPRATIO + { + double aspect_ratio = ((double)img.cols) / img.rows; + newWidth = windowRect.width; + newHeight = (int)(windowRect.width / aspect_ratio); + if (newHeight > windowRect.height) + { + newWidth = (int)(windowRect.height * aspect_ratio); + newHeight = windowRect.height; + } + } - FramebufferWindow::FramebufferWindow(FramebufferBackend &_backend, int _flags): - backend(_backend), flags(_flags) + if ((newWidth != img.cols) && (newHeight != img.rows)) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::FramebufferWindow()"); - FB_ID = "FramebufferWindow"; - windowRect = Rect(0,0, backend.getFBWidth(), backend.getFBHeight()); + Mat imResize; + cv::resize(img, imResize, cv::Size(newWidth, newHeight), INTER_LINEAR); + img = imResize; } - FramebufferWindow::~FramebufferWindow() + CV_LOG_INFO(NULL, "UI: Formated image: " + << cv::typeToString(img.type()) << " size " << img.size()); + + if (backend.getMode() == FB_MODE_EMU) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::~FramebufferWindow()"); + CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); + return; } - void FramebufferWindow::imshow(InputArray image) + if (backend.getFBPointer() == MAP_FAILED) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::imshow(InputArray image)"); - currentImg = image.getMat().clone(); - - CV_LOG_INFO(NULL, "UI: InputArray image: " - << cv::typeToString(image.type()) << " size " << image.size()); - - if (currentImg.empty()) - { - CV_LOG_WARNING(NULL, "UI: image is empty"); - return; - } - CV_CheckEQ(currentImg.dims, 2, "UI: dims != 2"); - - Mat img = image.getMat(); - switch (img.channels()) - { - case 1: - { - Mat tmp; - switch(img.type()) - { - case CV_8U: - tmp = img; - break; - case CV_8S: - cv::convertScaleAbs(img, tmp, 1, 127); - break; - case CV_16S: - cv::convertScaleAbs(img, tmp, 1/255., 127); - break; - case CV_16U: - cv::convertScaleAbs(img, tmp, 1/255.); - break; - case CV_32F: - case CV_64F: // assuming image has values in range [0, 1) - img.convertTo(tmp, CV_8U, 255., 0.); - break; - } - Mat rgb(img.rows, img.cols, CV_8UC3); - cvtColor(tmp, rgb, COLOR_GRAY2RGB); - img = rgb; - } - break; - case 3: - case 4: - { - Mat tmp(img.rows, img.cols, CV_8UC3); - convertToShow(img, tmp, true); - img = tmp; - } - break; - default: - CV_LOG_ERROR(NULL, "UI: imshow can't convert image to show"); - CV_Assert(img.channels() < 1); - CV_Assert(img.channels() > 4); - } - { - Mat bgra(img.rows, img.cols, CV_8UC4); - cvtColor(img, bgra, COLOR_RGB2BGRA, bgra.channels()); - img = bgra; - } + CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); + return; + } - int newWidth = windowRect.width; - int newHeight = windowRect.height; - int cntChannel = img.channels(); - cv::Size imgSize = currentImg.size(); + int xOffset = backend.getFBXOffset(); + int yOffset = backend.getFBYOffset(); + int fbHeight = backend.getFBHeight(); + int fbWidth = backend.getFBWidth(); + int lineLength = backend.getFBLineLength(); - if (flags & WINDOW_AUTOSIZE) - { - windowRect.width = imgSize.width; - windowRect.height = imgSize.height; - newWidth = windowRect.width; - newHeight = windowRect.height; - } + int img_start_x; + int img_start_y; + int img_end_x; + int img_end_y; + int fb_start_x; + int fb_start_y; - if (flags & WINDOW_FREERATIO) - { - newWidth = windowRect.width; - newHeight = windowRect.height; - } - else //WINDOW_KEEPRATIO - { - double aspect_ratio = ((double)img.cols) / img.rows; - newWidth = windowRect.width; - newHeight = (int)(windowRect.width / aspect_ratio); + if (windowRect.y - yOffset < 0) + { + img_start_y = - (windowRect.y - yOffset); + } + else + { + img_start_y = 0; + } + if (windowRect.x - xOffset < 0) + { + img_start_x = - (windowRect.x - xOffset); + } + else + { + img_start_x = 0; + } - if (newHeight > windowRect.height) - { - newWidth = (int)(windowRect.height * aspect_ratio); - newHeight = windowRect.height; - } - } + if (windowRect.y + yOffset + img.rows > fbHeight) + { + img_end_y = fbHeight - windowRect.y - yOffset; + } + else + { + img_end_y = img.rows; + } + if (windowRect.x + xOffset + img.cols > fbWidth) + { + img_end_x = fbWidth - windowRect.x - xOffset; + } + else + { + img_end_x = img.cols; + } - if ((newWidth != img.cols) && (newHeight != img.rows)) - { - Mat imResize; - cv::resize(img, imResize, cv::Size(newWidth, newHeight), INTER_LINEAR); - img = imResize; - } + if (windowRect.y + yOffset >= 0) + { + fb_start_y = windowRect.y + yOffset; + } + else + { + fb_start_y = 0; + } + if (windowRect.x + xOffset >= 0) + { + fb_start_x = windowRect.x + xOffset; + } + else + { + fb_start_x = 0; + } - CV_LOG_INFO(NULL, "UI: Formated image: " - << cv::typeToString(img.type()) << " size " << img.size()); + for (int y = img_start_y; y < img_end_y; y++) + { + std::memcpy(backend.getFBPointer() + + (fb_start_y + y - img_start_y) * lineLength + fb_start_x * cntChannel, + img.ptr(y) + img_start_x * cntChannel, + (img_end_x - img_start_x) * cntChannel); + } +} - if (backend.getMode() == FB_MODE_EMU) - { - CV_LOG_WARNING(NULL, "UI: FramebufferWindow::imshow is used in EMU mode"); - return; - } +double FramebufferWindow::getProperty(int /*prop*/) const +{ + CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); + return 0.0; +} - if (backend.getFBPointer() == MAP_FAILED) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer is not mapped"); - return; - } +bool FramebufferWindow::setProperty(int /*prop*/, double /*value*/) +{ + CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); + return false; +} - int xOffset = backend.getFBXOffset(); - int yOffset = backend.getFBYOffset(); - int fbHeight = backend.getFBHeight(); - int fbWidth = backend.getFBWidth(); - int lineLength = backend.getFBLineLength(); +void FramebufferWindow::resize(int width, int height) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::resize(int width " + << width <<", height " << height << ")"); - int img_start_x; - int img_start_y; - int img_end_x; - int img_end_y; - int fb_start_x; - int fb_start_y; + CV_Assert(width > 0); + CV_Assert(height > 0); - if (windowRect.y - yOffset < 0) - { - img_start_y = - (windowRect.y - yOffset); - } - else - { - img_start_y = 0; - } - if (windowRect.x - xOffset < 0) - { - img_start_x = - (windowRect.x - xOffset); - } - else - { - img_start_x = 0; - } + if (!(flags & WINDOW_AUTOSIZE)) + { + windowRect.width = width; + windowRect.height = height; - if (windowRect.y + yOffset + img.rows > fbHeight) - { - img_end_y = fbHeight - windowRect.y - yOffset; - } - else - { - img_end_y = img.rows; - } - if (windowRect.x + xOffset + img.cols > fbWidth) - { - img_end_x = fbWidth - windowRect.x - xOffset; - } - else + if ((currentImg.cols > 0) && (currentImg.rows > 0)) { - img_end_x = img.cols; + imshow(currentImg); } + } +} - if (windowRect.y + yOffset >= 0) - { - fb_start_y = windowRect.y + yOffset; - } - else - { - fb_start_y = 0; - } - if (windowRect.x + xOffset >= 0) - { - fb_start_x = windowRect.x + xOffset; - } - else - { - fb_start_x = 0; - } +void FramebufferWindow::move(int x, int y) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); - for (int y = img_start_y; y < img_end_y; y++) - { - std::memcpy(backend.getFBPointer() + - (fb_start_y + y - img_start_y) * lineLength + fb_start_x * cntChannel, - img.ptr(y) + img_start_x * cntChannel, - (img_end_x - img_start_x) * cntChannel); - } - } + windowRect.x = x; + windowRect.y = y; - double FramebufferWindow::getProperty(int /*prop*/) const + if ((currentImg.cols > 0) && (currentImg.rows > 0)) { - CV_LOG_WARNING(NULL, "UI: getProperty (not supported)"); - return 0.0; + imshow(currentImg); } +} - bool FramebufferWindow::setProperty(int /*prop*/, double /*value*/) - { - CV_LOG_WARNING(NULL, "UI: setProperty (not supported)"); - return false; - } +Rect FramebufferWindow::getImageRect() const +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::getImageRect()"); + return windowRect; +} - void FramebufferWindow::resize(int width, int height) - { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::resize(int width " - << width <<", height " << height << ")"); +void FramebufferWindow::setTitle(const std::string& /*title*/) +{ + CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); +} - CV_Assert(width > 0); - CV_Assert(height > 0); +void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/) +{ + CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); +} - if (!(flags & WINDOW_AUTOSIZE)) - { - windowRect.width = width; - windowRect.height = height; +std::shared_ptr FramebufferWindow::createTrackbar( + const std::string& /*name*/, + int /*count*/, + TrackbarCallback /*onChange*/, + void* /*userdata*/) +{ + CV_LOG_WARNING(NULL, "UI: createTrackbar (not supported)"); + return nullptr; +} - if ((currentImg.cols > 0) && (currentImg.rows > 0)) - { - imshow(currentImg); - } - } - } +std::shared_ptr FramebufferWindow::findTrackbar(const std::string& /*name*/) +{ + CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); + return nullptr; +} - void FramebufferWindow::move(int x, int y) - { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::move(int x " << x << ", y " << y <<")"); +const std::string& FramebufferWindow::getID() const +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::getID()"); + return FB_ID; +} - windowRect.x = x; - windowRect.y = y; +bool FramebufferWindow::isActive() const +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::isActive()"); + return true; +} - if ((currentImg.cols > 0) && (currentImg.rows > 0)) - { - imshow(currentImg); - } - } +void FramebufferWindow::destroy() +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::destroy()"); +} + +int FramebufferBackend::fbOpenAndGetInfo() +{ + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" + << fbFileName); - Rect FramebufferWindow::getImageRect() const + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::getImageRect()"); - return windowRect; + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; } - void FramebufferWindow::setTitle(const std::string& /*title*/) + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) { - CV_LOG_WARNING(NULL, "UI: setTitle (not supported)"); + CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); + return -1; } - void FramebufferWindow::setMouseCallback(MouseCallback /*onMouse*/, void* /*userdata*/) + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) { - CV_LOG_WARNING(NULL, "UI: setMouseCallback (not supported)"); + CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); + return -1; } - std::shared_ptr FramebufferWindow::createTrackbar( - const std::string& /*name*/, - int /*count*/, - TrackbarCallback /*onChange*/, - void* /*userdata*/) + CV_LOG_INFO(NULL, "UI: framebuffer info: \n" + << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" + << " green offset " << varInfo.green.offset << " length " << varInfo.green.length << "\n" + << " blue offset " << varInfo.blue.offset << " length " << varInfo.blue.length << "\n" + << "transp offset " << varInfo.transp.offset << " length " < FramebufferWindow::findTrackbar(const std::string& /*name*/) + fbWidth = varInfo.xres; + fbHeight = varInfo.yres; + fbXOffset = varInfo.xoffset; + fbYOffset = varInfo.yoffset; + fbBitsPerPixel = varInfo.bits_per_pixel; + fbLineLength = fixInfo.line_length; + + fbScreenSize = max(varInfo.xres, varInfo.xres_virtual) * + max(varInfo.yres, varInfo.yres_virtual) * + fbBitsPerPixel / 8; + + fbPointer = (unsigned char*) + mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + + if (fbPointer == MAP_FAILED) { - CV_LOG_WARNING(NULL, "UI: findTrackbar (not supported)"); - return nullptr; + CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); + return -1; } - const std::string& FramebufferWindow::getID() const + return fb_fd; +} + +int FramebufferBackend::XvfbOpenAndGetInfo() +{ + std::string fbFileName = getFBFileName(); + CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" + << fbFileName); + + int fb_fd = open(fbFileName.c_str(), O_RDWR); + if (fb_fd == -1) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::getID()"); - return FB_ID; + CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); + return -1; } - bool FramebufferWindow::isActive() const + XWDFileHeader *xwd_header; + + xwd_header = (XWDFileHeader*) + mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); + + if (xwd_header == MAP_FAILED) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::isActive()"); - return true; + CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); + return -1; } - void FramebufferWindow::destroy() + if (C32INT(&(xwd_header->pixmap_format)) != ZPixmap) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::destroy()"); + CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); + return -1; } - int FramebufferBackend::fbOpenAndGetInfo() + if (xwd_header->xoffset != 0) { - std::string fbFileName = getFBFileName(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" - << fbFileName); - - int fb_fd = open(fbFileName.c_str(), O_RDWR); - if (fb_fd == -1) - { - CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); - return -1; - } + CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); + return -1; + } - if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixInfo)) - { - CV_LOG_ERROR(NULL, "UI: can't read fix info for framebuffer"); - return -1; - } + unsigned int r = C32INT(&(xwd_header->red_mask)); + unsigned int g = C32INT(&(xwd_header->green_mask)); + unsigned int b = C32INT(&(xwd_header->blue_mask)); - if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &varInfo)) - { - CV_LOG_ERROR(NULL, "UI: can't read var info for framebuffer"); - return -1; - } + fbWidth = C32INT(&(xwd_header->pixmap_width)); + fbHeight = C32INT(&(xwd_header->pixmap_height)); + fbXOffset = 0; + fbYOffset = 0; + fbLineLength = C32INT(&(xwd_header->bytes_per_line)); + fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); - CV_LOG_INFO(NULL, "UI: framebuffer info: \n" - << " red offset " << varInfo.red.offset << " length " << varInfo.red.length << "\n" - << " green offset " << varInfo.green.offset << " length " << varInfo.green.length << "\n" - << " blue offset " << varInfo.blue.offset << " length " << varInfo.blue.length << "\n" - << "transp offset " << varInfo.transp.offset << " length " <header_size)); + xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); + xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * + C32INT(&(xwd_header->pixmap_height)); - fbPointer = (unsigned char*) - mmap(0, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); + munmap(xwd_header, sizeof(XWDFileHeader)); - if (fbPointer == MAP_FAILED) - { - CV_LOG_ERROR(NULL, "UI: can't mmap framebuffer"); - return -1; - } + fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; + xwd_header = (XWDFileHeader*) + mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); - return fb_fd; - } + fbPointer = (unsigned char*)xwd_header; + fbPointer_dist = xvfb_len_header + xvfb_len_colors; - int FramebufferBackend::XvfbOpenAndGetInfo() - { - std::string fbFileName = getFBFileName(); - CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" - << fbFileName); + return fb_fd; +} - int fb_fd = open(fbFileName.c_str(), O_RDWR); - if (fb_fd == -1) - { - CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); - return -1; - } +fb_var_screeninfo &FramebufferBackend::getVarInfo() +{ + return varInfo; +} - XWDFileHeader *xwd_header; +fb_fix_screeninfo &FramebufferBackend::getFixInfo() +{ + return fixInfo; +} - xwd_header = (XWDFileHeader*) - mmap(NULL, sizeof(XWDFileHeader), PROT_READ, MAP_SHARED, fb_fd, 0); +int FramebufferBackend::getFramebuffrerID() +{ + return fbID; +} - if (xwd_header == MAP_FAILED) - { - CV_LOG_ERROR(NULL, "UI: can't mmap xwd header"); - return -1; - } +int FramebufferBackend::getFBWidth() +{ + return fbWidth; +} - if (C32INT(&(xwd_header->pixmap_format)) != ZPixmap) - { - CV_LOG_ERROR(NULL, "Unsupported pixmap format: " << xwd_header->pixmap_format); - return -1; - } +int FramebufferBackend::getFBHeight() +{ + return fbHeight; +} - if (xwd_header->xoffset != 0) - { - CV_LOG_ERROR(NULL, "UI: Unsupported xoffset value: " << xwd_header->xoffset ); - return -1; - } +int FramebufferBackend::getFBXOffset() +{ + return fbXOffset; +} - unsigned int r = C32INT(&(xwd_header->red_mask)); - unsigned int g = C32INT(&(xwd_header->green_mask)); - unsigned int b = C32INT(&(xwd_header->blue_mask)); +int FramebufferBackend::getFBYOffset() +{ + return fbYOffset; +} - fbWidth = C32INT(&(xwd_header->pixmap_width)); - fbHeight = C32INT(&(xwd_header->pixmap_height)); - fbXOffset = 0; - fbYOffset = 0; - fbLineLength = C32INT(&(xwd_header->bytes_per_line)); - fbBitsPerPixel = C32INT(&(xwd_header->bits_per_pixel)); +int FramebufferBackend::getFBBitsPerPixel() +{ + return fbBitsPerPixel; +} - CV_LOG_INFO(NULL, "UI: XVFB info: \n" - << " red_mask " << r << "\n" - << " green_mask " << g << "\n" - << " blue_mask " << b << "\n" - << "bits_per_pixel " << fbBitsPerPixel); +int FramebufferBackend::getFBLineLength() +{ + return fbLineLength; +} - if ((r != 16711680 ) && (g != 65280 ) && (b != 255 ) && - (fbBitsPerPixel != 32)) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer format is not supported " - << "(use BGRA format with bits_per_pixel = 32)"); - return -1; - } +unsigned char* FramebufferBackend::getFBPointer() +{ + return fbPointer + fbPointer_dist; +} - xvfb_len_header = C32INT(&(xwd_header->header_size)); - xvfb_len_colors = sizeof(XWDColor) * C32INT(&(xwd_header->ncolors)); - xvfb_len_pixmap = C32INT(&(xwd_header->bytes_per_line)) * - C32INT(&(xwd_header->pixmap_height)); +Mat& FramebufferBackend::getBackgroundBuff() +{ + return backgroundBuff; +} - munmap(xwd_header, sizeof(XWDFileHeader)); +OpenCVFBMode FramebufferBackend::getMode() +{ + return mode; +} - fbScreenSize = xvfb_len_header + xvfb_len_colors + xvfb_len_pixmap; - xwd_header = (XWDFileHeader*) - mmap(NULL, fbScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); +FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - fbPointer = (unsigned char*)xwd_header; - fbPointer_dist = xvfb_len_header + xvfb_len_colors; + std::string fbModeStr = getFBMode(); - return fb_fd; - } - - fb_var_screeninfo &FramebufferBackend::getVarInfo() + if (fbModeStr == "EMU") { - return varInfo; + mode = FB_MODE_EMU; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); } - - fb_fix_screeninfo &FramebufferBackend::getFixInfo() + if (fbModeStr == "FB") { - return fixInfo; + mode = FB_MODE_FB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); } - - int FramebufferBackend::getFramebuffrerID() + if (fbModeStr == "XVFB") { - return fbID; + mode = FB_MODE_XVFB; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); } - int FramebufferBackend::getFBWidth() + fbID = -1; + if (mode == FB_MODE_FB) { - return fbWidth; + fbID = fbOpenAndGetInfo(); } - - int FramebufferBackend::getFBHeight() + if (mode == FB_MODE_XVFB) { - return fbHeight; + fbID = XvfbOpenAndGetInfo(); } - int FramebufferBackend::getFBXOffset() - { - return fbXOffset; - } + CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - int FramebufferBackend::getFBYOffset() + if (fbID == -1) { - return fbYOffset; - } + mode = FB_MODE_EMU; + fbWidth = 640; + fbHeight = 480; + fbXOffset = 0; + fbYOffset = 0; + fbBitsPerPixel = 0; + fbLineLength = 0; - int FramebufferBackend::getFBBitsPerPixel() - { - return fbBitsPerPixel; + CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); + return; } - int FramebufferBackend::getFBLineLength() - { - return fbLineLength; - } + CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " + << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); - unsigned char* FramebufferBackend::getFBPointer() - { - return fbPointer + fbPointer_dist; - } + CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " + << fbXOffset << " " << fbYOffset << " " << fbLineLength); - Mat& FramebufferBackend::getBackgroundBuff() + backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); + int cntChannel = 4; + for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - return backgroundBuff; + std::memcpy(backgroundBuff.ptr(y - fbYOffset), + getFBPointer() + y * fbLineLength + fbXOffset * cntChannel, + backgroundBuff.cols * cntChannel); } +} - OpenCVFBMode FramebufferBackend::getMode() - { - return mode; - } +FramebufferBackend::~FramebufferBackend() +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); + if(fbID == -1) return; - FramebufferBackend::FramebufferBackend():mode(FB_MODE_FB), fbPointer_dist(0) + if (fbPointer != MAP_FAILED) { - CV_LOG_DEBUG(NULL, "UI: FramebufferWindow::FramebufferBackend()"); - - std::string fbModeStr = getFBMode(); - - if (fbModeStr == "EMU") - { - mode = FB_MODE_EMU; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use EMU mode"); - } - if (fbModeStr == "FB") - { - mode = FB_MODE_FB; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use FB mode"); - } - if (fbModeStr == "XVFB") - { - mode = FB_MODE_XVFB; - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is trying to use XVFB mode"); - } - - fbID = -1; - if (mode == FB_MODE_FB) - { - fbID = fbOpenAndGetInfo(); - } - if (mode == FB_MODE_XVFB) - { - fbID = XvfbOpenAndGetInfo(); - } - - CV_LOG_INFO(NULL, "UI: FramebufferWindow::fbID " << fbID); - - if (fbID == -1) - { - mode = FB_MODE_EMU; - fbWidth = 640; - fbHeight = 480; - fbXOffset = 0; - fbYOffset = 0; - fbBitsPerPixel = 0; - fbLineLength = 0; - - CV_LOG_WARNING(NULL, "UI: FramebufferWindow is used in EMU mode"); - return; - } - - CV_LOG_INFO(NULL, "UI: Framebuffer's width, height, bits per pix: " - << fbWidth << " " << fbHeight << " " << fbBitsPerPixel); - - CV_LOG_INFO(NULL, "UI: Framebuffer's offsets (x, y), line length: " - << fbXOffset << " " << fbYOffset << " " << fbLineLength); - - backgroundBuff = Mat(fbHeight, fbWidth, CV_8UC4); int cntChannel = 4; for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) { - std::memcpy(backgroundBuff.ptr(y - fbYOffset), - getFBPointer() + y * fbLineLength + fbXOffset * cntChannel, + std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset * cntChannel, + backgroundBuff.ptr(y - fbYOffset), backgroundBuff.cols * cntChannel); } - } - - FramebufferBackend::~FramebufferBackend() - { - CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::~FramebufferBackend()"); - if(fbID == -1) return; - - if (fbPointer != MAP_FAILED) - { - int cntChannel = 4; - for (int y = fbYOffset; y < backgroundBuff.rows + fbYOffset; y++) - { - std::memcpy(getFBPointer() + y * fbLineLength + fbXOffset * cntChannel, - backgroundBuff.ptr(y - fbYOffset), - backgroundBuff.cols * cntChannel); - } - munmap(fbPointer, fbScreenSize); - } - close(fbID); + munmap(fbPointer, fbScreenSize); } + close(fbID); +} - void FramebufferBackend::destroyAllWindows() { - CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::destroyAllWindows()"); - } +void FramebufferBackend::destroyAllWindows() { + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::destroyAllWindows()"); +} + +// namedWindow +std::shared_ptr FramebufferBackend::createWindow( + const std::string& winname, + int flags) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::createWindow(" + << winname << ", " << flags << ")"); + return std::make_shared(*this, flags); +} - // namedWindow - std::shared_ptr FramebufferBackend::createWindow( - const std::string& winname, - int flags) +void FramebufferBackend::initTermios(int echo, int wait) +{ + tcgetattr(0, &old); + current = old; + current.c_lflag &= ~ICANON; + current.c_lflag &= ~ISIG; + current.c_cc[VMIN] = wait; + if (echo) { - CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::createWindow(" - << winname << ", " << flags << ")"); - return std::make_shared(*this, flags); + current.c_lflag |= ECHO; } - - void FramebufferBackend::initTermios(int echo, int wait) + else { - tcgetattr(0, &old); - current = old; - current.c_lflag &= ~ICANON; - current.c_lflag &= ~ISIG; - current.c_cc[VMIN] = wait; - if (echo) - { - current.c_lflag |= ECHO; - } - else - { - current.c_lflag &= ~ECHO; - } - tcsetattr(0, TCSANOW, ¤t); + current.c_lflag &= ~ECHO; } + tcsetattr(0, TCSANOW, ¤t); +} + +void FramebufferBackend::resetTermios(void) +{ + tcsetattr(0, TCSANOW, &old); +} - void FramebufferBackend::resetTermios(void) +int FramebufferBackend::getch_(int echo, int wait) +{ + int ch; + initTermios(echo, wait); + ch = getchar(); + if (ch < 0) { - tcsetattr(0, TCSANOW, &old); + rewind(stdin); } + resetTermios(); + return ch; +} - int FramebufferBackend::getch_(int echo, int wait) +bool FramebufferBackend::kbhit() +{ + int byteswaiting = 0; + initTermios(0, 1); + if (ioctl(0, FIONREAD, &byteswaiting) < 0) { - int ch; - initTermios(echo, wait); - ch = getchar(); - if (ch < 0) - { - rewind(stdin); - } - resetTermios(); - return ch; + CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); } + resetTermios(); - bool FramebufferBackend::kbhit() - { - int byteswaiting = 0; - initTermios(0, 1); - if (ioctl(0, FIONREAD, &byteswaiting) < 0) - { - CV_LOG_ERROR(NULL, "UI: Framebuffer ERR byteswaiting" ); - } - resetTermios(); + return byteswaiting > 0; +} - return byteswaiting > 0; - } +int FramebufferBackend::waitKeyEx(int delay) +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); - int FramebufferBackend::waitKeyEx(int delay) - { - CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::waitKeyEx(int delay = " << delay << ")"); + int code = -1; - int code = -1; + if (delay <= 0) + { + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; - if (delay <= 0) + while ((ch = getch_(0, 0)) >= 0) { - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); code = ch; - - while ((ch = getch_(0, 0)) >= 0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } - } - else - { - bool f_kbhit = false; - while (!(f_kbhit = kbhit()) && (delay > 0)) - { - delay -= 1; - usleep(1000); - } - if (f_kbhit) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); - - int ch = getch_(0, 1); - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); - code = ch; - - while ((ch = getch_(0, 0)) >= 0) - { - CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " - << (int)ch << " (additional code on )"); - code = ch; - } - } } - - CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); - return code; } - - int FramebufferBackend::pollKey() + else { - CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::pollKey()"); - int code = -1; bool f_kbhit = false; - f_kbhit = kbhit(); - + while (!(f_kbhit = kbhit()) && (delay > 0)) + { + delay -= 1; + usleep(1000); + } if (f_kbhit) { CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); @@ -773,13 +744,41 @@ namespace highgui_backend { code = ch; } } - - return code; } - const std::string FramebufferBackend::getName() const + CV_LOG_INFO(NULL, "UI: FramebufferBackend::waitKeyEx() result code = " << code); + return code; +} + +int FramebufferBackend::pollKey() +{ + CV_LOG_DEBUG(NULL, "UI: FramebufferBackend::pollKey()"); + int code = -1; + bool f_kbhit = false; + f_kbhit = kbhit(); + + if (f_kbhit) { - return "FB"; + CV_LOG_INFO(NULL, "UI: FramebufferBackend kbhit is True "); + + int ch = getch_(0, 1); + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " << (int)ch); + code = ch; + + while ((ch = getch_(0, 0)) >= 0) + { + CV_LOG_INFO(NULL, "UI: FramebufferBackend::getch_() take value = " + << (int)ch << " (additional code on )"); + code = ch; + } } + return code; +} + +const std::string FramebufferBackend::getName() const +{ + return "FB"; +} + }} // cv::highgui_backend:: From 3a63f85c1225fde4eb82429dc16ade84b3986d9e Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 12 Jun 2024 06:48:20 +0000 Subject: [PATCH 73/81] comparison fixed --- modules/highgui/src/window_framebuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index 5ecc5e435564..ca62842341d5 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -282,7 +282,7 @@ void FramebufferWindow::resize(int width, int height) windowRect.width = width; windowRect.height = height; - if ((currentImg.cols > 0) && (currentImg.rows > 0)) + if (!currentImg.empty()) { imshow(currentImg); } @@ -296,7 +296,7 @@ void FramebufferWindow::move(int x, int y) windowRect.x = x; windowRect.y = y; - if ((currentImg.cols > 0) && (currentImg.rows > 0)) + if (!currentImg.empty()) { imshow(currentImg); } From 2972dff32cdf491fd042cbb7fa5ead39b810a9d7 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 14 Jun 2024 19:33:36 +0300 Subject: [PATCH 74/81] removal of XWD dependency --- CMakeLists.txt | 4 +- modules/highgui/CMakeLists.txt | 23 +++- modules/highgui/src/XWDFile.h | 130 ------------------ modules/highgui/src/Xmd.h | 146 --------------------- modules/highgui/src/window_framebuffer.cpp | 20 ++- modules/highgui/src/window_framebuffer.hpp | 4 +- modules/highgui/test/test_gui.cpp | 6 +- 7 files changed, 47 insertions(+), 286 deletions(-) delete mode 100644 modules/highgui/src/XWDFile.h delete mode 100644 modules/highgui/src/Xmd.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 41a68bbf6742..c6b2e0645a52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,6 +306,8 @@ OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF VERIFY HAVE_GTK AND NOT HAVE_GTK3) OCV_OPTION(WITH_FRAMEBUFFER "Include framebuffer support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID) +OCV_OPTION(WITH_FRAMEBUFFER_XVFB "Include virtual framebuffer support" OFF + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID) OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID VERIFY HAVE_WAYLAND) @@ -1451,7 +1453,7 @@ if(WITH_GTK OR HAVE_GTK) endif() endif() -if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER) +if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB OR HAVE_FRAMEBUFFER_XVFB) status(" Framebuffer UI:" "YES") endif() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index d81a8beb9ece..db1d8612b188 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -49,13 +49,30 @@ list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${n set(OPENCV_HIGHGUI_BUILTIN_BACKEND "") -if(WITH_FRAMEBUFFER) +if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") + if(WITH_FRAMEBUFFER_XVFB) + include(CheckCXXSourceCompiles) + check_cxx_source_compiles( + "#include + #include + + int main(void) + { + XWDFileHeader *xwd_header; + XWDColor *xwd_colors; + return 0; + }" + HAVE_XWD_STRUCT) + if(HAVE_XWD_STRUCT) + add_definitions(-DHAVE_FRAMEBUFFER_XVFB) + else() + message(FATAL_ERROR "XWD structure not found") + endif() + endif() add_definitions(-DHAVE_FRAMEBUFFER) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/XWDFile.h) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/Xmd.h) endif() if(WITH_WAYLAND AND HAVE_WAYLAND) diff --git a/modules/highgui/src/XWDFile.h b/modules/highgui/src/XWDFile.h deleted file mode 100644 index 20ebf568e8e3..000000000000 --- a/modules/highgui/src/XWDFile.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - -Copyright 1985, 1986, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -*/ - -/* - * XWDFile.h MIT Project Athena, X Window system window raster - * image dumper, dump file format header file. - * - * Author: Tony Della Fera, DEC - * 27-Jun-85 - * - * Modifier: William F. Wyatt, SAO - * 18-Nov-86 - version 6 for saving/restoring color maps - */ - -#ifndef XWDFILE_H -#define XWDFILE_H - -// replaced "#include " with "#include "Xmd.h"" -#include "Xmd.h" - -#define XWD_FILE_VERSION 7 -#define sz_XWDheader 100 -#define sz_XWDColor 12 - -// Added macro to convert big-endian numbers to local representation -#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | \ - (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) - -/***************************************************************** - * Start. Added from - *****************************************************************/ - -#define XYBitmap 0 /* depth 1, XYFormat */ -#define XYPixmap 1 /* depth == drawable depth */ -#define ZPixmap 2 /* depth == drawable depth */ - -/***************************************************************** - * End. Added from - *****************************************************************/ - - -typedef CARD32 xwdval; /* for old broken programs */ - -/* Values in the file are most significant byte first. */ - -typedef struct _xwd_file_header { - /* header_size = SIZEOF(XWDheader) + length of null-terminated - * window name. */ - CARD32 header_size; - - CARD32 file_version; /* = XWD_FILE_VERSION above */ - CARD32 pixmap_format; /* ZPixmap or XYPixmap */ - CARD32 pixmap_depth; /* Pixmap depth */ - CARD32 pixmap_width; /* Pixmap width */ - CARD32 pixmap_height; /* Pixmap height */ - CARD32 xoffset; /* Bitmap x offset, normally 0 */ - CARD32 byte_order; /* of image data: MSBFirst, LSBFirst */ - - /* bitmap_unit applies to bitmaps (depth 1 format XY) only. - * It is the number of bits that each scanline is padded to. */ - CARD32 bitmap_unit; - - CARD32 bitmap_bit_order; /* bitmaps only: MSBFirst, LSBFirst */ - - /* bitmap_pad applies to pixmaps (non-bitmaps) only. - * It is the number of bits that each scanline is padded to. */ - CARD32 bitmap_pad; - - CARD32 bits_per_pixel; /* Bits per pixel */ - - /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps) - * or bitmap_pad (pixmaps). It is the delta (in bytes) to get - * to the same x position on an adjacent row. */ - CARD32 bytes_per_line; - CARD32 visual_class; /* Class of colormap */ - CARD32 red_mask; /* Z red mask */ - CARD32 green_mask; /* Z green mask */ - CARD32 blue_mask; /* Z blue mask */ - CARD32 bits_per_rgb; /* Log2 of distinct color values */ - CARD32 colormap_entries; /* Number of entries in colormap; not used? */ - CARD32 ncolors; /* Number of XWDColor structures */ - CARD32 window_width; /* Window width */ - CARD32 window_height; /* Window height */ - CARD32 window_x; /* Window upper left X coordinate */ - CARD32 window_y; /* Window upper left Y coordinate */ - CARD32 window_bdrwidth; /* Window border width */ -} XWDFileHeader; - -/* Null-terminated window name follows the above structure. */ - -/* Next comes XWDColor structures, at offset XWDFileHeader.header_size in - * the file. XWDFileHeader.ncolors tells how many XWDColor structures - * there are. - */ - -typedef struct { - CARD32 pixel; - CARD16 red; - CARD16 green; - CARD16 blue; - CARD8 flags; - CARD8 pad; -} XWDColor; - -/* Last comes the image data in the format described by XWDFileHeader. */ - -#endif /* XWDFILE_H */ diff --git a/modules/highgui/src/Xmd.h b/modules/highgui/src/Xmd.h deleted file mode 100644 index 431d36de9618..000000000000 --- a/modules/highgui/src/Xmd.h +++ /dev/null @@ -1,146 +0,0 @@ -/*********************************************************** - -Copyright 1987, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -******************************************************************/ -#ifndef XMD_H -# define XMD_H 1 -/* - * Xmd.h: MACHINE DEPENDENT DECLARATIONS. - */ - -/* - * Special per-machine configuration flags. - */ -# if defined(__sun) && defined(__SVR4) -# include /* Solaris: defines _LP64 if necessary */ -# endif - -#if defined(__SIZEOF_LONG__) -# if __SIZEOF_LONG__ == 8 -# define LONG64 /* 32/64-bit architecture */ -# endif -# elif defined (_LP64) || defined(__LP64__) || \ - defined(__alpha) || defined(__alpha__) || \ - defined(__ia64__) || defined(ia64) || \ - defined(__sparc64__) || \ - defined(__s390x__) || \ - defined(__amd64__) || defined(amd64) || \ - defined(__powerpc64__) -# if !defined(__ILP32__) /* amd64-x32 is 32bit */ -# define LONG64 /* 32/64-bit architecture */ -# endif /* !__ILP32__ */ -# endif - -/* - * Definition of macro used to set constants for size of network structures; - * machines with preprocessors that can't handle all of the sz_ symbols - * can define this macro to be sizeof(x) if and only if their compiler doesn't - * pad out structures (esp. the xTextElt structure which contains only two - * one-byte fields). Network structures should always define sz_symbols. - * - * The sz_ prefix is used instead of something more descriptive so that the - * symbols are no more than 32 characters long (which causes problems for some - * compilers and preprocessors). - * - * The extra indirection is to get macro arguments to expand correctly before - * the concatenation, rather than afterward. - */ -# define _SIZEOF(x) sz_##x -# define SIZEOF(x) _SIZEOF(x) - -/* - * Bitfield suffixes for the protocol structure elements, if you - * need them. Note that bitfields are not guaranteed to be signed - * (or even unsigned) according to ANSI C. - */ -# define B32 /* bitfield not needed on architectures with native 32-bit type */ -# define B16 /* bitfield not needed on architectures with native 16-bit type */ -# ifdef LONG64 -typedef long INT64; -typedef int INT32; -# else -typedef long INT32; -# endif -typedef short INT16; - -typedef signed char INT8; - -# ifdef LONG64 -typedef unsigned long CARD64; -typedef unsigned int CARD32; -# else -typedef unsigned long long CARD64; -typedef unsigned long CARD32; -# endif -typedef unsigned short CARD16; -typedef unsigned char CARD8; - -typedef CARD32 BITS32; -typedef CARD16 BITS16; - -typedef CARD8 BYTE; -typedef CARD8 BOOL; - -/* - * was definitions for sign-extending bitfields on architectures without - * native types smaller than 64-bit, now just backwards compatibility - */ -# define cvtINT8toInt(val) (val) -# define cvtINT16toInt(val) (val) -# define cvtINT32toInt(val) (val) -# define cvtINT8toShort(val) (val) -# define cvtINT16toShort(val) (val) -# define cvtINT32toShort(val) (val) -# define cvtINT8toLong(val) (val) -# define cvtINT16toLong(val) (val) -# define cvtINT32toLong(val) (val) - -/* - * this version should leave result of type (t *), but that should only be - * used when not in MUSTCOPY - */ -# define NEXTPTR(p,t) (((t *)(p)) + 1) - -#endif /* XMD_H */ diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index ca62842341d5..a3a22bfc2658 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -1,6 +1,7 @@ // This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. + #include "precomp.hpp" #include "window_framebuffer.hpp" @@ -26,7 +27,14 @@ #include "opencv2/imgproc.hpp" -#include "XWDFile.h" +#ifdef HAVE_FRAMEBUFFER_XVFB +#include +#include + +#define C32INT(ptr) ((((unsigned char*)ptr)[0] << 24) | (((unsigned char*)ptr)[1] << 16) | \ + (((unsigned char*)ptr)[2] << 8) | (((unsigned char*)ptr)[3] << 0)) +#endif + namespace cv { namespace highgui_backend { @@ -419,11 +427,14 @@ int FramebufferBackend::fbOpenAndGetInfo() int FramebufferBackend::XvfbOpenAndGetInfo() { + int fb_fd = -1; + +#ifdef HAVE_FRAMEBUFFER_XVFB std::string fbFileName = getFBFileName(); CV_LOG_INFO(NULL, "UI: FramebufferWindow::The following is used as a framebuffer file: \n" << fbFileName); - int fb_fd = open(fbFileName.c_str(), O_RDWR); + fb_fd = open(fbFileName.c_str(), O_RDWR); if (fb_fd == -1) { CV_LOG_ERROR(NULL, "UI: can't open framebuffer"); @@ -492,6 +503,11 @@ int FramebufferBackend::XvfbOpenAndGetInfo() fbPointer = (unsigned char*)xwd_header; fbPointer_dist = xvfb_len_header + xvfb_len_colors; +#else + CV_LOG_WARNING(NULL, "UI: To use virtual framebuffer, " + << "compile OpenCV with the WITH_FRAMEBUFFER_XVFB=ON"); +#endif + return fb_fd; } diff --git a/modules/highgui/src/window_framebuffer.hpp b/modules/highgui/src/window_framebuffer.hpp index 4e975b0afa99..e7bf50dff661 100644 --- a/modules/highgui/src/window_framebuffer.hpp +++ b/modules/highgui/src/window_framebuffer.hpp @@ -1,6 +1,7 @@ // This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. + #ifndef OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP #define OPENCV_HIGHGUI_WINDOWS_FRAMEBUFFER_HPP @@ -64,7 +65,7 @@ class FramebufferWindow : public UIWindow virtual void destroy() override; }; // FramebufferWindow -class CV_EXPORTS FramebufferBackend: public UIBackend +class FramebufferBackend: public UIBackend { OpenCVFBMode mode; @@ -131,5 +132,4 @@ class CV_EXPORTS FramebufferBackend: public UIBackend }} // cv::highgui_backend:: - #endif diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index b8093e07ecec..13c64451242a 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -149,7 +149,8 @@ static void Foo(int, void* counter) && !defined HAVE_WAYLAND \ ) \ || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ - || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ \ + || defined HAVE_FRAMEBUFFER_XVFB /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar_unsafe) #else TEST(Highgui_GUI, trackbar_unsafe) @@ -190,7 +191,8 @@ void testTrackbarCallback(int pos, void* param) && !defined HAVE_WAYLAND \ ) \ || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ - || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ \ + || defined HAVE_FRAMEBUFFER_XVFB /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar) #else TEST(Highgui_GUI, trackbar) From dabbb5fc5056817572a8c6875848d852804a101f Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Fri, 14 Jun 2024 20:06:26 +0300 Subject: [PATCH 75/81] fixed trailing whitespace --- modules/highgui/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index db1d8612b188..0497e2345e93 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -53,7 +53,7 @@ if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") if(WITH_FRAMEBUFFER_XVFB) include(CheckCXXSourceCompiles) - check_cxx_source_compiles( + check_cxx_source_compiles( "#include #include @@ -62,8 +62,7 @@ if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) XWDFileHeader *xwd_header; XWDColor *xwd_colors; return 0; - }" - HAVE_XWD_STRUCT) + }" HAVE_XWD_STRUCT) if(HAVE_XWD_STRUCT) add_definitions(-DHAVE_FRAMEBUFFER_XVFB) else() From 757160baa64fd2464d07331517919e87bb00ada9 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 19 Jun 2024 12:12:35 +0000 Subject: [PATCH 76/81] fixed CMake files for framebuffer --- CMakeLists.txt | 13 +++++++++- cmake/checks/framebuffer.cpp | 9 +++++++ modules/highgui/CMakeLists.txt | 25 +++++-------------- .../highgui/cmake/detect_framebuffer.cmake | 18 +++++++++++++ modules/highgui/cmake/init.cmake | 7 ++++++ 5 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 cmake/checks/framebuffer.cpp create mode 100644 modules/highgui/cmake/detect_framebuffer.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c6b2e0645a52..c53d8957b1e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1454,7 +1454,18 @@ if(WITH_GTK OR HAVE_GTK) endif() if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB OR HAVE_FRAMEBUFFER_XVFB) - status(" Framebuffer UI:" "YES") + if(HAVE_FRAMEBUFFER OR HAVE_FRAMEBUFFER_XVFB) + if(HAVE_FRAMEBUFFER) + status(" Framebuffer UI:" "YES") + endif() + if(HAVE_FRAMEBUFFER_XVFB) + status(" Virtual framebuffer UI:" "YES") + else() + status(" Virtual framebuffer UI:" "NO") + endif() + else() + status(" Framebuffer UI:" "NO") + endif() endif() if(WITH_OPENGL OR HAVE_OPENGL) diff --git a/cmake/checks/framebuffer.cpp b/cmake/checks/framebuffer.cpp new file mode 100644 index 000000000000..77bb60275c94 --- /dev/null +++ b/cmake/checks/framebuffer.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(void) +{ + XWDFileHeader *xwd_header; + XWDColor *xwd_colors; + return 0; +} diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 0497e2345e93..086264570799 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -51,27 +51,14 @@ set(OPENCV_HIGHGUI_BUILTIN_BACKEND "") if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") - if(WITH_FRAMEBUFFER_XVFB) - include(CheckCXXSourceCompiles) - check_cxx_source_compiles( - "#include - #include - - int main(void) - { - XWDFileHeader *xwd_header; - XWDColor *xwd_colors; - return 0; - }" HAVE_XWD_STRUCT) - if(HAVE_XWD_STRUCT) + if(HAVE_FRAMEBUFFER_XVFB) add_definitions(-DHAVE_FRAMEBUFFER_XVFB) - else() - message(FATAL_ERROR "XWD structure not found") - endif() endif() - add_definitions(-DHAVE_FRAMEBUFFER) - list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + if(HAVE_FRAMEBUFFER) + add_definitions(-DHAVE_FRAMEBUFFER) + list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + endif() endif() if(WITH_WAYLAND AND HAVE_WAYLAND) diff --git a/modules/highgui/cmake/detect_framebuffer.cmake b/modules/highgui/cmake/detect_framebuffer.cmake new file mode 100644 index 000000000000..9a6470bb1f48 --- /dev/null +++ b/modules/highgui/cmake/detect_framebuffer.cmake @@ -0,0 +1,18 @@ +# --- FB --- +ocv_clear_vars(HAVE_FRAMEBUFFER HAVE_FRAMEBUFFER_XVFB) +if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) + set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") + if(WITH_FRAMEBUFFER_XVFB) + try_compile(HAVE_FRAMEBUFFER_XVFB + "${CMAKE_CURRENT_BINARY_DIR}" + "${OpenCV_SOURCE_DIR}/cmake/checks/framebuffer.cpp") + if(HAVE_FRAMEBUFFER_XVFB) + message(STATUS "Check virtual framebuffer - done") + else() + message(STATUS + "Check virtual framebuffer - faild\n" + "Please install the xorg-x11-proto-devel or x11proto-dev package\n") + endif() + endif() + set(HAVE_FRAMEBUFFER ON) +endif() diff --git a/modules/highgui/cmake/init.cmake b/modules/highgui/cmake/init.cmake index 49d4799b308b..1af5bd3a48e6 100644 --- a/modules/highgui/cmake/init.cmake +++ b/modules/highgui/cmake/init.cmake @@ -39,6 +39,13 @@ endmacro() add_backend("gtk" WITH_GTK) add_backend("win32ui" WITH_WIN32UI) add_backend("wayland" WITH_WAYLAND) +if(WITH_FRAMEBUFFER AND WITH_FRAMEBUFFER_XVFB) + add_backend("framebuffer" WITH_FRAMEBUFFER) +else() + add_backend("framebuffer" WITH_FRAMEBUFFER) + add_backend("framebuffer" WITH_FRAMEBUFFER_XVFB) +endif() + # TODO cocoa # TODO qt # TODO opengl From 7b41776fe2c518d98cd0665cdcdb0e5da7fc1a66 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 19 Jun 2024 12:18:14 +0000 Subject: [PATCH 77/81] delete set for OPENCV_HIGHGUI_BUILTIN_BACKEND at detect_framebuffer.cmake --- modules/highgui/cmake/detect_framebuffer.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/highgui/cmake/detect_framebuffer.cmake b/modules/highgui/cmake/detect_framebuffer.cmake index 9a6470bb1f48..42df6988feb8 100644 --- a/modules/highgui/cmake/detect_framebuffer.cmake +++ b/modules/highgui/cmake/detect_framebuffer.cmake @@ -1,7 +1,6 @@ # --- FB --- ocv_clear_vars(HAVE_FRAMEBUFFER HAVE_FRAMEBUFFER_XVFB) if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) - set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") if(WITH_FRAMEBUFFER_XVFB) try_compile(HAVE_FRAMEBUFFER_XVFB "${CMAKE_CURRENT_BINARY_DIR}" From 0de5a51dd9e751de607d5939098428d9642569e5 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 19 Jun 2024 12:50:26 +0000 Subject: [PATCH 78/81] fixed trailing whitespace~ --- modules/highgui/cmake/detect_framebuffer.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/cmake/detect_framebuffer.cmake b/modules/highgui/cmake/detect_framebuffer.cmake index 42df6988feb8..d2e32450d7cc 100644 --- a/modules/highgui/cmake/detect_framebuffer.cmake +++ b/modules/highgui/cmake/detect_framebuffer.cmake @@ -8,7 +8,7 @@ if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) if(HAVE_FRAMEBUFFER_XVFB) message(STATUS "Check virtual framebuffer - done") else() - message(STATUS + message(STATUS "Check virtual framebuffer - faild\n" "Please install the xorg-x11-proto-devel or x11proto-dev package\n") endif() From 6c5d2dc12eaaffafe1e798c2d98500d008690b11 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Wed, 19 Jun 2024 17:11:06 +0300 Subject: [PATCH 79/81] fixed some comments --- CMakeLists.txt | 10 ++-------- modules/highgui/cmake/detect_framebuffer.cmake | 8 ++++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c53d8957b1e4..badc01770914 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1455,14 +1455,8 @@ endif() if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB OR HAVE_FRAMEBUFFER_XVFB) if(HAVE_FRAMEBUFFER OR HAVE_FRAMEBUFFER_XVFB) - if(HAVE_FRAMEBUFFER) - status(" Framebuffer UI:" "YES") - endif() - if(HAVE_FRAMEBUFFER_XVFB) - status(" Virtual framebuffer UI:" "YES") - else() - status(" Virtual framebuffer UI:" "NO") - endif() + status(" Framebuffer UI:" HAVE_FRAMEBUFFER THEN YES ELSE NO) + status(" Virtual framebuffer UI:" HAVE_FRAMEBUFFER_XVFB THEN YES ELSE NO) else() status(" Framebuffer UI:" "NO") endif() diff --git a/modules/highgui/cmake/detect_framebuffer.cmake b/modules/highgui/cmake/detect_framebuffer.cmake index d2e32450d7cc..3a7959a1c58b 100644 --- a/modules/highgui/cmake/detect_framebuffer.cmake +++ b/modules/highgui/cmake/detect_framebuffer.cmake @@ -3,14 +3,14 @@ ocv_clear_vars(HAVE_FRAMEBUFFER HAVE_FRAMEBUFFER_XVFB) if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) if(WITH_FRAMEBUFFER_XVFB) try_compile(HAVE_FRAMEBUFFER_XVFB - "${CMAKE_CURRENT_BINARY_DIR}" - "${OpenCV_SOURCE_DIR}/cmake/checks/framebuffer.cpp") + "${CMAKE_CURRENT_BINARY_DIR}" + "${OpenCV_SOURCE_DIR}/cmake/checks/framebuffer.cpp") if(HAVE_FRAMEBUFFER_XVFB) message(STATUS "Check virtual framebuffer - done") else() message(STATUS - "Check virtual framebuffer - faild\n" - "Please install the xorg-x11-proto-devel or x11proto-dev package\n") + "Check virtual framebuffer - faild\n" + "Please install the xorg-x11-proto-devel or x11proto-dev package\n") endif() endif() set(HAVE_FRAMEBUFFER ON) From 2b99518631e046ad864f29e42b5e8f93640e9b82 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 24 Jun 2024 17:25:59 +0300 Subject: [PATCH 80/81] fixed work with framebuffer in cmake --- CMakeLists.txt | 8 +++--- modules/highgui/CMakeLists.txt | 6 +++-- .../highgui/cmake/detect_framebuffer.cmake | 25 ++++++++----------- modules/highgui/cmake/init.cmake | 7 +----- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index badc01770914..b0df5b967940 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1453,12 +1453,10 @@ if(WITH_GTK OR HAVE_GTK) endif() endif() -if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB OR HAVE_FRAMEBUFFER_XVFB) - if(HAVE_FRAMEBUFFER OR HAVE_FRAMEBUFFER_XVFB) - status(" Framebuffer UI:" HAVE_FRAMEBUFFER THEN YES ELSE NO) +if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER) + status(" Framebuffer UI:" HAVE_FRAMEBUFFER THEN YES ELSE NO) + if(WITH_FRAMEBUFFER_XVFB OR HAVE_FRAMEBUFFER_XVFB) status(" Virtual framebuffer UI:" HAVE_FRAMEBUFFER_XVFB THEN YES ELSE NO) - else() - status(" Framebuffer UI:" "NO") endif() endif() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 086264570799..f73bdd2f2604 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -49,10 +49,12 @@ list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${n set(OPENCV_HIGHGUI_BUILTIN_BACKEND "") -if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) +if(WITH_FRAMEBUFFER) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") - if(HAVE_FRAMEBUFFER_XVFB) + if(WITH_FRAMEBUFFER_XVFB) + if(HAVE_FRAMEBUFFER_XVFB) add_definitions(-DHAVE_FRAMEBUFFER_XVFB) + endif() endif() if(HAVE_FRAMEBUFFER) add_definitions(-DHAVE_FRAMEBUFFER) diff --git a/modules/highgui/cmake/detect_framebuffer.cmake b/modules/highgui/cmake/detect_framebuffer.cmake index 3a7959a1c58b..86fd6a03edce 100644 --- a/modules/highgui/cmake/detect_framebuffer.cmake +++ b/modules/highgui/cmake/detect_framebuffer.cmake @@ -1,17 +1,14 @@ # --- FB --- -ocv_clear_vars(HAVE_FRAMEBUFFER HAVE_FRAMEBUFFER_XVFB) -if(WITH_FRAMEBUFFER OR WITH_FRAMEBUFFER_XVFB) - if(WITH_FRAMEBUFFER_XVFB) - try_compile(HAVE_FRAMEBUFFER_XVFB - "${CMAKE_CURRENT_BINARY_DIR}" - "${OpenCV_SOURCE_DIR}/cmake/checks/framebuffer.cpp") - if(HAVE_FRAMEBUFFER_XVFB) - message(STATUS "Check virtual framebuffer - done") - else() - message(STATUS - "Check virtual framebuffer - faild\n" - "Please install the xorg-x11-proto-devel or x11proto-dev package\n") - endif() +set(HAVE_FRAMEBUFFER ON) +if(WITH_FRAMEBUFFER_XVFB) + try_compile(HAVE_FRAMEBUFFER_XVFB + "${CMAKE_CURRENT_BINARY_DIR}" + "${OpenCV_SOURCE_DIR}/cmake/checks/framebuffer.cpp") + if(HAVE_FRAMEBUFFER_XVFB) + message(STATUS "Check virtual framebuffer - done") + else() + message(STATUS + "Check virtual framebuffer - faild\n" + "Please install the xorg-x11-proto-devel or x11proto-dev package\n") endif() - set(HAVE_FRAMEBUFFER ON) endif() diff --git a/modules/highgui/cmake/init.cmake b/modules/highgui/cmake/init.cmake index 1af5bd3a48e6..f52ce2a4a8e3 100644 --- a/modules/highgui/cmake/init.cmake +++ b/modules/highgui/cmake/init.cmake @@ -39,12 +39,7 @@ endmacro() add_backend("gtk" WITH_GTK) add_backend("win32ui" WITH_WIN32UI) add_backend("wayland" WITH_WAYLAND) -if(WITH_FRAMEBUFFER AND WITH_FRAMEBUFFER_XVFB) - add_backend("framebuffer" WITH_FRAMEBUFFER) -else() - add_backend("framebuffer" WITH_FRAMEBUFFER) - add_backend("framebuffer" WITH_FRAMEBUFFER_XVFB) -endif() +add_backend("framebuffer" WITH_FRAMEBUFFER) # TODO cocoa # TODO qt From 6bf5fcfd409b7105ffed96c9c1051cdd9250a7a2 Mon Sep 17 00:00:00 2001 From: "kozinov.e" Date: Mon, 24 Jun 2024 20:05:57 +0300 Subject: [PATCH 81/81] review comments have been corrected --- modules/highgui/CMakeLists.txt | 16 ++++++---------- modules/highgui/cmake/detect_framebuffer.cmake | 2 +- modules/highgui/src/window_framebuffer.cpp | 4 +--- modules/highgui/test/test_gui.cpp | 6 ++---- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index f73bdd2f2604..0108626dfde0 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -49,17 +49,13 @@ list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${n set(OPENCV_HIGHGUI_BUILTIN_BACKEND "") -if(WITH_FRAMEBUFFER) +if(WITH_FRAMEBUFFER AND HAVE_FRAMEBUFFER) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "FB") - if(WITH_FRAMEBUFFER_XVFB) - if(HAVE_FRAMEBUFFER_XVFB) - add_definitions(-DHAVE_FRAMEBUFFER_XVFB) - endif() - endif() - if(HAVE_FRAMEBUFFER) - add_definitions(-DHAVE_FRAMEBUFFER) - list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) - list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + add_definitions(-DHAVE_FRAMEBUFFER) + list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.cpp) + list(APPEND highgui_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/window_framebuffer.hpp) + if(HAVE_FRAMEBUFFER_XVFB) + add_definitions(-DHAVE_FRAMEBUFFER_XVFB) endif() endif() diff --git a/modules/highgui/cmake/detect_framebuffer.cmake b/modules/highgui/cmake/detect_framebuffer.cmake index 86fd6a03edce..8e292f72acab 100644 --- a/modules/highgui/cmake/detect_framebuffer.cmake +++ b/modules/highgui/cmake/detect_framebuffer.cmake @@ -8,7 +8,7 @@ if(WITH_FRAMEBUFFER_XVFB) message(STATUS "Check virtual framebuffer - done") else() message(STATUS - "Check virtual framebuffer - faild\n" + "Check virtual framebuffer - failed\n" "Please install the xorg-x11-proto-devel or x11proto-dev package\n") endif() endif() diff --git a/modules/highgui/src/window_framebuffer.cpp b/modules/highgui/src/window_framebuffer.cpp index a3a22bfc2658..687bf9172411 100644 --- a/modules/highgui/src/window_framebuffer.cpp +++ b/modules/highgui/src/window_framebuffer.cpp @@ -129,9 +129,7 @@ void FramebufferWindow::imshow(InputArray image) } break; default: - CV_LOG_ERROR(NULL, "UI: imshow can't convert image to show"); - CV_Assert(img.channels() < 1); - CV_Assert(img.channels() > 4); + CV_Error(cv::Error::StsBadArg, "Bad image: wrong number of channels"); } { Mat bgra(img.rows, img.cols, CV_8UC4); diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index 13c64451242a..b8093e07ecec 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -149,8 +149,7 @@ static void Foo(int, void* counter) && !defined HAVE_WAYLAND \ ) \ || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ - || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ \ - || defined HAVE_FRAMEBUFFER_XVFB /* trackbar is not supported */ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar_unsafe) #else TEST(Highgui_GUI, trackbar_unsafe) @@ -191,8 +190,7 @@ void testTrackbarCallback(int pos, void* param) && !defined HAVE_WAYLAND \ ) \ || defined(__APPLE__) /* test fails on Mac (cocoa) */ \ - || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ \ - || defined HAVE_FRAMEBUFFER_XVFB /* trackbar is not supported */ + || defined HAVE_FRAMEBUFFER /* trackbar is not supported */ TEST(Highgui_GUI, DISABLED_trackbar) #else TEST(Highgui_GUI, trackbar)