[libcamera-devel,v3,3/5] gstreamer: Convert from GStreamer colorimetry to libcamera ColorSpace
diff mbox series

Message ID 20220711153711.36679-4-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
Add map colorimetryToColorSpace that maps the GStreamer colorimetry to
libcamera ColorSpace and the function colorspace_from_colorimetry()
to convert from gstreamer colorimetry to libcamera colorspace using the map.
The obtained colorspace form the conversion will be applied to the
colorSpace field of the StreamConfiguration.

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

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index a2d9b64d..5b3bfd70 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -51,6 +51,12 @@  static const std::vector<std::pair<ColorSpace, std::string>> ColorSpaceToColorim
 	{ ColorSpace::Rec2020, GST_VIDEO_COLORIMETRY_BT2020 },
 };
 
+static const std::map<std::string, ColorSpace> colorimetryToColorSpace = {
+	{ GST_VIDEO_COLORIMETRY_SRGB, ColorSpace::Srgb },
+	{ GST_VIDEO_COLORIMETRY_BT709, ColorSpace::Rec709 },
+	{ GST_VIDEO_COLORIMETRY_BT2020, ColorSpace::Rec2020 },
+};
+
 static GstVideoFormat
 pixel_format_to_gst_format(const PixelFormat &format)
 {
@@ -117,6 +123,18 @@  colorimetry_from_colorspace(ColorSpace colorSpace)
 	return colorimetry_gst_string;
 }
 
+static std::optional<ColorSpace>
+colorspace_from_colorimetry(const gchar *colorimetry)
+{
+	std::optional<ColorSpace> colorSpace;
+	auto iterColorSpace = colorimetryToColorSpace.find(colorimetry);
+	if (iterColorSpace != colorimetryToColorSpace.end()) {
+		colorSpace = iterColorSpace->second;
+	}
+
+	return colorSpace;
+}
+
 GstCaps *
 gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
 {