gst/: Handle strides correctly, fix identity flipping, convert navigation event correctly again.

Original commit message from CVS:
2005-11-24  Julien MOUTTE  <julien@moutte.net>

* gst/debug/gstnavigationtest.c: (draw_box_planar411):
* gst/videofilter/gstvideoflip.c:
(gst_videoflip_method_get_type),
(gst_videoflip_set_caps), (gst_videoflip_transform_caps),
(gst_videoflip_get_unit_size), (gst_videoflip_flip),
(gst_videoflip_transform), (gst_videoflip_handle_src_event),
(gst_videoflip_set_property), (gst_videoflip_base_init),
(gst_videoflip_class_init), (gst_videoflip_init): Handle strides
correctly, fix identity flipping, convert navigation event
correctly again.
This commit is contained in:
Julien Moutte 2005-11-24 12:50:28 +00:00
parent 557da6614b
commit 20c7083ccd
3 changed files with 201 additions and 52 deletions

View file

@ -1,3 +1,15 @@
2005-11-24 Julien MOUTTE <julien@moutte.net>
* gst/debug/gstnavigationtest.c: (draw_box_planar411):
* gst/videofilter/gstvideoflip.c: (gst_videoflip_method_get_type),
(gst_videoflip_set_caps), (gst_videoflip_transform_caps),
(gst_videoflip_get_unit_size), (gst_videoflip_flip),
(gst_videoflip_transform), (gst_videoflip_handle_src_event),
(gst_videoflip_set_property), (gst_videoflip_base_init),
(gst_videoflip_class_init), (gst_videoflip_init): Handle strides
correctly, fix identity flipping, convert navigation event
correctly again.
2005-11-23 Thomas Vander Stichele <thomas at apestaart dot org> 2005-11-23 Thomas Vander Stichele <thomas at apestaart dot org>
* configure.ac: back to HEAD * configure.ac: back to HEAD

View file

