summaryrefslogtreecommitdiff
path: root/gst/videomixer
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu.duponchelle@epitech.eu>2013-07-25 13:49:57 +0200
committerSebastian Dröge <slomo@circular-chaos.org>2013-09-10 10:36:30 +0200
commit8db36485443c767c93c3aebe379a66efa0fd301b (patch)
tree264644e6a4e93fc652ab12be7ffc6b36a5acedc3 /gst/videomixer
parent374a97a3e9a93869108748e88a6b9f8dfd706c2b (diff)
videomixer: Bundle private copies of videoconvert code
Ideally, this would be part of libgstvideo. Prefixes videoconvert symbols with videomixer_. https://bugzilla.gnome.org/show_bug.cgi?id=704950
Diffstat (limited to 'gst/videomixer')
-rw-r--r--gst/videomixer/Makefile.am9
-rw-r--r--gst/videomixer/blend.c2
-rw-r--r--gst/videomixer/blendorc.orc220
-rw-r--r--gst/videomixer/gstcms.c573
-rw-r--r--gst/videomixer/gstcms.h71
-rw-r--r--gst/videomixer/videoconvert.c1420
-rw-r--r--gst/videomixer/videoconvert.h80
-rw-r--r--gst/videomixer/videomixer2.c1
-rw-r--r--gst/videomixer/videomixerorc.orc1516
9 files changed, 3669 insertions, 223 deletions
diff --git a/gst/videomixer/Makefile.am b/gst/videomixer/Makefile.am
index 767337e56..00d546409 100644
--- a/gst/videomixer/Makefile.am
+++ b/gst/videomixer/Makefile.am
@@ -1,10 +1,13 @@
plugin_LTLIBRARIES = libgstvideomixer.la
-ORC_SOURCE=blendorc
+ORC_SOURCE=videomixerorc
+
include $(top_srcdir)/common/orc.mak
libgstvideomixer_la_SOURCES = \
blend.c \
+ videoconvert.c \
+ gstcms.c \
videomixer2.c
nodist_libgstvideomixer_la_SOURCES = $(ORC_NODIST_SOURCES)
@@ -20,7 +23,9 @@ libgstvideomixer_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS = \
blend.h \
videomixer2.h \
- videomixer2pad.h
+ videomixer2pad.h \
+ videoconvert.h \
+ gstcms.h
Android.mk: Makefile.am $(BUILT_SOURCES)
androgenizer \
diff --git a/gst/videomixer/blend.c b/gst/videomixer/blend.c
index aa5aa516c..894ea2101 100644
--- a/gst/videomixer/blend.c
+++ b/gst/videomixer/blend.c
@@ -27,7 +27,7 @@
#endif
#include "blend.h"
-#include "blendorc.h"
+#include "videomixerorc.h"
#include <string.h>
diff --git a/gst/videomixer/blendorc.orc b/gst/videomixer/blendorc.orc
deleted file mode 100644
index cbc1a4685..000000000
--- a/gst/videomixer/blendorc.orc
+++ /dev/null
@@ -1,220 +0,0 @@
-.function video_mixer_orc_splat_u32
-.dest 4 d1 guint32
-.param 4 p1 guint32
-
-copyl d1, p1
-
-.function video_mixer_orc_memcpy_u32
-.dest 4 d1 guint32
-.source 4 s1 guint32
-
-copyl d1, s1
-
-.function video_mixer_orc_blend_u8
-.flags 2d
-.dest 1 d1 guint8
-.source 1 s1 guint8
-.param 2 p1
-.temp 2 t1
-.temp 2 t2
-.const 1 c1 8
-
-convubw t1, d1
-convubw t2, s1
-subw t2, t2, t1
-mullw t2, t2, p1
-shlw t1, t1, c1
-addw t2, t1, t2
-shruw t2, t2, c1
-convsuswb d1, t2
-
-
-.function video_mixer_orc_blend_argb
-.flags 2d
-.dest 4 d guint8
-.source 4 s guint8
-.param 2 alpha
-.temp 4 t
-.temp 2 tw
-.temp 1 tb
-.temp 4 a
-.temp 8 d_wide
-.temp 8 s_wide
-.temp 8 a_wide
-.const 4 a_alpha 0x000000ff
-
-loadl t, s
-convlw tw, t
-convwb tb, tw
-splatbl a, tb
-x4 convubw a_wide, a
-x4 mullw a_wide, a_wide, alpha
-x4 shruw a_wide, a_wide, 8
-x4 convubw s_wide, t
-loadl t, d
-x4 convubw d_wide, t
-x4 subw s_wide, s_wide, d_wide
-x4 mullw s_wide, s_wide, a_wide
-x4 div255w s_wide, s_wide
-x4 addw d_wide, d_wide, s_wide
-x4 convwb t, d_wide
-orl t, t, a_alpha
-storel d, t
-
-.function video_mixer_orc_blend_bgra
-.flags 2d
-.dest 4 d guint8
-.source 4 s guint8
-.param 2 alpha
-.temp 4 t
-.temp 4 t2
-.temp 2 tw
-.temp 1 tb
-.temp 4 a
-.temp 8 d_wide
-.temp 8 s_wide
-.temp 8 a_wide
-.const 4 a_alpha 0xff000000
-
-loadl t, s
-shrul t2, t, 24
-convlw tw, t2
-convwb tb, tw
-splatbl a, tb
-x4 convubw a_wide, a
-x4 mullw a_wide, a_wide, alpha
-x4 shruw a_wide, a_wide, 8
-x4 convubw s_wide, t
-loadl t, d
-x4 convubw d_wide, t
-x4 subw s_wide, s_wide, d_wide
-x4 mullw s_wide, s_wide, a_wide
-x4 div255w s_wide, s_wide
-x4 addw d_wide, d_wide, s_wide
-x4 convwb t, d_wide
-orl t, t, a_alpha
-storel d, t
-
-
-.function video_mixer_orc_overlay_argb
-.flags 2d
-.dest 4 d guint8
-.source 4 s guint8
-.param 2 alpha
-.temp 4 t
-.temp 2 tw
-.temp 1 tb
-.temp 8 alpha_s
-.temp 8 alpha_s_inv
-.temp 8 alpha_d
-.temp 4 a
-.temp 8 d_wide
-.temp 8 s_wide
-.const 4 xfs 0xffffffff
-.const 4 a_alpha 0x000000ff
-.const 4 a_alpha_inv 0xffffff00
-
-# calc source alpha as alpha_s = alpha_s * alpha / 256
-loadl t, s
-convlw tw, t
-convwb tb, tw
-splatbl a, tb
-x4 convubw alpha_s, a
-x4 mullw alpha_s, alpha_s, alpha
-x4 shruw alpha_s, alpha_s, 8
-x4 convubw s_wide, t
-x4 mullw s_wide, s_wide, alpha_s
-
-# calc destination alpha as alpha_d = (255-alpha_s) * alpha_d / 255
-loadpl a, xfs
-x4 convubw alpha_s_inv, a
-x4 subw alpha_s_inv, alpha_s_inv, alpha_s
-loadl t, d
-convlw tw, t
-convwb tb, tw
-splatbl a, tb
-x4 convubw alpha_d, a
-x4 mullw alpha_d, alpha_d, alpha_s_inv
-x4 div255w alpha_d, alpha_d
-x4 convubw d_wide, t
-x4 mullw d_wide, d_wide, alpha_d
-
-# calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_d*(255-alpha_s)/255
-x4 addw d_wide, d_wide, s_wide
-
-# calc the final destination alpha_d = alpha_s + alpha_d * (255-alpha_s)/255
-x4 addw alpha_d, alpha_d, alpha_s
-
-# now normalize the pix_d by the final alpha to make it associative
-x4 divluw, d_wide, d_wide, alpha_d
-
-# pack the new alpha into the correct spot
-x4 convwb t, d_wide
-andl t, t, a_alpha_inv
-x4 convwb a, alpha_d
-andl a, a, a_alpha
-orl t, t, a
-storel d, t
-
-.function video_mixer_orc_overlay_bgra
-.flags 2d
-.dest 4 d guint8
-.source 4 s guint8
-.param 2 alpha
-.temp 4 t
-.temp 4 t2
-.temp 2 tw
-.temp 1 tb
-.temp 8 alpha_s
-.temp 8 alpha_s_inv
-.temp 8 alpha_d
-.temp 4 a
-.temp 8 d_wide
-.temp 8 s_wide
-.const 4 xfs 0xffffffff
-.const 4 a_alpha 0xff000000
-.const 4 a_alpha_inv 0x00ffffff
-
-# calc source alpha as alpha_s = alpha_s * alpha / 256
-loadl t, s
-shrul t2, t, 24
-convlw tw, t2
-convwb tb, tw
-splatbl a, tb
-x4 convubw alpha_s, a
-x4 mullw alpha_s, alpha_s, alpha
-x4 shruw alpha_s, alpha_s, 8
-x4 convubw s_wide, t
-x4 mullw s_wide, s_wide, alpha_s
-
-# calc destination alpha as alpha_d = (255-alpha_s) * alpha_d / 255
-loadpl a, xfs
-x4 convubw alpha_s_inv, a
-x4 subw alpha_s_inv, alpha_s_inv, alpha_s
-loadl t, d
-shrul t2, t, 24
-convlw tw, t2
-convwb tb, tw
-splatbl a, tb
-x4 convubw alpha_d, a
-x4 mullw alpha_d, alpha_d, alpha_s_inv
-x4 div255w alpha_d, alpha_d
-x4 convubw d_wide, t
-x4 mullw d_wide, d_wide, alpha_d
-
-# calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_d*(255-alpha_s)/255
-x4 addw d_wide, d_wide, s_wide
-
-# calc the final destination alpha_d = alpha_s + alpha_d * (255-alpha_s)/255
-x4 addw alpha_d, alpha_d, alpha_s
-
-# now normalize the pix_d by the final alpha to make it associative
-x4 divluw, d_wide, d_wide, alpha_d
-
-# pack the new alpha into the correct spot
-x4 convwb t, d_wide
-andl t, t, a_alpha_inv
-x4 convwb a, alpha_d
-andl a, a, a_alpha
-orl t, t, a
-storel d, t
diff --git a/gst/videomixer/gstcms.c b/gst/videomixer/gstcms.c
new file mode 100644
index 000000000..96a9f70b0
--- /dev/null
+++ b/gst/videomixer/gstcms.c
@@ -0,0 +1,573 @@
+/* GStreamer
+ * Copyright (C) 2008 David Schleef <ds@entropywave.com>
+ *
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/math-compat.h>
+#include "gstcms.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+
+/* our simple CMS */
+
+void
+color_xyY_to_XYZ (Color * c)
+{
+ if (c->v[1] == 0) {
+ c->v[0] = 0;
+ c->v[1] = 0;
+ c->v[2] = 0;
+ } else {
+ double X, Y, Z;
+ X = c->v[0] * c->v[2] / c->v[1];
+ Y = c->v[2];
+ Z = (1.0 - c->v[0] - c->v[1]) * c->v[2] / c->v[1];
+ c->v[0] = X;
+ c->v[1] = Y;
+ c->v[2] = Z;
+ }
+}
+
+void
+color_XYZ_to_xyY (Color * c)
+{
+ double d;
+ d = c->v[0] + c->v[1] + c->v[2];
+ if (d == 0) {
+ c->v[0] = 0.3128;
+ c->v[1] = 0.3290;
+ c->v[2] = 0;
+ } else {
+ double x, y, Y;
+ x = c->v[0] / d;
+ y = c->v[1] / d;
+ Y = c->v[1];
+ c->v[0] = x;
+ c->v[1] = y;
+ c->v[2] = Y;
+ }
+}
+
+void
+color_set (Color * c, double x, double y, double z)
+{
+ c->v[0] = x;
+ c->v[1] = y;
+ c->v[2] = z;
+}
+
+void
+color_matrix_set_identity (ColorMatrix * m)
+{
+ int i, j;
+
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ m->m[i][j] = (i == j);
+ }
+ }
+}
+
+/* Prettyprint a 4x4 matrix @m@ */
+void
+color_matrix_dump (ColorMatrix * m)
+{
+ int i, j;
+
+ printf ("[\n");
+ for (i = 0; i < 4; i++) {
+ printf (" ");
+ for (j = 0; j < 4; j++) {
+ printf (" %8.5g", m->m[i][j]);
+ }
+ printf ("\n");
+ }
+ printf ("]\n");
+}
+
+/* Perform 4x4 matrix multiplication:
+ * - @dst@ = @a@ * @b@
+ * - @dst@ may be a pointer to @a@ andor @b@
+ */
+void
+color_matrix_multiply (ColorMatrix * dst, ColorMatrix * a, ColorMatrix * b)
+{
+ ColorMatrix tmp;
+ int i, j, k;
+
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ double x = 0;
+ for (k = 0; k < 4; k++) {
+ x += a->m[i][k] * b->m[k][j];
+ }
+ tmp.m[i][j] = x;
+ }
+ }
+
+ memcpy (dst, &tmp, sizeof (ColorMatrix));
+}
+
+void
+color_matrix_apply (ColorMatrix * m, Color * dest, Color * src)
+{
+ int i;
+ Color tmp;
+
+ for (i = 0; i < 3; i++) {
+ double x = 0;
+ x += m->m[i][0] * src->v[0];
+ x += m->m[i][1] * src->v[1];
+ x += m->m[i][2] * src->v[2];
+ x += m->m[i][3];
+ tmp.v[i] = x;
+ }
+ memcpy (dest, &tmp, sizeof (tmp));
+}
+
+void
+color_matrix_offset_components (ColorMatrix * m, double a1, double a2,
+ double a3)
+{
+ ColorMatrix a;
+
+ color_matrix_set_identity (&a);
+ a.m[0][3] = a1;
+ a.m[1][3] = a2;
+ a.m[2][3] = a3;
+ color_matrix_multiply (m, &a, m);
+}
+
+void
+color_matrix_scale_components (ColorMatrix * m, double a1, double a2, double a3)
+{
+ ColorMatrix a;
+
+ color_matrix_set_identity (&a);
+ a.m[0][0] = a1;
+ a.m[1][1] = a2;
+ a.m[2][2] = a3;
+ color_matrix_multiply (m, &a, m);
+}
+
+void
+color_matrix_YCbCr_to_RGB (ColorMatrix * m, double Kr, double Kb)
+{
+ double Kg = 1.0 - Kr - Kb;
+ ColorMatrix k = {
+ {
+ {1., 0., 2 * (1 - Kr), 0.},
+ {1., -2 * Kb * (1 - Kb) / Kg, -2 * Kr * (1 - Kr) / Kg, 0.},
+ {1., 2 * (1 - Kb), 0., 0.},
+ {0., 0., 0., 1.},
+ }
+ };
+
+ color_matrix_multiply (m, &k, m);
+}
+
+void
+color_matrix_RGB_to_YCbCr (ColorMatrix * m, double Kr, double Kb)
+{
+ double Kg = 1.0 - Kr - Kb;
+ ColorMatrix k;
+ double x;
+
+ k.m[0][0] = Kr;
+ k.m[0][1] = Kg;
+ k.m[0][2] = Kb;
+ k.m[0][3] = 0;
+
+ x = 1 / (2 * (1 - Kb));
+ k.m[1][0] = -x * Kr;
+ k.m[1][1] = -x * Kg;
+ k.m[1][2] = x * (1 - Kb);
+ k.m[1][3] = 0;
+
+ x = 1 / (2 * (1 - Kr));
+ k.m[2][0] = x * (1 - Kr);
+ k.m[2][1] = -x * Kg;
+ k.m[2][2] = -x * Kb;
+ k.m[2][3] = 0;
+
+ k.m[3][0] = 0;
+ k.m[3][1] = 0;
+ k.m[3][2] = 0;
+ k.m[3][3] = 1;
+
+ color_matrix_multiply (m, &k, m);
+}
+
+void
+color_matrix_build_yuv_to_rgb_601 (ColorMatrix * dst)
+{
+ /*
+ * At this point, everything is in YCbCr
+ * All components are in the range [0,255]
+ */
+ color_matrix_set_identity (dst);
+
+ /* offset required to get input video black to (0.,0.,0.) */
+ color_matrix_offset_components (dst, -16, -128, -128);
+
+ /* scale required to get input video black to (0.,0.,0.) */
+ color_matrix_scale_components (dst, (1 / 219.0), (1 / 224.0), (1 / 224.0));
+
+ /* colour matrix, YCbCr -> RGB */
+ /* Requires Y in [0,1.0], Cb&Cr in [-0.5,0.5] */
+ color_matrix_YCbCr_to_RGB (dst, 0.2990, 0.1140); /* SD */
+
+ /*
+ * We are now in RGB space
+ */
+
+#if 0
+ /* scale to output range. */
+ color_matrix_scale_components (dst, 255.0, 255.0, 255.0);
+#endif
+}
+
+void
+color_matrix_build_bt709_to_bt601 (ColorMatrix * dst)
+{
+ color_matrix_set_identity (dst);
+
+ /* offset required to get input video black to (0.,0.,0.) */
+ color_matrix_offset_components (dst, -16, -128, -128);
+
+ /* scale required to get input video black to (0.,0.,0.) */
+ color_matrix_scale_components (dst, (1 / 219.0), (1 / 224.0), (1 / 224.0));
+
+ /* colour matrix, YCbCr -> RGB */
+ /* Requires Y in [0,1.0], Cb&Cr in [-0.5,0.5] */
+ color_matrix_YCbCr_to_RGB (dst, 0.2126, 0.0722); /* HD */
+
+ color_matrix_RGB_to_YCbCr (dst, 0.2990, 0.1140); /* SD */
+
+ color_matrix_scale_components (dst, 219.0, 224.0, 224.0);
+
+ color_matrix_offset_components (dst, 16, 128, 128);
+}
+
+void
+color_matrix_build_rgb_to_yuv_601 (ColorMatrix * dst)
+{
+ color_matrix_set_identity (dst);
+
+ color_matrix_RGB_to_YCbCr (dst, 0.2990, 0.1140); /* SD */
+
+ color_matrix_scale_components (dst, 219.0, 224.0, 224.0);
+
+ color_matrix_offset_components (dst, 16, 128, 128);
+
+ {
+ Color c;
+ int i;
+ for (i = 7; i >= 0; i--) {
+ color_set (&c, (i & 2) ? 0.75 : 0.0, (i & 4) ? 0.75 : 0.0,
+ (i & 1) ? 0.75 : 0.0);
+ color_matrix_apply (dst, &c, &c);
+ g_print (" { %g, %g, %g },\n", rint (c.v[0]), rint (c.v[1]),
+ rint (c.v[2]));
+ }
+ color_set (&c, -0.075, -0.075, -0.075);
+ color_matrix_apply (dst, &c, &c);
+ g_print (" { %g, %g, %g },\n", rint (c.v[0]), rint (c.v[1]),
+ rint (c.v[2]));
+ color_set (&c, 0.075, 0.075, 0.075);
+ color_matrix_apply (dst, &c, &c);
+ g_print (" { %g, %g, %g },\n", rint (c.v[0]), rint (c.v[1]),
+ rint (c.v[2]));
+ }
+}
+
+void
+color_matrix_invert (ColorMatrix * m)
+{
+ ColorMatrix tmp;
+ int i, j;
+ double det;
+
+ color_matrix_set_identity (&tmp);
+ for (j = 0; j < 3; j++) {
+ for (i = 0; i < 3; i++) {
+ tmp.m[j][i] =
+ m->m[(i + 1) % 3][(j + 1) % 3] * m->m[(i + 2) % 3][(j + 2) % 3] -
+ m->m[(i + 1) % 3][(j + 2) % 3] * m->m[(i + 2) % 3][(j + 1) % 3];
+ }
+ }
+ det =
+ tmp.m[0][0] * m->m[0][0] + tmp.m[0][1] * m->m[1][0] +
+ tmp.m[0][2] * m->m[2][0];
+ for (j = 0; j < 3; j++) {
+ for (i = 0; i < 3; i++) {
+ tmp.m[i][j] /= det;
+ }
+ }
+ memcpy (m, &tmp, sizeof (tmp));
+}
+
+void
+color_matrix_copy (ColorMatrix * dest, ColorMatrix * src)
+{
+ memcpy (dest, src, sizeof (ColorMatrix));
+}
+
+void
+color_matrix_transpose (ColorMatrix * m)
+{
+ int i, j;
+ ColorMatrix tmp;
+
+ color_matrix_set_identity (&tmp);
+ for (i = 0; i < 3; i++) {
+ for (j = 0; j < 3; j++) {
+ tmp.m[i][j] = m->m[j][i];
+ }
+ }
+ memcpy (m, &tmp, sizeof (ColorMatrix));
+}
+
+void
+color_matrix_build_XYZ (ColorMatrix * dst,
+ double rx, double ry,
+ double gx, double gy, double bx, double by, double wx, double wy)
+{
+ Color r, g, b, w, scale;
+ ColorMatrix m;
+
+ color_set (&r, rx, ry, 1.0);
+ color_xyY_to_XYZ (&r);
+ color_set (&g, gx, gy, 1.0);
+ color_xyY_to_XYZ (&g);
+ color_set (&b, bx, by, 1.0);
+ color_xyY_to_XYZ (&b);
+ color_set (&w, wx, wy, 1.0);
+ color_xyY_to_XYZ (&w);
+
+ color_matrix_set_identity (dst);
+
+ dst->m[0][0] = r.v[0];
+ dst->m[0][1] = r.v[1];
+ dst->m[0][2] = r.v[2];
+ dst->m[1][0] = g.v[0];
+ dst->m[1][1] = g.v[1];
+ dst->m[1][2] = g.v[2];
+ dst->m[2][0] = b.v[0];
+ dst->m[2][1] = b.v[1];
+ dst->m[2][2] = b.v[2];
+
+ color_matrix_dump (dst);
+ color_matrix_copy (&m, dst);
+ color_matrix_invert (&m);
+ color_matrix_dump (&m);
+
+ color_matrix_transpose (&m);
+ color_matrix_apply (&m, &scale, &w);
+ g_print ("%g %g %g\n", scale.v[0], scale.v[1], scale.v[2]);
+
+ dst->m[0][0] = r.v[0] * scale.v[0];
+ dst->m[0][1] = r.v[1] * scale.v[0];
+ dst->m[0][2] = r.v[2] * scale.v[0];
+ dst->m[1][0] = g.v[0] * scale.v[1];
+ dst->m[1][1] = g.v[1] * scale.v[1];
+ dst->m[1][2] = g.v[2] * scale.v[1];
+ dst->m[2][0] = b.v[0] * scale.v[2];
+ dst->m[2][1] = b.v[1] * scale.v[2];
+ dst->m[2][2] = b.v[2] * scale.v[2];
+
+ color_matrix_transpose (dst);
+ color_matrix_dump (dst);
+
+ color_set (&scale, 1, 1, 1);
+ color_matrix_apply (dst, &scale, &scale);
+ color_XYZ_to_xyY (&scale);
+ g_print ("white %g %g %g\n", scale.v[0], scale.v[1], scale.v[2]);
+
+}
+
+void
+color_matrix_build_rgb_to_XYZ_601 (ColorMatrix * dst)
+{
+ /* SMPTE C primaries, SMPTE 170M-2004 */
+ color_matrix_build_XYZ (dst,
+ 0.630, 0.340, 0.310, 0.595, 0.155, 0.070, 0.3127, 0.3290);
+#if 0
+ /* NTSC 1953 primaries, SMPTE 170M-2004 */
+ color_matrix_build_XYZ (dst,
+ 0.67, 0.33, 0.21, 0.71, 0.14, 0.08, 0.3127, 0.3290);
+#endif
+}
+
+void
+color_matrix_build_XYZ_to_rgb_709 (ColorMatrix * dst)
+{
+ /* Rec. ITU-R BT.709-5 */
+ color_matrix_build_XYZ (dst,
+ 0.640, 0.330, 0.300, 0.600, 0.150, 0.060, 0.3127, 0.3290);
+}
+
+void
+color_matrix_build_XYZ_to_rgb_dell (ColorMatrix * dst)
+{
+ /* Dell monitor */
+#if 1
+ color_matrix_build_XYZ (dst,
+ 0.662, 0.329, 0.205, 0.683, 0.146, 0.077, 0.3135, 0.3290);
+#endif
+#if 0
+ color_matrix_build_XYZ (dst,
+ 0.630, 0.340, 0.310, 0.595, 0.155, 0.070, 0.3127, 0.3290);
+#endif
+ color_matrix_invert (dst);
+}
+
+void
+color_transfer_function_apply (Color * dest, Color * src)
+{
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ if (src->v[i] < 0.0812) {
+ dest->v[i] = src->v[i] / 4.500;
+ } else {
+ dest->v[i] = pow (src->v[i] + 0.099, 1 / 0.4500);
+ }
+ }
+}
+
+void
+color_transfer_function_unapply (Color * dest, Color * src)
+{
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ if (src->v[i] < 0.0812 / 4.500) {
+ dest->v[i] = src->v[i] * 4.500;
+ } else {
+ dest->v[i] = pow (src->v[i], 0.4500) - 0.099;
+ }
+ }
+}
+
+void
+color_gamut_clamp (Color * dest, Color * src)
+{
+ dest->v[0] = CLAMP (src->v[0], 0.0, 1.0);
+ dest->v[1] = CLAMP (src->v[1], 0.0, 1.0);
+ dest->v[2] = CLAMP (src->v[2], 0.0, 1.0);
+}
+
+#if 0
+static guint8 *
+get_color_transform_table (void)
+{
+ static guint8 *color_transform_table = NULL;
+
+#if 1
+ if (!color_transform_table) {
+ ColorMatrix bt601_to_rgb;
+ ColorMatrix bt601_to_yuv;
+ ColorMatrix bt601_rgb_to_XYZ;
+ ColorMatrix dell_XYZ_to_rgb;
+ guint8 *table_y;
+ guint8 *table_u;
+ guint8 *table_v;
+ int y, u, v;
+
+ color_matrix_build_yuv_to_rgb_601 (&bt601_to_rgb);
+ color_matrix_build_rgb_to_yuv_601 (&bt601_to_yuv);
+ color_matrix_build_rgb_to_XYZ_601 (&bt601_rgb_to_XYZ);
+ color_matrix_build_XYZ_to_rgb_dell (&dell_XYZ_to_rgb);
+
+ color_transform_table = g_malloc (0x1000000 * 3);
+
+ table_y = COG_OFFSET (color_transform_table, 0 * 0x1000000);
+ table_u = COG_OFFSET (color_transform_table, 1 * 0x1000000);
+ table_v = COG_OFFSET (color_transform_table, 2 * 0x1000000);
+
+ for (y = 0; y < 256; y++) {
+ for (u = 0; u < 256; u++) {
+ for (v = 0; v < 256; v++) {
+ Color c;
+
+ c.v[0] = y;
+ c.v[1] = u;
+ c.v[2] = v;
+ color_matrix_apply (&bt601_to_rgb, &c, &c);
+ color_gamut_clamp (&c, &c);
+ color_transfer_function_apply (&c, &c);
+ color_matrix_apply (&bt601_rgb_to_XYZ, &c, &c);
+ color_matrix_apply (&dell_XYZ_to_rgb, &c, &c);
+ color_transfer_function_unapply (&c, &c);
+ color_gamut_clamp (&c, &c);
+ color_matrix_apply (&bt601_to_yuv, &c, &c);
+
+ table_y[(y << 16) | (u << 8) | (v)] = rint (c.v[0]);
+ table_u[(y << 16) | (u << 8) | (v)] = rint (c.v[1]);
+ table_v[(y << 16) | (u << 8) | (v)] = rint (c.v[2]);
+ }
+ }
+ }
+ }
+#endif
+#if 0
+ if (!color_transform_table) {
+ ColorMatrix bt709_to_bt601;
+ guint8 *table_y;
+ guint8 *table_u;
+ guint8 *table_v;
+ int y, u, v;
+
+ color_matrix_build_bt709_to_bt601 (&bt709_to_bt601);
+
+ color_transform_table = g_malloc (0x1000000 * 3);
+
+ table_y = COG_OFFSET (color_transform_table, 0 * 0x1000000);
+ table_u = COG_OFFSET (color_transform_table, 1 * 0x1000000);
+ table_v = COG_OFFSET (color_transform_table, 2 * 0x1000000);
+
+ for (y = 0; y < 256; y++) {
+ for (u = 0; u < 256; u++) {
+ for (v = 0; v < 256; v++) {
+ Color c;
+
+ c.v[0] = y;
+ c.v[1] = u;
+ c.v[2] = v;
+ color_matrix_apply (&bt709_to_bt601, &c, &c);
+
+ table_y[(y << 16) | (u << 8) | (v)] = rint (c.v[0]);
+ table_u[(y << 16) | (u << 8) | (v)] = rint (c.v[1]);
+ table_v[(y << 16) | (u << 8) | (v)] = rint (c.v[2]);
+ }
+ }
+ }
+ }
+#endif
+
+ return color_transform_table;
+}
+#endif
diff --git a/gst/videomixer/gstcms.h b/gst/videomixer/gstcms.h
new file mode 100644
index 000000000..f926a44af
--- /dev/null
+++ b/gst/videomixer/gstcms.h
@@ -0,0 +1,71 @@
+/* GStreamer
+ * Copyright (C) 2008 David Schleef <ds@entropywave.com>
+ *
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GST_CMS_H_
+#define _GST_CMS_H_
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+typedef struct _Color Color;
+typedef struct _ColorMatrix ColorMatrix;
+
+struct _Color
+{
+ double v[3];
+};
+
+struct _ColorMatrix
+{
+ double m[4][4];
+};
+
+void color_xyY_to_XYZ (Color * c);
+void color_XYZ_to_xyY (Color * c);
+void color_set (Color * c, double x, double y, double z);
+void color_matrix_set_identity (ColorMatrix * m);
+void color_matrix_dump (ColorMatrix * m);
+void color_matrix_multiply (ColorMatrix * dst, ColorMatrix * a, ColorMatrix * b);
+void color_matrix_apply (ColorMatrix * m, Color * dest, Color * src);
+void color_matrix_offset_components (ColorMatrix * m, double a1, double a2,
+ double a3);
+void color_matrix_scale_components (ColorMatrix * m, double a1, double a2, double a3);
+void color_matrix_YCbCr_to_RGB (ColorMatrix * m, double Kr, double Kb);
+void color_matrix_RGB_to_YCbCr (ColorMatrix * m, double Kr, double Kb);
+void color_matrix_build_yuv_to_rgb_601 (ColorMatrix * dst);
+void color_matrix_build_bt709_to_bt601 (ColorMatrix * dst);
+void color_matrix_build_rgb_to_yuv_601 (ColorMatrix * dst);
+void color_matrix_invert (ColorMatrix * m);
+void color_matrix_copy (ColorMatrix * dest, ColorMatrix * src);
+void color_matrix_transpose (ColorMatrix * m);
+void color_matrix_build_XYZ (ColorMatrix * dst,
+ double rx, double ry,
+ double gx, double gy, double bx, double by, double wx, double wy);
+void color_matrix_build_rgb_to_XYZ_601 (ColorMatrix * dst);
+void color_matrix_build_XYZ_to_rgb_709 (ColorMatrix * dst);
+void color_matrix_build_XYZ_to_rgb_dell (ColorMatrix * dst);
+void color_transfer_function_apply (Color * dest, Color * src);
+void color_transfer_function_unapply (Color * dest, Color * src);
+void color_gamut_clamp (Color * dest, Color * src);
+
+G_END_DECLS
+
+#endif
+
diff --git a/gst/videomixer/videoconvert.c b/gst/videomixer/videoconvert.c
new file mode 100644
index 000000000..ae95d59bc
--- /dev/null
+++ b/gst/videomixer/videoconvert.c
@@ -0,0 +1,1420 @@
+/* GStreamer
+ * Copyright (C) 2010 David Schleef <ds@schleef.org>
+ * Copyright (C) 2010 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
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "videoconvert.h"
+
+#include <glib.h>
+#include <string.h>
+#include <math.h>
+
+#include "videomixerorc.h"
+
+
+static void videomixer_videoconvert_convert_generic (VideoConvert * convert,
+ GstVideoFrame * dest, const GstVideoFrame * src);
+static void videomixer_videoconvert_convert_matrix8 (VideoConvert * convert,
+ gpointer pixels);
+static void videomixer_videoconvert_convert_matrix16 (VideoConvert * convert,
+ gpointer pixels);
+static gboolean videomixer_videoconvert_convert_lookup_fastpath (VideoConvert *
+ convert);
+static gboolean videomixer_videoconvert_convert_compute_matrix (VideoConvert *
+ convert);
+static gboolean videomixer_videoconvert_convert_compute_resample (VideoConvert *
+ convert);
+static void videomixer_videoconvert_dither_verterr (VideoConvert * convert,
+ guint16 * pixels, int j);
+static void videomixer_videoconvert_dither_halftone (VideoConvert * convert,
+ guint16 * pixels, int j);
+
+
+VideoConvert *
+videomixer_videoconvert_convert_new (GstVideoInfo * in_info,
+ GstVideoInfo * out_info)
+{
+ VideoConvert *convert;
+ gint width;
+
+ convert = g_malloc0 (sizeof (VideoConvert));
+
+ convert->in_info = *in_info;
+ convert->out_info = *out_info;
+ convert->dither16 = NULL;
+
+ convert->width = GST_VIDEO_INFO_WIDTH (in_info);
+ convert->height = GST_VIDEO_INFO_HEIGHT (in_info);
+
+ if (!videomixer_videoconvert_convert_lookup_fastpath (convert)) {
+ convert->convert = videomixer_videoconvert_convert_generic;
+ if (!videomixer_videoconvert_convert_compute_matrix (convert))
+ goto no_convert;
+
+ if (!videomixer_videoconvert_convert_compute_resample (convert))
+ goto no_convert;
+ }
+
+ width = convert->width;
+
+ convert->lines = out_info->finfo->pack_lines;
+ convert->errline = g_malloc0 (sizeof (guint16) * width * 4);
+
+ return convert;
+
+ /* ERRORS */
+no_convert:
+ {
+ videomixer_videoconvert_convert_free (convert);
+ return NULL;
+ }
+}
+
+void
+videomixer_videoconvert_convert_free (VideoConvert * convert)
+{
+ gint i;
+
+ if (convert->upsample)
+ gst_video_chroma_resample_free (convert->upsample);
+ if (convert->downsample)
+ gst_video_chroma_resample_free (convert->downsample);
+
+ for (i = 0; i < convert->n_tmplines; i++)
+ g_free (convert->tmplines[i]);
+ g_free (convert->tmplines);
+ g_free (convert->errline);
+
+ g_free (convert);
+}
+
+void
+videomixer_videoconvert_convert_set_dither (VideoConvert * convert, int type)
+{
+ switch (type) {
+ case 0:
+ default:
+ convert->dither16 = NULL;
+ break;
+ case 1:
+ convert->dither16 = videomixer_videoconvert_dither_verterr;
+ break;
+ case 2:
+ convert->dither16 = videomixer_videoconvert_dither_halftone;
+ break;
+ }
+}
+
+void
+videomixer_videoconvert_convert_convert (VideoConvert * convert,
+ GstVideoFrame * dest, const GstVideoFrame * src)
+{
+ convert->convert (convert, dest, src);
+}
+
+#define SCALE (8)
+#define SCALE_F ((float) (1 << SCALE))
+
+static void
+videomixer_videoconvert_convert_matrix8 (VideoConvert * convert,
+ gpointer pixels)
+{
+ int i;
+ int r, g, b;
+ int y, u, v;
+ guint8 *p = pixels;
+
+ for (i = 0; i < convert->width; i++) {
+ r = p[i * 4 + 1];
+ g = p[i * 4 + 2];
+ b = p[i * 4 + 3];
+
+ y = (convert->cmatrix[0][0] * r + convert->cmatrix[0][1] * g +
+ convert->cmatrix[0][2] * b + convert->cmatrix[0][3]) >> SCALE;
+ u = (convert->cmatrix[1][0] * r + convert->cmatrix[1][1] * g +
+ convert->cmatrix[1][2] * b + convert->cmatrix[1][3]) >> SCALE;
+ v = (convert->cmatrix[2][0] * r + convert->cmatrix[2][1] * g +
+ convert->cmatrix[2][2] * b + convert->cmatrix[2][3]) >> SCALE;
+
+ p[i * 4 + 1] = CLAMP (y, 0, 255);
+ p[i * 4 + 2] = CLAMP (u, 0, 255);
+ p[i * 4 + 3] = CLAMP (v, 0, 255);
+ }
+}
+
+static void
+videomixer_videoconvert_convert_matrix16 (VideoConvert * convert,
+ gpointer pixels)
+{
+ int i;
+ int r, g, b;
+ int y, u, v;
+ guint16 *p = pixels;
+
+ for (i = 0; i < convert->width; i++) {
+ r = p[i * 4 + 1];
+ g = p[i * 4 + 2];
+ b = p[i * 4 + 3];
+
+ y = (convert->cmatrix[0][0] * r + convert->cmatrix[0][1] * g +
+ convert->cmatrix[0][2] * b + convert->cmatrix[0][3]) >> SCALE;
+ u = (convert->cmatrix[1][0] * r + convert->cmatrix[1][1] * g +
+ convert->cmatrix[1][2] * b + convert->cmatrix[1][3]) >> SCALE;
+ v = (convert->cmatrix[2][0] * r + convert->cmatrix[2][1] * g +
+ convert->cmatrix[2][2] * b + convert->cmatrix[2][3]) >> SCALE;
+
+ p[i * 4 + 1] = CLAMP (y, 0, 65535);
+ p[i * 4 + 2] = CLAMP (u, 0, 65535);
+ p[i * 4 + 3] = CLAMP (v, 0, 65535);
+ }
+}
+
+static gboolean
+get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb)
+{
+ gboolean res = TRUE;
+
+ switch (matrix) {
+ /* RGB */
+ default:
+ case GST_VIDEO_COLOR_MATRIX_RGB:
+ res = FALSE;
+ break;
+ /* YUV */
+ case GST_VIDEO_COLOR_MATRIX_FCC:
+ *Kr = 0.30;
+ *Kb = 0.11;
+ break;
+ case GST_VIDEO_COLOR_MATRIX_BT709:
+ *Kr = 0.2126;
+ *Kb = 0.0722;
+ break;
+ case GST_VIDEO_COLOR_MATRIX_BT601:
+ *Kr = 0.2990;
+ *Kb = 0.1140;
+ break;
+ case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
+ *Kr = 0.212;
+ *Kb = 0.087;
+ break;
+ }
+ GST_DEBUG ("matrix: %d, Kr %f, Kb %f", matrix, *Kr, *Kb);
+ return res;
+}
+
+static gboolean
+videomixer_videoconvert_convert_compute_matrix (VideoConvert * convert)
+{
+ GstVideoInfo *in_info, *out_info;
+ ColorMatrix dst;
+ gint i, j;
+ const GstVideoFormatInfo *sfinfo, *dfinfo;
+ const GstVideoFormatInfo *suinfo, *duinfo;
+ gint offset[4], scale[4];
+ gdouble Kr = 0, Kb = 0;
+
+ in_info = &convert->in_info;
+ out_info = &convert->out_info;
+
+ sfinfo = in_info->finfo;
+ dfinfo = out_info->finfo;
+
+ if (sfinfo->unpack_func == NULL)
+ goto no_unpack_func;
+
+ if (dfinfo->pack_func == NULL)
+ goto no_pack_func;
+
+ suinfo = gst_video_format_get_info (sfinfo->unpack_format);
+ duinfo = gst_video_format_get_info (dfinfo->unpack_format);
+
+ convert->in_bits = GST_VIDEO_FORMAT_INFO_DEPTH (suinfo, 0);
+ convert->out_bits = GST_VIDEO_FORMAT_INFO_DEPTH (duinfo, 0);
+
+ GST_DEBUG ("in bits %d, out bits %d", convert->in_bits, convert->out_bits);
+
+ if (in_info->colorimetry.range == out_info->colorimetry.range &&
+ in_info->colorimetry.matrix == out_info->colorimetry.matrix) {
+ GST_DEBUG ("using identity color transform");
+ convert->matrix = NULL;
+ return TRUE;
+ }
+
+ /* calculate intermediate format for the matrix. When unpacking, we expand
+ * input to 16 when one of the inputs is 16 bits */
+ if (convert->in_bits == 16 || convert->out_bits == 16) {
+ convert->matrix = videomixer_videoconvert_convert_matrix16;
+
+ if (GST_VIDEO_FORMAT_INFO_IS_RGB (suinfo))
+ suinfo = gst_video_format_get_info (GST_VIDEO_FORMAT_ARGB64);
+ else
+ suinfo = gst_video_format_get_info (GST_VIDEO_FORMAT_AYUV64);
+
+ if (GST_VIDEO_FORMAT_INFO_IS_RGB (duinfo))
+ duinfo = gst_video_format_get_info (GST_VIDEO_FORMAT_ARGB64);
+ else
+ duinfo = gst_video_format_get_info (GST_VIDEO_FORMAT_AYUV64);
+ } else {
+ convert->matrix = videomixer_videoconvert_convert_matrix8;
+ }
+
+ color_matrix_set_identity (&dst);
+
+ /* 1, bring color components to [0..1.0] range */
+ gst_video_color_range_offsets (in_info->colorimetry.range, suinfo, offset,
+ scale);
+ color_matrix_offset_components (&dst, -offset[0], -offset[1], -offset[2]);
+
+ color_matrix_scale_components (&dst, 1 / ((float) scale[0]),
+ 1 / ((float) scale[1]), 1 / ((float) scale[2]));
+
+ /* 2. bring components to R'G'B' space */
+ if (get_Kr_Kb (in_info->colorimetry.matrix, &Kr, &Kb))
+ color_matrix_YCbCr_to_RGB (&dst, Kr, Kb);
+
+ /* 3. inverse transfer function. R'G'B' to linear RGB */
+
+ /* 4. from RGB to XYZ using the primaries */
+
+ /* 5. from XYZ to RGB using the primaries */
+
+ /* 6. transfer function. linear RGB to R'G'B' */
+
+ /* 7. bring components to YCbCr space */
+ if (get_Kr_Kb (out_info->colorimetry.matrix, &Kr, &Kb))
+ color_matrix_RGB_to_YCbCr (&dst, Kr, Kb);
+
+ /* 8, bring color components to nominal range */
+ gst_video_color_range_offsets (out_info->colorimetry.range, duinfo, offset,
+ scale);
+ color_matrix_scale_components (&dst, (float) scale[0], (float) scale[1],
+ (float) scale[2]);
+
+ color_matrix_offset_components (&dst, offset[0], offset[1], offset[2]);
+
+ /* because we're doing fixed point matrix coefficients */
+ color_matrix_scale_components (&dst, SCALE_F, SCALE_F, SCALE_F);
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ convert->cmatrix[i][j] = rint (dst.m[i][j]);
+
+ GST_DEBUG ("[%6d %6d %6d %6d]", convert->cmatrix[0][0],
+ convert->cmatrix[0][1], convert->cmatrix[0][2], convert->cmatrix[0][3]);
+ GST_DEBUG ("[%6d %6d %6d %6d]", convert->cmatrix[1][0],
+ convert->cmatrix[1][1], convert->cmatrix[1][2], convert->cmatrix[1][3]);
+ GST_DEBUG ("[%6d %6d %6d %6d]", convert->cmatrix[2][0],
+ convert->cmatrix[2][1], convert->cmatrix[2][2], convert->cmatrix[2][3]);
+ GST_DEBUG ("[%6d %6d %6d %6d]", convert->cmatrix[3][0],
+ convert->cmatrix[3][1], convert->cmatrix[3][2], convert->cmatrix[3][3]);
+
+ return TRUE;
+
+ /* ERRORS */
+no_unpack_func:
+ {
+ GST_ERROR ("no unpack_func for format %s",
+ gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)));
+ return FALSE;
+ }
+no_pack_func:
+ {
+ GST_ERROR ("no pack_func for format %s",
+ gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info)));
+ return FALSE;
+ }
+}
+
+static void
+videomixer_videoconvert_dither_verterr (VideoConvert * convert,
+ guint16 * pixels, int j)
+{
+ int i;
+ guint16 *errline = convert->errline;
+ unsigned int mask = 0xff;
+
+ for (i = 0; i < 4 * convert->width; i++) {
+ int x = pixels[i] + errline[i];
+ if (x > 65535)
+ x = 65535;
+ pixels[i] = x;
+ errline[i] = x & mask;
+ }
+}
+
+static void
+videomixer_videoconvert_dither_halftone (VideoConvert * convert,
+ guint16 * pixels, int j)
+{
+ int i;
+ static guint16 halftone[8][8] = {
+ {0, 128, 32, 160, 8, 136, 40, 168},
+ {192, 64, 224, 96, 200, 72, 232, 104},
+ {48, 176, 16, 144, 56, 184, 24, 152},
+ {240, 112, 208, 80, 248, 120, 216, 88},
+ {12, 240, 44, 172, 4, 132, 36, 164},
+ {204, 76, 236, 108, 196, 68, 228, 100},
+ {60, 188, 28, 156, 52, 180, 20, 148},
+ {252, 142, 220, 92, 244, 116, 212, 84}
+ };
+
+ for (i = 0; i < convert->width * 4; i++) {
+ int x;
+ x = pixels[i] + halftone[(i >> 2) & 7][j & 7];
+ if (x > 65535)
+ x = 65535;
+ pixels[i] = x;
+ }
+}
+
+static gboolean
+videomixer_videoconvert_convert_compute_resample (VideoConvert * convert)
+{
+ GstVideoInfo *in_info, *out_info;
+ const GstVideoFormatInfo *sfinfo, *dfinfo;
+ gint lines, i;
+ gint width;
+
+ in_info = &convert->in_info;
+ out_info = &convert->out_info;
+
+ sfinfo = in_info->finfo;
+ dfinfo = out_info->finfo;
+
+ width = convert->width;
+
+ convert->upsample = gst_video_chroma_resample_new (0,
+ in_info->chroma_site, 0, sfinfo->unpack_format, sfinfo->w_sub[2],
+ sfinfo->h_sub[2]);
+ if (convert->upsample) {
+ gst_video_chroma_resample_get_info (convert->upsample,
+ &convert->up_n_lines, &convert->up_offset);
+ } else {
+ convert->up_n_lines = 1;
+ convert->up_offset = 0;
+ }
+ GST_DEBUG ("upsample: %p, offset %d, n_lines %d", convert->upsample,
+ convert->up_offset, convert->up_n_lines);
+
+ convert->downsample = gst_video_chroma_resample_new (0,
+ out_info->chroma_site, 0, dfinfo->unpack_format, -dfinfo->w_sub[2],
+ -dfinfo->h_sub[2]);
+ if (convert->downsample) {
+ gst_video_chroma_resample_get_info (convert->downsample,
+ &convert->down_n_lines, &convert->down_offset);
+ } else {
+ convert->down_n_lines = 1;
+ convert->down_offset = 0;
+ }
+
+ GST_DEBUG ("downsample: %p, offset %d, n_lines %d", convert->downsample,
+ convert->down_offset, convert->down_n_lines);
+
+ lines = MAX (convert->down_n_lines, convert->up_n_lines);
+
+ convert->n_tmplines = lines;
+ convert->tmplines = g_malloc (lines * sizeof (gpointer));
+ for (i = 0; i < lines; i++)
+ convert->tmplines[i] = g_malloc (sizeof (guint16) * (width + 8) * 4);
+
+ return TRUE;
+}
+
+#define TO_16(x) (((x)<<8) | (x))
+
+static void
+convert_to16 (gpointer line, gint width)
+{
+ guint8 *line8 = line;
+ guint16 *line16 = line;
+ gint i;
+
+ for (i = (width - 1) * 4; i >= 0; i--)
+ line16[i] = TO_16 (line8[i]);
+}
+
+static void
+convert_to8 (gpointer line, gint width)
+{
+ guint8 *line8 = line;
+ guint16 *line16 = line;
+ gint i;
+
+ for (i = 0; i < width * 4; i++)
+ line8[i] = line16[i] >> 8;
+}
+
+#define UNPACK_FRAME(frame,dest,line,width) \
+ frame->info.finfo->unpack_func (frame->info.finfo, \
+ (GST_VIDEO_FRAME_IS_INTERLACED (frame) ? \
+ GST_VIDEO_PACK_FLAG_INTERLACED : \
+ GST_VIDEO_PACK_FLAG_NONE), \
+ dest, frame->data, frame->info.stride, 0, \
+ line, width)
+#define PACK_FRAME(frame,dest,line,width) \
+ frame->info.finfo->pack_func (frame->info.finfo, \
+ (GST_VIDEO_FRAME_IS_INTERLACED (frame) ? \
+ GST_VIDEO_PACK_FLAG_INTERLACED : \
+ GST_VIDEO_PACK_FLAG_NONE), \
+ dest, 0, frame->data, frame->info.stride, \
+ frame->info.chroma_site, line, width);
+
+static void
+videomixer_videoconvert_convert_generic (VideoConvert * convert,
+ GstVideoFrame * dest, const GstVideoFrame * src)
+{
+ int j, k;
+ gint width, height, lines, max_lines;
+ guint in_bits, out_bits;
+ gconstpointer pal;
+ gsize palsize;
+ guint up_n_lines, down_n_lines;
+ gint up_offset, down_offset;
+ gint in_lines, out_lines;
+ gint up_line, down_line;
+ gint start_offset, stop_offset;
+ gpointer in_tmplines[8];
+ gpointer out_tmplines[8];
+
+ height = convert->height;
+ width = convert->width;
+
+ in_bits = convert->in_bits;
+ out_bits = convert->out_bits;
+
+ lines = convert->lines;
+ up_n_lines = convert->up_n_lines;
+ up_offset = convert->up_offset;
+ down_n_lines = convert->down_n_lines;
+ down_offset = convert->down_offset;
+ max_lines = MAX (down_n_lines, up_n_lines);
+
+ in_lines = 0;
+ out_lines = 0;
+
+ GST_DEBUG ("up_offset %d, up_n_lines %u", up_offset, up_n_lines);
+
+ start_offset = MIN (up_offset, down_offset);
+ stop_offset = height + start_offset + MAX (up_n_lines, down_n_lines);
+
+ for (; start_offset < stop_offset; start_offset++) {
+ guint idx, start;
+
+ idx = CLAMP (start_offset, 0, height);
+ in_tmplines[in_lines] = convert->tmplines[idx % max_lines];
+ out_tmplines[out_lines] = in_tmplines[in_lines];
+ GST_DEBUG ("start_offset %d, %d, idx %u, in %d, out %d", start_offset,
+ up_offset, idx, in_lines, out_lines);
+
+ up_line = up_offset + in_lines;
+
+ /* extract the next line */
+ if (up_line >= 0 && up_line < height) {
+ GST_DEBUG ("unpack line %d", up_line);
+ UNPACK_FRAME (src, in_tmplines[in_lines], up_line, width);
+ }
+
+ if (start_offset >= up_offset)
+ in_lines++;
+
+ if (start_offset >= down_offset)
+ out_lines++;
+
+ if (in_lines < up_n_lines)
+ continue;
+
+ in_lines = 0;
+
+ /* we have enough lines to upsample */
+ if (convert->upsample) {
+ GST_DEBUG ("doing upsample");
+ gst_video_chroma_resample (convert->upsample, in_tmplines, width);
+ }
+
+ /* convert upsampled lines */
+ for (k = 0; k < up_n_lines; k++) {
+ down_line = up_offset + k;
+
+ /* only takes lines with valid output */
+ if (down_line < 0 || down_line >= height)
+ continue;
+
+ GST_DEBUG ("handle line %d, %d/%d, down_line %d", k, out_lines,
+ down_n_lines, down_line);
+
+ if (out_bits == 16 || in_bits == 16) {
+ /* FIXME, we can scale in the conversion matrix */
+ if (in_bits == 8)
+ convert_to16 (in_tmplines[k], width);
+
+ if (convert->matrix)
+ convert->matrix (convert, in_tmplines[k]);
+ if (convert->dither16)
+ convert->dither16 (convert, in_tmplines[k], down_line);
+
+ if (out_bits == 8)
+ convert_to8 (in_tmplines[k], width);
+ } else {
+ if (convert->matrix)
+ convert->matrix (convert, in_tmplines[k]);
+ }
+ }
+
+ start = 0;
+ while (out_lines >= down_n_lines) {
+ GST_DEBUG ("doing downsample %u", start);
+ if (convert->downsample)
+ gst_video_chroma_resample (convert->downsample,
+ &out_tmplines[start], width);
+
+ for (j = 0; j < down_n_lines; j += lines) {
+ idx = down_offset + j;
+
+ if (idx >= 0 && idx < height) {
+ GST_DEBUG ("packing line %d %d %d", j + start, down_offset, idx);
+ /* FIXME, not correct if lines > 1 */
+ PACK_FRAME (dest, out_tmplines[j + start], idx, width);
+ }
+ }
+ down_offset += down_n_lines;
+ start += down_n_lines;
+ out_lines -= down_n_lines;
+ }
+ up_offset += up_n_lines;
+ }
+ if ((pal =
+ gst_video_format_get_palette (GST_VIDEO_FRAME_FORMAT (dest),
+ &palsize))) {
+ memcpy (GST_VIDEO_FRAME_PLANE_DATA (dest, 1), pal, palsize);
+ }
+}
+
+#define FRAME_GET_PLANE_STRIDE(frame, plane) \
+ GST_VIDEO_FRAME_PLANE_STRIDE (frame, plane)
+#define FRAME_GET_PLANE_LINE(frame, plane, line) \
+ (gpointer)(((guint8*)(GST_VIDEO_FRAME_PLANE_DATA (frame, plane))) + \
+ FRAME_GET_PLANE_STRIDE (frame, plane) * (line))
+
+#define FRAME_GET_COMP_STRIDE(frame, comp) \
+ GST_VIDEO_FRAME_COMP_STRIDE (frame, comp)
+#define FRAME_GET_COMP_LINE(frame, comp, line) \
+ (gpointer)(((guint8*)(GST_VIDEO_FRAME_COMP_DATA (frame, comp))) + \
+ FRAME_GET_COMP_STRIDE (frame, comp) * (line))
+
+#define FRAME_GET_STRIDE(frame) FRAME_GET_PLANE_STRIDE (frame, 0)
+#define FRAME_GET_LINE(frame,line) FRAME_GET_PLANE_LINE (frame, 0, line)
+
+#define FRAME_GET_Y_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_Y, line)
+#define FRAME_GET_U_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_U, line)
+#define FRAME_GET_V_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_V, line)
+#define FRAME_GET_A_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_A, line)
+
+#define FRAME_GET_Y_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_Y)
+#define FRAME_GET_U_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_U)
+#define FRAME_GET_V_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_V)
+#define FRAME_GET_A_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_A)
+
+/* Fast paths */
+
+#define GET_LINE_OFFSETS(interlaced,line,l1,l2) \
+ if (interlaced) { \
+ l1 = (line & 2 ? line - 1 : line); \
+ l2 = l1 + 2; \
+ } else { \
+ l1 = line; \
+ l2 = l1 + 1; \
+ }
+
+
+static void
+convert_I420_YUY2 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ int i;
+ gint width = convert->width;
+ gint height = convert->height;
+ gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src);
+ gint l1, l2;
+
+ for (i = 0; i < GST_ROUND_DOWN_2 (height); i += 2) {
+ GET_LINE_OFFSETS (interlaced, i, l1, l2);
+
+ videomixer_video_convert_orc_convert_I420_YUY2 (FRAME_GET_LINE (dest, l1),
+ FRAME_GET_LINE (dest, l2),
+ FRAME_GET_Y_LINE (src, l1),
+ FRAME_GET_Y_LINE (src, l2),
+ FRAME_GET_U_LINE (src, i >> 1),
+ FRAME_GET_V_LINE (src, i >> 1), (width + 1) / 2);
+ }
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_I420_UYVY (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ int i;
+ gint width = convert->width;
+ gint height = convert->height;
+ gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src);
+ gint l1, l2;
+
+ for (i = 0; i < GST_ROUND_DOWN_2 (height); i += 2) {
+ GET_LINE_OFFSETS (interlaced, i, l1, l2);
+
+ videomixer_video_convert_orc_convert_I420_UYVY (FRAME_GET_LINE (dest, l1),
+ FRAME_GET_LINE (dest, l2),
+ FRAME_GET_Y_LINE (src, l1),
+ FRAME_GET_Y_LINE (src, l2),
+ FRAME_GET_U_LINE (src, i >> 1),
+ FRAME_GET_V_LINE (src, i >> 1), (width + 1) / 2);
+ }
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_I420_AYUV (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ int i;
+ gint width = convert->width;
+ gint height = convert->height;
+ gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src);
+ gint l1, l2;
+
+ for (i = 0; i < GST_ROUND_DOWN_2 (height); i += 2) {
+ GET_LINE_OFFSETS (interlaced, i, l1, l2);
+
+ videomixer_video_convert_orc_convert_I420_AYUV (FRAME_GET_LINE (dest, l1),
+ FRAME_GET_LINE (dest, l2),
+ FRAME_GET_Y_LINE (src, l1),
+ FRAME_GET_Y_LINE (src, l2),
+ FRAME_GET_U_LINE (src, i >> 1), FRAME_GET_V_LINE (src, i >> 1), width);
+ }
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_I420_Y42B (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_memcpy_2d (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), width, height);
+
+ videomixer_video_convert_orc_planar_chroma_420_422 (FRAME_GET_U_LINE (dest,
+ 0), 2 * FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (dest, 1),
+ 2 * FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), (width + 1) / 2, height / 2);
+
+ videomixer_video_convert_orc_planar_chroma_420_422 (FRAME_GET_V_LINE (dest,
+ 0), 2 * FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (dest, 1),
+ 2 * FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height / 2);
+}
+
+static void
+convert_I420_Y444 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_memcpy_2d (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), width, height);
+
+ videomixer_video_convert_orc_planar_chroma_420_444 (FRAME_GET_U_LINE (dest,
+ 0), 2 * FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (dest, 1),
+ 2 * FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), (width + 1) / 2, height / 2);
+
+ videomixer_video_convert_orc_planar_chroma_420_444 (FRAME_GET_V_LINE (dest,
+ 0), 2 * FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (dest, 1),
+ 2 * FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height / 2);
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_YUY2_I420 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ int i, h;
+ gint width = convert->width;
+ gint height = convert->height;
+ gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src);
+ gint l1, l2;
+
+ h = height;
+ if (width & 1)
+ h--;
+
+ for (i = 0; i < h; i += 2) {
+ GET_LINE_OFFSETS (interlaced, i, l1, l2);
+
+ videomixer_video_convert_orc_convert_YUY2_I420 (FRAME_GET_Y_LINE (dest, l1),
+ FRAME_GET_Y_LINE (dest, l2),
+ FRAME_GET_U_LINE (dest, i >> 1),
+ FRAME_GET_V_LINE (dest, i >> 1),
+ FRAME_GET_LINE (src, l1), FRAME_GET_LINE (src, l2), (width + 1) / 2);
+ }
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_YUY2_AYUV (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_YUY2_AYUV (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2,
+ height & 1 ? height - 1 : height);
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_YUY2_Y42B (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_YUY2_Y42B (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_U_LINE (dest, 0),
+ FRAME_GET_U_STRIDE (dest), FRAME_GET_V_LINE (dest, 0),
+ FRAME_GET_V_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_YUY2_Y444 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_YUY2_Y444 (FRAME_GET_COMP_LINE (dest, 0,
+ 0), FRAME_GET_COMP_STRIDE (dest, 0), FRAME_GET_COMP_LINE (dest, 1, 0),
+ FRAME_GET_COMP_STRIDE (dest, 1), FRAME_GET_COMP_LINE (dest, 2, 0),
+ FRAME_GET_COMP_STRIDE (dest, 2), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2, height);
+}
+
+
+static void
+convert_UYVY_I420 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ int i;
+ gint width = convert->width;
+ gint height = convert->height;
+ gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src);
+ gint l1, l2;
+
+ for (i = 0; i < GST_ROUND_DOWN_2 (height); i += 2) {
+ GET_LINE_OFFSETS (interlaced, i, l1, l2);
+
+ videomixer_video_convert_orc_convert_UYVY_I420 (FRAME_GET_COMP_LINE (dest,
+ 0, l1), FRAME_GET_COMP_LINE (dest, 0, l2),
+ FRAME_GET_COMP_LINE (dest, 1, i >> 1), FRAME_GET_COMP_LINE (dest, 2,
+ i >> 1), FRAME_GET_LINE (src, l1), FRAME_GET_LINE (src, l2),
+ (width + 1) / 2);
+ }
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_UYVY_AYUV (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_UYVY_AYUV (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2,
+ height & 1 ? height - 1 : height);
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_UYVY_YUY2 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_UYVY_YUY2 (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_UYVY_Y42B (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_UYVY_Y42B (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_U_LINE (dest, 0),
+ FRAME_GET_U_STRIDE (dest), FRAME_GET_V_LINE (dest, 0),
+ FRAME_GET_V_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_UYVY_Y444 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_UYVY_Y444 (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_U_LINE (dest, 0),
+ FRAME_GET_U_STRIDE (dest), FRAME_GET_V_LINE (dest, 0),
+ FRAME_GET_V_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_AYUV_I420 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_I420 (FRAME_GET_Y_LINE (dest, 0),
+ 2 * FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (dest, 1),
+ 2 * FRAME_GET_Y_STRIDE (dest), FRAME_GET_U_LINE (dest, 0),
+ FRAME_GET_U_STRIDE (dest), FRAME_GET_V_LINE (dest, 0),
+ FRAME_GET_V_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ 2 * FRAME_GET_STRIDE (src), FRAME_GET_LINE (src, 1),
+ 2 * FRAME_GET_STRIDE (src), width / 2, height / 2);
+}
+
+static void
+convert_AYUV_YUY2 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_YUY2 (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width / 2, height);
+}
+
+static void
+convert_AYUV_UYVY (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_UYVY (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width / 2, height);
+}
+
+static void
+convert_AYUV_Y42B (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_Y42B (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_U_LINE (dest, 0),
+ FRAME_GET_U_STRIDE (dest), FRAME_GET_V_LINE (dest, 0),
+ FRAME_GET_V_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), (width + 1) / 2,
+ height & 1 ? height - 1 : height);
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_AYUV_Y444 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_Y444 (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_U_LINE (dest, 0),
+ FRAME_GET_U_STRIDE (dest), FRAME_GET_V_LINE (dest, 0),
+ FRAME_GET_V_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width, height);
+}
+
+static void
+convert_Y42B_I420 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_memcpy_2d (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), width, height);
+
+ videomixer_video_convert_orc_planar_chroma_422_420 (FRAME_GET_U_LINE (dest,
+ 0), FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (src, 0),
+ 2 * FRAME_GET_U_STRIDE (src), FRAME_GET_U_LINE (src, 1),
+ 2 * FRAME_GET_U_STRIDE (src), (width + 1) / 2, height / 2);
+
+ videomixer_video_convert_orc_planar_chroma_422_420 (FRAME_GET_V_LINE (dest,
+ 0), FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (src, 0),
+ 2 * FRAME_GET_V_STRIDE (src), FRAME_GET_V_LINE (src, 1),
+ 2 * FRAME_GET_V_STRIDE (src), (width + 1) / 2, height / 2);
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_Y42B_Y444 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_memcpy_2d (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), width, height);
+
+ videomixer_video_convert_orc_planar_chroma_422_444 (FRAME_GET_U_LINE (dest,
+ 0), FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), (width + 1) / 2, height);
+
+ videomixer_video_convert_orc_planar_chroma_422_444 (FRAME_GET_V_LINE (dest,
+ 0), FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_Y42B_YUY2 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_Y42B_YUY2 (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_Y42B_UYVY (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_Y42B_UYVY (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_Y42B_AYUV (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_Y42B_AYUV (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width) / 2, height);
+}
+
+static void
+convert_Y444_I420 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_memcpy_2d (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), width, height);
+
+ videomixer_video_convert_orc_planar_chroma_444_420 (FRAME_GET_U_LINE (dest,
+ 0), FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (src, 0),
+ 2 * FRAME_GET_U_STRIDE (src), FRAME_GET_U_LINE (src, 1),
+ 2 * FRAME_GET_U_STRIDE (src), (width + 1) / 2, height / 2);
+
+ videomixer_video_convert_orc_planar_chroma_444_420 (FRAME_GET_V_LINE (dest,
+ 0), FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (src, 0),
+ 2 * FRAME_GET_V_STRIDE (src), FRAME_GET_V_LINE (src, 1),
+ 2 * FRAME_GET_V_STRIDE (src), (width + 1) / 2, height / 2);
+
+ /* now handle last line */
+ if (height & 1) {
+ UNPACK_FRAME (src, convert->tmplines[0], height - 1, width);
+ PACK_FRAME (dest, convert->tmplines[0], height - 1, width);
+ }
+}
+
+static void
+convert_Y444_Y42B (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_memcpy_2d (FRAME_GET_Y_LINE (dest, 0),
+ FRAME_GET_Y_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), width, height);
+
+ videomixer_video_convert_orc_planar_chroma_444_422 (FRAME_GET_U_LINE (dest,
+ 0), FRAME_GET_U_STRIDE (dest), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), (width + 1) / 2, height);
+
+ videomixer_video_convert_orc_planar_chroma_444_422 (FRAME_GET_V_LINE (dest,
+ 0), FRAME_GET_V_STRIDE (dest), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_Y444_YUY2 (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_Y444_YUY2 (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_Y444_UYVY (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_Y444_UYVY (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), (width + 1) / 2, height);
+}
+
+static void
+convert_Y444_AYUV (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_Y444_AYUV (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_Y_LINE (src, 0),
+ FRAME_GET_Y_STRIDE (src), FRAME_GET_U_LINE (src, 0),
+ FRAME_GET_U_STRIDE (src), FRAME_GET_V_LINE (src, 0),
+ FRAME_GET_V_STRIDE (src), width, height);
+}
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+static void
+convert_AYUV_ARGB (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_ARGB (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width, height);
+}
+
+static void
+convert_AYUV_BGRA (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_BGRA (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width, height);
+}
+
+static void
+convert_AYUV_ABGR (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_ABGR (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width, height);
+}
+
+static void
+convert_AYUV_RGBA (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ gint width = convert->width;
+ gint height = convert->height;
+
+ videomixer_video_convert_orc_convert_AYUV_RGBA (FRAME_GET_LINE (dest, 0),
+ FRAME_GET_STRIDE (dest), FRAME_GET_LINE (src, 0),
+ FRAME_GET_STRIDE (src), width, height);
+}
+
+static void
+convert_I420_BGRA (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src)
+{
+ int i;
+ int quality = 0;
+ gint width = convert->width;
+ gint height = convert->height;
+
+ if (quality > 3) {
+ for (i = 0; i < height; i++) {
+ if (i & 1) {
+ videomixer_video_convert_orc_convert_I420_BGRA_avg (FRAME_GET_LINE
+ (dest, i), FRAME_GET_Y_LINE (src, i), FRAME_GET_U_LINE (src,
+ i >> 1), FRAME_GET_U_LINE (src, (i >> 1) + 1),
+ FRAME_GET_V_LINE (src, i >> 1), FRAME_GET_V_LINE (src,
+ (i >> 1) + 1), width);
+ } else {
+ videomixer_video_convert_orc_convert_I420_BGRA (FRAME_GET_LINE (dest,
+ i), FRAME_GET_Y_LINE (src, i), FRAME_GET_U_LINE (src, i >> 1),
+ FRAME_GET_V_LINE (src, i >> 1), width);
+ }
+ }
+ } else {
+ for (i = 0; i < height; i++) {
+ videomixer_video_convert_orc_convert_I420_BGRA (FRAME_GET_LINE (dest, i),
+ FRAME_GET_Y_LINE (src, i),
+ FRAME_GET_U_LINE (src, i >> 1),
+ FRAME_GET_V_LINE (src, i >> 1), width);
+ }
+ }
+}
+#endif
+
+
+
+/* Fast paths */
+
+typedef struct
+{
+ GstVideoFormat in_format;
+ GstVideoColorMatrix in_matrix;
+ GstVideoFormat out_format;
+ GstVideoColorMatrix out_matrix;
+ gboolean keeps_color_matrix;
+ gboolean keeps_interlaced;
+ void (*convert) (VideoConvert * convert, GstVideoFrame * dest,
+ const GstVideoFrame * src);
+} VideoTransform;
+
+static const VideoTransform transforms[] = {
+ {GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_YUY2,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_I420_YUY2},
+ {GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_UYVY,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_I420_UYVY},
+ {GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_AYUV,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_I420_AYUV},
+ {GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y42B,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, FALSE, convert_I420_Y42B},
+ {GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y444,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, FALSE, convert_I420_Y444},
+
+ {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_I420,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_YUY2_I420},
+ {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_UYVY,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_UYVY_YUY2}, /* alias */
+ {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_AYUV,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_YUY2_AYUV},
+ {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y42B,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_YUY2_Y42B},
+ {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y444,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_YUY2_Y444},
+
+ {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_I420,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_UYVY_I420},
+ {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_YUY2,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_UYVY_YUY2},
+ {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_AYUV,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_UYVY_AYUV},
+ {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y42B,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_UYVY_Y42B},
+ {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y444,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_UYVY_Y444},
+
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_I420,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, FALSE, convert_AYUV_I420},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_YUY2,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_AYUV_YUY2},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_UYVY,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_AYUV_UYVY},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y42B,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_AYUV_Y42B},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y444,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_AYUV_Y444},
+
+ {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_I420,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, FALSE, convert_Y42B_I420},
+ {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_YUY2,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y42B_YUY2},
+ {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_UYVY,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y42B_UYVY},
+ {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_AYUV,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y42B_AYUV},
+ {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y444,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y42B_Y444},
+
+ {GST_VIDEO_FORMAT_Y444, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_I420,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, FALSE, convert_Y444_I420},
+ {GST_VIDEO_FORMAT_Y444, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_YUY2,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y444_YUY2},
+ {GST_VIDEO_FORMAT_Y444, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_UYVY,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y444_UYVY},
+ {GST_VIDEO_FORMAT_Y444, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_AYUV,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y444_AYUV},
+ {GST_VIDEO_FORMAT_Y444, GST_VIDEO_COLOR_MATRIX_UNKNOWN, GST_VIDEO_FORMAT_Y42B,
+ GST_VIDEO_COLOR_MATRIX_UNKNOWN, TRUE, TRUE, convert_Y444_Y42B},
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_ARGB,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_ARGB},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_BGRA,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_BGRA},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_xRGB,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_ARGB}, /* alias */
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_BGRx,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_BGRA}, /* alias */
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_ABGR,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_ABGR},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_RGBA,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_RGBA},
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_xBGR,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_ABGR}, /* alias */
+ {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_RGBx,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, TRUE, convert_AYUV_RGBA}, /* alias */
+
+ {GST_VIDEO_FORMAT_I420, GST_VIDEO_COLOR_MATRIX_BT601, GST_VIDEO_FORMAT_BGRA,
+ GST_VIDEO_COLOR_MATRIX_RGB, FALSE, FALSE, convert_I420_BGRA},
+#endif
+};
+
+static gboolean
+videomixer_videoconvert_convert_lookup_fastpath (VideoConvert * convert)
+{
+ int i;
+ GstVideoFormat in_format, out_format;
+ GstVideoColorMatrix in_matrix, out_matrix;
+ gboolean interlaced;
+
+ in_format = GST_VIDEO_INFO_FORMAT (&convert->in_info);
+ out_format = GST_VIDEO_INFO_FORMAT (&convert->out_info);
+
+ in_matrix = convert->in_info.colorimetry.matrix;
+ out_matrix = convert->out_info.colorimetry.matrix;
+
+ interlaced = GST_VIDEO_INFO_IS_INTERLACED (&convert->in_info);
+ interlaced |= GST_VIDEO_INFO_IS_INTERLACED (&convert->out_info);
+
+ for (i = 0; i < sizeof (transforms) / sizeof (transforms[0]); i++) {
+ if (transforms[i].in_format == in_format &&
+ transforms[i].out_format == out_format &&
+ (transforms[i].keeps_color_matrix ||
+ (transforms[i].in_matrix == in_matrix &&
+ transforms[i].out_matrix == out_matrix)) &&
+ (transforms[i].keeps_interlaced || !interlaced)) {
+ GST_DEBUG ("using fastpath");
+ convert->convert = transforms[i].convert;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
diff --git a/gst/videomixer/videoconvert.h b/gst/videomixer/videoconvert.h
new file mode 100644
index 000000000..b83b28ba1
--- /dev/null
+++ b/gst/videomixer/videoconvert.h
@@ -0,0 +1,80 @@
+/* Video conversion functions
+ * Copyright (C) 2010 David Schleef <ds@schleef.org>
+ *
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __COLORSPACE_H__
+#define __COLORSPACE_H__
+
+#include <gst/video/video.h>
+#include "gstcms.h"
+
+G_BEGIN_DECLS
+
+typedef struct _VideoConvert VideoConvert;
+
+typedef enum {
+ DITHER_NONE,
+ DITHER_VERTERR,
+ DITHER_HALFTONE
+} ColorSpaceDitherMethod;
+
+struct _VideoConvert {
+ GstVideoInfo in_info;
+ GstVideoInfo out_info;
+
+ gint width;
+ gint height;
+
+ gint in_bits;
+ gint out_bits;
+ gint cmatrix[4][4];
+
+ ColorSpaceDitherMethod dither;
+
+ guint lines;
+
+ guint n_tmplines;
+ gpointer *tmplines;
+ guint16 *errline;
+
+ GstVideoChromaResample *upsample;
+ guint up_n_lines;
+ gint up_offset;
+ GstVideoChromaResample *downsample;
+ guint down_n_lines;
+ gint down_offset;
+
+ void (*convert) (VideoConvert *convert, GstVideoFrame *dest, const GstVideoFrame *src);
+ void (*matrix) (VideoConvert *convert, gpointer pixels);
+ void (*dither16) (VideoConvert *convert, guint16 * pixels, int j);
+
+};
+
+VideoConvert * videomixer_videoconvert_convert_new (GstVideoInfo *in_info,
+ GstVideoInfo *out_info);
+void videomixer_videoconvert_convert_free (VideoConvert * convert);
+
+void videomixer_videoconvert_convert_set_dither (VideoConvert * convert, int type);
+
+void videomixer_videoconvert_convert_convert (VideoConvert * convert,
+ GstVideoFrame *dest, const GstVideoFrame *src);
+
+
+G_END_DECLS
+
+#endif /* __GST_COLORSPACE_H__ */
diff --git a/gst/videomixer/videomixer2.c b/gst/videomixer/videomixer2.c
index c60759f81..46e856b56 100644
--- a/gst/videomixer/videomixer2.c
+++ b/gst/videomixer/videomixer2.c
@@ -86,6 +86,7 @@
#include "videomixer2.h"
#include "videomixer2pad.h"
+#include "videoconvert.h"
#ifdef DISABLE_ORC
#define orc_memset memset
diff --git a/gst/videomixer/videomixerorc.orc b/gst/videomixer/videomixerorc.orc
new file mode 100644
index 000000000..7ee7fef4a
--- /dev/null
+++ b/gst/videomixer/videomixerorc.orc
@@ -0,0 +1,1516 @@
+.function video_mixer_orc_splat_u32
+.dest 4 d1 guint32
+.param 4 p1 guint32
+
+copyl d1, p1
+
+.function video_mixer_orc_memcpy_u32
+.dest 4 d1 guint32
+.source 4 s1 guint32
+
+copyl d1, s1
+
+.function video_mixer_orc_blend_u8
+.flags 2d
+.dest 1 d1 guint8
+.source 1 s1 guint8
+.param 2 p1
+.temp 2 t1
+.temp 2 t2
+.const 1 c1 8
+
+convubw t1, d1
+convubw t2, s1
+subw t2, t2, t1
+mullw t2, t2, p1
+shlw t1, t1, c1
+addw t2, t1, t2
+shruw t2, t2, c1
+convsuswb d1, t2
+
+
+.function video_mixer_orc_blend_argb
+.flags 2d
+.dest 4 d guint8
+.source 4 s guint8
+.param 2 alpha
+.temp 4 t
+.temp 2 tw
+.temp 1 tb
+.temp 4 a
+.temp 8 d_wide
+.temp 8 s_wide
+.temp 8 a_wide
+.const 4 a_alpha 0x000000ff
+
+loadl t, s
+convlw tw, t
+convwb tb, tw
+splatbl a, tb
+x4 convubw a_wide, a
+x4 mullw a_wide, a_wide, alpha
+x4 shruw a_wide, a_wide, 8
+x4 convubw s_wide, t
+loadl t, d
+x4 convubw d_wide, t
+x4 subw s_wide, s_wide, d_wide
+x4 mullw s_wide, s_wide, a_wide
+x4 div255w s_wide, s_wide
+x4 addw d_wide, d_wide, s_wide
+x4 convwb t, d_wide
+orl t, t, a_alpha
+storel d, t
+
+.function video_mixer_orc_blend_bgra
+.flags 2d
+.dest 4 d guint8
+.source 4 s guint8
+.param 2 alpha
+.temp 4 t
+.temp 4 t2
+.temp 2 tw
+.temp 1 tb
+.temp 4 a
+.temp 8 d_wide
+.temp 8 s_wide
+.temp 8 a_wide
+.const 4 a_alpha 0xff000000
+
+loadl t, s
+shrul t2, t, 24
+convlw tw, t2
+convwb tb, tw
+splatbl a, tb
+x4 convubw a_wide, a
+x4 mullw a_wide, a_wide, alpha
+x4 shruw a_wide, a_wide, 8
+x4 convubw s_wide, t
+loadl t, d
+x4 convubw d_wide, t
+x4 subw s_wide, s_wide, d_wide
+x4 mullw s_wide, s_wide, a_wide
+x4 div255w s_wide, s_wide
+x4 addw d_wide, d_wide, s_wide
+x4 convwb t, d_wide
+orl t, t, a_alpha
+storel d, t
+
+
+.function video_mixer_orc_overlay_argb
+.flags 2d
+.dest 4 d guint8
+.source 4 s guint8
+.param 2 alpha
+.temp 4 t
+.temp 2 tw
+.temp 1 tb
+.temp 8 alpha_s
+.temp 8 alpha_s_inv
+.temp 8 alpha_d
+.temp 4 a
+.temp 8 d_wide
+.temp 8 s_wide
+.const 4 xfs 0xffffffff
+.const 4 a_alpha 0x000000ff
+.const 4 a_alpha_inv 0xffffff00
+
+# calc source alpha as alpha_s = alpha_s * alpha / 256
+loadl t, s
+convlw tw, t
+convwb tb, tw
+splatbl a, tb
+x4 convubw alpha_s, a
+x4 mullw alpha_s, alpha_s, alpha
+x4 shruw alpha_s, alpha_s, 8
+x4 convubw s_wide, t
+x4 mullw s_wide, s_wide, alpha_s
+
+# calc destination alpha as alpha_d = (255-alpha_s) * alpha_d / 255
+loadpl a, xfs
+x4 convubw alpha_s_inv, a
+x4 subw alpha_s_inv, alpha_s_inv, alpha_s
+loadl t, d
+convlw tw, t
+convwb tb, tw
+splatbl a, tb
+x4 convubw alpha_d, a
+x4 mullw alpha_d, alpha_d, alpha_s_inv
+x4 div255w alpha_d, alpha_d
+x4 convubw d_wide, t
+x4 mullw d_wide, d_wide, alpha_d
+
+# calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_d*(255-alpha_s)/255
+x4 addw d_wide, d_wide, s_wide
+
+# calc the final destination alpha_d = alpha_s + alpha_d * (255-alpha_s)/255
+x4 addw alpha_d, alpha_d, alpha_s
+
+# now normalize the pix_d by the final alpha to make it associative
+x4 divluw, d_wide, d_wide, alpha_d
+
+# pack the new alpha into the correct spot
+x4 convwb t, d_wide
+andl t, t, a_alpha_inv
+x4 convwb a, alpha_d
+andl a, a, a_alpha
+orl t, t, a
+storel d, t
+
+.function video_mixer_orc_overlay_bgra
+.flags 2d
+.dest 4 d guint8
+.source 4 s guint8
+.param 2 alpha
+.temp 4 t
+.temp 4 t2
+.temp 2 tw
+.temp 1 tb
+.temp 8 alpha_s
+.temp 8 alpha_s_inv
+.temp 8 alpha_d
+.temp 4 a
+.temp 8 d_wide
+.temp 8 s_wide
+.const 4 xfs 0xffffffff
+.const 4 a_alpha 0xff000000
+.const 4 a_alpha_inv 0x00ffffff
+
+# calc source alpha as alpha_s = alpha_s * alpha / 256
+loadl t, s
+shrul t2, t, 24
+convlw tw, t2
+convwb tb, tw
+splatbl a, tb
+x4 convubw alpha_s, a
+x4 mullw alpha_s, alpha_s, alpha
+x4 shruw alpha_s, alpha_s, 8
+x4 convubw s_wide, t
+x4 mullw s_wide, s_wide, alpha_s
+
+# calc destination alpha as alpha_d = (255-alpha_s) * alpha_d / 255
+loadpl a, xfs
+x4 convubw alpha_s_inv, a
+x4 subw alpha_s_inv, alpha_s_inv, alpha_s
+loadl t, d
+shrul t2, t, 24
+convlw tw, t2
+convwb tb, tw
+splatbl a, tb
+x4 convubw alpha_d, a
+x4 mullw alpha_d, alpha_d, alpha_s_inv
+x4 div255w alpha_d, alpha_d
+x4 convubw d_wide, t
+x4 mullw d_wide, d_wide, alpha_d
+
+# calc final pixel as pix_d = pix_s*alpha_s + pix_d*alpha_d*(255-alpha_s)/255
+x4 addw d_wide, d_wide, s_wide
+
+# calc the final destination alpha_d = alpha_s + alpha_d * (255-alpha_s)/255
+x4 addw alpha_d, alpha_d, alpha_s
+
+# now normalize the pix_d by the final alpha to make it associative
+x4 divluw, d_wide, d_wide, alpha_d
+
+# pack the new alpha into the correct spot
+x4 convwb t, d_wide
+andl t, t, a_alpha_inv
+x4 convwb a, alpha_d
+andl a, a, a_alpha
+orl t, t, a
+storel d, t
+
+# Videoconvert logic, copy from videomixer_videoconvert.
+# Remove that when videomixer_videoconvert lands in libgstvideo.
+
+.function videomixer_video_convert_orc_memcpy_2d
+.flags 2d
+.dest 1 d1 guint8
+.source 1 s1 guint8
+
+copyb d1, s1
+
+.function videomixer_video_convert_orc_convert_I420_UYVY
+.dest 4 d1 guint8
+.dest 4 d2 guint8
+.source 2 y1 guint8
+.source 2 y2 guint8
+.source 1 u guint8
+.source 1 v guint8
+.temp 2 uv
+
+mergebw uv, u, v
+x2 mergebw d1, uv, y1
+x2 mergebw d2, uv, y2
+
+
+.function videomixer_video_convert_orc_convert_I420_YUY2
+.dest 4 d1 guint8
+.dest 4 d2 guint8
+.source 2 y1 guint8
+.source 2 y2 guint8
+.source 1 u guint8
+.source 1 v guint8
+.temp 2 uv
+
+mergebw uv, u, v
+x2 mergebw d1, y1, uv
+x2 mergebw d2, y2, uv
+
+
+
+.function videomixer_video_convert_orc_convert_I420_AYUV
+.dest 4 d1 guint8
+.dest 4 d2 guint8
+.source 1 y1 guint8
+.source 1 y2 guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+.temp 1 tu
+.temp 1 tv
+
+loadupdb tu, u
+loadupdb tv, v
+mergebw uv, tu, tv
+mergebw ay, c255, y1
+mergewl d1, ay, uv
+mergebw ay, c255, y2
+mergewl d2, ay, uv
+
+
+.function videomixer_video_convert_orc_convert_YUY2_I420
+.dest 2 y1 guint8
+.dest 2 y2 guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 4 yuv1 guint8
+.source 4 yuv2 guint8
+.temp 2 t1
+.temp 2 t2
+.temp 2 ty
+
+x2 splitwb t1, ty, yuv1
+storew y1, ty
+x2 splitwb t2, ty, yuv2
+storew y2, ty
+x2 avgub t1, t1, t2
+splitwb v, u, t1
+
+
+.function videomixer_video_convert_orc_convert_UYVY_YUY2
+.flags 2d
+.dest 4 yuy2 guint8
+.source 4 uyvy guint8
+
+x2 swapw yuy2, uyvy
+
+
+.function videomixer_video_convert_orc_planar_chroma_420_422
+.flags 2d
+.dest 1 d1 guint8
+.dest 1 d2 guint8
+.source 1 s guint8
+
+copyb d1, s
+copyb d2, s
+
+
+.function videomixer_video_convert_orc_planar_chroma_420_444
+.flags 2d
+.dest 2 d1 guint8
+.dest 2 d2 guint8
+.source 1 s guint8
+.temp 2 t
+
+splatbw t, s
+storew d1, t
+storew d2, t
+
+
+.function videomixer_video_convert_orc_planar_chroma_422_444
+.flags 2d
+.dest 2 d1 guint8
+.source 1 s guint8
+.temp 2 t
+
+splatbw t, s
+storew d1, t
+
+
+.function videomixer_video_convert_orc_planar_chroma_444_422
+.flags 2d
+.dest 1 d guint8
+.source 2 s guint8
+.temp 1 t1
+.temp 1 t2
+
+splitwb t1, t2, s
+avgub d, t1, t2
+
+
+.function videomixer_video_convert_orc_planar_chroma_444_420
+.flags 2d
+.dest 1 d guint8
+.source 2 s1 guint8
+.source 2 s2 guint8
+.temp 2 t
+.temp 1 t1
+.temp 1 t2
+
+x2 avgub t, s1, s2
+splitwb t1, t2, t
+avgub d, t1, t2
+
+
+.function videomixer_video_convert_orc_planar_chroma_422_420
+.flags 2d
+.dest 1 d guint8
+.source 1 s1 guint8
+.source 1 s2 guint8
+
+avgub d, s1, s2
+
+
+.function videomixer_video_convert_orc_convert_YUY2_AYUV
+.flags 2d
+.dest 8 ayuv guint8
+.source 4 yuy2 guint8
+.const 2 c255 0xff
+.temp 2 yy
+.temp 2 uv
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitwb uv, yy, yuy2
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_convert_UYVY_AYUV
+.flags 2d
+.dest 8 ayuv guint8
+.source 4 uyvy guint8
+.const 2 c255 0xff
+.temp 2 yy
+.temp 2 uv
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitwb yy, uv, uyvy
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_convert_YUY2_Y42B
+.flags 2d
+.dest 2 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 4 yuy2 guint8
+.temp 2 uv
+
+x2 splitwb uv, y, yuy2
+splitwb v, u, uv
+
+
+.function videomixer_video_convert_orc_convert_UYVY_Y42B
+.flags 2d
+.dest 2 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 4 uyvy guint8
+.temp 2 uv
+
+x2 splitwb y, uv, uyvy
+splitwb v, u, uv
+
+
+.function videomixer_video_convert_orc_convert_YUY2_Y444
+.flags 2d
+.dest 2 y guint8
+.dest 2 uu guint8
+.dest 2 vv guint8
+.source 4 yuy2 guint8
+.temp 2 uv
+.temp 1 u
+.temp 1 v
+
+x2 splitwb uv, y, yuy2
+splitwb v, u, uv
+splatbw uu, u
+splatbw vv, v
+
+
+.function videomixer_video_convert_orc_convert_UYVY_Y444
+.flags 2d
+.dest 2 y guint8
+.dest 2 uu guint8
+.dest 2 vv guint8
+.source 4 uyvy guint8
+.temp 2 uv
+.temp 1 u
+.temp 1 v
+
+x2 splitwb y, uv, uyvy
+splitwb v, u, uv
+splatbw uu, u
+splatbw vv, v
+
+
+.function videomixer_video_convert_orc_convert_UYVY_I420
+.dest 2 y1 guint8
+.dest 2 y2 guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 4 yuv1 guint8
+.source 4 yuv2 guint8
+.temp 2 t1
+.temp 2 t2
+.temp 2 ty
+
+x2 splitwb ty, t1, yuv1
+storew y1, ty
+x2 splitwb ty, t2, yuv2
+storew y2, ty
+x2 avgub t1, t1, t2
+splitwb v, u, t1
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_I420
+.flags 2d
+.dest 2 y1 guint8
+.dest 2 y2 guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 8 ayuv1 guint8
+.source 8 ayuv2 guint8
+.temp 4 ay
+.temp 4 uv1
+.temp 4 uv2
+.temp 4 uv
+.temp 2 uu
+.temp 2 vv
+.temp 1 t1
+.temp 1 t2
+
+x2 splitlw uv1, ay, ayuv1
+x2 select1wb y1, ay
+x2 splitlw uv2, ay, ayuv2
+x2 select1wb y2, ay
+x4 avgub uv, uv1, uv2
+x2 splitwb vv, uu, uv
+splitwb t1, t2, uu
+avgub u, t1, t2
+splitwb t1, t2, vv
+avgub v, t1, t2
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_YUY2
+.flags 2d
+.dest 4 yuy2 guint8
+.source 8 ayuv guint8
+.temp 2 yy
+.temp 2 uv1
+.temp 2 uv2
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+x2 select1wb yy, ayay
+x2 mergebw yuy2, yy, uv1
+
+
+.function videomixer_video_convert_orc_convert_AYUV_UYVY
+.flags 2d
+.dest 4 yuy2 guint8
+.source 8 ayuv guint8
+.temp 2 yy
+.temp 2 uv1
+.temp 2 uv2
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+x2 select1wb yy, ayay
+x2 mergebw yuy2, uv1, yy
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_Y42B
+.flags 2d
+.dest 2 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 8 ayuv guint8
+.temp 4 ayay
+.temp 4 uvuv
+.temp 2 uv1
+.temp 2 uv2
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+splitwb v, u, uv1
+x2 select1wb y, ayay
+
+
+.function videomixer_video_convert_orc_convert_AYUV_Y444
+.flags 2d
+.dest 1 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 4 ayuv guint8
+.temp 2 ay
+.temp 2 uv
+
+splitlw uv, ay, ayuv
+splitwb v, u, uv
+select1wb y, ay
+
+
+.function videomixer_video_convert_orc_convert_Y42B_YUY2
+.flags 2d
+.dest 4 yuy2 guint8
+.source 2 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.temp 2 uv
+
+mergebw uv, u, v
+x2 mergebw yuy2, y, uv
+
+
+.function videomixer_video_convert_orc_convert_Y42B_UYVY
+.flags 2d
+.dest 4 uyvy guint8
+.source 2 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.temp 2 uv
+
+mergebw uv, u, v
+x2 mergebw uyvy, uv, y
+
+
+.function videomixer_video_convert_orc_convert_Y42B_AYUV
+.flags 2d
+.dest 8 ayuv guint8
+.source 2 yy guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+.temp 4 uvuv
+.temp 4 ayay
+
+mergebw uv, u, v
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_convert_Y444_YUY2
+.flags 2d
+.dest 4 yuy2 guint8
+.source 2 y guint8
+.source 2 u guint8
+.source 2 v guint8
+.temp 2 uv
+.temp 4 uvuv
+.temp 2 uv1
+.temp 2 uv2
+
+x2 mergebw uvuv, u, v
+splitlw uv1, uv2, uvuv
+x2 avgub uv, uv1, uv2
+x2 mergebw yuy2, y, uv
+
+
+.function videomixer_video_convert_orc_convert_Y444_UYVY
+.flags 2d
+.dest 4 uyvy guint8
+.source 2 y guint8
+.source 2 u guint8
+.source 2 v guint8
+.temp 2 uv
+.temp 4 uvuv
+.temp 2 uv1
+.temp 2 uv2
+
+x2 mergebw uvuv, u, v
+splitlw uv1, uv2, uvuv
+x2 avgub uv, uv1, uv2
+x2 mergebw uyvy, uv, y
+
+
+.function videomixer_video_convert_orc_convert_Y444_AYUV
+.flags 2d
+.dest 4 ayuv guint8
+.source 1 yy guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+
+mergebw uv, u, v
+mergebw ay, c255, yy
+mergewl ayuv, ay, uv
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_ARGB
+.flags 2d
+.dest 4 argb guint8
+.source 4 ayuv guint8
+.temp 2 t1
+.temp 2 t2
+.temp 1 a
+.temp 1 y
+.temp 1 u
+.temp 1 v
+.temp 2 wy
+.temp 2 wu
+.temp 2 wv
+.temp 2 wr
+.temp 2 wg
+.temp 2 wb
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 4 x
+.const 1 c8 8
+
+x4 subb x, ayuv, 128
+splitlw t1, t2, x
+splitwb y, a, t2
+splitwb v, u, t1
+convsbw wy, y
+convsbw wu, u
+convsbw wv, v
+
+mullw t1, wy, 42
+shrsw t1, t1, c8
+addssw wy, wy, t1
+
+addssw wr, wy, wv
+mullw t1, wv, 103
+shrsw t1, t1, c8
+subssw wr, wr, t1
+addssw wr, wr, wv
+
+addssw wb, wy, wu
+addssw wb, wb, wu
+mullw t1, wu, 4
+shrsw t1, t1, c8
+addssw wb, wb, t1
+
+mullw t1, wu, 100
+shrsw t1, t1, c8
+subssw wg, wy, t1
+mullw t1, wv, 104
+shrsw t1, t1, c8
+subssw wg, wg, t1
+subssw wg, wg, t1
+
+convssswb r, wr
+convssswb g, wg
+convssswb b, wb
+
+mergebw t1, a, r
+mergebw t2, g, b
+mergewl x, t1, t2
+x4 addb argb, x, 128
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_BGRA
+.flags 2d
+.dest 4 argb guint8
+.source 4 ayuv guint8
+.temp 2 t1
+.temp 2 t2
+.temp 1 a
+.temp 1 y
+.temp 1 u
+.temp 1 v
+.temp 2 wy
+.temp 2 wu
+.temp 2 wv
+.temp 2 wr
+.temp 2 wg
+.temp 2 wb
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 4 x
+.const 1 c8 8
+
+x4 subb x, ayuv, 128
+splitlw t1, t2, x
+splitwb y, a, t2
+splitwb v, u, t1
+convsbw wy, y
+convsbw wu, u
+convsbw wv, v
+
+mullw t1, wy, 42
+shrsw t1, t1, c8
+addssw wy, wy, t1
+
+addssw wr, wy, wv
+mullw t1, wv, 103
+shrsw t1, t1, c8
+subssw wr, wr, t1
+addssw wr, wr, wv
+
+addssw wb, wy, wu
+addssw wb, wb, wu
+mullw t1, wu, 4
+shrsw t1, t1, c8
+addssw wb, wb, t1
+
+mullw t1, wu, 100
+shrsw t1, t1, c8
+subssw wg, wy, t1
+mullw t1, wv, 104
+shrsw t1, t1, c8
+subssw wg, wg, t1
+subssw wg, wg, t1
+
+convssswb r, wr
+convssswb g, wg
+convssswb b, wb
+
+mergebw t1, b, g
+mergebw t2, r, a
+mergewl x, t1, t2
+x4 addb argb, x, 128
+
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_ABGR
+.flags 2d
+.dest 4 argb guint8
+.source 4 ayuv guint8
+.temp 2 t1
+.temp 2 t2
+.temp 1 a
+.temp 1 y
+.temp 1 u
+.temp 1 v
+.temp 2 wy
+.temp 2 wu
+.temp 2 wv
+.temp 2 wr
+.temp 2 wg
+.temp 2 wb
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 4 x
+.const 1 c8 8
+
+x4 subb x, ayuv, 128
+splitlw t1, t2, x
+splitwb y, a, t2
+splitwb v, u, t1
+convsbw wy, y
+convsbw wu, u
+convsbw wv, v
+
+mullw t1, wy, 42
+shrsw t1, t1, c8
+addssw wy, wy, t1
+
+addssw wr, wy, wv
+mullw t1, wv, 103
+shrsw t1, t1, c8
+subssw wr, wr, t1
+addssw wr, wr, wv
+
+addssw wb, wy, wu
+addssw wb, wb, wu
+mullw t1, wu, 4
+shrsw t1, t1, c8
+addssw wb, wb, t1
+
+mullw t1, wu, 100
+shrsw t1, t1, c8
+subssw wg, wy, t1
+mullw t1, wv, 104
+shrsw t1, t1, c8
+subssw wg, wg, t1
+subssw wg, wg, t1
+
+convssswb r, wr
+convssswb g, wg
+convssswb b, wb
+
+mergebw t1, a, b
+mergebw t2, g, r
+mergewl x, t1, t2
+x4 addb argb, x, 128
+
+
+
+.function videomixer_video_convert_orc_convert_AYUV_RGBA
+.flags 2d
+.dest 4 argb guint8
+.source 4 ayuv guint8
+.temp 2 t1
+.temp 2 t2
+.temp 1 a
+.temp 1 y
+.temp 1 u
+.temp 1 v
+.temp 2 wy
+.temp 2 wu
+.temp 2 wv
+.temp 2 wr
+.temp 2 wg
+.temp 2 wb
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 4 x
+.const 1 c8 8
+
+x4 subb x, ayuv, 128
+splitlw t1, t2, x
+splitwb y, a, t2
+splitwb v, u, t1
+convsbw wy, y
+convsbw wu, u
+convsbw wv, v
+
+mullw t1, wy, 42
+shrsw t1, t1, c8
+addssw wy, wy, t1
+
+addssw wr, wy, wv
+mullw t1, wv, 103
+shrsw t1, t1, c8
+subssw wr, wr, t1
+addssw wr, wr, wv
+
+addssw wb, wy, wu
+addssw wb, wb, wu
+mullw t1, wu, 4
+shrsw t1, t1, c8
+addssw wb, wb, t1
+
+mullw t1, wu, 100
+shrsw t1, t1, c8
+subssw wg, wy, t1
+mullw t1, wv, 104
+shrsw t1, t1, c8
+subssw wg, wg, t1
+subssw wg, wg, t1
+
+convssswb r, wr
+convssswb g, wg
+convssswb b, wb
+
+mergebw t1, r, g
+mergebw t2, b, a
+mergewl x, t1, t2
+x4 addb argb, x, 128
+
+
+
+.function videomixer_video_convert_orc_convert_I420_BGRA
+.dest 4 argb guint8
+.source 1 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.temp 2 t1
+.temp 2 t2
+.temp 1 t3
+.temp 2 wy
+.temp 2 wu
+.temp 2 wv
+.temp 2 wr
+.temp 2 wg
+.temp 2 wb
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 4 x
+.const 1 c8 8
+.const 1 c128 128
+
+subb t3, y, c128
+convsbw wy, t3
+loadupib t3, u
+subb t3, t3, c128
+convsbw wu, t3
+loadupib t3, v
+subb t3, t3, c128
+convsbw wv, t3
+
+mullw t1, wy, 42
+shrsw t1, t1, c8
+addssw wy, wy, t1
+
+addssw wr, wy, wv
+mullw t1, wv, 103
+shrsw t1, t1, c8
+subssw wr, wr, t1
+addssw wr, wr, wv
+
+addssw wb, wy, wu
+addssw wb, wb, wu
+mullw t1, wu, 4
+shrsw t1, t1, c8
+addssw wb, wb, t1
+
+mullw t1, wu, 100
+shrsw t1, t1, c8
+subssw wg, wy, t1
+mullw t1, wv, 104
+shrsw t1, t1, c8
+subssw wg, wg, t1
+subssw wg, wg, t1
+
+convssswb r, wr
+convssswb g, wg
+convssswb b, wb
+
+mergebw t1, b, g
+mergebw t2, r, 255
+mergewl x, t1, t2
+x4 addb argb, x, c128
+
+
+
+.function videomixer_video_convert_orc_convert_I420_BGRA_avg
+.dest 4 argb guint8
+.source 1 y guint8
+.source 1 u1 guint8
+.source 1 u2 guint8
+.source 1 v1 guint8
+.source 1 v2 guint8
+.temp 2 t1
+.temp 2 t2
+.temp 1 t3
+.temp 1 t4
+.temp 2 wy
+.temp 2 wu
+.temp 2 wv
+.temp 2 wr
+.temp 2 wg
+.temp 2 wb
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 4 x
+.const 1 c8 8
+.const 1 c128 128
+
+subb t3, y, c128
+convsbw wy, t3
+loadupib t3, u1
+loadupib t4, u2
+avgub t3, t3, t4
+subb t3, t3, c128
+convsbw wu, t3
+loadupib t3, v1
+loadupib t4, v2
+avgub t3, t3, t4
+subb t3, t3, c128
+convsbw wv, t3
+
+mullw t1, wy, 42
+shrsw t1, t1, c8
+addssw wy, wy, t1
+
+addssw wr, wy, wv
+mullw t1, wv, 103
+shrsw t1, t1, c8
+subssw wr, wr, t1
+addssw wr, wr, wv
+
+addssw wb, wy, wu
+addssw wb, wb, wu
+mullw t1, wu, 4
+shrsw t1, t1, c8
+addssw wb, wb, t1
+
+mullw t1, wu, 100
+shrsw t1, t1, c8
+subssw wg, wy, t1
+mullw t1, wv, 104
+shrsw t1, t1, c8
+subssw wg, wg, t1
+subssw wg, wg, t1
+
+convssswb r, wr
+convssswb g, wg
+convssswb b, wb
+
+mergebw t1, b, g
+mergebw t2, r, 255
+mergewl x, t1, t2
+x4 addb argb, x, c128
+
+
+
+.function videomixer_video_convert_orc_getline_I420
+.dest 4 d guint8
+.source 1 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+.temp 1 tu
+.temp 1 tv
+
+loadupdb tu, u
+loadupdb tv, v
+mergebw uv, tu, tv
+mergebw ay, c255, y
+mergewl d, ay, uv
+
+.function videomixer_video_convert_orc_getline_YUV9
+.dest 8 d guint8
+.source 2 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 tuv
+.temp 4 ay
+.temp 4 uv
+.temp 1 tu
+.temp 1 tv
+
+loadupdb tu, u
+loadupdb tv, v
+mergebw tuv, tu, tv
+mergewl uv, tuv, tuv
+x2 mergebw ay, c255, y
+x2 mergewl d, ay, uv
+
+.function videomixer_video_convert_orc_getline_YUY2
+.dest 8 ayuv guint8
+.source 4 yuy2 guint8
+.const 2 c255 0xff
+.temp 2 yy
+.temp 2 uv
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitwb uv, yy, yuy2
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_getline_UYVY
+.dest 8 ayuv guint8
+.source 4 uyvy guint8
+.const 2 c255 0xff
+.temp 2 yy
+.temp 2 uv
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitwb yy, uv, uyvy
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_getline_YVYU
+.dest 8 ayuv guint8
+.source 4 uyvy guint8
+.const 2 c255 0xff
+.temp 2 yy
+.temp 2 uv
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitwb uv, yy, uyvy
+swapw uv, uv
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_getline_Y42B
+.dest 8 ayuv guint8
+.source 2 yy guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+.temp 4 uvuv
+.temp 4 ayay
+
+mergebw uv, u, v
+x2 mergebw ayay, c255, yy
+mergewl uvuv, uv, uv
+x2 mergewl ayuv, ayay, uvuv
+
+
+.function videomixer_video_convert_orc_getline_Y444
+.dest 4 ayuv guint8
+.source 1 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+
+mergebw uv, u, v
+mergebw ay, c255, y
+mergewl ayuv, ay, uv
+
+
+.function videomixer_video_convert_orc_getline_Y800
+.dest 4 ayuv guint8
+.source 1 y guint8
+.const 1 c255 255
+.const 2 c0x8080 0x8080
+.temp 2 ay
+
+mergebw ay, c255, y
+mergewl ayuv, ay, c0x8080
+
+.function videomixer_video_convert_orc_getline_Y16
+.dest 4 ayuv guint8
+.source 2 y guint8
+.const 1 c255 255
+.const 2 c0x8080 0x8080
+.temp 2 ay
+.temp 1 yb
+
+convhwb yb, y
+mergebw ay, c255, yb
+mergewl ayuv, ay, c0x8080
+
+.function videomixer_video_convert_orc_getline_BGRA
+.dest 4 argb guint8
+.source 4 bgra guint8
+
+swapl argb, bgra
+
+
+.function videomixer_video_convert_orc_getline_ABGR
+.dest 4 argb guint8
+.source 4 abgr guint8
+.temp 1 a
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 2 gr
+.temp 2 ab
+.temp 2 ar
+.temp 2 gb
+
+splitlw gr, ab, abgr
+splitwb r, g, gr
+splitwb b, a, ab
+mergebw ar, a, r
+mergebw gb, g, b
+mergewl argb, ar, gb
+
+
+.function videomixer_video_convert_orc_getline_RGBA
+.dest 4 argb guint8
+.source 4 rgba guint8
+.temp 1 a
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 2 rg
+.temp 2 ba
+.temp 2 ar
+.temp 2 gb
+
+splitlw ba, rg, rgba
+splitwb g, r, rg
+splitwb a, b, ba
+mergebw ar, a, r
+mergebw gb, g, b
+mergewl argb, ar, gb
+
+
+.function videomixer_video_convert_orc_getline_NV12
+.dest 8 d guint8
+.source 2 y guint8
+.source 2 uv guint8
+.const 1 c255 255
+.temp 4 ay
+.temp 4 uvuv
+
+mergewl uvuv, uv, uv
+x2 mergebw ay, c255, y
+x2 mergewl d, ay, uvuv
+
+
+.function videomixer_video_convert_orc_getline_NV21
+.dest 8 d guint8
+.source 2 y guint8
+.source 2 vu guint8
+.const 1 c255 255
+.temp 2 uv
+.temp 4 ay
+.temp 4 uvuv
+
+swapw uv, vu
+mergewl uvuv, uv, uv
+x2 mergebw ay, c255, y
+x2 mergewl d, ay, uvuv
+
+.function videomixer_video_convert_orc_getline_A420
+.dest 4 d guint8
+.source 1 y guint8
+.source 1 u guint8
+.source 1 v guint8
+.source 1 a guint8
+.temp 2 uv
+.temp 2 ay
+.temp 1 tu
+.temp 1 tv
+
+loadupdb tu, u
+loadupdb tv, v
+mergebw uv, tu, tv
+mergebw ay, a, y
+mergewl d, ay, uv
+
+.function videomixer_video_convert_orc_putline_I420
+.dest 2 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 8 ayuv guint8
+.temp 4 ay
+.temp 4 uv
+.temp 2 uu
+.temp 2 vv
+.temp 1 t1
+.temp 1 t2
+
+x2 splitlw uv, ay, ayuv
+x2 select1wb y, ay
+x2 splitwb vv, uu, uv
+splitwb t1, t2, uu
+avgub u, t1, t2
+splitwb t1, t2, vv
+avgub v, t1, t2
+
+
+
+.function videomixer_video_convert_orc_putline_YUY2
+.dest 4 yuy2 guint8
+.source 8 ayuv guint8
+.temp 2 yy
+.temp 2 uv1
+.temp 2 uv2
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+x2 select1wb yy, ayay
+x2 mergebw yuy2, yy, uv1
+
+
+.function videomixer_video_convert_orc_putline_YVYU
+.dest 4 yuy2 guint8
+.source 8 ayuv guint8
+.temp 2 yy
+.temp 2 uv1
+.temp 2 uv2
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+x2 select1wb yy, ayay
+swapw uv1, uv1
+x2 mergebw yuy2, yy, uv1
+
+
+.function videomixer_video_convert_orc_putline_UYVY
+.dest 4 yuy2 guint8
+.source 8 ayuv guint8
+.temp 2 yy
+.temp 2 uv1
+.temp 2 uv2
+.temp 4 ayay
+.temp 4 uvuv
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+x2 select1wb yy, ayay
+x2 mergebw yuy2, uv1, yy
+
+
+
+.function videomixer_video_convert_orc_putline_Y42B
+.dest 2 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 8 ayuv guint8
+.temp 4 ayay
+.temp 4 uvuv
+.temp 2 uv1
+.temp 2 uv2
+
+x2 splitlw uvuv, ayay, ayuv
+splitlw uv1, uv2, uvuv
+x2 avgub uv1, uv1, uv2
+splitwb v, u, uv1
+x2 select1wb y, ayay
+
+
+.function videomixer_video_convert_orc_putline_Y444
+.dest 1 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.source 4 ayuv guint8
+.temp 2 ay
+.temp 2 uv
+
+splitlw uv, ay, ayuv
+splitwb v, u, uv
+select1wb y, ay
+
+
+.function videomixer_video_convert_orc_putline_Y800
+.dest 1 y guint8
+.source 4 ayuv guint8
+.temp 2 ay
+
+select0lw ay, ayuv
+select1wb y, ay
+
+.function videomixer_video_convert_orc_putline_Y16
+.dest 2 y guint8
+.source 4 ayuv guint8
+.temp 2 ay
+.temp 1 yb
+
+select0lw ay, ayuv
+select1wb yb, ay
+convubw ay, yb
+shlw y, ay, 8
+
+.function videomixer_video_convert_orc_putline_BGRA
+.dest 4 bgra guint8
+.source 4 argb guint8
+
+swapl bgra, argb
+
+
+.function videomixer_video_convert_orc_putline_ABGR
+.dest 4 abgr guint8
+.source 4 argb guint8
+.temp 1 a
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 2 gr
+.temp 2 ab
+.temp 2 ar
+.temp 2 gb
+
+splitlw gb, ar, argb
+splitwb b, g, gb
+splitwb r, a, ar
+mergebw ab, a, b
+mergebw gr, g, r
+mergewl abgr, ab, gr
+
+
+.function videomixer_video_convert_orc_putline_RGBA
+.dest 4 rgba guint8
+.source 4 argb guint8
+.temp 1 a
+.temp 1 r
+.temp 1 g
+.temp 1 b
+.temp 2 rg
+.temp 2 ba
+.temp 2 ar
+.temp 2 gb
+
+splitlw gb, ar, argb
+splitwb b, g, gb
+splitwb r, a, ar
+mergebw ba, b, a
+mergebw rg, r, g
+mergewl rgba, rg, ba
+
+
+.function videomixer_video_convert_orc_putline_NV12
+.dest 2 y guint8
+.dest 2 uv guint8
+.source 8 ayuv guint8
+.temp 4 ay
+.temp 4 uvuv
+.temp 2 uv1
+.temp 2 uv2
+
+x2 splitlw uvuv, ay, ayuv
+x2 select1wb y, ay
+splitlw uv1, uv2, uvuv
+x2 avgub uv, uv1, uv2
+
+
+.function videomixer_video_convert_orc_putline_NV21
+.dest 2 y guint8
+.dest 2 vu guint8
+.source 8 ayuv guint8
+.temp 4 ay
+.temp 4 uvuv
+.temp 2 uv1
+.temp 2 uv2
+.temp 2 uv
+
+x2 splitlw uvuv, ay, ayuv
+x2 select1wb y, ay
+splitlw uv1, uv2, uvuv
+x2 avgub uv, uv1, uv2
+swapw vu, uv
+
+.function videomixer_video_convert_orc_putline_A420
+.dest 2 y guint8
+.dest 1 u guint8
+.dest 1 v guint8
+.dest 2 a guint8
+.source 8 ayuv guint8
+.temp 4 ay
+.temp 4 uv
+.temp 2 uu
+.temp 2 vv
+.temp 1 t1
+.temp 1 t2
+
+x2 splitlw uv, ay, ayuv
+x2 select1wb y, ay
+x2 select0wb a, ay
+x2 splitwb vv, uu, uv
+splitwb t1, t2, uu
+avgub u, t1, t2
+splitwb t1, t2, vv
+avgub v, t1, t2