]> git.sesse.net Git - vlc/blobdiff - plugins/sdl/vout_sdl.c
* ./extras/MacOSX_dvdioctl: removed outdated files.
[vlc] / plugins / sdl / vout_sdl.c
index ec21d18476f062f09df8fa9f4bb3281a51c2b769..8a1e4e34741f6d19bdbb813e21a5d746d5b7f9d7 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * vout_sdl.c: SDL video output display method
  *****************************************************************************
- * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: vout_sdl.c,v 1.63 2001/09/26 12:32:25 massiot Exp $
+ * Copyright (C) 1998-2001 VideoLAN
+ * $Id: vout_sdl.c,v 1.85 2002/03/18 19:14:52 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Pierre Baillet <oct@zoy.org>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#define MODULE_NAME sdl
-#include "modules_inner.h"
-
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
 #include <errno.h>                                                 /* ENOMEM */
 #include <stdlib.h>                                                /* free() */
 #include <string.h>                                            /* strerror() */
 
+#include <videolan/vlc.h>
+
 #include <sys/types.h>
 #ifndef WIN32
 #   include <netinet/in.h>                            /* BSD: struct in_addr */
 
 #include SDL_INCLUDE_FILE
 
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
-#include "tests.h"
+#include "netutils.h"
 
 #include "video.h"
 #include "video_output.h"
 
-#include "intf_msg.h"
 #include "interface.h"
-/* FIXME: get rid of this */
-#include "keystrokes.h"
-#include "main.h"
-#include "netutils.h"
 
-#include "modules.h"
-#include "modules_export.h"
+#include "stream_control.h"                 /* needed by input_ext-intf.h... */
+#include "input_ext-intf.h"
 
-/*****************************************************************************
- * FIXME: this file is ...                                                   *
- *                                                                           *
- *              XXX   XXX     FIXME     XXX     XXX   XXX   XXX              *
- *              XXX   XXX   XXX   XXX   XXX     XXX   XXX   XXX              *
- *              XXX   XXX   XXX         XXX       FIXME     XXX              *
- *              XXX   XXX   XXX  TODO   XXX        XXX      XXX              *
- *              XXX   XXX   XXX   XXX   XXX        XXX                       *
- *                FIXME       FIXME       FIXME    XXX      XXX              *
- *                                                                           *
- *****************************************************************************/
+#define SDL_MAX_DIRECTBUFFERS 10
+#define SDL_DEFAULT_BPP 16
 
 /*****************************************************************************
  * vout_sys_t: video output SDL method descriptor
  *****************************************************************************/
 typedef struct vout_sys_s
 {
+    SDL_Surface *   p_display;                             /* display device */
+
     int i_width;
     int i_height;
 
-    SDL_Surface *   p_display;                             /* display device */
-    SDL_Overlay *   p_overlay;                             /* overlay device */
+    /* For YUV output */
+    SDL_Overlay * p_overlay;   /* An overlay we keep to grab the XVideo port */
 
-    boolean_t   b_overlay;
-    boolean_t   b_cursor;
-    boolean_t   b_reopen_display;
+    /* For RGB output */
+    int i_surfaces;
 
+    boolean_t   b_cursor;
     boolean_t   b_cursor_autohidden;
     mtime_t     i_lastmoved;
 
-    Uint8   *   p_sdl_buf[2];                          /* Buffer information */
-
 } vout_sys_t;
 
