mirror of https://github.com/mpv-player/mpv
vf_dsize: use option parser
Mostly backwards compatible, we don't change much because we just want to get rid of the legacy option string handling. You can't pass an aspect as first argument anymore.
This commit is contained in:
parent
43a6dd1ed5
commit
3201a40234
|
@ -156,7 +156,7 @@ Available filters are:
|
|||
:0: Disable accurate rounding (default).
|
||||
:1: Enable accurate rounding.
|
||||
|
||||
``dsize[=aspect|w:h:aspect-method:r]``
|
||||
``dsize[=w:h:aspect-method:r:aspect]``
|
||||
Changes the intended display size/aspect at an arbitrary point in the
|
||||
filter chain. Aspect can be given as a fraction (4/3) or floating point
|
||||
number (1.33). Alternatively, you may specify the exact display width and
|
||||
|
@ -205,6 +205,9 @@ Available filters are:
|
|||
Rounds up to make both width and height divisible by ``<r>``
|
||||
(default: 1).
|
||||
|
||||
``<aspect>``
|
||||
Force an aspect ratio.
|
||||
|
||||
``format[=fmt[:outfmt]]``
|
||||
Restricts the color space for the next filter without doing any conversion.
|
||||
Use together with the scale filter for a real conversion.
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "mpvcore/mp_msg.h"
|
||||
#include "mpvcore/m_option.h"
|
||||
|
||||
#include "video/img_format.h"
|
||||
#include "video/mp_image.h"
|
||||
|
@ -76,45 +78,31 @@ static int config(struct vf_instance *vf,
|
|||
return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
|
||||
}
|
||||
|
||||
static void uninit(vf_instance_t *vf) {
|
||||
free(vf->priv);
|
||||
vf->priv = NULL;
|
||||
}
|
||||
|
||||
static int vf_open(vf_instance_t *vf, char *args)
|
||||
{
|
||||
vf->config = config;
|
||||
vf->uninit = uninit;
|
||||
vf->priv = calloc(sizeof(struct vf_priv_s), 1);
|
||||
vf->priv->aspect = 0.;
|
||||
vf->priv->w = -1;
|
||||
vf->priv->h = -1;
|
||||
vf->priv->method = -1;
|
||||
vf->priv->round = 1;
|
||||
if (args) {
|
||||
if (strchr(args, '/')) {
|
||||
int w, h;
|
||||
sscanf(args, "%d/%d", &w, &h);
|
||||
vf->priv->aspect = (float)w/h;
|
||||
} else if (strchr(args, '.')) {
|
||||
sscanf(args, "%f", &vf->priv->aspect);
|
||||
} else {
|
||||
sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round);
|
||||
}
|
||||
}
|
||||
if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) ||
|
||||
((vf->priv->w < -1) && (vf->priv->h < -1)) ||
|
||||
(vf->priv->method < -1) || (vf->priv->method > 3) ||
|
||||
(vf->priv->round < 0)) {
|
||||
mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round);
|
||||
free(vf->priv); vf->priv = NULL;
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define OPT_BASE_STRUCT struct vf_priv_s
|
||||
const vf_info_t vf_info_dsize = {
|
||||
.description = "reset displaysize/aspect",
|
||||
.name = "dsize",
|
||||
.open = vf_open,
|
||||
.priv_size = sizeof(struct vf_priv_s),
|
||||
.priv_defaults = &(const struct vf_priv_s){
|
||||
.aspect = 0.0,
|
||||
.w = -1,
|
||||
.h = -1,
|
||||
.method = -1,
|
||||
.round = 1,
|
||||
},
|
||||
.options = (const struct m_option[]){
|
||||
OPT_INTRANGE("w", w, 0, -3, INT_MAX),
|
||||
OPT_INTRANGE("h", w, 0, -3, INT_MAX),
|
||||
OPT_INTRANGE("method", method, 0, -1, 3),
|
||||
OPT_INTRANGE("round", round, 0, 0, 9999),
|
||||
OPT_FLOAT("aspect", aspect, CONF_RANGE, .min = 0, .max = 10),
|
||||
{0}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue