annotate libmpcodecs/vf_tfields.c @ 9809:508dc4231269

Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS. Now we can really compare XviD and libavcodec :)
author rguyom
date Thu, 03 Apr 2003 06:53:01 +0000
parents e9a2af584986
children 69f10d08c3be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9514
08264c647f46 new filter
rfelker
parents:
diff changeset
1 #include <stdio.h>
08264c647f46 new filter
rfelker
parents:
diff changeset
2 #include <stdlib.h>
08264c647f46 new filter
rfelker
parents:
diff changeset
3 #include <string.h>
08264c647f46 new filter
rfelker
parents:
diff changeset
4
08264c647f46 new filter
rfelker
parents:
diff changeset
5 #include "../config.h"
08264c647f46 new filter
rfelker
parents:
diff changeset
6 #include "../mp_msg.h"
08264c647f46 new filter
rfelker
parents:
diff changeset
7
08264c647f46 new filter
rfelker
parents:
diff changeset
8 #include "img_format.h"
08264c647f46 new filter
rfelker
parents:
diff changeset
9 #include "mp_image.h"
08264c647f46 new filter
rfelker
parents:
diff changeset
10 #include "vf.h"
08264c647f46 new filter
rfelker
parents:
diff changeset
11
08264c647f46 new filter
rfelker
parents:
diff changeset
12 #include "../libvo/fastmemcpy.h"
08264c647f46 new filter
rfelker
parents:
diff changeset
13
08264c647f46 new filter
rfelker
parents:
diff changeset
14 struct vf_priv_s {
08264c647f46 new filter
rfelker
parents:
diff changeset
15 int mode;
08264c647f46 new filter
rfelker
parents:
diff changeset
16 };
08264c647f46 new filter
rfelker
parents:
diff changeset
17
08264c647f46 new filter
rfelker
parents:
diff changeset
18 static inline void *my_memcpy_pic(void * dst, void * src, int bytesPerLine, int height, int dstStride, int srcStride)
08264c647f46 new filter
rfelker
parents:
diff changeset
19 {
08264c647f46 new filter
rfelker
parents:
diff changeset
20 int i;
08264c647f46 new filter
rfelker
parents:
diff changeset
21 void *retval=dst;
08264c647f46 new filter
rfelker
parents:
diff changeset
22
08264c647f46 new filter
rfelker
parents:
diff changeset
23 for(i=0; i<height; i++)
08264c647f46 new filter
rfelker
parents:
diff changeset
24 {
08264c647f46 new filter
rfelker
parents:
diff changeset
25 memcpy(dst, src, bytesPerLine);
08264c647f46 new filter
rfelker
parents:
diff changeset
26 src+= srcStride;
08264c647f46 new filter
rfelker
parents:
diff changeset
27 dst+= dstStride;
08264c647f46 new filter
rfelker
parents:
diff changeset
28 }
08264c647f46 new filter
rfelker
parents:
diff changeset
29
08264c647f46 new filter
rfelker
parents:
diff changeset
30 return retval;
08264c647f46 new filter
rfelker
parents:
diff changeset
31 }
08264c647f46 new filter
rfelker
parents:
diff changeset
32
08264c647f46 new filter
rfelker
parents:
diff changeset
33 static void deint(unsigned char *dest, int ds, unsigned char *src, int ss, int w, int h, int field)
08264c647f46 new filter
rfelker
parents:
diff changeset
34 {
08264c647f46 new filter
rfelker
parents:
diff changeset
35 int x, y;
08264c647f46 new filter
rfelker
parents:
diff changeset
36 src += ss;
08264c647f46 new filter
rfelker
parents:
diff changeset
37 dest += ds;
08264c647f46 new filter
rfelker
parents:
diff changeset
38 if (field) {
08264c647f46 new filter
rfelker
parents:
diff changeset
39 src += ss;
08264c647f46 new filter
rfelker
parents:
diff changeset
40 dest += ds;
08264c647f46 new filter
rfelker
parents:
diff changeset
41 h -= 2;
08264c647f46 new filter
rfelker
parents:
diff changeset
42 }
08264c647f46 new filter
rfelker
parents:
diff changeset
43 for (y=h/2; y; y--) {
08264c647f46 new filter
rfelker
parents:
diff changeset
44 for (x=0; x<w; x++) {
08264c647f46 new filter
rfelker
parents:
diff changeset
45 if (((src[x-ss] < src[x]) && (src[x+ss] < src[x])) ||
08264c647f46 new filter
rfelker
parents:
diff changeset
46 ((src[x-ss] > src[x]) && (src[x+ss] > src[x]))) {
08264c647f46 new filter
rfelker
parents:
diff changeset
47 //dest[x] = (src[x+ss] + src[x-ss])>>1;
08264c647f46 new filter
rfelker
parents:
diff changeset
48 dest[x] = ((src[x+ss]<<1) + (src[x-ss]<<1)
08264c647f46 new filter
rfelker
parents:
diff changeset
49 + src[x+ss+1] + src[x-ss+1]
08264c647f46 new filter
rfelker
parents:
diff changeset
50 + src[x+ss-1] + src[x-ss-1])>>3;
08264c647f46 new filter
rfelker
parents:
diff changeset
51 }
08264c647f46 new filter
rfelker
parents:
diff changeset
52 else dest[x] = src[x];
08264c647f46 new filter
rfelker
parents:
diff changeset
53 }
08264c647f46 new filter
rfelker
parents:
diff changeset
54 dest += ds<<1;
08264c647f46 new filter
rfelker
parents:
diff changeset
55 src += ss<<1;
08264c647f46 new filter
rfelker
parents:
diff changeset
56 }
08264c647f46 new filter
rfelker
parents:
diff changeset
57 }
08264c647f46 new filter
rfelker
parents:
diff changeset
58
08264c647f46 new filter
rfelker
parents:
diff changeset
59
08264c647f46 new filter
rfelker
parents:
diff changeset
60
08264c647f46 new filter
rfelker
parents:
diff changeset
61 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi)
08264c647f46 new filter
rfelker
parents:
diff changeset
62 {
08264c647f46 new filter
rfelker
parents:
diff changeset
63 int ret;
08264c647f46 new filter
rfelker
parents:
diff changeset
64 mp_image_t *dmpi;
08264c647f46 new filter
rfelker
parents:
diff changeset
65
08264c647f46 new filter
rfelker
parents:
diff changeset
66 switch (vf->priv->mode) {
08264c647f46 new filter
rfelker
parents:
diff changeset
67 case 0:
08264c647f46 new filter
rfelker
parents:
diff changeset
68 dmpi = vf_get_image(vf->next, mpi->imgfmt,
08264c647f46 new filter
rfelker
parents:
diff changeset
69 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
08264c647f46 new filter
rfelker
parents:
diff changeset
70 mpi->width, mpi->height/2);
08264c647f46 new filter
rfelker
parents:
diff changeset
71 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
72 dmpi->stride[0], mpi->stride[0]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
73 if (mpi->flags & MP_IMGFLAG_PLANAR) {
08264c647f46 new filter
rfelker
parents:
diff changeset
74 memcpy_pic(dmpi->planes[1], mpi->planes[1],
08264c647f46 new filter
rfelker
parents:
diff changeset
75 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
76 dmpi->stride[1], mpi->stride[1]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
77 memcpy_pic(dmpi->planes[2], mpi->planes[2],
08264c647f46 new filter
rfelker
parents:
diff changeset
78 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
79 dmpi->stride[2], mpi->stride[2]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
80 }
08264c647f46 new filter
rfelker
parents:
diff changeset
81 ret = vf_next_put_image(vf, dmpi);
08264c647f46 new filter
rfelker
parents:
diff changeset
82
08264c647f46 new filter
rfelker
parents:
diff changeset
83 memcpy_pic(dmpi->planes[0], mpi->planes[0] + mpi->stride[0],
08264c647f46 new filter
rfelker
parents:
diff changeset
84 mpi->w, mpi->h/2, dmpi->stride[0], mpi->stride[0]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
85 if (mpi->flags & MP_IMGFLAG_PLANAR) {
08264c647f46 new filter
rfelker
parents:
diff changeset
86 memcpy_pic(dmpi->planes[1], mpi->planes[1] + mpi->stride[1],
08264c647f46 new filter
rfelker
parents:
diff changeset
87 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
88 dmpi->stride[1], mpi->stride[1]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
89 memcpy_pic(dmpi->planes[2], mpi->planes[2] + mpi->stride[2],
08264c647f46 new filter
rfelker
parents:
diff changeset
90 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
91 dmpi->stride[2], mpi->stride[2]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
92 }
08264c647f46 new filter
rfelker
parents:
diff changeset
93 return vf_next_put_image(vf, dmpi) || ret;
08264c647f46 new filter
rfelker
parents:
diff changeset
94 case 1:
08264c647f46 new filter
rfelker
parents:
diff changeset
95 dmpi = vf_get_image(vf->next, mpi->imgfmt,
08264c647f46 new filter
rfelker
parents:
diff changeset
96 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
08264c647f46 new filter
rfelker
parents:
diff changeset
97 mpi->width, mpi->height);
08264c647f46 new filter
rfelker
parents:
diff changeset
98 my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
99 dmpi->stride[0]*2, mpi->stride[0]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
100 deint(dmpi->planes[0], dmpi->stride[0], mpi->planes[0], mpi->stride[0], mpi->w, mpi->h, 0);
08264c647f46 new filter
rfelker
parents:
diff changeset
101 if (mpi->flags & MP_IMGFLAG_PLANAR) {
08264c647f46 new filter
rfelker
parents:
diff changeset
102 my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
08264c647f46 new filter
rfelker
parents:
diff changeset
103 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
104 dmpi->stride[1]*2, mpi->stride[1]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
105 my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
08264c647f46 new filter
rfelker
parents:
diff changeset
106 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
107 dmpi->stride[2]*2, mpi->stride[2]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
108 deint(dmpi->planes[1], dmpi->stride[1], mpi->planes[1], mpi->stride[1],
08264c647f46 new filter
rfelker
parents:
diff changeset
109 mpi->chroma_width, mpi->chroma_height, 0);
08264c647f46 new filter
rfelker
parents:
diff changeset
110 deint(dmpi->planes[2], dmpi->stride[2], mpi->planes[2], mpi->stride[2],
08264c647f46 new filter
rfelker
parents:
diff changeset
111 mpi->chroma_width, mpi->chroma_height, 0);
08264c647f46 new filter
rfelker
parents:
diff changeset
112 }
08264c647f46 new filter
rfelker
parents:
diff changeset
113 ret = vf_next_put_image(vf, dmpi);
08264c647f46 new filter
rfelker
parents:
diff changeset
114
08264c647f46 new filter
rfelker
parents:
diff changeset
115 my_memcpy_pic(dmpi->planes[0] + dmpi->stride[0], mpi->planes[0] + mpi->stride[0],
08264c647f46 new filter
rfelker
parents:
diff changeset
116 mpi->w, mpi->h/2, dmpi->stride[0]*2, mpi->stride[0]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
117 deint(dmpi->planes[0], dmpi->stride[0], mpi->planes[0], mpi->stride[0], mpi->w, mpi->h, 1);
08264c647f46 new filter
rfelker
parents:
diff changeset
118 if (mpi->flags & MP_IMGFLAG_PLANAR) {
08264c647f46 new filter
rfelker
parents:
diff changeset
119 my_memcpy_pic(dmpi->planes[1] + dmpi->stride[1], mpi->planes[1] + mpi->stride[1],
08264c647f46 new filter
rfelker
parents:
diff changeset
120 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
121 dmpi->stride[1]*2, mpi->stride[1]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
122 my_memcpy_pic(dmpi->planes[2] + dmpi->stride[2], mpi->planes[2] + mpi->stride[2],
08264c647f46 new filter
rfelker
parents:
diff changeset
123 mpi->chroma_width, mpi->chroma_height/2,
08264c647f46 new filter
rfelker
parents:
diff changeset
124 dmpi->stride[2]*2, mpi->stride[2]*2);
08264c647f46 new filter
rfelker
parents:
diff changeset
125 deint(dmpi->planes[1], dmpi->stride[1], mpi->planes[1], mpi->stride[1],
08264c647f46 new filter
rfelker
parents:
diff changeset
126 mpi->chroma_width, mpi->chroma_height, 1);
08264c647f46 new filter
rfelker
parents:
diff changeset
127 deint(dmpi->planes[2], dmpi->stride[2], mpi->planes[2], mpi->stride[2],
08264c647f46 new filter
rfelker
parents:
diff changeset
128 mpi->chroma_width, mpi->chroma_height, 1);
08264c647f46 new filter
rfelker
parents:
diff changeset
129 }
08264c647f46 new filter
rfelker
parents:
diff changeset
130 return vf_next_put_image(vf, dmpi) || ret;
08264c647f46 new filter
rfelker
parents:
diff changeset
131 }
08264c647f46 new filter
rfelker
parents:
diff changeset
132 return 0;
08264c647f46 new filter
rfelker
parents:
diff changeset
133 }
08264c647f46 new filter
rfelker
parents:
diff changeset
134
08264c647f46 new filter
rfelker
parents:
diff changeset
135 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
08264c647f46 new filter
rfelker
parents:
diff changeset
136 {
08264c647f46 new filter
rfelker
parents:
diff changeset
137 /* FIXME - figure out which other formats work */
08264c647f46 new filter
rfelker
parents:
diff changeset
138 switch (fmt) {
08264c647f46 new filter
rfelker
parents:
diff changeset
139 case IMGFMT_YV12:
08264c647f46 new filter
rfelker
parents:
diff changeset
140 case IMGFMT_IYUV:
08264c647f46 new filter
rfelker
parents:
diff changeset
141 case IMGFMT_I420:
08264c647f46 new filter
rfelker
parents:
diff changeset
142 return vf_next_query_format(vf, fmt);
08264c647f46 new filter
rfelker
parents:
diff changeset
143 }
08264c647f46 new filter
rfelker
parents:
diff changeset
144 return 0;
08264c647f46 new filter
rfelker
parents:
diff changeset
145 }
08264c647f46 new filter
rfelker
parents:
diff changeset
146
08264c647f46 new filter
rfelker
parents:
diff changeset
147 static int config(struct vf_instance_s* vf,
08264c647f46 new filter
rfelker
parents:
diff changeset
148 int width, int height, int d_width, int d_height,
08264c647f46 new filter
rfelker
parents:
diff changeset
149 unsigned int flags, unsigned int outfmt)
08264c647f46 new filter
rfelker
parents:
diff changeset
150 {
08264c647f46 new filter
rfelker
parents:
diff changeset
151 switch (vf->priv->mode) {
08264c647f46 new filter
rfelker
parents:
diff changeset
152 case 0:
08264c647f46 new filter
rfelker
parents:
diff changeset
153 return vf_next_config(vf,width,height/2,d_width,d_height,flags,outfmt);
08264c647f46 new filter
rfelker
parents:
diff changeset
154 case 1:
08264c647f46 new filter
rfelker
parents:
diff changeset
155 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
08264c647f46 new filter
rfelker
parents:
diff changeset
156 }
08264c647f46 new filter
rfelker
parents:
diff changeset
157 return 0;
08264c647f46 new filter
rfelker
parents:
diff changeset
158 }
08264c647f46 new filter
rfelker
parents:
diff changeset
159
08264c647f46 new filter
rfelker
parents:
diff changeset
160 static void uninit(struct vf_instance_s* vf)
08264c647f46 new filter
rfelker
parents:
diff changeset
161 {
08264c647f46 new filter
rfelker
parents:
diff changeset
162 free(vf->priv);
08264c647f46 new filter
rfelker
parents:
diff changeset
163 }
08264c647f46 new filter
rfelker
parents:
diff changeset
164
08264c647f46 new filter
rfelker
parents:
diff changeset
165 static int open(vf_instance_t *vf, char* args)
08264c647f46 new filter
rfelker
parents:
diff changeset
166 {
08264c647f46 new filter
rfelker
parents:
diff changeset
167 struct vf_priv_s *p;
08264c647f46 new filter
rfelker
parents:
diff changeset
168 vf->config = config;
08264c647f46 new filter
rfelker
parents:
diff changeset
169 vf->put_image = put_image;
08264c647f46 new filter
rfelker
parents:
diff changeset
170 vf->query_format = query_format;
08264c647f46 new filter
rfelker
parents:
diff changeset
171 vf->uninit = uninit;
08264c647f46 new filter
rfelker
parents:
diff changeset
172 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
08264c647f46 new filter
rfelker
parents:
diff changeset
173 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
08264c647f46 new filter
rfelker
parents:
diff changeset
174 vf->priv->mode = 0;
08264c647f46 new filter
rfelker
parents:
diff changeset
175 if (args) sscanf(args, "%d", &vf->priv->mode);
08264c647f46 new filter
rfelker
parents:
diff changeset
176 return 1;
08264c647f46 new filter
rfelker
parents:
diff changeset
177 }
08264c647f46 new filter
rfelker
parents:
diff changeset
178
08264c647f46 new filter
rfelker
parents:
diff changeset
179 vf_info_t vf_info_tfields = {
08264c647f46 new filter
rfelker
parents:
diff changeset
180 "temporal field separation",
08264c647f46 new filter
rfelker
parents:
diff changeset
181 "tfields",
08264c647f46 new filter
rfelker
parents:
diff changeset
182 "Rich Felker",
08264c647f46 new filter
rfelker
parents:
diff changeset
183 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9514
diff changeset
184 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9514
diff changeset
185 NULL
9514
08264c647f46 new filter
rfelker
parents:
diff changeset
186 };
08264c647f46 new filter
rfelker
parents:
diff changeset
187
08264c647f46 new filter
rfelker
parents:
diff changeset
188