[vlc-devel] [PATCH 6/7] display: don't overwrite the osys->crop values when updating osys->source

Steve Lhomme robux4 at ycbcr.xyz
Fri Nov 13 16:56:33 CET 2020


Use local variables that can be scaled if there is a crop ratio.

After calling VOUT_DISPLAY_CHANGE_SOURCE_CROP there was no reason to set
osys->crop either to odd values.
---
 src/video_output/display.c | 47 ++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index 19a5d3ef0f7..0255537fd79 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -452,6 +452,11 @@ static int vout_UpdateSourceCrop(vout_display_t *vd)
     vout_display_priv_t *osys = container_of(vd, vout_display_priv_t, display);
     video_format_t fmt = osys->source;
 
+    int crop_left   = osys->crop.left;
+    int crop_right  = osys->crop.right;
+    int crop_top    = osys->crop.top;
+    int crop_bottom = osys->crop.bottom;
+
     if (osys->crop.num != 0 && osys->crop.den != 0) {
         unsigned scaled_width  = (uint64_t)osys->source.i_visible_height * osys->crop.num * osys->source.i_sar_den
                                                                          / osys->crop.den / osys->source.i_sar_num;
@@ -459,15 +464,15 @@ static int vout_UpdateSourceCrop(vout_display_t *vd)
                                                                          / osys->crop.num / osys->source.i_sar_den;
 
         if (scaled_width < osys->source.i_visible_width) {
-            osys->crop.left   = (osys->source.i_visible_width - scaled_width) / 2;
-            osys->crop.top    = 0;
-            osys->crop.right  = osys->crop.left + scaled_width;
-            osys->crop.bottom = osys->source.i_visible_height;
+            crop_left   = (osys->source.i_visible_width - scaled_width) / 2;
+            crop_top    = 0;
+            crop_right  = crop_left + scaled_width;
+            crop_bottom = osys->source.i_visible_height;
         } else {
-            osys->crop.left   = 0;
-            osys->crop.top    = (osys->source.i_visible_height - scaled_height) / 2;
-            osys->crop.right  = osys->source.i_visible_width;
-            osys->crop.bottom = osys->crop.top  + scaled_height;
+            crop_left   = 0;
+            crop_top    = (osys->source.i_visible_height - scaled_height) / 2;
+            crop_right  = osys->source.i_visible_width;
+            crop_bottom = crop_top + scaled_height;
         }
     }
 
@@ -475,22 +480,22 @@ static int vout_UpdateSourceCrop(vout_display_t *vd)
                            + osys->source.i_visible_width;
     const int bottom_max = osys->source.i_y_offset
                            + osys->source.i_visible_height;
-    int left = VLC_CLIP((int)osys->source.i_x_offset + osys->crop.left,
+    int left = VLC_CLIP((int)osys->source.i_x_offset + crop_left,
                           0, right_max - 1);
-    int top  = VLC_CLIP((int)osys->source.i_y_offset + osys->crop.top,
+    int top  = VLC_CLIP((int)osys->source.i_y_offset + crop_top,
                         0, bottom_max - 1);
     int right, bottom;
 
-    if (osys->crop.right <= 0)
-        right = (int)(osys->source.i_x_offset + osys->source.i_visible_width) + osys->crop.right;
+    if (crop_right <= 0)
+        right = (int)(osys->source.i_x_offset + osys->source.i_visible_width) + crop_right;
     else
-        right = (int)osys->source.i_x_offset + osys->crop.right;
+        right = (int)osys->source.i_x_offset + crop_right;
     right = VLC_CLIP(right, left + 1, right_max);
 
-    if (osys->crop.bottom <= 0)
-        bottom = (int)(osys->source.i_y_offset + osys->source.i_visible_height) + osys->crop.bottom;
+    if (crop_bottom <= 0)
+        bottom = (int)(osys->source.i_y_offset + osys->source.i_visible_height) + crop_bottom;
     else
-        bottom = (int)osys->source.i_y_offset + osys->crop.bottom;
+        bottom = (int)osys->source.i_y_offset + crop_bottom;
     bottom = VLC_CLIP(bottom, top + 1, bottom_max);
 
     osys->source.i_x_offset       = left;
@@ -500,15 +505,7 @@ static int vout_UpdateSourceCrop(vout_display_t *vd)
     video_format_Print(VLC_OBJECT(vd), "SOURCE ", &fmt);
     video_format_Print(VLC_OBJECT(vd), "CROPPED ", &osys->source);
 
-    int ret = vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP);
-    osys->crop.left   = left - osys->source.i_x_offset;
-    osys->crop.top    = top  - osys->source.i_y_offset;
-    /* FIXME for right/bottom we should keep the 'type' border vs window */
-    osys->crop.right  = right -
-                        (osys->source.i_x_offset + osys->source.i_visible_width);
-    osys->crop.bottom = bottom -
-                        (osys->source.i_y_offset + osys->source.i_visible_height);
-    return ret;
+    return vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP);
 }
 
 static int vout_SetSourceAspect(vout_display_t *vd,
-- 
2.26.2



More information about the vlc-devel mailing list