typo fixes
[mplayer/greg.git] / libmpcodecs / vf_softpulldown.c
blob9ce22e563de6f915d3d04e141c7739da0e5be1d2
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "mp_msg.h"
8 #include "img_format.h"
9 #include "mp_image.h"
10 #include "vf.h"
12 #include "libvo/fastmemcpy.h"
13 #include "libvo/sub.h"
15 struct vf_priv_s {
16 int state;
17 long long in;
18 long long out;
21 static inline void *my_memcpy_pic(void * dst, void * src, int bytesPerLine, int height, int dstStride, int srcStride)
23 int i;
24 void *retval=dst;
26 for(i=0; i<height; i++)
28 memcpy(dst, src, bytesPerLine);
29 src+= srcStride;
30 dst+= dstStride;
33 return retval;
36 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
38 mp_image_t *dmpi;
39 int ret = 0;
40 int flags = mpi->fields;
41 int state = vf->priv->state;
43 dmpi = vf_get_image(vf->next, mpi->imgfmt,
44 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
45 MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
47 vf->priv->in++;
49 if ((state == 0 &&
50 !(flags & MP_IMGFIELD_TOP_FIRST)) ||
51 (state == 1 &&
52 flags & MP_IMGFIELD_TOP_FIRST)) {
53 mp_msg(MSGT_VFILTER, MSGL_WARN,
54 "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
55 state,
56 (flags & MP_IMGFIELD_TOP_FIRST) != 0,
57 (flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
58 state ^= 1;
61 if (state == 0) {
62 ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
63 vf->priv->out++;
64 if (flags & MP_IMGFIELD_REPEAT_FIRST) {
65 my_memcpy_pic(dmpi->planes[0],
66 mpi->planes[0], mpi->w, mpi->h/2,
67 dmpi->stride[0]*2, mpi->stride[0]*2);
68 if (mpi->flags & MP_IMGFLAG_PLANAR) {
69 my_memcpy_pic(dmpi->planes[1],
70 mpi->planes[1],
71 mpi->chroma_width,
72 mpi->chroma_height/2,
73 dmpi->stride[1]*2,
74 mpi->stride[1]*2);
75 my_memcpy_pic(dmpi->planes[2],
76 mpi->planes[2],
77 mpi->chroma_width,
78 mpi->chroma_height/2,
79 dmpi->stride[2]*2,
80 mpi->stride[2]*2);
82 state=1;
84 } else {
85 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
86 mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
87 dmpi->stride[0]*2, mpi->stride[0]*2);
88 if (mpi->flags & MP_IMGFLAG_PLANAR) {
89 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
90 mpi->planes[1]+mpi->stride[1],
91 mpi->chroma_width, mpi->chroma_height/2,
92 dmpi->stride[1]*2, mpi->stride[1]*2);
93 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
94 mpi->planes[2]+mpi->stride[2],
95 mpi->chroma_width, mpi->chroma_height/2,
96 dmpi->stride[2]*2, mpi->stride[2]*2);
98 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
99 vf->priv->out++;
100 if (flags & MP_IMGFIELD_REPEAT_FIRST) {
101 ret |= vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
102 vf->priv->out++;
103 state=0;
104 } else {
105 my_memcpy_pic(dmpi->planes[0],
106 mpi->planes[0], mpi->w, mpi->h/2,
107 dmpi->stride[0]*2, mpi->stride[0]*2);
108 if (mpi->flags & MP_IMGFLAG_PLANAR) {
109 my_memcpy_pic(dmpi->planes[1],
110 mpi->planes[1],
111 mpi->chroma_width,
112 mpi->chroma_height/2,
113 dmpi->stride[1]*2,
114 mpi->stride[1]*2);
115 my_memcpy_pic(dmpi->planes[2],
116 mpi->planes[2],
117 mpi->chroma_width,
118 mpi->chroma_height/2,
119 dmpi->stride[2]*2,
120 mpi->stride[2]*2);
125 vf->priv->state = state;
127 return ret;
130 static int config(struct vf_instance_s* vf,
131 int width, int height, int d_width, int d_height,
132 unsigned int flags, unsigned int outfmt)
134 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
137 static void uninit(struct vf_instance_s* vf)
139 mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
140 free(vf->priv);
143 static int open(vf_instance_t *vf, char* args)
145 struct vf_priv_s *p;
146 vf->config = config;
147 vf->put_image = put_image;
148 vf->uninit = uninit;
149 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
150 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
151 vf->priv->state = 0;
152 return 1;
155 vf_info_t vf_info_softpulldown = {
156 "mpeg2 soft 3:2 pulldown",
157 "softpulldown",
158 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
160 open,
161 NULL