]> git.sesse.net Git - vlc/blobdiff - src/video_output/vout_intf.c
* src/video_output/vout_intf.c: small fix for cropping.
[vlc] / src / video_output / vout_intf.c
index 91d949de422c65101bfa1cfb81e08e26afd6881f..c682954ed5681084e4caac380381347cad029551 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vout_intf.c : video output interface
  *****************************************************************************
- * Copyright (C) 2000-2004 VideoLAN
+ * Copyright (C) 2000-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
@@ -41,6 +41,8 @@
 /* Object variables callbacks */
 static int ZoomCallback( vlc_object_t *, char const *,
                          vlc_value_t, vlc_value_t, void * );
+static int CropCallback( vlc_object_t *, char const *,
+                         vlc_value_t, vlc_value_t, void * );
 static int OnTopCallback( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
 static int FullscreenCallback( vlc_object_t *, char const *,
@@ -177,6 +179,8 @@ void vout_IntfInit( vout_thread_t *p_vout )
     var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_vout, "monitor-aspect-ratio",
+                                      VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
@@ -211,6 +215,27 @@ void vout_IntfInit( vout_thread_t *p_vout )
 
     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
 
+    var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
+                VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
+
+    text.psz_string = _("Crop");
+    var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
+
+    val.psz_string = "";
+    var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
+    val.psz_string = ""; text.psz_string = _("Default");
+    var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
+    val.psz_string = "001:1"; text.psz_string = _("1:1");
+    var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
+    val.psz_string = "004:3"; text.psz_string = _("4:3");
+    var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
+    val.psz_string = "16:9"; text.psz_string = _("16:9");
+    var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
+    val.psz_string = "221:100"; text.psz_string = _("221:100");
+    var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
+
+    var_AddCallback( p_vout, "crop", CropCallback, NULL );
+
     /* Add a variable to indicate if the window should be on top of others */
     var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     text.psz_string = _("Always on top");
@@ -445,6 +470,57 @@ static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
+static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
+                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+    int64_t i_aspect_num, i_aspect_den;
+    unsigned int i_width, i_height;
+
+    char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
+
+    /* Restore defaults */
+    p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
+    p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
+    p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
+    p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
+
+    if( !psz_parser ) goto crop_end;
+
+    i_aspect_num = strtol( newval.psz_string, &psz_end, 0 );
+    if( psz_end == newval.psz_string ) goto crop_end;
+
+    i_aspect_den = strtol( ++psz_parser, &psz_end, 0 );
+    if( psz_end == psz_parser ) goto crop_end;
+
+    i_width = p_vout->fmt_in.i_sar_den * p_vout->fmt_render.i_visible_height *
+        i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
+    i_height = p_vout->fmt_render.i_visible_width * p_vout->fmt_in.i_sar_num *
+        i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
+
+    if( i_width < p_vout->fmt_render.i_visible_width )
+    {
+        p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
+            (p_vout->fmt_render.i_visible_width - i_width) / 2;
+        p_vout->fmt_in.i_visible_width = i_width;
+    }
+    else
+    {
+        p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
+            (p_vout->fmt_render.i_visible_height - i_height) / 2;
+        p_vout->fmt_in.i_visible_height = i_height;
+    }
+
+ crop_end:
+    msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
+             p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
+             p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
+             p_vout->fmt_in.i_visible_width,
+             p_vout->fmt_in.i_visible_height );
+
+    return VLC_SUCCESS;
+}
+
 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {