videotestsrc.c 34.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* GStreamer
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

20
21
22
23
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

24
25
/* non-GST-specific stuff */

26
27
#include "gstvideotestsrc.h"
#include "videotestsrc.h"
28
#include <liboil/liboil.h>
David Schleef's avatar
David Schleef committed
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43

#include <string.h>
#include <stdlib.h>

static unsigned char
random_char (void)
{
  static unsigned int state;

  state *= 1103515245;
  state += 12345;
  return (state >> 16);
}

44
#if 0
45
46
47
48
49
50
51
52
53
54
55
56
static void
random_chars (unsigned char *dest, int nbytes)
{
  int i;
  static unsigned int state;

  for (i = 0; i < nbytes; i++) {
    state *= 1103515245;
    state += 12345;
    dest[i] = (state >> 16);
  }
}
57
#endif
58

59
#if 0
60
61
62
63
64
65
66
67
68
69
70
static void
paint_rect_random (unsigned char *dest, int stride, int x, int y, int w, int h)
{
  unsigned char *d = dest + stride * y + x;
  int i;

  for (i = 0; i < h; i++) {
    random_chars (d, w);
    d += stride;
  }
}
71
#endif
72
73
74

#if 0
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
75
76
paint_rect (unsigned char *dest, int stride, int x, int y, int w, int h,
    unsigned char color)
77
78
79
80
81
{
  unsigned char *d = dest + stride * y + x;
  int i;

  for (i = 0; i < h; i++) {
David Schleef's avatar
David Schleef committed
82
    oil_splat_u8_ns (d, &color, w);
83
84
85
86
87
    d += stride;
  }
}
#endif

88
#if 0
89
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
90
91
paint_rect_s2 (unsigned char *dest, int stride, int x, int y, int w, int h,
    unsigned char col)
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
  unsigned char *d = dest + stride * y + x * 2;
  unsigned char *dp;
  int i, j;

  for (i = 0; i < h; i++) {
    dp = d;
    for (j = 0; j < w; j++) {
      *dp = col;
      dp += 2;
    }
    d += stride;
  }
}
106
#endif
107

108
#if 0
109
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110
111
paint_rect2 (unsigned char *dest, int stride, int x, int y, int w, int h,
    unsigned char *col)
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
  unsigned char *d = dest + stride * y + x * 2;
  unsigned char *dp;
  int i, j;

  for (i = 0; i < h; i++) {
    dp = d;
    for (j = 0; j < w; j++) {
      *dp++ = col[0];
      *dp++ = col[1];
    }
    d += stride;
  }
}
126
127
128
#endif

#if 0
129
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
130
131
paint_rect3 (unsigned char *dest, int stride, int x, int y, int w, int h,
    unsigned char *col)
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
  unsigned char *d = dest + stride * y + x * 3;
  unsigned char *dp;
  int i, j;

  for (i = 0; i < h; i++) {
    dp = d;
    for (j = 0; j < w; j++) {
      *dp++ = col[0];
      *dp++ = col[1];
      *dp++ = col[2];
    }
    d += stride;
  }
}
147
148
149
#endif

#if 0
150
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
151
152
paint_rect4 (unsigned char *dest, int stride, int x, int y, int w, int h,
    unsigned char *col)
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
  unsigned char *d = dest + stride * y + x * 4;
  unsigned char *dp;
  int i, j;

  for (i = 0; i < h; i++) {
    dp = d;
    for (j = 0; j < w; j++) {
      *dp++ = col[0];
      *dp++ = col[1];
      *dp++ = col[2];
      *dp++ = col[3];
    }
    d += stride;
  }
}
169
#endif
170

171
#if 0
172
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
173
174
paint_rect_s4 (unsigned char *dest, int stride, int x, int y, int w, int h,
    unsigned char col)
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{
  unsigned char *d = dest + stride * y + x * 4;
  unsigned char *dp;
  int i, j;

  for (i = 0; i < h; i++) {
    dp = d;
    for (j = 0; j < w; j++) {
      *dp = col;
      dp += 4;
    }
    d += stride;
  }
}
189
#endif
190

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
191
192
193
194
195
196
197
198
199
200
201
202
203
enum
{
  COLOR_WHITE = 0,
  COLOR_YELLOW,
  COLOR_CYAN,
  COLOR_GREEN,
  COLOR_MAGENTA,
  COLOR_RED,
  COLOR_BLUE,
  COLOR_BLACK,
  COLOR_NEG_I,
  COLOR_POS_Q,
  COLOR_SUPER_BLACK,
204
  COLOR_DARK_GREY
205
206
};

207
static const struct vts_color_struct vts_colors[] = {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  /* 100% white */
  {255, 128, 128, 255, 255, 255},
  /* yellow */
  {226, 0, 155, 255, 255, 0},
  /* cyan */
  {179, 170, 0, 0, 255, 255},
  /* green */
  {150, 46, 21, 0, 255, 0},
  /* magenta */
  {105, 212, 235, 255, 0, 255},
  /* red */
  {76, 85, 255, 255, 0, 0},
  /* blue */
  {29, 255, 107, 0, 0, 255},
  /* black */
  {16, 128, 128, 0, 0, 0},
  /* -I */
  {16, 198, 21, 0, 0, 128},
  /* +Q */
  {16, 235, 198, 0, 128, 255},
  /* superblack */
  {0, 128, 128, 0, 0, 0},
  /* 5% grey */
  {32, 128, 128, 32, 32, 32},
232
233
234
235
236
237
};


#if 0

/*                        wht  yel  cya  grn  mag  red  blu  blk   -I    Q, superblack, dark grey */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
238
239
240
241
242
static int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 16, 0, 32 };
static int u_colors[] =
    { 128, 0, 170, 46, 212, 85, 255, 128, 198, 235, 128, 128 };
