Quellcode durchsuchen

PfmFile::flip()

David Rose vor 13 Jahren
Ursprung
Commit
98d7643a23
2 geänderte Dateien mit 50 neuen und 0 gelöschten Zeilen
  1. 49 0
      panda/src/grutil/pfmFile.cxx
  2. 1 0
      panda/src/grutil/pfmFile.h

+ 49 - 0
panda/src/grutil/pfmFile.cxx

@@ -519,6 +519,55 @@ reverse_rows() {
   _table.swap(reversed);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::flip
+//       Access: Published
+//  Description: Reverses, transposes, and/or rotates the table
+//               in-place according to the specified parameters.  If
+//               flip_x is true, the x axis is reversed; if flip_y is
+//               true, the y axis is reversed.  Then, if transpose is
+//               true, the x and y axes are exchanged.  These
+//               parameters can be used to select any combination of
+//               90-degree or 180-degree rotations and flips.
+////////////////////////////////////////////////////////////////////
+void PfmFile::
+flip(bool flip_x, bool flip_y, bool transpose) {
+  nassertv(is_valid());
+
+  Table flipped;
+  flipped.reserve(_table.size());
+
+  if (transpose) {
+    // Transposed case.  X becomes Y, Y becomes X.
+    for (int xi = 0; xi < _x_size; ++xi) {
+      int source_xi = flip_x ? xi : _x_size - 1 - xi;
+      for (int yi = 0; yi < _y_size; ++yi) {
+        int source_yi = flip_y ? yi : _y_size - 1 - yi;
+        const LPoint3 &p = _table[source_yi * _x_size + source_xi];
+        flipped.push_back(p);
+      }
+    }
+
+    int t = _x_size;
+    _x_size = _y_size;
+    _y_size = t;
+
+  } else {
+    // Non-transposed.  X is X, Y is Y.
+    for (int yi = 0; yi < _y_size; ++yi) {
+      int source_yi = flip_y ? yi : _y_size - 1 - yi;
+      for (int xi = 0; xi < _x_size; ++xi) {
+        int source_xi = flip_x ? xi : _x_size - 1 - xi;
+        const LPoint3 &p = _table[source_yi * _x_size + source_xi];
+        flipped.push_back(p);
+      }
+    }
+  }
+
+  nassertv(flipped.size() == _table.size());
+  _table.swap(flipped);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::xform
 //       Access: Published

+ 1 - 0
panda/src/grutil/pfmFile.h

@@ -66,6 +66,7 @@ PUBLISHED:
 
   BLOCKING void resize(int new_x_size, int new_y_size);
   BLOCKING void reverse_rows();
+  BLOCKING void flip(bool flip_x, bool flip_y, bool transpose);
   BLOCKING void xform(const LMatrix4 &transform);
   BLOCKING void project(const Lens *lens);
   BLOCKING void merge(const PfmFile &other);