comparison libmpcodecs/vf_test.c @ 6278:a88b82461c17

test pattern filter
author michael
date Mon, 03 Jun 2002 14:13:28 +0000
parents
children ac9c125ea627
comparison
equal deleted inserted replaced
6277:710b99c6ac05 6278:a88b82461c17
1 /*
2 Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
3
4 This program 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 This program 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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
23
24 #include "../config.h"
25 #include "../mp_msg.h"
26
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
30
31 #include "../libvo/fastmemcpy.h"
32
33 //===========================================================================//
34
35 #include <inttypes.h>
36 #include <math.h>
37
38 #define MAX(a,b) ((a) > (b) ? (a) : (b))
39 #define MIN(a,b) ((a) < (b) ? (a) : (b))
40 #define ABS(a,b) ((a) > 0 ? (a) : -(a))
41
42 #define WIDTH 512
43 #define HEIGHT 512
44
45 static int config(struct vf_instance_s* vf,
46 int width, int height, int d_width, int d_height,
47 unsigned int flags, unsigned int outfmt){
48
49 if(vf_next_query_format(vf,IMGFMT_YV12)<=0){
50 printf("yv12 not supported by next filter/vo :(\n");
51 return 0;
52 }
53
54 //hmm whats the meaning of these ... ;)
55 d_width= width= WIDTH;
56 d_height= height= HEIGHT;
57
58 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_YV12);
59 }
60
61 static double c[64];
62
63 static void initIdct()
64 {
65 int i;
66
67 for (i=0; i<8; i++)
68 {
69 double s= i==0 ? sqrt(0.125) : 0.5;
70 int j;
71
72 for(j=0; j<8; j++)
73 c[i*8+j]= s*cos((3.141592654/8.0)*i*(j+0.5));
74 }
75 }
76
77
78 static void idct(uint8_t *dst, int dstStride, int src[64])
79 {
80 int i, j, k;
81 double tmp[64];
82
83 for(i=0; i<8; i++)
84 {
85 for(j=0; j<8; j++)
86 {
87 double sum= 0.0;
88
89 for(k=0; k<8; k++)
90 sum+= c[k*8+j]*src[8*i+k];
91
92 tmp[8*i+j]= sum;
93 }
94 }
95
96 for(j=0; j<8; j++)
97 {
98 for(i=0; i<8; i++)
99 {
100 int v;
101 double sum= 0.0;
102
103 for(k=0; k<8; k++)
104 sum+= c[k*8+i]*tmp[8*k+j];
105
106 v= (int)(sum+0.5);
107 if(v<0) v=0;
108 else if(v>255) v=255;
109
110 dst[dstStride*i + j] = v;
111 }
112 }
113 }
114
115 static void drawDc(uint8_t *dst, int stride, int color, int w, int h)
116 {
117 int y;
118 for(y=0; y<h; y++)
119 {
120 int x;
121 for(x=0; x<w; x++)
122 {
123 dst[x + y*stride]= color;
124 }
125 }
126 }
127
128 static void drawBasis(uint8_t *dst, int stride, int amp, int freq, int dc)
129 {
130 int src[64];
131
132 memset(src, 0, 64*sizeof(int));
133 src[0]= dc;
134 if(amp) src[freq]= amp;
135 idct(dst, stride, src);
136 }
137
138 static void drawCbp(uint8_t *dst[3], int stride[3], int cbp, int amp, int dc)
139 {
140 if(cbp&1) drawBasis(dst[0] , stride[0], amp, 1, dc);
141 if(cbp&2) drawBasis(dst[0]+8 , stride[0], amp, 1, dc);
142 if(cbp&4) drawBasis(dst[0]+ 8*stride[0], stride[0], amp, 1, dc);
143 if(cbp&8) drawBasis(dst[0]+8+8*stride[0], stride[0], amp, 1, dc);
144 if(cbp&16)drawBasis(dst[1] , stride[1], amp, 1, dc);
145 if(cbp&32)drawBasis(dst[2] , stride[2], amp, 1, dc);
146 }
147
148 static void dc1Test(uint8_t *dst, int stride, int w, int h, int off)
149 {
150 const int step= MAX(256/(w*h/256), 1);
151 int y;
152 int color=off;
153 for(y=0; y<h; y+=16)
154 {
155 int x;
156 for(x=0; x<w; x+=16)
157 {
158 drawDc(dst + x + y*stride, stride, color, 8, 8);
159 color+=step;
160 }
161 }
162 }
163
164 static void freq1Test(uint8_t *dst, int stride, int off)
165 {
166 int y;
167 int freq=0;
168 for(y=0; y<8*16; y+=16)
169 {
170 int x;
171 for(x=0; x<8*16; x+=16)
172 {
173 drawBasis(dst + x + y*stride, stride, 4*(128+off), freq, 128*8);
174 freq++;
175 }
176 }
177 }
178
179 static void amp1Test(uint8_t *dst, int stride, int off)
180 {
181 int y;
182 int amp=off;
183 for(y=0; y<16*16; y+=16)
184 {
185 int x;
186 for(x=0; x<16*16; x+=16)
187 {
188 drawBasis(dst + x + y*stride, stride, 4*(amp), 1, 128*8);
189 amp++;
190 }
191 }
192 }
193
194 static void cbp1Test(uint8_t *dst[3], int stride[3], int off)
195 {
196 int y;
197 int cbp=0;
198 for(y=0; y<16*8; y+=16)
199 {
200 int x;
201 for(x=0; x<16*8; x+=16)
202 {
203 uint8_t *dst1[3];
204 dst1[0]= dst[0] + x*2 + y*2*stride[0];
205 dst1[1]= dst[1] + x + y*stride[1];
206 dst1[2]= dst[2] + x + y*stride[2];
207
208 drawCbp(dst1, stride, cbp, (64+off)*4, 128*8);
209 cbp++;
210 }
211 }
212 }
213
214 static void mv1Test(uint8_t *dst, int stride, int off)
215 {
216 int y;
217 for(y=0; y<16*16; y++)
218 {
219 int x;
220 if(y&16) continue;
221 for(x=0; x<16*16; x++)
222 {
223 dst[x + y*stride]= x + off*8/(y/32+1);
224 }
225 }
226 }
227
228 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
229 mp_image_t *dmpi;
230 static int frame=0;
231
232 // hope we'll get DR buffer:
233 dmpi=vf_get_image(vf->next,IMGFMT_YV12,
234 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
235 WIDTH, HEIGHT);
236
237 // clean
238 memset(dmpi->planes[0], 0, dmpi->stride[0]*dmpi->h);
239 memset(dmpi->planes[1], 128, dmpi->stride[1]*dmpi->h>>1);
240 memset(dmpi->planes[2], 128, dmpi->stride[2]*dmpi->h>>1);
241
242 if(frame%30)
243 {
244 switch(frame/30)
245 {
246 case 0: dc1Test(dmpi->planes[0], dmpi->stride[0], 256, 256, frame%30); break;
247 case 1: dc1Test(dmpi->planes[1], dmpi->stride[1], 256, 256, frame%30); break;
248 case 2: freq1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
249 case 3: freq1Test(dmpi->planes[1], dmpi->stride[1], frame%30); break;
250 case 4: amp1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
251 case 5: amp1Test(dmpi->planes[1], dmpi->stride[1], frame%30); break;
252 case 6: cbp1Test(dmpi->planes , dmpi->stride , frame%30); break;
253 case 7: mv1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
254 }
255 }
256
257 vf_next_put_image(vf,dmpi);
258 frame++;
259 }
260
261 //===========================================================================//
262
263 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
264 return vf_next_query_format(vf,IMGFMT_YV12) & (~VFCAP_CSP_SUPPORTED_BY_HW);
265 }
266
267 static int open(vf_instance_t *vf, char* args){
268 vf->config=config;
269 vf->put_image=put_image;
270 vf->query_format=query_format;
271 initIdct();
272 return 1;
273 }
274
275 vf_info_t vf_info_test = {
276 "test pattern generator",
277 "test",
278 "Michael Niedermayer",
279 "",
280 open
281 };
282
283 //===========================================================================//