Skip to content
Snippets Groups Projects
Commit 34f848b1 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow for multi screen in screen capture

parent da8500bf
No related branches found
No related tags found
No related merge requests found
Pipeline #19997 passed
...@@ -65,8 +65,16 @@ enum struct definition_t : uint8_t { ...@@ -65,8 +65,16 @@ enum struct definition_t : uint8_t {
Invalid Invalid
}; };
/**
* Find exact match definition.
*/
definition_t findDefinition(int width, int height); definition_t findDefinition(int width, int height);
/**
* Find a definition that matches the requested height.
*/
definition_t findDefinition(int height);
/** /**
* Get width in pixels of definition. * Get width in pixels of definition.
*/ */
......
...@@ -47,3 +47,16 @@ definition_t ftl::codecs::findDefinition(int width, int height) { ...@@ -47,3 +47,16 @@ definition_t ftl::codecs::findDefinition(int width, int height) {
return definition_t::Invalid; return definition_t::Invalid;
} }
definition_t ftl::codecs::findDefinition(int height) {
int best = 0;
for(const Resolution res : resolutions) {
if (res.height == height) {
return static_cast<definition_t>(best);
}
best++;
}
return definition_t::Invalid;
}
...@@ -61,8 +61,16 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host) ...@@ -61,8 +61,16 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host)
} }
s.screen = s.window_attributes.screen; s.screen = s.window_attributes.screen;
params_.width = s.window_attributes.width; full_width_ = s.window_attributes.width;
params_.height = s.window_attributes.height; full_height_ = s.window_attributes.height;
offset_x_ = host_->value("offset_x",0);
offset_y_ = host_->value("offset_y",0);
// Choose a correct aspect ratio
int awidth = ftl::codecs::getWidth(ftl::codecs::findDefinition(full_height_));
params_.width = awidth;
params_.height = full_height_;
s.ximg = XShmCreateImage(s.display, DefaultVisualOfScreen(s.screen), s.ximg = XShmCreateImage(s.display, DefaultVisualOfScreen(s.screen),
DefaultDepthOfScreen(s.screen), ZPixmap, NULL, &s.shminfo, DefaultDepthOfScreen(s.screen), ZPixmap, NULL, &s.shminfo,
...@@ -110,6 +118,13 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host) ...@@ -110,6 +118,13 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host)
state_.getLeft() = params_; state_.getLeft() = params_;
}); });
host_->on("offset_x", [this](const ftl::config::Event &e) {
offset_x_ = host_->value("offset_x", 0);
});
host_->on("offset_y", [this](const ftl::config::Event &e) {
offset_y_ = host_->value("offset_y", 0);
});
} }
ScreenCapture::~ScreenCapture() { ScreenCapture::~ScreenCapture() {
...@@ -130,7 +145,7 @@ bool ScreenCapture::compute(int n, int b) { ...@@ -130,7 +145,7 @@ bool ScreenCapture::compute(int n, int b) {
cv::Mat img; cv::Mat img;
#ifdef HAVE_X11 #ifdef HAVE_X11
XShmGetImage(impl_state_->display, impl_state_->root, impl_state_->ximg, 0, 0, 0x00ffffff); XShmGetImage(impl_state_->display, impl_state_->root, impl_state_->ximg, getOffsetX(), getOffsetY(), 0x00ffffff);
img = cv::Mat(params_.height, params_.width, CV_8UC4, impl_state_->ximg->data); img = cv::Mat(params_.height, params_.width, CV_8UC4, impl_state_->ximg->data);
#endif #endif
......
...@@ -28,12 +28,20 @@ class ScreenCapture : public ftl::rgbd::detail::Source { ...@@ -28,12 +28,20 @@ class ScreenCapture : public ftl::rgbd::detail::Source {
bool compute(int n=-1, int b=-1); bool compute(int n=-1, int b=-1);
bool isReady(); bool isReady();
int getOffsetX() const { return (offset_x_ > full_width_-params_.width) ? full_width_-params_.width : offset_x_; }
int getOffsetY() const { return (offset_y_ > full_height_-params_.height) ? full_height_-params_.height : offset_y_; }
private: private:
bool ready_; bool ready_;
int64_t cap_ts_; int64_t cap_ts_;
int64_t cur_ts_; int64_t cur_ts_;
ftl::rgbd::Frame sframe_; ftl::rgbd::Frame sframe_;
int full_width_;
int full_height_;
int offset_x_;
int offset_y_;
ImplState *impl_state_; ImplState *impl_state_;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment