FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_telecine.c
Go to the documentation of this file.
1 /*
2  * This file is part of MPlayer.
3  *
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.
8  *
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.
13  *
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.
17  */
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include "config.h"
24 #include "mp_msg.h"
25 
26 #include "img_format.h"
27 #include "mp_image.h"
28 #include "vf.h"
29 
30 #include "libvo/fastmemcpy.h"
31 
32 struct vf_priv_s {
33  int frame;
34 };
35 
36 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
37 {
38  mp_image_t *dmpi;
39  int ret;
40  int w = (IMGFMT_IS_YUVP16(mpi->imgfmt) ? 2 : 1) * mpi->w;
41  int chroma_width = (IMGFMT_IS_YUVP16(mpi->imgfmt) ? 2 : 1) * mpi->chroma_width;
42 
43  vf->priv->frame = (vf->priv->frame+1)%4;
44 
45  dmpi = ff_vf_get_image(vf->next, mpi->imgfmt,
47  MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
48 
49  ret = 0;
50  // 0/0 1/1 2/2 2/3 3/0
51  switch (vf->priv->frame) {
52  case 0:
53  my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
54  mpi->planes[0]+mpi->stride[0], w, mpi->h/2,
55  dmpi->stride[0]*2, mpi->stride[0]*2);
56  if (mpi->flags & MP_IMGFLAG_PLANAR) {
57  my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
58  mpi->planes[1]+mpi->stride[1],
59  chroma_width, mpi->chroma_height/2,
60  dmpi->stride[1]*2, mpi->stride[1]*2);
61  my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
62  mpi->planes[2]+mpi->stride[2],
63  chroma_width, mpi->chroma_height/2,
64  dmpi->stride[2]*2, mpi->stride[2]*2);
65  }
66  ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
67  /* Fallthrough */
68  case 1:
69  case 2:
70  memcpy_pic(dmpi->planes[0], mpi->planes[0], w, mpi->h,
71  dmpi->stride[0], mpi->stride[0]);
72  if (mpi->flags & MP_IMGFLAG_PLANAR) {
73  memcpy_pic(dmpi->planes[1], mpi->planes[1],
74  chroma_width, mpi->chroma_height,
75  dmpi->stride[1], mpi->stride[1]);
76  memcpy_pic(dmpi->planes[2], mpi->planes[2],
77  chroma_width, mpi->chroma_height,
78  dmpi->stride[2], mpi->stride[2]);
79  }
80  return ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret;
81  case 3:
82  my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
83  mpi->planes[0]+mpi->stride[0], w, mpi->h/2,
84  dmpi->stride[0]*2, mpi->stride[0]*2);
85  if (mpi->flags & MP_IMGFLAG_PLANAR) {
86  my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
87  mpi->planes[1]+mpi->stride[1],
88  chroma_width, mpi->chroma_height/2,
89  dmpi->stride[1]*2, mpi->stride[1]*2);
90  my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
91  mpi->planes[2]+mpi->stride[2],
92  chroma_width, mpi->chroma_height/2,
93  dmpi->stride[2]*2, mpi->stride[2]*2);
94  }
95  ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
96  my_memcpy_pic(dmpi->planes[0], mpi->planes[0], w, mpi->h/2,
97  dmpi->stride[0]*2, mpi->stride[0]*2);
98  if (mpi->flags & MP_IMGFLAG_PLANAR) {
99  my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
100  chroma_width, mpi->chroma_height/2,
101  dmpi->stride[1]*2, mpi->stride[1]*2);
102  my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
103  chroma_width, mpi->chroma_height/2,
104  dmpi->stride[2]*2, mpi->stride[2]*2);
105  }
106  return ret;
107  }
108  return 0;
109 }
110 
111 #if 0
112 static int query_format(struct vf_instance *vf, unsigned int fmt)
113 {
114  /* FIXME - figure out which other formats work */
115  switch (fmt) {
116  case IMGFMT_YV12:
117  case IMGFMT_IYUV:
118  case IMGFMT_I420:
119  return ff_vf_next_query_format(vf, fmt);
120  }
121  return 0;
122 }
123 
124 static int config(struct vf_instance *vf,
125  int width, int height, int d_width, int d_height,
126  unsigned int flags, unsigned int outfmt)
127 {
128  return ff_vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
129 }
130 #endif
131 
132 static void uninit(struct vf_instance *vf)
133 {
134  free(vf->priv);
135 }
136 
137 static int vf_open(vf_instance_t *vf, char *args)
138 {
139  //vf->config = config;
140  vf->put_image = put_image;
141  //vf->query_format = query_format;
142  vf->uninit = uninit;
144  vf->priv = calloc(1, sizeof(struct vf_priv_s));
145  vf->priv->frame = 1;
146  if (args) sscanf(args, "%d", &vf->priv->frame);
147  vf->priv->frame--;
148  return 1;
149 }
150 
152  "telecine filter",
153  "telecine",
154  "Rich Felker",
155  "",
156  vf_open,
157  NULL
158 };