comparison libmpcodecs/vf_tfields.c @ 9514:08264c647f46

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