X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Frotate.c;h=2cfb868783c3a99cf05f9161abd2adfd30807671;hb=d36f3bd678299b077464c86cc795db5dcfbbe427;hp=2789093c09b1a93059090ba2075ced2d62663838;hpb=35f85be0d72b91a5ec1131e06ca428f93cddd5ab;p=vlc diff --git a/modules/video_filter/rotate.c b/modules/video_filter/rotate.c index 2789093c09..2cfb868783 100644 --- a/modules/video_filter/rotate.c +++ b/modules/video_filter/rotate.c @@ -1,7 +1,7 @@ /***************************************************************************** * rotate.c : video rotation filter ***************************************************************************** - * Copyright (C) 2000-2008 the VideoLAN team + * Copyright (C) 2000-2008 VLC authors and VideoLAN * $Id$ * * Authors: Antoine Cellerier @@ -33,7 +33,7 @@ #include #include - +#include #include #include "filter_picture.h" #include "../control/motionlib.h" @@ -51,10 +51,6 @@ static int RotateCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ); -static int PreciseRotateCallback( vlc_object_t *p_this, char const *psz_var, - vlc_value_t oldval, vlc_value_t newval, - void *p_data ); - #define ANGLE_TEXT N_("Angle in degrees") #define ANGLE_LONGTEXT N_("Angle in degrees (0 to 359)") #define MOTION_TEXT N_("Use motion sensors") @@ -73,8 +69,7 @@ vlc_module_begin () set_category( CAT_VIDEO ) set_subcategory( SUBCAT_VIDEO_VFILTER ) - add_integer_with_range( FILTER_PREFIX "angle", 30, 0, 359, - ANGLE_TEXT, ANGLE_LONGTEXT, false ) + add_float( FILTER_PREFIX "angle", 30., ANGLE_TEXT, ANGLE_LONGTEXT, false ) add_bool( FILTER_PREFIX "use-motion", false, MOTION_TEXT, MOTION_LONGTEXT, false ) @@ -91,18 +86,25 @@ static const char *const ppsz_filter_options[] = { *****************************************************************************/ struct filter_sys_t { - vlc_spinlock_t lock; - int i_cos; - int i_sin; - int i_angle; + atomic_uint_fast32_t sincos; motion_sensors_t *p_motion; }; -static inline void cache_trigo( int i_angle, int *i_sin, int *i_cos ) +static void store_trigo( struct filter_sys_t *sys, float f_angle ) { - const double f_angle = (((double)i_angle)*M_PI)/1800.; - *i_sin = (int)(sin( f_angle )*4096.); - *i_cos = (int)(cos( f_angle )*4096.); + f_angle *= M_PI / 180.f; /* degrees -> radians */ + + uint16_t i_sin = lroundf(sinf(f_angle) * 4096.f); + uint16_t i_cos = lroundf(cosf(f_angle) * 4096.f); + atomic_store( &sys->sincos, (i_cos << 16) | (i_sin << 0)); +} + +static void fetch_trigo( struct filter_sys_t *sys, int *i_sin, int *i_cos ) +{ + uint32_t sincos = atomic_load( &sys->sincos ); + + *i_sin = (int16_t)(sincos & 0xFFFF); + *i_cos = (int16_t)(sincos >> 16); } /***************************************************************************** @@ -144,30 +146,23 @@ static int Create( vlc_object_t *p_this ) config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, p_filter->p_cfg ); - p_sys->p_motion = NULL; if( var_InheritBool( p_filter, FILTER_PREFIX "use-motion" ) ) { p_sys->p_motion = motion_create( VLC_OBJECT( p_filter ) ); if( p_sys->p_motion == NULL ) { - free( p_filter->p_sys ); + free( p_sys ); return VLC_EGENERIC; } - p_sys->i_angle = 0; - cache_trigo( p_sys->i_angle, &p_sys->i_sin, &p_sys->i_cos ); } else { - int i_angle = var_CreateGetIntegerCommand( p_filter, - FILTER_PREFIX "angle" ) * 10; - cache_trigo( i_angle, &p_sys->i_sin, &p_sys->i_cos ); - var_Create( p_filter, FILTER_PREFIX "deciangle", - VLC_VAR_INTEGER|VLC_VAR_ISCOMMAND ); - vlc_spin_init( &p_sys->lock ); + float f_angle = var_CreateGetFloatCommand( p_filter, + FILTER_PREFIX "angle" ); + store_trigo( p_sys, f_angle ); var_AddCallback( p_filter, FILTER_PREFIX "angle", RotateCallback, p_sys ); - var_AddCallback( p_filter, FILTER_PREFIX "deciangle", - PreciseRotateCallback, p_sys ); + p_sys->p_motion = NULL; } return VLC_SUCCESS; @@ -187,9 +182,6 @@ static void Destroy( vlc_object_t *p_this ) { var_DelCallback( p_filter, FILTER_PREFIX "angle", RotateCallback, p_sys ); - var_DelCallback( p_filter, FILTER_PREFIX "deciangle", - PreciseRotateCallback, p_sys ); - vlc_spin_destroy( &p_sys->lock ); } free( p_sys ); } @@ -211,29 +203,14 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) return NULL; } - int s, c; if( p_sys->p_motion != NULL ) { - int i_angle = motion_get_angle( p_sys->p_motion ) / 2; - if( p_sys->i_angle != i_angle ) - { - p_sys->i_angle = i_angle; - cache_trigo( i_angle, &p_sys->i_sin, &p_sys->i_cos ); - } - - s = p_sys->i_sin; - c = p_sys->i_cos; - } - else - { - vlc_spin_lock( &p_sys->lock ); - s = p_sys->i_sin; - c = p_sys->i_cos; - vlc_spin_unlock( &p_sys->lock ); + int i_angle = motion_get_angle( p_sys->p_motion ); + store_trigo( p_sys, i_angle / 20.f ); } - const int i_sin = s; - const int i_cos = c; + int i_sin, i_cos; + fetch_trigo( p_sys, &i_sin, &i_cos ); for( int i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) { @@ -381,29 +358,14 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic ) const int i_line_center = i_visible_lines>>1; const int i_col_center = i_visible_pitch>>1; - int s, c; if( p_sys->p_motion != NULL ) { - int i_angle = motion_get_angle( p_sys->p_motion ) / 2; - if( p_sys->i_angle != i_angle ) - { - p_sys->i_angle = i_angle; - cache_trigo( i_angle, &p_sys->i_sin, &p_sys->i_cos ); - } - - s = p_sys->i_sin; - c = p_sys->i_cos; - } - else - { - vlc_spin_lock( &p_sys->lock ); - s = p_sys->i_sin; - c = p_sys->i_cos; - vlc_spin_unlock( &p_sys->lock ); + int i_angle = motion_get_angle( p_sys->p_motion ); + store_trigo( p_sys, i_angle / 20.f ); } - const int i_sin = s; - const int i_cos = c; + int i_sin, i_cos; + fetch_trigo( p_sys, &i_sin, &i_cos ); int i_col, i_line; for( i_line = 0; i_line < i_visible_lines; i_line++ ) @@ -461,29 +423,14 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic ) } /***************************************************************************** - * Angle modification callbacks. + * Angle modification callback. *****************************************************************************/ static int RotateCallback( vlc_object_t *p_this, char const *psz_var, - vlc_value_t oldval, vlc_value_t newval, - void *p_data ) + vlc_value_t oldval, vlc_value_t newval, void *data ) { - oldval.i_int *= 10; - newval.i_int *= 10; - return PreciseRotateCallback( p_this, psz_var, oldval, newval, p_data ); -} - -static int PreciseRotateCallback( vlc_object_t *p_this, char const *psz_var, - vlc_value_t oldval, vlc_value_t newval, - void *p_data ) -{ - VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(oldval); - filter_sys_t *p_sys = (filter_sys_t *)p_data; - int i_sin, i_cos; + filter_sys_t *p_sys = data; - cache_trigo( newval.i_int, &i_sin, &i_cos ); - vlc_spin_lock( &p_sys->lock ); - p_sys->i_sin = i_sin; - p_sys->i_cos = i_cos; - vlc_spin_unlock( &p_sys->lock ); + store_trigo( p_sys, newval.f_float ); + (void) p_this; (void) psz_var; (void) oldval; return VLC_SUCCESS; }