+/*****************************************************************************
+ * picture_sys_t: direct buffer method descriptor
+ *****************************************************************************
+ * This structure is part of the picture descriptor, it describes the
+ * SDL specific properties of a direct buffer.
+ *****************************************************************************/
+typedef struct picture_sys_s
+{
+    SDL_Overlay *p_overlay;
+
+} picture_sys_t;
+
+/*****************************************************************************
+ * Seeking function TODO: put this in a generic location !
+ *****************************************************************************/
+static __inline__ void vout_Seek( off_t i_seek )
+{
+    off_t i_tell;
+
+    vlc_mutex_lock( &p_input_bank->lock );
+    if( p_input_bank->pp_input[0] != NULL )
+    {
+#define S p_input_bank->pp_input[0]->stream
+        i_tell = S.p_selected_area->i_tell + i_seek * (off_t)50 * S.i_mux_rate;
+
+        i_tell = ( i_tell <= 0 /*S.p_selected_area->i_start*/ )
+                   ? 0 /*S.p_selected_area->i_start*/
+                   : ( i_tell >= S.p_selected_area->i_size )
+                       ? S.p_selected_area->i_size
+                       : i_tell;
+
+        input_Seek( p_input_bank->pp_input[0], i_tell );
+#undef S
+    }
+    vlc_mutex_unlock( &p_input_bank->lock );
+}
+
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static int  vout_Probe     ( probedata_t *p_data );
-static int  vout_Create    ( struct vout_thread_s * );
-static int  vout_Init      ( struct vout_thread_s * );
-static void vout_End       ( struct vout_thread_s * );
-static void vout_Destroy   ( struct vout_thread_s * );
-static int  vout_Manage    ( struct vout_thread_s * );
-static void vout_Display   ( struct vout_thread_s * );
-static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
-                             u16 *blue, u16 *transp );
-
-static int  SDLOpenDisplay     ( vout_thread_t *p_vout );
-static void SDLCloseDisplay    ( vout_thread_t *p_vout );
-static void OutputCoords       ( const picture_t *p_pic, const boolean_t scale,
-                                 const int win_w, const int win_h,
-                                 int *dx, int *dy, int *w, int *h );
+static int  vout_Create     ( struct vout_thread_s * );
+static int  vout_Init       ( struct vout_thread_s * );
+static void vout_End        ( struct vout_thread_s * );
+static void vout_Destroy    ( struct vout_thread_s * );
+static int  vout_Manage     ( struct vout_thread_s * );
+static void vout_Render     ( struct vout_thread_s *, struct picture_s * );
+static void vout_Display    ( struct vout_thread_s *, struct picture_s * );
+
+static int  OpenDisplay     ( struct vout_thread_s * );
+static void CloseDisplay    ( struct vout_thread_s * );
+static int  NewPicture      ( struct vout_thread_s *, struct picture_s * );
+static void SetPalette      ( struct vout_thread_s *, u16 *, u16 *, u16 * );
 
 /*****************************************************************************
  * Functions exported as capabilities. They are declared as static so that
@@ -123,30 +136,13 @@ static void OutputCoords       ( const picture_t *p_pic, const boolean_t scale,
  *****************************************************************************/
 void _M( vout_getfunctions )( function_list_t * p_function_list )
 {
-    p_function_list->pf_probe = vout_Probe;
     p_function_list->functions.vout.pf_create     = vout_Create;
     p_function_list->functions.vout.pf_init       = vout_Init;
     p_function_list->functions.vout.pf_end        = vout_End;
     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
     p_function_list->functions.vout.pf_manage     = vout_Manage;
+    p_function_list->functions.vout.pf_render     = vout_Render;
     p_function_list->functions.vout.pf_display    = vout_Display;
-    p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
-}
-
-/*****************************************************************************
- * vout_Probe: probe the video driver and return a score
- *****************************************************************************
- * This function tries to initialize SDL and returns a score to the
- * plugin manager so that it can select the best plugin.
- *****************************************************************************/
-static int vout_Probe( probedata_t *p_data )
-{
-    if( TestMethod( VOUT_METHOD_VAR, "sdl" ) )
-    {
-        return( 999 );
-    }
-
-    return( 100 );
 }
 
 /*****************************************************************************
@@ -158,6 +154,13 @@ static int vout_Probe( probedata_t *p_data )
  *****************************************************************************/
 static int vout_Create( vout_thread_t *p_vout )
 {
+    char *psz_method;
+
+    if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
+    {
+        return( 1 );
+    }
+
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
@@ -166,6 +169,20 @@ static int vout_Create( vout_thread_t *p_vout )
         return( 1 );
     }
 
+    psz_method = config_GetPszVariable( "vout" );
+    if( psz_method )
+    {
+        while( *psz_method && *psz_method != ':' )
+        {
+            psz_method++;
+        }
+
+        if( *psz_method )
+        {
+            setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
+        }
+    }
+
     /* Initialize library */
     if( SDL_Init( SDL_INIT_VIDEO
 #ifndef WIN32
@@ -184,55 +201,45 @@ static int vout_Create( vout_thread_t *p_vout )
         return( 1 );
     }
 
-    p_vout->p_sys->b_cursor = 1; /* TODO should be done with a main_GetInt.. */
-
+    p_vout->p_sys->b_cursor = 1;
     p_vout->p_sys->b_cursor_autohidden = 0;
     p_vout->p_sys->i_lastmoved = mdate();
 
-    p_vout->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
-                                VOUT_FULLSCREEN_DEFAULT );
-    p_vout->p_sys->b_overlay = main_GetIntVariable( VOUT_OVERLAY_VAR,
-                                VOUT_OVERLAY_DEFAULT );
-    p_vout->p_sys->i_width = p_vout->i_width;
-    p_vout->p_sys->i_height = p_vout->i_height;
+    if( p_vout->render.i_height * p_vout->render.i_aspect
+         >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
+    {
+        p_vout->p_sys->i_width = p_vout->render.i_height
+            * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
+        p_vout->p_sys->i_height = p_vout->render.i_height;
+    }
+    else
+    {
+        p_vout->p_sys->i_width = p_vout->render.i_width;
+        p_vout->p_sys->i_height = p_vout->render.i_width
+            * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;
+    }
 
-    p_vout->p_sys->p_display = NULL;
-    p_vout->p_sys->p_overlay = NULL;
+#if 0
+    if( p_vout->p_sys->i_width <= 300 && p_vout->p_sys->i_height <= 300 )
+    {
+        p_vout->p_sys->i_width <<= 1;
+        p_vout->p_sys->i_height <<= 1;
+    }
+    else if( p_vout->p_sys->i_width <= 400 && p_vout->p_sys->i_height <= 400 )
+    {
+        p_vout->p_sys->i_width += p_vout->p_sys->i_width >> 1;
+        p_vout->p_sys->i_height += p_vout->p_sys->i_height >> 1;
+    }
+#endif
 
-    if( SDLOpenDisplay(p_vout) )
+    if( OpenDisplay( p_vout ) )
     {
         intf_ErrMsg( "vout error: can't set up SDL (%s)", SDL_GetError() );
+        SDL_QuitSubSystem( SDL_INIT_VIDEO );
         free( p_vout->p_sys );
         return( 1 );
     }
 
-    /* FIXME: get rid of this ASAP, it's FUCKING UGLY */
-    { intf_thread_t * p_intf = p_main->p_intf;
-    intf_AssignKey(p_intf, SDLK_q,      INTF_KEY_QUIT, 0);
-    intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
-    /* intf_AssignKey(p_intf,3,'Q'); */
-    intf_AssignKey(p_intf, SDLK_0,      INTF_KEY_SET_CHANNEL,0);
-    intf_AssignKey(p_intf, SDLK_1,      INTF_KEY_SET_CHANNEL,1);
-    intf_AssignKey(p_intf, SDLK_2,      INTF_KEY_SET_CHANNEL,2);
-    intf_AssignKey(p_intf, SDLK_3,      INTF_KEY_SET_CHANNEL,3);
-    intf_AssignKey(p_intf, SDLK_4,      INTF_KEY_SET_CHANNEL,4);
-    intf_AssignKey(p_intf, SDLK_5,      INTF_KEY_SET_CHANNEL,5);
-    intf_AssignKey(p_intf, SDLK_6,      INTF_KEY_SET_CHANNEL,6);
-    intf_AssignKey(p_intf, SDLK_7,      INTF_KEY_SET_CHANNEL,7);
-    intf_AssignKey(p_intf, SDLK_8,      INTF_KEY_SET_CHANNEL,8);
-    intf_AssignKey(p_intf, SDLK_9,      INTF_KEY_SET_CHANNEL,9);
-    intf_AssignKey(p_intf, SDLK_PLUS,   INTF_KEY_INC_VOLUME, 0);
-    intf_AssignKey(p_intf, SDLK_MINUS,  INTF_KEY_DEC_VOLUME, 0);
-    intf_AssignKey(p_intf, SDLK_m,      INTF_KEY_TOGGLE_VOLUME, 0);
-    /* intf_AssignKey(p_intf,'M','M'); */
-    intf_AssignKey(p_intf, SDLK_g,      INTF_KEY_DEC_GAMMA, 0);
-    /* intf_AssignKey(p_intf,'G','G'); */
-    intf_AssignKey(p_intf, SDLK_c,      INTF_KEY_TOGGLE_GRAYSCALE, 0);
-    intf_AssignKey(p_intf, SDLK_SPACE,  INTF_KEY_TOGGLE_INTERFACE, 0);
-    intf_AssignKey(p_intf, SDLK_i,      INTF_KEY_TOGGLE_INFO, 0);
-    intf_AssignKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, 0);
-    intf_AssignKey(p_intf, SDLK_d,      INTF_KEY_DUMP_STREAM, 0); }
-
     return( 0 );
 }
 
