summaryrefslogtreecommitdiffstats
path: root/gst/videomixer
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-05-28 13:04:51 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-05-28 13:04:51 +0200
commitf66906e89109f83bc29b23e201f9259375933fd2 (patch)
tree34611ed5ce854cce3b96b75185f01e96800a173e /gst/videomixer
parent82abbeaf4f69f22191a28c72a99c0093835edb11 (diff)
videomixer: Blend BGRA ourselves instead of using Cairo
Diffstat (limited to 'gst/videomixer')
-rw-r--r--gst/videomixer/Makefile.am4
-rw-r--r--gst/videomixer/blend_bgra.c85
2 files changed, 61 insertions, 28 deletions
diff --git a/gst/videomixer/Makefile.am b/gst/videomixer/Makefile.am
index c5669b8f..392c9b75 100644
--- a/gst/videomixer/Makefile.am
+++ b/gst/videomixer/Makefile.am
@@ -1,8 +1,8 @@
plugin_LTLIBRARIES = libgstvideomixer.la
libgstvideomixer_la_SOURCES = videomixer.c blend_ayuv.c blend_bgra.c blend_i420.c
-libgstvideomixer_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(CAIRO_CFLAGS)
-libgstvideomixer_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(CAIRO_LIBS)
+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)
libgstvideomixer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstvideomixer_la_LIBTOOLFLAGS = --tag=disable-static
diff --git a/gst/videomixer/blend_bgra.c b/gst/videomixer/blend_bgra.c
index 3fc44dd4..f3d58f39 100644
--- a/gst/videomixer/blend_bgra.c
+++ b/gst/videomixer/blend_bgra.c
@@ -19,41 +19,74 @@
#include <gst/gst.h>
-#include <cairo.h>
+#define BLEND_NORMAL(B1,G1,R1,B2,G2,R2,B,G,R,alpha) \
+ B = ((B1*(255-alpha))+(B2*alpha))>>8; \
+ G = ((G1*(255-alpha))+(G2*alpha))>>8; \
+ R = ((R1*(255-alpha))+(R2*alpha))>>8;
+
+#define BLEND_MODE BLEND_NORMAL
void
gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
gint src_width, gint src_height, gdouble src_alpha,
guint8 * dest, gint dest_width, gint dest_height)
{
- cairo_surface_t *srcSurface = 0;
- cairo_surface_t *destSurface = 0;
- cairo_t *cairo = 0;
-
- srcSurface =
- cairo_image_surface_create_for_data (src, CAIRO_FORMAT_ARGB32, src_width,
- src_height, src_width * 4);
- g_assert (srcSurface);
- destSurface =
- cairo_image_surface_create_for_data (dest, CAIRO_FORMAT_ARGB32,
- dest_width, dest_height, dest_width * 4);
- g_assert (destSurface);
- cairo = cairo_create (destSurface);
- g_assert (cairo);
-
- //copy source buffer in destiation
- cairo_translate (cairo, xpos, ypos);
- cairo_set_source_surface (cairo, srcSurface, 0, 0);
- cairo_paint (cairo);
-
- cairo_surface_finish (srcSurface);
- cairo_surface_finish (destSurface);
- cairo_surface_destroy (srcSurface);
- cairo_surface_destroy (destSurface);
- cairo_destroy (cairo);
+ gint alpha, b_alpha;
+ gint i, j;
+ gint src_stride, dest_stride;
+ gint src_add, dest_add;
+ gint B, G, R;
+
+ src_stride = src_width * 4;
+ dest_stride = dest_width * 4;
+
+ b_alpha = (gint) (src_alpha * 255);
+ /* adjust src pointers for negative sizes */
+ if (xpos < 0) {
+ src += -xpos * 4;
+ src_width -= -xpos;
+ xpos = 0;
+ }
+ if (ypos < 0) {
+ src += -ypos * src_stride;
+ src_height -= -ypos;
+ ypos = 0;
+ }
+ /* adjust width/height if the src is bigger than dest */
+ if (xpos + src_width > dest_width) {
+ src_width = dest_width - xpos;
+ }
+ if (ypos + src_height > dest_height) {
+ src_height = dest_height - ypos;
+ }
+
+ src_add = src_stride - (4 * src_width);
+ dest_add = dest_stride - (4 * src_width);
+
+ dest = dest + 4 * xpos + (ypos * dest_stride);
+
+ /* 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++) {
+ alpha = (src[3] * b_alpha) >> 8;
+ BLEND_MODE (dest[1], dest[2], dest[3], src[1], src[2], src[3],
+ B, G, R, alpha);
+ dest[0] = B;
+ dest[1] = G;
+ dest[2] = R;
+ dest[3] = 0xff;
+
+ src += 4;
+ dest += 4;
+ }
+ src += src_add;
+ dest += dest_add;
+ }
}
+#undef BLEND_MODE
+
/* fill a buffer with a checkerboard pattern */
void
gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height)