static int v_colors[] =
    { 128, 155, 0, 21, 235, 255, 107, 128, 21, 198, 128, 128 };
243
244

/*                        wht  yel  cya  grn  mag  red  blu  blk   -I    Q  superblack, dark grey */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
245
246
247
static int r_colors[] = { 255, 255, 0, 0, 255, 255, 0, 0, 0, 0, 0, 32 };
static int g_colors[] = { 255, 255, 255, 255, 0, 0, 0, 0, 0, 128, 0, 32 };
static int b_colors[] = { 255, 0, 255, 0, 255, 0, 255, 0, 128, 255, 0, 32 };
248
249
250
#endif


251
252
253
254
255
256
257
258
259
static void paint_setup_I420 (paintinfo * p, unsigned char *dest);
static void paint_setup_YV12 (paintinfo * p, unsigned char *dest);
static void paint_setup_YUY2 (paintinfo * p, unsigned char *dest);
static void paint_setup_UYVY (paintinfo * p, unsigned char *dest);
static void paint_setup_YVYU (paintinfo * p, unsigned char *dest);
static void paint_setup_IYU2 (paintinfo * p, unsigned char *dest);
static void paint_setup_Y41B (paintinfo * p, unsigned char *dest);
static void paint_setup_Y42B (paintinfo * p, unsigned char *dest);
static void paint_setup_Y800 (paintinfo * p, unsigned char *dest);
260
static void paint_setup_AYUV (paintinfo * p, unsigned char *dest);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
261

262
#if 0
263
264
265
266
static void paint_setup_IMC1 (paintinfo * p, unsigned char *dest);
static void paint_setup_IMC2 (paintinfo * p, unsigned char *dest);
static void paint_setup_IMC3 (paintinfo * p, unsigned char *dest);
static void paint_setup_IMC4 (paintinfo * p, unsigned char *dest);
267
#endif
268
269
static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest);
static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest);
270
271
272
273
static void paint_setup_ARGB8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_ABGR8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_RGBA8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_BGRA8888 (paintinfo * p, unsigned char *dest);
274
275
276
277
278
279
280
281
static void paint_setup_xRGB8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_xBGR8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_RGBx8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_BGRx8888 (paintinfo * p, unsigned char *dest);
static void paint_setup_RGB888 (paintinfo * p, unsigned char *dest);
static void paint_setup_BGR888 (paintinfo * p, unsigned char *dest);
static void paint_setup_RGB565 (paintinfo * p, unsigned char *dest);
static void paint_setup_xRGB1555 (paintinfo * p, unsigned char *dest);
282
283
284

static void paint_hline_I420 (paintinfo * p, int x, int y, int w);
static void paint_hline_YUY2 (paintinfo * p, int x, int y, int w);
285
static void paint_hline_IYU2 (paintinfo * p, int x, int y, int w);
286
287
static void paint_hline_Y41B (paintinfo * p, int x, int y, int w);
static void paint_hline_Y42B (paintinfo * p, int x, int y, int w);
288
static void paint_hline_Y800 (paintinfo * p, int x, int y, int w);
289
static void paint_hline_AYUV (paintinfo * p, int x, int y, int w);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
290

291
#if 0
292
static void paint_hline_IMC1 (paintinfo * p, int x, int y, int w);
293
#endif
294
static void paint_hline_YUV9 (paintinfo * p, int x, int y, int w);
295
296
297
298
299
300
301
302
303
304
static void paint_hline_str4 (paintinfo * p, int x, int y, int w);
static void paint_hline_str3 (paintinfo * p, int x, int y, int w);
static void paint_hline_RGB565 (paintinfo * p, int x, int y, int w);
static void paint_hline_xRGB1555 (paintinfo * p, int x, int y, int w);

struct fourcc_list_struct fourcc_list[] = {
/* packed */
  {"YUY2", "YUY2", 16, paint_setup_YUY2, paint_hline_YUY2},
  {"UYVY", "UYVY", 16, paint_setup_UYVY, paint_hline_YUY2},
  {"Y422", "Y422", 16, paint_setup_UYVY, paint_hline_YUY2},
305
  {"UYNV", "UYNV", 16, paint_setup_UYVY, paint_hline_YUY2},     /* FIXME: UYNV? */
306
  {"YVYU", "YVYU", 16, paint_setup_YVYU, paint_hline_YUY2},
307
  {"AYUV", "AYUV", 32, paint_setup_AYUV, paint_hline_AYUV},
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325

  /* interlaced */
  /*{ "IUYV", "IUY2", 16, paint_setup_YVYU, paint_hline_YUY2 }, */

  /* inverted */
  /*{ "cyuv", "cyuv", 16, paint_setup_YVYU, paint_hline_YUY2 }, */

  /*{ "Y41P", "Y41P", 12, paint_setup_YVYU, paint_hline_YUY2 }, */

  /* interlaced */
  /*{ "IY41", "IY41", 12, paint_setup_YVYU, paint_hline_YUY2 }, */

  /*{ "Y211", "Y211", 8, paint_setup_YVYU, paint_hline_YUY2 }, */

