]> git.sesse.net Git - mlt/commitdiff
do not use lanc_kernels as global var. moved to filter struct
authorgmarco <g.marco@freenet.de>
Mon, 2 Jan 2012 19:12:49 +0000 (20:12 +0100)
committerDan Dennedy <dan@dennedy.org>
Mon, 2 Jan 2012 20:04:36 +0000 (12:04 -0800)
src/modules/videostab/filter_videostab.c
src/modules/videostab/stab/resample.c
src/modules/videostab/stab/resample.h
src/modules/videostab/stab/utils.c
src/modules/videostab/stab/utils.h

index 0cd0cd54d1c7364c01cf9ad45904a2d364f2cadb..c569801fb34260fc839c860f5789e78babec4612 100644 (file)
@@ -38,6 +38,7 @@
 typedef struct {
        mlt_filter parent;
        int initialized;
+       int* lanc_kernels;
        es_ctx *es;
        vc *pos_i;
        vc *pos_h;
@@ -162,8 +163,8 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                int i;
 
                                for (i = 0; i < h; i ++)
-                                       self->pos_y[i] = interp( self->pos_h, length, pos + (i - h / 2.0) * shutter_angle / (h * 360.0) );
-                               rs_resample( self->rs, *image, self->pos_y );
+                                       self->pos_y[i] = interp( self->lanc_kernels,self->pos_h, length, pos + (i - h / 2.0) * shutter_angle / (h * 360.0) );
+                               rs_resample( self->lanc_kernels,self->rs, *image, self->pos_y );
                        }
                }
                mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
@@ -186,7 +187,7 @@ void filter_close( mlt_filter parent )
        if ( self->pos_h ) free( self->pos_h );
        if ( self->pos_y ) free( self->pos_y );
        if ( self->rs ) rs_free( self->rs );
-       free_lanc_kernels();
+       if ( self->lanc_kernels) free_lanc_kernels(self->lanc_kernels);
        free( self );
        parent->close = NULL;
        parent->child = NULL;
@@ -203,7 +204,7 @@ mlt_filter filter_videostab_init( mlt_profile profile, mlt_service_type type, co
                parent->process = filter_process;
                self->parent = parent;
                mlt_properties_set( MLT_FILTER_PROPERTIES(parent), "shutterangle", "0" ); // 0 - 180 , default 0
-               prepare_lanc_kernels();
+               self->lanc_kernels=prepare_lanc_kernels();
                return parent;
        }
        return NULL;
index 3ed516548b9e16ece6bee918e25da6f1e26941a3..12d82af70de9a1c78fa6046f3c4a6766685e6f45 100644 (file)
@@ -26,14 +26,14 @@ rs_ctx *rs_init(int nc, int nr) {
     rs_ctx *rs = (rs_ctx *)malloc(sizeof(rs_ctx));
 
     rs->tf = (unsigned char *)malloc(nc * nr * 3 * sizeof(unsigned char));
-    
+
     rs->nc = nc;
     rs->nr = nr;
 
     return rs;
 }
 
