[vlc-devel] [PATCH] Revert "vout: change spu_area to unsigned"

Steve Lhomme robux4 at videolabs.io
Tue Dec 19 16:31:27 CET 2017


This reverts commit 956af56870bf3218fa0dae4933a45631bebd27b3.

The offset can be negative when there is room in the vout area between the
border and the video area.

Fixes #18665
---
 src/video_output/vout_subpictures.c | 43 ++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 50c358be04..54165df397 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -332,15 +332,15 @@ static int spu_invscale_h(unsigned v, const spu_scale_t s)
  * A few area functions helpers
  */
 typedef struct {
-    unsigned x;
-    unsigned y;
-    unsigned width;
-    unsigned height;
+    int x;
+    int y;
+    int width;
+    int height;
 
     spu_scale_t scale;
 } spu_area_t;
 
-static spu_area_t spu_area_create(unsigned x, unsigned y, unsigned w, unsigned h, spu_scale_t s)
+static spu_area_t spu_area_create(int x, int y, int w, int h, spu_scale_t s)
 {
     spu_area_t a = { .x = x, .y = y, .width = w, .height = h, .scale = s };
     return a;
@@ -375,11 +375,14 @@ static spu_area_t spu_area_unscaled(spu_area_t a, spu_scale_t s)
 }
 static bool spu_area_overlap(spu_area_t a, spu_area_t b)
 {
+    const int dx = 0;
+    const int dy = 0;
+
     a = spu_area_scaled(a);
     b = spu_area_scaled(b);
 
-    return __MAX(a.x, b.x) < __MIN(a.x + a.width, b.x + b.width ) &&
-           __MAX(a.y, b.y) < __MIN(a.y + a.height, b.y + b.height);
+    return __MAX(a.x - dx, b.x) < __MIN(a.x + a.width  + dx, b.x + b.width ) &&
+           __MAX(a.y - dy, b.y) < __MIN(a.y + a.height + dy, b.y + b.height);
 }
 
 /**
@@ -432,21 +435,17 @@ static void SpuAreaFitInside(spu_area_t *area, const spu_area_t *boundary)
 {
     spu_area_t a = spu_area_scaled(*area);
 
-    if((a.x + a.width) > boundary->width)
-    {
-        if(boundary->width > a.width)
-            a.x = boundary->width - a.width;
-        else
-            a.x = 0;
-    }
-
-    if((a.y + a.height) > boundary->height)
-    {
-        if(boundary->height > a.height)
-            a.y = boundary->height - a.height;
-        else
-            a.y = 0;
-    }
+    const int i_error_x = (a.x + a.width) - boundary->width;
+    if (i_error_x > 0)
+        a.x -= i_error_x;
+    if (a.x < 0)
+        a.x = 0;
+
+    const int i_error_y = (a.y + a.height) - boundary->height;
+    if (i_error_y > 0)
+        a.y -= i_error_y;
+    if (a.y < 0)
+        a.y = 0;
 
     *area = spu_area_unscaled(a, area->scale);
 }
-- 
2.14.2



More information about the vlc-devel mailing list