glutils: Export affine transformation functions for gtkglsink
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Tue, 29 Aug 2017 21:21:05 +0000 (17:21 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 12 Oct 2021 20:27:34 +0000 (20:27 +0000)
Also remove duplicated copy of those functions from the gl plugin

With contributions from Bastien Nocera

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1088>

subprojects/gst-plugins-base/ext/gl/gstglimagesink.c
subprojects/gst-plugins-base/ext/gl/gstgltransformation.c
subprojects/gst-plugins-base/ext/gl/gstglutils.c
subprojects/gst-plugins-base/ext/gl/gstglutils.h
subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c
subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.c
subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.h
subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils_private.h

index 35f24af..26b729e 100644 (file)
@@ -2409,10 +2409,10 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
       if (gl_sink->transform_matrix) {
         gfloat tmp[16];
 
-        gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, tmp);
+        gst_gl_get_affine_transformation_meta_as_ndc (af_meta, tmp);
         gst_gl_multiply_matrix4 (tmp, gl_sink->transform_matrix, matrix);
       } else {
-        gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, matrix);
+        gst_gl_get_affine_transformation_meta_as_ndc (af_meta, matrix);
       }
 
       gst_gl_shader_set_uniform_matrix_4fv (gl_sink->redisplay_shader,
index a5ca200..3a03b99 100644 (file)
@@ -807,7 +807,7 @@ gst_gl_transformation_prepare_output_buffer (GstBaseTransform * trans,
     GST_LOG_OBJECT (trans, "applying transformation to existing affine "
         "transformation meta");
 
-    gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, upstream);
+    gst_gl_get_affine_transformation_meta_as_ndc (af_meta, upstream);
 
     /* apply the transformation to the existing affine meta */
     graphene_matrix_init_from_float (&upstream_matrix, upstream);
@@ -822,7 +822,7 @@ gst_gl_transformation_prepare_output_buffer (GstBaseTransform * trans,
     graphene_matrix_multiply (&tmp, &yflip, &tmp2);
 
     graphene_matrix_to_float (&tmp2, downstream);
-    gst_gl_set_affine_transformation_meta_from_ndc_ext (af_meta, downstream);
+    gst_gl_set_affine_transformation_meta_from_ndc (af_meta, downstream);
 
     return GST_FLOW_OK;
   }
index 12209a6..bbbcb0f 100644 (file)
@@ -106,73 +106,3 @@ gst_gl_context_gen_shader (GstGLContext * context, const gchar * vert_src,
 
   return *shader != NULL;
 }
-
-static const gfloat identity_matrix[] = {
-  1.0, 0.0, 0.0, 0.0,
-  0.0, 1.0, 0.0, 0.0,
-  0.0, 0.0, 1.0, 0.0,
-  0.0, 0.0, 0.0, 1.0,
-};
-
-static const gfloat from_ndc_matrix[] = {
-  0.5, 0.0, 0.0, 0.0,
-  0.0, 0.5, 0.0, 0.0,
-  0.0, 0.0, 0.5, 0.0,
-  0.5, 0.5, 0.5, 1.0,
-};
-
-static const gfloat to_ndc_matrix[] = {
-  2.0, 0.0, 0.0, 0.0,
-  0.0, 2.0, 0.0, 0.0,
-  0.0, 0.0, 2.0, 0.0,
-  -1.0, -1.0, -1.0, 1.0,
-};
-
-void
-gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
-{
-  int i, j, k;
-  gfloat tmp[16] = { 0.0f };
-
-  if (!a || !b || !result)
-    return;
-
-  for (i = 0; i < 4; i++) {     /* column */
-    for (j = 0; j < 4; j++) {   /* row */
-      for (k = 0; k < 4; k++) {
-        tmp[j + (i * 4)] += a[k + (i * 4)] * b[j + (k * 4)];
-      }
-    }
-  }
-
-  for (i = 0; i < 16; i++)
-    result[i] = tmp[i];
-}
-
-void gst_gl_get_affine_transformation_meta_as_ndc_ext
-    (GstVideoAffineTransformationMeta * meta, gfloat * matrix)
-{
-  if (!meta) {
-    int i;
-
-    for (i = 0; i < 16; i++) {
-      matrix[i] = identity_matrix[i];
-    }
-  } else {
-    float tmp[16];
-
-    gst_gl_multiply_matrix4 (from_ndc_matrix, meta->matrix, tmp);
-    gst_gl_multiply_matrix4 (tmp, to_ndc_matrix, matrix);
-  }
-}
-
-void gst_gl_set_affine_transformation_meta_from_ndc_ext
-    (GstVideoAffineTransformationMeta * meta, const gfloat * matrix)
-{
-  float tmp[16];
-
-  g_return_if_fail (meta != NULL);
-
-  gst_gl_multiply_matrix4 (to_ndc_matrix, matrix, tmp);
-  gst_gl_multiply_matrix4 (tmp, from_ndc_matrix, meta->matrix);
-}
index bf567f6..ee7d4c6 100644 (file)
@@ -28,10 +28,6 @@ G_BEGIN_DECLS
 gboolean gst_gl_context_gen_shader (GstGLContext * context,
     const gchar * shader_vertex_source,
     const gchar * shader_fragment_source, GstGLShader ** shader);
-void gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result);
-void gst_gl_get_affine_transformation_meta_as_ndc_ext (GstVideoAffineTransformationMeta *
-    meta, gfloat * matrix);
-void gst_gl_set_affine_transformation_meta_from_ndc_ext (GstVideoAffineTransformationMeta * meta, const gfloat * matrix);
 
 G_END_DECLS
 
