]> git.sesse.net Git - vlc/commitdiff
Fixed crop behavior (with a ratio) after AR changes.
authorLaurent Aimar <fenrir@videolan.org>
Wed, 19 May 2010 19:49:40 +0000 (21:49 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Wed, 19 May 2010 19:53:59 +0000 (21:53 +0200)
src/video_output/display.c
src/video_output/video_output.c

index 423f4ed0d9259e6bc85ac17e2dbf6b9ee1abaaae..4fd32f23df0169e1c85f3915e5ffb84b8d5f0435 100644 (file)
@@ -673,6 +673,29 @@ static void VoutDisplayFitWindow(vout_display_t *vd, bool default_size)
     vlc_mutex_unlock(&osys->lock);
 }
 
+static void VoutDisplayCropRatio(unsigned *x, unsigned *y,
+                                 unsigned *width, unsigned *height,
+                                 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) {
+        *x      = (source->i_visible_width - scaled_width) / 2;
+        *y      = 0;
+        *width  = scaled_width;
+        *height = source->i_visible_height;
+    } else {
+        *x      = 0;
+        *y      = (source->i_visible_height - scaled_height) / 2;
+        *width  = source->i_visible_width;
+        *height = scaled_height;
+    }
+    *x += source->i_x_offset;
+    *y += source->i_y_offset;
+}
+
 void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
@@ -888,12 +911,24 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
                              65536);
                 vout_SendEventSourceAspect(osys->vout, dar_num, dar_den);
             }
+            /* 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) {
             video_format_t source = vd->source;
+
             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 = source.i_sar_num;
+                fmt.i_sar_den = source.i_sar_den;
+                VoutDisplayCropRatio(&osys->crop.x, &osys->crop.y,
+                                     &osys->crop.width, &osys->crop.height,
+                                     &fmt, crop_num, crop_den);
+            }
 
             source.i_x_offset       = osys->crop.x;
             source.i_y_offset       = osys->crop.y;
@@ -1043,7 +1078,9 @@ void vout_SetDisplayCrop(vout_display_t *vd,
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
     if (osys->crop.x != x || osys->crop.y != y ||
-        osys->crop.width  != width || osys->crop.height != height) {
+        osys->crop.width  != width || osys->crop.height != height ||
+        (crop_num > 0 && crop_den > 0 &&
+         (crop_num != osys->crop.num || crop_den != osys->crop.den))) {
 
         osys->crop.x      = x;
         osys->crop.y      = y;
index 5b06f51b5add848718bfe0ededa329d66ec43d7a..2a8086eb7fd3a89655082f04d874c1884bade897 100644 (file)
@@ -839,33 +839,10 @@ static void ThreadExecuteCropRatio(vout_thread_t *vout,
                                    unsigned num, unsigned den)
 {
     const video_format_t *source = &vout->p->original;
-
-    int x, y;
-    int width, height;
-    if (num <= 0 || den <= 0) {
-        num = 0;
-        den = 0;
-        x   = 0;
-        y   = 0;
-        width  = source->i_visible_width;
-        height = source->i_visible_height;
-    } else {
-        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) {
-            x      = (source->i_visible_width - scaled_width) / 2;
-            y      = 0;
-            width  = scaled_width;
-            height = source->i_visible_height;
-        } else {
-            x      = 0;
-            y      = (source->i_visible_height - scaled_height) / 2;
-            width  = source->i_visible_width;
-            height = scaled_height;
-        }
-    }
-    ThreadExecuteCropWindow(vout, num, den, x, y, width, height);
+    ThreadExecuteCropWindow(vout, num, den,
+                            0, 0,
+                            source->i_visible_width,
+                            source->i_visible_height);
 }
 
 static int ThreadInit(vout_thread_t *vout)