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-06 22:05:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2002-04-06 22:05:01 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2003-03-15 20:45:03 +00:00
|
|
|
|
2007-11-09 06:58:32 +00:00
|
|
|
static const struct vf_priv_s {
|
2002-04-06 22:05:01 +00:00
|
|
|
int crop_w,crop_h;
|
|
|
|
int crop_x,crop_y;
|
2007-11-09 06:58:32 +00:00
|
|
|
} vf_priv_dflt = {
|
2003-03-15 20:45:03 +00:00
|
|
|
-1,-1,
|
|
|
|
-1,-1
|
2002-04-06 22:05:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2002-04-06 22:05:01 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
2014-04-13 16:00:51 +00:00
|
|
|
unsigned int flags, unsigned int outfmt)
|
2012-12-26 20:22:44 +00:00
|
|
|
{
|
2002-04-06 22:05:01 +00:00
|
|
|
// calculate the missing parameters:
|
|
|
|
if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width;
|
|
|
|
if(vf->priv->crop_h<=0 || vf->priv->crop_h>height) vf->priv->crop_h=height;
|
|
|
|
if(vf->priv->crop_x<0) vf->priv->crop_x=(width-vf->priv->crop_w)/2;
|
|
|
|
if(vf->priv->crop_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2;
|
2003-01-05 15:39:52 +00:00
|
|
|
// rounding:
|
2012-12-26 20:22:44 +00:00
|
|
|
|
|
|
|
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(outfmt);
|
|
|
|
|
|
|
|
vf->priv->crop_x = MP_ALIGN_DOWN(vf->priv->crop_x, fmt.align_x);
|
|
|
|
vf->priv->crop_y = MP_ALIGN_DOWN(vf->priv->crop_y, fmt.align_y);
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
// check:
|
2002-05-12 19:06:15 +00:00
|
|
|
if(vf->priv->crop_w+vf->priv->crop_x>width ||
|
|
|
|
vf->priv->crop_h+vf->priv->crop_y>height){
|
2015-04-16 20:46:52 +00:00
|
|
|
MP_WARN(vf, "Bad position/width/height - cropped area outside of the original!\n");
|
2014-04-13 16:00:51 +00:00
|
|
|
return 0;
|
2002-05-12 19:06:15 +00:00
|
|
|
}
|
2013-01-22 12:28:31 +00:00
|
|
|
vf_rescale_dsize(&d_width, &d_height, width, height,
|
2012-12-26 20:22:44 +00:00
|
|
|
vf->priv->crop_w, vf->priv->crop_h);
|
2002-05-12 19:06:15 +00:00
|
|
|
return vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt);
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
|
|
|
|
{
|
2012-12-26 20:22:44 +00:00
|
|
|
mp_image_crop(mpi, vf->priv->crop_x, vf->priv->crop_y,
|
|
|
|
vf->priv->crop_x + vf->priv->crop_w,
|
|
|
|
vf->priv->crop_y + vf->priv->crop_h);
|
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
|
|
|
return mpi;
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 20:22:44 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
|
|
|
if (!IMGFMT_IS_HWACCEL(fmt))
|
|
|
|
return vf_next_query_format(vf, fmt);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2013-12-03 23:01:38 +00:00
|
|
|
static int vf_open(vf_instance_t *vf){
|
2002-04-06 22:05:01 +00:00
|
|
|
vf->config=config;
|
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
|
|
|
vf->filter=filter;
|
2012-12-26 20:22:44 +00:00
|
|
|
vf->query_format=query_format;
|
2002-04-06 22:05:01 +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
|
2007-11-09 06:58:32 +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_INT("w", crop_w, M_OPT_MIN, .min = 0),
|
|
|
|
OPT_INT("h", crop_h, M_OPT_MIN, .min = 0),
|
|
|
|
OPT_INT("x", crop_x, M_OPT_MIN, .min = -1),
|
|
|
|
OPT_INT("y", crop_y, M_OPT_MIN, .min = -1),
|
|
|
|
{0}
|
2003-03-15 20:45:03 +00:00
|
|
|
};
|
|
|
|
|
2007-11-09 06:58:32 +00:00
|
|
|
const vf_info_t vf_info_crop = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "cropping",
|
|
|
|
.name = "crop",
|
|
|
|
.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,
|
2002-04-06 22:05:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|