blend.c 35.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* 
 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
 * Copyright (C) 2006 Mindfruit Bv.
 *   Author: Sjoerd Simons <sjoerd@luon.net>
 *   Author: Alex Ugarte <alexugarte@gmail.com>
 * Copyright (C) 2009 Alex Ugarte <augarte@vicomtech.org>
 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
 *
 * 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
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
21 22
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
23 24 25 26 27 28 29
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "blend.h"
30
#include "videomixerorc.h"
31 32 33

#include <string.h>

34 35
#include <gst/video/video.h>

36 37
#define BLEND(D,S,alpha) (((D) * (256 - (alpha)) + (S) * (alpha)) >> 8)

38 39 40
GST_DEBUG_CATEGORY_STATIC (gst_videomixer_blend_debug);
#define GST_CAT_DEFAULT gst_videomixer_blend_debug

41 42 43
/* Below are the implementations of everything */

/* A32 is for AYUV, ARGB and BGRA */
44
#define BLEND_A32(name, method, LOOP)		\
45
static void \
46
method##_ ##name (GstVideoFrame * srcframe, gint xpos, gint ypos, \
Wim Taymans's avatar
Wim Taymans committed
47
    gdouble src_alpha, GstVideoFrame * destframe) \
48 49 50
{ \
  guint s_alpha; \
  gint src_stride, dest_stride; \
51 52
  gint dest_width, dest_height; \
  guint8 *src, *dest; \
Wim Taymans's avatar
Wim Taymans committed
53
  gint src_width, src_height; \
54
  \
Wim Taymans's avatar
Wim Taymans committed
55 56
  src_width = GST_VIDEO_FRAME_WIDTH (srcframe); \
  src_height = GST_VIDEO_FRAME_HEIGHT (srcframe); \
57 58 59 60 61 62
  src = GST_VIDEO_FRAME_PLANE_DATA (srcframe, 0); \
  src_stride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \
  dest = GST_VIDEO_FRAME_PLANE_DATA (destframe, 0); \
  dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \
  dest_width = GST_VIDEO_FRAME_COMP_WIDTH (destframe, 0); \
  dest_height = GST_VIDEO_FRAME_COMP_HEIGHT (destframe, 0); \
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
  \
  s_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \
  \
  /* If it's completely transparent... we just return */ \
  if (G_UNLIKELY (s_alpha == 0)) \
    return; \
  \
  /* adjust src pointers for negative sizes */ \
  if (xpos < 0) { \
    src += -xpos * 4; \
    src_width -= -xpos; \
    xpos = 0; \
  } \
  if (ypos < 0) { \
    src += -ypos * src_stride; \
    src_height -= -ypos; \
    ypos = 0; \
  } \
  /* adjust width/height if the src is bigger than dest */ \
  if (xpos + src_width > dest_width) { \
    src_width = dest_width - xpos; \
  } \
  if (ypos + src_height > dest_height) { \
    src_height = dest_height - ypos; \
  } \
  \
89 90
  if (src_height > 0 && src_width > 0) { \
    dest = dest + 4 * xpos + (ypos * dest_stride); \
91
  \
92 93
    LOOP (dest, src, src_height, src_width, src_stride, dest_stride, s_alpha); \
  } \
94 95
}

96
#define BLEND_A32_LOOP(name, method)			\
97
static inline void \
98
_##method##_loop_##name (guint8 * dest, const guint8 * src, gint src_height, \
99 100 101
    gint src_width, gint src_stride, gint dest_stride, guint s_alpha) \
{ \
  s_alpha = MIN (255, s_alpha); \
102
  video_mixer_orc_##method##_##name (dest, dest_stride, src, src_stride, \
103
      s_alpha, src_width, src_height); \
104 105
}

106 107 108 109
BLEND_A32_LOOP (argb, blend);
BLEND_A32_LOOP (bgra, blend);
BLEND_A32_LOOP (argb, overlay);
BLEND_A32_LOOP (bgra, overlay);
110

111
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
112 113 114 115
BLEND_A32 (argb, blend, _blend_loop_argb);
BLEND_A32 (bgra, blend, _blend_loop_bgra);
BLEND_A32 (argb, overlay, _overlay_loop_argb);
BLEND_A32 (bgra, overlay, _overlay_loop_bgra);
116
#else
117 118 119 120
BLEND_A32 (argb, blend, _blend_loop_bgra);
BLEND_A32 (bgra, blend, _blend_loop_argb);
BLEND_A32 (argb, overlay, _overlay_loop_bgra);
BLEND_A32 (bgra, overlay, _overlay_loop_argb);
121
#endif
122 123 124

#define A32_CHECKER_C(name, RGB, A, C1, C2, C3) \
static void \
125
fill_checker_##name##_c (GstVideoFrame * frame) \
126 127 128 129
{ \
  gint i, j; \
  gint val; \
  static const gint tab[] = { 80, 160, 80, 160 }; \
130 131 132 133 134 135
  gint width, height; \
  guint8 *dest; \
  \
  dest = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
  width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0); \
  height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0); \
136 137 138 139 140 141 142 143
  \
  if (!RGB) { \
    for (i = 0; i < height; i++) { \
      for (j = 0; j < width; j++) { \
        dest[A] = 0xff; \
        dest[C1] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; \
        dest[C2] = 128; \
        dest[C3] = 128; \
144
        dest += 4; \
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
      } \
    } \
  } else { \
    for (i = 0; i < height; i++) { \
      for (j = 0; j < width; j++) { \
        val = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; \
        dest[A] = 0xFF; \
        dest[C1] = val; \
        dest[C2] = val; \
        dest[C3] = val; \
        dest += 4; \
      } \
    } \
  } \
}

A32_CHECKER_C (argb, TRUE, 0, 1, 2, 3);
A32_CHECKER_C (bgra, TRUE, 3, 2, 1, 0);
A32_CHECKER_C (ayuv, FALSE, 0, 1, 2, 3);

