summaryrefslogtreecommitdiffstats
path: root/video/filter/vf_screenshot.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_screenshot.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_screenshot.c')
-rw-r--r--video/filter/vf_screenshot.c55
1 files changed, 9 insertions, 46 deletions
diff --git a/video/filter/vf_screenshot.c b/video/filter/vf_screenshot.c
index d94bb3c5cf..d02581a461 100644
--- a/video/filter/vf_screenshot.c
+++ b/video/filter/vf_screenshot.c
@@ -34,7 +34,7 @@
#include <libswscale/swscale.h>
struct vf_priv_s {
- mp_image_t *image;
+ int display_w, display_h;
void (*image_callback)(void *, mp_image_t *);
void *image_callback_ctx;
int shot;
@@ -46,58 +46,24 @@ static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt)
{
- free_mp_image(vf->priv->image);
- vf->priv->image = new_mp_image(width, height);
- mp_image_setfmt(vf->priv->image, outfmt);
- vf->priv->image->display_w = d_width;
- vf->priv->image->display_h = d_height;
+ vf->priv->display_w = d_width;
+ vf->priv->display_h = d_height;
return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
}
-static void get_image(struct vf_instance *vf, mp_image_t *mpi)
+static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
{
- vf->dmpi= vf_get_image(vf->next, mpi->imgfmt,
- mpi->type, mpi->flags/* | MP_IMGFLAG_READABLE*/, mpi->width, mpi->height);
-
- for (int i = 0; i < MP_MAX_PLANES; i++) {
- mpi->planes[i]=vf->dmpi->planes[i];
- mpi->stride[i]=vf->dmpi->stride[i];
- }
- mpi->width=vf->dmpi->width;
-
- mpi->flags|=MP_IMGFLAG_DIRECT;
-
- mpi->priv=(void*)vf->dmpi;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
- mp_image_t *dmpi = (mp_image_t *)mpi->priv;
-
- if(!(mpi->flags&(MP_IMGFLAG_DIRECT))){
- dmpi=vf_get_image(vf->next,mpi->imgfmt,
- MP_IMGTYPE_EXPORT, 0,
- mpi->width, mpi->height);
- vf_clone_mpi_attributes(dmpi, mpi);
- for (int i = 0; i < MP_MAX_PLANES; i++) {
- dmpi->planes[i]=mpi->planes[i];
- dmpi->stride[i]=mpi->stride[i];
- }
- dmpi->width=mpi->width;
- dmpi->height=mpi->height;
- }
-
if(vf->priv->shot) {
vf->priv->shot=0;
- mp_image_t image = *dmpi;
+ mp_image_t image = *mpi;
image.flags &= ~MP_IMGFLAG_ALLOCATED;
mp_image_copy_attributes(&image, mpi);
- mp_image_set_display_size(&image, vf->priv->image->display_w,
- vf->priv->image->display_h);
+ mp_image_set_display_size(&image, vf->priv->display_w,
+ vf->priv->display_h);
vf->priv->image_callback(vf->priv->image_callback_ctx, &image);
}
- return vf_next_put_image(vf, dmpi, pts);
+ return mpi;
}
static int control (vf_instance_t *vf, int request, void *data)
@@ -126,7 +92,6 @@ static int query_format(struct vf_instance *vf, unsigned int fmt)
static void uninit(vf_instance_t *vf)
{
- free_mp_image(vf->priv->image);
free(vf->priv);
}
@@ -134,13 +99,11 @@ static int vf_open(vf_instance_t *vf, char *args)
{
vf->config=config;
vf->control=control;
- vf->put_image=put_image;
+ vf->filter=filter;
vf->query_format=query_format;
- vf->get_image=get_image;
vf->uninit=uninit;
vf->priv=malloc(sizeof(struct vf_priv_s));
vf->priv->shot=0;
- vf->priv->image=NULL;
return 1;
}