diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-07 19:21:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-10 11:19:22 +0200 |
commit | 1d3fa41e12c9f17f184084f734fe78a4f1468b60 (patch) | |
tree | 1c07b6c90ee3351adc66738540304fc9ced464c6 /pose-widget | |
parent | c114e085b3bb51da51c4a7ecceda146e095c7a2e (diff) |
pose-widget: add empty space to prevent out-out-bounds writes
Diffstat (limited to 'pose-widget')
-rw-r--r-- | pose-widget/pose-widget.cpp | 33 | ||||
-rw-r--r-- | pose-widget/pose-widget.hpp | 2 |
2 files changed, 18 insertions, 17 deletions
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<bool> fresh; static constexpr int w = 320, h = 240; |