#define YUV_TO_R(Y,U,V) (CLAMP (1.164 * (Y - 16) + 1.596 * (V - 128), 0, 255))
#define YUV_TO_G(Y,U,V) (CLAMP (1.164 * (Y - 16) - 0.813 * (V - 128) - 0.391 * (U - 128), 0, 255))
#define YUV_TO_B(Y,U,V) (CLAMP (1.164 * (Y - 16) + 2.018 * (U - 128), 0, 255))

169
#define A32_COLOR(name, RGB, A, C1, C2, C3) \
170
static void \
171
fill_color_##name (GstVideoFrame * frame, gint Y, gint U, gint V) \
172 173
{ \
  gint c1, c2, c3; \
174
  guint32 val; \
175 176 177 178 179 180
  gint width, height; \
  guint8 *dest; \
  \
  dest = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
  width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0); \
  height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0); \
181 182 183 184 185 186 187 188 189 190
  \
  if (RGB) { \
    c1 = YUV_TO_R (Y, U, V); \
    c2 = YUV_TO_G (Y, U, V); \
    c3 = YUV_TO_B (Y, U, V); \
  } else { \
    c1 = Y; \
    c2 = U; \
    c3 = V; \
  } \
191
  val = GUINT32_FROM_BE ((0xff << A) | (c1 << C1) | (c2 << C2) | (c3 << C3)); \
192
  \
193
  video_mixer_orc_splat_u32 ((guint32 *) dest, val, height * width); \
194 195
}

196 197 198 199 200
A32_COLOR (argb, TRUE, 24, 16, 8, 0);
A32_COLOR (bgra, TRUE, 0, 8, 16, 24);
A32_COLOR (abgr, TRUE, 24, 0, 8, 16);
A32_COLOR (rgba, TRUE, 0, 24, 16, 8);
A32_COLOR (ayuv, FALSE, 24, 16, 8, 0);
201

202
/* Y444, Y42B, I420, YV12, Y41B */
203
#define PLANAR_YUV_BLEND(format_name,format_enum,x_round,y_round,MEMCPY,BLENDLOOP) \
204
inline static void \
205
_blend_##format_name (const guint8 * src, guint8 * dest, \
206
    gint src_stride, gint dest_stride, gint src_width, gint src_height, \
207
    gdouble src_alpha) \
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
{ \
  gint i; \
  gint b_alpha; \
  \
  /* If it's completely transparent... we just return */ \
  if (G_UNLIKELY (src_alpha == 0.0)) { \
    GST_INFO ("Fast copy (alpha == 0.0)"); \
    return; \
  } \
  \
  /* If it's completely opaque, we do a fast copy */ \
  if (G_UNLIKELY (src_alpha == 1.0)) { \
    GST_INFO ("Fast copy (alpha == 1.0)"); \
    for (i = 0; i < src_height; i++) { \
      MEMCPY (dest, src, src_width); \
      src += src_stride; \
      dest += dest_stride; \
    } \
    return; \
  } \
  \
  b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \
  \
231
  BLENDLOOP(dest, dest_stride, src, src_stride, b_alpha, src_width, src_height); \
232 233 234
} \
\
static void \
235
blend_##format_name (GstVideoFrame * srcframe, gint xpos, gint ypos, \
Wim Taymans's avatar
Wim Taymans committed
236
    gdouble src_alpha, GstVideoFrame * destframe) \
237 238 239
{ \
  const guint8 *b_src; \
  guint8 *b_dest; \
Wim Taymans's avatar
Wim Taymans committed
240 241
  gint b_src_width; \
  gint b_src_height; \
242 243
  gint xoffset = 0; \
  gint yoffset = 0; \
244
  gint src_comp_rowstride, dest_comp_rowstride; \
245 246
  gint src_comp_height; \
  gint src_comp_width; \
247 248
  gint comp_ypos, comp_xpos; \
  gint comp_yoffset, comp_xoffset; \
249 250
  gint dest_width, dest_height; \
  const GstVideoFormatInfo *info; \
Wim Taymans's avatar
Wim Taymans committed
251 252 253 254
  gint src_width, src_height; \
  \
  src_width = GST_VIDEO_FRAME_WIDTH (srcframe); \
  src_height = GST_VIDEO_FRAME_HEIGHT (srcframe); \
255 256 257
  \
  info = srcframe->info.finfo; \
  dest_width = GST_VIDEO_FRAME_WIDTH (destframe); \
258
  dest_height = GST_VIDEO_FRAME_HEIGHT (destframe); \
259
  \
260 261
  xpos = x_round (xpos); \
  ypos = y_round (ypos); \
262
  \
Wim Taymans's avatar
Wim Taymans committed
263 264 265
  b_src_width = src_width; \
  b_src_height = src_height; \
  \
266 267 268 269 270 271 272
  /* adjust src pointers for negative sizes */ \
  if (xpos < 0) { \
    xoffset = -xpos; \
    b_src_width -= -xpos; \
    xpos = 0; \
  } \
  if (ypos < 0) { \
273
    yoffset = -ypos; \
274 275 276 277
    b_src_height -= -ypos; \
    ypos = 0; \
  } \
  /* If x or y offset are larger then the source it's outside of the picture */ \
278
  if (xoffset >= src_width || yoffset >= src_height) { \
279 280 281 282
    return; \
  } \
  \
  /* adjust width/height if the src is bigger than dest */ \
283
  if (xpos + b_src_width > dest_width) { \
284 285
    b_src_width = dest_width - xpos; \
  } \
286
  if (ypos + b_src_height > dest_height) { \
287 288
    b_src_height = dest_height - ypos; \
  } \
289
  if (b_src_width <= 0 || b_src_height <= 0) { \
290 291 292 293
    return; \
  } \
  \
  /* First mix Y, then U, then V */ \
294 295 296 297 298 299 300 301 302 303
  b_src = GST_VIDEO_FRAME_COMP_DATA (srcframe, 0); \
  b_dest = GST_VIDEO_FRAME_COMP_DATA (destframe, 0); \
  src_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \
  dest_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \
  src_comp_width = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info, 0, b_src_width); \
  src_comp_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info, 0, b_src_height); \
  comp_xpos = (xpos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 0, xpos); \
  comp_ypos = (ypos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 0, ypos); \
  comp_xoffset = (xoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 0, xoffset); \
  comp_yoffset = (yoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 0, yoffset); \