@@ -243,28 +250,60 @@ static int vout_Create( vout_thread_t *p_vout )
  *****************************************************************************/
 static int vout_Init( vout_thread_t *p_vout )
 {
-    /* This hack is hugly, but hey, you are, too. */
+    int i_index;
+    picture_t *p_pic;
 
-    SDL_Overlay *   p_overlay;
-    
-    p_overlay = SDL_CreateYUVOverlay( 
-           main_GetIntVariable( VOUT_WIDTH_VAR,VOUT_WIDTH_DEFAULT ),
-           main_GetIntVariable( VOUT_HEIGHT_VAR,VOUT_HEIGHT_DEFAULT ),
-                                      SDL_YV12_OVERLAY, 
-                                      p_vout->p_sys->p_display );
+    p_vout->p_sys->i_surfaces = 0;
 
-    if( p_overlay == NULL )
+    I_OUTPUTPICTURES = 0;
+
+    /* Initialize the output structure */
+    if( p_vout->p_sys->p_overlay == NULL )
+    {
+        /* All we have is an RGB image with square pixels */
+        p_vout->output.i_width  = p_vout->p_sys->i_width;
+        p_vout->output.i_height = p_vout->p_sys->i_height;
+        p_vout->output.i_aspect = p_vout->p_sys->i_width
+                                   * VOUT_ASPECT_FACTOR
+                                   / p_vout->p_sys->i_height;
+    }
+    else
     {
-        intf_ErrMsg( "vout error: could not create SDL overlay" );
-        p_vout->b_need_render = 1;
-        return( 0 );
+        /* We may need to convert the chroma, but at least we keep the
+         * aspect ratio */
+        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;
     }
 
-    intf_WarnMsg( 2, "vout: YUV acceleration %s",
-              p_overlay->hw_overlay ? "activated" : "unavailable !" ); 
-    p_vout->b_need_render = !p_overlay->hw_overlay;
+    /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
+    while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
+    {
+        p_pic = NULL;
 
-    SDL_FreeYUVOverlay( p_overlay );
+        /* Find an empty picture slot */
+        for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
+        {
+            if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
+            {
+                p_pic = p_vout->p_picture + i_index;
+                break;
+            }
+        }
+
+        /* Allocate the picture if we found one */
+        if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
+        {
+            break;
+        }
+
+        p_pic->i_status = DESTROYED_PICTURE;
+        p_pic->i_type   = DIRECT_PICTURE;
+
+        PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
+
+        I_OUTPUTPICTURES++;
+    }
 
     return( 0 );
 }