  /*{ "Y41T", "Y41T", 12, paint_setup_YVYU, paint_hline_YUY2 }, */
  /*{ "Y42P", "Y42P", 16, paint_setup_YVYU, paint_hline_YUY2 }, */
  /*{ "CLJR", "CLJR", 8, paint_setup_YVYU, paint_hline_YUY2 }, */
  /*{ "IYU1", "IYU1", 12, paint_setup_YVYU, paint_hline_YUY2 }, */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
326
  {"IYU2", "IYU2", 24, paint_setup_IYU2, paint_hline_IYU2},
327
328
329

/* planar */
  /* YVU9 */
330
  {"YVU9", "YVU9", 9, paint_setup_YVU9, paint_hline_YUV9},
331
  /* YUV9 */
332
  {"YUV9", "YUV9", 9, paint_setup_YUV9, paint_hline_YUV9},
333
334
335
336
337
338
339
  /* IF09 */
  /* YV12 */
  {"YV12", "YV12", 12, paint_setup_YV12, paint_hline_I420},
  /* I420 */
  {"I420", "I420", 12, paint_setup_I420, paint_hline_I420},
  /* NV12 */
  /* NV21 */
340
#if 0
341
342
343
344
345
346
347
348
  /* IMC1 */
  {"IMC1", "IMC1", 16, paint_setup_IMC1, paint_hline_IMC1},
  /* IMC2 */
  {"IMC2", "IMC2", 12, paint_setup_IMC2, paint_hline_IMC1},
  /* IMC3 */
  {"IMC3", "IMC3", 16, paint_setup_IMC3, paint_hline_IMC1},
  /* IMC4 */
  {"IMC4", "IMC4", 12, paint_setup_IMC4, paint_hline_IMC1},
349
#endif
350
351
  /* CLPL */
  /* Y41B */
352
  {"Y41B", "Y41B", 12, paint_setup_Y41B, paint_hline_Y41B},
353
  /* Y42B */
354
  {"Y42B", "Y42B", 16, paint_setup_Y42B, paint_hline_Y42B},
355
356
357
358
  /* Y800 grayscale */
  {"Y800", "Y800", 8, paint_setup_Y800, paint_hline_Y800},