304
  _blend_##format_name (b_src + comp_xoffset + comp_yoffset * src_comp_rowstride, \
305 306 307
      b_dest + comp_xpos + comp_ypos * dest_comp_rowstride, \
      src_comp_rowstride, \
      dest_comp_rowstride, src_comp_width, src_comp_height, \
308
      src_alpha); \
309
  \
310 311 312 313 314 315 316 317 318 319
  b_src = GST_VIDEO_FRAME_COMP_DATA (srcframe, 1); \
  b_dest = GST_VIDEO_FRAME_COMP_DATA (destframe, 1); \
  src_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 1); \
  dest_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 1); \
  src_comp_width = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info, 1, b_src_width); \
  src_comp_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info, 1, b_src_height); \
  comp_xpos = (xpos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 1, xpos); \
  comp_ypos = (ypos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 1, ypos); \
  comp_xoffset = (xoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 1, xoffset); \
  comp_yoffset = (yoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 1, yoffset); \
320
  _blend_##format_name (b_src + comp_xoffset + comp_yoffset * src_comp_rowstride, \
321 322 323
      b_dest + comp_xpos + comp_ypos * dest_comp_rowstride, \
      src_comp_rowstride, \
      dest_comp_rowstride, src_comp_width, src_comp_height, \
324
      src_alpha); \
325
  \
326 327 328 329 330 331 332 333 334 335
  b_src = GST_VIDEO_FRAME_COMP_DATA (srcframe, 2); \
  b_dest = GST_VIDEO_FRAME_COMP_DATA (destframe, 2); \
  src_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 2); \
  dest_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 2); \
  src_comp_width = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info, 2, b_src_width); \
  src_comp_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info, 2, b_src_height); \
  comp_xpos = (xpos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 2, xpos); \
  comp_ypos = (ypos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 2, ypos); \
  comp_xoffset = (xoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 2, xoffset); \
  comp_yoffset = (yoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 2, yoffset); \
336
  _blend_##format_name (b_src + comp_xoffset + comp_yoffset * src_comp_rowstride, \
337 338 339
      b_dest + comp_xpos + comp_ypos * dest_comp_rowstride, \
      src_comp_rowstride, \
      dest_comp_rowstride, src_comp_width, src_comp_height, \
340
      src_alpha); \
341 342
}

343
#define PLANAR_YUV_FILL_CHECKER(format_name, format_enum, MEMSET) \
344
static void \
345
fill_checker_##format_name (GstVideoFrame * frame) \
346 347 348
{ \
  gint i, j; \
  static const int tab[] = { 80, 160, 80, 160 }; \
349 350 351
  guint8 *p; \
  gint comp_width, comp_height; \
  gint rowstride; \
352
  \
353 354 355 356
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 0); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
357 358 359
  \
  for (i = 0; i < comp_height; i++) { \
    for (j = 0; j < comp_width; j++) { \
360 361
      *p++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; \
    } \
362 363 364
    p += rowstride - comp_width; \
  } \
  \
365 366 367 368
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 1); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1); \
369 370 371 372
  \
  for (i = 0; i < comp_height; i++) { \
    MEMSET (p, 0x80, comp_width); \
    p += rowstride; \
373 374
  } \
  \
375 376 377 378
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 2); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 2); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 2); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 2); \
379
  \
380 381 382 383
  for (i = 0; i < comp_height; i++) { \
    MEMSET (p, 0x80, comp_width); \
    p += rowstride; \
  } \
384 385
}

386
#define PLANAR_YUV_FILL_COLOR(format_name,format_enum,MEMSET) \
387
static void \
388
fill_color_##format_name (GstVideoFrame * frame, \
389 390
    gint colY, gint colU, gint colV) \
{ \
391 392 393 394 395
  guint8 *p; \
  gint comp_width, comp_height; \
  gint rowstride; \
  gint i; \
  \
396 397 398 399
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 0); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
400 401 402 403 404 405
  \
  for (i = 0; i < comp_height; i++) { \
    MEMSET (p, colY, comp_width); \
    p += rowstride; \
  } \
  \
406 407 408 409
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 1); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1); \
410
  \
411 412 413 414
  for (i = 0; i < comp_height; i++) { \
    MEMSET (p, colU, comp_width); \
    p += rowstride; \
  } \
415
  \
416 417 418 419
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 2); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 2); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 2); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 2); \
420
  \
421 422 423 424
  for (i = 0; i < comp_height; i++) { \
    MEMSET (p, colV, comp_width); \
    p += rowstride; \
  } \
425 426
}

427 428
#define GST_ROUND_UP_1(x) (x)

429
PLANAR_YUV_BLEND (i420, GST_VIDEO_FORMAT_I420, GST_ROUND_UP_2,
430
    GST_ROUND_UP_2, memcpy, video_mixer_orc_blend_u8);
431 432 433 434
PLANAR_YUV_FILL_CHECKER (i420, GST_VIDEO_FORMAT_I420, memset);
PLANAR_YUV_FILL_COLOR (i420, GST_VIDEO_FORMAT_I420, memset);
PLANAR_YUV_FILL_COLOR (yv12, GST_VIDEO_FORMAT_YV12, memset);
PLANAR_YUV_BLEND (y444, GST_VIDEO_FORMAT_Y444, GST_ROUND_UP_1,
435
    GST_ROUND_UP_1, memcpy, video_mixer_orc_blend_u8);
436 437 438
PLANAR_YUV_FILL_CHECKER (y444, GST_VIDEO_FORMAT_Y444, memset);
PLANAR_YUV_FILL_COLOR (y444, GST_VIDEO_FORMAT_Y444, memset);
PLANAR_YUV_BLEND (y42b, GST_VIDEO_FORMAT_Y42B, GST_ROUND_UP_2,
439
    GST_ROUND_UP_1, memcpy, video_mixer_orc_blend_u8);
440 441 442
PLANAR_YUV_FILL_CHECKER (y42b, GST_VIDEO_FORMAT_Y42B, memset);
PLANAR_YUV_FILL_COLOR (y42b, GST_VIDEO_FORMAT_Y42B, memset);
PLANAR_YUV_BLEND (y41b, GST_VIDEO_FORMAT_Y41B, GST_ROUND_UP_4,
443
    GST_ROUND_UP_1, memcpy, video_mixer_orc_blend_u8);
444 445
PLANAR_YUV_FILL_CHECKER (y41b, GST_VIDEO_FORMAT_Y41B, memset);
PLANAR_YUV_FILL_COLOR (y41b, GST_VIDEO_FORMAT_Y41B, memset);
446

447
/* NV12, NV21 */
448
#define NV_YUV_BLEND(format_name,MEMCPY,BLENDLOOP) \
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
inline static void \
_blend_##format_name (const guint8 * src, guint8 * dest, \
    gint src_stride, gint dest_stride, gint src_width, gint src_height, \
    gdouble src_alpha) \
{ \
  gint i; \
  gint b_alpha; \
  \
  /* If it's completely transparent... we just return */ \
  if (G_UNLIKELY (src_alpha == 0.0)) { \
    GST_INFO ("Fast copy (alpha == 0.0)"); \
    return; \
  } \
  \
  /* If it's completely opaque, we do a fast copy */ \
  if (G_UNLIKELY (src_alpha == 1.0)) { \
    GST_INFO ("Fast copy (alpha == 1.0)"); \
    for (i = 0; i < src_height; i++) { \
      MEMCPY (dest, src, src_width); \
      src += src_stride; \
      dest += dest_stride; \
    } \
    return; \
  } \
  \
  b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \
  \
  BLENDLOOP(dest, dest_stride, src, src_stride, b_alpha, src_width, src_height); \
} \
\
static void \
blend_##format_name (GstVideoFrame * srcframe, gint xpos, gint ypos, \
    gdouble src_alpha, GstVideoFrame * destframe)                    \
{ \
  const guint8 *b_src; \
  guint8 *b_dest; \
  gint b_src_width; \
  gint b_src_height; \
  gint xoffset = 0; \
  gint yoffset = 0; \
  gint src_comp_rowstride, dest_comp_rowstride; \
  gint src_comp_height; \
  gint src_comp_width; \
  gint comp_ypos, comp_xpos; \
  gint comp_yoffset, comp_xoffset; \
  gint dest_width, dest_height; \
  const GstVideoFormatInfo *info; \
  gint src_width, src_height; \
  \
  src_width = GST_VIDEO_FRAME_WIDTH (srcframe); \
  src_height = GST_VIDEO_FRAME_HEIGHT (srcframe); \
  \
  info = srcframe->info.finfo; \
  dest_width = GST_VIDEO_FRAME_WIDTH (destframe); \
503
  dest_height = GST_VIDEO_FRAME_HEIGHT (destframe); \
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
  \
  xpos = GST_ROUND_UP_2 (xpos); \
  ypos = GST_ROUND_UP_2 (ypos); \
  \
  b_src_width = src_width; \
  b_src_height = src_height; \
  \
  /* adjust src pointers for negative sizes */ \
  if (xpos < 0) { \
    xoffset = -xpos; \
    b_src_width -= -xpos; \
    xpos = 0; \
  } \
  if (ypos < 0) { \
    yoffset += -ypos; \
    b_src_height -= -ypos; \
    ypos = 0; \
  } \
  /* If x or y offset are larger then the source it's outside of the picture */ \
523
  if (xoffset > src_width || yoffset > src_height) { \
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
    return; \
  } \
  \
  /* adjust width/height if the src is bigger than dest */ \
  if (xpos + src_width > dest_width) { \
    b_src_width = dest_width - xpos; \
  } \
  if (ypos + src_height > dest_height) { \
    b_src_height = dest_height - ypos; \
  } \
  if (b_src_width < 0 || b_src_height < 0) { \
    return; \
  } \
  \
  /* First mix Y, then UV */ \
  b_src = GST_VIDEO_FRAME_COMP_DATA (srcframe, 0); \
  b_dest = GST_VIDEO_FRAME_COMP_DATA (destframe, 0); \
  src_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \
  dest_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \
  src_comp_width = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info, 0, b_src_width); \
  src_comp_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info, 0, b_src_height); \
  comp_xpos = (xpos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 0, xpos); \
  comp_ypos = (ypos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 0, ypos); \
  comp_xoffset = (xoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 0, xoffset); \
  comp_yoffset = (yoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 0, yoffset); \
  _blend_##format_name (b_src + comp_xoffset + comp_yoffset * src_comp_rowstride, \
      b_dest + comp_xpos + comp_ypos * dest_comp_rowstride, \
      src_comp_rowstride, \
      dest_comp_rowstride, src_comp_width, src_comp_height, \
      src_alpha); \
  \