@@ -276,8 +315,25 @@ static int vout_Init( vout_thread_t *p_vout )
  *****************************************************************************/
 static void vout_End( vout_thread_t *p_vout )
 {
-    SDLCloseDisplay( p_vout );
-    SDL_QuitSubSystem( SDL_INIT_VIDEO );
+    int i_index;
+
+    /* Free the output buffers we allocated */
+    for( i_index = I_OUTPUTPICTURES ; i_index ; )
+    {
+        i_index--;
+        if( p_vout->p_sys->p_overlay == NULL )
+        {
+            /* RGB picture */
+        }
+        else
+        {
+            SDL_UnlockYUVOverlay(
+                    PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
+            SDL_FreeYUVOverlay(
+                    PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
+        }
+        free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
+    }
 }
 
 /*****************************************************************************
@@ -287,6 +343,10 @@ static void vout_End( vout_thread_t *p_vout )
  *****************************************************************************/
 static void vout_Destroy( vout_thread_t *p_vout )
 {
+    CloseDisplay( p_vout );
+
+    SDL_QuitSubSystem( SDL_INIT_VIDEO );
+
     free( p_vout->p_sys );
 }
 
@@ -299,7 +359,6 @@ static void vout_Destroy( vout_thread_t *p_vout )
 static int vout_Manage( vout_thread_t *p_vout )
 {
     SDL_Event event;                                            /* SDL event */
-    char *    p_key;
 
     /* Process events */
     while( SDL_PollEvent(&event) )
@@ -307,9 +366,10 @@ static int vout_Manage( vout_thread_t *p_vout )
         switch( event.type )
         {
         case SDL_VIDEORESIZE:                          /* Resizing of window */
-            p_vout->i_width = event.resize.w;
-            p_vout->i_height = event.resize.h;
-            p_vout->i_changes |= VOUT_SIZE_CHANGE;
+            p_vout->p_sys->i_width = event.resize.w;
+            p_vout->p_sys->i_height = event.resize.h;
+            CloseDisplay( p_vout );
+            OpenDisplay( p_vout );
             break;
 
         case SDL_MOUSEMOTION:
@@ -340,26 +400,39 @@ static int vout_Manage( vout_thread_t *p_vout )
         case SDL_MOUSEBUTTONDOWN:
             switch( event.button.button )
             {
-            case SDL_BUTTON_MIDDLE:
-                p_vout->i_changes |= VOUT_CURSOR_CHANGE;
+            case SDL_BUTTON_LEFT:
+                /* In this part we will eventually manage
+                 * clicks for DVD navigation for instance. For the
+                 * moment just pause the stream. */
+                input_SetStatus( p_input_bank->pp_input[0],
+                                 INPUT_STATUS_PAUSE );
+                break;
+
+            case 4:
+                vout_Seek( 15 );
+                break;
+
+            case 5:
+                vout_Seek( -15 );
                 break;
             }
             break;
 
         case SDL_QUIT:
-            intf_ProcessKey( p_main->p_intf, SDLK_q );
+            p_main->p_intf->b_die = 1;
             break;
 
         case SDL_KEYDOWN:                             /* if a key is pressed */
 
             switch( event.key.keysym.sym )
             {
-            case SDLK_f:                             /* switch to fullscreen */
-                p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
+            case SDLK_q:                                             /* quit */
+            case SDLK_ESCAPE:
+                p_main->p_intf->b_die = 1;
                 break;
 
-            case SDLK_y:                               /* switch to hard YUV */
-                p_vout->i_changes |= VOUT_YUV_CHANGE;
+            case SDLK_f:                             /* switch to fullscreen */
+                p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
                 break;
 
             case SDLK_c:                                 /* toggle grayscale */
@@ -382,50 +455,38 @@ static int vout_Manage( vout_thread_t *p_vout )
                 p_vout->i_changes |= VOUT_INTF_CHANGE;
                 break;
             
-            case SDLK_F10:
-                network_ChannelJoin( 0 );
-                break;
-            case SDLK_F1:
-                network_ChannelJoin( 1 );
-                break;
-            case SDLK_F2:
-                network_ChannelJoin( 2 );
-                break;
-            case SDLK_F3:
-                network_ChannelJoin( 3 );
-                break;
-            case SDLK_F4:
-                network_ChannelJoin( 4 );
-                break;
-            case SDLK_F5:
-                network_ChannelJoin( 5 );
-                break;
-            case SDLK_F6:
-                network_ChannelJoin( 6 );
+            case SDLK_MENU:
+                p_main->p_intf->b_menu_change = 1;
                 break;
-            case SDLK_F7:
-                network_ChannelJoin( 7 );
+
+            case SDLK_LEFT:
+                vout_Seek( -5 );
                 break;
-            case SDLK_F8:
-                network_ChannelJoin( 8 );
+
+            case SDLK_RIGHT:
+                vout_Seek( 5 );
                 break;
-            case SDLK_F9:
-                network_ChannelJoin( 9 );
+
+            case SDLK_UP:
+                vout_Seek( 60 );
                 break;
 
-            case SDLK_MENU:
-                p_main->p_intf->b_menu_change = 1;
+            case SDLK_DOWN:
+                vout_Seek( -60 );
                 break;
-                
+
+            case SDLK_F10: network_ChannelJoin( 0 ); break;
+            case SDLK_F1:  network_ChannelJoin( 1 ); break;
+            case SDLK_F2:  network_ChannelJoin( 2 ); break;
+            case SDLK_F3:  network_ChannelJoin( 3 ); break;
+            case SDLK_F4:  network_ChannelJoin( 4 ); break;
+            case SDLK_F5:  network_ChannelJoin( 5 ); break;
+            case SDLK_F6:  network_ChannelJoin( 6 ); break;
+            case SDLK_F7:  network_ChannelJoin( 7 ); break;
+            case SDLK_F8:  network_ChannelJoin( 8 ); break;
+            case SDLK_F9:  network_ChannelJoin( 9 ); break;
+
             default:
-                p_key = SDL_GetKeyName( event.key.keysym.sym ) ;
-                if( intf_ProcessKey( p_main->p_intf, 
-                                     (char )event.key.keysym.sym ) )
-                {
-                   intf_DbgMsg( "unhandled key '%c' (%i)", 
-                                (char)event.key.keysym.sym, 
-                                event.key.keysym.sym );                
-                }
                 break;
             }
             break;
@@ -435,44 +496,7 @@ static int vout_Manage( vout_thread_t *p_vout )
         }
     }
 
-    /*
-     * Size Change 
-     */
-    if( p_vout->i_changes & VOUT_SIZE_CHANGE )
-    {
-        p_vout->p_sys->i_width = p_vout->i_width;
-        p_vout->p_sys->i_height = p_vout->i_height;
-
-        /* Need to reopen display */
-        SDLCloseDisplay( p_vout );
-        if( SDLOpenDisplay( p_vout ) )
-        {
-          intf_ErrMsg( "vout error: can't reopen display after resize" );
-          return( 1 );
-        }
-        p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
-    }
-    
-    /*
-     * YUV Change 
-     */
-    if( p_vout->i_changes & VOUT_YUV_CHANGE )
-    {
-        p_vout->b_need_render = ! p_vout->b_need_render;
-        
-        /* Need to reopen display */
-        SDLCloseDisplay( p_vout );
-        if( SDLOpenDisplay( p_vout ) )
-        {
-          intf_ErrMsg( "error: can't reopen display after YUV change" );
-          return( 1 );
-        }
-        p_vout->i_changes &= ~VOUT_YUV_CHANGE;
-    }
-
-    /*
-     * Fullscreen change
-     */
+    /* Fullscreen change */
     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
     {
         p_vout->b_fullscreen = ! p_vout->b_fullscreen;
@@ -486,9 +510,7 @@ static int vout_Manage( vout_thread_t *p_vout )
         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
     }
 
-    /*
-     * Pointer change
-     */
+    /* Pointer change */
     if( ! p_vout->p_sys->b_cursor_autohidden &&
         ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
     {
@@ -497,337 +519,371 @@ static int vout_Manage( vout_thread_t *p_vout )
         SDL_ShowCursor( 0 );
     }
 
-    if( p_vout->i_changes & VOUT_CURSOR_CHANGE )
-    {
-        p_vout->p_sys->b_cursor = ! p_vout->p_sys->b_cursor;
-
-        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
-                        ! p_vout->p_sys->b_cursor_autohidden );
-
-        p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
-    }
-    
     return( 0 );
 }
 
 /*****************************************************************************
- * vout_SetPalette: sets an 8 bpp palette
- *****************************************************************************
- * This function sets the palette given as an argument. It does not return
- * anything, but could later send information on which colors it was unable
- * to set.
+ * vout_Render: render previously calculated output
  *****************************************************************************/
-static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
-                         u16 *blue, u16 *transp)
+static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
 {
-     /* Create a display surface with a grayscale palette */
-    SDL_Color colors[256];
-    int i;
-  
-    /* Fill colors with color information */
-    for( i = 0; i < 256; i++ )
-    {
-        colors[ i ].r = red[ i ] >> 8;
-        colors[ i ].g = green[ i ] >> 8;
-        colors[ i ].b = blue[ i ] >> 8;
-    }
-
-    /* Set palette */
-    if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
-    {
-        intf_ErrMsg( "vout error: failed setting palette" );
-    }
-
+    ;
 }
 
 /*****************************************************************************
  * vout_Display: displays previously rendered output
  *****************************************************************************
- * This function send the currently rendered image to the display, wait until
- * it is displayed and switch the two rendering buffer, preparing next frame.
+ * This function sends the currently rendered image to the display.
  *****************************************************************************/
