video: Add API to parse the image orientation from a GstTagList
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Tue, 4 May 2021 19:50:59 +0000 (15:50 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 12 Oct 2021 20:27:34 +0000 (20:27 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1088>

subprojects/gst-plugins-base/gst-libs/gst/video/video.c
subprojects/gst-plugins-base/gst-libs/gst/video/video.h

index 21cc5a1..4e20baa 100644 (file)
@@ -237,3 +237,52 @@ gst_video_orientation_method_get_type (void)
 
   return (GType) video_orientation_method_type;
 }
+
+/**
+ * gst_video_orientation_from_tag:
+ * @taglist: A #GstTagList
+ * @method: The location where to return the orientation.
+ *
+ * Parses the "image-orientation" tag and transforms it into the
+ * #GstVideoOrientationMethod enum.
+ *
+ * Returns: TRUE if there was a valid "image-orientation" tag in the taglist.
+ *
+ * Since: 1.20
+ */
+gboolean
+gst_video_orientation_from_tag (GstTagList * taglist,
+    GstVideoOrientationMethod * method)
+{
+  gchar *orientation;
+  gboolean ret = TRUE;
+
+  g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE);
+  g_return_val_if_fail (method != NULL, FALSE);
+
+  if (!gst_tag_list_get_string (taglist, "image-orientation", &orientation))
+    return FALSE;
+
+  if (!g_strcmp0 ("rotate-0", orientation))
+    *method = GST_VIDEO_ORIENTATION_IDENTITY;
+  else if (!g_strcmp0 ("rotate-90", orientation))
+    *method = GST_VIDEO_ORIENTATION_90R;
+  else if (!g_strcmp0 ("rotate-180", orientation))
+    *method = GST_VIDEO_ORIENTATION_180;
+  else if (!g_strcmp0 ("rotate-270", orientation))
+    *method = GST_VIDEO_ORIENTATION_90L;
+  else if (!g_strcmp0 ("flip-rotate-0", orientation))
+    *method = GST_VIDEO_ORIENTATION_HORIZ;
+  else if (!g_strcmp0 ("flip-rotate-90", orientation))
+    *method = GST_VIDEO_ORIENTATION_UR_LL;
+  else if (!g_strcmp0 ("flip-rotate-180", orientation))
+    *method = GST_VIDEO_ORIENTATION_VERT;
+  else if (!g_strcmp0 ("flip-rotate-270", orientation))
+    *method = GST_VIDEO_ORIENTATION_UL_LR;
+  else
+    ret = FALSE;
+
+  g_free (orientation);
+
+  return ret;
+}
index 24a3a73..a1a6d1a 100644 (file)
@@ -172,6 +172,11 @@ GstSample *   gst_video_convert_sample       (GstSample     * sample,
                                               GstClockTime    timeout,
                                               GError       ** error);
 
+
+GST_VIDEO_API
+gboolean gst_video_orientation_from_tag (GstTagList * taglist,
+                                         GstVideoOrientationMethod * method);
+
 G_END_DECLS
 
 #include <gst/video/colorbalancechannel.h>