-void rs_resample(rs_ctx *rs, unsigned char *f, vc *p) {
+void rs_resample(int* lanc_kernels,rs_ctx *rs, unsigned char *f, vc *p) {
 
     int i, x, y, c;
 
@@ -42,24 +42,24 @@ void rs_resample(rs_ctx *rs, unsigned char *f, vc *p) {
         int yp = y * rs->nc;
         int xd = floor(p[y].x);
 
-        int *lk = select_lanc_kernel(p[y].x);
+        int *lk = select_lanc_kernel(lanc_kernels,p[y].x);
 
         for (x = 0; x < rs->nc; x ++) {
 
             int pd = (yp + x) * 3;
             int a[3];
-            
+
             for (c = 0; c < 3; c ++)
                 a[c] = 0;
 
             for (i = -3; i < 5; i ++) {
-            
+
                 int ps = (yp + clamp(x + xd + i, 0, rs->nc - 1)) * 3;
 
                 for (c = 0; c < 3; c ++)
                     a[c] += f[ps + c] * lk[i + 3];
             }
-            
+
             for (c = 0; c < 3; c ++)
                 rs->tf[pd + c] = clamp(a[c] / 1024, 0, 255);
         }
@@ -70,18 +70,18 @@ void rs_resample(rs_ctx *rs, unsigned char *f, vc *p) {
         int yp = y * rs->nc;
         int yd = floor(p[y].y);
 
-        int *lk = select_lanc_kernel(p[y].y);
+        int *lk = select_lanc_kernel(lanc_kernels,p[y].y);
 
         for (x = 0; x < rs->nc; x ++) {
 
             int pd = (yp + x) * 3;
             int a[3];
-            
+
             for (c = 0; c < 3; c ++)
                 a[c] = 0;
-            
+
             for (i = -3; i < 5; i ++) {
-            
+
                 int ps = (clamp(y + yd + i, 0, rs->nr - 1) * rs->nc + x) * 3;
 
                 for (c = 0; c < 3; c ++)
index a2cf73e2262b3aac750f1b2c732585d273370b33..aefa4a80673ad1ae232df7eb1f3282bc9b9f5483 100644 (file)
@@ -12,7 +12,7 @@ typedef struct {
 
 rs_ctx *rs_init(int, int);
 
-void rs_resample(rs_ctx *, unsigned char *, vc *);
+void rs_resample(int*,rs_ctx *, unsigned char *, vc *);
 
 void rs_free(rs_ctx *);
 
index 6f06eaf11192466522b74a9cf5538ee2363c292e..43fc30efde6831b9ace9abc20232bec720a962ae 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "utils.h"
 
-int *lanc_kernels = NULL;
-
 float lanc(float x, float r) {
 
     float t = x * M_PI;
@@ -32,7 +30,7 @@ float lanc(float x, float r) {
 
     if (x <= -r || x >= r)
         return 0.0;
-        
+
     return r * sin(t) * sin(t / r) / (t * t);
 }
 
@@ -67,7 +65,7 @@ void lopass(vc *vi, vc *vo, int l, int r) {
         cw += ck[i] = hann(i, d - 1);
 
     for (i = 0; i < l; i ++) {
-    
+
         vc a = vc_zero();
 
         for (j = i - r; j <= i + r; j ++) {
@@ -79,7 +77,7 @@ void lopass(vc *vi, vc *vo, int l, int r) {
 
         vo[i] = vc_div(a, cw);
     }
-    
+
     free(ck);
 }
 
@@ -93,37 +91,38 @@ void hipass(vc *vi, vc *vo, int l, int r) {
         vo[i] = vc_sub(vi[i], vo[i]);
 }
 
-void prepare_lanc_kernels() {
+int* prepare_lanc_kernels() {
 
     int i, j;
 
-    lanc_kernels = (int *)malloc(256 * 8 * sizeof(int));
+    int* lanc_kernels = (int *)malloc(256 * 8 * sizeof(int));
 
     for (i = 0; i < 256; i ++)
         for (j = -3; j < 5; j ++)
             lanc_kernels[i * 8 + j + 3] = lanc(j - i / 256.0, 4) * 1024.0;
+    return lanc_kernels;
 }
 
-int *select_lanc_kernel(float x) {
+int *select_lanc_kernel(int* lanc_kernels,float x) {
 
     return lanc_kernels + (int)((x - floor(x)) * 256.0) * 8;
 }
 
-void free_lanc_kernels() {
+void free_lanc_kernels(int *lanc_kernels) {
 
     free(lanc_kernels);
 }
 
-vc interp(vc *vi, int l, float x) {
+vc interp(int* lanc_kernels, vc *vi, int l, float x) {
 
     vc a = vc_zero();
     int xd = floor(x);
-    int *lk = select_lanc_kernel(x);
+    int *lk = select_lanc_kernel(lanc_kernels,x);
 
     int i;
 
     for (i = -3; i < 5; i ++) {
-    
+
         int ic = clamp(xd + i, 0, l - 1);
 
         vc_mul_acc(&a, vi[ic], lk[i + 3]);
index 7128b71172652066308569a1fe41e901dc7589d8..a8c38862649baec951e94f3b970a88b50952a9ae 100644 (file)
@@ -15,7 +15,6 @@
 #define FALSE 0
 #endif
 
-int *lanc_kernels;
 
 float lanc(float, float);
 float hann(float, float);
@@ -25,11 +24,11 @@ int clamp(int, int, int);
 void lopass(vc *, vc *, int, int);
 void hipass(vc *, vc *, int, int);
 
-void prepare_lanc_kernels();
-int *select_lanc_kernel(float);
-void free_lanc_kernels();
+int* prepare_lanc_kernels();
+int *select_lanc_kernel(int*,float);
+void free_lanc_kernels(int*);
 
-vc interp(vc *, int, float);
+vc interp(int*,vc *, int, float);
 
 #endif