[libcamera-devel,v3,1/5] gstreamer: convert from libcamera colorspace to GStreamer colorimetry.
diff mbox series

Message ID 20220711153711.36679-2-rishikeshdonadkar@gmail.com
State Superseded
Headers show
Series
  • Add colorimetry support to libcamera gstreamer element.
Related show

Commit Message

Rishikesh Donadkar July 11, 2022, 3:37 p.m. UTC
Libcamera StreamConfiguration class has colorSpace attribute, which
holds the colorspace that is being applied to the camera after the
validation of the camera configuration.

Add a std::map that will map libcamera colorspace to GStreamer colorimetry and
find the colorimetry corresponding to the colorspace that is being applied to
the camera.If the colorimetry is found, the helper function
libcamera_colorimetry_to_gst_string() will take in a std::string representation
of colorimetry and convert it into G_TYPE_STRING so that it can be pushed into the
caps. No need to check if the colorimetry if found is valid as we are working with
known predefined colorimetry.

Signed-off-by: Rishikesh Donadkar <rishikeshdonadkar@gmail.com>
---
 src/gstreamer/gstlibcamera-utils.cpp | 30 ++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index c97c0d43..43837602 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -45,6 +45,12 @@  static struct {
 	/* \todo NV42 is used in libcamera but is not mapped in GStreamer yet. */
 };
 
+static const std::vector<std::pair<ColorSpace, std::string>> ColorSpaceToColorimetry = {
+	{ ColorSpace::Srgb, GST_VIDEO_COLORIMETRY_SRGB },
+	{ ColorSpace::Rec709, GST_VIDEO_COLORIMETRY_BT709 },
+	{ ColorSpace::Rec2020, GST_VIDEO_COLORIMETRY_BT2020 },
+};
+
 static GstVideoFormat
 pixel_format_to_gst_format(const PixelFormat &format)
 {
@@ -87,6 +93,30 @@  bare_structure_from_format(const PixelFormat &format)
 	}
 }
 
+static gchar *
+libcamera_colorimetry_to_gst_string(const std::string &colorimetry_str)
+{
+	gchar *colorimetry_gst_string = (gchar *)colorimetry_str.c_str();
+	return colorimetry_gst_string;
+}
+
+static gchar *
+colorimetry_from_colorspace(ColorSpace colorSpace)
+{
+	gchar *colorimetry_gst_string = nullptr;
+
+	auto iterColorimetry = std::find_if(ColorSpaceToColorimetry.begin(), ColorSpaceToColorimetry.end(),
+					    [&colorSpace](const auto &item) {
+						    return colorSpace == item.first;
+					    });
+	if (iterColorimetry != ColorSpaceToColorimetry.end()) {
+		const std::string &colrorimetry_string = iterColorimetry->second;
+		colorimetry_gst_string = libcamera_colorimetry_to_gst_string(colrorimetry_string);
+	}
+		
+	return colorimetry_gst_string;
+}
+
 GstCaps *
 gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
 {