[libcamera-devel,v1,4/5] gstreamer:Convert between requested colorimetry and libcamera ColorSpace
diff mbox series

Message ID 20220703073358.76643-4-rishikeshdonadkar@gmail.com
State Superseded
Headers show
Series
  • [libcamera-devel,v1,1/5] gstreamer: Convert form colorspace to colorimetry.
Related show

Commit Message

Rishikesh Donadkar July 3, 2022, 7:33 a.m. UTC
Add map colorimetryToColorSpace and the function
colorspace_form_colorimetry() to convert from gstreamer colorimetry
to libcamera colorspace. 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 | 15 +++++++++++++++
 src/gstreamer/gstlibcamera-utils.h   |  1 +
 2 files changed, 16 insertions(+)

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index 690a9f43..221100e9 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -73,6 +73,12 @@  static const std::map<ColorSpace::Range, GstVideoColorRange> ToGstVideoColorRang
 	{ ColorSpace::Range::Limited, GST_VIDEO_COLOR_RANGE_16_235 },
 };
 
+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)
 {
@@ -158,6 +164,15 @@  colorimerty_from_colorspace(std::optional<ColorSpace> colorSpace)
 	return colorimetry_str;
 }
 
+void colorspace_form_colorimetry(std::optional<ColorSpace> &colorspace, const gchar *colorimetry)
+{
+	auto iterColorSpace = colorimetryToColorSpace.find(colorimetry);
+	if (iterColorSpace != colorimetryToColorSpace.end()) {
+		colorspace = iterColorSpace->second;
+		return;
+	}
+}
+
 GstCaps *
 gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
 {
diff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h
index d54f1588..6aff6be0 100644
--- a/src/gstreamer/gstlibcamera-utils.h
+++ b/src/gstreamer/gstlibcamera-utils.h
@@ -20,6 +20,7 @@  void gst_libcamera_configure_stream_from_caps(libcamera::StreamConfiguration &st
 					      GstCaps *caps);
 void gst_libcamera_resume_task(GstTask *task);
 std::shared_ptr<libcamera::CameraManager> gst_libcamera_get_camera_manager(int &ret);
+void colorspace_form_colorimetry(std::optional<libcamera::ColorSpace> &colorspace, const gchar *colorimetry);
 
 /**
  * \class GLibLocker