2003-09-03 22:44:28 +00:00
|
|
|
/*
|
2008-05-13 10:16:20 +00:00
|
|
|
* Copyright (C) 2002 Jindrich Makovicka <makovick@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2003-09-03 22:44:28 +00:00
|
|
|
|
|
|
|
/* A very simple tv station logo remover */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
2011-05-23 16:32:14 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2003-09-03 22:44:28 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
|
|
|
#include "mpvcore/cpudetect.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2003-09-03 22:44:28 +00:00
|
|
|
#include "vf.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/memcpy_pic.h"
|
2003-09-03 22:44:28 +00:00
|
|
|
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/m_option.h"
|
2003-09-05 16:04:40 +00:00
|
|
|
|
2003-09-03 22:44:28 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
2003-09-05 16:04:40 +00:00
|
|
|
static struct vf_priv_s {
|
2003-09-03 22:44:28 +00:00
|
|
|
unsigned int outfmt;
|
|
|
|
int xoff, yoff, lw, lh, band, show;
|
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
|
|
|
char *file;
|
2011-05-23 16:32:14 +00:00
|
|
|
struct timed_rectangle {
|
|
|
|
int ts, x, y, w, h, b;
|
|
|
|
} *timed_rect;
|
|
|
|
int n_timed_rect;
|
|
|
|
int cur_timed_rect;
|
2007-01-28 16:48:01 +00:00
|
|
|
} const vf_priv_dflt = {
|
2003-09-05 16:04:40 +00:00
|
|
|
0,
|
2011-05-23 16:32:14 +00:00
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
NULL, NULL, 0, 0,
|
2003-09-03 22:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
|
2011-05-23 16:32:14 +00:00
|
|
|
/**
|
|
|
|
* Adjust the coordinates to suit the band width
|
|
|
|
* Also print a notice in verbose mode
|
|
|
|
*/
|
|
|
|
static void fix_band(struct vf_priv_s *p)
|
|
|
|
{
|
|
|
|
p->show = 0;
|
|
|
|
if (p->band < 0) {
|
|
|
|
p->band = 4;
|
|
|
|
p->show = 1;
|
|
|
|
}
|
|
|
|
p->lw += p->band*2;
|
|
|
|
p->lh += p->band*2;
|
|
|
|
p->xoff -= p->band;
|
|
|
|
p->yoff -= p->band;
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_V, "delogo: %d x %d, %d x %d, band = %d\n",
|
|
|
|
p->xoff, p->yoff, p->lw, p->lh, p->band);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_sub(struct vf_priv_s *p, double pts)
|
|
|
|
{
|
|
|
|
int ipts = pts * 1000;
|
|
|
|
int tr = p->cur_timed_rect;
|
|
|
|
while (tr < p->n_timed_rect - 1 && ipts >= p->timed_rect[tr + 1].ts)
|
|
|
|
tr++;
|
|
|
|
while (tr >= 0 && ipts < p->timed_rect[tr].ts)
|
|
|
|
tr--;
|
|
|
|
if (tr == p->cur_timed_rect)
|
|
|
|
return;
|
|
|
|
p->cur_timed_rect = tr;
|
|
|
|
if (tr >= 0) {
|
|
|
|
p->xoff = p->timed_rect[tr].x;
|
|
|
|
p->yoff = p->timed_rect[tr].y;
|
|
|
|
p->lw = p->timed_rect[tr].w;
|
|
|
|
p->lh = p->timed_rect[tr].h;
|
|
|
|
p->band = p->timed_rect[tr].b;
|
|
|
|
} else {
|
|
|
|
p->xoff = p->yoff = p->lw = p->lh = p->band = 0;
|
|
|
|
}
|
|
|
|
fix_band(p);
|
|
|
|
}
|
|
|
|
|
2003-09-03 22:44:28 +00:00
|
|
|
static void delogo(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height,
|
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
|
|
|
int logo_x, int logo_y, int logo_w, int logo_h, int band, int show) {
|
2003-09-03 22:44:28 +00:00
|
|
|
int y, x;
|
|
|
|
int interp, dist;
|
|
|
|
uint8_t *xdst, *xsrc;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-09-03 22:44:28 +00:00
|
|
|
uint8_t *topleft, *botleft, *topright;
|
|
|
|
int xclipl, xclipr, yclipt, yclipb;
|
2003-09-05 10:42:13 +00:00
|
|
|
int logo_x1, logo_x2, logo_y1, logo_y2;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-09-03 22:44:28 +00:00
|
|
|
xclipl = MAX(-logo_x, 0);
|
|
|
|
xclipr = MAX(logo_x+logo_w-width, 0);
|
|
|
|
yclipt = MAX(-logo_y, 0);
|
|
|
|
yclipb = MAX(logo_y+logo_h-height, 0);
|
|
|
|
|
2003-09-05 10:42:13 +00:00
|
|
|
logo_x1 = logo_x + xclipl;
|
|
|
|
logo_x2 = logo_x + logo_w - xclipr;
|
|
|
|
logo_y1 = logo_y + yclipt;
|
|
|
|
logo_y2 = logo_y + logo_h - yclipb;
|
|
|
|
|
|
|
|
topleft = src+logo_y1*srcStride+logo_x1;
|
2003-10-06 18:11:38 +00:00
|
|
|
topright = src+logo_y1*srcStride+logo_x2-1;
|
2003-09-05 10:42:13 +00:00
|
|
|
botleft = src+(logo_y2-1)*srcStride+logo_x1;
|
2003-09-03 22:44:28 +00:00
|
|
|
|
2003-09-05 10:42:13 +00:00
|
|
|
dst += (logo_y1+1)*dstStride;
|
|
|
|
src += (logo_y1+1)*srcStride;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-09-05 10:42:13 +00:00
|
|
|
for(y = logo_y1+1; y < logo_y2-1; y++)
|
2003-09-03 22:44:28 +00:00
|
|
|
{
|
2011-07-06 04:09:03 +00:00
|
|
|
for (x = logo_x1+1, xdst = dst+logo_x1+1, xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) {
|
|
|
|
interp = ((topleft[srcStride*(y-logo_y-yclipt)]
|
|
|
|
+ topleft[srcStride*(y-logo_y-1-yclipt)]
|
|
|
|
+ topleft[srcStride*(y-logo_y+1-yclipt)])*(logo_w-(x-logo_x))/logo_w
|
|
|
|
+ (topright[srcStride*(y-logo_y-yclipt)]
|
|
|
|
+ topright[srcStride*(y-logo_y-1-yclipt)]
|
|
|
|
+ topright[srcStride*(y-logo_y+1-yclipt)])*(x-logo_x)/logo_w
|
|
|
|
+ (topleft[x-logo_x-xclipl]
|
|
|
|
+ topleft[x-logo_x-1-xclipl]
|
|
|
|
+ topleft[x-logo_x+1-xclipl])*(logo_h-(y-logo_y))/logo_h
|
|
|
|
+ (botleft[x-logo_x-xclipl]
|
|
|
|
+ botleft[x-logo_x-1-xclipl]
|
|
|
|
+ botleft[x-logo_x+1-xclipl])*(y-logo_y)/logo_h
|
|
|
|
)/6;
|
|
|
|
/* interp = (topleft[srcStride*(y-logo_y)]*(logo_w-(x-logo_x))/logo_w
|
|
|
|
+ topright[srcStride*(y-logo_y)]*(x-logo_x)/logo_w
|
|
|
|
+ topleft[x-logo_x]*(logo_h-(y-logo_y))/logo_h
|
|
|
|
+ botleft[x-logo_x]*(y-logo_y)/logo_h
|
|
|
|
)/2;*/
|
|
|
|
if (y >= logo_y+band && y < logo_y+logo_h-band && x >= logo_x+band && x < logo_x+logo_w-band) {
|
|
|
|
*xdst = interp;
|
|
|
|
} else {
|
|
|
|
dist = 0;
|
|
|
|
if (x < logo_x+band) dist = MAX(dist, logo_x-x+band);
|
|
|
|
else if (x >= logo_x+logo_w-band) dist = MAX(dist, x-(logo_x+logo_w-1-band));
|
|
|
|
if (y < logo_y+band) dist = MAX(dist, logo_y-y+band);
|
|
|
|
else if (y >= logo_y+logo_h-band) dist = MAX(dist, y-(logo_y+logo_h-1-band));
|
|
|
|
*xdst = (*xsrc*dist + interp*(band-dist))/band;
|
|
|
|
if (show && (dist == band-1)) *xdst = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dst+= dstStride;
|
|
|
|
src+= srcStride;
|
2003-09-03 22:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2011-07-06 04:09:03 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
2003-09-03 22:44:28 +00:00
|
|
|
|
|
|
|
return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct mp_image *dmpi = mpi;
|
|
|
|
if (!mp_image_is_writeable(mpi)) {
|
|
|
|
dmpi = vf_alloc_out_image(vf);
|
|
|
|
mp_image_copy_attributes(dmpi, mpi);
|
2013-05-26 15:10:32 +00:00
|
|
|
mp_image_copy(dmpi, mpi);
|
2003-09-03 22:44:28 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 16:32:14 +00:00
|
|
|
if (vf->priv->timed_rect)
|
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
|
|
|
update_sub(vf->priv, dmpi->pts);
|
2003-09-03 22:44:28 +00:00
|
|
|
delogo(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->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
|
|
|
vf->priv->xoff, vf->priv->yoff, vf->priv->lw, vf->priv->lh, vf->priv->band, vf->priv->show);
|
2003-09-03 22:44:28 +00:00
|
|
|
delogo(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2,
|
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->priv->xoff/2, vf->priv->yoff/2, vf->priv->lw/2, vf->priv->lh/2, vf->priv->band/2, vf->priv->show);
|
2003-09-03 22:44:28 +00:00
|
|
|
delogo(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2,
|
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->priv->xoff/2, vf->priv->yoff/2, vf->priv->lw/2, vf->priv->lh/2, vf->priv->band/2, vf->priv->show);
|
2003-09-03 22:44:28 +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
|
|
|
if (dmpi != mpi)
|
|
|
|
talloc_free(mpi);
|
|
|
|
return dmpi;
|
2003-09-03 22:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt){
|
2003-09-03 22:44:28 +00:00
|
|
|
switch(fmt)
|
|
|
|
{
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
case IMGFMT_420P:
|
2011-07-06 04:09:03 +00:00
|
|
|
return vf_next_query_format(vf,vf->priv->outfmt);
|
2003-09-03 22:44:28 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const unsigned int fmt_list[]={
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
IMGFMT_420P,
|
2003-09-03 22:44:28 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2011-05-23 16:32:14 +00:00
|
|
|
static int load_timed_rectangles(struct vf_priv_s *delogo)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char line[2048];
|
|
|
|
int lineno = 0, p;
|
|
|
|
double ts, last_ts = 0;
|
|
|
|
struct timed_rectangle *rect = NULL, *nr;
|
|
|
|
int n_rect = 0, alloc_rect = 0;
|
|
|
|
|
|
|
|
f = fopen(delogo->file, "r");
|
|
|
|
if (!f) {
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_ERR, "delogo: unable to load %s: %s\n",
|
|
|
|
delogo->file, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
while (fgets(line, sizeof(line), f)) {
|
|
|
|
lineno++;
|
|
|
|
if (*line == '#' || *line == '\n')
|
|
|
|
continue;
|
|
|
|
if (n_rect == alloc_rect) {
|
|
|
|
if (alloc_rect > INT_MAX / 2 / (int)sizeof(*rect)) {
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_WARN,
|
|
|
|
"delogo: too many rectangles\n");
|
|
|
|
goto load_error;
|
|
|
|
}
|
|
|
|
alloc_rect = alloc_rect ? 2 * alloc_rect : 256;
|
|
|
|
nr = realloc(rect, alloc_rect * sizeof(*rect));
|
|
|
|
if (!nr) {
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_WARN, "delogo: out of memory\n");
|
|
|
|
goto load_error;
|
|
|
|
}
|
|
|
|
rect = nr;
|
|
|
|
}
|
|
|
|
nr = rect + n_rect;
|
|
|
|
memset(nr, 0, sizeof(*nr));
|
|
|
|
p = sscanf(line, "%lf %d:%d:%d:%d:%d",
|
|
|
|
&ts, &nr->x, &nr->y, &nr->w, &nr->h, &nr->b);
|
|
|
|
if ((p == 2 && !nr->x) || p == 5 || p == 6) {
|
|
|
|
if (ts <= last_ts)
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_WARN, "delogo: %s:%d: wrong time\n",
|
|
|
|
delogo->file, lineno);
|
|
|
|
nr->ts = 1000 * ts + 0.5;
|
|
|
|
n_rect++;
|
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_WARN, "delogo: %s:%d: syntax error\n",
|
|
|
|
delogo->file, lineno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
if (!n_rect) {
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_ERR, "delogo: %s: no rectangles found\n",
|
|
|
|
delogo->file);
|
|
|
|
free(rect);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
nr = realloc(rect, n_rect * sizeof(*rect));
|
|
|
|
if (nr)
|
|
|
|
rect = nr;
|
|
|
|
delogo->timed_rect = rect;
|
|
|
|
delogo->n_timed_rect = n_rect;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
load_error:
|
|
|
|
free(rect);
|
|
|
|
fclose(f);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
2003-09-03 22:44:28 +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;
|
2003-09-03 22:44:28 +00:00
|
|
|
vf->query_format=query_format;
|
|
|
|
|
2011-05-23 16:32:14 +00:00
|
|
|
if (vf->priv->file) {
|
|
|
|
if (load_timed_rectangles(vf->priv))
|
|
|
|
return 0;
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_V, "delogo: %d from %s\n",
|
|
|
|
vf->priv->n_timed_rect, vf->priv->file);
|
|
|
|
vf->priv->cur_timed_rect = -1;
|
2003-09-03 22:44:28 +00:00
|
|
|
}
|
2011-05-23 16:32:14 +00:00
|
|
|
fix_band(vf->priv);
|
2003-09-03 22:44:28 +00:00
|
|
|
|
|
|
|
// check csp:
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P);
|
2003-09-03 22:44:28 +00:00
|
|
|
if(!vf->priv->outfmt)
|
|
|
|
{
|
|
|
|
return 0; // no csp match :(
|
|
|
|
}
|
|
|
|
|
|
|
|
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_INT("x", xoff, 0),
|
|
|
|
OPT_INT("y", yoff, 0),
|
|
|
|
OPT_INT("w", lw, 0),
|
|
|
|
OPT_INT("h", lh, 0),
|
|
|
|
OPT_INT("t", band, 0),
|
|
|
|
OPT_INT("band", band, 0), // alias
|
|
|
|
OPT_STRING("file", file, 0),
|
|
|
|
{0}
|
2003-09-05 16:04:40 +00:00
|
|
|
};
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_delogo = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "simple logo remover",
|
|
|
|
.name = "delogo",
|
|
|
|
.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,
|
2003-09-03 22:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|