2009-07-07 02:01:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Loren Merritt <lorenm@u.washignton.edu>
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
2012-01-08 17:25:26 +00:00
|
|
|
#include <math.h>
|
2009-07-07 02:01:36 +00:00
|
|
|
|
|
|
|
#include "vf.h"
|
|
|
|
|
2014-03-16 09:36:06 +00:00
|
|
|
#include "common/common.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2012-01-08 17:12:43 +00:00
|
|
|
|
2013-12-03 21:24:49 +00:00
|
|
|
#include "vf_lavfi.h"
|
|
|
|
|
2009-07-07 02:01:36 +00:00
|
|
|
struct vf_priv_s {
|
2012-01-08 17:12:43 +00:00
|
|
|
float cfg_thresh;
|
|
|
|
int cfg_radius;
|
2012-01-08 17:25:26 +00:00
|
|
|
float cfg_size;
|
2009-07-07 02:01:36 +00:00
|
|
|
int radius;
|
2014-03-16 09:36:06 +00:00
|
|
|
|
2013-12-03 21:24:49 +00:00
|
|
|
struct vf_lw_opts *lw_opts;
|
2012-01-08 17:12:43 +00:00
|
|
|
} const vf_priv_dflt = {
|
2012-01-10 20:18:26 +00:00
|
|
|
.cfg_thresh = 1.5,
|
2012-01-08 17:25:26 +00:00
|
|
|
.cfg_radius = -1,
|
|
|
|
.cfg_size = -1,
|
2009-07-07 02:01:36 +00:00
|
|
|
};
|
|
|
|
|
2013-12-03 21:24:49 +00:00
|
|
|
static void lavfi_recreate(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf_lw_old_priv(vf);
|
2013-12-07 18:33:11 +00:00
|
|
|
int w = vf->fmt_in.w;
|
|
|
|
int h = vf->fmt_in.h;
|
2013-12-03 21:24:49 +00:00
|
|
|
p->radius = p->cfg_radius;
|
|
|
|
if (p->cfg_size > -1)
|
|
|
|
p->radius = (p->cfg_size / 100.0f) * sqrtf(w * w + h * h);
|
2014-03-16 09:36:06 +00:00
|
|
|
p->radius = MPCLAMP((p->radius+1)&~1, 4, 32);
|
2013-12-03 21:24:49 +00:00
|
|
|
vf_lw_update_graph(vf, "gradfun", "%f:%d", p->cfg_thresh, p->radius);
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:01:38 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
2009-07-07 02:01:36 +00:00
|
|
|
{
|
2012-01-08 17:25:26 +00:00
|
|
|
bool have_radius = vf->priv->cfg_radius > -1;
|
|
|
|
bool have_size = vf->priv->cfg_size > -1;
|
|
|
|
|
|
|
|
if (have_radius && have_size) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "scale: gradfun: only one of "
|
2012-01-08 17:25:26 +00:00
|
|
|
"radius/size parameters allowed at the same time!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_radius && !have_size)
|
2012-01-10 20:18:26 +00:00
|
|
|
vf->priv->cfg_size = 1.0;
|
2012-01-08 17:25:26 +00:00
|
|
|
|
2013-12-03 21:24:49 +00:00
|
|
|
if (vf_lw_set_graph(vf, vf->priv->lw_opts, "gradfun", "%f:4",
|
|
|
|
vf->priv->cfg_thresh) >= 0)
|
|
|
|
{
|
|
|
|
vf_lw_set_recreate_cb(vf, lavfi_recreate);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-16 09:36:06 +00:00
|
|
|
MP_FATAL(vf, "Requires libavfilter.\n");
|
|
|
|
return 0;
|
2009-07-07 02:01:36 +00:00
|
|
|
}
|
|
|
|
|
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
|
2012-01-08 17:12:43 +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_FLOATRANGE("strength", cfg_thresh, 0, 0.51, 255),
|
|
|
|
OPT_INTRANGE("radius", cfg_radius, 0, 4, 32),
|
|
|
|
OPT_FLOATRANGE("size", cfg_size, 0, 0.1, 5.0),
|
2013-12-03 21:24:49 +00:00
|
|
|
OPT_SUBSTRUCT("", lw_opts, vf_lw_conf, 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}
|
2012-01-08 17:12:43 +00:00
|
|
|
};
|
|
|
|
|
2009-07-07 02:01:36 +00:00
|
|
|
const vf_info_t vf_info_gradfun = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "gradient deband",
|
|
|
|
.name = "gradfun",
|
|
|
|
.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),
|
|
|
|
.priv_defaults = &vf_priv_dflt,
|
|
|
|
.options = vf_opts_fields,
|
2009-07-07 02:01:36 +00:00
|
|
|
};
|