From 7f8eaa6cbfec856c2364835b9fa3c669aebd7a9d Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Thu, 5 Jan 2012 10:29:48 +0100 Subject: [PATCH] image: add helpers to extract pixels to user buffers. --- docs/reference/libs/libs-sections.txt | 2 + gst-libs/gst/vaapi/gstvaapiimage.c | 84 +++++++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapiimage.h | 14 ++++++ 3 files changed, 100 insertions(+) diff --git a/docs/reference/libs/libs-sections.txt b/docs/reference/libs/libs-sections.txt index 751ba64..cfd3189 100644 --- a/docs/reference/libs/libs-sections.txt +++ b/docs/reference/libs/libs-sections.txt @@ -307,6 +307,8 @@ gst_vaapi_image_get_plane_count gst_vaapi_image_get_plane gst_vaapi_image_get_pitch gst_vaapi_image_get_data_size +gst_vaapi_image_get_buffer +gst_vaapi_image_get_raw gst_vaapi_image_update_from_buffer GST_VAAPI_IMAGE diff --git a/gst-libs/gst/vaapi/gstvaapiimage.c b/gst-libs/gst/vaapi/gstvaapiimage.c index f0aa730..49a19e5 100644 --- a/gst-libs/gst/vaapi/gstvaapiimage.c +++ b/gst-libs/gst/vaapi/gstvaapiimage.c @@ -1138,6 +1138,90 @@ copy_image( } /** + * gst_vaapi_image_get_buffer: + * @image: a #GstVaapiImage + * @buffer: a #GstBuffer + * @rect: a #GstVaapiRectangle expressing a region, or %NULL for the + * whole image + * + * Transfers pixels data contained in the @image into the #GstBuffer. + * Both image structures shall have the same format. + * + * Return value: %TRUE on success + */ +gboolean +gst_vaapi_image_get_buffer( + GstVaapiImage *image, + GstBuffer *buffer, + GstVaapiRectangle *rect +) +{ + GstVaapiImagePrivate *priv; + GstVaapiImageRaw dst_image, src_image; + gboolean success; + + g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE); + g_return_val_if_fail(image->priv->is_constructed, FALSE); + g_return_val_if_fail(GST_IS_BUFFER(buffer), FALSE); + + priv = image->priv; + + if (!init_image_from_buffer(&dst_image, buffer)) + return FALSE; + if (dst_image.format != priv->format) + return FALSE; + if (dst_image.width != priv->width || dst_image.height != priv->height) + return FALSE; + + if (!_gst_vaapi_image_map(image, &src_image)) + return FALSE; + + success = copy_image(&dst_image, &src_image, rect); + + if (!_gst_vaapi_image_unmap(image)) + return FALSE; + + return success; +} + +/** + * gst_vaapi_image_get_raw: + * @image: a #GstVaapiImage + * @dst_image: a #GstVaapiImageRaw + * @buffer: a #GstBuffer + * @rect: a #GstVaapiRectangle expressing a region, or %NULL for the + * whole image + * + * Transfers pixels data contained in the @image into the #GstVaapiImageRaw. + * Both image structures shall have the same format. + * + * Return value: %TRUE on success + */ +gboolean +gst_vaapi_image_get_raw( + GstVaapiImage *image, + GstVaapiImageRaw *dst_image, + GstVaapiRectangle *rect +) +{ + GstVaapiImageRaw src_image; + gboolean success; + + g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE); + g_return_val_if_fail(image->priv->is_constructed, FALSE); + + if (!_gst_vaapi_image_map(image, &src_image)) + return FALSE; + + success = copy_image(dst_image, &src_image, rect); + + if (!_gst_vaapi_image_unmap(image)) + return FALSE; + + return success; +} + +/** * gst_vaapi_image_update_from_buffer: * @image: a #GstVaapiImage * @buffer: a #GstBuffer diff --git a/gst-libs/gst/vaapi/gstvaapiimage.h b/gst-libs/gst/vaapi/gstvaapiimage.h index 5b6557f..a2b5ba2 100644 --- a/gst-libs/gst/vaapi/gstvaapiimage.h +++ b/gst-libs/gst/vaapi/gstvaapiimage.h @@ -176,6 +176,20 @@ guint gst_vaapi_image_get_data_size(GstVaapiImage *image); gboolean +gst_vaapi_image_get_buffer( + GstVaapiImage *image, + GstBuffer *buffer, + GstVaapiRectangle *rect +); + +gboolean +gst_vaapi_image_get_raw( + GstVaapiImage *image, + GstVaapiImageRaw *dst_image, + GstVaapiRectangle *rect +); + +gboolean gst_vaapi_image_update_from_buffer( GstVaapiImage *image, GstBuffer *buffer, -- 2.7.4