ffmpeg / libavfilter / libmpcodecs / vf_test.c @ e4852fb3
History  View  Annotate  Download (9.27 KB)
1 
/*


2 
* Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>

3 
*

4 
* This file is part of MPlayer.

5 
*

6 
* MPlayer is free software; you can redistribute it and/or modify

7 
* it under the terms of the GNU General Public License as published by

8 
* the Free Software Foundation; either version 2 of the License, or

9 
* (at your option) any later version.

10 
*

11 
* MPlayer is distributed in the hope that it will be useful,

12 
* but WITHOUT ANY WARRANTY; without even the implied warranty of

13 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

14 
* GNU General Public License for more details.

15 
*

16 
* You should have received a copy of the GNU General Public License along

17 
* with MPlayer; if not, write to the Free Software Foundation, Inc.,

18 
* 51 Franklin Street, Fifth Floor, Boston, MA 021101301 USA.

19 
*/

20  
21 
#include <stdio.h> 
22 
#include <stdlib.h> 
23 
#include <string.h> 
24 
#include <inttypes.h> 
25  
26 
#include "config.h" 
27 
#include "mp_msg.h" 
28 
#include "help_mp.h" 
29  
30 
#include "img_format.h" 
31 
#include "mp_image.h" 
32 
#include "vf.h" 
33  
34 
//===========================================================================//

35  
36 
#include <inttypes.h> 
37 
#include <math.h> 
38  
39 
#define MAX(a,b) ((a) > (b) ? (a) : (b))

40 
#define MIN(a,b) ((a) < (b) ? (a) : (b))

41 
#define ABS(a,b) ((a) > 0 ? (a) : (a)) 
42  
43 
#define WIDTH 512 
44 
#define HEIGHT 512 
45  
46 
struct vf_priv_s {

47 
int frame_num;

48 
}; 
49  
50 
static int config(struct vf_instance *vf, 
51 
int width, int height, int d_width, int d_height, 
52 
unsigned int flags, unsigned int outfmt){ 
53  
54 
if(vf_next_query_format(vf,IMGFMT_YV12)<=0){ 
55 
mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_WarnNextFilterDoesntSupport, "YV12");

56 
return 0; 
57 
} 
58  
59 
//hmm whats the meaning of these ... ;)

60 
d_width= width= WIDTH; 
61 
d_height= height= HEIGHT; 
62  
63 
return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_YV12);

64 
} 
65  
66 
static double c[64]; 
67  
68 
static void initIdct(void) 
69 
{ 
70 
int i;

71  
72 
for (i=0; i<8; i++) 
73 
{ 
74 
double s= i==0 ? sqrt(0.125) : 0.5; 
75 
int j;

76  
77 
for(j=0; j<8; j++) 
78 
c[i*8+j]= s*cos((3.141592654/8.0)*i*(j+0.5)); 
79 
} 
80 
} 
81  
82  
83 
static void idct(uint8_t *dst, int dstStride, int src[64]) 
84 
{ 
85 
int i, j, k;

86 
double tmp[64]; 
87  
88 
for(i=0; i<8; i++) 
89 
{ 
90 
for(j=0; j<8; j++) 
91 
{ 
92 
double sum= 0.0; 
93  
94 
for(k=0; k<8; k++) 
95 
sum+= c[k*8+j]*src[8*i+k]; 
96  
97 
tmp[8*i+j]= sum;

98 
} 
99 
} 
100  
101 
for(j=0; j<8; j++) 
102 
{ 
103 
for(i=0; i<8; i++) 
104 
{ 
105 
int v;

106 
double sum= 0.0; 
107  
108 
for(k=0; k<8; k++) 
109 
sum+= c[k*8+i]*tmp[8*k+j]; 
110  
111 
v= (int)floor(sum+0.5); 
112 
if(v<0) v=0; 
113 
else if(v>255) v=255; 
114  
115 
dst[dstStride*i + j] = v; 
116 
} 
117 
} 
118 
} 
119  
120 
static void drawDc(uint8_t *dst, int stride, int color, int w, int h) 
121 
{ 
122 
int y;

123 
for(y=0; y<h; y++) 
124 
{ 
125 
int x;

126 
for(x=0; x<w; x++) 
127 
{ 
128 
dst[x + y*stride]= color; 
129 
} 
130 
} 
131 
} 
132  
133 
static void drawBasis(uint8_t *dst, int stride, int amp, int freq, int dc) 
134 
{ 
135 
int src[64]; 
136  
137 
memset(src, 0, 64*sizeof(int)); 
138 
src[0]= dc;

139 
if(amp) src[freq]= amp;

140 
idct(dst, stride, src); 
141 
} 
142  
143 
static void drawCbp(uint8_t *dst[3], int stride[3], int cbp, int amp, int dc) 
144 
{ 
145 
if(cbp&1) drawBasis(dst[0] , stride[0], amp, 1, dc); 
146 
if(cbp&2) drawBasis(dst[0]+8 , stride[0], amp, 1, dc); 
147 
if(cbp&4) drawBasis(dst[0]+ 8*stride[0], stride[0], amp, 1, dc); 
148 
if(cbp&8) drawBasis(dst[0]+8+8*stride[0], stride[0], amp, 1, dc); 
149 
if(cbp&16)drawBasis(dst[1] , stride[1], amp, 1, dc); 
150 
if(cbp&32)drawBasis(dst[2] , stride[2], amp, 1, dc); 
151 
} 
152  
153 
static void dc1Test(uint8_t *dst, int stride, int w, int h, int off) 
154 
{ 
155 
const int step= MAX(256/(w*h/256), 1); 
156 
int y;

157 
int color=off;

158 
for(y=0; y<h; y+=16) 
159 
{ 
160 
int x;

161 
for(x=0; x<w; x+=16) 
162 
{ 
163 
drawDc(dst + x + y*stride, stride, color, 8, 8); 
164 
color+=step; 
165 
} 
166 
} 
167 
} 
168  
169 
static void freq1Test(uint8_t *dst, int stride, int off) 
170 
{ 
171 
int y;

172 
int freq=0; 
173 
for(y=0; y<8*16; y+=16) 
174 
{ 
175 
int x;

176 
for(x=0; x<8*16; x+=16) 
177 
{ 
178 
drawBasis(dst + x + y*stride, stride, 4*(96+off), freq, 128*8); 
179 
freq++; 
180 
} 
181 
} 
182 
} 
183  
184 
static void amp1Test(uint8_t *dst, int stride, int off) 
185 
{ 
186 
int y;

187 
int amp=off;

188 
for(y=0; y<16*16; y+=16) 
189 
{ 
190 
int x;

191 
for(x=0; x<16*16; x+=16) 
192 
{ 
193 
drawBasis(dst + x + y*stride, stride, 4*(amp), 1, 128*8); 
194 
amp++; 
195 
} 
196 
} 
197 
} 
198  
199 
static void cbp1Test(uint8_t *dst[3], int stride[3], int off) 
200 
{ 
201 
int y;

202 
int cbp=0; 
203 
for(y=0; y<16*8; y+=16) 
204 
{ 
205 
int x;

206 
for(x=0; x<16*8; x+=16) 
207 
{ 
208 
uint8_t *dst1[3];

209 
dst1[0]= dst[0] + x*2 + y*2*stride[0]; 
210 
dst1[1]= dst[1] + x + y*stride[1]; 
211 
dst1[2]= dst[2] + x + y*stride[2]; 
212  
213 
drawCbp(dst1, stride, cbp, (64+off)*4, 128*8); 
214 
cbp++; 
215 
} 
216 
} 
217 
} 
218  
219 
static void mv1Test(uint8_t *dst, int stride, int off) 
220 
{ 
221 
int y;

222 
for(y=0; y<16*16; y++) 
223 
{ 
224 
int x;

225 
if(y&16) continue; 
226 
for(x=0; x<16*16; x++) 
227 
{ 
228 
dst[x + y*stride]= x + off*8/(y/32+1); 
229 
} 
230 
} 
231 
} 
232  
233 
static void ring1Test(uint8_t *dst, int stride, int off) 
234 
{ 
235 
int y;

236 
int color=0; 
237 
for(y=off; y<16*16; y+=16) 
238 
{ 
239 
int x;

240 
for(x=off; x<16*16; x+=16) 
241 
{ 
242 
drawDc(dst + x + y*stride, stride, ((x+y)&16) ? color : color, 16, 16); 
243 
// dst[x + y*stride]= 255 + (off&1);

244 
color++; 
245 
} 
246 
} 
247 
} 
248  
249 
static void ring2Test(uint8_t *dst, int stride, int off) 
250 
{ 
251 
int y;

252 
for(y=0; y<16*16; y++) 
253 
{ 
254 
int x;

255 
for(x=0; x<16*16; x++) 
256 
{ 
257 
double d= sqrt((x8*16)*(x8*16) + (y8*16)*(y8*16)); 
258 
double r= d/20  (int)(d/20); 
259 
if(r<off/30.0) 
260 
{ 
261 
dst[x + y*stride]= 255;

262 
dst[x + y*stride+256]= 0; 
263 
} 
264 
else{

265 
dst[x + y*stride]= x; 
266 
dst[x + y*stride+256]= x;

267 
} 
268 
} 
269 
} 
270 
} 
271  
272 
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ 
273 
mp_image_t *dmpi; 
274 
int frame= vf>priv>frame_num;

