Permalink
Browse files

Vignette cleanup

  • Loading branch information...
1 parent 77dfc8b commit c232b9db725f7df1330c1fe6a9f4a4c490ae0998 @jliljebl jliljebl committed May 12, 2014
Showing with 38 additions and 31 deletions.
  1. +38 −31 src/modules/oldfilm/filter_vignette.c
@@ -24,22 +24,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
+
#define MIN(a,b) (a<b?a:b)
#define MAX(a,b) (a<b?b:a)
-
#define SIGMOD_STEPS 1000
#define POSITION_VALUE(p,s,e) (s+((double)(e-s)*p ))
-static float geometry_to_float(char *val, mlt_position pos )
+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);
+ 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;
}
@@ -56,42 +56,49 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
mlt_properties filter_props = MLT_FILTER_PROPERTIES( filter ) ;
mlt_position pos = mlt_filter_get_position( filter, frame );
- 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 );
+ 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;
- 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));
+ int x, y;
+ int w2 = cx, h2 = cy;
+ double delta = 1.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++ )
+ {
+ uint8_t *pix = ( *image + y * video_width * 2 + x * 2 );
+ int dx = sqrt( h2_pow2 + pow( x - w2, 2.0 ));
- if (radius-smooth>dx){ //center, make not darker
+ if (radius-smooth > dx) //center, make not darker
+ {
continue;
}
- else if (radius+smooth<=dx){//max dark after smooth area
- delta=0.0;
- }else{
+ else if ( radius + smooth <= dx ) //max dark after smooth area
+ {
+ delta = 0.0;
+ }
+ else
+ {
// linear pos from of opacity (from 0 to 1)
- delta=(double)(radius+smooth-dx)/(2.0*smooth);
- if (mode==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 = (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;
+ delta = MAX( max_opac, delta );
+ *pix = (double) (*pix) * delta;
+ *(pix+1) = ((double)(*(pix+1) - 127.0 ) * delta ) + 127.0;
}
}
}

0 comments on commit c232b9d

Please sign in to comment.