X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fpuzzle.c;h=5e402c55d3acbd321d60e59dd2faf2b7bcfabde2;hb=a2b72dbb66f9efbff9ff85f04dca60824f0df9db;hp=5097f7ec92197e93ff9b35904de5ab6a69e7b4bb;hpb=806cf5165824be921bf2402ecf11fd3ee6501f9c;p=vlc diff --git a/modules/video_filter/puzzle.c b/modules/video_filter/puzzle.c index 5097f7ec92..5e402c55d3 100644 --- a/modules/video_filter/puzzle.c +++ b/modules/video_filter/puzzle.c @@ -25,7 +25,12 @@ * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include @@ -66,27 +71,24 @@ 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_capability( "video filter", 0 ); - set_category( CAT_VIDEO ); - set_subcategory( SUBCAT_VIDEO_VFILTER ); +vlc_module_begin () + 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 ); - change_safe(); + ROWS_TEXT, ROWS_LONGTEXT, false ) add_integer_with_range( CFG_PREFIX "cols", 4, 1, 128, NULL, - COLS_TEXT, COLS_LONGTEXT, VLC_FALSE ); - change_safe(); + COLS_TEXT, COLS_LONGTEXT, false ) add_bool( CFG_PREFIX "black-slot", 0, NULL, - BLACKSLOT_TEXT, BLACKSLOT_LONGTEXT, VLC_FALSE ); - change_safe(); + BLACKSLOT_TEXT, BLACKSLOT_LONGTEXT, false ) - set_callbacks( Create, Destroy ); -vlc_module_end(); + 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 }; @@ -103,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; }; /***************************************************************************** @@ -119,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 ) @@ -146,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 ) { @@ -171,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++ ) { @@ -202,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 ); @@ -290,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 ; ) { @@ -300,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 @@ -328,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 ); } @@ -363,14 +359,14 @@ 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; } msleep( VOUT_OUTMEM_SLEEP ); } - vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date ); + p_outpic->date = p_pic->date; for( i_plane = 0; i_plane < p_outpic->i_planes; i_plane++ ) { @@ -390,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 ); } @@ -407,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, @@ -419,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; @@ -429,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++ ) @@ -441,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; @@ -471,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; @@ -482,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; @@ -493,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; @@ -523,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 ); @@ -533,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; } @@ -548,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; @@ -563,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" ) ) {