<div dir="ltr"><div dir="ltr"><div>Hello Rishikesh,</div><div><br></div><div>Thanks for the patch.</div><div><br></div><div>Subject line can be better as suggested by Nicolas: <br></div><div><br></div><div>gstreamer: convert from GStreamer to libcamera colorspace<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jul 3, 2022 at 9:34 AM Rishikesh Donadkar <<a href="mailto:rishikeshdonadkar@gmail.com" target="_blank">rishikeshdonadkar@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Libcamera StreamConfiguration class has colorSpace attribute, which<br>
holds the colorspace that is being applied to the camera after the<br>
validation of the camera configuration.<br>
<br>
Map between the libcamera colorspace and GStreamer colorimetry and find<br>
the closest colorimetry corresponding to the colorspace in stream<br>
configuration.<br></blockquote><div><br></div><div>s/Map between the libcamera colorspace and GStreamer colorimetr/Map the libcamera colorspace to GStreamer colorimetry.</div><div>  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Signed-off-by: Rishikesh Donadkar <<a href="mailto:rishikeshdonadkar@gmail.com" target="_blank">rishikeshdonadkar@gmail.com</a>><br>
---<br>
 src/gstreamer/gstlibcamera-utils.cpp | 71 ++++++++++++++++++++++++++++<br>
 1 file changed, 71 insertions(+)<br>
<br>
diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp<br>
index 3f242286..20c39919 100644<br>
--- a/src/gstreamer/gstlibcamera-utils.cpp<br>
+++ b/src/gstreamer/gstlibcamera-utils.cpp<br>
@@ -45,6 +45,34 @@ static struct {<br>
        /* \todo NV42 is used in libcamera but is not mapped in GStreamer yet. */<br>
 };<br>
<br>
+static const std::vector<std::pair<ColorSpace, std::string>> ColorSpaceTocolorimetry = {<br>
+       { ColorSpace::Srgb, GST_VIDEO_COLORIMETRY_SRGB },<br>
+       { ColorSpace::Rec709, GST_VIDEO_COLORIMETRY_BT709 },<br>
+       { ColorSpace::Rec2020, GST_VIDEO_COLORIMETRY_BT2020 },<br>
+};<br>
+<br>
+static const std::map<ColorSpace::Primaries, GstVideoColorPrimaries> ToGstVideoColorPrimaries = {<br>
+       { ColorSpace::Primaries::Smpte170m, GST_VIDEO_COLOR_PRIMARIES_SMPTE170M },<br>
+       { ColorSpace::Primaries::Rec709, GST_VIDEO_COLOR_PRIMARIES_BT709 },<br>
+       { ColorSpace::Primaries::Rec2020, GST_VIDEO_COLOR_PRIMARIES_BT2020 },<br>
+};<br>
+<br>
+static const std::map<ColorSpace::TransferFunction, GstVideoTransferFunction> ToGstVideoTransferFunction = {<br>
+       { ColorSpace::TransferFunction::Srgb, GST_VIDEO_TRANSFER_SRGB },<br>
+       { ColorSpace::TransferFunction::Rec709, GST_VIDEO_TRANSFER_BT709 },<br>
+};<br>
+<br>
+static const std::map<ColorSpace::YcbcrEncoding, GstVideoColorMatrix> ToGstVideoColorMatrix = {<br>
+       { ColorSpace::YcbcrEncoding::Rec601, GST_VIDEO_COLOR_MATRIX_BT601 },<br>
+       { ColorSpace::YcbcrEncoding::Rec709, GST_VIDEO_COLOR_MATRIX_BT709 },<br>
+       { ColorSpace::YcbcrEncoding::Rec2020, GST_VIDEO_COLOR_MATRIX_BT2020 },<br>
+};<br>
+<br>
+static const std::map<ColorSpace::Range, GstVideoColorRange> ToGstVideoColorRange = {<br>
+       { ColorSpace::Range::Full, GST_VIDEO_COLOR_RANGE_0_255 },<br>
+       { ColorSpace::Range::Limited, GST_VIDEO_COLOR_RANGE_16_235 },<br>
+};<br>
+<br>
 static GstVideoFormat<br>
 pixel_format_to_gst_format(const PixelFormat &format)<br>
 {<br>
@@ -87,6 +115,49 @@ bare_structure_from_format(const PixelFormat &format)<br>
        }<br>
 }<br>
<br>
+static const gchar *<br>
+colorimerty_from_colorspace(std::optional<ColorSpace> colorSpace)<br>
+{<br>
+       const gchar *colorimetry_str;<br>
+       GstVideoColorimetry colorimetry;<br>
+<br>
+       auto iterColorimetry = std::find_if(ColorSpaceTocolorimetry.begin(), ColorSpaceTocolorimetry.end(),<br>
+                                           [&colorSpace](const auto &item) {<br>
+                                                   return colorSpace == item.first;<br>
+                                           });<br>
+       if (iterColorimetry != ColorSpaceTocolorimetry.end()) {<br>
+               colorimetry_str = (gchar *)iterColorimetry->second.c_str();<br>
+               return colorimetry_str;<br>
+       }<br>
+<br>
+       auto iterPrimaries = ToGstVideoColorPrimaries.find(colorSpace->primaries);<br>
+       if (iterPrimaries != ToGstVideoColorPrimaries.end())<br>
+               colorimetry.primaries = iterPrimaries->second;<br>
+       else<br>
+               colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;<br>
+<br>
+       auto iterTransferFunction = ToGstVideoTransferFunction.find(colorSpace->transferFunction);<br>
+       if (iterTransferFunction != ToGstVideoTransferFunction.end())<br>
+               colorimetry.transfer = iterTransferFunction->second;<br>
+       else<br>
+               colorimetry.transfer = GST_VIDEO_TRANSFER_UNKNOWN;<br>
+<br>
+       auto iterYcbcrEncoding = ToGstVideoColorMatrix.find(colorSpace->ycbcrEncoding);<br>
+       if (iterYcbcrEncoding != ToGstVideoColorMatrix.end())<br>
+               colorimetry.matrix = iterYcbcrEncoding->second;<br>
+       else<br>
+               colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;<br>
+<br>
+       auto iterRange = ToGstVideoColorRange.find(colorSpace->range);<br>
+       if (iterRange != ToGstVideoColorRange.end())<br>
+               colorimetry.range = iterRange->second;<br>
+       else<br>
+               colorimetry.range = GST_VIDEO_COLOR_RANGE_UNKNOWN;<br>
+<br>
+       colorimetry_str = gst_video_colorimetry_to_string(&colorimetry);<br>
+       return colorimetry_str;<br>
+}<br>
+<br>
 GstCaps *<br>
 gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)<br>
 {<br>
-- <br>
2.25.1<br>
<br></blockquote><div><br></div><div>Regards,</div><div>Vedant Paranjape <br></div></div></div>