]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - tests/videogen.c
PPC: 32-bit asm for MAC64 and MLS64
[frescor/ffmpeg.git] / tests / videogen.c
index 396fcdd605721a5312250c73319e1985cf1a365f..55b7f2813e8dbc89cc4e5741f5c8d7c4e3fa16c5 100644 (file)
@@ -1,21 +1,40 @@
 /*
  * Generates a synthetic YUV video sequence suitable for codec testing.
- * NOTE: no floats are used to guaranty a bit exact output.
+ * NOTE: No floats are used to guarantee a bit exact output.
+ *
+ * Copyright (c) 2002 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
 #include <stdlib.h>
+#include <stdint.h>
 #include <stdio.h>
 
 #define SCALEBITS 8
 #define ONE_HALF  (1 << (SCALEBITS - 1))
-#define FIX(x)         ((int) ((x) * (1L<<SCALEBITS) + 0.5))
-typedef unsigned char UINT8;
+#define FIX(x)    ((int) ((x) * (1L<<SCALEBITS) + 0.5))
 
-static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
-                              UINT8 *src, int width, int height)
+static void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr,
+                              uint8_t *src, int width, int height)
 {
     int wrap, wrap3, x, y;
     int r, g, b, r1, g1, b1;
-    UINT8 *p;
+    uint8_t *p;
 
     wrap = width;
     wrap3 = width * 3;
@@ -28,7 +47,7 @@ static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
             r1 = r;
             g1 = g;
             b1 = b;
-            lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + 
+            lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
             r = p[3];
             g = p[4];
@@ -36,7 +55,7 @@ static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
             r1 += r;
             g1 += g;
             b1 += b;
-            lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + 
+            lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
             p += wrap3;
             lum += wrap;
@@ -47,7 +66,7 @@ static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
             r1 += r;
             g1 += g;
             b1 += b;
-            lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + 
+            lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
             r = p[3];
             g = p[4];
@@ -55,12 +74,12 @@ static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
             r1 += r;
             g1 += g;
             b1 += b;
-            lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + 
+            lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
-            
-            cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + 
+
+            cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +
                       FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
-            cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - 
+            cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 -
                      FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
 
             cb++;
@@ -76,10 +95,10 @@ static void rgb24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
 /* cif format */
 #define DEFAULT_WIDTH   352
 #define DEFAULT_HEIGHT  288
-#define DEFAULT_NB_PICT 125 /* 5 seconds */
+#define DEFAULT_NB_PICT 50 /* 2 seconds */
 
-void pgmyuv_save(const char *filename, int w, int h,
-                 unsigned char *rgb_tab)
+static void pgmyuv_save(const char *filename, int w, int h,
+                        unsigned char *rgb_tab)
 {
     FILE *f;
     int i, h2, w2;
@@ -92,7 +111,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;
@@ -115,7 +134,7 @@ void pgmyuv_save(const char *filename, int w, int h,
 unsigned char *rgb_tab;
 int width, height, wrap;
 
-void put_pixel(int x, int y, int r, int g, int b)
+static void put_pixel(int x, int y, int r, int g, int b)
 {
     unsigned char *p;
 
@@ -152,7 +171,7 @@ static unsigned int myrnd(unsigned int *seed_ptr, int n)
 #define FRAC_ONE (1 << FRAC_BITS)
 
 /* cosine approximate with 1-x^2 */
-int int_cos(int a)
+static int int_cos(int a)
 {
     int v, neg;
     a = a & (FRAC_ONE - 1);
@@ -179,7 +198,7 @@ VObj objs[NB_OBJS];
 
 unsigned int seed = 1;
 
-void gen_image(int num, int w, int h)
+static void gen_image(int num, int w, int h)
 {
     int r, g, b, x, y, i, dx, dy, x1, y1;
     unsigned int seed1;
@@ -221,7 +240,7 @@ void gen_image(int num, int w, int h)
             put_pixel(x + NOISE_X, y + NOISE_Y, r, g, b);
         }
     }
-    
+
     /* then moving objects */
     for(i=0;i<NB_OBJS;i++) {
         VObj *p = &objs[i];
@@ -268,11 +287,11 @@ int main(int argc, char **argv)
     height = h;
 
     for(i=0;i<DEFAULT_NB_PICT;i++) {
-        snprintf(buf, sizeof(buf), "%s%d.pgm", argv[1], i);
+        snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
         gen_image(i, w, h);
         pgmyuv_save(buf, w, h, rgb_tab);
     }
-    
+
     free(rgb_tab);
     return 0;
 }