555 556
  b_src = GST_VIDEO_FRAME_PLANE_DATA (srcframe, 1); \
  b_dest = GST_VIDEO_FRAME_PLANE_DATA (destframe, 1); \
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
  src_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 1); \
  dest_comp_rowstride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 1); \
  src_comp_width = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info, 1, b_src_width); \
  src_comp_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info, 1, b_src_height); \
  comp_xpos = (xpos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 1, xpos); \
  comp_ypos = (ypos == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 1, ypos); \
  comp_xoffset = (xoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (info, 1, xoffset); \
  comp_yoffset = (yoffset == 0) ? 0 : GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (info, 1, yoffset); \
  _blend_##format_name (b_src + comp_xoffset * 2 + comp_yoffset * src_comp_rowstride, \
      b_dest + comp_xpos * 2 + comp_ypos * dest_comp_rowstride, \
      src_comp_rowstride, \
      dest_comp_rowstride, 2 * src_comp_width, src_comp_height, \
      src_alpha); \
}

572
#define NV_YUV_FILL_CHECKER(format_name, MEMSET)        \
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
static void \
fill_checker_##format_name (GstVideoFrame * frame) \
{ \
  gint i, j; \
  static const int tab[] = { 80, 160, 80, 160 }; \
  guint8 *p; \
  gint comp_width, comp_height; \
  gint rowstride; \
  \
  p = GST_VIDEO_FRAME_COMP_DATA (frame, 0); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
  \
  for (i = 0; i < comp_height; i++) { \
    for (j = 0; j < comp_width; j++) { \
      *p++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; \
    } \
    p += rowstride - comp_width; \
  } \
  \
594
  p = GST_VIDEO_FRAME_PLANE_DATA (frame, 1); \
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 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1); \
  \
  for (i = 0; i < comp_height; i++) { \
    MEMSET (p, 0x80, comp_width * 2); \
    p += rowstride; \
  } \
}

#define NV_YUV_FILL_COLOR(format_name,MEMSET) \
static void \
fill_color_##format_name (GstVideoFrame * frame, \
    gint colY, gint colU, gint colV) \
{ \
  guint8 *y, *u, *v; \
  gint comp_width, comp_height; \
  gint rowstride; \
  gint i, j; \
  \
  y = GST_VIDEO_FRAME_COMP_DATA (frame, 0); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 0); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 0); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
  \
  for (i = 0; i < comp_height; i++) { \
    MEMSET (y, colY, comp_width); \
    y += rowstride; \
  } \
  \
  u = GST_VIDEO_FRAME_COMP_DATA (frame, 1); \
  v = GST_VIDEO_FRAME_COMP_DATA (frame, 2); \
  comp_width = GST_VIDEO_FRAME_COMP_WIDTH (frame, 1); \
  comp_height = GST_VIDEO_FRAME_COMP_HEIGHT (frame, 1); \
  rowstride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1); \
  \
  for (i = 0; i < comp_height; i++) { \
    for (j = 0; j < comp_width; j++) { \
      u[j*2] = colU; \
      v[j*2] = colV; \
    } \
    u += rowstride; \
    v += rowstride; \
  } \
}

641 642
NV_YUV_BLEND (nv12, memcpy, video_mixer_orc_blend_u8);
NV_YUV_FILL_CHECKER (nv12, memset);
643
NV_YUV_FILL_COLOR (nv12, memset);
644 645
NV_YUV_BLEND (nv21, memcpy, video_mixer_orc_blend_u8);
NV_YUV_FILL_CHECKER (nv21, memset);
646

647 648 649 650
/* RGB, BGR, xRGB, xBGR, RGBx, BGRx */

#define RGB_BLEND(name, bpp, MEMCPY, BLENDLOOP) \
static void \
651
blend_##name (GstVideoFrame * srcframe, gint xpos, gint ypos, \
Wim Taymans's avatar
Wim Taymans committed
652
    gdouble src_alpha, GstVideoFrame * destframe) \
653 654 655 656
{ \
  gint b_alpha; \
  gint i; \
  gint src_stride, dest_stride; \
657 658
  gint dest_width, dest_height; \
  guint8 *dest, *src; \
Wim Taymans's avatar
Wim Taymans committed
659 660 661 662
  gint src_width, src_height; \
  \
  src_width = GST_VIDEO_FRAME_WIDTH (srcframe); \
  src_height = GST_VIDEO_FRAME_HEIGHT (srcframe); \
663 664 665 666 667 668
  \
  src = GST_VIDEO_FRAME_PLANE_DATA (srcframe, 0); \
  dest = GST_VIDEO_FRAME_PLANE_DATA (destframe, 0); \
  \
  dest_width = GST_VIDEO_FRAME_WIDTH (destframe); \
  dest_height = GST_VIDEO_FRAME_HEIGHT (destframe); \
669
  \
670 671
  src_stride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \
  dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
  \
  b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \
  \
  /* adjust src pointers for negative sizes */ \
  if (xpos < 0) { \
    src += -xpos * bpp; \
    src_width -= -xpos; \
    xpos = 0; \
  } \
  if (ypos < 0) { \
    src += -ypos * src_stride; \
    src_height -= -ypos; \
    ypos = 0; \
  } \
  /* adjust width/height if the src is bigger than dest */ \
  if (xpos + src_width > dest_width) { \
    src_width = dest_width - xpos; \
  } \
  if (ypos + src_height > dest_height) { \
    src_height = dest_height - ypos; \
  } \
  \
  dest = dest + bpp * xpos + (ypos * dest_stride); \
  /* If it's completely transparent... we just return */ \
  if (G_UNLIKELY (src_alpha == 0.0)) { \
    GST_INFO ("Fast copy (alpha == 0.0)"); \
    return; \
  } \
  \
  /* If it's completely opaque, we do a fast copy */ \
  if (G_UNLIKELY (src_alpha == 1.0)) { \
    GST_INFO ("Fast copy (alpha == 1.0)"); \
    for (i = 0; i < src_height; i++) { \
      MEMCPY (dest, src, bpp * src_width); \
      src += src_stride; \
      dest += dest_stride; \
    } \
    return; \
  } \
  \
712
  BLENDLOOP(dest, dest_stride, src, src_stride, b_alpha, src_width * bpp, src_height); \
713 714 715 716
}