-static void vout_Display( vout_thread_t *p_vout )
+static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
 {
-    SDL_Rect    disp;
+    int x, y, w, h;
+    SDL_Rect disp;
 
-    if((p_vout->p_sys->p_display != NULL) && !p_vout->p_sys->b_reopen_display)
-    {
-        if( !p_vout->b_need_render )
-        {
-            /*
-             * p_vout->p_rendered_pic->p_y/u/v contains the YUV buffers to
-             * render 
-             */
-            /* TODO: support for streams other than 4:2:0 */
-            /* create the overlay if necessary */
-            if( p_vout->p_sys->p_overlay == NULL )
-            {
-                p_vout->p_sys->p_overlay = SDL_CreateYUVOverlay( 
-                                             p_vout->p_rendered_pic->i_width, 
-                                             p_vout->p_rendered_pic->i_height,
-                                             SDL_YV12_OVERLAY, 
-                                             p_vout->p_sys->p_display );
+    vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
+                       &x, &y, &w, &h );
+    disp.x = x;
+    disp.y = y;
+    disp.w = w;
+    disp.h = h;
 
-                if( p_vout->p_sys->p_overlay != NULL )
-                {
-                    intf_WarnMsg( 2, "vout: YUV acceleration %s",
-                                  p_vout->p_sys->p_overlay->hw_overlay
-                                   ? "activated" : "unavailable !" ); 
-                }
-            }
-
-            if( p_vout->p_sys->p_overlay == NULL )
-            {
-                /* Overlay allocation failed, switch back to software mode */
-                intf_ErrMsg( "vout error: could not create SDL overlay" );
-                p_vout->b_need_render = 1;
-            }
-            else
-            {
-                int i_x, i_y, i_w, i_h;
-
-                SDL_LockYUVOverlay( p_vout->p_sys->p_overlay );
-                /* copy the data into video buffers */
-                /* Y first */
-                memcpy( p_vout->p_sys->p_overlay->pixels[0],
-                        p_vout->p_rendered_pic->p_y,
-                        p_vout->p_sys->p_overlay->h *
-                        p_vout->p_sys->p_overlay->pitches[0] );
-                /* then V */
-                memcpy( p_vout->p_sys->p_overlay->pixels[1],
-                        p_vout->p_rendered_pic->p_v,
-                        p_vout->p_sys->p_overlay->h *
-                        p_vout->p_sys->p_overlay->pitches[1] / 2 );
-                /* and U */
-                memcpy( p_vout->p_sys->p_overlay->pixels[2],
-                        p_vout->p_rendered_pic->p_u,
-                        p_vout->p_sys->p_overlay->h *
-                        p_vout->p_sys->p_overlay->pitches[2] / 2 );
-
-                OutputCoords( p_vout->p_rendered_pic, 1,
-                              p_vout->p_sys->i_width,
-                              p_vout->p_sys->i_height,
-                              &i_x, &i_y,
-                              &i_w, &i_h);
-                disp.x = i_x;
-                disp.y = i_y;
-                disp.w = i_w;
-                disp.h = i_h;
-
-                SDL_DisplayYUVOverlay( p_vout->p_sys->p_overlay , &disp );
-                SDL_UnlockYUVOverlay(p_vout->p_sys->p_overlay);
-
-                return;
-            }
-        }
-    
-        /* Software YUV: change display frame */
+    if( p_vout->p_sys->p_overlay == NULL )
+    {
+        /* RGB picture */
         SDL_Flip( p_vout->p_sys->p_display );
     }
+    else
+    {
+        /* Overlay picture */
+        SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
+        SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
+        SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
+    }
 }
 
 /* following functions are local */
 
 /*****************************************************************************
- * SDLOpenDisplay: open and initialize SDL device
+ * OpenDisplay: open and initialize SDL device
  *****************************************************************************
  * Open and initialize display according to preferences specified in the vout
  * thread fields.
  *****************************************************************************/
