summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-01-23 10:56:36 +0100
committerwm4 <wm4@nowhere>2013-01-23 10:56:36 +0100
commit7885fce7ea68d4c64e034b152f2a0b08bb648adc (patch)
tree1287161e93f05b5964347d008b82c18f0aad0ca8 /video
parentccaed5eb071319f9d412f42610302765b844f978 (diff)
downloadmpv-7885fce7ea68d4c64e034b152f2a0b08bb648adc.tar.bz2
mpv-7885fce7ea68d4c64e034b152f2a0b08bb648adc.tar.xz
video: add --autofit and --autofit-larger options
--autofit=WxH sets the window size to a maximum width and/or height, without changing the window's aspect ratio. --autofit-larger=WxH does the same, but only if the video size is actually larger than the window size that would result when using the --autofit=WxH option with the same arguments.
Diffstat (limited to 'video')
-rw-r--r--video/out/vo.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/video/out/vo.c b/video/out/vo.c
index 29307b7218..484aa20a56 100644
--- a/video/out/vo.c
+++ b/video/out/vo.c
@@ -355,6 +355,32 @@ struct vo *init_best_video_out(struct MPOpts *opts,
return NULL;
}
+// Fit *w/*h into the size specified by geo.
+static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
+ struct m_geometry *geo, bool allow_upscale)
+{
+ if (!geo->wh_valid)
+ return;
+
+ int dummy;
+ int n_w = *w, n_h = *h;
+ m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
+
+ if (!allow_upscale && *w <= n_w && *h <= n_h)
+ return;
+
+ // If aspect mismatches, always make the window smaller than the fit box
+ double asp = (double)*w / *h;
+ double n_asp = (double)n_w / n_h;
+ if (n_asp <= asp) {
+ *w = n_w;
+ *h = n_w / asp;
+ } else {
+ *w = n_h * asp;
+ *h = n_h;
+ }
+}
+
// Set window size (vo->dwidth/dheight) and position (vo->dx/dy) according to
// the video display size d_w/d_h.
// NOTE: currently, all GUI backends do their own handling of window geometry
@@ -365,6 +391,9 @@ static void determine_window_geometry(struct vo *vo, int d_w, int d_h)
{
struct MPOpts *opts = vo->opts;
+ int scr_w = opts->vo_screenwidth;
+ int scr_h = opts->vo_screenheight;
+
int vid_w = vo->aspdat.orgw;
int vid_h = vo->aspdat.orgh;
@@ -400,10 +429,12 @@ static void determine_window_geometry(struct vo *vo, int d_w, int d_h)
}
}
+ apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->vo_autofit, true);
+ apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->vo_autofit_larger, false);
+
vo->dx = (int)(opts->vo_screenwidth - d_w) / 2;
vo->dy = (int)(opts->vo_screenheight - d_h) / 2;
- m_geometry_apply(&vo->dx, &vo->dy, &d_w, &d_h,
- opts->vo_screenwidth, opts->vo_screenheight,
+ m_geometry_apply(&vo->dx, &vo->dy, &d_w, &d_h, scr_w, scr_h,
&opts->vo_geometry);
vo->dx += xinerama_x;