  {"RGB ", "xRGB8888", 32, paint_setup_xRGB8888, paint_hline_str4, 1, 24,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
359
      0x00ff0000, 0x0000ff00, 0x000000ff},
360
  {"RGB ", "xBGR8888", 32, paint_setup_xBGR8888, paint_hline_str4, 1, 24,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
361
      0x000000ff, 0x0000ff00, 0x00ff0000},
362
  {"RGB ", "RGBx8888", 32, paint_setup_RGBx8888, paint_hline_str4, 1, 24,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
363
      0xff000000, 0x00ff0000, 0x0000ff00},
364
  {"RGB ", "BGRx8888", 32, paint_setup_BGRx8888, paint_hline_str4, 1, 24,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
365
      0x0000ff00, 0x00ff0000, 0xff000000},
366
367
368
369
370
371
372
373
  {"RGB ", "ARGB8888", 32, paint_setup_ARGB8888, paint_hline_str4, 1, 32,
      0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
  {"RGB ", "ABGR8888", 32, paint_setup_ABGR8888, paint_hline_str4, 1, 32,
      0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000},
  {"RGB ", "RGBA8888", 32, paint_setup_RGBA8888, paint_hline_str4, 1, 32,
      0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff},
  {"RGB ", "BGRA8888", 32, paint_setup_BGRA8888, paint_hline_str4, 1, 32,
      0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff},
374
  {"RGB ", "RGB888", 24, paint_setup_RGB888, paint_hline_str3, 1, 24,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
375
      0x00ff0000, 0x0000ff00, 0x000000ff},
376
  {"RGB ", "BGR888", 24, paint_setup_BGR888, paint_hline_str3, 1, 24,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
377
      0x000000ff, 0x0000ff00, 0x00ff0000},
378
  {"RGB ", "RGB565", 16, paint_setup_RGB565, paint_hline_RGB565, 1, 16,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
379
      0x0000f800, 0x000007e0, 0x0000001f},
380
  {"RGB ", "xRGB1555", 16, paint_setup_xRGB1555, paint_hline_xRGB1555, 1, 15,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
381
      0x00007c00, 0x000003e0, 0x0000001f},
382
};
383
int n_fourccs = G_N_ELEMENTS (fourcc_list);
384

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
385
386
struct fourcc_list_struct *
paintinfo_find_by_structure (const GstStructure * structure)
387
388
{
  int i;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
389
  const char *media_type = gst_structure_get_name (structure);
David Schleef's avatar
David Schleef committed
390
  int ret;
391

David Schleef's avatar
David Schleef committed
392
393
  g_return_val_if_fail (structure, NULL);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
394
  if (strcmp (media_type, "video/x-raw-yuv") == 0) {
David Schleef's avatar
David Schleef committed
395
396
    char *s;
    int fourcc;
David Schleef's avatar
David Schleef committed
397
    guint32 format;
David Schleef's avatar
David Schleef committed
398

David Schleef's avatar
David Schleef committed
399
    ret = gst_structure_get_fourcc (structure, "format", &format);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
400
401
    if (!ret)
      return NULL;
David Schleef's avatar
David Schleef committed
402
403
    for (i = 0; i < n_fourccs; i++) {
      s = fourcc_list[i].fourcc;
404
      /* g_print("testing %" GST_FOURCC_FORMAT " and %s\n", GST_FOURCC_ARGS(format), s); */
David Schleef's avatar
David Schleef committed
405
      fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
406
      if (fourcc == format) {
407
        return fourcc_list + i;
David Schleef's avatar
David Schleef committed
408
      }
409
    }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
410
  } else if (strcmp (media_type, "video/x-raw-rgb") == 0) {
David Schleef's avatar
David Schleef committed
411
412
413
    int red_mask;
    int green_mask;
    int blue_mask;
414
    int alpha_mask;
David Schleef's avatar
David Schleef committed
415
416
417
    int depth;
    int bpp;

David Schleef's avatar
David Schleef committed
418
419
420
421
422
423
    ret = gst_structure_get_int (structure, "red_mask", &red_mask);
    ret &= gst_structure_get_int (structure, "green_mask", &green_mask);
    ret &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
    ret &= gst_structure_get_int (structure, "depth", &depth);
    ret &= gst_structure_get_int (structure, "bpp", &bpp);

424
425
426
427
428
429
430
431
432
433
434
435
    if (depth == 32) {
      ret &= gst_structure_get_int (structure, "alpha_mask", &alpha_mask);
      ret &= (alpha_mask != 0);
    } else {
      alpha_mask = 0;
    }

    if (!ret) {
      GST_WARNING ("incomplete caps structure: %" GST_PTR_FORMAT, structure);
      return NULL;
    }

David Schleef's avatar
David Schleef committed
436
    for (i = 0; i < n_fourccs; i++) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
437
      if (strcmp (fourcc_list[i].fourcc, "RGB ") == 0 &&
438
439
440
          fourcc_list[i].red_mask == red_mask &&
          fourcc_list[i].green_mask == green_mask &&
          fourcc_list[i].blue_mask == blue_mask &&
441
          (alpha_mask == 0 || fourcc_list[i].alpha_mask == alpha_mask) &&
442
443
          fourcc_list[i].depth == depth && fourcc_list[i].bitspp == bpp) {
        return fourcc_list + i;
David Schleef's avatar
David Schleef committed
444
445
      }
    }
David Schleef's avatar
David Schleef committed
446
    return NULL;
447
  }
David Schleef's avatar
David Schleef committed
448

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
449
  g_critical ("format not found for media type %s", media_type);
David Schleef's avatar
David Schleef committed
450

451
452
453
  return NULL;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
454
455
struct fourcc_list_struct *
paintrect_find_fourcc (int find_fourcc)
456
457
458
459
460
461
462
463
464
465
466
{
  int i;

  for (i = 0; i < n_fourccs; i++) {
    char *s;
    int fourcc;

    s = fourcc_list[i].fourcc;
    fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
    if (find_fourcc == fourcc) {
      /* If YUV format, it's good */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
467
      if (!fourcc_list[i].ext_caps) {
468
        return fourcc_list + i;
469
470
471
472
473
474
475
476
      }

      return fourcc_list + i;
    }
  }
  return NULL;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
477
478
struct fourcc_list_struct *
paintrect_find_name (const char *name)
479
480
481
482
{
  int i;

  for (i = 0; i < n_fourccs; i++) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
483
    if (strcmp (name, fourcc_list[i].name) == 0) {
484
485
486
487
488
489
490
      return fourcc_list + i;
    }
  }
  return NULL;
}


Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
491
492
GstStructure *
paint_get_structure (struct fourcc_list_struct * format)
493
{
494
  GstStructure *structure = NULL;
495
496
  unsigned int fourcc;

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
497
  g_return_val_if_fail (format, NULL);
498

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
499
500
501
  fourcc =
      GST_MAKE_FOURCC (format->fourcc[0], format->fourcc[1], format->fourcc[2],
      format->fourcc[3]);
502

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
503
  if (format->ext_caps) {
David Schleef's avatar
David Schleef committed
504
    int endianness;
505

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
506
    if (format->bitspp == 16) {
David Schleef's avatar
David Schleef committed
507
      endianness = G_BYTE_ORDER;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
508
    } else {
David Schleef's avatar
David Schleef committed
509
      endianness = G_BIG_ENDIAN;
510
    }
511
    structure = gst_structure_new ("video/x-raw-rgb",
512
513
514
515
516
517
        "bpp", G_TYPE_INT, format->bitspp,
        "endianness", G_TYPE_INT, endianness,
        "depth", G_TYPE_INT, format->depth,
        "red_mask", G_TYPE_INT, format->red_mask,
        "green_mask", G_TYPE_INT, format->green_mask,
        "blue_mask", G_TYPE_INT, format->blue_mask, NULL);
518
519
520
521
    if (format->depth == 32 && format->alpha_mask > 0) {
      gst_structure_set (structure, "alpha_mask", G_TYPE_INT,
          format->alpha_mask, NULL);
    }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
522
  } else {
523
    structure = gst_structure_new ("video/x-raw-yuv",
524
        "format", GST_TYPE_FOURCC, fourcc, NULL);
525
  }
526
  return structure;
527
528
}

529
/* returns the size in bytes for one video frame of the given dimensions
Andy Wingo's avatar
Andy Wingo committed
530
 * given the fourcc in GstVideoTestSrc */
531
int
532
gst_video_test_src_get_size (GstVideoTestSrc * v, int w, int h)
533
{
534
  paintinfo pi = { NULL, };
535
536
537
538
539
540
541
542
543
544
545
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return 0;

  fourcc->paint_setup (p, NULL);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
546
  return (unsigned long) p->endptr;
547
548
}

549
void
550
551
gst_video_test_src_smpte (GstVideoTestSrc * v, unsigned char *dest, int w,
    int h)
552
553
554
555
{
  int i;
  int y1, y2;
  int j;
556
  paintinfo pi = { NULL, };
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

  y1 = 2 * h / 3;
  y2 = h * 0.75;

  /* color bars */
  for (i = 0; i < 7; i++) {
    int x1 = i * w / 7;
    int x2 = (i + 1) * w / 7;

    p->color = vts_colors + i;
    for (j = 0; j < y1; j++) {
      p->paint_hline (p, x1, j, (x2 - x1));
    }
  }

  /* inverse blue bars */
  for (i = 0; i < 7; i++) {
    int x1 = i * w / 7;
    int x2 = (i + 1) * w / 7;
    int k;

    if (i & 1) {
      k = 7;
    } else {
      k = 6 - i;
    }
    p->color = vts_colors + k;
    for (j = y1; j < y2; j++) {
      p->paint_hline (p, x1, j, (x2 - x1));
    }
  }

  /* -I, white, Q regions */
  for (i = 0; i < 3; i++) {
    int x1 = i * w / 6;
    int x2 = (i + 1) * w / 6;
    int k;

    if (i == 0) {
      k = 8;
    } else if (i == 1) {
      k = 0;
    } else
      k = 9;

    p->color = vts_colors + k;
    for (j = y2; j < h; j++) {
      p->paint_hline (p, x1, j, (x2 - x1));
    }
  }

  /* superblack, black, dark grey */
  for (i = 0; i < 3; i++) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
621
622
    int x1 = w / 2 + i * w / 12;
    int x2 = w / 2 + (i + 1) * w / 12;
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
    int k;

    if (i == 0) {
      k = COLOR_SUPER_BLACK;
    } else if (i == 1) {
      k = COLOR_BLACK;
    } else
      k = COLOR_DARK_GREY;

    p->color = vts_colors + k;
    for (j = y2; j < h; j++) {
      p->paint_hline (p, x1, j, (x2 - x1));
    }
  }

