瀏覽代碼

PfmFile::apply_1d_lut()

David Rose 10 年之前
父節點
當前提交
caf3a9f24c
共有 2 個文件被更改,包括 28 次插入0 次删除
  1. 26 0
      panda/src/pnmimage/pfmFile.cxx
  2. 2 0
      panda/src/pnmimage/pfmFile.h

+ 26 - 0
panda/src/pnmimage/pfmFile.cxx

@@ -1439,6 +1439,32 @@ reverse_distort(const PfmFile &dist, PN_float32 scale_factor) {
   _table.swap(result._table);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PfmFile::apply_1d_lut
+//       Access: Published
+//  Description: Assumes that lut is an X by 1, 1-component PfmFile
+//               whose X axis maps points to target points.  For each
+//               point in this pfm file, computes: p(u, v)[channel] =
+//               lut(p(u, v)[channel] * x_scale, 0)[0]
+////////////////////////////////////////////////////////////////////
+void PfmFile::
+apply_1d_lut(int channel, const PfmFile &lut, PN_float32 x_scale) {
+  for (int yi = 0; yi < _y_size; ++yi) {
+    for (int xi = 0; xi < _x_size; ++xi) {
+      if (!has_point(xi, yi)) {
+        continue;
+      }
+
+      PN_float32 v = get_channel(xi, yi, channel);
+      LPoint3f p;
+      if (!lut.calc_bilinear_point(p, v * x_scale, 0.5)) {
+        continue;
+      }
+      set_channel(xi, yi, channel, p[0]);
+    }
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PfmFile::merge
 //       Access: Published

+ 2 - 0
panda/src/pnmimage/pfmFile.h

@@ -122,6 +122,8 @@ PUBLISHED:
   INLINE BLOCKING void xform(const LMatrix4d &transform);
   BLOCKING void forward_distort(const PfmFile &dist, PN_float32 scale_factor = 1.0);
   BLOCKING void reverse_distort(const PfmFile &dist, PN_float32 scale_factor = 1.0);
+  BLOCKING void apply_1d_lut(int channel, const PfmFile &lut, PN_float32 x_scale = 1.0);
+
   BLOCKING void merge(const PfmFile &other);
   BLOCKING void apply_mask(const PfmFile &other);
   BLOCKING void copy_channel(int to_channel, const PfmFile &other, int from_channel);