2 * Copyright (C) <2014> Collabora Ltd.
3 * Author: Matthieu Bouron <matthieu.bouron@gmail.com>
4 * Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
25 #include "gstvideoaffinetransformationmeta.h"
30 * SECTION:gstvideoaffinetransformationmeta
31 * @title: GstVideoAffineTransformationMeta
32 * @short_description: GstMeta for video affine transformation
37 gst_video_affine_transformation_meta_api_get_type (void)
39 static GType type = 0;
40 static const gchar *tags[] =
41 { GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_ORIENTATION_STR,
42 GST_META_TAG_VIDEO_ORIENTATION_STR, NULL
45 if (g_once_init_enter (&type)) {
47 gst_meta_api_type_register ("GstVideoAffineTransformationAPI", tags);
48 g_once_init_leave (&type, _type);
54 gst_video_affine_transformation_meta_transform (GstBuffer * dest,
55 GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data)
57 GstVideoAffineTransformationMeta *dmeta, *smeta;
59 smeta = (GstVideoAffineTransformationMeta *) meta;
61 if (GST_META_TRANSFORM_IS_COPY (type)) {
63 (GstVideoAffineTransformationMeta *) gst_buffer_add_meta (dest,
64 GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO, NULL);
69 memcpy (dmeta->matrix, smeta->matrix, sizeof (dmeta->matrix[0]) * 16);
75 gst_video_affine_transformation_meta_init (GstMeta * meta, gpointer params,
78 GstVideoAffineTransformationMeta *af_meta =
79 (GstVideoAffineTransformationMeta *) meta;
81 1.0f, 0.0f, 0.0f, 0.0f,
82 0.0f, 1.0f, 0.0f, 0.0f,
83 0.0f, 0.0f, 1.0f, 0.0f,
84 0.0f, 0.0f, 0.0f, 1.0f
87 memcpy (af_meta->matrix, matrix, sizeof (matrix[0]) * 16);
93 gst_video_affine_transformation_meta_get_info (void)
95 static const GstMetaInfo *info = NULL;
97 if (g_once_init_enter ((GstMetaInfo **) & info)) {
98 const GstMetaInfo *meta =
99 gst_meta_register (GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE,
100 "GstVideoAffineTransformationMeta",
101 sizeof (GstVideoAffineTransformationMeta),
102 gst_video_affine_transformation_meta_init,
104 gst_video_affine_transformation_meta_transform);
105 g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta);
111 * gst_buffer_add_video_affine_transformation_meta:
112 * @buffer: a #GstBuffer
114 * Attaches GstVideoAffineTransformationMeta metadata to @buffer with
115 * the given parameters.
117 * Returns: (transfer none): the #GstVideoAffineTransformationMeta on @buffer.
121 GstVideoAffineTransformationMeta *
122 gst_buffer_add_video_affine_transformation_meta (GstBuffer * buffer)
124 GstVideoAffineTransformationMeta *meta;
126 g_return_val_if_fail (buffer != NULL, NULL);
129 (GstVideoAffineTransformationMeta *) gst_buffer_add_meta (buffer,
130 GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO, NULL);
139 * gst_video_affine_transformation_meta_apply_matrix:
140 * @meta: a #GstVideoAffineTransformationMeta
141 * @matrix: (array fixed-size=16): a 4x4 transformation matrix to be applied
143 * Apply a transformation using the given 4x4 transformation matrix.
144 * Performs the multiplication, meta->matrix X matrix.
148 void gst_video_affine_transformation_meta_apply_matrix
149 (GstVideoAffineTransformationMeta * meta, const gfloat matrix[16])
151 gfloat res[16] = { 0.0f };
154 for (i = 0; i < 4; i++) {
155 for (j = 0; j < 4; j++) {
156 for (k = 0; k < 4; k++) {
157 res[i + (j * 4)] += meta->matrix[i + (k * 4)] * matrix[k + (j * 4)];
162 memcpy (meta->matrix, res, sizeof (meta->matrix[0]) * 16);