ximagesrc: fix various width/height calculations being off by one,

ximagesrc: fix various width/height calculations being off by one,
 and make it so a single pixel width/height can be captured (except
 the top left one, as 0,0,0,0 is reserved for full screen as per
 the property comments).
This commit is contained in:
Vincent Penquerc'h 2010-11-27 17:15:32 +00:00 committed by Sebastian Dröge
parent 66387181ac
commit fbd9581f87

View file

@ -465,10 +465,10 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
if (ximagesrc->endx > ximagesrc->startx && if (ximagesrc->endx > ximagesrc->startx &&
ximagesrc->endy > ximagesrc->starty) { ximagesrc->endy > ximagesrc->starty) {
/* see if damage area intersects */ /* see if damage area intersects */
if (rects[i].x + rects[i].width < ximagesrc->startx || if (rects[i].x + rects[i].width - 1 < ximagesrc->startx ||
rects[i].x > ximagesrc->endx) { rects[i].x > ximagesrc->endx) {
/* trivial reject */ /* trivial reject */
} else if (rects[i].y + rects[i].height < ximagesrc->starty || } else if (rects[i].y + rects[i].height - 1 < ximagesrc->starty ||
rects[i].y > ximagesrc->endy) { rects[i].y > ximagesrc->endy) {
/* trivial reject */ /* trivial reject */
} else { } else {
@ -479,12 +479,12 @@ gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
rects[i].x; rects[i].x;
starty = (rects[i].y < ximagesrc->starty) ? ximagesrc->starty : starty = (rects[i].y < ximagesrc->starty) ? ximagesrc->starty :
rects[i].y; rects[i].y;
width = (rects[i].x + rects[i].width < ximagesrc->endx) ? width = (rects[i].x + rects[i].width - 1 < ximagesrc->endx) ?
rects[i].x + rects[i].width - startx : rects[i].x + rects[i].width - startx :
ximagesrc->endx - startx; ximagesrc->endx - startx + 1;
height = (rects[i].y + rects[i].height < ximagesrc->endy) ? height = (rects[i].y + rects[i].height - 1 < ximagesrc->endy) ?
rects[i].y + rects[i].height - starty : ximagesrc->endy - rects[i].y + rects[i].height - starty : ximagesrc->endy -
starty; starty + 1;
GST_LOG_OBJECT (ximagesrc, GST_LOG_OBJECT (ximagesrc,
"Retrieving damaged sub-region @ %d,%d size %dx%d as intersect region", "Retrieving damaged sub-region @ %d,%d size %dx%d as intersect region",
@ -943,27 +943,36 @@ gst_ximage_src_get_caps (GstBaseSrc * bs)
width = xcontext->width; width = xcontext->width;
height = xcontext->height; height = xcontext->height;
if (s->endx > s->startx && s->endy > s->starty) {
/* property comments say 0 means right/bottom, means we can't capture
the top left pixel alone */
if (s->endx == 0)
s->endx = width - 1;
if (s->endy == 0)
s->endy = height - 1;
if (s->endx >= s->startx && s->endy >= s->starty) {
/* this means user has put in values */ /* this means user has put in values */
if (s->startx < xcontext->width && s->endx < xcontext->width && if (s->startx < xcontext->width && s->endx < xcontext->width &&
s->starty < xcontext->height && s->endy < xcontext->height) { s->starty < xcontext->height && s->endy < xcontext->height &&
s->startx >= 0 && s->starty >= 0) {
/* values are fine */ /* values are fine */
s->width = width = s->endx - s->startx; s->width = width = s->endx - s->startx + 1;
s->height = height = s->endy - s->starty; s->height = height = s->endy - s->starty + 1;
} else { } else {
GST_WARNING GST_WARNING
("User put in co-ordinates overshooting the X resolution, setting to full screen"); ("User put in co-ordinates overshooting the X resolution, setting to full screen");
s->startx = 0; s->startx = 0;
s->starty = 0; s->starty = 0;
s->endx = 0; s->endx = width - 1;
s->endy = 0; s->endy = height - 1;
} }
} else { } else {
GST_WARNING ("User put in bogus co-ordinates, setting to full screen"); GST_WARNING ("User put in bogus co-ordinates, setting to full screen");
s->startx = 0; s->startx = 0;
s->starty = 0; s->starty = 0;
s->endx = 0; s->endx = width - 1;
s->endy = 0; s->endy = height - 1;
} }
GST_DEBUG ("width = %d, height=%d", width, height); GST_DEBUG ("width = %d, height=%d", width, height);
return gst_caps_new_simple ("video/x-raw-rgb", return gst_caps_new_simple ("video/x-raw-rgb",