diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-03-19 12:26:11 +0100 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-03-19 12:26:11 +0100 |
commit | e620dbc57ddf4846e2b21ff29e774bdb5eb40141 (patch) | |
tree | fe5dc6d81a94f549af5c495a6fbc5d528caafc9f | |
parent | dfb8e7cb2cdd78807f20e741b8965e5c4607b8e0 (diff) |
video: add function to copy one video plane
-rw-r--r-- | gst-libs/gst/video/video.c | 76 | ||||
-rw-r--r-- | gst-libs/gst/video/video.h | 2 |
2 files changed, 56 insertions, 22 deletions
diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index 6c0fc2ce4..77ac4b3f4 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -1133,17 +1133,24 @@ gst_video_frame_unmap (GstVideoFrame * frame) * gst_video_frame_copy: * @dest: a #GstVideoFrame * @src: a #GstVideoFrame + * @plane: a plane * - * Copy the contents from @src to @dest. + * Copy the plane with index @plane from @src to @dest. * * Returns: TRUE if the contents could be copied. */ gboolean -gst_video_frame_copy (GstVideoFrame * dest, const GstVideoFrame * src) +gst_video_frame_copy_plane (GstVideoFrame * dest, const GstVideoFrame * src, + guint plane) { - guint i, n_planes; const GstVideoInfo *sinfo; GstVideoInfo *dinfo; + guint w, h, j; + guint8 *sp, *dp; + gint ss, ds; + + g_return_val_if_fail (dest != NULL, FALSE); + g_return_val_if_fail (src != NULL, FALSE); sinfo = &src->info; dinfo = &dest->info; @@ -1151,33 +1158,58 @@ gst_video_frame_copy (GstVideoFrame * dest, const GstVideoFrame * src) g_return_val_if_fail (dinfo->finfo->format == sinfo->finfo->format, FALSE); g_return_val_if_fail (dinfo->width == sinfo->width && dinfo->height == sinfo->height, FALSE); + g_return_val_if_fail (dinfo->finfo->n_planes < plane, FALSE); - n_planes = dinfo->finfo->n_planes; + sp = src->data[plane]; + dp = dest->data[plane]; - GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "doing video frame copy"); + ss = sinfo->stride[plane]; + ds = dinfo->stride[plane]; - for (i = 0; i < n_planes; i++) { - guint w, h, j; - guint8 *sp, *dp; - gint ss, ds; + w = MIN (ABS (ss), ABS (ds)); + h = GST_VIDEO_FRAME_COMP_HEIGHT (dest, plane); - sp = src->data[i]; - dp = dest->data[i]; + GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "copy plane %d, w:%d h:%d ", plane, w, h); - ss = sinfo->stride[i]; - ds = dinfo->stride[i]; + for (j = 0; j < h; j++) { + memcpy (dp, sp, w); + dp += ds; + sp += ss; + } + return TRUE; +} - w = MIN (ABS (ss), ABS (ds)); - h = GST_VIDEO_FRAME_COMP_HEIGHT (dest, i); +/** + * 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; - GST_DEBUG ("w %d h %d", w, h); + g_return_val_if_fail (dest != NULL, FALSE); + g_return_val_if_fail (src != NULL, FALSE); + + sinfo = &src->info; + dinfo = &dest->info; + + g_return_val_if_fail (dinfo->finfo->format == sinfo->finfo->format, FALSE); + g_return_val_if_fail (dinfo->width == sinfo->width + && dinfo->height == sinfo->height, FALSE); + + n_planes = dinfo->finfo->n_planes; + + for (i = 0; i < n_planes; i++) + gst_video_frame_copy_plane (dest, src, i); - for (j = 0; j < h; j++) { - memcpy (dp, sp, w); - dp += ds; - sp += ss; - } - } return TRUE; } diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h index e8cb1ebca..c3b7b52fa 100644 --- a/gst-libs/gst/video/video.h +++ b/gst-libs/gst/video/video.h @@ -632,6 +632,8 @@ gboolean gst_video_frame_map_id (GstVideoFrame *frame, GstVideoInfo *i void gst_video_frame_unmap (GstVideoFrame *frame); gboolean gst_video_frame_copy (GstVideoFrame *dest, const GstVideoFrame *src); +gboolean gst_video_frame_copy_plane (GstVideoFrame *dest, const GstVideoFrame *src, + guint plane); /* general info */ #define GST_VIDEO_FRAME_FORMAT(f) (GST_VIDEO_INFO_FORMAT(&(f)->info)) |