-static int SDLOpenDisplay( vout_thread_t *p_vout )
+static int OpenDisplay( vout_thread_t *p_vout )
 {
-    SDL_Rect    clipping_rect;
-    Uint32      flags;
-    int bpp;
-    /* Open display 
-     * TODO: Check that we can request for a DOUBLEBUF HWSURFACE display
-     */
+    Uint32 i_flags;
+    int    i_bpp;
 
-    /* init flags and cursor */
-    flags = SDL_ANYFORMAT | SDL_HWPALETTE;
+    /* Initialize flags and cursor */
+    i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
+    i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
 
-    if( p_vout->b_fullscreen )
+    i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
+                             SDL_DEFAULT_BPP, i_flags );
+    if( i_bpp == 0 )
     {
-        flags |= SDL_FULLSCREEN;
-    }
-    else
-    {
-        flags |= SDL_RESIZABLE;
+        intf_ErrMsg( "vout error: no video mode available" );
+        return( 1 );
     }
 
-    if( p_vout->b_need_render )
+    p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
+                                                 p_vout->p_sys->i_height,
+                                                 i_bpp, i_flags );
+
+    if( p_vout->p_sys->p_display == NULL )
     {
-        flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
+        intf_ErrMsg( "vout error: cannot set video mode" );
+        return( 1 );
     }
-    else
+
+    SDL_LockSurface( p_vout->p_sys->p_display );
+
+    /* Choose the chroma we will try first. */
+    switch( p_vout->render.i_chroma )
     {
-        flags |= SDL_SWSURFACE; /* save video memory */
+        case FOURCC_YUY2:
+        case FOURCC_YUNV:
+            p_vout->output.i_chroma = SDL_YUY2_OVERLAY;
+            break;
+        case FOURCC_UYVY:
+        case FOURCC_UYNV:
+        case FOURCC_Y422:
+            p_vout->output.i_chroma = SDL_UYVY_OVERLAY;
+            break;
+        case FOURCC_YVYU:
+            p_vout->output.i_chroma = SDL_YVYU_OVERLAY;
+            break;
+        case FOURCC_YV12:
+        case FOURCC_I420:
+        case FOURCC_IYUV:
+        default:
+            p_vout->output.i_chroma = SDL_YV12_OVERLAY;
+            break;
     }
 
-    bpp = SDL_VideoModeOK( p_vout->p_sys->i_width,
-                           p_vout->p_sys->i_height,
-                           p_vout->i_screen_depth, flags );
+    p_vout->p_sys->p_overlay =
+        SDL_CreateYUVOverlay( 32, 32, p_vout->output.i_chroma,
+                              p_vout->p_sys->p_display );
+    /* FIXME: if the first overlay we find is software, don't stop,
+     * because we may find a hardware one later ... */
 
-    if( bpp == 0 )
+    /* If this best choice failed, fall back to other chromas */
+    if( p_vout->p_sys->p_overlay == NULL )
     {
-        intf_ErrMsg( "vout error: no video mode available" );
-        return( 1 );
+        p_vout->output.i_chroma = SDL_IYUV_OVERLAY;
+        p_vout->p_sys->p_overlay =
+            SDL_CreateYUVOverlay( 32, 32, p_vout->output.i_chroma,
+                                  p_vout->p_sys->p_display );
     }
 
-    p_vout->p_sys->p_display = SDL_SetVideoMode(p_vout->p_sys->i_width,
-                                                p_vout->p_sys->i_height,
-                                                bpp, flags);
+    if( p_vout->p_sys->p_overlay == NULL )
+    {
+        p_vout->output.i_chroma = SDL_YV12_OVERLAY;
+        p_vout->p_sys->p_overlay =
+            SDL_CreateYUVOverlay( 32, 32, p_vout->output.i_chroma,
+                                  p_vout->p_sys->p_display );
+    }
 
-    if( p_vout->p_sys->p_display == NULL )
+    if( p_vout->p_sys->p_overlay == NULL )
     {
-        intf_ErrMsg( "vout error: cannot set video mode" );
-        return( 1 );
+        p_vout->output.i_chroma = SDL_YUY2_OVERLAY;
+        p_vout->p_sys->p_overlay =
+            SDL_CreateYUVOverlay( 32, 32, p_vout->output.i_chroma,
+                                  p_vout->p_sys->p_display );
     }
 
