[libcamera-devel,v3,2/5] gstreamer: Update the obtained colorimetry in caps.
diff mbox series

Message ID 20220711153711.36679-3-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
If the colorspace is set in the StreamConfiguration, convert the
libcamera colorspace to GStreamer colorimetry using the function
colorimetry_from_colorspace() which will take in the ColorSpace value
and return the gst string representation of the colorimetry.

If the colorimetry corresponding to the colorspace set in the
StreamConfiguration is not available in GStreamer remove the
field colorimetry from the caps structure if present.

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

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index 43837602..a2d9b64d 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -164,11 +164,24 @@  gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg
 {
 	GstCaps *caps = gst_caps_new_empty();
 	GstStructure *s = bare_structure_from_format(stream_cfg.pixelFormat);
+	gchar *colorimetry = nullptr;
+	std::optional<ColorSpace> colorspace = stream_cfg.colorSpace;
 
 	gst_structure_set(s,
 			  "width", G_TYPE_INT, stream_cfg.size.width,
 			  "height", G_TYPE_INT, stream_cfg.size.height,
 			  nullptr);
+
+	if (colorspace) {
+		ColorSpace colorspaceValue = colorspace.value();
+		colorimetry = colorimetry_from_colorspace(colorspaceValue);
+		if (colorimetry)
+			gst_structure_set(s, "colorimetry", G_TYPE_STRING, colorimetry, nullptr);
+		else
+			gst_structure_remove_fields(s, "colorimetry", nullptr);
+		
+	}
+
 	gst_caps_append_structure(caps, s);
 
 	return caps;