[vlc-commits] vout: use struct vout_crop in display

Rémi Denis-Courmont git at videolan.org
Mon Feb 8 15:15:08 UTC 2021


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb  6 18:14:24 2021 +0200| [63384a250570bf26c7cedd3061f6df64f8958cbf] | committer: Rémi Denis-Courmont

vout: use struct vout_crop in display

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=63384a250570bf26c7cedd3061f6df64f8958cbf
---

 src/video_output/display.c | 105 ++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 69 deletions(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index 6d91d57849..06dd9533db 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -263,15 +263,7 @@ typedef struct {
 
     /* */
     vout_display_cfg_t cfg;
-
-    struct {
-        int      left;
-        int      top;
-        int      right;
-        int      bottom;
-        unsigned num;
-        unsigned den;
-    } crop;
+    struct vout_crop crop;
 
     /* */
     video_format_t source;
@@ -457,35 +449,48 @@ 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;
-    const unsigned crop_num = osys->crop.num;
-    const unsigned crop_den = osys->crop.den;
+    int left, top, right, bottom;
 
-    if (crop_num != 0 && crop_den != 0) {
-        VoutDisplayCropRatio(&osys->crop.left,  &osys->crop.top,
-                             &osys->crop.right, &osys->crop.bottom,
-                             &osys->source, crop_num, crop_den);
+    switch (osys->crop.mode) {
+        case VOUT_CROP_NONE:
+            left = top = right = bottom = 0;
+            break;
+        case VOUT_CROP_RATIO:
+            VoutDisplayCropRatio(&left, &top, &right, &bottom, &osys->source,
+                                 osys->crop.ratio.num, osys->crop.ratio.den);
+            break;
+        case VOUT_CROP_WINDOW:
+            left = osys->crop.window.x;
+            top = osys->crop.window.y;
+            right = osys->crop.window.width;
+            bottom = osys->crop.window.height;
+            break;
+        case VOUT_CROP_BORDER:
+            left = osys->crop.border.left;
+            top = osys->crop.border.top;
+            right = -(int)osys->crop.border.right;
+            bottom = -(int)osys->crop.border.bottom;
+            break;
     }
 
     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;
+
+    left = VLC_CLIP((int)osys->source.i_x_offset + left, 0, right_max - 1);
+    top  = VLC_CLIP((int)osys->source.i_y_offset + top, 0, bottom_max - 1);
+
+    if (right <= 0)
+        right = (int)(osys->source.i_x_offset + osys->source.i_visible_width) + right;
     else
-        right = (int)osys->source.i_x_offset + osys->crop.right;
+        right = (int)osys->source.i_x_offset + 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 (bottom <= 0)
+        bottom = (int)(osys->source.i_y_offset + osys->source.i_visible_height) + bottom;
     else
-        bottom = (int)osys->source.i_y_offset + osys->crop.bottom;
+        bottom = (int)osys->source.i_y_offset + bottom;
     bottom = VLC_CLIP(bottom, top + 1, bottom_max);
 
     osys->source.i_x_offset       = left;
@@ -513,8 +518,7 @@ static int vout_SetSourceAspect(vout_display_t *vd,
         ret = -1;
 
     /* If a crop ratio is requested, recompute the parameters */
-    if (osys->crop.num != 0 && osys->crop.den != 0
-     && vout_UpdateSourceCrop(vd))
+    if (osys->crop.mode != VOUT_CROP_NONE && vout_UpdateSourceCrop(vd))
         ret = -1;
 
     return ret;
@@ -622,41 +626,9 @@ void vout_SetDisplayCrop(vout_display_t *vd,
                          const struct vout_crop *restrict crop)
 {
     vout_display_priv_t *osys = container_of(vd, vout_display_priv_t, display);
-    unsigned crop_num = 0, crop_den = 0, left = 0, top = 0;
-    int right = 0, bottom = 0;
-
-    switch (crop->mode) {
-        case VOUT_CROP_NONE:
-            break;
-        case VOUT_CROP_RATIO:
-            crop_num = crop->ratio.num;
-            crop_den = crop->ratio.den;
-            break;
-        case VOUT_CROP_WINDOW:
-            left = crop->window.x;
-            top = crop->window.y;
-            right = crop->window.width;
-            bottom = crop->window.height;
-            break;
-        case VOUT_CROP_BORDER:
-            left = crop->border.left;
-            top = crop->border.top;
-            right = -(int)crop->border.right;
-            bottom = -(int)crop->border.bottom;
-            break;
-    }
-
-    if (osys->crop.left  != (int)left  || osys->crop.top != (int)top ||
-        osys->crop.right != right || osys->crop.bottom != bottom ||
-        (crop_num != 0 && crop_den != 0 &&
-         (crop_num != osys->crop.num || crop_den != osys->crop.den))) {
 
-        osys->crop.left   = left;
-        osys->crop.top    = top;
-        osys->crop.right  = right;
-        osys->crop.bottom = bottom;
-        osys->crop.num    = crop_num;
-        osys->crop.den    = crop_den;
+    if (!vout_CropEqual(crop, &osys->crop)) {
+        osys->crop = *crop;
 
         if (vout_UpdateSourceCrop(vd))
             vout_display_Reset(vd);
@@ -712,12 +684,7 @@ vout_display_t *vout_display_New(vlc_object_t *parent,
     osys->pool = NULL;
 
     video_format_Copy(&osys->source, source);
-    osys->crop.left   = 0;
-    osys->crop.top    = 0;
-    osys->crop.right  = 0;
-    osys->crop.bottom = 0;
-    osys->crop.num = 0;
-    osys->crop.den = 0;
+    osys->crop.mode = VOUT_CROP_NONE;
 
     osys->src_vctx = vctx ? vlc_video_context_Hold( vctx ) : NULL;
 



More information about the vlc-commits mailing list