#define RGB_FILL_CHECKER_C(name, bpp, r, g, b) \
static void \
717
fill_checker_##name##_c (GstVideoFrame * frame) \
718 719 720
{ \
  gint i, j; \
  static const int tab[] = { 80, 160, 80, 160 }; \
721 722 723 724 725 726 727 728
  gint stride, dest_add, width, height; \
  guint8 *dest; \
  \
  width = GST_VIDEO_FRAME_WIDTH (frame); \
  height = GST_VIDEO_FRAME_HEIGHT (frame); \
  dest = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
  stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
  dest_add = stride - width * bpp; \
729 730 731 732 733 734 735 736 737 738 739 740 741 742
  \
  for (i = 0; i < height; i++) { \
    for (j = 0; j < width; j++) { \
      dest[r] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)];       /* red */ \
      dest[g] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)];       /* green */ \
      dest[b] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)];       /* blue */ \
      dest += bpp; \
    } \
    dest += dest_add; \
  } \
}

#define RGB_FILL_COLOR(name, bpp, MEMSET_RGB) \
static void \
743
fill_color_##name (GstVideoFrame * frame, \
744 745 746 747
    gint colY, gint colU, gint colV) \
{ \
  gint red, green, blue; \
  gint i; \
748 749 750 751 752 753 754 755
  gint dest_stride; \
  gint width, height; \
  guint8 *dest; \
  \
  width = GST_VIDEO_FRAME_WIDTH (frame); \
  height = GST_VIDEO_FRAME_HEIGHT (frame); \
  dest = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
  dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
756
  \
757 758 759
  red = YUV_TO_R (colY, colU, colV); \
  green = YUV_TO_G (colY, colU, colV); \
  blue = YUV_TO_B (colY, colU, colV); \
760 761 762 763 764 765 766
  \
  for (i = 0; i < height; i++) { \
    MEMSET_RGB (dest, red, green, blue, width); \
    dest += dest_stride; \
  } \
}

767
#define MEMSET_RGB_C(name, r, g, b) \
768 769 770 771 772 773 774 775
static inline void \
_memset_##name##_c (guint8* dest, gint red, gint green, gint blue, gint width) { \
  gint j; \
  \
  for (j = 0; j < width; j++) { \
    dest[r] = red; \
    dest[g] = green; \
    dest[b] = blue; \
776
    dest += 3; \
777 778 779
  } \
}

780 781 782 783 784 785
#define MEMSET_XRGB(name, r, g, b) \
static inline void \
_memset_##name (guint8* dest, gint red, gint green, gint blue, gint width) { \
  guint32 val; \
  \
  val = GUINT32_FROM_BE ((red << r) | (green << g) | (blue << b)); \
786
  video_mixer_orc_splat_u32 ((guint32 *) dest, val, width); \
787 788
}

789
#define _orc_memcpy_u32(dest,src,len) video_mixer_orc_memcpy_u32((guint32 *) dest, (const guint32 *) src, len/4)
790

791
RGB_BLEND (rgb, 3, memcpy, video_mixer_orc_blend_u8);
792
RGB_FILL_CHECKER_C (rgb, 3, 0, 1, 2);
793
MEMSET_RGB_C (rgb, 0, 1, 2);
794 795
RGB_FILL_COLOR (rgb_c, 3, _memset_rgb_c);

796
MEMSET_RGB_C (bgr, 2, 1, 0);
797 798
RGB_FILL_COLOR (bgr_c, 3, _memset_bgr_c);

799
RGB_BLEND (xrgb, 4, _orc_memcpy_u32, video_mixer_orc_blend_u8);
800
RGB_FILL_CHECKER_C (xrgb, 4, 1, 2, 3);
801 802
MEMSET_XRGB (xrgb, 24, 16, 0);
RGB_FILL_COLOR (xrgb, 4, _memset_xrgb);
803

804 805
MEMSET_XRGB (xbgr, 0, 16, 24);
RGB_FILL_COLOR (xbgr, 4, _memset_xbgr);
806

807 808
MEMSET_XRGB (rgbx, 24, 16, 8);
RGB_FILL_COLOR (rgbx, 4, _memset_rgbx);
809

810 811
MEMSET_XRGB (bgrx, 8, 16, 24);
RGB_FILL_COLOR (bgrx, 4, _memset_bgrx);
812

813 814 815 816
/* YUY2, YVYU, UYVY */

#define PACKED_422_BLEND(name, MEMCPY, BLENDLOOP) \
static void \
817
blend_##name (GstVideoFrame * srcframe, gint xpos, gint ypos, \
Wim Taymans's avatar
Wim Taymans committed
818
    gdouble src_alpha, GstVideoFrame * destframe) \
819 820 821 822
{ \
  gint b_alpha; \
  gint i; \
  gint src_stride, dest_stride; \
823 824
  gint dest_width, dest_height; \
  guint8 *src, *dest; \
Wim Taymans's avatar
Wim Taymans committed
825 826 827 828
  gint src_width, src_height; \
  \
  src_width = GST_VIDEO_FRAME_WIDTH (srcframe); \
  src_height = GST_VIDEO_FRAME_HEIGHT (srcframe); \
829 830 831 832 833 834
  \
  dest_width = GST_VIDEO_FRAME_WIDTH (destframe); \
  dest_height = GST_VIDEO_FRAME_HEIGHT (destframe); \
  \
  src = GST_VIDEO_FRAME_PLANE_DATA (srcframe, 0); \
  dest = GST_VIDEO_FRAME_PLANE_DATA (destframe, 0); \
835
  \
836 837
  src_stride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \
  dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \
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
  \
  b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \
  \
  xpos = GST_ROUND_UP_2 (xpos); \
  \
  /* adjust src pointers for negative sizes */ \
  if (xpos < 0) { \
    src += -xpos * 2; \
    src_width -= -xpos; \
    xpos = 0; \
  } \
  if (ypos < 0) { \
    src += -ypos * src_stride; \
    src_height -= -ypos; \
    ypos = 0; \
  } \
  \
  /* adjust width/height if the src is bigger than dest */ \
  if (xpos + src_width > dest_width) { \
    src_width = dest_width - xpos; \
  } \
  if (ypos + src_height > dest_height) { \
    src_height = dest_height - ypos; \
  } \
  \
  dest = dest + 2 * xpos + (ypos * dest_stride); \
  /* If it's completely transparent... we just return */ \
  if (G_UNLIKELY (src_alpha == 0.0)) { \
    GST_INFO ("Fast copy (alpha == 0.0)"); \
    return; \
  } \
  \
  /* If it's completely opaque, we do a fast copy */ \
  if (G_UNLIKELY (src_alpha == 1.0)) { \
    GST_INFO ("Fast copy (alpha == 1.0)"); \
    for (i = 0; i < src_height; i++) { \
      MEMCPY (dest, src, 2 * src_width); \
      src += src_stride; \
      dest += dest_stride; \
    } \
    return; \
  } \
  \
881
  BLENDLOOP(dest, dest_stride, src, src_stride, b_alpha, 2 * src_width, src_height); \
882 883 884 885
}

