diff --git a/components/codecs/include/ftl/codecs/codecs.hpp b/components/codecs/include/ftl/codecs/codecs.hpp index 8ff9705db85c7678140e9b03a42b9349d53d74e3..49097ba929975be25432c1a43c2155fe5d7b16ac 100644 --- a/components/codecs/include/ftl/codecs/codecs.hpp +++ b/components/codecs/include/ftl/codecs/codecs.hpp @@ -65,8 +65,16 @@ enum struct definition_t : uint8_t { Invalid }; +/** + * Find exact match definition. + */ 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. */ diff --git a/components/codecs/src/bitrates.cpp b/components/codecs/src/bitrates.cpp index 5781c4f5f80c3a6452214f3d7a7c86608893c9bc..4d5fe63f3ccadbd93eb24e511d1c77c484dc2224 100644 --- a/components/codecs/src/bitrates.cpp +++ b/components/codecs/src/bitrates.cpp @@ -47,3 +47,16 @@ definition_t ftl::codecs::findDefinition(int width, int height) { 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; +} + diff --git a/components/rgbd-sources/src/sources/screencapture/screencapture.cpp b/components/rgbd-sources/src/sources/screencapture/screencapture.cpp index 5fb014344f9fca55ec7312ec323fa5d653353ffe..ef3e3badca05fabc7beda76d73c4042a9151e7cc 100644 --- a/components/rgbd-sources/src/sources/screencapture/screencapture.cpp +++ b/components/rgbd-sources/src/sources/screencapture/screencapture.cpp @@ -61,8 +61,16 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host) } s.screen = s.window_attributes.screen; - params_.width = s.window_attributes.width; - params_.height = s.window_attributes.height; + full_width_ = s.window_attributes.width; + 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), DefaultDepthOfScreen(s.screen), ZPixmap, NULL, &s.shminfo, @@ -110,6 +118,13 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host) 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() { @@ -130,7 +145,7 @@ bool ScreenCapture::compute(int n, int b) { cv::Mat img; #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); #endif diff --git a/components/rgbd-sources/src/sources/screencapture/screencapture.hpp b/components/rgbd-sources/src/sources/screencapture/screencapture.hpp index 4c8ee78c4f4f05f2674fd05b6f64ed6d08c2d36c..a6f19f4f56afaebe4d659cbeb1550a40bfb2de38 100644 --- a/components/rgbd-sources/src/sources/screencapture/screencapture.hpp +++ b/components/rgbd-sources/src/sources/screencapture/screencapture.hpp @@ -28,12 +28,20 @@ class ScreenCapture : public ftl::rgbd::detail::Source { bool compute(int n=-1, int b=-1); 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: bool ready_; int64_t cap_ts_; int64_t cur_ts_; ftl::rgbd::Frame sframe_; + int full_width_; + int full_height_; + int offset_x_; + int offset_y_; + ImplState *impl_state_; };