Revision 6afd3b92 tests/rotozoom.c
tests/rotozoom.c  

5  5 
*/ 
6  6 
#include <stdlib.h> 
7  7 
#include <stdio.h> 
8 
#include <math.h> 

8 
#include <inttypes.h> 

9  
10 
#define FIXP (1<<16) 

11 
#define MY_PI 205887 //(M_PI*FIX) 

12  
13 
static int64_t int_pow(int64_t a, int p){ 

14 
int64_t v= FIXP; 

15  
16 
for(; p; p){ 

17 
v*= a; 

18 
v/= FIXP; 

19 
} 

20  
21 
return v; 

22 
} 

23  
24 
static int64_t int_sin(int64_t a){ 

25 
if(a<0) a= MY_PIa; // 0..inf 

26 
a %= 2*MY_PI; // 0..2PI 

27  
28 
if(a>=MY_PI*3/2) a = 2*MY_PI; // PI/2 .. 3PI/2 

29 
if(a>=MY_PI/2 ) a = MY_PI  a; // PI/2 .. PI/2 

30 


31 
return a  int_pow(a, 3)/6 + int_pow(a, 5)/120  int_pow(a, 7)/5040; 

32 
} 

9  33  
10  34 
#define SCALEBITS 8 
11  35 
#define ONE_HALF (1 << (SCALEBITS  1)) 
...  ...  
78  102 
/* cif format */ 
79  103 
#define DEFAULT_WIDTH 352 
80  104 
#define DEFAULT_HEIGHT 288 
81 
#define DEFAULT_NB_PICT 360


105 
#define DEFAULT_NB_PICT 50


82  106  
83  107 
void pgmyuv_save(const char *filename, int w, int h, 
84  108 
unsigned char *rgb_tab) 
...  ...  
160  184  
161  185 
for (j=0;j<h;j++) { 
162  186  
163 
x = xprime + xi; 

187 
x = xprime + xi + FIXP*w/2;


164  188 
xprime += s; 
165  189  
166 
y = yprime + yi; 

190 
y = yprime + yi + FIXP*h/2;


167  191 
yprime += c; 
168  192 

169  193 
for ( i=0 ; i<w ; i++ ) { 
170  194 
x += c; 
171  195 
y = s; 
172 
dep = ((x>>8)&255) + (y&(255<<8));


196 
dep = ((x>>16)&255) + (((y>>16)&255)<<8);


173  197 
put_pixel(i, j, tab_r[dep], tab_g[dep], tab_b[dep]); 
174  198 
} 
175  199 
} 
176  200 
teta = (teta+1) % 360; 
177  201 
} 
178  202  
203 
#define W 256 

204 
#define H 256 

205  
179  206 
void init_demo() { 
180  207 
int i,j; 
181 
double h;


182 
double radian;


183 
char line[3 * 128];


208 
int h;


209 
int radian;


210 
char line[3 * W];


184  211  
185  212 
FILE *fichier; 
186  213  
187  
188 
fichier = fopen("rotozoomffmpeg.pnm","r"); 

214 
fichier = fopen("lena.pnm","r"); 

189  215 
fread(line, 1, 15, fichier); 
190 
for (i=0;i<128;i++) {


191 
fread(line,1,3*128,fichier);


192 
for (j=0;j<128;j++) {


193 
tab_r[256*i+j] = line[3*j ];


194 
tab_g[256*i+j] = line[3*j + 1];


195 
tab_b[256*i+j] = line[3*j + 2];


216 
for (i=0;i<H;i++) {


217 
fread(line,1,3*W,fichier);


218 
for (j=0;j<W;j++) {


219 
tab_r[W*i+j] = line[3*j ];


220 
tab_g[W*i+j] = line[3*j + 1];


221 
tab_b[W*i+j] = line[3*j + 2];


196  222 
} 
197 
memcpy(tab_r + 257*128 + i*256, tab_r + i*256, 128); 

198 
memcpy(tab_g + 257*128 + i*256, tab_g + i*256, 128); 

199 
memcpy(tab_b + 257*128 + i*256, tab_b + i*256, 128); 

200  223 
} 
201  224 
fclose(fichier); 
202  225  
203 
fichier = fopen("rotozoomtux.pnm","r"); 

204 
fread(line, 1, 15, fichier); 

205 
for (i=0;i<128;i++) { 

206 
fread(line,1,3*128,fichier); 

207 
for (j=0;j<128;j++) { 

208 
tab_r[128 + 256*i+j] = line[3*j ]; 

209 
tab_g[128 + 256*i+j] = line[3*j + 1]; 

210 
tab_b[128 + 256*i+j] = line[3*j + 2]; 

211 
} 

212 
memcpy(tab_r + 256*128 + i*256, tab_r + 128 + i*256, 128); 

213 
memcpy(tab_g + 256*128 + i*256, tab_g + 128 + i*256, 128); 

214 
memcpy(tab_b + 256*128 + i*256, tab_b + 128 + i*256, 128); 

215 
} 

216 
fclose(fichier); 

217  
218  
219  
220  226 
/* tables sin/cos */ 
221  227 
for (i=0;i<360;i++) { 
222 
radian = 2*i*M_PI/360; 

223 
h = 2 + cos (radian);


224 
h_cos[i] = 256 * ( h * cos (radian) );


225 
h_sin[i] = 256 * ( h * sin (radian) );


228 
radian = 2*i*MY_PI/360;


229 
h = 2*FIXP + int_sin (radian);


230 
h_cos[i] = ( h * int_sin (radian + MY_PI/2) )/2/FIXP;


231 
h_sin[i] = ( h * int_sin (radian ) )/2/FIXP;


226  232 
} 
227  233 
} 
228  234  
...  ...  
248  254 
init_demo(); 
249  255  
250  256 
for(i=0;i<DEFAULT_NB_PICT;i++) { 
251 
snprintf(buf, sizeof(buf), "%s%03d.pgm", argv[1], i);


257 
snprintf(buf, sizeof(buf), "%s%d.pgm", argv[1], i); 

252  258 
gen_image(i, w, h); 
253  259 
pgmyuv_save(buf, w, h, rgb_tab); 
254  260 
} 
Also available in: Unified diff