~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/tests/videogen.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <stdint.h>
26
26
#include <stdio.h>
27
27
 
28
 
#define SCALEBITS 8
29
 
#define ONE_HALF  (1 << (SCALEBITS - 1))
30
 
#define FIX(x)    ((int) ((x) * (1L << SCALEBITS) + 0.5))
31
 
 
32
 
static void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr,
33
 
                             uint8_t *src, int width, int height)
34
 
{
35
 
    int wrap, wrap3, x, y;
36
 
    int r, g, b, r1, g1, b1;
37
 
    uint8_t *p;
38
 
 
39
 
    wrap  = width;
40
 
    wrap3 = width * 3;
41
 
    p     = src;
42
 
    for (y = 0; y < height; y += 2) {
43
 
        for (x = 0; x < width; x += 2) {
44
 
            r       = p[0];
45
 
            g       = p[1];
46
 
            b       = p[2];
47
 
            r1      = r;
48
 
            g1      = g;
49
 
            b1      = b;
50
 
            lum[0]  = (FIX(0.29900) * r + FIX(0.58700) * g +
51
 
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
52
 
            r       = p[3];
53
 
            g       = p[4];
54
 
            b       = p[5];
55
 
            r1     += r;
56
 
            g1     += g;
57
 
            b1     += b;
58
 
            lum[1]  = (FIX(0.29900) * r + FIX(0.58700) * g +
59
 
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
60
 
            p      += wrap3;
61
 
            lum    += wrap;
62
 
 
63
 
            r       = p[0];
64
 
            g       = p[1];
65
 
            b       = p[2];
66
 
            r1     += r;
67
 
            g1     += g;
68
 
            b1     += b;
69
 
            lum[0]  = (FIX(0.29900) * r + FIX(0.58700) * g +
70
 
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
71
 
            r       = p[3];
72
 
            g       = p[4];
73
 
            b       = p[5];
74
 
            r1     += r;
75
 
            g1     += g;
76
 
            b1     += b;
77
 
            lum[1]  = (FIX(0.29900) * r + FIX(0.58700) * g +
78
 
                       FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
79
 
 
80
 
            cb[0]   = 128 + ((- FIX(0.16874) * r1 -
81
 
                                FIX(0.33126) * g1 +
82
 
                                FIX(0.50000) * b1 +
83
 
                              4 * ONE_HALF - 1)
84
 
                             >> (SCALEBITS + 2));
85
 
            cr[0]   = 128 + ((FIX(0.50000) * r1 -
86
 
                              FIX(0.41869) * g1 -
87
 
                              FIX(0.08131) * b1 +
88
 
                              4 * ONE_HALF - 1)
89
 
                             >> (SCALEBITS + 2));
90
 
 
91
 
            cb++;
92
 
            cr++;
93
 
            p   += -wrap3 + 2 * 3;
94
 
            lum += -wrap + 2;
95
 
        }
96
 
        p   += wrap3;
97
 
        lum += wrap;
98
 
    }
99
 
}
100
 
 
101
 
/* cif format */
102
 
#define DEFAULT_WIDTH   352
103
 
#define DEFAULT_HEIGHT  288
104
 
#define DEFAULT_NB_PICT 50 /* 2 seconds */
105
 
 
106
 
static void pgmyuv_save(const char *filename, int w, int h,
107
 
                        unsigned char *rgb_tab)
108
 
{
109
 
    FILE *f;
110
 
    int i, h2, w2;
111
 
    unsigned char *cb, *cr;
112
 
    unsigned char *lum_tab, *cb_tab, *cr_tab;
113
 
 
114
 
    lum_tab = malloc(w * h);
115
 
    cb_tab  = malloc((w * h) / 4);
116
 
    cr_tab  = malloc((w * h) / 4);
117
 
 
118
 
    rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
119
 
 
120
 
    f = fopen(filename, "wb");
121
 
    fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255);
122
 
    fwrite(lum_tab, 1, w * h, f);
123
 
    h2 = h / 2;
124
 
    w2 = w / 2;
125
 
    cb = cb_tab;
126
 
    cr = cr_tab;
127
 
    for (i = 0; i < h2; i++) {
128
 
        fwrite(cb, 1, w2, f);
129
 
        fwrite(cr, 1, w2, f);
130
 
        cb += w2;
131
 
        cr += w2;
132
 
    }
133
 
    fclose(f);
134
 
 
135
 
    free(lum_tab);
136
 
    free(cb_tab);
137
 
    free(cr_tab);
138
 
}
139
 
 
140
 
unsigned char *rgb_tab;
141
 
int width, height, wrap;
142
 
 
143
 
static void put_pixel(int x, int y, int r, int g, int b)
144
 
{
145
 
    unsigned char *p;
146
 
 
147
 
    if (x < 0 || x >= width ||
148
 
        y < 0 || y >= height)
149
 
        return;
150
 
 
151
 
    p    = rgb_tab + y * wrap + x * 3;
152
 
    p[0] = r;
153
 
    p[1] = g;
154
 
    p[2] = b;
155
 
}
 
28
#include "utils.c"
156
29
 
157
30
static unsigned int myrnd(unsigned int *seed_ptr, int n)
158
31
{
200
73
    int r, g, b;
201
74
} VObj;
202
75
 
203
 
VObj objs[NB_OBJS];
 
76
static VObj objs[NB_OBJS];
204
77
 
205
 
unsigned int seed = 1;
 
78
static unsigned int seed = 1;
206
79
 
207
80
static void gen_image(int num, int w, int h)
208
81
{
272
145
{
273
146
    int w, h, i;
274
147
    char buf[1024];
 
148
    int isdir = 0;
275
149
 
276
150
    if (argc != 2) {
277
 
        printf("usage: %s file\n"
 
151
        printf("usage: %s file|dir\n"
278
152
               "generate a test video stream\n", argv[0]);
279
153
        exit(1);
280
154
    }
281
155
 
 
156
    if (!freopen(argv[1], "wb", stdout))
 
157
        isdir = 1;
 
158
 
282
159
    w = DEFAULT_WIDTH;
283
160
    h = DEFAULT_HEIGHT;
284
161
 
288
165
    height  = h;
289
166
 
290
167
    for (i = 0; i < DEFAULT_NB_PICT; i++) {
291
 
        snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
292
168
        gen_image(i, w, h);
293
 
        pgmyuv_save(buf, w, h, rgb_tab);
 
169
        if (isdir) {
 
170
            snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
 
171
            pgmyuv_save(buf, w, h, rgb_tab);
 
172
        } else {
 
173
            pgmyuv_save(NULL, w, h, rgb_tab);
 
174
        }
294
175
    }
295
176
 
296
177
    free(rgb_tab);