]> git.sesse.net Git - mlt/blobdiff - src/modules/oldfilm/filter_vignette.c
Add mlt_properties_frames_to_time() and mlt_properties_time_to_frames().
[mlt] / src / modules / oldfilm / filter_vignette.c
index e9e3f5d0f814a44086b990deeeac8b4a98869b34..d0cc38bb1dc6c30304008615a1fd9b505f93f8cb 100644 (file)
 #define SIGMOD_STEPS 1000
 #define POSITION_VALUE(p,s,e) (s+((double)(e-s)*p ))
 //static double pow2[SIGMOD_STEPS];
+static float geometry_to_float(char *val, mlt_position pos )
+{
+    float ret=0.0;
+    struct mlt_geometry_item_s item;
+
+       mlt_geometry geom=mlt_geometry_init();
+    mlt_geometry_parse(geom,val,-1,-1,-1);
+    mlt_geometry_fetch(geom,&item , pos );
+    ret=item.x;
+    mlt_geometry_close(geom);
+
+    return ret;
+}
 
 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
 {
        
        mlt_filter filter = mlt_frame_pop_service( this );
+       *format = mlt_image_yuv422;
        int error = mlt_frame_get_image( this, image, format, width, height, 1 );
 
-       if ( error == 0 && *image && *format == mlt_image_yuv422 )
+       if ( error == 0 && *image )
        {
-               mlt_position in = mlt_filter_get_in( filter );
-               //mlt_position out = mlt_filter_get_out( filter );
-               mlt_position time = mlt_frame_get_position( this );
-               
-               mlt_geometry geom=mlt_geometry_init();
-               struct mlt_geometry_item_s item;
                float smooth, radius, cx, cy, opac;
-               char *val=mlt_properties_get(MLT_FILTER_PROPERTIES( filter ), "geometry" );
-               mlt_geometry_parse(geom,val,-1,-1,-1);
-               mlt_geometry_fetch(geom,&item,time-in);
-               smooth=item.x;
-               radius=item.y;
-               cx=item.w;
-               cy=item.h;
-               opac=item.mix;
-               mlt_geometry_close(geom);
-               
+               mlt_properties filter_props = MLT_FILTER_PROPERTIES( filter ) ;
+               mlt_position pos = mlt_filter_get_position( filter, this );
+
+               smooth = geometry_to_float ( mlt_properties_get( filter_props , "smooth" ) , pos ) * 100.0 ;
+               radius = geometry_to_float ( mlt_properties_get( filter_props , "radius" ) , pos ) * *width;
+               cx = geometry_to_float ( mlt_properties_get( filter_props , "x" ) , pos ) * *width;
+               cy = geometry_to_float ( mlt_properties_get( filter_props , "y" ) , pos ) * *height;
+               opac = geometry_to_float ( mlt_properties_get( filter_props , "opacity" ) , pos );
+               int mode = mlt_properties_get_int( filter_props , "mode" );
+
                int video_width = *width;
                int video_height = *height;
                
                int x,y;
                int w2=cx,h2=cy;
                double delta=1.0;
-               double max_opac=opac/100.0;
-
+               double max_opac=opac;
                for (y=0;y<video_height;y++){
                        int h2_pow2=pow(y-h2,2.0);
                        for (x=0;x<video_width;x++){
@@ -76,20 +83,18 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                else if (radius+smooth<=dx){//max dark after smooth area
                                        delta=0.0;
                                }else{
-                                       //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
+                                       // linear pos from of opacity (from 0 to 1)
+                                       delta=(double)(radius+smooth-dx)/(2.0*smooth);
+                                       if (mode==1){
+                                               //make cos for smoother non linear fade
+                                               delta = (double)pow(cos(((1.0-delta)*3.14159/2.0)),3.0);
+                                       }
                                }
                                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
-               // c: =gray pix 2
-               // d: +=red,-=green
        }
        
        return error;
@@ -97,7 +102,6 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 {
-       
        mlt_frame_push_service( frame, this );
        mlt_frame_push_get_image( frame, filter_get_image );
        return frame;
@@ -117,7 +121,13 @@ mlt_filter filter_vignette_init( mlt_profile profile, mlt_service_type type, con
                */
                
                this->process = filter_process;
-               mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "geometry", "80:50%:50%:50%:0" );
+               mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "smooth", 0.8 );
+               mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "radius", 0.5 );
+               mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "x", 0.5 );
+               mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "y", 0.5 );
+               mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "opacity", 0.0 );
+               mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "mode", 0 );
+
                //mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "end", "" );
 
        }