- vlc_bool_t b_finished;
-
- vlc_bool_t b_blackslot;
-};
-
-/*****************************************************************************
- * Control: control facility for the vout (forwards to child vout)
- *****************************************************************************/
-static int Control( vout_thread_t *p_vout, int i_query, va_list args )
-{
- return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
-}
-
-/*****************************************************************************
- * Misc stuff...
- *****************************************************************************/
-static vlc_bool_t 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;
- }
- return VLC_TRUE;
-}
-static vlc_bool_t is_valid( vout_sys_t *p_sys )
-{
- int i, j, d=0;
- if( p_sys->b_blackslot == VLC_FALSE ) return VLC_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 )
- {
- d += i / p_sys->i_cols + 1;
- continue;
- }
- for( j = i+1; j < p_sys->i_cols * p_sys->i_rows; j++ )
- {
- if( p_sys->pi_order[j] == p_sys->i_cols * p_sys->i_rows - 1 )
- continue;
- if( p_sys->pi_order[i] > p_sys->pi_order[j] ) d++;
- }
- }
- if( d%2!=0 ) return VLC_FALSE;
- else return VLC_TRUE;
-}
-static void shuffle( vout_sys_t *p_sys )
-{
- int i, c;
- free( p_sys->pi_order );
- p_sys->pi_order = malloc( p_sys->i_cols * p_sys->i_rows * sizeof( int ) );
- do
- {
- for( i = 0; i < p_sys->i_cols * p_sys->i_rows; i++ )
- {
- p_sys->pi_order[i] = -1;
- }
- i = 0;
- for( c = 0; c < p_sys->i_cols * p_sys->i_rows; )
- {
- i = rand()%( p_sys->i_cols * p_sys->i_rows );
- if( p_sys->pi_order[i] == -1 )
- {
- p_sys->pi_order[i] = c;
- c++;
- }
- }
- p_sys->b_finished = finished( p_sys );
- } while( p_sys->b_finished == VLC_TRUE
- || is_valid( p_sys ) == VLC_FALSE );
-
- if( p_sys->b_blackslot == VLC_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 )
- {
- p_sys->i_selected = i;
- break;
- }
- }
- }
- else
- {
- p_sys->i_selected = -1;
- }
-}
-
-/*****************************************************************************
- * Create: allocates Magnify video thread output method
- *****************************************************************************/
-static int Create( vlc_object_t *p_this )
-{
- vout_thread_t *p_vout = (vout_thread_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 );
-
- 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 );
-
- p_vout->pf_init = Init;
- p_vout->pf_end = End;
- p_vout->pf_manage = NULL;
- p_vout->pf_render = Render;
- p_vout->pf_display = NULL;
- p_vout->pf_control = Control;
-
- return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Init: initialize Magnify video thread output method
- *****************************************************************************/
-static int Init( vout_thread_t *p_vout )
-{
- int i_index;
- picture_t *p_pic;
- video_format_t fmt;
- memset( &fmt, 0, sizeof( video_format_t ) );
-
- I_OUTPUTPICTURES = 0;
-
- /* Initialize the output structure */
- p_vout->output.i_chroma = p_vout->render.i_chroma;
- p_vout->output.i_width = p_vout->render.i_width;
- p_vout->output.i_height = p_vout->render.i_height;
- p_vout->output.i_aspect = p_vout->render.i_aspect;