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-19 02:18:46 +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"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2002-04-19 02:18:46 +00:00
|
|
|
|
|
|
|
#include "vf.h"
|
2014-04-20 19:26:30 +00:00
|
|
|
#include "vf_lavfi.h"
|
2002-04-19 02:18:46 +00:00
|
|
|
|
|
|
|
struct vf_priv_s {
|
2014-04-20 19:26:30 +00:00
|
|
|
int angle;
|
|
|
|
struct vf_lw_opts *lw_opts;
|
2002-04-19 02:18:46 +00:00
|
|
|
};
|
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
static const char *const rot[] = {
|
|
|
|
"null",
|
|
|
|
"transpose=clock",
|
|
|
|
"vflip,hflip",
|
|
|
|
"transpose=cclock",
|
|
|
|
"null", // actually set in lavfi_recreate()
|
|
|
|
};
|
|
|
|
|
|
|
|
static int lavfi_reconfig(struct vf_instance *vf,
|
|
|
|
struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf_lw_old_priv(vf);
|
|
|
|
if (p->angle == 4) { // "auto"
|
|
|
|
int r = in->rotate;
|
2014-11-21 08:59:58 +00:00
|
|
|
if (r < 0 || r >= 360 || (r % 90) != 0) {
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
MP_ERR(vf, "Can't apply rotation of %d degrees.\n", r);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
vf_lw_update_graph(vf, NULL, "%s", rot[(r / 90) % 360]);
|
|
|
|
out->rotate = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-20 19:26:30 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
{
|
2014-04-20 19:26:30 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
2002-04-19 02:18:46 +00:00
|
|
|
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
if (vf_lw_set_graph(vf, p->lw_opts, NULL, "%s", rot[p->angle]) >= 0) {
|
|
|
|
vf_lw_set_reconfig_cb(vf, lavfi_reconfig);
|
2014-04-20 19:26:30 +00:00
|
|
|
return 1;
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
}
|
2003-01-03 21:54:54 +00:00
|
|
|
|
2015-02-11 16:32:41 +00:00
|
|
|
return 0;
|
2002-04-19 02:18:46 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 22:42:49 +00:00
|
|
|
#define OPT_BASE_STRUCT struct vf_priv_s
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_rotate = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "rotate",
|
|
|
|
.name = "rotate",
|
|
|
|
.open = vf_open,
|
2013-12-03 22:42:49 +00:00
|
|
|
.priv_size = sizeof(struct vf_priv_s),
|
|
|
|
.options = (const struct m_option[]){
|
2014-04-20 19:26:30 +00:00
|
|
|
OPT_CHOICE("angle", angle, 0,
|
|
|
|
({"0", 0},
|
|
|
|
{"90", 1},
|
|
|
|
{"180", 2},
|
video: change automatic rotation and 3D filter insertion
We inserted these filters with fixed parameters, which was ok. But this
also didn't change image parameters for the filters down the filter
chain and the VO. For example, if rotation by 90° was requested by the
file, we would insert a filter and rotate the video, but the VO would
still receive image parameters that direct rotation by 90°.
This wasn't a problem, but it could become one.
Fix this by letting the filters automatically pick up the image params.
The image params are reset on application. (We could probably also
always try to apply and reset image params in a filter, instead of
having special "auto" parameters. This would probably work, and video.c
would insert a "rotate=0" filter. But I'm afraid this would be confusing
and the current solution is cosmetically slightly nicer.)
Unfortunately, the vf_stereo3d.c change turned out a big mess, but once
the "internal" filter is fully replaced with libavfilter, most of this
can be radically simplified.
2014-09-27 16:13:14 +00:00
|
|
|
{"270", 3},
|
|
|
|
{"auto", 4})),
|
2014-04-20 19:26:30 +00:00
|
|
|
OPT_SUBSTRUCT("", lw_opts, vf_lw_conf, 0),
|
2013-12-03 22:42:49 +00:00
|
|
|
{0}
|
|
|
|
},
|
2002-04-19 02:18:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|