Commit c03f02f5 authored by Zaheer Abbas Merali's avatar Zaheer Abbas Merali
Browse files

sys/ximagesrc/: Fix ximagesrc so a) the cursor doesnt trail and b) there are...

sys/ximagesrc/: Fix ximagesrc so a) the cursor doesnt trail and b) there are no yellow rectangles with the cursor

Original commit message from CVS:
2006-03-31  Zaheer Abbas Merali  <zaheerabbas at merali dot org>

* sys/ximagesrc/ximagesrc.c: (composite_pixel),
(gst_ximagesrc_ximage_get), (gst_ximagesrc_set_property),
(gst_ximagesrc_get_caps), (gst_ximagesrc_class_init):
* sys/ximagesrc/ximagesrc.h:
* sys/ximagesrc/ximageutil.c: (ximageutil_xcontext_get):
* sys/ximagesrc/ximageutil.h:
Fix ximagesrc so a) the cursor doesnt trail and b) there are no
yellow rectangles with the cursor
parent 9b064ff8
common @ c18b429f
Subproject commit 45cc64e522d61410eb8d1a3e7ef67569851cd77a
Subproject commit c18b429f2a3698b6fc5e849a637aa0c8b91e82b9
......@@ -43,7 +43,7 @@ static GstStaticPadTemplate t =
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb, "
"framerate = (fraction) [ 0, MAX ], "
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]"));
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ] "));
enum
{
......@@ -221,11 +221,11 @@ composite_pixel (GstXContext * xcontext, guchar * dest, guchar * src)
guint8 g = src[1];
guint8 b = src[0];
guint8 a = src[3];
gint dr, dg, db;
guint8 dr, dg, db;
guint32 color;
gint r_shift, r_max;
gint g_shift, g_max;
gint b_shift, b_max;
gint r_shift, r_max, r_shift_out;
gint g_shift, g_max, g_shift_out;
gint b_shift, b_max, b_shift_out;
switch (xcontext->bpp) {
case 8:
......@@ -242,12 +242,21 @@ composite_pixel (GstXContext * xcontext, guchar * dest, guchar * src)
color = 0;
}
/* FIXME: move the code that finds shift and max in the _link function */
for (r_shift = 0; !(xcontext->visual->red_mask & (1 << r_shift)); r_shift++);
for (g_shift = 0; !(xcontext->visual->green_mask & (1 << g_shift));
g_shift++);
for (b_shift = 0; !(xcontext->visual->blue_mask & (1 << b_shift)); b_shift++);
for (r_shift_out = 0; !(xcontext->visual->red_mask & (1 << r_shift_out));
r_shift_out++);
for (g_shift_out = 0; !(xcontext->visual->green_mask & (1 << g_shift_out));
g_shift_out++);
for (b_shift_out = 0; !(xcontext->visual->blue_mask & (1 << b_shift_out));
b_shift_out++);
r_max = (xcontext->visual->red_mask >> r_shift);
b_max = (xcontext->visual->blue_mask >> b_shift);
g_max = (xcontext->visual->green_mask >> g_shift);
......@@ -264,8 +273,9 @@ composite_pixel (GstXContext * xcontext, guchar * dest, guchar * src)
dg = (g * a + (0xff - a) * dg) / 0xff;
db = (b * a + (0xff - a) * db) / 0xff;
color = (((dr * r_max) / 255) << r_shift) +
(((dg * g_max) / 255) << g_shift) + (((db * b_max) / 255) << b_shift);
color = (((dr * r_max) / 255) << r_shift_out) +
(((dg * g_max) / 255) << g_shift_out) +
(((db * b_max) / 255) << b_shift_out);
switch (xcontext->bpp) {
case 8:
......@@ -289,6 +299,7 @@ static GstXImageSrcBuffer *
gst_ximagesrc_ximage_get (GstXImageSrc * ximagesrc)
{
GstXImageSrcBuffer *ximage = NULL;
GstCaps *caps = NULL;
g_mutex_lock (ximagesrc->pool_lock);
while (ximagesrc->buffer_pool != NULL) {
......@@ -323,19 +334,19 @@ gst_ximagesrc_ximage_get (GstXImageSrc * ximagesrc)
xcontext = ximagesrc->xcontext;
/* FIXME: Include the PAR */
gst_buffer_set_caps (GST_BUFFER (ximage),
gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, xcontext->bpp,
"depth", G_TYPE_INT, xcontext->depth,
"endianness", G_TYPE_INT, xcontext->endianness,
"red_mask", G_TYPE_INT, xcontext->visual->red_mask,
"green_mask", G_TYPE_INT, xcontext->visual->green_mask,
"blue_mask", G_TYPE_INT, xcontext->visual->blue_mask,
"width", G_TYPE_INT, xcontext->width,
"height", G_TYPE_INT, xcontext->height,
"framerate", GST_TYPE_FRACTION, ximagesrc->fps_n, ximagesrc->fps_d,
NULL));
caps = gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, xcontext->bpp,
"depth", G_TYPE_INT, xcontext->depth,
"endianness", G_TYPE_INT, xcontext->endianness,
"red_mask", G_TYPE_INT, xcontext->r_mask_output,
"green_mask", G_TYPE_INT, xcontext->g_mask_output,
"blue_mask", G_TYPE_INT, xcontext->b_mask_output,
"width", G_TYPE_INT, xcontext->width,
"height", G_TYPE_INT, xcontext->height,
"framerate", GST_TYPE_FRACTION, ximagesrc->fps_n, ximagesrc->fps_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, xcontext->par, NULL);
gst_buffer_set_caps (GST_BUFFER (ximage), caps);
g_mutex_unlock (ximagesrc->x_lock);
}
......@@ -379,6 +390,35 @@ gst_ximagesrc_ximage_get (GstXImageSrc * ximagesrc)
}
} while (XPending (ximagesrc->xcontext->disp));
XDamageSubtract (ximagesrc->xcontext->disp, ximagesrc->damage, None, None);
#ifdef HAVE_XFIXES
/* re-get area where last mouse pointer was */
if (ximagesrc->cursor_image) {
gint x, y, width, height;
x = ximagesrc->cursor_image->x - ximagesrc->cursor_image->xhot;
y = ximagesrc->cursor_image->y - ximagesrc->cursor_image->yhot;
width = ximagesrc->cursor_image->width;
height = ximagesrc->cursor_image->height;
/* bounds checking */
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (x + width > ximagesrc->width)
width = ximagesrc->width - x;
if (y + height > ximagesrc->height)
height = ximagesrc->height - y;
g_assert (x >= 0);
g_assert (y >= 0);
GST_DEBUG_OBJECT (ximagesrc, "Removing cursor from %d,%d", x, y);
XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
x, y, width, height, AllPlanes, ZPixmap, ximage->ximage, x, y);
}
#endif
} else {
#endif
......@@ -401,29 +441,33 @@ gst_ximagesrc_ximage_get (GstXImageSrc * ximagesrc)
#ifdef HAVE_XFIXES
if (ximagesrc->show_pointer && ximagesrc->have_xfixes) {
XFixesCursorImage *cursor_image;
GST_DEBUG_OBJECT (ximagesrc, "Using XFixes to draw cursor");
/* get cursor */
cursor_image = XFixesGetCursorImage (ximagesrc->xcontext->disp);
if (cursor_image != NULL) {
ximagesrc->cursor_image = XFixesGetCursorImage (ximagesrc->xcontext->disp);
if (ximagesrc->cursor_image != NULL) {
int cx, cy, i, j, count;
cx = cursor_image->x - cursor_image->xhot;
cy = cursor_image->y - cursor_image->yhot;
cx = ximagesrc->cursor_image->x - ximagesrc->cursor_image->xhot;
cy = ximagesrc->cursor_image->y - ximagesrc->cursor_image->yhot;
//count = image->width * image->height;
count = cursor_image->width * cursor_image->height;
count = ximagesrc->cursor_image->width * ximagesrc->cursor_image->height;
for (i = 0; i < count; i++)
cursor_image->pixels[i] = GUINT_TO_LE (cursor_image->pixels[i]);
ximagesrc->cursor_image->pixels[i] =
GUINT_TO_LE (ximagesrc->cursor_image->pixels[i]);
/* copy those pixels across */
for (j = cy; j < cy + cursor_image->height && j < ximagesrc->height; j++) {
for (i = cx; i < cx + cursor_image->width && i < ximagesrc->width; i++) {
for (j = cy;
j < cy + ximagesrc->cursor_image->height && j < ximagesrc->height;
j++) {
for (i = cx;
i < cx + ximagesrc->cursor_image->width && i < ximagesrc->width;
i++) {
guint8 *src, *dest;
src =
(guint8 *) & (cursor_image->pixels[((j -
cy) * cursor_image->width + (i - cx))]);
(guint8 *) & (ximagesrc->cursor_image->pixels[((j -
cy) * ximagesrc->cursor_image->width + (i - cx))]);
dest =
(guint8 *) & (ximage->ximage->data[(j * ximagesrc->width +
i) * (ximagesrc->xcontext->bpp / 8)]);
......@@ -639,14 +683,13 @@ gst_ximagesrc_get_caps (GstBaseSrc * bs)
xcontext = s->xcontext;
/* FIXME: Add PAR */
return gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, xcontext->bpp,
"depth", G_TYPE_INT, xcontext->depth,
"endianness", G_TYPE_INT, xcontext->endianness,
"red_mask", G_TYPE_INT, xcontext->visual->red_mask,
"green_mask", G_TYPE_INT, xcontext->visual->green_mask,
"blue_mask", G_TYPE_INT, xcontext->visual->blue_mask,
"red_mask", G_TYPE_INT, xcontext->r_mask_output,
"green_mask", G_TYPE_INT, xcontext->g_mask_output,
"blue_mask", G_TYPE_INT, xcontext->b_mask_output,
"width", G_TYPE_INT, xcontext->width,
"height", G_TYPE_INT, xcontext->height,
"framerate", GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
......
......@@ -77,6 +77,8 @@ struct _GstXImageSrc
gboolean show_pointer;
#ifdef HAVE_XFIXES
int fixes_event_base;
XFixesCursorImage *cursor_image;
#endif
#ifdef HAVE_XDAMAGE
Damage damage;
......
......@@ -204,13 +204,13 @@ ximageutil_xcontext_get (GstElement * parent, const gchar * display_name)
if ((xcontext->bpp == 24 || xcontext->bpp == 32) &&
xcontext->endianness == G_LITTLE_ENDIAN) {
xcontext->endianness = G_BIG_ENDIAN;
xcontext->visual->red_mask = GUINT32_TO_BE (xcontext->visual->red_mask);
xcontext->visual->green_mask = GUINT32_TO_BE (xcontext->visual->green_mask);
xcontext->visual->blue_mask = GUINT32_TO_BE (xcontext->visual->blue_mask);
xcontext->r_mask_output = GUINT32_TO_BE (xcontext->visual->red_mask);
xcontext->g_mask_output = GUINT32_TO_BE (xcontext->visual->green_mask);
xcontext->b_mask_output = GUINT32_TO_BE (xcontext->visual->blue_mask);
if (xcontext->bpp == 24) {
xcontext->visual->red_mask >>= 8;
xcontext->visual->green_mask >>= 8;
xcontext->visual->blue_mask >>= 8;
xcontext->r_mask_output >>= 8;
xcontext->g_mask_output >>= 8;
xcontext->b_mask_output >>= 8;
}
}
......@@ -283,7 +283,8 @@ ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext)
GST_DEBUG ("Decided on index %d (%d/%d)", index,
par[index][0], par[index][1]);
g_free (xcontext->par);
if (xcontext->par)
g_free (xcontext->par);
xcontext->par = g_new0 (GValue, 1);
g_value_init (xcontext->par, GST_TYPE_FRACTION);
gst_value_set_fraction (xcontext->par, par[index][0], par[index][1]);
......
......@@ -89,6 +89,12 @@ struct _GstXContext {
gint width, height;
gint widthmm, heightmm;
/* these are the output masks
* for buffers from ximagesrc
* and are in big endian */
guint32 r_mask_output, g_mask_output, b_mask_output;
GValue *par; /* calculated pixel aspect ratio */
gboolean use_xshm;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment