From e8f83186825966232900cf7c70ac88134cbdf0cd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 7 May 2017 08:10:03 +0200 Subject: pose-widget: projected pixel overflow isn'n an issue --- pose-widget/pose-widget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pose-widget') diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index b511f4c5..c3e87dff 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -270,8 +270,8 @@ void pose_transform::project_quad_texture() return; } - for (int y = 1; y < sy; y++) - for (int x = 1; x < sx; x++) + for (int y = 0; y < sy; y++) + for (int x = 0; x < sx; x++) { vec2 pos(x, y); vec2 uv; -- cgit v1.2.3 From 1d3fa41e12c9f17f184084f734fe78a4f1468b60 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 7 May 2017 19:21:49 +0200 Subject: pose-widget: add empty space to prevent out-out-bounds writes --- pose-widget/pose-widget.cpp | 33 ++++++++++++++++++--------------- pose-widget/pose-widget.hpp | 2 -- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'pose-widget') diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index c3e87dff..54278c34 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -18,11 +18,12 @@ using namespace pose_widget_impl; +static constexpr int offset = 2; + pose_transform::pose_transform(QWidget* dst) : dst(dst), - image(w, h, QImage::Format_ARGB32), - image2(w, h, QImage::Format_ARGB32), - width(w), height(h), + image(w+offset*2, h+offset*2, QImage::Format_ARGB32), + image2(w+offset*2, h+offset*2, QImage::Format_ARGB32), fresh(false) { front = QImage(QString(":/images/side1.png")); @@ -43,8 +44,10 @@ pose_transform::~pose_transform() void pose_widget::paintEvent(QPaintEvent* event) { QPainter p(this); - xform.with_image_lock([&](const QImage& image) { - p.drawImage(event->rect(), image); + + xform.with_image_lock([&](const QImage& image) + { + p.drawImage(event->rect(), image, offset, offset); }); } @@ -186,7 +189,7 @@ void pose_transform::project_quad_texture() num dir; vec2 pt[4]; - const int sx = width - 1, sy = height - 1; + const int sx = w - 1, sy = h - 1; vec2 projected[3]; { @@ -252,7 +255,7 @@ void pose_transform::project_quad_texture() const unsigned dest_pitch = image.bytesPerLine(); const unsigned char* orig = tex.bits(); - unsigned char* dest = image.bits(); + unsigned char* dest = image.bits() + offset*dest_pitch; const int orig_depth = tex.depth() / 8; const int dest_depth = image.depth() / 8; @@ -309,7 +312,7 @@ void pose_transform::project_quad_texture() const float ax = 1 - ax_; const float ay = 1 - ay_; - const unsigned pos = y * dest_pitch + x * dest_depth; + const unsigned pos = y * dest_pitch + (x+offset) * dest_depth; for (int k = 0; k < 4; k++) { @@ -336,13 +339,13 @@ vec2 pose_transform::project(const vec3 &point) vec3 ret = rotation * point; num z = std::fmax(num(.5), 1 + translation.z()/-80); - num w = width, h = height; - num x = w * translation.x() / 2 / -80; - if (fabs(x) > w/2) - x = x > 0 ? w/2 : w/-2; - num y = h * translation.y() / 2 / -80; - if (fabs(y) > h/2) - y = y > 0 ? h/2 : h/-2; + num w_ = w, h_ = h; + num x = w_ * translation.x() / 2 / -80; + if (fabs(x) > w_/2) + x = x > 0 ? w_/2 : w_/-2; + num y = h_ * translation.y() / 2 / -80; + if (fabs(y) > h_/2) + y = y > 0 ? h_/2 : h_/-2; return vec2(z * (ret.x() + x), z * (ret.y() + y)); } diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp index b528d394..1d34778a 100644 --- a/pose-widget/pose-widget.hpp +++ b/pose-widget/pose-widget.hpp @@ -69,8 +69,6 @@ class pose_transform final : private QThread QImage front, back; QImage image, image2; - int width, height; - std::atomic fresh; static constexpr int w = 320, h = 240; -- cgit v1.2.3 From 4c4c783d023cf1bb6a8d7d883bf8d3384f7b7da1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 12 May 2017 15:43:50 +0200 Subject: minor fixes only --- dinput/keybinding-worker.cpp | 5 +++-- options/connector.cpp | 7 ++++--- options/group.cpp | 4 +++- options/scoped.cpp | 2 +- pose-widget/pose-widget.cpp | 4 ++-- pose-widget/pose-widget.hpp | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) (limited to 'pose-widget') diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp index b94b762e..0e16ac71 100644 --- a/dinput/keybinding-worker.cpp +++ b/dinput/keybinding-worker.cpp @@ -9,6 +9,7 @@ #ifdef _WIN32 #include "keybinding-worker.hpp" +#include "compat/util.hpp" #include #include #include @@ -18,8 +19,8 @@ bool Key::should_process() { if (!enabled || (keycode == 0 && guid == "")) return false; - bool ret = !held || timer.elapsed_ms() > 100; - timer.start(); + bool ret = prog1(!held || timer.elapsed_ms() > 100, + timer.start()); return ret; } diff --git a/options/connector.cpp b/options/connector.cpp index 63d70ca7..075a57e1 100644 --- a/options/connector.cpp +++ b/options/connector.cpp @@ -83,11 +83,12 @@ void connector::on_value_created(const QString& name, value_type val) QMutexLocker l(get_mtx()); - if (on_value_destructed_impl(name, val)) + int i = 1; + while (on_value_destructed_impl(name, val)) { qWarning() << "options/connector: value created twice;" - << "bundle" - << val->b->name() + << "cnt" << i++ + << "bundle" << val->b->name() << "value-name" << name << "value-ptr" << quintptr(val); } diff --git a/options/group.cpp b/options/group.cpp index 3f800ff0..60e8a7b4 100644 --- a/options/group.cpp +++ b/options/group.cpp @@ -30,7 +30,9 @@ group::group(const QString& name) : name(name) { auto tmp = k_.toUtf8(); QString k(tmp); - kvs[k] = conf.value(k_); + QVariant val = conf.value(k_); + if (val.type() != QVariant::Invalid) + kvs[k] = std::move(val); } conf.endGroup(); }); diff --git a/options/scoped.cpp b/options/scoped.cpp index 96f4a261..58a4ee02 100644 --- a/options/scoped.cpp +++ b/options/scoped.cpp @@ -2,8 +2,8 @@ #include #include -// for std::abort() #include +#include #include diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 54278c34..8646df30 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -47,7 +47,7 @@ void pose_widget::paintEvent(QPaintEvent* event) xform.with_image_lock([&](const QImage& image) { - p.drawImage(event->rect(), image, offset, offset); + p.drawImage(event->rect(), image, QRect(offset, offset, pose_transform::w, pose_transform::h)); }); } @@ -71,7 +71,7 @@ void pose_transform::run() project_quad_texture(); end: - portable::sleep(9); + portable::sleep(23); } } diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp index 1d34778a..a27bf4b9 100644 --- a/pose-widget/pose-widget.hpp +++ b/pose-widget/pose-widget.hpp @@ -37,7 +37,7 @@ using lock_guard = std::unique_lock; class pose_widget; -class pose_transform final : private QThread +struct pose_transform final : private QThread { pose_transform(QWidget* dst); ~pose_transform(); -- cgit v1.2.3