[vlc-devel] [PATCH v2 1/3] video_output:display: move source aspect ratio/crop change handling in functions

Steve Lhomme robux4 at ycbcr.xyz
Wed Aug 22 09:42:26 CEST 2018


---
 src/video_output/display.c | 144 ++++++++++++++++++++-----------------
 1 file changed, 80 insertions(+), 64 deletions(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index b0c0fdbb3e..36704f46af 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -634,6 +634,84 @@ static void VoutDisplayCropRatio(int *left, int *top, int *right, int *bottom,
     }
 }
 
+static void UpdateSourceCrop(vout_display_t *vd)
+{
+    vout_display_owner_sys_t *osys = vd->owner.sys;
+
+    unsigned crop_num = osys->crop.num;
+    unsigned crop_den = osys->crop.den;
+
+    if (crop_num != 0 && crop_den != 0) {
+        video_format_t fmt = osys->source;
+        fmt.i_sar_num = vd->source.i_sar_num;
+        fmt.i_sar_den = vd->source.i_sar_den;
+        VoutDisplayCropRatio(&osys->crop.left,  &osys->crop.top,
+                             &osys->crop.right, &osys->crop.bottom,
+                             &fmt, crop_num, crop_den);
+    }
+
+    const int right_max  = osys->source.i_x_offset + 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,
+                          0, right_max - 1);
+    int top    = VLC_CLIP((int)osys->source.i_y_offset + osys->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;
+    else
+        right = (int)osys->source.i_x_offset + osys->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;
+    else
+        bottom = (int)osys->source.i_y_offset + osys->crop.bottom;
+    bottom = VLC_CLIP(bottom, top + 1, bottom_max);
+
+    vd->source.i_x_offset       = left;
+    vd->source.i_y_offset       = top;
+    vd->source.i_visible_width  = right - left;
+    vd->source.i_visible_height = bottom - top;
+    video_format_Print(VLC_OBJECT(vd), "SOURCE ", &osys->source);
+    video_format_Print(VLC_OBJECT(vd), "CROPPED", &vd->source);
+    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);
+    osys->crop.num    = crop_num;
+    osys->crop.den    = crop_den;
+
+    osys->ch_crop = false;
+}
+
+static void UpdateSourceAspect(vout_display_t *vd)
+{
+    vout_display_owner_sys_t *osys = vd->owner.sys;
+
+    if (osys->sar.num > 0 && osys->sar.den > 0) {
+        vd->source.i_sar_num = osys->sar.num;
+        vd->source.i_sar_den = osys->sar.den;
+    } else {
+        vd->source.i_sar_num = osys->source.i_sar_num;
+        vd->source.i_sar_den = osys->source.i_sar_den;
+    }
+
+    vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_ASPECT);
+    osys->sar.num = vd->source.i_sar_num;
+    osys->sar.den = vd->source.i_sar_den;
+
+    /* If a crop ratio is requested, recompute the parameters */
+    if (osys->crop.num != 0 && osys->crop.den != 0)
+        osys->ch_crop = true;
+
+    osys->ch_sar  = false;
+}
+
 bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
@@ -680,75 +758,13 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
     bool fit_window = false;
 
     if (osys->ch_sar) {
-        if (osys->sar.num > 0 && osys->sar.den > 0) {
-            vd->source.i_sar_num = osys->sar.num;
-            vd->source.i_sar_den = osys->sar.den;
-        } else {
-            vd->source.i_sar_num = osys->source.i_sar_num;
-            vd->source.i_sar_den = osys->source.i_sar_den;
-        }
-
-        vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_ASPECT);
+        UpdateSourceAspect(vd);
         fit_window = true;
-        osys->sar.num = vd->source.i_sar_num;
-        osys->sar.den = vd->source.i_sar_den;
-        osys->ch_sar  = false;
-
-        /* If a crop ratio is requested, recompute the parameters */
-        if (osys->crop.num != 0 && osys->crop.den != 0)
-            osys->ch_crop = true;
     }
 
     if (osys->ch_crop) {
-        unsigned crop_num = osys->crop.num;
-        unsigned crop_den = osys->crop.den;
-
-        if (crop_num != 0 && crop_den != 0) {
-            video_format_t fmt = osys->source;
-            fmt.i_sar_num = vd->source.i_sar_num;
-            fmt.i_sar_den = vd->source.i_sar_den;
-            VoutDisplayCropRatio(&osys->crop.left,  &osys->crop.top,
-                                 &osys->crop.right, &osys->crop.bottom,
-                                 &fmt, crop_num, crop_den);
-        }
-
-        const int right_max  = osys->source.i_x_offset + 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,
-                              0, right_max - 1);
-        int top    = VLC_CLIP((int)osys->source.i_y_offset + osys->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;
-        else
-            right = (int)osys->source.i_x_offset + osys->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;
-        else
-            bottom = (int)osys->source.i_y_offset + osys->crop.bottom;
-        bottom = VLC_CLIP(bottom, top + 1, bottom_max);
-
-        vd->source.i_x_offset       = left;
-        vd->source.i_y_offset       = top;
-        vd->source.i_visible_width  = right - left;
-        vd->source.i_visible_height = bottom - top;
-        video_format_Print(VLC_OBJECT(vd), "SOURCE ", &osys->source);
-        video_format_Print(VLC_OBJECT(vd), "CROPPED", &vd->source);
-        vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP);
+        UpdateSourceCrop(vd);
         fit_window = true;
-        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);
-        osys->crop.num    = crop_num;
-        osys->crop.den    = crop_den;
-        osys->ch_crop = false;
     }
 
     if (fit_window)
-- 
2.17.0



More information about the vlc-devel mailing list