275  
276 
// hope we'll get DR buffer:

277 
dmpi=vf_get_image(vf>next,IMGFMT_YV12, 
278 
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, 
279 
WIDTH, HEIGHT); 
280  
281 
// clean

282 
memset(dmpi>planes[0], 0, dmpi>stride[0]*dmpi>h); 
283 
memset(dmpi>planes[1], 128, dmpi>stride[1]*dmpi>h>>dmpi>chroma_y_shift); 
284 
memset(dmpi>planes[2], 128, dmpi>stride[2]*dmpi>h>>dmpi>chroma_y_shift); 
285  
286 
if(frame%30) 
287 
{ 
288 
switch(frame/30) 
289 
{ 
290 
case 0: dc1Test(dmpi>planes[0], dmpi>stride[0], 256, 256, frame%30); break; 
291 
case 1: dc1Test(dmpi>planes[1], dmpi>stride[1], 256, 256, frame%30); break; 
292 
case 2: freq1Test(dmpi>planes[0], dmpi>stride[0], frame%30); break; 
293 
case 3: freq1Test(dmpi>planes[1], dmpi>stride[1], frame%30); break; 
294 
case 4: amp1Test(dmpi>planes[0], dmpi>stride[0], frame%30); break; 
295 
case 5: amp1Test(dmpi>planes[1], dmpi>stride[1], frame%30); break; 
296 
case 6: cbp1Test(dmpi>planes , dmpi>stride , frame%30); break; 
297 
case 7: mv1Test(dmpi>planes[0], dmpi>stride[0], frame%30); break; 
298 
case 8: ring1Test(dmpi>planes[0], dmpi>stride[0], frame%30); break; 
299 
case 9: ring2Test(dmpi>planes[0], dmpi>stride[0], frame%30); break; 
300 
} 
301 
} 
302  
303 
frame++; 
304 
vf>priv>frame_num= frame; 
305 
return vf_next_put_image(vf,dmpi, pts);

306 
} 
307  
308 
//===========================================================================//

309  
310 
static int query_format(struct vf_instance *vf, unsigned int fmt){ 
311 
return vf_next_query_format(vf,IMGFMT_YV12) & (~VFCAP_CSP_SUPPORTED_BY_HW);

312 
} 
313  
314 
static int vf_open(vf_instance_t *vf, char *args){ 
315 
vf>config=config; 
316 
vf>put_image=put_image; 
317 
vf>query_format=query_format; 
318 
vf>priv=malloc(sizeof(struct vf_priv_s)); 
319 
vf>priv>frame_num= args ? atoi(args) : 0;

320 
initIdct(); 
321 
return 1; 
322 
} 
323  
324 
const vf_info_t vf_info_test = {

325 
"test pattern generator",

326 
"test",

327 
"Michael Niedermayer",

328 
"",

329 
vf_open, 
330 
NULL

331 
}; 
332  
333 
//===========================================================================//
