libs: utils: map GstVideoColorimetry to VAAPI VPP
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Tue, 4 Feb 2020 19:32:54 +0000 (11:32 -0800)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 5 Feb 2020 17:59:43 +0000 (09:59 -0800)
Fallback to VAProcColorStandardExplicit if there is no
1:1 mapping.

gst-libs/gst/vaapi/gstvaapiutils.c
gst-libs/gst/vaapi/gstvaapiutils.h

index 1169db3..925510d 100644 (file)
@@ -951,3 +951,39 @@ to_GstVaapiBufferMemoryType (guint va_type)
     return GST_VAAPI_BUFFER_MEMORY_TYPE_USER_PTR;
   return 0;
 }
+
+/**
+ * from_GstVideoColorimetry:
+ * @colorimetry: a #GstVideoColorimetry type
+ *
+ * VPP: maps the #GstVideoColorimetry type to the VAProcColorStandardType.  If
+ * @colorimetry is NULL or colorimetry->primaries are unknown, then returns
+ * VAProcColorStandardNone.  If there is no 1:1 correlation, then returns
+ * VAProcColorStandardExplicit.  Otherwise, the correlating
+ * VAProcColorStandardType is returned.
+ *
+ * Returns: a VAProcColorStandardType.
+ **/
+guint
+from_GstVideoColorimetry (const GstVideoColorimetry * const colorimetry)
+{
+  if (!colorimetry
+      || colorimetry->primaries == GST_VIDEO_COLOR_PRIMARIES_UNKNOWN)
+    return VAProcColorStandardNone;
+  if (gst_video_colorimetry_matches (colorimetry, GST_VIDEO_COLORIMETRY_BT709))
+    return VAProcColorStandardBT709;
+  /* NOTE: VAProcColorStandardBT2020 in VAAPI is the same as
+   * GST_VIDEO_COLORIMETRY_BT2020_10 in gstreamer. */
+  if (gst_video_colorimetry_matches (colorimetry,
+          GST_VIDEO_COLORIMETRY_BT2020_10))
+    return VAProcColorStandardBT2020;
+  if (gst_video_colorimetry_matches (colorimetry, GST_VIDEO_COLORIMETRY_BT601))
+    return VAProcColorStandardBT601;
+  if (gst_video_colorimetry_matches (colorimetry,
+          GST_VIDEO_COLORIMETRY_SMPTE240M))
+    return VAProcColorStandardSMPTE240M;
+  if (gst_video_colorimetry_matches (colorimetry, GST_VIDEO_COLORIMETRY_SRGB))
+    return VAProcColorStandardSRGB;
+
+  return VAProcColorStandardExplicit;
+}
index cf19fb3..b2c0867 100644 (file)
@@ -26,6 +26,7 @@
 #define GST_VAAPI_UTILS_H
 
 #include <glib.h>
+#include <gst/video/video.h>
 #include <va/va.h>
 
 /** calls vaInitialize() redirecting the logging mechanism */
@@ -166,4 +167,8 @@ G_GNUC_INTERNAL
 guint
 to_GstVaapiBufferMemoryType (guint va_type);
 
+G_GNUC_INTERNAL
+guint
+from_GstVideoColorimetry (const GstVideoColorimetry *const colorimetry);
+
 #endif /* GST_VAAPI_UTILS_H */