1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:42:17 +00:00

vf_dsize, vf_scale: fix behavior on multiple config() calls

When config() is called multiple times (e.g. aspect ratio changes
while the same file is playing), the user settings are not honoured,
because config() overwrites them. Don't do that.
This commit is contained in:
wm4 2011-12-12 21:16:05 +01:00 committed by Uoti Urpala
parent efe28bf2ab
commit 4478acd618
2 changed files with 26 additions and 19 deletions

View File

@ -39,29 +39,31 @@ static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt)
{
int w = vf->priv->w;
int h = vf->priv->h;
if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params
if (vf->priv->w == 0) vf->priv->w = d_width;
if (vf->priv->h == 0) vf->priv->h = d_height;
if (vf->priv->w == -1) vf->priv->w = width;
if (vf->priv->h == -1) vf->priv->h = height;
if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height;
if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height;
if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width;
if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width;
if (w == 0) w = d_width;
if (h == 0) h = d_height;
if (w == -1) w = width;
if (h == -1) h = height;
if (w == -2) w = h * (double)d_width / d_height;
if (w == -3) w = h * (double)width / height;
if (h == -2) h = w * (double)d_height / d_width;
if (h == -3) h = w * (double)height / width;
if (vf->priv->method > -1) {
double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width);
if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) {
vf->priv->h = vf->priv->w * aspect;
if ((h > w * aspect) ^ (vf->priv->method & 1)) {
h = w * aspect;
} else {
vf->priv->w = vf->priv->h / aspect;
w = h / aspect;
}
}
if (vf->priv->round > 1) { // round up
vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round);
vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round);
w += (vf->priv->round - 1 - (w - 1) % vf->priv->round);
h += (vf->priv->round - 1 - (h - 1) % vf->priv->round);
}
d_width = vf->priv->w;
d_height = vf->priv->h;
d_width = w;
d_height = h;
} else {
if (vf->priv->aspect * height > width) {
d_width = height * vf->priv->aspect + .5;

View File

@ -44,6 +44,7 @@
static struct vf_priv_s {
int w,h;
int cfg_w, cfg_h;
int v_chr_drop;
double param[2];
unsigned int fmt;
@ -55,6 +56,7 @@ static struct vf_priv_s {
int accurate_rnd;
struct mp_csp_details colorspace;
} const vf_priv_dflt = {
0, 0,
-1,-1,
0,
{SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
@ -204,6 +206,9 @@ static int config(struct vf_instance *vf,
vo_flags=vf->next->query_format(vf->next,best);
vf->priv->w = vf->priv->cfg_w;
vf->priv->h = vf->priv->cfg_h;
// scaling to dwidth*d_height, if all these TRUE:
// - option -zoom
// - no other sw/hw up/down scaling avail.
@ -628,8 +633,8 @@ static int vf_open(vf_instance_t *vf, char *args){
vf->control= control;
vf->uninit=uninit;
mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
vf->priv->w,
vf->priv->h);
vf->priv->cfg_w,
vf->priv->cfg_h);
return 1;
}
@ -754,8 +759,8 @@ static const m_obj_presets_t size_preset = {
#undef ST_OFF
#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
static const m_option_t vf_opts_fields[] = {
{"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
{"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
{"w", ST_OFF(cfg_w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
{"h", ST_OFF(cfg_h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
{"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
{"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
{"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},