]> git.sesse.net Git - vlc/blobdiff - modules/video_output/directx/directx.c
* modules/video_output/directx/directx.c: support on-the-fly cropping.
[vlc] / modules / video_output / directx / directx.c
index f3da672886432e1951d57162a8ca07fdd1e33aa2..4ccbd29e3464141fa6ff445d68d036e37ffc5ff5 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vout.c: Windows DirectX video output display method
  *****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN
+ * Copyright (C) 2001-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
@@ -76,6 +76,7 @@ static int  Init      ( vout_thread_t * );
 static void End       ( vout_thread_t * );
 static int  Manage    ( vout_thread_t * );
 static void Display   ( vout_thread_t *, picture_t * );
+static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
 
 static int  NewPictureVec  ( vout_thread_t *, picture_t *, int );
 static void FreePictureVec ( vout_thread_t *, picture_t *, int );
@@ -94,7 +95,7 @@ static void DirectXGetDDrawCaps   ( vout_thread_t *p_vout );
 static int  DirectXLockSurface    ( vout_thread_t *p_vout, picture_t *p_pic );
 static int  DirectXUnlockSurface  ( vout_thread_t *p_vout, picture_t *p_pic );
 
-static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t i_color );
+static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t *i_color );
 
 void SwitchWallpaperMode( vout_thread_t *, vlc_bool_t );
 
@@ -140,6 +141,9 @@ static char *ppsz_dev[] = { "" };
 static char *ppsz_dev_text[] = { N_("Default") };
 
 vlc_module_begin();
+    set_shortname( "DirectX" );
+    set_category( CAT_VIDEO );
+    set_subcategory( SUBCAT_VIDEO_VOUT );
     add_bool( "directx-hw-yuv", 1, NULL, HW_YUV_TEXT, HW_YUV_LONGTEXT,
               VLC_TRUE );
     add_bool( "directx-use-sysmem", 0, NULL, SYSMEM_TEXT, SYSMEM_LONGTEXT,
@@ -218,7 +222,7 @@ static int OpenVideo( vlc_object_t *p_this )
     p_vout->p_sys->GetMonitorInfo = NULL;
     if( (huser32 = GetModuleHandle( _T("USER32") ) ) )
     {
-        p_vout->p_sys->MonitorFromWindow =
+        p_vout->p_sys->MonitorFromWindow = (HMONITOR (WINAPI *)( HWND, DWORD ))
             GetProcAddress( huser32, _T("MonitorFromWindow") );
         p_vout->p_sys->GetMonitorInfo =
 #ifndef UNICODE
@@ -352,6 +356,8 @@ static int Init( vout_thread_t *p_vout )
     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;
+    p_vout->fmt_out = p_vout->fmt_in;
+    E_(DirectXUpdateRects)( p_vout, VLC_TRUE );
 
 #define MAX_DIRECTBUFFERS 1
     /* Right now we use only 1 directbuffer because we don't want the
@@ -409,6 +415,7 @@ static int Init( vout_thread_t *p_vout )
     /* Change the window title bar text */
     PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
 
+    p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
     return VLC_SUCCESS;
 }
 
@@ -532,6 +539,19 @@ static int Manage( vout_thread_t *p_vout )
         }
     }
 
+    /* Check for cropping changes */
+    if( p_vout->fmt_out.i_x_offset != p_vout->fmt_in.i_x_offset ||
+        p_vout->fmt_out.i_y_offset != p_vout->fmt_in.i_y_offset ||
+        p_vout->fmt_out.i_visible_width != p_vout->fmt_in.i_visible_width ||
+        p_vout->fmt_out.i_visible_height != p_vout->fmt_in.i_visible_height )
+    {
+        p_vout->fmt_out.i_x_offset = p_vout->fmt_in.i_x_offset;
+        p_vout->fmt_out.i_y_offset = p_vout->fmt_in.i_y_offset;
+        p_vout->fmt_out.i_visible_width = p_vout->fmt_in.i_visible_width;
+        p_vout->fmt_out.i_visible_height = p_vout->fmt_in.i_visible_height;
+        E_(DirectXUpdateRects)( p_vout, VLC_TRUE );
+    }
+
     /* We used to call the Win32 PeekMessage function here to read the window
      * messages. But since window can stay blocked into this function for a
      * long time (for example when you move your window on the screen), I
@@ -1017,7 +1037,7 @@ static int DirectXCreateDisplay( vout_thread_t *p_vout )
     /* Make sure the colorkey will be painted */
     p_vout->p_sys->i_colorkey = 1;
     p_vout->p_sys->i_rgb_colorkey =
