From a90f6d5d67fc556e8c2109b1ccec32c76fd36381 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 20 Jul 2023 20:50:26 +1000 Subject: [PATCH] gl/format: add helper for returning the number of components in a GL format Part-of: --- girs/GstGL-1.0.gir | 26 ++++++++++++ .../gst-libs/gst/gl/gstglformat.c | 41 +++++++++++++++++++ .../gst-libs/gst/gl/gstglformat.h | 2 + 3 files changed, 69 insertions(+) diff --git a/girs/GstGL-1.0.gir b/girs/GstGL-1.0.gir index b719d23a86..4cfec0bdab 100644 --- a/girs/GstGL-1.0.gir +++ b/girs/GstGL-1.0.gir @@ -3914,6 +3914,19 @@ See also: gst_gl_filter_render_to_target() + + + + the number of components in a #GstGLFormat + + + + + the #GstGLFormat + + + + Get the unsized format and type from @format for usage in glReadPixels, glTex{Sub}Image*, glTexImage* and similar functions. @@ -10757,6 +10770,19 @@ The returned #GstGLContext will be shared with a GStreamer created OpenGL contex + + + + the number of components in a #GstGLFormat + + + + + the #GstGLFormat + + + + Get the unsized format and type from @format for usage in glReadPixels, glTex{Sub}Image*, glTexImage* and similar functions. diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c index 74ce48bd1b..4c7548bc4f 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.c @@ -415,6 +415,47 @@ gst_gl_format_type_from_sized_gl_format (GstGLFormat format, } } +/** + * gst_gl_format_n_components: + * @gl_format: the #GstGLFormat + * + * Returns: the number of components in a #GstGLFormat + * + * Since: 1.24 + */ +guint +gst_gl_format_n_components (GstGLFormat gl_format) +{ + switch (gl_format) { + case GST_GL_LUMINANCE: + case GST_GL_ALPHA: + case GST_GL_RED: + case GST_GL_R8: + case GST_GL_DEPTH_COMPONENT16: + case GST_GL_R16: + return 1; + case GST_GL_LUMINANCE_ALPHA: + case GST_GL_RG: + case GST_GL_RG8: + case GST_GL_DEPTH24_STENCIL8: + case GST_GL_RG16: + return 2; + case GST_GL_RGB: + case GST_GL_RGB8: + case GST_GL_RGB565: + case GST_GL_RGB16: + return 3; + case GST_GL_RGBA: + case GST_GL_RGBA8: + case GST_GL_RGBA16: + case GST_GL_RGB10_A2: + return 4; + default: + g_warn_if_reached (); + return 0; + } +} + /** * gst_gl_format_is_supported: * @context: a #GstGLContext diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.h index 0db5a1422a..c85061dee3 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglformat.h @@ -154,6 +154,8 @@ void gst_gl_format_type_from_sized_gl_format (GstGLFormat GST_GL_API gboolean gst_gl_format_is_supported (GstGLContext * context, GstGLFormat format); +GST_GL_API +guint gst_gl_format_n_components (GstGLFormat gl_format); GST_GL_API GstGLTextureTarget gst_gl_texture_target_from_string (const gchar * str);