2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "core/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"
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/m_option.h"
|
|
|
|
#include "core/m_struct.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,
|
2012-12-26 20:22:44 +00:00
|
|
|
unsigned int flags, unsigned int outfmt)
|
|
|
|
{
|
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){
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_VFILTER, MSGL_WARN, "[CROP] Bad position/width/height - cropped area outside of the original!\n");
|
2002-05-12 19:06:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
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;
|
2003-01-10 10:43:01 +00:00
|
|
|
mp_msg(MSGT_VFILTER, MSGL_INFO, "Crop: %d x %d, %d ; %d\n",
|
2002-04-06 22:05:01 +00:00
|
|
|
vf->priv->crop_w,
|
|
|
|
vf->priv->crop_h,
|
|
|
|
vf->priv->crop_x,
|
|
|
|
vf->priv->crop_y);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-03-15 20:45:03 +00:00
|
|
|
#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
|
2007-11-09 06:58:32 +00:00
|
|
|
static const m_option_t vf_opts_fields[] = {
|
2003-03-15 20:55:33 +00:00
|
|
|
{"w", ST_OFF(crop_w), CONF_TYPE_INT, M_OPT_MIN,0 ,0, NULL},
|
|
|
|
{"h", ST_OFF(crop_h), CONF_TYPE_INT, M_OPT_MIN,0 ,0, NULL},
|
|
|
|
{"x", ST_OFF(crop_x), CONF_TYPE_INT, M_OPT_MIN,-1 ,0, NULL},
|
|
|
|
{"y", ST_OFF(crop_y), CONF_TYPE_INT, M_OPT_MIN,-1 ,0, NULL},
|
2003-03-15 20:45:03 +00:00
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2007-11-09 06:58:32 +00:00
|
|
|
static const m_struct_t vf_opts = {
|
2003-03-15 20:45:03 +00:00
|
|
|
"crop",
|
|
|
|
sizeof(struct vf_priv_s),
|
|
|
|
&vf_priv_dflt,
|
|
|
|
vf_opts_fields
|
|
|
|
};
|
|
|
|
|
2007-11-09 06:58:32 +00:00
|
|
|
const vf_info_t vf_info_crop = {
|
2002-04-06 22:05:01 +00:00
|
|
|
"cropping",
|
|
|
|
"crop",
|
|
|
|
"A'rpi",
|
|
|
|
"",
|
2010-02-21 13:40:49 +00:00
|
|
|
vf_open,
|
2003-03-15 20:45:03 +00:00
|
|
|
&vf_opts
|
2002-04-06 22:05:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|