-    SDL_LockSurface( p_vout->p_sys->p_display );
+    if( p_vout->p_sys->p_overlay == NULL )
+    {
+        intf_WarnMsg( 3, "vout warning: no SDL overlay for 0x%.8x (%4.4s)",
+                         p_vout->render.i_chroma,
+                         (char*)&p_vout->render.i_chroma );
 
-    SDL_WM_SetCaption( VOUT_TITLE " (SDL output)",
-                       VOUT_TITLE " (SDL output)" );
-    SDL_EventState(SDL_KEYUP , SDL_IGNORE);                /* ignore keys up */
+        switch( p_vout->p_sys->p_display->format->BitsPerPixel )
+        {
+            case 8:
+                p_vout->output.i_chroma = FOURCC_RGB2;
+                p_vout->output.pf_setpalette = SetPalette;
+                break;
+            case 15:
+                p_vout->output.i_chroma = FOURCC_RV15;
+                break;
+            case 16:
+                p_vout->output.i_chroma = FOURCC_RV16;
+                break;
+            case 24:
+                p_vout->output.i_chroma = FOURCC_RV24;
+                break;
+            case 32:
+                p_vout->output.i_chroma = FOURCC_RV32;
+                break;
+            default:
+                intf_ErrMsg( "vout error: unknown screen depth" );
+                SDL_UnlockSurface( p_vout->p_sys->p_display );
+                SDL_FreeSurface( p_vout->p_sys->p_display );
+                return( -1 );
+        }
 
-    if( p_vout->b_need_render )
-    {
-        p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
-        SDL_Flip(p_vout->p_sys->p_display);
-        p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
-        SDL_Flip(p_vout->p_sys->p_display);
-
-        /* Set clipping for text */
-        clipping_rect.x = 0;
-        clipping_rect.y = 0;
-        clipping_rect.w = p_vout->p_sys->p_display->w;
-        clipping_rect.h = p_vout->p_sys->p_display->h;
-        SDL_SetClipRect(p_vout->p_sys->p_display, &clipping_rect);
-
-        /* Set thread information */
-        p_vout->i_width =           p_vout->p_sys->p_display->w;
-        p_vout->i_height =          p_vout->p_sys->p_display->h;
-        p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
-
-        p_vout->i_screen_depth =
-            p_vout->p_sys->p_display->format->BitsPerPixel;
-        p_vout->i_bytes_per_pixel =
-            p_vout->p_sys->p_display->format->BytesPerPixel;
-
-        p_vout->i_red_mask =        p_vout->p_sys->p_display->format->Rmask;
-        p_vout->i_green_mask =      p_vout->p_sys->p_display->format->Gmask;
-        p_vout->i_blue_mask =       p_vout->p_sys->p_display->format->Bmask;
-
-        /* FIXME: palette in 8bpp ?? */
-        /* Set and initialize buffers */
-        p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
-                                       p_vout->p_sys->p_sdl_buf[ 1 ] );
+        p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
+        p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
+        p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
+
+        SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
+                           VOUT_TITLE " (software RGB SDL output)" );
     }
     else
     {
-        p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
-        p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
-
-        /* Set thread information */
-        p_vout->i_width =           p_vout->p_sys->p_display->w;
-        p_vout->i_height =          p_vout->p_sys->p_display->h;
-        p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
-
-        p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
-                                       p_vout->p_sys->p_sdl_buf[ 1 ] );
+        if( p_vout->p_sys->p_overlay->hw_overlay )
+        {
+            SDL_WM_SetCaption( VOUT_TITLE " (hardware YUV SDL output)",
+                               VOUT_TITLE " (hardware YUV SDL output)" );
+        }
+        else
+        {
+            SDL_WM_SetCaption( VOUT_TITLE " (software YUV SDL output)",
+                               VOUT_TITLE " (software YUV SDL output)" );
+        }
     }
 
-    p_vout->p_sys->b_reopen_display = 0;
+    SDL_EventState( SDL_KEYUP, SDL_IGNORE );               /* ignore keys up */
 
     return( 0 );
 }
 
 /*****************************************************************************
- * SDLCloseDisplay: close and reset SDL device
+ * CloseDisplay: close and reset SDL device
  *****************************************************************************
- * This function returns all resources allocated by SDLOpenDisplay and restore
+ * This function returns all resources allocated by OpenDisplay and restore
  * the original state of the device.
  *****************************************************************************/
-static void SDLCloseDisplay( vout_thread_t *p_vout )
+static void CloseDisplay( vout_thread_t *p_vout )
 {
-    if( p_vout->p_sys->p_display != NULL )
-    {
-        if( p_vout->p_sys->p_overlay != NULL )
-        {            
-            SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
-            p_vout->p_sys->p_overlay = NULL;
-        }
-
-        SDL_UnlockSurface ( p_vout->p_sys->p_display );
-        SDL_FreeSurface( p_vout->p_sys->p_display );
-        p_vout->p_sys->p_display = NULL;
-    }
+    SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
+    SDL_UnlockSurface ( p_vout->p_sys->p_display );
+    SDL_FreeSurface( p_vout->p_sys->p_display );
 }
 
 /*****************************************************************************
- * OutputCoords: compute the dimensions of the destination image
+ * NewPicture: allocate a picture
  *****************************************************************************
- * This based on some code in SetBufferPicture... , it is also in use in the
- * the xvideo plugin. Maybe we should think about putting standard video
- * processing functions in a common library ?
+ * Returns 0 on success, -1 otherwise
  *****************************************************************************/
