]> git.sesse.net Git - vlc/blobdiff - src/video_output/vout_intf.c
Allow on the fly cropping size change with top, left, right and bottom offsets.
[vlc] / src / video_output / vout_intf.c
index 3d8527efad5d3ed4336e65afb5f284695da50fef..8ced97e264823bd86ded5e5681f31780bf9b6013 100644 (file)
@@ -225,6 +225,22 @@ void vout_IntfInit( vout_thread_t *p_vout )
 
     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
 
+    /* Crop offset vars */
+    var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
+    var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
+    var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
+    var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
+
+    var_SetInteger( p_vout, "crop-left", 0 );
+    var_SetInteger( p_vout, "crop-top", 0 );
+    var_SetInteger( p_vout, "crop-right", 0 );
+    var_SetInteger( p_vout, "crop-bottom", 0 );
+
+    var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
+    var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
+    var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
+    var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
+
     /* Crop object var */
     var_Create( p_vout, "crop", VLC_VAR_STRING |
                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
@@ -782,105 +798,129 @@ static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
     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 )
+    if( !strcmp( psz_cmd, "crop" ) )
     {
-        /* We're using the 3:4 syntax */
-        i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
-        if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
+        char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
+        if( psz_parser )
+        {
+            /* We're using the 3:4 syntax */
+            i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
+            if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
 
-        i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
-        if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
+            i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
+            if( psz_end == psz_parser || !i_aspect_den ) 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;
+            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;
+            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;
+            }
         }
         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;
-        }
-    }
-    else
-    {
-        psz_parser = strchr( newval.psz_string, 'x' );
-        if( psz_parser )
-        {
-            /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
-            unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
-
-            i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
-            if( psz_end != psz_parser ) goto crop_end;
+            psz_parser = strchr( newval.psz_string, 'x' );
+            if( psz_parser )
+            {
+                /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
+                unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
 
-            psz_parser = strchr( ++psz_end, '+' );
-            i_crop_height = strtol( psz_end, &psz_end, 10 );
-            if( psz_end != psz_parser ) goto crop_end;
+                i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
+                if( psz_end != psz_parser ) goto crop_end;
 
-            psz_parser = strchr( ++psz_end, '+' );
-            i_crop_left = strtol( psz_end, &psz_end, 10 );
-            if( psz_end != psz_parser ) goto crop_end;
+                psz_parser = strchr( ++psz_end, '+' );
+                i_crop_height = strtol( psz_end, &psz_end, 10 );
+                if( psz_end != psz_parser ) goto crop_end;
 
-            i_crop_top = strtol( ++psz_end, &psz_end, 10 );
-            if( *psz_end != '\0' ) goto crop_end;
+                psz_parser = strchr( ++psz_end, '+' );
+                i_crop_left = strtol( psz_end, &psz_end, 10 );
+                if( psz_end != psz_parser ) goto crop_end;
 
-            i_width = i_crop_width;
-            p_vout->fmt_in.i_visible_width = i_width;
+                i_crop_top = strtol( ++psz_end, &psz_end, 10 );
+                if( *psz_end != '\0' ) goto crop_end;
 
-            i_height = i_crop_height;
-            p_vout->fmt_in.i_visible_height = i_height;
+                i_width = i_crop_width;
+                p_vout->fmt_in.i_visible_width = i_width;
 
-            p_vout->fmt_in.i_x_offset = i_crop_left;
-            p_vout->fmt_in.i_y_offset = i_crop_top;
-        }
-        else
-        {
-            /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
-            unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
+                i_height = i_crop_height;
+                p_vout->fmt_in.i_visible_height = i_height;
 
-            psz_parser = strchr( newval.psz_string, '+' );
-            i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
-            if( psz_end != psz_parser ) goto crop_end;
+                p_vout->fmt_in.i_x_offset = i_crop_left;
+                p_vout->fmt_in.i_y_offset = i_crop_top;
+            }
+            else
+            {
+                /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
+                unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
 
-            psz_parser = strchr( ++psz_end, '+' );
-            i_crop_top = strtol( psz_end, &psz_end, 10 );
-            if( psz_end != psz_parser ) goto crop_end;
+                psz_parser = strchr( newval.psz_string, '+' );
+                i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
+                if( psz_end != psz_parser ) goto crop_end;
 
-            psz_parser = strchr( ++psz_end, '+' );
-            i_crop_right = strtol( psz_end, &psz_end, 10 );
-            if( psz_end != psz_parser ) goto crop_end;
+                psz_parser = strchr( ++psz_end, '+' );
+                i_crop_top = strtol( psz_end, &psz_end, 10 );
+                if( psz_end != psz_parser ) goto crop_end;
 
-            i_crop_bottom = strtol( ++psz_end, &psz_end, 10 );
-            if( *psz_end != '\0' ) goto crop_end;
+                psz_parser = strchr( ++psz_end, '+' );
+                i_crop_right = strtol( psz_end, &psz_end, 10 );
+                if( psz_end != psz_parser ) goto crop_end;
 
+                i_crop_bottom = strtol( ++psz_end, &psz_end, 10 );
+                if( *psz_end != '\0' ) goto crop_end;
 
-            i_width = p_vout->fmt_render.i_visible_width
-                      - i_crop_left - i_crop_right;
-            p_vout->fmt_in.i_visible_width = i_width;
+                i_width = p_vout->fmt_render.i_visible_width
+                          - i_crop_left - i_crop_right;
+                p_vout->fmt_in.i_visible_width = i_width;
 
-            i_height = p_vout->fmt_render.i_visible_height
-                       - i_crop_top - i_crop_bottom;
-            p_vout->fmt_in.i_visible_height = i_height;
+                i_height = p_vout->fmt_render.i_visible_height
+                           - i_crop_top - i_crop_bottom;
+                p_vout->fmt_in.i_visible_height = i_height;
 
-            p_vout->fmt_in.i_x_offset = i_crop_left;
-            p_vout->fmt_in.i_y_offset = i_crop_top;
+                p_vout->fmt_in.i_x_offset = i_crop_left;
+                p_vout->fmt_in.i_y_offset = i_crop_top;
+            }
         }
     }
+    else if( !strcmp( psz_cmd, "crop-top" )
+          || !strcmp( psz_cmd, "crop-left" )
+          || !strcmp( psz_cmd, "crop-bottom" )
+          || !strcmp( psz_cmd, "crop-right" ) )
+    {
+        unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
+
+        i_crop_top = var_GetInteger( p_vout, "crop-top" );
+        i_crop_left = var_GetInteger( p_vout, "crop-left" );
+        i_crop_right = var_GetInteger( p_vout, "crop-right" );
+        i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
+
+        i_width = p_vout->fmt_render.i_visible_width
+                  - i_crop_left - i_crop_right;
+        p_vout->fmt_in.i_visible_width = i_width;
+
+        i_height = p_vout->fmt_render.i_visible_height
+                   - i_crop_top - i_crop_bottom;
+        p_vout->fmt_in.i_visible_height = i_height;
+
+        p_vout->fmt_in.i_x_offset = i_crop_left;
+        p_vout->fmt_in.i_y_offset = i_crop_top;
+    }
 
  crop_end:
     InitWindowSize( p_vout, &p_vout->i_window_width,