docs: document --quvi-format
[mplayer.git] / libmpcodecs / vf_lavcdeint.c
blob3a67c8db59923257461d656fc20844802fe0d007
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
30 #include "libavcodec/avcodec.h"
33 struct vf_priv_s
35 int width, height;
36 int pix_fmt;
39 /* Support for avcodec's built-in deinterlacer.
40 * Based on vf_lavc.c
43 //===========================================================================//
46 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported
47 * IMGFMT's, and return -1 if the deinterlacer doesn't support
48 * that format (-1 because 0 is a valid PIX_FMT).
50 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */
51 static int
52 imgfmt_to_pixfmt (int imgfmt)
54 switch(imgfmt)
56 /* I hope I got all the supported formats */
58 /* 4:2:0 */
59 case IMGFMT_YV12:
60 case IMGFMT_I420:
61 case IMGFMT_IYUV:
62 return PIX_FMT_YUV420P;
63 break;
65 #if 0
66 /* 4:2:2 */
67 case IMGFMT_UYVY:
68 case IMGFMT_UYNV:
69 case IMGFMT_Y422:
70 case IMGFMT_YUY2:
71 case IMGFMT_YUNV:
72 case IMGFMT_YVYU:
73 case IMGFMT_Y42T:
74 case IMGFMT_V422:
75 case IMGFMT_V655:
76 return PIX_FMT_YUV422P;
77 break;
78 #endif
80 /* Are there any _planar_ YUV 4:4:4 formats? */
82 default:
83 return -1;
88 static int
89 config (struct vf_instance *vf,
90 int width, int height, int d_width, int d_height,
91 unsigned int flags, unsigned int outfmt)
93 struct vf_priv_s *priv = vf->priv;
95 priv->pix_fmt = imgfmt_to_pixfmt(outfmt);
96 if(priv->pix_fmt == -1)
97 return 0;
99 /* The deinterlacer will fail if this is false */
100 if ((width & 3) != 0 || (height & 3) != 0)
101 return 0;
103 /* If we get here, the deinterlacer is guaranteed not to fail */
105 priv->width = width;
106 priv->height = height;
108 return vf_next_config(vf,
109 width, height,
110 d_width, d_height,
111 flags, outfmt);
114 static int
115 put_image (struct vf_instance *vf, mp_image_t *mpi, double pts)
117 struct vf_priv_s *priv = vf->priv;
118 mp_image_t* dmpi;
119 AVPicture pic;
120 AVPicture lavc_picture;
122 lavc_picture.data[0] = mpi->planes[0];
123 lavc_picture.data[1] = mpi->planes[1];
124 lavc_picture.data[2] = mpi->planes[2];
125 lavc_picture.linesize[0] = mpi->stride[0];
126 lavc_picture.linesize[1] = mpi->stride[1];
127 lavc_picture.linesize[2] = mpi->stride[2];
129 dmpi = vf_get_image(vf->next, mpi->imgfmt,
130 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
131 priv->width, priv->height);
133 pic.data[0] = dmpi->planes[0];
134 pic.data[1] = dmpi->planes[1];
135 pic.data[2] = dmpi->planes[2];
136 pic.linesize[0] = dmpi->stride[0];
137 pic.linesize[1] = dmpi->stride[1];
138 pic.linesize[2] = dmpi->stride[2];
140 if (avpicture_deinterlace(&pic, &lavc_picture,
141 priv->pix_fmt, priv->width, priv->height) < 0)
143 /* This should not happen -- see config() */
144 return 0;
147 return vf_next_put_image(vf, dmpi, pts);
151 static int
152 query_format (struct vf_instance *vf, unsigned int fmt)
154 if(imgfmt_to_pixfmt(fmt) == -1)
155 return 0;
157 return vf_next_query_format(vf,fmt);
161 static int
162 vf_open(vf_instance_t *vf, char *args)
164 /* We don't have any args */
165 (void) args;
167 vf->config = config;
168 vf->put_image = put_image;
169 vf->query_format = query_format;
170 vf->priv = malloc(sizeof(struct vf_priv_s));
171 memset(vf->priv,0,sizeof(struct vf_priv_s));
173 return 1;
177 const vf_info_t vf_info_lavcdeint = {
178 "libavcodec's deinterlacing filter",
179 "lavcdeint",
180 "Joe Rabinoff",
181 "libavcodec's internal deinterlacer, in case you don't like "
182 "the builtin ones (invoked with -pp or -npp)",
183 vf_open,
184 NULL
188 //===========================================================================//