From: gmarco Date: Mon, 2 Jan 2012 19:12:49 +0000 (+0100) Subject: do not use lanc_kernels as global var. moved to filter struct X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;ds=sidebyside;h=fd45c0a15bb80b7aa9fc98fd81cefca9a92830b1;p=mlt do not use lanc_kernels as global var. moved to filter struct --- diff --git a/src/modules/videostab/filter_videostab.c b/src/modules/videostab/filter_videostab.c index 0cd0cd54..c569801f 100644 --- a/src/modules/videostab/filter_videostab.c +++ b/src/modules/videostab/filter_videostab.c @@ -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; diff --git a/src/modules/videostab/stab/resample.c b/src/modules/videostab/stab/resample.c index 3ed51654..12d82af7 100644 --- a/src/modules/videostab/stab/resample.c +++ b/src/modules/videostab/stab/resample.c @@ -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 ++) diff --git a/src/modules/videostab/stab/resample.h b/src/modules/videostab/stab/resample.h index a2cf73e2..aefa4a80 100644 --- a/src/modules/videostab/stab/resample.h +++ b/src/modules/videostab/stab/resample.h @@ -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 *); diff --git a/src/modules/videostab/stab/utils.c b/src/modules/videostab/stab/utils.c index 6f06eaf1..43fc30ef 100644 --- a/src/modules/videostab/stab/utils.c +++ b/src/modules/videostab/stab/utils.c @@ -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]); diff --git a/src/modules/videostab/stab/utils.h b/src/modules/videostab/stab/utils.h index 7128b711..a8c38862 100644 --- a/src/modules/videostab/stab/utils.h +++ b/src/modules/videostab/stab/utils.h @@ -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