#define PACKED_422_FILL_CHECKER_C(name, Y1, U, Y2, V) \
static void \
886
fill_checker_##name##_c (GstVideoFrame * frame) \
887 888 889 890
{ \
  gint i, j; \
  static const int tab[] = { 80, 160, 80, 160 }; \
  gint dest_add; \
891 892
  gint width, height; \
  guint8 *dest; \
893
  \
894
  width = GST_VIDEO_FRAME_WIDTH (frame); \
895
  width = GST_ROUND_UP_2 (width); \
896
  height = GST_VIDEO_FRAME_HEIGHT (frame); \
897
  dest = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
898
  dest_add = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0) - width * 2; \
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
  width /= 2; \
  \
  for (i = 0; i < height; i++) { \
    for (j = 0; j < width; j++) { \
      dest[Y1] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; \
      dest[Y2] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; \
      dest[U] = 128; \
      dest[V] = 128; \
      dest += 4; \
    } \
    dest += dest_add; \
  } \
}

#define PACKED_422_FILL_COLOR(name, Y1, U, Y2, V) \
static void \
915
fill_color_##name (GstVideoFrame * frame, \
916 917
    gint colY, gint colU, gint colV) \
{ \
918 919 920
  gint i; \
  gint dest_stride; \
  guint32 val; \
921 922
  gint width, height; \
  guint8 *dest; \
923
  \
924
  width = GST_VIDEO_FRAME_WIDTH (frame); \
925
  width = GST_ROUND_UP_2 (width); \
926
  height = GST_VIDEO_FRAME_HEIGHT (frame); \
927
  dest = GST_VIDEO_FRAME_PLANE_DATA (frame, 0); \
928
  dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); \
929 930
  width /= 2; \
  \
931 932
  val = GUINT32_FROM_BE ((colY << Y1) | (colY << Y2) | (colU << U) | (colV << V)); \
  \
933
  for (i = 0; i < height; i++) { \
934
    video_mixer_orc_splat_u32 ((guint32 *) dest, val, width); \
935
    dest += dest_stride; \
936 937 938
  } \
}

939
PACKED_422_BLEND (yuy2, memcpy, video_mixer_orc_blend_u8);
940 941
PACKED_422_FILL_CHECKER_C (yuy2, 0, 1, 2, 3);
PACKED_422_FILL_CHECKER_C (uyvy, 1, 0, 3, 2);
942 943 944
PACKED_422_FILL_COLOR (yuy2, 24, 16, 8, 0);
PACKED_422_FILL_COLOR (yvyu, 24, 0, 8, 16);
PACKED_422_FILL_COLOR (uyvy, 16, 24, 0, 8);
945

946 947 948
/* Init function */
BlendFunction gst_video_mixer_blend_argb;
BlendFunction gst_video_mixer_blend_bgra;
949 950
BlendFunction gst_video_mixer_overlay_argb;
BlendFunction gst_video_mixer_overlay_bgra;
951
/* AYUV/ABGR is equal to ARGB, RGBA is equal to BGRA */
952 953
BlendFunction gst_video_mixer_blend_y444;
BlendFunction gst_video_mixer_blend_y42b;
954
BlendFunction gst_video_mixer_blend_i420;
955
/* I420 is equal to YV12 */
956 957
BlendFunction gst_video_mixer_blend_nv12;
BlendFunction gst_video_mixer_blend_nv21;
958
BlendFunction gst_video_mixer_blend_y41b;
959 960 961 962
BlendFunction gst_video_mixer_blend_rgb;
/* BGR is equal to RGB */
BlendFunction gst_video_mixer_blend_rgbx;
/* BGRx, xRGB, xBGR are equal to RGBx */
963 964
BlendFunction gst_video_mixer_blend_yuy2;
/* YVYU and UYVY are equal to YUY2 */
965 966 967

FillCheckerFunction gst_video_mixer_fill_checker_argb;
FillCheckerFunction gst_video_mixer_fill_checker_bgra;
968
/* ABGR is equal to ARGB, RGBA is equal to BGRA */
969
FillCheckerFunction gst_video_mixer_fill_checker_ayuv;
970 971
FillCheckerFunction gst_video_mixer_fill_checker_y444;
FillCheckerFunction gst_video_mixer_fill_checker_y42b;
972
FillCheckerFunction gst_video_mixer_fill_checker_i420;
973
/* I420 is equal to YV12 */
974 975
FillCheckerFunction gst_video_mixer_fill_checker_nv12;
FillCheckerFunction gst_video_mixer_fill_checker_nv21;
976
FillCheckerFunction gst_video_mixer_fill_checker_y41b;
977 978 979 980
FillCheckerFunction gst_video_mixer_fill_checker_rgb;
/* BGR is equal to RGB */
FillCheckerFunction gst_video_mixer_fill_checker_xrgb;
/* BGRx, xRGB, xBGR are equal to RGBx */
981 982 983
FillCheckerFunction gst_video_mixer_fill_checker_yuy2;
/* YVYU is equal to YUY2 */
FillCheckerFunction gst_video_mixer_fill_checker_uyvy;
984 985 986