  {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
639
    int x1 = w * 3 / 4;
640
641
642
643
644
645
646
    struct vts_color_struct color;

    color = vts_colors[COLOR_BLACK];
    p->color = &color;

    for (i = x1; i < w; i++) {
      for (j = y2; j < h; j++) {
647
648
649
650
651
652
        /* FIXME not strictly correct */
        color.Y = random_char ();
        color.R = color.Y;
        color.G = color.Y;
        color.B = color.Y;
        p->paint_hline (p, i, j, 1);
653
654
655
656
657
658
659
      }
    }

  }
}

void
660
gst_video_test_src_snow (GstVideoTestSrc * v, unsigned char *dest, int w, int h)
661
662
663
{
  int i;
  int j;
664
  paintinfo pi = { NULL, };
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;
  struct vts_color_struct color;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

  color = vts_colors[COLOR_BLACK];
  p->color = &color;

  for (i = 0; i < w; i++) {
    for (j = 0; j < h; j++) {
      /* FIXME not strictly correct */
      color.Y = random_char ();
      color.R = color.Y;
      color.G = color.Y;
      color.B = color.Y;
      p->paint_hline (p, i, j, 1);
    }
  }
}

693
694
static void
gst_video_test_src_unicolor (GstVideoTestSrc * v, unsigned char *dest, int w,
695
    int h, const struct vts_color_struct *color)
696
697
{
  int i;
698
  paintinfo pi = { NULL, };
699
700
701
702
703
704
705
706
707
708
709
710
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

711
  p->color = color;
712

713
714
  for (i = 0; i < h; i++) {
    p->paint_hline (p, 0, i, w);
715
716
717
  }
}

718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
void
gst_video_test_src_black (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  gst_video_test_src_unicolor (v, dest, w, h, vts_colors + COLOR_BLACK);
}

void
gst_video_test_src_white (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  gst_video_test_src_unicolor (v, dest, w, h, vts_colors + COLOR_WHITE);
}

void
gst_video_test_src_red (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  gst_video_test_src_unicolor (v, dest, w, h, vts_colors + COLOR_RED);
}

void
gst_video_test_src_green (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  gst_video_test_src_unicolor (v, dest, w, h, vts_colors + COLOR_GREEN);
}

void
gst_video_test_src_blue (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  gst_video_test_src_unicolor (v, dest, w, h, vts_colors + COLOR_BLUE);
}

748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
void
gst_video_test_src_checkers1 (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  int x, y;
  paintinfo pi = { NULL, };
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

  for (y = 0; y < h; y++) {
    p->color = vts_colors + COLOR_GREEN;
    p->paint_hline (p, 0, y, w);
    for (x = (y % 2); x < w; x += 2) {
      p->color = vts_colors + COLOR_RED;
      p->paint_hline (p, x, y, 1);
    }
  }
}

void
gst_video_test_src_checkers2 (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  int x, y;
  paintinfo pi = { NULL, };
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

  p->color = vts_colors + COLOR_GREEN;
  for (y = 0; y < h; y++) {
    p->paint_hline (p, 0, y, w);
  }

  for (y = 0; y < h; y += 2) {
    for (x = ((y % 4) == 0) ? 0 : 2; x < w; x += 4) {
      guint len = (x < (w - 1)) ? 2 : (w - x);

      p->color = vts_colors + COLOR_RED;
      p->paint_hline (p, x, y + 0, len);
      if (G_LIKELY ((y + 1) < h)) {
        p->paint_hline (p, x, y + 1, len);
      }
    }
  }
}

void
gst_video_test_src_checkers4 (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  int x, y;
  paintinfo pi = { NULL, };
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

  p->color = vts_colors + COLOR_GREEN;
  for (y = 0; y < h; y++) {
    p->paint_hline (p, 0, y, w);
  }

  for (y = 0; y < h; y += 4) {
    for (x = ((y % 8) == 0) ? 0 : 4; x < w; x += 8) {
      guint len = (x < (w - 3)) ? 4 : (w - x);

      p->color = vts_colors + COLOR_RED;
      p->paint_hline (p, x, y + 0, len);
      if (G_LIKELY ((y + 1) < h)) {
        p->paint_hline (p, x, y + 1, len);
        if (G_LIKELY ((y + 2) < h)) {
          p->paint_hline (p, x, y + 2, len);
          if (G_LIKELY ((y + 3) < h)) {
            p->paint_hline (p, x, y + 3, len);
          }
        }
      }
    }
  }
}

