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

Message ID 20220706080030.30929-1-rishikeshdonadkar@gmail.com
State Superseded
Headers show
Series
  • [libcamera-devel,v2,1/5] gstreamer: convert from libcamera colorspace to GStreamer colorimetry.
Related show

Commit Message

Rishikesh Donadkar July 6, 2022, 8 a.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.

Map the libcamera colorspace to GStreamer colorimetry and find
the colorimetry corresponding to the colorspace that is being applied to
the camera. This colorimetry if found will be pushed in the caps.

Signed-off-by: Rishikesh Donadkar <rishikeshdonadkar@gmail.com>
---
 .vscode/settings.json                | 10 +++++++++
 src/gstreamer/gstlibcamera-utils.cpp | 32 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 .vscode/settings.json

Patch
diff mbox series

diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..ff799f4b
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,10 @@ 
+{
+    "files.associations": {
+        "hash_map": "cpp",
+        "*.tcc": "cpp",
+        "string": "cpp",
+        "unordered_map": "cpp",
+        "unordered_set": "cpp",
+        "string_view": "cpp"
+    }
+}
\ No newline at end of file
diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index c97c0d43..60ac8c8e 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,32 @@  bare_structure_from_format(const PixelFormat &format)
 	}
 }
 
+static gchar *
+colorimerty_from_colorspace(std::optional<ColorSpace> colorSpace)
+{
+	gchar *colorimetry_str = nullptr;
+	gchar *colorimetry_found = nullptr;
+	GstVideoColorimetry colorimetry;
+	gboolean isColorimetryValid;
+
+	auto iterColorimetry = std::find_if(ColorSpaceTocolorimetry.begin(), ColorSpaceTocolorimetry.end(),
+					    [&colorSpace](const auto &item) {
+						    return colorSpace == item.first;
+					    });
+	if (iterColorimetry != ColorSpaceTocolorimetry.end()) {
+		colorimetry_found = (gchar *)iterColorimetry->second.c_str();
+		isColorimetryValid = gst_video_colorimetry_from_string(&colorimetry, colorimetry_found);
+	}
+	if (isColorimetryValid) {
+		colorimetry_str = gst_video_colorimetry_to_string(&colorimetry);
+		return colorimetry_str;
+	} else {
+		g_free(colorimetry_found);
+		g_free(colorimetry_str);
+		return nullptr;
+	}
+}
+
 GstCaps *
 gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
 {