]> git.sesse.net Git - ffmpeg/blobdiff - tests/rotozoom.c
10l (overflows)
[ffmpeg] / tests / rotozoom.c
index 71d369f9e56307d3040b2b72271a30a2d042791a..adbd0ae0549a548de679eefd3f96ccad3767944b 100644 (file)
@@ -118,7 +118,7 @@ void pgmyuv_save(const char *filename, int w, int h,
 
     rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
 
-    f = fopen(filename,"w");
+    f = fopen(filename,"wb");
     fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255);
     fwrite(lum_tab, 1, w * h, f);
     h2 = h / 2;
@@ -163,6 +163,21 @@ int teta = 0;
 int h_cos [360];
 int h_sin [360];
 
+static int ipol(uint8_t *src, int x, int y){
+    int int_x= x>>16;
+    int int_y= y>>16;
+    int frac_x= x&0xFFFF;
+    int frac_y= y&0xFFFF;
+    int s00= src[ ( int_x   &255) + 256*( int_y   &255) ];
+    int s01= src[ ((int_x+1)&255) + 256*( int_y   &255) ];
+    int s10= src[ ( int_x   &255) + 256*((int_y+1)&255) ];
+    int s11= src[ ((int_x+1)&255) + 256*((int_y+1)&255) ];
+    int s0= (((1<<16) - frac_x)*s00 + frac_x*s01)>>8;
+    int s1= (((1<<16) - frac_x)*s10 + frac_x*s11)>>8;
+    
+    return (((1<<16) - frac_y)*s0 + frac_y*s1)>>24;
+}
+
 void gen_image(int num, int w, int h)
 {
   const int c = h_cos [teta];
@@ -173,8 +188,6 @@ void gen_image(int num, int w, int h)
   
   const int xj = -(h/2) * s;
   const int yj = -(h/2) * c;
-  
-  unsigned dep;
   int i,j;
   
   int x,y;
@@ -193,8 +206,15 @@ void gen_image(int num, int w, int h)
     for ( i=0 ; i<w ; i++ ) {
       x += c;
       y -= s;
-      dep = ((x>>16)&255) + (((y>>16)&255)<<8);
-      put_pixel(i, j, tab_r[dep], tab_g[dep], tab_b[dep]);
+#if 1
+      put_pixel(i, j, ipol(tab_r, x, y), ipol(tab_g, x, y), ipol(tab_b, x, y));
+#else
+      {
+          unsigned dep;
+          dep = ((x>>16)&255) + (((y>>16)&255)<<8);
+          put_pixel(i, j, tab_r[dep], tab_g[dep], tab_b[dep]);
+      }
+#endif
     }
   }
   teta = (teta+1) % 360;
@@ -203,7 +223,7 @@ void gen_image(int num, int w, int h)
 #define W 256
 #define H 256
 
-void init_demo() {
+void init_demo(const char *filename) {
   int i,j;
   int h;
   int radian;
@@ -211,7 +231,12 @@ void init_demo() {
 
   FILE *fichier;
 
-  fichier = fopen("lena.pnm","r");
+  fichier = fopen(filename,"rb");
+  if (!fichier) {
+      perror(filename);
+      exit(1);
+  }
+      
   fread(line, 1, 15, fichier);
   for (i=0;i<H;i++) {
     fread(line,1,3*W,fichier);
@@ -237,8 +262,8 @@ int main(int argc, char **argv)
     int w, h, i;
     char buf[1024];
 
-    if (argc != 2) {
-        printf("usage: %s directory/\n"
+    if (argc != 3) {
+        printf("usage: %s directory/ image.pnm\n"
                "generate a test video stream\n", argv[0]);
         exit(1);
     }
@@ -251,7 +276,7 @@ int main(int argc, char **argv)
     width = w;
     height = h;
 
-    init_demo();
+    init_demo(argv[2]);
 
     for(i=0;i<DEFAULT_NB_PICT;i++) {
         snprintf(buf, sizeof(buf), "%s%d.pgm", argv[1], i);