void
gst_video_test_src_checkers8 (GstVideoTestSrc * v, guchar * dest, int w, int h)
{
  int x, y;
  paintinfo pi = { NULL, };
  paintinfo *p = &pi;
  struct fourcc_list_struct *fourcc;

  p->width = w;
  p->height = h;
  fourcc = v->fourcc;
  if (fourcc == NULL)
    return;

  fourcc->paint_setup (p, dest);
  p->paint_hline = fourcc->paint_hline;

  p->color = vts_colors + COLOR_GREEN;
  for (y = 0; y < h; y++) {
    p->paint_hline (p, 0, y, w);
  }

  for (y = 0; y < h; y += 8) {
    for (x = ((GST_ROUND_UP_8 (y) % 16) == 0) ? 0 : 8; x < w; x += 16) {
      guint len = (x < (w - 7)) ? 8 : (w - x);

      p->color = vts_colors + COLOR_RED;
      p->paint_hline (p, x, y + 0, len);
      if (G_LIKELY ((y + 1) < h)) {
        p->paint_hline (p, x, y + 1, len);
        if (G_LIKELY ((y + 2) < h)) {
          p->paint_hline (p, x, y + 2, len);
          if (G_LIKELY ((y + 3) < h)) {
            p->paint_hline (p, x, y + 3, len);
            if (G_LIKELY ((y + 4) < h)) {
              p->paint_hline (p, x, y + 4, len);
              if (G_LIKELY ((y + 5) < h)) {
                p->paint_hline (p, x, y + 5, len);
                if (G_LIKELY ((y + 6) < h)) {
                  p->paint_hline (p, x, y + 6, len);
                  if (G_LIKELY ((y + 7) < h)) {
                    p->paint_hline (p, x, y + 7, len);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

904
static void
905
paint_setup_I420 (paintinfo * p, unsigned char *dest)
906
907
{
  p->yp = dest;
908
909
910
911
912
913
  p->ystride = GST_ROUND_UP_4 (p->width);
  p->up = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
  p->ustride = GST_ROUND_UP_8 (p->width) / 2;
  p->vp = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
  p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
  p->endptr = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
914
915
916
917
918
}

static void
paint_hline_I420 (paintinfo * p, int x, int y, int w)
{
Wim Taymans's avatar
Wim Taymans committed
919
#ifdef oil_splat_u8_ns
920
921
  int x1 = x / 2;
  int x2 = (x + w) / 2;
922
923
  int offset = y * p->ystride;
  int offset1 = (y / 2) * p->ustride;
924

David Schleef's avatar
David Schleef committed
925
926
927
  oil_splat_u8_ns (p->yp + offset + x, &p->color->Y, w);
  oil_splat_u8_ns (p->up + offset1 + x1, &p->color->U, x2 - x1);
  oil_splat_u8_ns (p->vp + offset1 + x1, &p->color->V, x2 - x1);
Wim Taymans's avatar
Wim Taymans committed
928
#endif
929
930
931
}

static void
932
paint_setup_YV12 (paintinfo * p, unsigned char *dest)
933
934
{
  p->yp = dest;
935
936
937
938
939
940
  p->ystride = GST_ROUND_UP_4 (p->width);
  p->vp = p->yp + p->ystride * GST_ROUND_UP_2 (p->height);
  p->vstride = GST_ROUND_UP_8 (p->ystride) / 2;
  p->up = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2;
  p->ustride = GST_ROUND_UP_8 (p->ystride) / 2;
  p->endptr = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2;
941
942
}

943
944
945
946
947
948
949
950
951
952
953
static void
paint_setup_AYUV (paintinfo * p, unsigned char *dest)
{
  p->ap = dest;
  p->yp = dest + 1;
  p->up = dest + 2;
  p->vp = dest + 3;
  p->ystride = p->width * 4;
  p->endptr = dest + p->ystride * p->height;
}

954
static void
955
paint_setup_YUY2 (paintinfo * p, unsigned char *dest)
956
957
958
959
{
  p->yp = dest;
  p->up = dest + 1;
  p->vp = dest + 3;
960
  p->ystride = GST_ROUND_UP_2 (p->width) * 2;
961
  p->endptr = dest + p->ystride * p->height;
962
963
964
}

static void
965
paint_setup_UYVY (paintinfo * p, unsigned char *dest)
966
967
968
969
{
  p->yp = dest + 1;
  p->up = dest;
  p->vp = dest + 2;
970
  p->ystride = GST_ROUND_UP_2 (p->width) * 2;
971
  p->endptr = dest + p->ystride * p->height;
972
973
974
}

static void
975
paint_setup_YVYU (paintinfo * p, unsigned char *dest)
976
977
978
979
{
  p->yp = dest;
  p->up = dest + 3;
  p->vp = dest + 1;
980
  p->ystride = GST_ROUND_UP_2 (p->width) * 2;
981
  p->endptr = dest + p->ystride * p->height;
982
983
}

984
985
986
987
988
989
990
991
992
993
994
995
996
997
static void
paint_hline_AYUV (paintinfo * p, int x, int y, int w)
{
  /* TODO: put into colour struct or take value from property maybe */
  const uint8_t alpha_color = 128;
  int offset;

  offset = (y * p->ystride) + (x * 4);
  oil_splat_u8 (p->yp + offset, 4, &p->color->Y, w);
  oil_splat_u8 (p->up + offset, 4, &p->color->U, w);
  oil_splat_u8 (p->vp + offset, 4, &p->color->V, w);
  oil_splat_u8 (p->ap + offset, 4, &alpha_color, w);
}

998
999
1000
1001
1002
1003
1004
static void
paint_hline_YUY2 (paintinfo * p, int x, int y, int w)
{
  int x1 = x / 2;
  int x2 = (x + w) / 2;
  int offset;

1005
  offset = y * p->ystride;
David Schleef's avatar
David Schleef committed
1006
1007
1008
  oil_splat_u8 (p->yp + offset + x * 2, 2, &p->color->Y, w);
  oil_splat_u8 (p->up + offset + x1 * 4, 4, &p->color->U, x2 - x1);
  oil_splat_u8 (p->vp + offset + x1 * 4, 4, &p->color->V, x2 - x1);
1009
1010
}

1011
static void
1012
paint_setup_IYU2 (paintinfo * p, unsigned char *dest)
1013
{
1014
  /* untested */
1015
1016
1017
  p->yp = dest + 1;
  p->up = dest + 0;
  p->vp = dest + 2;
1018
  p->ystride = GST_ROUND_UP_4 (p->width * 3);
1019
  p->endptr = dest + p->ystride * p->height;
1020
1021
1022
1023
1024
1025
1026
}

static void
paint_hline_IYU2 (paintinfo * p, int x, int y, int w)
{
  int offset;

1027
  offset = y * p->ystride;
David Schleef's avatar
David Schleef committed
1028
1029
1030
  oil_splat_u8 (p->yp + offset + x * 3, 3, &p->color->Y, w);
  oil_splat_u8 (p->up + offset + x * 3, 3, &p->color->U, w);
  oil_splat_u8 (p->vp + offset + x * 3, 3, &p->color->V, w);
1031
1032
}

1033
static void
1034
paint_setup_Y41B (paintinfo * p, unsigned char *dest)
1035
1036
{
  p->yp = dest;
1037
  p->ystride = GST_ROUND_UP_4 (p->width);
1038
  p->up = p->yp + p->ystride * p->height;
1039
  p->ustride = GST_ROUND_UP_8 (p->width) / 4;
1040
  p->vp = p->up + p->ustride * p->height;
1041
  p->vstride = GST_ROUND_UP_8 (p->width) / 4;
1042
1043
1044
1045
1046
1047
  p->endptr = p->vp + p->vstride * p->height;
}

static void
paint_hline_Y41B (paintinfo * p, int x, int y, int w)
{
Wim Taymans's avatar
Wim Taymans committed
1048
#ifdef oil_splat_u8_ns
1049
1050
1051
1052
1053
  int x1 = x / 4;
  int x2 = (x + w) / 4;
  int offset = y * p->ystride;
  int offset1 = y * p->ustride;

David Schleef's avatar
David Schleef committed
1054
1055
1056
  oil_splat_u8_ns (p->yp + offset + x, &p->color->Y, w);
  oil_splat_u8_ns (p->up + offset1 + x1, &p->color->U, x2 - x1);
  oil_splat_u8_ns (p->vp + offset1 + x1, &p->color->V, x2 - x1);
Wim Taymans's avatar
Wim Taymans committed
1057
#endif
1058
1059
1060
}

static void
1061
paint_setup_Y42B (paintinfo * p, unsigned char *dest)
1062
1063
{
  p->yp = dest;
1064
  p->ystride = GST_ROUND_UP_4 (p->width);
1065
  p->up = p->yp + p->ystride * p->height;
1066
  p->ustride = GST_ROUND_UP_8 (p->width) / 2;
1067
  p->vp = p->up + p->ustride * p->height;
1068
  p->vstride = GST_ROUND_UP_8 (p->width) / 2;
1069
1070
1071
1072
1073
1074
  p->endptr = p->vp + p->vstride * p->height;
}

static void
paint_hline_Y42B (paintinfo * p, int x, int y, int w)
{
Wim Taymans's avatar
Wim Taymans committed
1075
#ifdef oil_splat_u8_ns
1076
1077
1078
1079
1080
  int x1 = x / 2;
  int x2 = (x + w) / 2;
  int offset = y * p->ystride;
  int offset1 = y * p->ustride;

David Schleef's avatar
David Schleef committed
1081
1082
1083
  oil_splat_u8_ns (p->yp + offset + x, &p->color->Y, w);
  oil_splat_u8_ns (p->up + offset1 + x1, &p->color->U, x2 - x1);
  oil_splat_u8_ns (p->vp + offset1 + x1, &p->color->V, x2 - x1);
Wim Taymans's avatar
Wim Taymans committed
1084
#endif
1085
1086
}

1087
static void
1088
paint_setup_Y800 (paintinfo * p, unsigned char *dest)
1089
{
1090
  /* untested */
1091
  p->yp = dest;
1092
  p->ystride = GST_ROUND_UP_4 (p->width);
1093
  p->endptr = dest + p->ystride * p->height;
1094
1095
1096
1097
1098
}

static void
paint_hline_Y800 (paintinfo * p, int x, int y, int w)
{
Wim Taymans's avatar
Wim Taymans committed
1099
#ifdef oil_splat_u8_ns
1100
  int offset = y * p->ystride;
1101

David Schleef's avatar
David Schleef committed
1102
  oil_splat_u8_ns (p->yp + offset + x, &p->color->Y, w);
Wim Taymans's avatar
Wim Taymans committed
1103
#endif
1104
1105
}

1106
#if 0
1107
static void
1108
paint_setup_IMC1 (paintinfo * p, unsigned char *dest)
1109
1110
1111
1112
1113
1114
1115
{
  p->yp = dest;
  p->up = dest + p->width * p->height;
  p->vp = dest + p->width * p->height + p->width * p->height / 2;
}

static void
1116
paint_setup_IMC2 (paintinfo * p, unsigned char *dest)
1117
1118
1119
1120
1121
1122
1123
{
  p->yp = dest;
  p->vp = dest + p->width * p->height;
  p->up = dest + p->width * p->height + p->width / 2;
}

static void
1124
paint_setup_IMC3 (paintinfo * p, unsigned char *dest)
1125
1126
1127
1128
1129
1130
1131
{
  p->yp = dest;
  p->up = dest + p->width * p->height + p->width * p->height / 2;
  p->vp = dest + p->width * p->height;
}

static void
1132
paint_setup_IMC4 (paintinfo * p, unsigned char *dest)
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
{
  p->yp = dest;
  p->vp = dest + p->width * p->height + p->width / 2;
  p->up = dest + p->width * p->height;
}

static void
paint_hline_IMC1 (paintinfo * p, int x, int y, int w)
{
  int x1 = x / 2;
  int x2 = (x + w) / 2;
  int offset = y * p->width;
  int offset1 = (y / 2) * p->width;

David Schleef's avatar
David Schleef committed
1147
1148
1149
  oil_splat_u8_ns (p->yp + offset + x, &p->color->Y, w);
  oil_splat_u8_ns (p->up + offset1 + x1, &p->color->U, x2 - x1);
  oil_splat_u8_ns (p->vp + offset1 + x1, &p->color->V, x2 - x1);
1150
}
1151
#endif
1152

1153
static void
1154
paint_setup_YVU9 (paintinfo * p, unsigned char *dest)
1155
{
1156
  int h = GST_ROUND_UP_4 (p->height);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1157

1158
  p->yp = dest;
1159
1160
1161
1162
1163
1164
  p->ystride = GST_ROUND_UP_4 (p->width);
  p->vp = p->yp + p->ystride * GST_ROUND_UP_4 (p->height);
  p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
  p->up = p->vp + p->vstride * GST_ROUND_UP_4 (h / 4);
  p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
  p->endptr = p->up + p->ustride * GST_ROUND_UP_4 (h / 4);
1165
1166
1167
}

static void
1168
paint_setup_YUV9 (paintinfo * p, unsigned char *dest)
1169
{
1170
  /* untested */
1171
  int h = GST_ROUND_UP_4 (p->height);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1172

1173
  p->yp = dest;
1174
  p->ystride = GST_ROUND_UP_4 (p->width);
1175
  p->up = p->yp + p->ystride * h;
1176
1177
1178
1179
  p->ustride = GST_ROUND_UP_4 (p->ystride / 4);
  p->vp = p->up + p->ustride * GST_ROUND_UP_4 (h / 4);
  p->vstride = GST_ROUND_UP_4 (p->ystride / 4);
  p->endptr = p->vp + p->vstride * GST_ROUND_UP_4 (h / 4);
1180
1181
1182
1183
1184
}

static void
paint_hline_YUV9 (paintinfo * p, int x, int y, int w)
{
Wim Taymans's avatar
Wim Taymans committed
1185
#ifdef oil_splat_u8_ns
1186
1187
  int x1 = x / 4;
  int x2 = (x + w) / 4;
1188
1189
  int offset = y * p->ystride;
  int offset1 = (y / 4) * p->ustride;
1190

David Schleef's avatar
David Schleef committed
1191
1192
1193
  oil_splat_u8_ns (p->yp + offset + x, &p->color->Y, w);
  oil_splat_u8_ns (p->up + offset1 + x1, &p->color->U, x2 - x1);
  oil_splat_u8_ns (p->vp + offset1 + x1, &p->color->V, x2 - x1);
Wim Taymans's avatar
Wim Taymans committed
1194
#endif
1195
1196
}

1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
static void
paint_setup_ARGB8888 (paintinfo * p, unsigned char *dest)
{
  paint_setup_xRGB8888 (p, dest);
  p->ap = dest;
}

static void
paint_setup_ABGR8888 (paintinfo * p, unsigned char *dest)
{
  paint_setup_xBGR8888 (p, dest);
  p->ap = dest;
}

static void
paint_setup_RGBA8888 (paintinfo * p, unsigned char *dest)
{
  paint_setup_RGBx8888 (p, dest);
  p->ap = dest + 3;
}

static void
paint_setup_BGRA8888 (paintinfo * p, unsigned char *dest)
{
  paint_setup_BGRx8888 (p, dest);
  p->ap = dest + 3;
}

1225
static void
1226
paint_setup_xRGB8888 (paintinfo * p, unsigned char *dest)
1227
1228
1229
1230
{
  p->yp = dest + 1;
  p->up = dest + 2;
  p->vp = dest + 3;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1231
  p->ystride = p->width * 4;
1232
  p->endptr = p->dest + p->ystride * p->height;
1233
1234
1235
}

static void
1236
paint_setup_xBGR8888 (paintinfo * p, unsigned char *dest)
1237
1238
1239
1240
{
  p->yp = dest + 3;
  p->up = dest + 2;
  p->vp = dest + 1;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1241
  p->ystride = p->width * 4;
1242
  p->endptr = p->dest + p->ystride * p->height;
1243
1244
1245
}

static void
1246
paint_setup_RGBx8888 (paintinfo * p, unsigned char *dest)
1247
1248
1249
1250
{
  p->yp = dest + 0;
  p->up = dest + 1;
  p->vp = dest + 2;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1251
  p->ystride = p->width * 4;
1252
  p->endptr = p->dest + p->ystride * p->height;
1253
1254
1255
}

static void
1256
paint_setup_BGRx8888 (paintinfo * p, unsigned char *dest)
David Schleef's avatar