index a08016b..14dabcb 100644 (file)
@@ -1616,7 +1616,7 @@ gst_gl_video_mixer_callback (gpointer stuff)
           gst_video_aggregator_pad_get_current_buffer (vagg_pad);
 
       af_meta = gst_buffer_get_video_affine_transformation_meta (buffer);
-      gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, af_matrix);
+      gst_gl_get_affine_transformation_meta_as_ndc (af_meta, af_matrix);
       gst_gl_multiply_matrix4 (af_matrix, pad->m_matrix, matrix);
       gst_gl_shader_set_uniform_matrix_4fv (video_mixer->shader,
           "u_transformation", 1, FALSE, matrix);
index 52fa7d8..5e4f92e 100644 (file)
@@ -810,17 +810,28 @@ static const gfloat to_ndc_matrix[] = {
   -1.0, -1.0, -1.0, 1.0,
 };
 
-/* multiplies two 4x4 matrices, @a X @b, and stores the result in @result
- * https://en.wikipedia.org/wiki/Matrix_multiplication
+/**
+ * gst_gl_multiply_matrix4:
+ * @a: (array fixed-size=16): a 2-dimensional 4x4 array of #gfloat
+ * @b: (array fixed-size=16): another 2-dimensional 4x4 array of #gfloat
+ * @result: (out) (array fixed-size=16): the result of the multiplication
+ *
+ * Multiplies two 4x4 matrices, @a and @b, and stores the result, a
+ * 2-dimensional array of #gfloat, in @result.
+ *
+ * Since: 1.20
  */
-static void
+/* https://en.wikipedia.org/wiki/Matrix_multiplication */
+void
 gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
 {
   int i, j, k;
   gfloat tmp[16] = { 0.0f };
 
-  if (!a || !b || !result)
-    return;
+  g_return_if_fail (a != NULL);
+  g_return_if_fail (b != NULL);
+  g_return_if_fail (result != NULL);
+
   for (i = 0; i < 4; i++) {     /* column */
     for (j = 0; j < 4; j++) {   /* row */
       for (k = 0; k < 4; k++) {
@@ -833,7 +844,7 @@ gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
     result[i] = tmp[i];
 }
 
-/*
+/**
  * gst_gl_get_affine_transformation_meta_as_ndc:
  * @meta: (nullable): a #GstVideoAffineTransformationMeta
  * @matrix: (out): result of the 4x4 matrix
@@ -845,11 +856,15 @@ gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
  * - x - [-1, 1] - +ve X moves right
  * - y - [-1, 1] - +ve Y moves up
  * - z - [-1, 1] - +ve Z moves into
+ *
+ * Since: 1.20
  */
 void
 gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta *
     meta, gfloat * matrix)
 {
+  g_return_if_fail (matrix != NULL);
+
   if (!meta) {
     int i;
 
@@ -865,12 +880,23 @@ gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta *
   }
 }
 
+/**
+ * gst_gl_set_affine_transformation_meta_from_ndc:
+ * @meta: a #GstVideoAffineTransformationMeta
+ * @matrix: a 4x4 matrix
+ *
+ * Set the 4x4 affine transformation matrix stored in @meta from the
+ * NDC coordinates in @matrix.
+ *
+ * Since: 1.20
+ */
 void gst_gl_set_affine_transformation_meta_from_ndc
     (GstVideoAffineTransformationMeta * meta, const gfloat * matrix)
 {
   float tmp[16];
 
   g_return_if_fail (meta != NULL);
+  g_return_if_fail (matrix != NULL);
 
   /* change of basis multiplications */
   gst_gl_multiply_matrix4 (to_ndc_matrix, matrix, tmp);
index bbae73e..b271454 100644 (file)
@@ -59,6 +59,15 @@ gboolean gst_gl_value_set_texture_target (GValue * value, GstGLTextureTarget tar
 GST_GL_API
 GstGLTextureTarget gst_gl_value_get_texture_target_mask (const GValue * value);
 
+GST_GL_API
+void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, gfloat * matrix);
+GST_GL_API
+void gst_gl_set_affine_transformation_meta_from_ndc (GstVideoAffineTransformationMeta * meta, const gfloat * matrix);
+
+GST_GL_API
+void gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result);
+
+
 G_END_DECLS
 
 #endif /* __GST_GL_UTILS_H__ */
index 5a314e3..9bc652d 100644 (file)
@@ -26,8 +26,6 @@
 G_BEGIN_DECLS
 
 G_GNUC_INTERNAL gboolean gst_gl_run_query (GstElement * element, GstQuery * query, GstPadDirection direction);
-G_GNUC_INTERNAL void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, gfloat * matrix);
-G_GNUC_INTERNAL void gst_gl_set_affine_transformation_meta_from_ndc (GstVideoAffineTransformationMeta * meta, const gfloat * matrix);
 
 G_END_DECLS