summaryrefslogtreecommitdiffhomepage
path: root/pose-widget
diff options
context:
space:
mode:
Diffstat (limited to 'pose-widget')
-rw-r--r--pose-widget/images/side1.pngbin540324 -> 35513 bytes
-rw-r--r--pose-widget/images/side6.pngbin543073 -> 35720 bytes
-rw-r--r--pose-widget/pose-widget.cpp80
-rw-r--r--pose-widget/pose-widget.hpp24
4 files changed, 38 insertions, 66 deletions
diff --git a/pose-widget/images/side1.png b/pose-widget/images/side1.png
index d15c3658..2955bc01 100644
--- a/pose-widget/images/side1.png
+++ b/pose-widget/images/side1.png
Binary files differ
diff --git a/pose-widget/images/side6.png b/pose-widget/images/side6.png
index 7338690d..3bae0e50 100644
--- a/pose-widget/images/side6.png
+++ b/pose-widget/images/side6.png
Binary files differ
diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp
index 12de49d3..943fc0ad 100644
--- a/pose-widget/pose-widget.cpp
+++ b/pose-widget/pose-widget.cpp
@@ -22,16 +22,13 @@
// XXX this needs rewriting in terms of scanline rendering -sh 20180105
// see: <https://mikro.naprvyraz.sk/docs/Coding/2/TEXTURE4.TXT>
-using namespace pose_widget_impl;
-
-pose_transform::pose_transform(QWidget* dst) :
- dst(dst),
- front(":/images/side1.png", nullptr),
- back(":/images/side6.png", nullptr),
- image(w, h, QImage::Format_ARGB32),
- image2(w, h, QImage::Format_ARGB32),
- fresh(false)
+namespace pose_widget_impl {
+
+pose_transform::pose_transform(QWidget* dst, double dpr) : dst(dst)
{
+ for (QImage* img : { &image, &image2, &front, &back })
+ img->setDevicePixelRatio(dpr);
+
image.fill(Qt::transparent);
image2.fill(Qt::transparent);
}
@@ -79,7 +76,7 @@ end:
}
}
-pose_widget::pose_widget(QWidget* parent) : QWidget(parent), xform(this)
+pose_widget::pose_widget(QWidget* parent) : QWidget(parent), xform{this, devicePixelRatioF()}
{
rotate_sync(0,0,0, 0,0,0);
}
@@ -182,7 +179,7 @@ bool Triangle::barycentric_coords(const vec2& px, vec2& uv, int& i) const
std::pair<vec2i, vec2i> pose_transform::get_bounds(const vec2& size)
{
- const int x = size.x(), y = size.y();
+ const num x = size.x(), y = size.y();
const vec3 corners[] = {
{ -x, -y, 0 },
@@ -193,7 +190,7 @@ std::pair<vec2i, vec2i> pose_transform::get_bounds(const vec2& size)
vec2 min(w-1, h-1), max(0, 0);
- for (unsigned k = 0; k < 4; k++)
+ for (unsigned k = 0; k < 4; k++) // NOLINT(modernize-loop-convert)
{
const vec2 pt = project(corners[k]) + vec2(w/2, h/2);
@@ -275,17 +272,15 @@ void pose_transform::project_quad_texture()
const QImage& tex = dir < 0 ? back : front;
- Triangle t(pt[0], pt[1], pt[2]);
-
- const unsigned orig_pitch = tex.bytesPerLine();
- const unsigned dest_pitch = image.bytesPerLine();
+ const unsigned orig_pitch = (unsigned)tex.bytesPerLine();
+ const unsigned dest_pitch = (unsigned)image.bytesPerLine();
unsigned char const* __restrict orig = tex.constBits();
unsigned char* __restrict dest = image.bits();
const int orig_depth = tex.depth() / 8;
const int dest_depth = image.depth() / 8;
- constexpr int const_depth = 4;
+ constexpr unsigned const_depth = 4;
if (unlikely(orig_depth != const_depth || dest_depth != const_depth))
{
@@ -294,10 +289,13 @@ void pose_transform::project_quad_texture()
return;
}
+ Triangle t(pt[0], pt[1], pt[2]);
+
const vec2u dist(max.x() - min.x(), max.y() - min.y());
+ unsigned len = (unsigned)(dist.x() * dist.y());
- if (int(uv_vec.size()) < dist.x() * dist.y())
- uv_vec.resize(dist.x() * dist.y());
+ if (uv_vec.size() < len)
+ uv_vec.resize(len);
for (int y = 0; y < dist.y(); y++)
for (int x = 0; x < dist.x(); x++)
@@ -337,42 +335,14 @@ void pose_transform::project_quad_texture()
vec2 const& uv = uv__->coords;
int const i = uv__->i;
- float fx = origs[i][0].x()
- + uv.x() * origs[i][2].x()
- + uv.y() * origs[i][1].x();
- float fy = origs[i][0].y()
- + uv.x() * origs[i][2].y()
- + uv.y() * origs[i][1].y();
-
-//#define BILINEAR_FILTER
-
-#if defined BILINEAR_FILTER
- const unsigned px_ = fx + 1;
- const unsigned py_ = fy + 1;
-#endif
- const unsigned px = fx;
- const unsigned py = fy;
+ unsigned px = (unsigned)(origs[i][0].x() +
+ uv.x() * origs[i][2].x() +
+ uv.y() * origs[i][1].x());
+ unsigned py = (unsigned)(origs[i][0].y() +
+ uv.x() * origs[i][2].y() +
+ uv.y() * origs[i][1].y());
const unsigned orig_pos = py * orig_pitch + px * const_depth;
-#if defined BILINEAR_FILTER
- const unsigned orig_pos_ = py_ * orig_pitch + px_ * const_depth;
- const unsigned orig_pos__ = py * orig_pitch + px_ * const_depth;
- const unsigned orig_pos___ = py_ * orig_pitch + px * const_depth;
-#endif
-
- // 1, 0 -- ax_, ay
- // 0, 1 -- ax, ay_
- // 1, 1 -- ax_, ay_
- // 0, 0 -- ax, ay
- //const uc alpha = (a1 * ax + a3 * ax_) * ay + (a4 * ax + a2 * ax_) * ay_;
-
-#if defined BILINEAR_FILTER
- const float ax_ = fx - unsigned(fx);
- const float ay_ = fy - unsigned(fy);
- const float ax = 1 - ax_;
- const float ay = 1 - ay_;
-#endif
-
const unsigned pos = y * dest_pitch + x * const_depth;
if (orig[orig_pos + 3] == uc(255)) // alpha
@@ -380,7 +350,7 @@ void pose_transform::project_quad_texture()
dest[pos + k] = orig[orig_pos + k];
else
for (int k = 0; k < 3; k++)
- dest[pos + k] = bgcolor(k);
+ dest[pos + k] = (unsigned char)bgcolor(k);
}
}
}
@@ -421,3 +391,5 @@ inline void pose_transform::with_image_lock(F&& fun)
fun(image2);
}
+
+} // ns pose_widget_impl
diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp
index fa956b47..aa51957e 100644
--- a/pose-widget/pose-widget.hpp
+++ b/pose-widget/pose-widget.hpp
@@ -47,8 +47,8 @@ public:
struct pose_transform final : QThread
{
- pose_transform(QWidget* dst);
- ~pose_transform();
+ pose_transform(QWidget* dst, double device_pixel_ratio);
+ ~pose_transform() override;
void rotate_async(double xAngle, double yAngle, double zAngle, double x, double y, double z);
void rotate_sync(double xAngle, double yAngle, double zAngle, double x, double y, double z);
@@ -63,8 +63,7 @@ struct pose_transform final : QThread
void project_quad_texture();
std::pair<vec2i, vec2i> get_bounds(const vec2& size);
- template<typename F>
- inline void with_image_lock(F&& fun);
+ template<typename F> inline void with_image_lock(F&& fun);
rmat rotation, rotation_;
vec3 translation, translation_;
@@ -73,27 +72,28 @@ struct pose_transform final : QThread
QWidget* dst;
- QImage front, back;
- QImage image, image2;
+ QImage front{QImage{":/images/side1.png"}.convertToFormat(QImage::Format_ARGB32)};
+ QImage back{QImage{":/images/side6.png"}.convertToFormat(QImage::Format_ARGB32)};
+ QImage image{w, h, QImage::Format_ARGB32};
+ QImage image2{w, h, QImage::Format_ARGB32};
- struct uv_
+ struct uv_ // NOLINT(cppcoreguidelines-pro-type-member-init)
{
vec2 coords;
int i;
};
std::vector<uv_> uv_vec;
+ std::atomic<bool> fresh{false};
- std::atomic<bool> fresh;
-
- static constexpr inline int w = 320, h = 240;
+ static constexpr int w = 320, h = 240;
};
class OTR_POSE_WIDGET_EXPORT pose_widget final : public QWidget
{
public:
pose_widget(QWidget *parent = nullptr);
- ~pose_widget();
+ ~pose_widget() override;
void rotate_async(double xAngle, double yAngle, double zAngle, double x, double y, double z);
void rotate_sync(double xAngle, double yAngle, double zAngle, double x, double y, double z);
@@ -104,4 +104,4 @@ private:
}
-using pose_widget_impl::pose_widget;
+using pose_widget = pose_widget_impl::pose_widget;