From: Wim Taymans Date: Mon, 19 Mar 2012 11:26:11 +0000 (+0100) Subject: video: add function to copy one video plane X-Git-Tag: 1.19.3~511^2~6681 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e620dbc57ddf4846e2b21ff29e774bdb5eb40141;p=platform%2Fupstream%2Fgstreamer.git video: add function to copy one video plane --- diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index 6c0fc2c..77ac4b3 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 e8cb1eb..c3b7b52 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))