-        DirectXFindColorkey( p_vout, p_vout->p_sys->i_colorkey );
+        DirectXFindColorkey( p_vout, &p_vout->p_sys->i_colorkey );
 
     /* Create the actual brush */
     SetClassLong( p_vout->p_sys->hvideownd, GCL_HBRBACKGROUND,
@@ -1224,9 +1244,10 @@ int E_(DirectXUpdateOverlay)( vout_thread_t *p_vout )
     {
         int i_x, i_y, i_width, i_height;
 
-        rect_src.left = rect_src.top = 0;
-        rect_src.right = p_vout->render.i_width;
-        rect_src.bottom = p_vout->render.i_height;
+        rect_src.left = p_vout->fmt_out.i_x_offset;
+        rect_src.top = p_vout->fmt_out.i_y_offset;
+        rect_src.right = rect_src.left + p_vout->fmt_out.i_visible_width;
+        rect_src.bottom = rect_src.top + p_vout->fmt_out.i_visible_height;
 
         rect_dest = p_vout->p_sys->rect_display;
         vout_PlacePicture( p_vout, rect_dest.right, rect_dest.bottom,
@@ -1494,8 +1515,9 @@ static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
             {
                 switch( ddpfPixelFormat.dwRGBBitCount )
                 {
-                case 8: /* FIXME: set the palette */
+                case 8:
                     p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
+                    p_vout->output.pf_setpalette = SetPalette;
                     break;
                 case 15:
                     p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
@@ -1906,7 +1928,7 @@ static int DirectXUnlockSurface( vout_thread_t *p_vout, picture_t *p_pic )
 /*****************************************************************************
  * DirectXFindColorkey: Finds out the 32bits RGB pixel value of the colorkey
  *****************************************************************************/
-static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t i_color )
+static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t *pi_color )
 {
     DDSURFACEDESC ddsd;
     HRESULT dxresult;
@@ -1924,16 +1946,20 @@ static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t i_color )
     switch( ddsd.ddpfPixelFormat.dwRGBBitCount )
     {
     case 4:
-        *(uint8_t *)ddsd.lpSurface = 0x11;
+        *(uint8_t *)ddsd.lpSurface = *pi_color | (*pi_color << 4);
         break;
     case 8:
-        *(uint8_t *)ddsd.lpSurface = 0x01;
+        *(uint8_t *)ddsd.lpSurface = *pi_color;
         break;
+    case 15:
     case 16:
-        *(uint16_t *)ddsd.lpSurface = 0x01;
+        *(uint16_t *)ddsd.lpSurface = *pi_color;
         break;
+    case 24:
+        /* Seems to be problematic so we'll just put black as the colorkey */
+        *pi_color = 0;
     default:
-        *(uint32_t *)ddsd.lpSurface = 0x01;
+        *(uint32_t *)ddsd.lpSurface = *pi_color;
         break;
     }
 
@@ -2107,3 +2133,12 @@ static int WallpaperCallback( vlc_object_t *p_this, char const *psz_cmd,
 
     return VLC_SUCCESS;
 }
+
+/*****************************************************************************
+ * SetPalette: sets an 8 bpp palette
+ *****************************************************************************/
+static void SetPalette( vout_thread_t *p_vout,
+                        uint16_t *red, uint16_t *green, uint16_t *blue )
+{
+    msg_Err( p_vout, "FIXME: SetPalette unimplemented" );
+}