mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-07 20:31:20 +00:00
video: add video copy function
Add a function to copy a video frame, taking care of source and destination strides.
This commit is contained in:
parent
6633910500
commit
1d9deae5be
2 changed files with 53 additions and 0 deletions
|
@ -966,6 +966,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
|
||||
|
|
|
@ -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 ]"
|
||||
|
||||
|
|
Loading…
Reference in a new issue