diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-07 14:37:16 +0100 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-16 07:48:48 +0100 | 
| commit | 91077b3e171e1aaeb4f8ef11dabab5a424928d86 (patch) | |
| tree | de76e447cf94c6e7f9bccd10661ea4d2ef809acf | |
| parent | eee37419cb05c698d02beecc66e85a3ec0ec5fb1 (diff) | |
pose-widget: handle octopus in 8-bit color w/ 1-bit alpha
| -rw-r--r-- | pose-widget/images/side1.png | bin | 540324 -> 35513 bytes | |||
| -rw-r--r-- | pose-widget/images/side6.png | bin | 543073 -> 35720 bytes | |||
| -rw-r--r-- | pose-widget/pose-widget.cpp | 57 | 
3 files changed, 15 insertions, 42 deletions
| diff --git a/pose-widget/images/side1.png b/pose-widget/images/side1.pngBinary files differ index d15c3658..2955bc01 100644 --- a/pose-widget/images/side1.png +++ b/pose-widget/images/side1.png diff --git a/pose-widget/images/side6.png b/pose-widget/images/side6.pngBinary files differ index 7338690d..3bae0e50 100644 --- a/pose-widget/images/side6.png +++ b/pose-widget/images/side6.png diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index d9b563e9..9a097340 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -26,8 +26,8 @@ using namespace pose_widget_impl;  pose_transform::pose_transform(QWidget* dst) :      dst(dst), -    front(":/images/side1.png", nullptr), -    back(":/images/side6.png", nullptr), +    front(QImage{":/images/side1.png"}.convertToFormat(QImage::Format_ARGB32)), +    back(QImage{":/images/side6.png"}.convertToFormat(QImage::Format_ARGB32)),      image(w, h, QImage::Format_ARGB32),      image2(w, h, QImage::Format_ARGB32),      fresh(false) @@ -193,7 +193,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,8 +275,6 @@ 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 = (unsigned)tex.bytesPerLine();      const unsigned dest_pitch = (unsigned)image.bytesPerLine(); @@ -285,7 +283,7 @@ void pose_transform::project_quad_texture()      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 +292,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 +338,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 = (unsigned)fx; -                const unsigned py = (unsigned)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 | 
