image: add helpers to extract pixels to user buffers.

This commit is contained in:
Gwenole Beauchesne 2012-01-05 10:29:48 +01:00
parent 13f00c67e6
commit 7f8eaa6cbf
3 changed files with 100 additions and 0 deletions

View file

@ -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
<SUBSECTION Standard>
GST_VAAPI_IMAGE

View file

@ -1137,6 +1137,90 @@ copy_image(
return TRUE;
}
/**
* 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

View file

@ -175,6 +175,20 @@ gst_vaapi_image_get_pitch(GstVaapiImage *image, guint plane);
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,