-static void OutputCoords( const picture_t *p_pic, const boolean_t scale,
-                          const int win_w, const int win_h,
-                          int *dx, int *dy, int *w, int *h )
+static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
-    if( !scale )
+    int i_width  = p_vout->output.i_width;
+    int i_height = p_vout->output.i_height;
+
+    if( p_vout->p_sys->p_overlay == NULL )
     {
-        *w = p_pic->i_width; *h = p_pic->i_height;
+        /* RGB picture */
+        if( p_vout->p_sys->i_surfaces )
+        {
+            /* We already allocated this surface, return */
+            return -1;
+        }
+
+        p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
+
+        if( p_pic->p_sys == NULL )
+        {
+            return -1;
+        }
+
+        switch( p_vout->p_sys->p_display->format->BitsPerPixel )
+        {
+            case 8:
+                p_pic->p->i_pixel_bytes = 1;
+                break;
+            case 15:
+            case 16:
+                p_pic->p->i_pixel_bytes = 2;
+                break;
+            case 24:
+            case 32:
+                p_pic->p->i_pixel_bytes = 4;
+                break;
+            default:
+                return( -1 );
+        }
+
+        p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
+        p_pic->p->i_lines = p_vout->p_sys->p_display->h;
+        p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
+
+        if( p_pic->p->i_pitch ==
+                p_pic->p->i_pixel_bytes * p_vout->p_sys->p_display->w )
+        {
+            p_pic->p->b_margin = 0;
+        }
+        else
+        {
+            p_pic->p->b_margin = 1;
+            p_pic->p->b_hidden = 1;
+            p_pic->p->i_visible_bytes =
+                p_pic->p->i_pixel_bytes * p_vout->p_sys->p_display->w;
+        }
+
+        p_vout->p_sys->i_surfaces++;
+
+        p_pic->i_planes = 1;
     }
     else
     {
-        *w = win_w;
-        switch( p_pic->i_aspect_ratio )
-        {
-            case AR_3_4_PICTURE:
-                *h = win_w * 3 / 4;
-                break;
+        p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
 
-            case AR_16_9_PICTURE:
-                *h = win_w * 9 / 16;
-                break;
+        if( p_pic->p_sys == NULL )
+        {
+            return -1;
+        }
 
-            case AR_221_1_PICTURE:
-                *h = win_w * 100 / 221;
-                break;
+        p_pic->p_sys->p_overlay =
+            SDL_CreateYUVOverlay( i_width, i_height,
+                                  p_vout->output.i_chroma,
+                                  p_vout->p_sys->p_display );
 
-            case AR_SQUARE_PICTURE:
-            default:
-                *h = win_w * p_pic->i_height / p_pic->i_width;
-                break;
+        if( p_pic->p_sys->p_overlay == NULL )
+        {
+            free( p_pic->p_sys );
+            return -1;
         }
 
-        if( *h > win_h )
+        SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
+
+        p_pic->Y_PIXELS = p_pic->p_sys->p_overlay->pixels[0];
+        p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_overlay->h;
+        p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[0];
+
+        switch( p_vout->output.i_chroma )
         {
-            *h = win_h;
-            switch( p_pic->i_aspect_ratio )
-            {
-                case AR_3_4_PICTURE:
-                    *w = win_h * 4 / 3;
-                    break;
-
-                case AR_16_9_PICTURE:
-                    *w = win_h * 16 / 9;
-                    break;
-
-                case AR_221_1_PICTURE:
-                    *w = win_h * 221 / 100;
-                    break;
-
-                case AR_SQUARE_PICTURE:
-                default:
-                    *w = win_h * p_pic->i_width / p_pic->i_height;
-                    break;
-            }
+        case SDL_YV12_OVERLAY:
+            p_pic->p[Y_PLANE].i_pixel_bytes = 1;
+            p_pic->p[Y_PLANE].b_margin = 0;
+
+            p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
+            p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
+            p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
+            p_pic->p[U_PLANE].i_pixel_bytes = 1;
+            p_pic->p[U_PLANE].b_margin = 0;
+
+            p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
+            p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
+            p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
+            p_pic->p[V_PLANE].i_pixel_bytes = 1;
+            p_pic->p[V_PLANE].b_margin = 0;
+
+            p_pic->i_planes = 3;
+            break;
+
+        case SDL_IYUV_OVERLAY:
+            p_pic->p[Y_PLANE].i_pixel_bytes = 1;
+            p_pic->p[Y_PLANE].b_margin = 0;
+
+            p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
+            p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
+            p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
+            p_pic->p[U_PLANE].i_pixel_bytes = 1;
+            p_pic->p[U_PLANE].b_margin = 0;
+
+            p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
+            p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
+            p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
+            p_pic->p[V_PLANE].i_pixel_bytes = 1;
+            p_pic->p[V_PLANE].b_margin = 0;
+
+            p_pic->i_planes = 3;
+            break;
+
+        default:
+            p_pic->p[Y_PLANE].i_pixel_bytes = 2;
+            p_pic->p[Y_PLANE].b_margin = 0;
+
+            p_pic->i_planes = 1;
+            break;
         }
     }
 
-    /* Set picture position */
-    *dx = (win_w - *w) / 2;
-    *dy = (win_h - *h) / 2;
+    return 0;
 }
+
+/*****************************************************************************
+ * SetPalette: sets an 8 bpp palette
+ *****************************************************************************/
+static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
+{
+    SDL_Color colors[256];
+    int i;
+  
+    /* Fill colors with color information */
+    for( i = 0; i < 256; i++ )
+    {
+        colors[ i ].r = red[ i ] >> 8;
+        colors[ i ].g = green[ i ] >> 8;
+        colors[ i ].b = blue[ i ] >> 8;
+    }
+
+    /* Set palette */
+    if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
+    {
+        intf_ErrMsg( "vout error: failed setting palette" );
+    }
+}
+