FillColorFunction gst_video_mixer_fill_color_argb;
FillColorFunction gst_video_mixer_fill_color_bgra;
987 988
FillColorFunction gst_video_mixer_fill_color_abgr;
FillColorFunction gst_video_mixer_fill_color_rgba;
989
FillColorFunction gst_video_mixer_fill_color_ayuv;
990 991
FillColorFunction gst_video_mixer_fill_color_y444;
FillColorFunction gst_video_mixer_fill_color_y42b;
992
FillColorFunction gst_video_mixer_fill_color_i420;
993
FillColorFunction gst_video_mixer_fill_color_yv12;
994 995
FillColorFunction gst_video_mixer_fill_color_nv12;
/* NV21 is equal to NV12 */
996
FillColorFunction gst_video_mixer_fill_color_y41b;
997 998 999 1000 1001 1002
FillColorFunction gst_video_mixer_fill_color_rgb;
FillColorFunction gst_video_mixer_fill_color_bgr;
FillColorFunction gst_video_mixer_fill_color_xrgb;
FillColorFunction gst_video_mixer_fill_color_xbgr;
FillColorFunction gst_video_mixer_fill_color_rgbx;
FillColorFunction gst_video_mixer_fill_color_bgrx;
1003 1004 1005
FillColorFunction gst_video_mixer_fill_color_yuy2;
FillColorFunction gst_video_mixer_fill_color_yvyu;
FillColorFunction gst_video_mixer_fill_color_uyvy;
1006 1007 1008 1009

void
gst_video_mixer_init_blend (void)
{
1010 1011 1012
  GST_DEBUG_CATEGORY_INIT (gst_videomixer_blend_debug, "videomixer_blend", 0,
      "video mixer blending functions");

1013 1014
  gst_video_mixer_blend_argb = blend_argb;
  gst_video_mixer_blend_bgra = blend_bgra;
1015 1016
  gst_video_mixer_overlay_argb = overlay_argb;
  gst_video_mixer_overlay_bgra = overlay_bgra;
1017
  gst_video_mixer_blend_i420 = blend_i420;
1018 1019
  gst_video_mixer_blend_nv12 = blend_nv12;
  gst_video_mixer_blend_nv21 = blend_nv21;
1020 1021 1022 1023 1024 1025
  gst_video_mixer_blend_y444 = blend_y444;
  gst_video_mixer_blend_y42b = blend_y42b;
  gst_video_mixer_blend_y41b = blend_y41b;
  gst_video_mixer_blend_rgb = blend_rgb;
  gst_video_mixer_blend_xrgb = blend_xrgb;
  gst_video_mixer_blend_yuy2 = blend_yuy2;
1026 1027 1028 1029

  gst_video_mixer_fill_checker_argb = fill_checker_argb_c;
  gst_video_mixer_fill_checker_bgra = fill_checker_bgra_c;
  gst_video_mixer_fill_checker_ayuv = fill_checker_ayuv_c;
1030
  gst_video_mixer_fill_checker_i420 = fill_checker_i420;
1031 1032
  gst_video_mixer_fill_checker_nv12 = fill_checker_nv12;
  gst_video_mixer_fill_checker_nv21 = fill_checker_nv21;
1033 1034 1035
  gst_video_mixer_fill_checker_y444 = fill_checker_y444;
  gst_video_mixer_fill_checker_y42b = fill_checker_y42b;
  gst_video_mixer_fill_checker_y41b = fill_checker_y41b;
1036 1037
  gst_video_mixer_fill_checker_rgb = fill_checker_rgb_c;
  gst_video_mixer_fill_checker_xrgb = fill_checker_xrgb_c;
1038 1039
  gst_video_mixer_fill_checker_yuy2 = fill_checker_yuy2_c;
  gst_video_mixer_fill_checker_uyvy = fill_checker_uyvy_c;
1040

1041 1042 1043 1044 1045 1046 1047
  gst_video_mixer_fill_color_argb = fill_color_argb;
  gst_video_mixer_fill_color_bgra = fill_color_bgra;
  gst_video_mixer_fill_color_abgr = fill_color_abgr;
  gst_video_mixer_fill_color_rgba = fill_color_rgba;
  gst_video_mixer_fill_color_ayuv = fill_color_ayuv;
  gst_video_mixer_fill_color_i420 = fill_color_i420;
  gst_video_mixer_fill_color_yv12 = fill_color_yv12;
1048
  gst_video_mixer_fill_color_nv12 = fill_color_nv12;
1049 1050 1051
  gst_video_mixer_fill_color_y444 = fill_color_y444;
  gst_video_mixer_fill_color_y42b = fill_color_y42b;
  gst_video_mixer_fill_color_y41b = fill_color_y41b;
1052 1053
  gst_video_mixer_fill_color_rgb = fill_color_rgb_c;
  gst_video_mixer_fill_color_bgr = fill_color_bgr_c;
1054 1055 1056 1057 1058 1059 1060
  gst_video_mixer_fill_color_xrgb = fill_color_xrgb;
  gst_video_mixer_fill_color_xbgr = fill_color_xbgr;
  gst_video_mixer_fill_color_rgbx = fill_color_rgbx;
  gst_video_mixer_fill_color_bgrx = fill_color_bgrx;
  gst_video_mixer_fill_color_yuy2 = fill_color_yuy2;
  gst_video_mixer_fill_color_yvyu = fill_color_yvyu;
  gst_video_mixer_fill_color_uyvy = fill_color_uyvy;
1061
}