From 1d9deae5be7012a0677d42fc5a317c2c3015d5ad Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 22 Jun 2011 15:25:35 +0200 Subject: [PATCH] video: add video copy function Add a function to copy a video frame, taking care of source and destination strides. --- gst-libs/gst/video/video.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ gst-libs/gst/video/video.h | 3 +++ 2 files changed, 53 insertions(+) diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index f6d9d47..4685a91 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -967,6 +967,56 @@ gst_video_frame_unmap (GstVideoFrame * frame) } /** + * gst_video_frame_copy: + * @dest: a #GstVideoFrame + * @src: a #GstVideoFrame + * + * Copy the contents from @src to @dest. + * + * Returns: TRUE if the contents could be copied. + */ +gboolean +gst_video_frame_copy (GstVideoFrame * dest, const GstVideoFrame * src) +{ + guint i, n_planes; + const GstVideoInfo *sinfo; + GstVideoInfo *dinfo; + + sinfo = &src->info; + dinfo = &dest->info; + + g_return_val_if_fail (dinfo->format == sinfo->format, FALSE); + g_return_val_if_fail (dinfo->width == sinfo->width + && dinfo->height == sinfo->height, FALSE); + + n_planes = dinfo->n_planes; + + for (i = 0; i < n_planes; i++) { + guint w, h, j; + guint8 *sp, *dp; + gint ss, ds; + + sp = src->data[i]; + dp = dest->data[i]; + + ss = sinfo->stride[i]; + ds = dinfo->stride[i]; + + w = MIN (ABS (ss), ABS (ds)); + h = gst_video_format_get_component_height (dinfo->format, i, dinfo->height); + + GST_DEBUG ("w %d h %d", w, h); + + for (j = 0; j < h; j++) { + memcpy (dp, sp, w); + dp += ds; + sp += ss; + } + } + return TRUE; +} + +/** * get_stride: * @format: a #GstVideoFormat * @component: the component index diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h index d35677a..9445ed4 100644 --- a/gst-libs/gst/video/video.h +++ b/gst-libs/gst/video/video.h @@ -256,6 +256,9 @@ gboolean gst_video_frame_map (GstVideoFrame *frame, GstVideoInfo *inf GstBuffer *buffer, GstMapFlags flags); void gst_video_frame_unmap (GstVideoFrame *frame); +gboolean gst_video_frame_copy (GstVideoFrame *dest, const GstVideoFrame *src); + + #define GST_VIDEO_SIZE_RANGE "(int) [ 1, max ]" #define GST_VIDEO_FPS_RANGE "(fraction) [ 0, max ]" -- 2.7.4