diff --git a/ChangeLog b/ChangeLog index 5602a2bef5..e1ad2940c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-07-27 Thomas Vander Stichele + + * gst/videoscale/README: + add testing examples + * gst/videoscale/gstvideoscale.c: (gst_videoscale_link), + (gst_videoscale_chain): + * gst/videoscale/videoscale.c: (gst_videoscale_setup), + (gst_videoscale_get_size): + add get_size function that handles stride like videotestsrc. + fixes conversion for YUV formats for as much as I can test them. + 2004-07-27 Thomas Vander Stichele * sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls), diff --git a/gst/videoscale/README b/gst/videoscale/README new file mode 100644 index 0000000000..3e08f4ecc3 --- /dev/null +++ b/gst/videoscale/README @@ -0,0 +1,5 @@ +- test different strides using +gst-launch -v videotestsrc ! video/x-raw-yuv,width=320,height=240,format=\(fourcc\)UYVY ! videoscale ! video/x-raw-yuv,width=328,height=240 ! xvimagesink +gst-launch -v videotestsrc ! video/x-raw-yuv,width=320,height=240,format=\(fourcc\)UYVY ! videoscale ! video/x-raw-yuv,width=324,height=240 ! xvimagesink +gst-launch -v videotestsrc ! video/x-raw-yuv,width=320,height=240,format=\(fourcc\)UYVY ! videoscale ! video/x-raw-yuv,width=322,height=240 ! xvimagesink +gst-launch -v videotestsrc ! video/x-raw-yuv,width=320,height=240,format=\(fourcc\)UYVY ! videoscale ! video/x-raw-yuv,width=321,height=240 ! xvimagesink diff --git a/gst/videoscale/gstvideoscale.c b/gst/videoscale/gstvideoscale.c index 8c5f7266be..c87d4ed151 100644 --- a/gst/videoscale/gstvideoscale.c +++ b/gst/videoscale/gstvideoscale.c @@ -214,7 +214,7 @@ gst_videoscale_link (GstPad * pad, const GstCaps * caps) struct videoscale_format_struct *format; int height, width; - GST_DEBUG ("gst_videoscale_link %s\n", gst_caps_to_string (caps)); + GST_DEBUG_OBJECT (pad, "_link with caps %" GST_PTR_FORMAT, caps); videoscale = GST_VIDEOSCALE (gst_pad_get_parent (pad)); otherpad = (pad == videoscale->srcpad) ? videoscale->sinkpad : @@ -366,18 +366,15 @@ gst_videoscale_chain (GstPad * pad, GstData * _data) size = GST_BUFFER_SIZE (buf); if (videoscale->passthru) { - GST_LOG_OBJECT (videoscale, "passing through buffer of %ld bytes in '%s'", - size, GST_OBJECT_NAME (videoscale)); + GST_LOG_OBJECT (videoscale, "passing through buffer of %ld bytes", size); gst_pad_push (videoscale->srcpad, GST_DATA (buf)); return; } - GST_LOG_OBJECT (videoscale, "got buffer of %ld bytes in '%s'", size, - GST_OBJECT_NAME (videoscale)); GST_LOG_OBJECT (videoscale, - "size=%ld from=%dx%d to=%dx%d fromsize=%ld (should be %d) tosize=%d", + "buffersize=%ld from=%dx%d to=%dx%d fromsize=%ld tosize=%ld", size, videoscale->from_width, videoscale->from_height, - videoscale->to_width, videoscale->to_height, size, + videoscale->to_width, videoscale->to_height, videoscale->from_buf_size, videoscale->to_buf_size); g_return_if_fail (size == videoscale->from_buf_size); @@ -394,8 +391,8 @@ gst_videoscale_chain (GstPad * pad, GstData * _data) videoscale->format->scale (videoscale, GST_BUFFER_DATA (outbuf), data); - GST_LOG_OBJECT (videoscale, "pushing buffer of %d bytes in '%s'", - GST_BUFFER_SIZE (outbuf), GST_OBJECT_NAME (videoscale)); + GST_LOG_OBJECT (videoscale, "pushing buffer of %d bytes", + GST_BUFFER_SIZE (outbuf)); gst_pad_push (videoscale->srcpad, GST_DATA (outbuf)); diff --git a/gst/videoscale/videoscale.c b/gst/videoscale/videoscale.c index d94d08586c..1d58fa8b72 100644 --- a/gst/videoscale/videoscale.c +++ b/gst/videoscale/videoscale.c @@ -34,6 +34,7 @@ #include "videoscale_x86.h" #endif +#define ROUND_UP_2(x) (((x) + 1) & ~1) #define ROUND_UP_4(x) (((x) + 3) & ~3) #define ROUND_UP_8(x) (((x) + 7) & ~7) @@ -50,6 +51,9 @@ static unsigned char gst_videoscale_bilinear (unsigned char *src, double x, static unsigned char gst_videoscale_bicubic (unsigned char *src, double x, double y, int sw, int sh); #endif +static int +gst_videoscale_get_size (struct videoscale_format_struct *format, int width, + int height); static void gst_videoscale_planar411 (GstVideoscale * scale, unsigned char *dest, unsigned char *src); @@ -211,7 +215,6 @@ gst_videoscale_setup (GstVideoscale * videoscale) { g_return_if_fail (GST_IS_VIDEOSCALE (videoscale)); g_return_if_fail (videoscale->format != NULL); - gint from_stride, to_stride; GST_DEBUG_OBJECT (videoscale, "format=%p " GST_FOURCC_FORMAT " from %dx%d to %dx%d, %d bpp", @@ -238,17 +241,10 @@ gst_videoscale_setup (GstVideoscale * videoscale) GST_DEBUG_OBJECT (videoscale, "scaling method POINT_SAMPLE"); - /* FIXME: we should get from and to strides from caps. For now we conform - * to videotestsrc's idea of it, which is to round w * bytespp to nearest - * multiple of 4 */ - from_stride = ROUND_UP_4 ((videoscale->from_width * - ROUND_UP_4 (videoscale->format->bpp)) / 8); - to_stride = ROUND_UP_4 ((videoscale->to_width * - ROUND_UP_4 (videoscale->format->bpp)) / 8); - GST_DEBUG_OBJECT (videoscale, "from_stride %d to_stride %d", - from_stride, to_stride); - videoscale->from_buf_size = from_stride * videoscale->from_height; - videoscale->to_buf_size = to_stride * videoscale->to_height; + videoscale->from_buf_size = gst_videoscale_get_size (videoscale->format, + videoscale->from_width, videoscale->from_height); + videoscale->to_buf_size = gst_videoscale_get_size (videoscale->format, + videoscale->to_width, videoscale->to_height); videoscale->passthru = FALSE; videoscale->inited = TRUE; @@ -283,6 +279,52 @@ gst_videoscale_scale_rgb (GstVideoscale * scale, unsigned char *dest, //scale->scaler(scale, src, dest, sw, sh, dw, dh); } #endif +/* calculate the total size needed for an image in the given format + * of the given width and height, taking stride into account */ +static int +gst_videoscale_get_size (struct videoscale_format_struct *format, int width, + int height) +{ + int stride = 0; + int ustride = 0, vstride = 0; + int size = 0; + + /* FIXME: we should get from and to strides from caps. For now we conform + * to videotestsrc's idea of it, which is to round w * bytespp to nearest + * multiple of 4 */ + + switch (format->fourcc) { + case fourcc_RGB_: + stride = ROUND_UP_4 (width * ROUND_UP_4 (format->bpp)) / 8; + size = stride * height; + break; + case fourcc_YUY2: + case fourcc_UYVY: + case fourcc_YVYU: + stride = ROUND_UP_2 (width) * 2; + size = stride * height; + break; + case fourcc_I420: + case fourcc_YV12: + stride = ROUND_UP_4 (width); + ustride = ROUND_UP_8 (width) / 2; + vstride = ROUND_UP_8 (stride) / 2; + size = stride * ROUND_UP_2 (height) + ustride * ROUND_UP_2 (height) / 2 + + vstride * ROUND_UP_2 (height) / 2; + break; + case fourcc_Y422: + case fourcc_UYNV: + case fourcc_Y800: + g_warning ("unhandled known YUV fourcc"); + break; + default: + g_warning ("unhandled unknown fourcc"); + break; + } + GST_LOG ("image size for %dx%d in " GST_FOURCC_FORMAT " is %d bytes", + width, height, GST_FOURCC_ARGS (format->fourcc), size); + return size; +} static void gst_videoscale_planar411 (GstVideoscale * scale, unsigned char *dest,