X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fpuzzle.c;h=9d0455c55767913590ca6462fbe6794aa8860acf;hb=688f0a8d8913f20ac5d3e27bf4f2bbe35c9f5de7;hp=b6384154b64e07883c8f36b19be5a5f3dd01a332;hpb=c09b9f61b78e6ecea335dccca234cb3111657283;p=vlc diff --git a/modules/video_filter/puzzle.c b/modules/video_filter/puzzle.c index b6384154b6..9d0455c557 100644 --- a/modules/video_filter/puzzle.c +++ b/modules/video_filter/puzzle.c @@ -24,10 +24,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include @@ -69,23 +72,23 @@ static int PuzzleCallback( vlc_object_t *, char const *, #define CFG_PREFIX "puzzle-" vlc_module_begin(); - set_description( _("Puzzle interactive game video filter") ); - set_shortname( _( "Puzzle" )); + set_description( N_("Puzzle interactive game video filter") ); + set_shortname( N_( "Puzzle" )); set_capability( "video filter", 0 ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); add_integer_with_range( CFG_PREFIX "rows", 4, 1, 128, NULL, - ROWS_TEXT, ROWS_LONGTEXT, VLC_FALSE ); + ROWS_TEXT, ROWS_LONGTEXT, false ); add_integer_with_range( CFG_PREFIX "cols", 4, 1, 128, NULL, - COLS_TEXT, COLS_LONGTEXT, VLC_FALSE ); + COLS_TEXT, COLS_LONGTEXT, false ); add_bool( CFG_PREFIX "black-slot", 0, NULL, - BLACKSLOT_TEXT, BLACKSLOT_LONGTEXT, VLC_FALSE ); + BLACKSLOT_TEXT, BLACKSLOT_LONGTEXT, false ); set_callbacks( Create, Destroy ); vlc_module_end(); -static const char *ppsz_filter_options[] = { +static const char *const ppsz_filter_options[] = { "rows", "cols", "black-slot", NULL }; @@ -102,9 +105,9 @@ struct vout_sys_t int i_rows; int *pi_order; int i_selected; - vlc_bool_t b_finished; + bool b_finished; - vlc_bool_t b_blackslot; + bool b_blackslot; }; /***************************************************************************** @@ -118,19 +121,19 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args ) /***************************************************************************** * Misc stuff... *****************************************************************************/ -static vlc_bool_t finished( vout_sys_t *p_sys ) +static bool finished( vout_sys_t *p_sys ) { int i; for( i = 0; i < p_sys->i_cols * p_sys->i_rows; i++ ) { - if( i != p_sys->pi_order[i] ) return VLC_FALSE; + if( i != p_sys->pi_order[i] ) return false; } - return VLC_TRUE; + return true; } -static vlc_bool_t is_valid( vout_sys_t *p_sys ) +static bool is_valid( vout_sys_t *p_sys ) { int i, j, d=0; - if( p_sys->b_blackslot == VLC_FALSE ) return VLC_TRUE; + if( p_sys->b_blackslot == false ) return true; for( i = 0; i < p_sys->i_cols * p_sys->i_rows; i++ ) { if( p_sys->pi_order[i] == p_sys->i_cols * p_sys->i_rows - 1 ) @@ -145,8 +148,8 @@ static vlc_bool_t is_valid( vout_sys_t *p_sys ) if( p_sys->pi_order[i] > p_sys->pi_order[j] ) d++; } } - if( d%2!=0 ) return VLC_FALSE; - else return VLC_TRUE; + if( d%2!=0 ) return false; + else return true; } static void shuffle( vout_sys_t *p_sys ) { @@ -170,10 +173,10 @@ static void shuffle( vout_sys_t *p_sys ) } } p_sys->b_finished = finished( p_sys ); - } while( p_sys->b_finished == VLC_TRUE - || is_valid( p_sys ) == VLC_FALSE ); + } while( p_sys->b_finished == true + || is_valid( p_sys ) == false ); - if( p_sys->b_blackslot == VLC_TRUE ) + if( p_sys->b_blackslot == true ) { for( i = 0; i < p_sys->i_cols * p_sys->i_rows; i++ ) { @@ -201,10 +204,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); @@ -289,6 +289,10 @@ static void End( vout_thread_t *p_vout ) { int i_index; + DEL_PARENT_CALLBACKS( SendEventsToChild ); + + DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); + /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { @@ -299,6 +303,8 @@ static void End( vout_thread_t *p_vout ) var_DelCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout); var_DelCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout); var_DelCallback( p_vout->p_sys->p_vout, "mouse-clicked", MouseEvent, p_vout); + + vout_CloseAndRelease( p_vout->p_sys->p_vout ); } #define SHUFFLE_WIDTH 81 @@ -327,18 +333,9 @@ static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; - if( p_vout->p_sys->p_vout ) - { - DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); - vlc_object_detach( p_vout->p_sys->p_vout ); - vout_Destroy( p_vout->p_sys->p_vout ); - } - image_HandlerDelete( p_vout->p_sys->p_image ); free( p_vout->p_sys->pi_order ); - DEL_PARENT_CALLBACKS( SendEventsToChild ); - free( p_vout->p_sys ); } @@ -362,7 +359,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) == NULL ) { - if( p_vout->b_die || p_vout->b_error ) + if( !vlc_object_alive (p_vout) || p_vout->b_error ) { return; } @@ -389,15 +386,14 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) i_row *= p_in->i_lines / i_rows; i_last_row *= p_in->i_lines / i_rows; - if( p_vout->p_sys->b_blackslot == VLC_TRUE - && p_vout->p_sys->b_finished == VLC_FALSE + if( p_vout->p_sys->b_blackslot == true + && p_vout->p_sys->b_finished == false && i == p_vout->p_sys->i_selected ) { uint8_t color = ( i_plane == Y_PLANE ? 0x0 : 0x80 ); for( ; i_row < i_last_row; i_row++, i_orow++ ) { - p_vout->p_libvlc-> - pf_memset( p_out->p_pixels + i_row * i_pitch + vlc_memset( p_out->p_pixels + i_row * i_pitch + i_col * i_pitch / i_cols, color, i_pitch / i_cols ); } @@ -406,8 +402,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { for( ; i_row < i_last_row; i_row++, i_orow++ ) { - p_vout->p_libvlc-> - pf_memcpy( p_out->p_pixels + i_row * i_pitch + vlc_memcpy( p_out->p_pixels + i_row * i_pitch + i_col * i_pitch / i_cols, p_in->p_pixels + i_orow * i_pitch + i_ocol * i_pitch / i_cols, @@ -418,7 +413,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) } if( p_vout->p_sys->i_selected != -1 - && p_vout->p_sys->b_blackslot == VLC_FALSE ) + && p_vout->p_sys->b_blackslot == false ) { plane_t *p_in = p_pic->p+Y_PLANE; plane_t *p_out = p_outpic->p+Y_PLANE; @@ -428,8 +423,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) int i_last_row = i_row + 1; i_row *= p_in->i_lines / i_rows; i_last_row *= p_in->i_lines / i_rows; - p_vout->p_libvlc-> - pf_memset( p_out->p_pixels + i_row * i_pitch + vlc_memset( p_out->p_pixels + i_row * i_pitch + i_col * i_pitch / i_cols, 0xff, i_pitch / i_cols ); for( ; i_row < i_last_row; i_row++ ) @@ -440,13 +434,12 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) + (i_col+1) * i_pitch / i_cols - 1 ] = 0xff; } i_row--; - p_vout->p_libvlc-> - pf_memset( p_out->p_pixels + i_row * i_pitch + vlc_memset( p_out->p_pixels + i_row * i_pitch + i_col * i_pitch / i_cols, 0xff, i_pitch / i_cols ); } - if( p_vout->p_sys->b_finished == VLC_TRUE ) + if( p_vout->p_sys->b_finished == true ) { int i, j; plane_t *p_out = p_outpic->p+Y_PLANE; @@ -470,6 +463,8 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) static int SendEvents( 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(oldval); + var_Set( (vlc_object_t *)p_data, psz_var, newval ); return VLC_SUCCESS; @@ -481,6 +476,7 @@ static int SendEvents( vlc_object_t *p_this, char const *psz_var, static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_data); VLC_UNUSED(oldval); vout_thread_t *p_vout = (vout_thread_t *)p_this; var_Set( p_vout->p_sys->p_vout, psz_var, newval ); return VLC_SUCCESS; @@ -492,6 +488,7 @@ static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var, static int MouseEvent( 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(oldval); VLC_UNUSED(newval); vout_thread_t *p_vout = (vout_thread_t*)p_data; int i_x, i_y; int i_v; @@ -522,7 +519,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, if( mouse & MOUSE_CLICKED ) { i_pos = p_vout->p_sys->i_cols * ( ( p_vout->p_sys->i_rows * i_y ) / v_h ) + (p_vout->p_sys->i_cols * i_x ) / v_w; - if( p_vout->p_sys->b_finished == VLC_TRUE + if( p_vout->p_sys->b_finished == true && i_x < SHUFFLE_WIDTH && i_y < SHUFFLE_HEIGHT ) { shuffle( p_vout->p_sys ); @@ -532,7 +529,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, p_vout->p_sys->i_selected = i_pos; } else if( p_vout->p_sys->i_selected == i_pos - && p_vout->p_sys->b_blackslot == VLC_FALSE ) + && p_vout->p_sys->b_blackslot == false ) { p_vout->p_sys->i_selected = -1; } @@ -547,7 +544,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, p_vout->p_sys->pi_order[ p_vout->p_sys->i_selected ] = p_vout->p_sys->pi_order[ i_pos ]; p_vout->p_sys->pi_order[ i_pos ] = a; - if( p_vout->p_sys->b_blackslot == VLC_TRUE ) + if( p_vout->p_sys->b_blackslot == true ) p_vout->p_sys->i_selected = i_pos; else p_vout->p_sys->i_selected = -1; @@ -562,6 +559,7 @@ static int PuzzleCallback( 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(oldval); vout_sys_t *p_sys = (vout_sys_t *)p_data; if( !strcmp( psz_var, CFG_PREFIX "rows" ) ) {