]> git.sesse.net Git - vlc/commitdiff
* src/video_output/vout_intf.c: added support for on-the-fly cropping in the core...
authorGildas Bazin <gbazin@videolan.org>
Tue, 25 Oct 2005 23:32:28 +0000 (23:32 +0000)
committerGildas Bazin <gbazin@videolan.org>
Tue, 25 Oct 2005 23:32:28 +0000 (23:32 +0000)
src/video_output/vout_intf.c

index 64576797882d1ead50d4ad7c26a1bb2f31aafcf8..3c801a37f56bda86bc0f1d2eb417eeea1d9a8c3e 100644 (file)
@@ -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 *,
@@ -213,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");
@@ -447,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_height )
+    {
+        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 )
 {