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

Message ID 20220707094402.28730-4-rishikeshdonadkar@gmail.com
State Superseded
Headers show
Series
  • Add colorimetry support to libcamera gstreamer element.
Related show

Commit Message

Rishikesh Donadkar July 7, 2022, 9:44 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 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Vedant Paranjape July 7, 2022, 12:27 p.m. UTC | #1
Hello Rishikesh,

Thanks for the patch.

> gstreamer:Convert between requested colorimetry and libcamera ColorSpace

You might want to fix the subject line s/gstreamer:Convert/gstreamer: Convert

On Thu, Jul 7, 2022 at 11:45 AM Rishikesh Donadkar
<rishikeshdonadkar@gmail.com> wrote:
>
> Add map colorimetryToColorSpace and the function

s/Add map colorimetryToColorSpace/This patch adds a std::map called
colorimetryToColorSpace

Additionally, it might be good to describe in short what this map
stores, even though the name suggests so, there's no harm in adding
few words.

> colorspace_form_colorimetry() to convert from gstreamer colorimetry
> to libcamera colorspace. The obtained colorspace form the conversion

s/colorspace form/colorspace from

> will be applied to the colorSpace field of the StreamConfiguration.
>
> Signed-off-by: Rishikesh Donadkar <rishikeshdonadkar@gmail.com>
> ---
>  src/gstreamer/gstlibcamera-utils.cpp | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
> index eb9c49da..feefead9 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)
>  {
> @@ -119,6 +125,15 @@ colorimerty_from_colorspace(std::optional<ColorSpace> colorSpace)
>         }
>  }
>
> +void colorspace_form_colorimetry(std::optional<ColorSpace> &colorspace, const gchar *colorimetry)

This function is used local to this source file, it needs to be
defined static. Why not set the return type to
std::optional<ColorSpace> instead of passing a variable(colorspace) by
reference and setting value to it.

Regards,
Vedant Paranjape


> +{
> +       auto iterColorSpace = colorimetryToColorSpace.find(colorimetry);
> +       if (iterColorSpace != colorimetryToColorSpace.end()) {
> +               colorspace = iterColorSpace->second;
> +               return;
> +       }
> +}
> +
>  GstCaps *
>  gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
>  {
> --
> 2.25.1
>

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index eb9c49da..feefead9 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)
 {
@@ -119,6 +125,15 @@  colorimerty_from_colorspace(std::optional<ColorSpace> colorSpace)
 	}
 }
 
+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)
 {