Message ID | 20241209174806.283905-5-barnabas.pocze@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
Quoting Barnabás Pőcze (2024-12-09 17:48:05) > I believe a simple range based for loop is easier to understand > here than `std::transform()`. Furthermore, using a for loop enables > the easy filtering of invalid pixel formats. > I agree, I find the std::transform() difficult to interpret. I prefer this - but it probably needs to be tested in the vivid pipeline handler and updated on that tree too to keep these consistent. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > --- > Documentation/guides/pipeline-handler.rst | 18 +++++++----------- > 1 file changed, 7 insertions(+), 11 deletions(-) > > diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst > index b65145e3a..a798733db 100644 > --- a/Documentation/guides/pipeline-handler.rst > +++ b/Documentation/guides/pipeline-handler.rst > @@ -827,9 +827,7 @@ To generate a ``StreamConfiguration``, you need a list of pixel formats and > frame sizes which are supported as outputs of the stream. You can fetch a map of > the ``V4LPixelFormat`` and ``SizeRange`` supported by the underlying output > device, but the pipeline handler needs to convert this to a > -``libcamera::PixelFormat`` type to pass to applications. We do this here using > -``std::transform`` to convert the formats and populate a new ``PixelFormat`` map > -as shown below. > +``libcamera::PixelFormat`` type to pass to applications. > > Continue adding the following code example to our ``generateConfiguration`` > implementation. > @@ -839,14 +837,12 @@ implementation. > std::map<V4L2PixelFormat, std::vector<SizeRange>> v4l2Formats = > data->video_->formats(); > std::map<PixelFormat, std::vector<SizeRange>> deviceFormats; > - std::transform(v4l2Formats.begin(), v4l2Formats.end(), > - std::inserter(deviceFormats, deviceFormats.begin()), > - [&](const decltype(v4l2Formats)::value_type &format) { > - return decltype(deviceFormats)::value_type{ > - format.first.toPixelFormat(), > - format.second > - }; > - }); > + > + for (auto &[v4l2PixelFormat, sizes] : v4l2Formats) { > + PixelFormat pixelFormat = v4l2PixelFormat.toPixelFormat(); > + if (pixelFormat.isValid()) > + deviceFormats.try_emplace(pixelFormat, std::move(sizes)); > + } > > The `StreamFormats`_ class holds information about the pixel formats and frame > sizes that a stream can support. The class groups size information by the pixel > -- > 2.47.1 >
diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst index b65145e3a..a798733db 100644 --- a/Documentation/guides/pipeline-handler.rst +++ b/Documentation/guides/pipeline-handler.rst @@ -827,9 +827,7 @@ To generate a ``StreamConfiguration``, you need a list of pixel formats and frame sizes which are supported as outputs of the stream. You can fetch a map of the ``V4LPixelFormat`` and ``SizeRange`` supported by the underlying output device, but the pipeline handler needs to convert this to a -``libcamera::PixelFormat`` type to pass to applications. We do this here using -``std::transform`` to convert the formats and populate a new ``PixelFormat`` map -as shown below. +``libcamera::PixelFormat`` type to pass to applications. Continue adding the following code example to our ``generateConfiguration`` implementation. @@ -839,14 +837,12 @@ implementation. std::map<V4L2PixelFormat, std::vector<SizeRange>> v4l2Formats = data->video_->formats(); std::map<PixelFormat, std::vector<SizeRange>> deviceFormats; - std::transform(v4l2Formats.begin(), v4l2Formats.end(), - std::inserter(deviceFormats, deviceFormats.begin()), - [&](const decltype(v4l2Formats)::value_type &format) { - return decltype(deviceFormats)::value_type{ - format.first.toPixelFormat(), - format.second - }; - }); + + for (auto &[v4l2PixelFormat, sizes] : v4l2Formats) { + PixelFormat pixelFormat = v4l2PixelFormat.toPixelFormat(); + if (pixelFormat.isValid()) + deviceFormats.try_emplace(pixelFormat, std::move(sizes)); + } The `StreamFormats`_ class holds information about the pixel formats and frame sizes that a stream can support. The class groups size information by the pixel
I believe a simple range based for loop is easier to understand here than `std::transform()`. Furthermore, using a for loop enables the easy filtering of invalid pixel formats. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- Documentation/guides/pipeline-handler.rst | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)