00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025 #include <stdint.h>
00026 #include <stdio.h>
00027
00028 #include "utils.c"
00029
00030 static unsigned int myrnd(unsigned int *seed_ptr, int n)
00031 {
00032 unsigned int seed, val;
00033
00034 seed = *seed_ptr;
00035 seed = (seed * 314159) + 1;
00036 if (n == 256) {
00037 val = seed >> 24;
00038 } else {
00039 val = seed % n;
00040 }
00041 *seed_ptr = seed;
00042 return val;
00043 }
00044
00045 #define NOISE_X 10
00046 #define NOISE_Y 30
00047 #define NOISE_W 26
00048
00049 #define FRAC_BITS 8
00050 #define FRAC_ONE (1 << FRAC_BITS)
00051
00052
00053 static int int_cos(int a)
00054 {
00055 int v, neg;
00056 a = a & (FRAC_ONE - 1);
00057 if (a >= (FRAC_ONE / 2))
00058 a = FRAC_ONE - a;
00059 neg = 0;
00060 if (a > (FRAC_ONE / 4)) {
00061 neg = -1;
00062 a = (FRAC_ONE / 2) - a;
00063 }
00064 v = FRAC_ONE - ((a * a) >> 4);
00065 v = (v ^ neg) - neg;
00066 return v;
00067 }
00068
00069 #define NB_OBJS 10
00070
00071 typedef struct VObj {
00072 int x, y, w, h;
00073 int r, g, b;
00074 } VObj;
00075
00076 static VObj objs[NB_OBJS];
00077
00078 static unsigned int seed = 1;
00079
00080 static void gen_image(int num, int w, int h)
00081 {
00082 int r, g, b, x, y, i, dx, dy, x1, y1;
00083 unsigned int seed1;
00084
00085 if (num == 0) {
00086 for (i = 0; i < NB_OBJS; i++) {
00087 objs[i].x = myrnd(&seed, w);
00088 objs[i].y = myrnd(&seed, h);
00089 objs[i].w = myrnd(&seed, w / 4) + 10;
00090 objs[i].h = myrnd(&seed, h / 4) + 10;
00091 objs[i].r = myrnd(&seed, 256);
00092 objs[i].g = myrnd(&seed, 256);
00093 objs[i].b = myrnd(&seed, 256);
00094 }
00095 }
00096
00097
00098
00099 dx = int_cos(num * FRAC_ONE / 50) * 35;
00100 dy = int_cos(num * FRAC_ONE / 50 + FRAC_ONE / 10) * 30;
00101 for (y = 0; y < h; y++) {
00102 for (x = 0; x < w; x++) {
00103 x1 = (x << FRAC_BITS) + dx;
00104 y1 = (y << FRAC_BITS) + dy;
00105 r = ((y1 * 7) >> FRAC_BITS) & 0xff;
00106 g = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff;
00107 b = ((x1 * 5) >> FRAC_BITS) & 0xff;
00108 put_pixel(x, y, r, g, b);
00109 }
00110 }
00111
00112
00113 seed1 = num;
00114 for (y = 0; y < NOISE_W; y++) {
00115 for (x = 0; x < NOISE_W; x++) {
00116 r = myrnd(&seed1, 256);
00117 g = myrnd(&seed1, 256);
00118 b = myrnd(&seed1, 256);
00119 put_pixel(x + NOISE_X, y + NOISE_Y, r, g, b);
00120 }
00121 }
00122
00123
00124 for (i = 0; i < NB_OBJS; i++) {
00125 VObj *p = &objs[i];
00126 seed1 = i;
00127 for (y = 0; y < p->h; y++) {
00128 for (x = 0; x < p->w; x++) {
00129 r = p->r;
00130 g = p->g;
00131 b = p->b;
00132
00133 r += myrnd(&seed1, 50);
00134 g += myrnd(&seed1, 50);
00135 b += myrnd(&seed1, 50);
00136 put_pixel(x + p->x, y + p->y, r, g, b);
00137 }
00138 }
00139 p->x += myrnd(&seed, 21) - 10;
00140 p->y += myrnd(&seed, 21) - 10;
00141 }
00142 }
00143
00144 int main(int argc, char **argv)
00145 {
00146 int w, h, i;
00147 char buf[1024];
00148
00149 if (argc != 2) {
00150 printf("usage: %s file\n"
00151 "generate a test video stream\n", argv[0]);
00152 exit(1);
00153 }
00154
00155 w = DEFAULT_WIDTH;
00156 h = DEFAULT_HEIGHT;
00157
00158 rgb_tab = malloc(w * h * 3);
00159 wrap = w * 3;
00160 width = w;
00161 height = h;
00162
00163 for (i = 0; i < DEFAULT_NB_PICT; i++) {
00164 snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
00165 gen_image(i, w, h);
00166 pgmyuv_save(buf, w, h, rgb_tab);
00167 }
00168
00169 free(rgb_tab);
00170 return 0;
00171 }