mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
videometa: add GstVideoAffineTransformationMeta
Adds a simple 4x4 affine transformations meta for passing arbitrary transformations on buffers. Based on patch by Matthieu Bouron https://bugzilla.gnome.org/show_bug.cgi?id=731791
This commit is contained in:
parent
ff6d1a2a25
commit
0b98ed32ce
6 changed files with 241 additions and 0 deletions
|
@ -197,6 +197,7 @@
|
|||
</para>
|
||||
<xi:include href="xml/gstvideo.xml" />
|
||||
<xi:include href="xml/gstvideometa.xml" />
|
||||
<xi:include href="xml/gstvideoaffinetransformationmeta.xml" />
|
||||
<xi:include href="xml/gstvideooverlaycomposition.xml" />
|
||||
<xi:include href="xml/gstvideofilter.xml" />
|
||||
<xi:include href="xml/gstvideodither.xml" />
|
||||
|
|
|
@ -2625,6 +2625,18 @@ gst_video_gl_texture_upload_meta_api_get_type
|
|||
gst_video_gl_texture_upload_meta_get_info
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gstvideoaffinetransformationmeta</FILE>
|
||||
<INCLUDE>gst/video/gstvideoaffinetransformationmeta.h</INCLUDE>
|
||||
GstVideoAffineTransformationMeta
|
||||
gst_buffer_add_video_affine_transformation_meta
|
||||
gst_buffer_get_video_affine_transformation_meta
|
||||
gst_video_affine_transformation_meta_apply_matrix
|
||||
<SUBSECTION Standard>
|
||||
gst_video_affine_transformation_meta_api_get_type
|
||||
gst_video_affine_transformation_meta_get_info
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gstvideooverlaycomposition</FILE>
|
||||
<INCLUDE>gst/video/video-overlay-composition.h</INCLUDE>
|
||||
|
|
|
@ -35,6 +35,7 @@ libgstvideo_@GST_API_VERSION@_la_SOURCES = \
|
|||
gstvideosink.c \
|
||||
gstvideofilter.c \
|
||||
convertframe.c \
|
||||
gstvideoaffinetransformationmeta.c \
|
||||
gstvideometa.c \
|
||||
gstvideopool.c \
|
||||
videoorientation.c \
|
||||
|
@ -69,6 +70,7 @@ libgstvideo_@GST_API_VERSION@include_HEADERS = \
|
|||
gstvideosink.h \
|
||||
gstvideofilter.h \
|
||||
gstvideometa.h \
|
||||
gstvideoaffinetransformationmeta.h \
|
||||
gstvideopool.h \
|
||||
videoorientation.h \
|
||||
videooverlay.h \
|
||||
|
|
152
gst-libs/gst/video/gstvideoaffinetransformationmeta.c
Normal file
152
gst-libs/gst/video/gstvideoaffinetransformationmeta.c
Normal file
|
@ -0,0 +1,152 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2014> Collabora Ltd.
|
||||
* Author: Matthieu Bouron <matthieu.bouron@gmail.com>
|
||||
* Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "gstvideoaffinetransformationmeta.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
GType
|
||||
gst_video_affine_transformation_meta_api_get_type (void)
|
||||
{
|
||||
static volatile GType type = 0;
|
||||
static const gchar *tags[] =
|
||||
{ GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_ORIENTATION_STR,
|
||||
GST_META_TAG_VIDEO_ORIENTATION_STR, NULL
|
||||
};
|
||||
|
||||
if (g_once_init_enter (&type)) {
|
||||
GType _type =
|
||||
gst_meta_api_type_register ("GstVideoAffineTransformationAPI", tags);
|
||||
g_once_init_leave (&type, _type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_video_affine_transformation_meta_transform (GstBuffer * dest,
|
||||
GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data)
|
||||
{
|
||||
GstVideoAffineTransformationMeta *dmeta, *smeta;
|
||||
|
||||
smeta = (GstVideoAffineTransformationMeta *) meta;
|
||||
|
||||
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
||||
dmeta =
|
||||
(GstVideoAffineTransformationMeta *) gst_buffer_add_meta (dest,
|
||||
GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO, NULL);
|
||||
|
||||
if (!dmeta)
|
||||
return FALSE;
|
||||
|
||||
memcpy (dmeta->matrix, smeta->matrix, sizeof (dmeta->matrix[0]) * 16);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_video_affine_transformation_meta_init (GstMeta * meta, gpointer params,
|
||||
GstBuffer * buffer)
|
||||
{
|
||||
GstVideoAffineTransformationMeta *af_meta =
|
||||
(GstVideoAffineTransformationMeta *) meta;
|
||||
gfloat matrix[] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
memcpy (af_meta->matrix, matrix, sizeof (matrix[0]) * 16);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const GstMetaInfo *
|
||||
gst_video_affine_transformation_meta_get_info (void)
|
||||
{
|
||||
static const GstMetaInfo *info = NULL;
|
||||
|
||||
if (g_once_init_enter (&info)) {
|
||||
const GstMetaInfo *meta =
|
||||
gst_meta_register (GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE,
|
||||
"GstVideoAffineTransformationMeta",
|
||||
sizeof (GstVideoAffineTransformationMeta),
|
||||
gst_video_affine_transformation_meta_init,
|
||||
NULL,
|
||||
gst_video_affine_transformation_meta_transform);
|
||||
g_once_init_leave (&info, meta);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_add_video_affine_transformation_meta
|
||||
* @buffer: a #GstBuffer
|
||||
*
|
||||
* Attaches GstVideoAffineTransformationMeta metadata to @buffer with
|
||||
* the given parameters.
|
||||
*
|
||||
* Returns: the #GstVideoAffineTransformationMeta on @buffer.
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
GstVideoAffineTransformationMeta *
|
||||
gst_buffer_add_video_affine_transformation_meta (GstBuffer * buffer)
|
||||
{
|
||||
GstVideoAffineTransformationMeta *meta;
|
||||
|
||||
g_return_val_if_fail (buffer != NULL, NULL);
|
||||
|
||||
meta =
|
||||
(GstVideoAffineTransformationMeta *) gst_buffer_add_meta (buffer,
|
||||
GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO, NULL);
|
||||
|
||||
if (!meta)
|
||||
return NULL;
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_affine_transformation_meta_apply_matrix:
|
||||
* @meta: a #GstVideoAffineTransformationMeta
|
||||
* @matrix: a 4x4 transformation matrix to be applied
|
||||
*
|
||||
* Apply a transformation using the given 4x4 transformation matrix
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
void gst_video_affine_transformation_meta_apply_matrix
|
||||
(GstVideoAffineTransformationMeta * meta, const gfloat matrix[16])
|
||||
{
|
||||
gfloat res[16] = { 0.0f };
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++) {
|
||||
res[i + (j * 4)] += meta->matrix[i + (k * 4)] * matrix[k + (j * 4)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy (meta->matrix, res, sizeof (meta->matrix[0]) * 16);
|
||||
}
|
70
gst-libs/gst/video/gstvideoaffinetransformationmeta.h
Normal file
70
gst-libs/gst/video/gstvideoaffinetransformationmeta.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) Collabora Ltd.
|
||||
* Author: Matthieu Bouron <matthieu.bouron@collabora.com>
|
||||
* Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_VIDEO_AFFINE_TRANSFORMATION_META_H__
|
||||
#define __GST_VIDEO_AFFINE_TRANSFORMATION_META_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE (gst_video_affine_transformation_meta_api_get_type())
|
||||
#define GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO (gst_video_affine_transformation_meta_get_info())
|
||||
|
||||
typedef struct _GstVideoAffineTransformationMeta GstVideoAffineTransformationMeta;
|
||||
typedef gboolean (*GstVideoAffineTransformationGetMatrix) (GstVideoAffineTransformationMeta * meta, gfloat * matrix);
|
||||
|
||||
#define GST_CAPS_FEATURE_META_GST_VIDEO_AFFINE_TRANSFORMATION_META "meta:GstVideoAffineTransformation"
|
||||
#define GST_BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META "GstBufferPoolOptionVideoAffineTransformation"
|
||||
|
||||
/**
|
||||
* GstVideoAffineTransformation:
|
||||
* @meta: parent #GstMeta
|
||||
* @matrix: the column-major 4x4 transformation matrix
|
||||
*
|
||||
* Extra buffer metadata for performing an affine transformation using a 4x4
|
||||
* matrix. The transformation matrix can be composed with
|
||||
* gst_video_affine_transformation_meta_apply_matrix().
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
|
||||
struct _GstVideoAffineTransformationMeta
|
||||
{
|
||||
GstMeta meta;
|
||||
|
||||
gfloat matrix[16];
|
||||
};
|
||||
|
||||
GType gst_video_affine_transformation_meta_api_get_type (void);
|
||||
const GstMetaInfo *gst_video_affine_transformation_meta_get_info (void);
|
||||
|
||||
#define gst_buffer_get_video_affine_transformation_meta(b) \
|
||||
((GstVideoAffineTransformationMeta *)gst_buffer_get_meta((b),GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE))
|
||||
GstVideoAffineTransformationMeta *gst_buffer_add_video_affine_transformation_meta (GstBuffer * buffer);
|
||||
|
||||
void gst_video_affine_transformation_meta_apply_matrix (GstVideoAffineTransformationMeta * meta,
|
||||
const gfloat matrix[16]);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_VIDEO_AFFINE_TRANSFORMATION_META_H__ */
|
|
@ -1,5 +1,6 @@
|
|||
EXPORTS
|
||||
_gst_video_decoder_error
|
||||
gst_buffer_add_video_affine_transformation_meta
|
||||
gst_buffer_add_video_gl_texture_upload_meta
|
||||
gst_buffer_add_video_meta
|
||||
gst_buffer_add_video_meta_full
|
||||
|
@ -51,6 +52,9 @@ EXPORTS
|
|||
gst_navigation_send_event
|
||||
gst_navigation_send_key_event
|
||||
gst_navigation_send_mouse_event
|
||||
gst_video_affine_transformation_meta_api_get_type
|
||||
gst_video_affine_transformation_meta_apply_matrix
|
||||
gst_video_affine_transformation_meta_get_info
|
||||
gst_video_alignment_reset
|
||||
gst_video_alpha_mode_get_type
|
||||
gst_video_blend
|
||||
|
|
Loading…
Reference in a new issue