@ -169,6 +169,7 @@ draw_box_planar411 (guint8 * dest, int width, int height, int x, int y,
guint8 colory, guint8 coloru, guint8 colorv) guint8 colory, guint8 coloru, guint8 colorv)
{ {
int x1, x2, y1, y2; int x1, x2, y1, y2;
guint8 *d = dest;
if (x < 0 || y < 0 || x >= width || y >= height) if (x < 0 || y < 0 || x >= width || y >= height)
return; return;
@ -180,27 +181,25 @@ draw_box_planar411 (guint8 * dest, int width, int height, int x, int y,
for (y = y1; y < y2; y++) { for (y = y1; y < y2; y++) {
for (x = x1; x < x2; x++) { for (x = x1; x < x2; x++) {
((guint8 *) dest)[y * width + x] = colory; ((guint8 *) d)[y * GST_VIDEO_I420_Y_ROWSTRIDE (width) + x] = colory;
} }
} }
dest += height * width; d = dest + GST_VIDEO_I420_U_OFFSET (width, height);
width /= 2;
height /= 2;
x1 /= 2; x1 /= 2;
x2 /= 2; x2 /= 2;
y1 /= 2; y1 /= 2;
y2 /= 2; y2 /= 2;
for (y = y1; y < y2; y++) { for (y = y1; y < y2; y++) {
for (x = x1; x < x2; x++) { for (x = x1; x < x2; x++) {
((guint8 *) dest)[y * width + x] = coloru; ((guint8 *) d)[y * GST_VIDEO_I420_U_ROWSTRIDE (width) + x] = coloru;
} }
} }
dest += height * width; d = dest + GST_VIDEO_I420_V_OFFSET (width, height);
for (y = y1; y < y2; y++) { for (y = y1; y < y2; y++) {
for (x = x1; x < x2; x++) { for (x = x1; x < x2; x++) {
((guint8 *) dest)[y * width + x] = colorv; ((guint8 *) d)[y * GST_VIDEO_I420_V_ROWSTRIDE (width) + x] = colorv;
} }
} }
} }

View file

@ -29,6 +29,8 @@
#include "gstvideoflip.h" #include "gstvideoflip.h"
#include <string.h>
#include <gst/video/video.h> #include <gst/video/video.h>
/* GstVideoflip signals and args */ /* GstVideoflip signals and args */
@ -231,61 +233,209 @@ gst_videoflip_get_unit_size (GstBaseTransform * btrans, GstCaps * caps,
} }
static GstFlowReturn static GstFlowReturn
gst_videoflip_flip (GstVideoflip * videoflip, unsigned char *dest, gst_videoflip_flip (GstVideoflip * videoflip, guint8 * dest,
unsigned char *src, int sw, int sh, int dw, int dh) guint8 * src, int sw, int sh, int dw, int dh)
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
int x, y; int x, y;
guint8 *s = src, *d = dest;
switch (videoflip->method) { switch (videoflip->method) {
case GST_VIDEOFLIP_METHOD_90R: case GST_VIDEOFLIP_METHOD_90R:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[(sh - 1 - x) * sw + y]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[(sh - 1 - x) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + y];
}
}
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - x) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + y];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - x) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + y];
} }
} }
break; break;
case GST_VIDEOFLIP_METHOD_90L: case GST_VIDEOFLIP_METHOD_90L:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[x * sw + (sw - 1 - y)]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[x * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - y)];
}
}
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[x * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 - 1 - y)];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[x * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 - 1 - y)];
} }
} }
break; break;
case GST_VIDEOFLIP_METHOD_180: case GST_VIDEOFLIP_METHOD_180:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[(sh - 1 - y) * sw + (sw - 1 - x)]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[(sh - 1 - y) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - x)];
}
}
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - y) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 -
1 - x)];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - y) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 -
1 - x)];
} }
} }
break; break;
case GST_VIDEOFLIP_METHOD_HORIZ: case GST_VIDEOFLIP_METHOD_HORIZ:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[y * sw + (sw - 1 - x)]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[y * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - x)];
}
}
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[y * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 - 1 - x)];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[y * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 - 1 - x)];
} }
} }
break; break;
case GST_VIDEOFLIP_METHOD_VERT: case GST_VIDEOFLIP_METHOD_VERT:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[(sh - 1 - y) * sw + x]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[(sh - 1 - y) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + x];
}
}
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - y) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + x];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - y) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + x];
} }
} }
break; break;
case GST_VIDEOFLIP_METHOD_TRANS: case GST_VIDEOFLIP_METHOD_TRANS:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[x * sw + y]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[x * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + y];
}
}
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[x * GST_VIDEO_I420_U_ROWSTRIDE (sw) + y];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[x * GST_VIDEO_I420_V_ROWSTRIDE (sw) + y];
} }
} }
break; break;
case GST_VIDEOFLIP_METHOD_OTHER: case GST_VIDEOFLIP_METHOD_OTHER:
/* Flip Y */
for (y = 0; y < dh; y++) { for (y = 0; y < dh; y++) {
for (x = 0; x < dw; x++) { for (x = 0; x < dw; x++) {
dest[y * dw + x] = src[(sh - 1 - x) * sw + (sw - 1 - y)]; d[y * GST_VIDEO_I420_Y_ROWSTRIDE (dw) + x] =
s[(sh - 1 - x) * GST_VIDEO_I420_Y_ROWSTRIDE (sw) + (sw - 1 - y)];
} }
} }
/* Flip U */
s = src + GST_VIDEO_I420_U_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_U_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_U_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - x) * GST_VIDEO_I420_U_ROWSTRIDE (sw) + (sw / 2 -
1 - y)];
}
}
/* Flip V */
s = src + GST_VIDEO_I420_V_OFFSET (sw, sh);
d = dest + GST_VIDEO_I420_V_OFFSET (dw, dh);
for (y = 0; y < dh / 2; y++) {
for (x = 0; x < dw / 2; x++) {
d[y * GST_VIDEO_I420_V_ROWSTRIDE (dw) + x] =
s[(sh / 2 - 1 - x) * GST_VIDEO_I420_V_ROWSTRIDE (sw) + (sw / 2 -
1 - y)];
}
}
break;
case GST_VIDEOFLIP_METHOD_IDENTITY:
memcpy (d, s, GST_VIDEO_I420_SIZE (dw, dh));
break; break;
default: default:
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
@ -319,27 +469,7 @@ gst_videoflip_transform (GstBaseTransform * trans, GstBuffer * in,
sw, sh, dw, dh); sw, sh, dw, dh);
ret = gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh); ret = gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
if (ret != GST_FLOW_OK)
goto beach;
src += sw * sh;
dest += dw * dh;
dh = dh >> 1;
dw = dw >> 1;
sh = sh >> 1;
sw = sw >> 1;
ret = gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
if (ret != GST_FLOW_OK)
goto beach;
src += sw * sh;
dest += dw * dh;
ret = gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
beach:
return ret; return ret;
} }
@ -348,7 +478,7 @@ gst_videoflip_handle_src_event (GstPad * pad, GstEvent * event)
{ {
GstVideoflip *vf; GstVideoflip *vf;
gboolean ret; gboolean ret;
gdouble x, y; gdouble new_x, new_y, x, y;
GstStructure *structure; GstStructure *structure;
vf = GST_VIDEOFLIP (gst_pad_get_parent (pad)); vf = GST_VIDEOFLIP (gst_pad_get_parent (pad));
@ -363,36 +493,44 @@ gst_videoflip_handle_src_event (GstPad * pad, GstEvent * event)
structure = (GstStructure *) gst_event_get_structure (event); structure = (GstStructure *) gst_event_get_structure (event);
if (gst_structure_get_double (structure, "pointer_x", &x) && if (gst_structure_get_double (structure, "pointer_x", &x) &&
gst_structure_get_double (structure, "pointer_y", &y)) { gst_structure_get_double (structure, "pointer_y", &y)) {
GST_DEBUG_OBJECT (vf, "converting %fx%f", x, y);
switch (vf->method) { switch (vf->method) {
case GST_VIDEOFLIP_METHOD_90R: case GST_VIDEOFLIP_METHOD_90R:
case GST_VIDEOFLIP_METHOD_OTHER: new_x = y;
x = y; new_y = vf->to_width - x;
y = vf->to_width - x;
break; break;
case GST_VIDEOFLIP_METHOD_90L: case GST_VIDEOFLIP_METHOD_90L:
new_x = vf->to_height - y;
new_y = x;
break;
case GST_VIDEOFLIP_METHOD_OTHER:
new_x = vf->to_height - y;
new_y = vf->to_width - x;
break;
case GST_VIDEOFLIP_METHOD_TRANS: case GST_VIDEOFLIP_METHOD_TRANS:
x = vf->to_height - y; new_x = y;
y = x; new_y = x;
break; break;
case GST_VIDEOFLIP_METHOD_180: case GST_VIDEOFLIP_METHOD_180:
x = vf->to_width - x; new_x = vf->to_width - x;
y = vf->to_height - y; new_y = vf->to_height - y;
break; break;
case GST_VIDEOFLIP_METHOD_HORIZ: case GST_VIDEOFLIP_METHOD_HORIZ:
x = vf->to_width - x; new_x = vf->to_width - x;
y = y; new_y = y;
break; break;
case GST_VIDEOFLIP_METHOD_VERT: case GST_VIDEOFLIP_METHOD_VERT:
x = x; new_x = x;
y = vf->to_height - y; new_y = vf->to_height - y;
break; break;
default: default:
x = x; new_x = x;
y = y; new_y = y;
break; break;
} }
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, GST_DEBUG_OBJECT (vf, "to %fx%f", x, y);
"pointer_y", G_TYPE_DOUBLE, y, NULL); gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, new_x,
"pointer_y", G_TYPE_DOUBLE, new_y, NULL);
} }
break; break;
default: default: