X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fpuzzle.c;h=5e402c55d3acbd321d60e59dd2faf2b7bcfabde2;hb=a2b72dbb66f9efbff9ff85f04dca60824f0df9db;hp=27ce25bc56f307144fb479252da04e14bd762823;hpb=9ce72981b5df1177e9e1b701698e992ca4437b0e;p=vlc diff --git a/modules/video_filter/puzzle.c b/modules/video_filter/puzzle.c index 27ce25bc56..5e402c55d3 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 @@ -52,6 +55,9 @@ static int SendEvents ( vlc_object_t *, char const *, static int MouseEvent ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); +static int PuzzleCallback( vlc_object_t *, char const *, + vlc_value_t, vlc_value_t, void * ); + /***************************************************************************** * Module descriptor *****************************************************************************/ @@ -63,22 +69,28 @@ static int MouseEvent ( vlc_object_t *, char const *, #define BLACKSLOT_TEXT N_("Make one tile a black slot") #define BLACKSLOT_LONGTEXT N_("Make one slot black. Other tiles can only be swapped with the black slot.") -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 ); +#define CFG_PREFIX "puzzle-" + +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( "puzzle-rows", 4, 1, 128, NULL, - ROWS_TEXT, ROWS_LONGTEXT, VLC_FALSE ); - add_integer_with_range( "puzzle-cols", 4, 1, 128, NULL, - COLS_TEXT, COLS_LONGTEXT, VLC_FALSE ); - add_bool( "puzzle-black-slot", 0, NULL, - BLACKSLOT_TEXT, BLACKSLOT_LONGTEXT, VLC_FALSE ); + add_integer_with_range( CFG_PREFIX "rows", 4, 1, 128, NULL, + ROWS_TEXT, ROWS_LONGTEXT, false ) + add_integer_with_range( CFG_PREFIX "cols", 4, 1, 128, NULL, + COLS_TEXT, COLS_LONGTEXT, false ) + add_bool( CFG_PREFIX "black-slot", 0, NULL, + BLACKSLOT_TEXT, BLACKSLOT_LONGTEXT, false ) - set_callbacks( Create, Destroy ); -vlc_module_end(); + set_callbacks( Create, Destroy ) +vlc_module_end () + +static const char *const ppsz_filter_options[] = { + "rows", "cols", "black-slot", NULL +}; /***************************************************************************** * vout_sys_t: Magnify video output method descriptor @@ -93,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; }; /***************************************************************************** @@ -109,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 ) @@ -136,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 ) { @@ -161,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++ ) { @@ -192,16 +204,25 @@ 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 ); - p_vout->p_sys->i_rows = config_GetInt( p_vout, "puzzle-rows" ); - p_vout->p_sys->i_cols = config_GetInt( p_vout, "puzzle-cols" ); - p_vout->p_sys->b_blackslot = config_GetInt( p_vout, "puzzle-black-slot" ); + config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options, + p_vout->p_cfg ); + + p_vout->p_sys->i_rows = + var_CreateGetIntegerCommand( p_vout, CFG_PREFIX "rows" ); + p_vout->p_sys->i_cols = + var_CreateGetIntegerCommand( p_vout, CFG_PREFIX "cols" ); + p_vout->p_sys->b_blackslot = + var_CreateGetBoolCommand( p_vout, CFG_PREFIX "black-slot" ); + var_AddCallback( p_vout, CFG_PREFIX "rows", + PuzzleCallback, p_vout->p_sys ); + var_AddCallback( p_vout, CFG_PREFIX "cols", + PuzzleCallback, p_vout->p_sys ); + var_AddCallback( p_vout, CFG_PREFIX "black-slot", + PuzzleCallback, p_vout->p_sys ); p_vout->p_sys->pi_order = NULL; shuffle( p_vout->p_sys ); @@ -223,7 +244,8 @@ static int Init( vout_thread_t *p_vout ) { int i_index; picture_t *p_pic; - video_format_t fmt = {0}; + video_format_t fmt; + memset( &fmt, 0, sizeof( video_format_t ) ); I_OUTPUTPICTURES = 0; @@ -267,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 ; ) { @@ -277,11 +303,13 @@ 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 #define SHUFFLE_HEIGHT 13 -static char *shuffle_button[] = +static const char *shuffle_button[] = { ".................................................................................", ".............. ............................ ........ ...... ...............", @@ -305,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 ); } @@ -327,7 +346,8 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) { picture_t *p_outpic; - //video_format_t fmt_out = {0}; + //video_format_t fmt_out; + // memset( &fmt_out, 0, sizeof(video_format_t) ); //picture_t *p_converted; int i_plane; @@ -339,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++ ) { @@ -366,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 ); } @@ -383,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, @@ -395,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; @@ -405,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++ ) @@ -417,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; @@ -447,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; @@ -458,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; @@ -469,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; @@ -499,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 ); @@ -509,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; } @@ -524,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; @@ -534,3 +554,25 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, } return VLC_SUCCESS; } + +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" ) ) + { + p_sys->i_rows = __MAX( 1, newval.i_int ); + } + else if( !strcmp( psz_var, CFG_PREFIX "cols" ) ) + { + p_sys->i_cols = __MAX( 1, newval.i_int ); + } + else if( !strcmp( psz_var, CFG_PREFIX "black-slot" ) ) + { + p_sys->b_blackslot = newval.b_bool; + } + shuffle( p_sys ); + return VLC_SUCCESS; +}