[libcamera-devel] [PATCH 3/6] libcamera: formats: PixelFormatInfo: Add v4l2 constructor

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Jun 29 23:46:03 CEST 2020


Hi Paul,

Thank you for the patch.

On Tue, Jun 30, 2020 at 12:14:08AM +0900, Paul Elder wrote:
> Add a constructor for PixelFormatInfo that takes a V4L2PixelFormat.

It's not a constructor, it's a lookup function.

> 
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
>  include/libcamera/internal/formats.h |  1 +
>  src/libcamera/formats.cpp            | 16 ++++++++++++++--
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h
> index dc19492..3c7440a 100644
> --- a/include/libcamera/internal/formats.h
> +++ b/include/libcamera/internal/formats.h
> @@ -44,6 +44,7 @@ public:
>  	bool isValid() const { return format.isValid(); }
>  
>  	static const PixelFormatInfo &info(const PixelFormat &format);
> +	static const PixelFormatInfo &info(const V4L2PixelFormat &format);
>  
>  	const char *name;
>  	PixelFormat format;
> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> index 88b5168..7029a94 100644
> --- a/src/libcamera/formats.cpp
> +++ b/src/libcamera/formats.cpp
> @@ -631,6 +631,8 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
>  
>  } /* namespace */
>  
> +static const PixelFormatInfo invalid{};

You can move this within the anonymous namespace and drop the static
keyword.

> +
>  /**
>   * \fn bool PixelFormatInfo::isValid() const
>   * \brief Check if the pixel format info is valid
> @@ -645,8 +647,6 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
>   */
>  const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
>  {
> -	static const PixelFormatInfo invalid{};
> -
>  	const auto iter = pixelFormatInfo.find(format);
>  	if (iter == pixelFormatInfo.end()) {
>  		LOG(Formats, Warning)
> @@ -658,4 +658,16 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
>  	return iter->second;
>  }
>  
> +const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)

Documentation please.

> +{
> +	auto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
> +				 [format](auto pair) {
> +					 return pair.second.v4l2Format == format;
> +				 });
> +	if (info == pixelFormatInfo.end())
> +		return invalid;
> +
> +	return info->second;
> +}
> +
>  } /* namespace libcamera */

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list