2010-01-30 16:57:40 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-01-30 16:57:40 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2010-01-30 16:57:40 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-30 16:57:40 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-30 16:57:40 +00:00
|
|
|
*/
|
|
|
|
|
2002-04-09 14:01:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2015-03-30 20:33:30 +00:00
|
|
|
#include "common/common.h"
|
2002-04-09 14:01:53 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2002-04-09 14:01:53 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2003-03-15 20:51:35 +00:00
|
|
|
|
2015-03-30 20:14:57 +00:00
|
|
|
struct vf_priv_s {
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
int fmt;
|
|
|
|
int outfmt;
|
2015-03-30 21:52:28 +00:00
|
|
|
int colormatrix;
|
|
|
|
int colorlevels;
|
|
|
|
int outputlevels;
|
|
|
|
int primaries;
|
2015-03-31 05:47:13 +00:00
|
|
|
int gamma;
|
2015-03-30 21:52:28 +00:00
|
|
|
int chroma_location;
|
2015-04-02 21:57:56 +00:00
|
|
|
int stereo_in;
|
|
|
|
int stereo_out;
|
2015-04-02 21:59:00 +00:00
|
|
|
int rotate;
|
2015-04-02 22:02:40 +00:00
|
|
|
int dw, dh;
|
2015-04-02 22:06:29 +00:00
|
|
|
double dar;
|
2002-04-09 14:01:53 +00:00
|
|
|
};
|
|
|
|
|
2015-03-30 20:33:30 +00:00
|
|
|
static bool is_compatible(int fmt1, int fmt2)
|
|
|
|
{
|
|
|
|
struct mp_imgfmt_desc d1 = mp_imgfmt_get_desc(fmt1);
|
|
|
|
struct mp_imgfmt_desc d2 = mp_imgfmt_get_desc(fmt2);
|
|
|
|
if (d1.num_planes < d2.num_planes)
|
|
|
|
return false;
|
|
|
|
if (!(d1.flags & MP_IMGFLAG_BYTE_ALIGNED) ||
|
|
|
|
!(d2.flags & MP_IMGFLAG_BYTE_ALIGNED))
|
|
|
|
return false;
|
|
|
|
for (int n = 0; n < MPMIN(d1.num_planes, d2.num_planes); n++) {
|
|
|
|
if (d1.bytes[n] != d2.bytes[n])
|
|
|
|
return false;
|
|
|
|
if (d1.xs[n] != d2.xs[n] || d1.ys[n] != d2.ys[n])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:14:57 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
|
|
|
if (fmt == vf->priv->fmt || !vf->priv->fmt) {
|
2015-03-30 20:33:30 +00:00
|
|
|
if (vf->priv->outfmt) {
|
|
|
|
if (!is_compatible(fmt, vf->priv->outfmt))
|
|
|
|
return 0;
|
2010-06-05 17:55:20 +00:00
|
|
|
fmt = vf->priv->outfmt;
|
2015-03-30 20:33:30 +00:00
|
|
|
}
|
2015-03-30 20:14:57 +00:00
|
|
|
return vf_next_query_format(vf, fmt);
|
2010-06-05 17:55:20 +00:00
|
|
|
}
|
2002-04-09 14:01:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:14:57 +00:00
|
|
|
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out)
|
|
|
|
{
|
2015-03-30 21:52:28 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
2015-03-30 20:14:57 +00:00
|
|
|
*out = *in;
|
2015-03-30 21:52:28 +00:00
|
|
|
|
|
|
|
if (p->outfmt)
|
|
|
|
out->imgfmt = p->outfmt;
|
|
|
|
if (p->colormatrix)
|
|
|
|
out->colorspace = p->colormatrix;
|
|
|
|
if (p->colorlevels)
|
|
|
|
out->colorlevels = p->colorlevels;
|
|
|
|
if (p->outputlevels)
|
|
|
|
out->outputlevels = p->outputlevels;
|
|
|
|
if (p->primaries)
|
|
|
|
out->primaries = p->primaries;
|
2015-03-31 05:47:13 +00:00
|
|
|
if (p->gamma)
|
|
|
|
out->gamma = p->gamma;
|
2015-03-30 21:52:28 +00:00
|
|
|
if (p->chroma_location)
|
|
|
|
out->chroma_location = p->chroma_location;
|
2015-04-02 21:57:56 +00:00
|
|
|
if (p->stereo_in)
|
|
|
|
out->stereo_in = p->stereo_in;
|
|
|
|
if (p->stereo_out)
|
|
|
|
out->stereo_out = p->stereo_out;
|
2015-04-02 21:59:00 +00:00
|
|
|
if (p->rotate >= 0)
|
|
|
|
out->rotate = p->rotate;
|
2015-04-02 22:02:40 +00:00
|
|
|
if (p->dw > 0)
|
|
|
|
out->d_w = p->dw;
|
|
|
|
if (p->dh > 0)
|
|
|
|
out->d_h = p->dh;
|
2015-04-02 22:06:29 +00:00
|
|
|
if (p->dar > 0)
|
|
|
|
vf_set_dar(&out->d_w, &out->d_h, out->w, out->h, p->dar);
|
2015-03-30 21:52:28 +00:00
|
|
|
|
|
|
|
// Make sure the user-overrides are consistent (no RGB csp for YUV, etc.).
|
|
|
|
mp_image_params_guess_csp(out);
|
|
|
|
|
2015-03-30 20:14:57 +00:00
|
|
|
return 0;
|
2010-06-05 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 15:23:01 +00:00
|
|
|
static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
|
|
|
|
{
|
|
|
|
if (vf->priv->outfmt)
|
|
|
|
mp_image_setfmt(mpi, vf->priv->outfmt);
|
|
|
|
return mpi;
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:14:57 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
vf->query_format = query_format;
|
|
|
|
vf->reconfig = reconfig;
|
|
|
|
vf->filter = filter;
|
2002-04-09 14:01:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
#define OPT_BASE_STRUCT struct vf_priv_s
|
2008-04-26 13:35:40 +00:00
|
|
|
static const m_option_t vf_opts_fields[] = {
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
OPT_IMAGEFORMAT("fmt", fmt, 0),
|
|
|
|
OPT_IMAGEFORMAT("outfmt", outfmt, 0),
|
2015-03-30 21:52:28 +00:00
|
|
|
OPT_CHOICE_C("colormatrix", colormatrix, 0, mp_csp_names),
|
|
|
|
OPT_CHOICE_C("colorlevels", colorlevels, 0, mp_csp_levels_names),
|
|
|
|
OPT_CHOICE_C("outputlevels", outputlevels, 0, mp_csp_levels_names),
|
|
|
|
OPT_CHOICE_C("primaries", primaries, 0, mp_csp_prim_names),
|
2015-03-31 05:47:13 +00:00
|
|
|
OPT_CHOICE_C("gamma", gamma, 0, mp_csp_trc_names),
|
2015-03-30 21:52:28 +00:00
|
|
|
OPT_CHOICE_C("chroma-location", chroma_location, 0, mp_chroma_names),
|
2015-04-02 21:57:56 +00:00
|
|
|
OPT_CHOICE_C("stereo-in", stereo_in, 0, mp_stereo3d_names),
|
|
|
|
OPT_CHOICE_C("stereo-out", stereo_out, 0, mp_stereo3d_names),
|
2015-04-02 21:59:00 +00:00
|
|
|
OPT_INTRANGE("rotate", rotate, 0, -1, 359),
|
2015-04-02 22:02:40 +00:00
|
|
|
OPT_INT("dw", dw, 0),
|
|
|
|
OPT_INT("dh", dh, 0),
|
2015-04-02 22:06:29 +00:00
|
|
|
OPT_DOUBLE("dar", dar, 0),
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
{0}
|
2003-03-15 20:51:35 +00:00
|
|
|
};
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_format = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "force output format",
|
|
|
|
.name = "format",
|
|
|
|
.open = vf_open,
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
.priv_size = sizeof(struct vf_priv_s),
|
|
|
|
.options = vf_opts_fields,
|
2015-04-02 21:59:00 +00:00
|
|
|
.priv_defaults = &(const struct vf_priv_s){
|
|
|
|
.rotate = -1,
|
|
|
|
},
|
2002-04-09 14:01:53 +00:00
|
|
|
};
|