2015-11-02 12:12:19 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
2018-04-28 13:50:11 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2015-11-02 12:12:19 +00:00
|
|
|
|
|
|
|
#include "gstvideoaffinetransformationmeta.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-04-02 13:08:48 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstvideoaffinetransformationmeta
|
|
|
|
* @title: GstVideoAffineTransformationMeta
|
|
|
|
* @short_description: GstMeta for video affine transformation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-11-02 12:12:19 +00:00
|
|
|
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;
|
|
|
|
|
2016-11-15 00:48:16 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & info)) {
|
2015-11-02 12:12:19 +00:00
|
|
|
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);
|
2016-11-15 00:48:16 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta);
|
2015-11-02 12:12:19 +00:00
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-23 19:36:11 +00:00
|
|
|
* gst_buffer_add_video_affine_transformation_meta:
|
2015-11-02 12:12:19 +00:00
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Attaches GstVideoAffineTransformationMeta metadata to @buffer with
|
|
|
|
* the given parameters.
|
|
|
|
*
|
2015-12-26 08:43:51 +00:00
|
|
|
* Returns: (transfer none): the #GstVideoAffineTransformationMeta on @buffer.
|
2015-11-02 12:12:19 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2017-08-24 09:11:29 +00:00
|
|
|
* Apply a transformation using the given 4x4 transformation matrix.
|
|
|
|
* Performs the multiplication, meta->matrix X matrix.
|
2015-11-02 12:12:19 +00:00
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
}
|