oldfilm/filter_vignette.{c,yml}:
[melted] / src / modules / oldfilm / filter_vignette.c
index 0574b20..11891cb 100644 (file)
@@ -28,7 +28,7 @@
 
 #define SIGMOD_STEPS 1000
 #define POSITION_VALUE(p,s,e) (s+((double)(e-s)*p ))
-static double pow2[SIGMOD_STEPS];
+//static double pow2[SIGMOD_STEPS];
 
 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
 {
@@ -38,12 +38,12 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        
        if ( error == 0 && *image && *format == mlt_image_yuv422 )
        {
-               int smooth_s=80,radius_s=50,x_s=50,y_s=50,opac_s=0;
-               int smooth_e=80,radius_e=50,x_e=50,y_e=50,opac_e=0;
+               float smooth_s=80,radius_s=50,x_s=50,y_s=50,opac_s=0;
+               float smooth_e=80,radius_e=50,x_e=50,y_e=50,opac_e=0;
                
-               sscanf(mlt_properties_get(MLT_FILTER_PROPERTIES( filter ), "start"  ), "%d:%d,%dx%d,%d",&smooth_s,&radius_s,&x_s,&y_s,&opac_s);
+               sscanf(mlt_properties_get(MLT_FILTER_PROPERTIES( filter ), "start"  ), "%f:%f:%fx%f:%f",&smooth_s,&radius_s,&x_s,&y_s,&opac_s);
                if (mlt_properties_get(MLT_FILTER_PROPERTIES( filter ), "end"  ) ){
-                       sscanf(mlt_properties_get(MLT_FILTER_PROPERTIES( filter ), "end"  ), "%d:%d,%dx%d,%d",&smooth_e,&radius_e,&x_e,&y_e,&opac_e);
+                       sscanf(mlt_properties_get(MLT_FILTER_PROPERTIES( filter ), "end"  ), "%f:%f:%fx%f:%f",&smooth_e,&radius_e,&x_e,&y_e,&opac_e);
                }else{
                        smooth_e=smooth_s;
                        radius_e=radius_s;
@@ -54,10 +54,10 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                mlt_position in = mlt_filter_get_in( filter );
                mlt_position out = mlt_filter_get_out( filter );
                mlt_position time = mlt_frame_get_position( this );
-               double position = ( double )( time -in ) / ( double )( out - in + 1 ) /100.0;
+               float position = ( double )( time -in ) / ( double )( out - in + 1 ) /100.0;
                
-               double smooth = POSITION_VALUE (position, smooth_s, smooth_e) ;
-               double radius = POSITION_VALUE (position, radius_s, radius_e)/100.0* *width;
+               float smooth = 2.0*POSITION_VALUE (position, smooth_s, smooth_e) ;
+               float radius = POSITION_VALUE (position, radius_s, radius_e)/100.0* *width;
                
                double cx = POSITION_VALUE (position, x_s, x_e ) * *width/100;
                double cy = POSITION_VALUE (position, y_s, y_e ) * *height/100; 
@@ -68,39 +68,30 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                
                int x,y;
                int w2=cx,h2=cy;
-               double delta=0.0;
-               double max_opac=255.0;
-               
-               if (opac>0.0)
-                       max_opac=100.0/opac;
-               
+               double delta=1.0;
+               double max_opac=opac/100.0;
+
                for (y=0;y<video_height;y++){
                        int h2_pow2=pow(y-h2,2.0);
                        for (x=0;x<video_width;x++){
                                uint8_t *pix=(*image+y*video_width*2+x*2);
                                int dx=sqrt(h2_pow2+pow(x-w2,2.0));
-                               double sigx=(double)(-dx+radius-smooth)/smooth;
                                
-                               if (smooth>0.001 && sigx>-10.0 && sigx<10.0){
-                                       delta=pow2[((int)((sigx+10)*SIGMOD_STEPS/20))];
-                               }else if (smooth>0.001 && sigx>10.0){
+                               if (radius-smooth>dx){  //center, make not darker
                                        continue;
-                               }else{
-                                       delta=255.0;
                                }
-                               if ( max_opac<delta){
-                                               delta=max_opac;
-                               }
-                               if (delta!=0.0){
-                                       *pix=(double)(*pix)/delta;
-                                       *(pix+1)=((double)(*(pix+1)-127.0)/delta)+127.0;
+                               else if (radius+smooth<=dx){//max dark after smooth area
+                                       delta=0.0;
                                }else{
-                                       *pix=*(pix+1)=0;
+                                       //double sigx=5.0-10.0*(double)(dx-radius+smooth)/(2.0*smooth);//smooth >10 inner area, <-10 in dark area
+                                       //delta=pow2[((int)((sigx+10.0)*SIGMOD_STEPS/20.0))];//sigmoidal
+                                       delta = ((double)(radius+smooth-dx)/(2.0*smooth));//linear
                                }
-                               
+                               delta=MAX(max_opac,delta);
+                               *pix=(double)(*pix)*delta;
+                               *(pix+1)=((double)(*(pix+1)-127.0)*delta)+127.0;
                        }
                }
-               
                // short a, short b, short c, short d
                // a= gray val pix 1
                // b: +=blue, -=yellow
@@ -123,14 +114,17 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 mlt_filter filter_vignette_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
        mlt_filter this = mlt_filter_new( );
-       int i=0;
+       //int i=0;
        if ( this != NULL )
        {
+               /*
                for (i=-SIGMOD_STEPS/2;i<SIGMOD_STEPS/2;i++){
-                       pow2[i+SIGMOD_STEPS/2]=1.0+pow(2.0,-((double)i)/((double)SIGMOD_STEPS/20.0));
+                       pow2[i+SIGMOD_STEPS/2]=1.0/(1.0+pow(2.0,-((double)i)/((double)SIGMOD_STEPS/20.0)));
                }
+               */
+               
                this->process = filter_process;
-               mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "start", "80:50:50x50:0" );
+               mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "start", "80:50,50x50,0" );
                //mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "end", "" );
 
        }