diff mbox

ximagesink: add support for 32-bit RGB with alpha mask

Message ID CA+M3ks7=mZ-e-rB=OneM36yWx_EgppnNXw30qVzjpzxpaim1mA@mail.gmail.com
State Accepted
Headers show

Commit Message

Benjamin Gaignard May 19, 2013, 6:04 a.m. UTC
From 80e700a566cdfe03751a7e48ae7fe3b18d1c6fb6 Mon Sep 17 00:00:00 2001
From: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Date: Thu, 16 May 2013 08:52:29 +0000
Subject: ximagesink: add support for 32-bit RGB with alpha mask

When X screen return a depth = 32 with bpp = 32, the alpha mask
must be correctly set to have a known GStreamer video format.
X visual structure doesn't provide the alpha mask information,
but we can find it from the others masks.
https://bugzilla.gnome.org/show_bug.cgi?id=700413
---
--
cgit v0.9.0.2-2-gbebe
diff mbox

Patch

diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c
index aaf7223..93fe19d 100644
--- a/sys/ximage/ximagesink.c
+++ b/sys/ximage/ximagesink.c
@@ -832,6 +832,7 @@  gst_ximagesink_xcontext_get (GstXImageSink * ximagesink)
   gint nb_formats = 0, i;
   gint endianness;
   GstVideoFormat vformat;
+  guint32 alpha_mask;

   g_return_val_if_fail (GST_IS_XIMAGESINK (ximagesink), NULL);

@@ -904,9 +905,15 @@  gst_ximagesink_xcontext_get (GstXImageSink * ximagesink)
     GST_DEBUG ("ximagesink is not using XShm extension");
   }

-  vformat = gst_video_format_from_masks (xcontext->depth, xcontext->bpp,
-      endianness, xcontext->visual->red_mask, xcontext->visual->green_mask,
-      xcontext->visual->blue_mask, 0);
+  /* extrapolate alpha mask */
+  alpha_mask = ~(xcontext->visual->red_mask
+      | xcontext->visual->green_mask | xcontext->visual->blue_mask);
+  alpha_mask &= 0xffffffff;
+
+  vformat =
+      gst_video_format_from_masks (xcontext->depth, xcontext->bpp, endianness,
+      xcontext->visual->red_mask, xcontext->visual->green_mask,
+      xcontext->visual->blue_mask, alpha_mask);

   if (vformat == GST_VIDEO_FORMAT_UNKNOWN)
     goto unknown_format;