Commit 5a1540b12795f22b87b2f6ff8df6136e6dc3686e
1 parent
8db62b7d
Fixed expand rect code
Showing
1 changed file
with
11 additions
and
22 deletions
openbr/plugins/metadata/expandrect.cpp
| @@ -23,6 +23,7 @@ namespace br | @@ -23,6 +23,7 @@ namespace br | ||
| 23 | * \ingroup transforms | 23 | * \ingroup transforms |
| 24 | * \brief Expand the width and height of a Template's rects by input width and height factors. | 24 | * \brief Expand the width and height of a Template's rects by input width and height factors. |
| 25 | * \author Charles Otto \cite caotto | 25 | * \author Charles Otto \cite caotto |
| 26 | + * \author Brendan Klare \cite bklare | ||
| 26 | */ | 27 | */ |
| 27 | class ExpandRectTransform : public UntrainableTransform | 28 | class ExpandRectTransform : public UntrainableTransform |
| 28 | { | 29 | { |
| @@ -31,35 +32,23 @@ class ExpandRectTransform : public UntrainableTransform | @@ -31,35 +32,23 @@ class ExpandRectTransform : public UntrainableTransform | ||
| 31 | Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false) | 32 | Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false) |
| 32 | BR_PROPERTY(float, widthExpand, .5) | 33 | BR_PROPERTY(float, widthExpand, .5) |
| 33 | BR_PROPERTY(float, heightExpand, .5) | 34 | BR_PROPERTY(float, heightExpand, .5) |
| 35 | + | ||
| 34 | void project(const Template &src, Template &dst) const | 36 | void project(const Template &src, Template &dst) const |
| 35 | { | 37 | { |
| 36 | dst = src; | 38 | dst = src; |
| 37 | - QList<QRectF> rects = dst.file.rects(); | 39 | + dst.file.clearRects(); |
| 40 | + QList<QRectF> rects = src.file.rects(); | ||
| 38 | for (int i=0;i < rects.size(); i++) { | 41 | for (int i=0;i < rects.size(); i++) { |
| 39 | - QRectF rect = rects[i]; | ||
| 40 | - | ||
| 41 | - qreal width = rect.width(); | ||
| 42 | - qreal height = rect.height(); | ||
| 43 | - float half_w_expansion = widthExpand / 2; | ||
| 44 | - float half_h_expansion = heightExpand / 2; | ||
| 45 | - | ||
| 46 | - qreal half_width = width * widthExpand; | ||
| 47 | - qreal quarter_width = width * half_w_expansion; | ||
| 48 | - qreal half_height = height * heightExpand; | ||
| 49 | - qreal quarter_height = height * half_h_expansion; | ||
| 50 | - | ||
| 51 | - rect.setX(std::max(qreal(0),(rect.x() - quarter_width))); | ||
| 52 | - rect.setY(std::max(qreal(0),(rect.y() - quarter_height))); | ||
| 53 | - | ||
| 54 | - qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1); | ||
| 55 | - qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1); | 42 | + qreal widthGrowth = rects[i].width() * widthExpand; |
| 43 | + qreal heightGrowth = rects[i].height() * heightExpand; | ||
| 56 | 44 | ||
| 57 | - rect.setWidth(x2 - rect.x()); | ||
| 58 | - rect.setHeight(y2 - rect.y()); | 45 | + qreal x = std::max(qreal(0), rects[i].x() - widthGrowth / 2.); |
| 46 | + qreal y = std::max(qreal(0), rects[i].y() - heightGrowth / 2.); | ||
| 47 | + dst.file.appendRect(QRectF(x, y, | ||
| 48 | + std::min(src.m().cols - x - 1, rects[i].width() + widthGrowth), | ||
| 49 | + std::min(src.m().rows - y - 1, rects[i].height() + heightGrowth))); | ||
| 59 | 50 | ||
| 60 | - rects[i] = rect; | ||
| 61 | } | 51 | } |
| 62 | - dst.file.setRects(rects); | ||
| 63 | } | 52 | } |
| 64 | }; | 53 | }; |
| 65 | 54 |