Commit 28a1f405624cb7b4e733e9b113c73b1e7da85602

Authored by bhklein
1 parent ca08ce35

preserve aspect and don't pad

openbr/plugins/imgproc/resize.cpp
... ... @@ -48,13 +48,20 @@ private:
48 48 Q_PROPERTY(int columns READ get_columns WRITE set_columns RESET reset_columns STORED false)
49 49 Q_PROPERTY(Method method READ get_method WRITE set_method RESET reset_method STORED false)
50 50 Q_PROPERTY(bool preserveAspect READ get_preserveAspect WRITE set_preserveAspect RESET reset_preserveAspect STORED false)
  51 + Q_PROPERTY(bool pad READ get_pad WRITE set_pad RESET reset_pad STORED false)
51 52 BR_PROPERTY(int, rows, -1)
52 53 BR_PROPERTY(int, columns, -1)
53 54 BR_PROPERTY(Method, method, Bilin)
54 55 BR_PROPERTY(bool, preserveAspect, false)
  56 + BR_PROPERTY(bool, pad, true)
55 57  
56 58 void project(const Template &src, Template &dst) const
57 59 {
  60 + if ((rows == -1) && (columns == -1)) {
  61 + dst = src;
  62 + return;
  63 + }
  64 +
58 65 if (!preserveAspect) {
59 66 resize(src, dst, Size((columns == -1) ? src.m().cols*rows/src.m().rows : columns, rows), 0, 0, method);
60 67 const float rowScaleFactor = (float)rows/src.m().rows;
... ... @@ -63,6 +70,13 @@ private:
63 70 for (int i=0; i<points.size(); i++)
64 71 points[i] = QPointF(points[i].x() * colScaleFactor,points[i].y() * rowScaleFactor);
65 72 dst.file.setPoints(points);
  73 + } else if (!pad) {
  74 + const int size = std::max(rows, columns);
  75 + float ratio = (float) src.m().rows / src.m().cols;
  76 + if (src.m().rows > src.m().cols)
  77 + resize(src, dst, Size(size/ratio, size), 0, 0, method);
  78 + else
  79 + resize(src, dst, Size(size, size*ratio), 0, 0, method);
66 80 } else {
67 81 float inRatio = (float) src.m().rows / src.m().cols;
68 82 float outRatio = (float) rows / columns;
... ...