[libcamera-devel] [PATCH v1 1/5] gstreamer: Convert form colorspace to colorimetry.
Vedant Paranjape
vedantparanjape160201 at gmail.com
Tue Jul 5 15:37:40 CEST 2022
Hello Rishikesh,
Thanks for the patch.
Subject line can be better as suggested by Nicolas:
gstreamer: convert from GStreamer to libcamera colorspace
On Sun, Jul 3, 2022 at 9:34 AM Rishikesh Donadkar <
rishikeshdonadkar at gmail.com> wrote:
> Libcamera StreamConfiguration class has colorSpace attribute, which
> holds the colorspace that is being applied to the camera after the
> validation of the camera configuration.
>
> Map between the libcamera colorspace and GStreamer colorimetry and find
> the closest colorimetry corresponding to the colorspace in stream
> configuration.
>
s/Map between the libcamera colorspace and GStreamer colorimetr/Map the
libcamera colorspace to GStreamer colorimetry.
> Signed-off-by: Rishikesh Donadkar <rishikeshdonadkar at gmail.com>
> ---
> src/gstreamer/gstlibcamera-utils.cpp | 71 ++++++++++++++++++++++++++++
> 1 file changed, 71 insertions(+)
>
> diff --git a/src/gstreamer/gstlibcamera-utils.cpp
> b/src/gstreamer/gstlibcamera-utils.cpp
> index 3f242286..20c39919 100644
> --- a/src/gstreamer/gstlibcamera-utils.cpp
> +++ b/src/gstreamer/gstlibcamera-utils.cpp
> @@ -45,6 +45,34 @@ static struct {
> /* \todo NV42 is used in libcamera but is not mapped in GStreamer
> yet. */
> };
>
> +static const std::vector<std::pair<ColorSpace, std::string>>
> ColorSpaceTocolorimetry = {
> + { ColorSpace::Srgb, GST_VIDEO_COLORIMETRY_SRGB },
> + { ColorSpace::Rec709, GST_VIDEO_COLORIMETRY_BT709 },
> + { ColorSpace::Rec2020, GST_VIDEO_COLORIMETRY_BT2020 },
> +};
> +
> +static const std::map<ColorSpace::Primaries, GstVideoColorPrimaries>
> ToGstVideoColorPrimaries = {
> + { ColorSpace::Primaries::Smpte170m,
> GST_VIDEO_COLOR_PRIMARIES_SMPTE170M },
> + { ColorSpace::Primaries::Rec709, GST_VIDEO_COLOR_PRIMARIES_BT709 },
> + { ColorSpace::Primaries::Rec2020, GST_VIDEO_COLOR_PRIMARIES_BT2020
> },
> +};
> +
> +static const std::map<ColorSpace::TransferFunction,
> GstVideoTransferFunction> ToGstVideoTransferFunction = {
> + { ColorSpace::TransferFunction::Srgb, GST_VIDEO_TRANSFER_SRGB },
> + { ColorSpace::TransferFunction::Rec709, GST_VIDEO_TRANSFER_BT709 },
> +};
> +
> +static const std::map<ColorSpace::YcbcrEncoding, GstVideoColorMatrix>
> ToGstVideoColorMatrix = {
> + { ColorSpace::YcbcrEncoding::Rec601, GST_VIDEO_COLOR_MATRIX_BT601
> },
> + { ColorSpace::YcbcrEncoding::Rec709, GST_VIDEO_COLOR_MATRIX_BT709
> },
> + { ColorSpace::YcbcrEncoding::Rec2020,
> GST_VIDEO_COLOR_MATRIX_BT2020 },
> +};
> +
> +static const std::map<ColorSpace::Range, GstVideoColorRange>
> ToGstVideoColorRange = {
> + { ColorSpace::Range::Full, GST_VIDEO_COLOR_RANGE_0_255 },
> + { ColorSpace::Range::Limited, GST_VIDEO_COLOR_RANGE_16_235 },
> +};
> +
> static GstVideoFormat
> pixel_format_to_gst_format(const PixelFormat &format)
> {
> @@ -87,6 +115,49 @@ bare_structure_from_format(const PixelFormat &format)
> }
> }
>
> +static const gchar *
> +colorimerty_from_colorspace(std::optional<ColorSpace> colorSpace)
> +{
> + const gchar *colorimetry_str;
> + GstVideoColorimetry colorimetry;
> +
> + auto iterColorimetry =
> std::find_if(ColorSpaceTocolorimetry.begin(), ColorSpaceTocolorimetry.end(),
> + [&colorSpace](const auto
> &item) {
> + return colorSpace ==
> item.first;
> + });
> + if (iterColorimetry != ColorSpaceTocolorimetry.end()) {
> + colorimetry_str = (gchar *)iterColorimetry->second.c_str();
> + return colorimetry_str;
> + }
> +
> + auto iterPrimaries =
> ToGstVideoColorPrimaries.find(colorSpace->primaries);
> + if (iterPrimaries != ToGstVideoColorPrimaries.end())
> + colorimetry.primaries = iterPrimaries->second;
> + else
> + colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
> +
> + auto iterTransferFunction =
> ToGstVideoTransferFunction.find(colorSpace->transferFunction);
> + if (iterTransferFunction != ToGstVideoTransferFunction.end())
> + colorimetry.transfer = iterTransferFunction->second;
> + else
> + colorimetry.transfer = GST_VIDEO_TRANSFER_UNKNOWN;
> +
> + auto iterYcbcrEncoding =
> ToGstVideoColorMatrix.find(colorSpace->ycbcrEncoding);
> + if (iterYcbcrEncoding != ToGstVideoColorMatrix.end())
> + colorimetry.matrix = iterYcbcrEncoding->second;
> + else
> + colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
> +
> + auto iterRange = ToGstVideoColorRange.find(colorSpace->range);
> + if (iterRange != ToGstVideoColorRange.end())
> + colorimetry.range = iterRange->second;
> + else
> + colorimetry.range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
> +
> + colorimetry_str = gst_video_colorimetry_to_string(&colorimetry);
> + return colorimetry_str;
> +}
> +
> GstCaps *
> gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)
> {
> --
> 2.25.1
>
>
Regards,
Vedant Paranjape
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20220705/0bf80cd9/attachment.htm>
More information about the libcamera-devel
mailing list