summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-07-10 19:34:41 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-07-10 19:35:49 +0200
commit0bf61ecfaf28bb72d2b4cdd20295e8677eef41ed (patch)
treecdc0e0d6093aed4ceab1fedd06bc1e06f3d50062
parentbbcb4f8f1501bcb442f48cc1cf1f315a0b18064b (diff)
videomixer: Add RGB, BGR, xRGB, RGBx, xBGR, BGRx support
-rw-r--r--gst/videomixer/Makefile.am2
-rw-r--r--gst/videomixer/blend_rgb.c156
-rw-r--r--gst/videomixer/videomixer.c83
3 files changed, 238 insertions, 3 deletions
diff --git a/gst/videomixer/Makefile.am b/gst/videomixer/Makefile.am
index f3a5a1027..7c6e1ded4 100644
--- a/gst/videomixer/Makefile.am
+++ b/gst/videomixer/Makefile.am
@@ -1,6 +1,6 @@
plugin_LTLIBRARIES = libgstvideomixer.la
-libgstvideomixer_la_SOURCES = videomixer.c blend_ayuv.c blend_bgra.c blend_i420.c
+libgstvideomixer_la_SOURCES = videomixer.c blend_ayuv.c blend_bgra.c blend_i420.c blend_rgb.c
libgstvideomixer_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstvideomixer_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(GST_PLUGINS_BASE_CFLAGS) -lgstvideo-@GST_MAJORMINOR@
libgstvideomixer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
diff --git a/gst/videomixer/blend_rgb.c b/gst/videomixer/blend_rgb.c
new file mode 100644
index 000000000..b580081f9
--- /dev/null
+++ b/gst/videomixer/blend_rgb.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2009 Alex Ugarte <augarte@vicomtech.org>
+ * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#include <gst/gst.h>
+#include <string.h>
+#include "videomixer.h"
+
+#define BLEND_NORMAL(R1,G1,B1,R2,G2,B2,alpha,R,G,B) \
+ R = ((R1*(255-alpha))+(R2*alpha))>>8; \
+ G = ((G1*(255-alpha))+(G2*alpha))>>8; \
+ B = ((B1*(255-alpha))+(B2*alpha))>>8;
+
+#define BLEND_MODE BLEND_NORMAL
+
+#define CREATE_FUNCTIONS(name, bpp, r, g, b) \
+void \
+gst_videomixer_blend_##name##_##name (guint8 * src, gint xpos, gint ypos, \
+ gint src_width, gint src_height, gdouble src_alpha, \
+ guint8 * dest, gint dest_width, gint dest_height) \
+{ \
+ gint b_alpha; \
+ gint i, j; \
+ gint src_stride, dest_stride; \
+ gint src_add, dest_add; \
+ gint R, G, B; \
+ \
+ src_stride = GST_ROUND_UP_4 (src_width * bpp); \
+ dest_stride = GST_ROUND_UP_4 (dest_width * bpp); \
+ \
+ b_alpha = (gint) (src_alpha * 255); \
+ \
+ /* adjust src pointers for negative sizes */ \
+ if (xpos < 0) { \
+ src += -xpos * bpp; \
+ src_width -= -xpos; \
+ xpos = 0; \
+ } \
+ if (ypos < 0) { \
+ src += -ypos * src_stride; \
+ src_height -= -ypos; \
+ ypos = 0; \
+ } \
+ /* adjust width/height if the src is bigger than dest */ \
+ if (xpos + src_width > dest_width) { \
+ src_width = dest_width - xpos; \
+ } \
+ if (ypos + src_height > dest_height) { \
+ src_height = dest_height - ypos; \
+ } \
+ \
+ src_add = src_stride - (bpp * src_width); \
+ dest_add = dest_stride - (bpp * src_width); \
+ \
+ dest = dest + bpp * xpos + (ypos * dest_stride); \
+ /* If it's completely transparent... we just return */ \
+ if (G_UNLIKELY (src_alpha == 0.0)) { \
+ GST_INFO ("Fast copy (alpha == 0.0)"); \
+ return; \
+ } \
+ \
+ /* If it's completely opaque, we do a fast copy */ \
+ if (G_UNLIKELY (src_alpha == 1.0)) { \
+ GST_INFO ("Fast copy (alpha == 1.0)"); \
+ for (i = 0; i < src_height; i++) { \
+ memcpy (dest, src, bpp * src_width); \
+ src += src_stride; \
+ dest += dest_stride; \
+ } \
+ return; \
+ } \
+ \
+ /* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */ \
+ for (i = 0; i < src_height; i++) { \
+ for (j = 0; j < src_width; j++) { \
+ BLEND_MODE (dest[r], dest[g], dest[b], src[r], src[g], src[b], \
+ b_alpha, R, G, B); \
+ dest[r] = R; \
+ dest[g] = G; \
+ dest[b] = B; \
+ \
+ src += bpp; \
+ dest += bpp; \
+ } \
+ src += src_add; \
+ dest += dest_add; \
+ } \
+} \
+\
+/* fill a buffer with a checkerboard pattern */ \
+void \
+gst_videomixer_fill_##name##_checker (guint8 * dest, gint width, gint height) \
+{ \
+ gint i, j; \
+ static const int tab[] = { 80, 160, 80, 160 }; \
+ gint dest_add = GST_ROUND_UP_4 (width * bpp) - width * bpp; \
+ \
+ for (i = 0; i < height; i++) { \
+ for (j = 0; j < width; j++) { \
+ dest[r] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* red */ \
+ dest[g] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* green */ \
+ dest[b] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* blue */ \
+ dest += bpp; \
+ } \
+ dest += dest_add; \
+ } \
+} \
+\
+void \
+gst_videomixer_fill_##name##_color (guint8 * dest, gint width, gint height, \
+ gint colY, gint colU, gint colV) \
+{ \
+ gint red, green, blue; \
+ gint i, j; \
+ gint dest_add = GST_ROUND_UP_4 (width * bpp) - width * bpp; \
+ \
+ red = CLAMP (1.164 * (colY - 16) + 1.596 * (colV - 128), 0, 255); \
+ green = \
+ CLAMP (1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128), \
+ 0, 255); \
+ blue = CLAMP (1.164 * (colY - 16) + 2.018 * (colU - 128), 0, 255); \
+ \
+ for (i = 0; i < height; i++) { \
+ for (j = 0; j < width; j++) { \
+ dest[r] = red; \
+ dest[g] = green; \
+ dest[b] = blue; \
+ dest += bpp; \
+ } \
+ dest += dest_add; \
+ } \
+}
+
+CREATE_FUNCTIONS (rgb, 3, 0, 1, 2);
+CREATE_FUNCTIONS (bgr, 3, 2, 1, 0);
+CREATE_FUNCTIONS (xrgb, 4, 1, 2, 3);
+CREATE_FUNCTIONS (xbgr, 4, 3, 2, 1);
+CREATE_FUNCTIONS (rgbx, 4, 0, 1, 2);
+CREATE_FUNCTIONS (bgrx, 4, 2, 1, 0);
diff --git a/gst/videomixer/videomixer.c b/gst/videomixer/videomixer.c
index cd4631488..61409bf00 100644
--- a/gst/videomixer/videomixer.c
+++ b/gst/videomixer/videomixer.c
@@ -116,6 +116,43 @@ void gst_videomixer_blend_argb_argb (guint8 * src, gint xpos, gint ypos,
void gst_videomixer_fill_argb_checker (guint8 * dest, gint width, gint height);
void gst_videomixer_fill_argb_color (guint8 * dest, gint width, gint height,
gint colY, gint colU, gint colV);
+/* RGB function definitions see file: blend_rgb.c */
+void gst_videomixer_blend_rgb_rgb (guint8 * src, gint xpos, gint ypos,
+ gint src_width, gint src_height, gdouble src_alpha,
+ guint8 * dest, gint dest_width, gint dest_height);
+void gst_videomixer_fill_rgb_checker (guint8 * dest, gint width, gint height);
+void gst_videomixer_fill_rgb_color (guint8 * dest, gint width, gint height,
+ gint colY, gint colU, gint colV);
+void gst_videomixer_blend_bgr_bgr (guint8 * src, gint xpos, gint ypos,
+ gint src_width, gint src_height, gdouble src_alpha,
+ guint8 * dest, gint dest_width, gint dest_height);
+void gst_videomixer_fill_bgr_checker (guint8 * dest, gint width, gint height);
+void gst_videomixer_fill_bgr_color (guint8 * dest, gint width, gint height,
+ gint colY, gint colU, gint colV);
+void gst_videomixer_blend_xrgb_xrgb (guint8 * src, gint xpos, gint ypos,
+ gint src_width, gint src_height, gdouble src_alpha,
+ guint8 * dest, gint dest_width, gint dest_height);
+void gst_videomixer_fill_xrgb_checker (guint8 * dest, gint width, gint height);
+void gst_videomixer_fill_xrgb_color (guint8 * dest, gint width, gint height,
+ gint colY, gint colU, gint colV);
+void gst_videomixer_blend_xbgr_xbgr (guint8 * src, gint xpos, gint ypos,
+ gint src_width, gint src_height, gdouble src_alpha,
+ guint8 * dest, gint dest_width, gint dest_height);
+void gst_videomixer_fill_xbgr_checker (guint8 * dest, gint width, gint height);
+void gst_videomixer_fill_xbgr_color (guint8 * dest, gint width, gint height,
+ gint colY, gint colU, gint colV);
+void gst_videomixer_blend_rgbx_rgbx (guint8 * src, gint xpos, gint ypos,
+ gint src_width, gint src_height, gdouble src_alpha,
+ guint8 * dest, gint dest_width, gint dest_height);
+void gst_videomixer_fill_rgbx_checker (guint8 * dest, gint width, gint height);
+void gst_videomixer_fill_rgbx_color (guint8 * dest, gint width, gint height,
+ gint colY, gint colU, gint colV);
+void gst_videomixer_blend_bgrx_bgrx (guint8 * src, gint xpos, gint ypos,
+ gint src_width, gint src_height, gdouble src_alpha,
+ guint8 * dest, gint dest_width, gint dest_height);
+void gst_videomixer_fill_bgrx_checker (guint8 * dest, gint width, gint height);
+void gst_videomixer_fill_bgrx_color (guint8 * dest, gint width, gint height,
+ gint colY, gint colU, gint colV);
/*I420 function definitions see file: blend_i420.c*/
void gst_videomixer_blend_i420_i420 (guint8 * src, gint xpos, gint ypos,
gint src_width, gint src_height, gdouble src_alpha,
@@ -450,14 +487,20 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
- GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_YUV ("I420"))
+ GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_YUV ("I420")
+ ";" GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR
+ ";" GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR
+ ";" GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx)
);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
GST_PAD_SINK,
GST_PAD_REQUEST,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
- GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_YUV ("I420"))
+ GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_YUV ("I420")
+ ";" GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR
+ ";" GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR
+ ";" GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx)
);
static void gst_videomixer_finalize (GObject * object);
@@ -940,6 +983,42 @@ gst_videomixer_setcaps (GstPad * pad, GstCaps * caps)
mixer->fill_color = gst_videomixer_fill_argb_color;
ret = TRUE;
break;
+ case GST_VIDEO_FORMAT_RGB:
+ mixer->blend = gst_videomixer_blend_rgb_rgb;
+ mixer->fill_checker = gst_videomixer_fill_rgb_checker;
+ mixer->fill_color = gst_videomixer_fill_rgb_color;
+ ret = TRUE;
+ break;
+ case GST_VIDEO_FORMAT_BGR:
+ mixer->blend = gst_videomixer_blend_bgr_bgr;
+ mixer->fill_checker = gst_videomixer_fill_bgr_checker;
+ mixer->fill_color = gst_videomixer_fill_bgr_color;
+ ret = TRUE;
+ break;
+ case GST_VIDEO_FORMAT_xRGB:
+ mixer->blend = gst_videomixer_blend_xrgb_xrgb;
+ mixer->fill_checker = gst_videomixer_fill_xrgb_checker;
+ mixer->fill_color = gst_videomixer_fill_xrgb_color;
+ ret = TRUE;
+ break;
+ case GST_VIDEO_FORMAT_xBGR:
+ mixer->blend = gst_videomixer_blend_xbgr_xbgr;
+ mixer->fill_checker = gst_videomixer_fill_xbgr_checker;
+ mixer->fill_color = gst_videomixer_fill_xbgr_color;
+ ret = TRUE;
+ break;
+ case GST_VIDEO_FORMAT_RGBx:
+ mixer->blend = gst_videomixer_blend_rgbx_rgbx;
+ mixer->fill_checker = gst_videomixer_fill_rgbx_checker;
+ mixer->fill_color = gst_videomixer_fill_rgbx_color;
+ ret = TRUE;
+ break;
+ case GST_VIDEO_FORMAT_BGRx:
+ mixer->blend = gst_videomixer_blend_bgrx_bgrx;
+ mixer->fill_checker = gst_videomixer_fill_bgrx_checker;
+ mixer->fill_color = gst_videomixer_fill_bgrx_color;
+ ret = TRUE;
+ break;
default:
break;
}