summaryrefslogtreecommitdiffstats
path: root/video/filter/vf_sub.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-05 14:25:04 +0100
committerwm4 <wm4@nowhere>2013-01-13 20:04:10 +0100
commitc54fc507da8edcc2c5d3bc3f50b0881d1c1406d7 (patch)
tree530d112301256e1c3ea50d7bb416b7ba2109130b /video/filter/vf_sub.c
parent1c412169aca2f0ad38380b0c89f2485e6a256766 (diff)
downloadmpv-c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7.tar.bz2
mpv-c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7.tar.xz
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.
Diffstat (limited to 'video/filter/vf_sub.c')
-rw-r--r--video/filter/vf_sub.c104
1 files changed, 29 insertions, 75 deletions
diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c
index 3307af0c90..10fcdbfc5b 100644
--- a/video/filter/vf_sub.c
+++ b/video/filter/vf_sub.c
@@ -89,37 +89,6 @@ static int config(struct vf_instance *vf,
d_height, flags, outfmt);
}
-static void get_image(struct vf_instance *vf, mp_image_t *mpi)
-{
- if (mpi->type == MP_IMGTYPE_IPB)
- return;
- if (mpi->flags & MP_IMGFLAG_PRESERVE)
- return;
- if (mpi->imgfmt != vf->priv->outfmt)
- return; // colorspace differ
-
- // width never changes, always try full DR
- mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type,
- mpi->flags | MP_IMGFLAG_READABLE,
- FFMAX(mpi->width, vf->priv->outw),
- FFMAX(mpi->height, vf->priv->outh));
-
- int tmargin = vf->priv->opt_top_margin;
- // set up mpi as a cropped-down image of dmpi:
- if (mpi->flags & MP_IMGFLAG_PLANAR) {
- mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0];
- mpi->planes[1] = vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1];
- mpi->planes[2] = vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2];
- mpi->stride[1] = vf->dmpi->stride[1];
- mpi->stride[2] = vf->dmpi->stride[2];
- } else {
- mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0];
- }
- mpi->stride[0] = vf->dmpi->stride[0];
- mpi->width = vf->dmpi->width;
- mpi->flags |= MP_IMGFLAG_DIRECT;
-}
-
static void blank(mp_image_t *mpi, int y1, int y2)
{
int color[3] = {16, 128, 128}; // black (YUV)
@@ -144,81 +113,67 @@ static void blank(mp_image_t *mpi, int y1, int y2)
}
}
-static int prepare_image(struct vf_instance *vf, mp_image_t *mpi)
+static void prepare_image(struct vf_instance *vf, struct mp_image *dmpi,
+ struct mp_image *mpi)
{
int tmargin = vf->priv->opt_top_margin;
- if (mpi->flags & MP_IMGFLAG_DIRECT) {
- vf->dmpi = mpi->priv;
- if (!vf->dmpi) {
- mp_tmsg(MSGT_ASS, MSGL_WARN, "Why do we get NULL??\n");
- return 0;
- }
- mpi->priv = NULL;
- // we've used DR, so we're ready...
- if (tmargin)
- blank(vf->dmpi, 0, tmargin);
- if (vf->priv->opt_bottom_margin)
- blank(vf->dmpi, vf->priv->outh - vf->priv->opt_bottom_margin,
- vf->priv->outh);
- if (!(mpi->flags & MP_IMGFLAG_PLANAR))
- vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
- return 0;
- }
-
- // hope we'll get DR buffer:
- vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP,
- MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE,
- vf->priv->outw, vf->priv->outh);
-
// copy mpi->dmpi...
if (mpi->flags & MP_IMGFLAG_PLANAR) {
- memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0],
+ memcpy_pic(dmpi->planes[0] + tmargin * dmpi->stride[0],
mpi->planes[0],
mpi->w,
mpi->h,
- vf->dmpi->stride[0],
+ dmpi->stride[0],
mpi->stride[0]);
- memcpy_pic(vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1],
+ memcpy_pic(dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * dmpi->stride[1],
mpi->planes[1],
mpi->w >> mpi->chroma_x_shift,
mpi->h >> mpi->chroma_y_shift,
- vf->dmpi->stride[1],
+ dmpi->stride[1],
mpi->stride[1]);
- memcpy_pic(vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2],
+ memcpy_pic(dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * dmpi->stride[2],
mpi->planes[2],
mpi->w >> mpi->chroma_x_shift,
mpi->h >> mpi->chroma_y_shift,
- vf->dmpi->stride[2],
+ dmpi->stride[2],
mpi->stride[2]);
} else {
- memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0],
+ memcpy_pic(dmpi->planes[0] + tmargin * dmpi->stride[0],
mpi->planes[0],
- mpi->w * (vf->dmpi->bpp / 8),
+ mpi->w * (dmpi->bpp / 8),
mpi->h,
- vf->dmpi->stride[0],
+ dmpi->stride[0],
mpi->stride[0]);
- vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
+ dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
}
if (tmargin)
- blank(vf->dmpi, 0, tmargin);
+ blank(dmpi, 0, tmargin);
if (vf->priv->opt_bottom_margin)
- blank(vf->dmpi, vf->priv->outh - vf->priv->opt_bottom_margin,
+ blank(dmpi, vf->priv->outh - vf->priv->opt_bottom_margin,
vf->priv->outh);
- return 0;
}
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
{
struct vf_priv_s *priv = vf->priv;
struct osd_state *osd = priv->osd;
- prepare_image(vf, mpi);
+ if (vf->priv->opt_top_margin || vf->priv->opt_bottom_margin ||
+ !mp_image_is_writeable(mpi))
+ {
+ struct mp_image *dmpi = vf_alloc_out_image(vf);
+ mp_image_copy_attributes(dmpi, mpi);
+ prepare_image(vf, dmpi, mpi);
+ talloc_free(mpi);
+ mpi = dmpi;
+ }
+
mp_image_set_colorspace_details(mpi, &priv->csp);
- if (pts != MP_NOPTS_VALUE)
- osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi);
+ if (mpi->pts != MP_NOPTS_VALUE)
+ osd_draw_on_image(osd, priv->dim, mpi->pts, OSD_DRAW_SUB_FILTER, mpi);
- return vf_next_put_image(vf, vf->dmpi, pts);
+ return mpi;
}
static int query_format(struct vf_instance *vf, unsigned int fmt)
@@ -273,8 +228,7 @@ static int vf_open(vf_instance_t *vf, char *args)
vf->query_format = query_format;
vf->uninit = uninit;
vf->control = control;
- vf->get_image = get_image;
- vf->put_image = put_image;
+ vf->filter = filter;
vf->default_caps = VFCAP_OSD;
return 1;
}