]> git.sesse.net Git - movit/blobdiff - deconvolution_sharpen_effect.cpp
Hard-assert on something that has bitten me too many times now.
[movit] / deconvolution_sharpen_effect.cpp
index 0a13dd642f3d9a3cb5d00ac857f2763cf4904ee5..2db15dc1bc98af9b3e340551028b99b29574321e 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <Eigen/Dense>
 #include <Eigen/Cholesky>
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <assert.h>
 #include <math.h>
 #include <stdio.h>
@@ -19,6 +19,8 @@
 using namespace Eigen;
 using namespace std;
 
+namespace movit {
+
 DeconvolutionSharpenEffect::DeconvolutionSharpenEffect()
        : R(5),
          circle_radius(2.0f),
@@ -29,7 +31,8 @@ DeconvolutionSharpenEffect::DeconvolutionSharpenEffect()
          last_circle_radius(-1.0f),
          last_gaussian_radius(-1.0f),
          last_correlation(-1.0f),
-         last_noise(-1.0f)
+         last_noise(-1.0f),
+         uniform_samples(NULL)
 {
        register_int("matrix_size", &R);
        register_float("circle_radius", &circle_radius);
@@ -38,6 +41,11 @@ DeconvolutionSharpenEffect::DeconvolutionSharpenEffect()
        register_float("noise", &noise);
 }
 
+DeconvolutionSharpenEffect::~DeconvolutionSharpenEffect()
+{
+       delete[] uniform_samples;
+}
+
 string DeconvolutionSharpenEffect::output_fragment_shader()
 {
        char buf[256];
@@ -46,6 +54,9 @@ string DeconvolutionSharpenEffect::output_fragment_shader()
        assert(R >= 1);
        assert(R <= 25);  // Same limit as Refocus.
 
+       uniform_samples = new float[4 * (R + 1) * (R + 1)];
+       register_uniform_vec4_array("samples", uniform_samples, (R + 1) * (R + 1));
+
        last_R = R;
        return buf + read_file("deconvolution_sharpen_effect.frag");
 }
@@ -301,7 +312,7 @@ void DeconvolutionSharpenEffect::update_deconvolution_kernel()
        MatrixXf r_uu(8 * R + 1, 8 * R + 1);
        for (int y = -4 * R; y <= 4 * R; ++y) { 
                for (int x = -4 * R; x <= 4 * R; ++x) {
-                       r_uu(x + 4 * R, y + 4 * R) = pow(correlation, hypot(x, y));
+                       r_uu(x + 4 * R, y + 4 * R) = pow(double(correlation), hypot(x, y));
                }
        }
 
@@ -431,16 +442,15 @@ void DeconvolutionSharpenEffect::set_gl_state(GLuint glsl_program_num, const str
                update_deconvolution_kernel();
        }
        // Now encode it as uniforms, and pass it on to the shader.
-       float samples[4 * (R + 1) * (R + 1)];
        for (int y = 0; y <= R; ++y) {
                for (int x = 0; x <= R; ++x) {
                        int i = y * (R + 1) + x;
-                       samples[i * 4 + 0] = x / float(width);
-                       samples[i * 4 + 1] = y / float(height);
-                       samples[i * 4 + 2] = g(y, x);
-                       samples[i * 4 + 3] = 0.0f;
+                       uniform_samples[i * 4 + 0] = x / float(width);
+                       uniform_samples[i * 4 + 1] = y / float(height);
+                       uniform_samples[i * 4 + 2] = g(y, x);
+                       uniform_samples[i * 4 + 3] = 0.0f;
                }
        }
-
-       set_uniform_vec4_array(glsl_program_num, prefix, "samples", samples, (R + 1) * (R + 1));
 }
+
+}  // namespace movit