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,
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);
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;
}
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);
-}
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
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);
-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++) {
result[i] = tmp[i];
}
-/*
+/**
* gst_gl_get_affine_transformation_meta_as_ndc:
* @meta: (nullable): a #GstVideoAffineTransformationMeta
* @matrix: (out): result of the 4x4 matrix
* - 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;
}
}
+/**
+ * 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);
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__ */
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