[vlc-devel] [PATCH 5/7] display: replace the only VoutDisplayCropRatio call with the actual code

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


This makes it easier to see what is affected by this code in relation to the
rest of the vout_UpdateSourceCrop function.

In particular osys->crop dimenions are first (re)set (user crop ratio) and then
set again at the end of the function to different values, which is odd since
they are internal values.
---
 src/video_output/display.c | 39 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index f010188f66f..19a5d3ef0f7 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -377,26 +377,6 @@ static int VoutDisplayCreateRender(vout_display_t *vd)
     return ret;
 }
 
-static void VoutDisplayCropRatio(int *left, int *top, int *right, int *bottom,
-                                 const video_format_t *source,
-                                 unsigned num, unsigned den)
-{
-    unsigned scaled_width  = (uint64_t)source->i_visible_height * num * source->i_sar_den / den / source->i_sar_num;
-    unsigned scaled_height = (uint64_t)source->i_visible_width  * den * source->i_sar_num / num / source->i_sar_den;
-
-    if (scaled_width < source->i_visible_width) {
-        *left   = (source->i_visible_width - scaled_width) / 2;
-        *top    = 0;
-        *right  = *left + scaled_width;
-        *bottom = *top  + source->i_visible_height;
-    } else {
-        *left   = 0;
-        *top    = (source->i_visible_height - scaled_height) / 2;
-        *right  = *left + source->i_visible_width;
-        *bottom = *top  + scaled_height;
-    }
-}
-
 /**
  * It retreives a picture pool from the display
  */
@@ -473,9 +453,22 @@ static int vout_UpdateSourceCrop(vout_display_t *vd)
     video_format_t fmt = osys->source;
 
     if (osys->crop.num != 0 && osys->crop.den != 0) {
-        VoutDisplayCropRatio(&osys->crop.left,  &osys->crop.top,
-                             &osys->crop.right, &osys->crop.bottom,
-                             &osys->source, osys->crop.num, osys->crop.den);
+        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;
+        unsigned scaled_height = (uint64_t)osys->source.i_visible_width  * osys->crop.den * osys->source.i_sar_num
+                                                                         / 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;
+        } 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;
+        }
     }
 
     const int right_max  = osys->source.i_x_offset
-- 
2.26.2



More information about the vlc-devel mailing list