2 * Generate a synthetic YUV video sequence suitable for codec testing.
3 * NOTE: No floats are used to guarantee bitexact output.
5 * Copyright (c) 2002 Fabrice Bellard
7 * This file is part of FFmpeg.
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 static unsigned int myrnd(unsigned int *seed_ptr
, int n
)
32 unsigned int seed
, val
;
35 seed
= (seed
* 314159) + 1;
50 #define FRAC_ONE (1 << FRAC_BITS)
52 /* cosine approximate with 1-x^2 */
53 static int int_cos(int a
)
56 a
= a
& (FRAC_ONE
- 1);
57 if (a
>= (FRAC_ONE
/ 2))
60 if (a
> (FRAC_ONE
/ 4)) {
62 a
= (FRAC_ONE
/ 2) - a
;
64 v
= FRAC_ONE
- ((a
* a
) >> 4);
76 static VObj objs
[NB_OBJS
];
78 static unsigned int seed
= 1;
80 static void gen_image(int num
, int w
, int h
)
82 int r
, g
, b
, x
, y
, i
, dx
, dy
, x1
, y1
;
86 for (i
= 0; i
< NB_OBJS
; i
++) {
87 objs
[i
].x
= myrnd(&seed
, w
);
88 objs
[i
].y
= myrnd(&seed
, h
);
89 objs
[i
].w
= myrnd(&seed
, w
/ 4) + 10;
90 objs
[i
].h
= myrnd(&seed
, h
/ 4) + 10;
91 objs
[i
].r
= myrnd(&seed
, 256);
92 objs
[i
].g
= myrnd(&seed
, 256);
93 objs
[i
].b
= myrnd(&seed
, 256);
97 /* first a moving background with gradients */
98 /* test motion estimation */
99 dx
= int_cos(num
* FRAC_ONE
/ 50) * 35;
100 dy
= int_cos(num
* FRAC_ONE
/ 50 + FRAC_ONE
/ 10) * 30;
101 for (y
= 0; y
< h
; y
++) {
102 for (x
= 0; x
< w
; x
++) {
103 x1
= (x
<< FRAC_BITS
) + dx
;
104 y1
= (y
<< FRAC_BITS
) + dy
;
105 r
= ((y1
* 7) >> FRAC_BITS
) & 0xff;
106 g
= (((x1
+ y1
) * 9) >> FRAC_BITS
) & 0xff;
107 b
= ((x1
* 5) >> FRAC_BITS
) & 0xff;
108 put_pixel(x
, y
, r
, g
, b
);
112 /* then some noise with very high intensity to test saturation */
114 for (y
= 0; y
< NOISE_W
; y
++) {
115 for (x
= 0; x
< NOISE_W
; x
++) {
116 r
= myrnd(&seed1
, 256);
117 g
= myrnd(&seed1
, 256);
118 b
= myrnd(&seed1
, 256);
119 put_pixel(x
+ NOISE_X
, y
+ NOISE_Y
, r
, g
, b
);
123 /* then moving objects */
124 for (i
= 0; i
< NB_OBJS
; i
++) {
127 for (y
= 0; y
< p
->h
; y
++) {
128 for (x
= 0; x
< p
->w
; x
++) {
132 /* add a per object noise */
133 r
+= myrnd(&seed1
, 50);
134 g
+= myrnd(&seed1
, 50);
135 b
+= myrnd(&seed1
, 50);
136 put_pixel(x
+ p
->x
, y
+ p
->y
, r
, g
, b
);
139 p
->x
+= myrnd(&seed
, 21) - 10;
140 p
->y
+= myrnd(&seed
, 21) - 10;
144 void print_help(const char* name
)
146 printf("usage: %s file|dir [w=%i] [h=%i]\n"
147 "generate a test video stream\n",
148 name
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
152 int main(int argc
, char **argv
)
158 if (argc
< 2 || argc
> 4) {
162 if (!freopen(argv
[1], "wb", stdout
))
168 if (w
< 1) print_help(argv
[0]);
173 if (h
< 1) print_help(argv
[0]);
176 rgb_tab
= malloc(w
* h
* 3);
181 for (i
= 0; i
< DEFAULT_NB_PICT
; i
++) {
184 snprintf(buf
, sizeof(buf
), "%s%02d.pgm", argv
[1], i
);
185 pgmyuv_save(buf
, w
, h
, rgb_tab
);
187 pgmyuv_save(NULL
, w
, h
, rgb_tab
);