[libcamera-devel,v4,1/6] libcamera: formats: Reimplement V4L2 PixelFormatInfo::info()
diff mbox series

Message ID 20220802160136.63075-2-jacopo@jmondi.org
State Accepted
Headers show
Series
  • libcamera: Map multiple V4L2 formats to a single libcamera::format
Related show

Commit Message

Jacopo Mondi Aug. 2, 2022, 4:01 p.m. UTC
The PixelFormatInfo::info(const V4L2PixelFormat &format) function
returns the PixelFormatInfo associated with a V4L2 pixel format.

As the pixelFormatInfo map is indexed using PixelFormat and a V4L2
format can easily be converted to a PixelFormat, simply return
the info() function overload instead of maintaining two similar
implementations of the same function.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/formats.cpp | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Laurent Pinchart Aug. 2, 2022, 4:31 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Tue, Aug 02, 2022 at 06:01:31PM +0200, Jacopo Mondi via libcamera-devel wrote:
> The PixelFormatInfo::info(const V4L2PixelFormat &format) function
> returns the PixelFormatInfo associated with a V4L2 pixel format.
> 
> As the pixelFormatInfo map is indexed using PixelFormat and a V4L2
> format can easily be converted to a PixelFormat, simply return
> the info() function overload instead of maintaining two similar
> implementations of the same function.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/formats.cpp | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> index 283ecb3d89d8..53207b734143 100644
> --- a/src/libcamera/formats.cpp
> +++ b/src/libcamera/formats.cpp
> @@ -987,22 +987,14 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
>  }
>  
>  /**
> - * \brief Retrieve information about a pixel format
> + * \brief Retrieve information about a V4L2 pixel format
>   * \param[in] format The V4L2 pixel format
>   * \return The PixelFormatInfo describing the V4L2 \a format if known, or an
>   * invalid PixelFormatInfo otherwise
>   */
>  const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
>  {
> -	const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
> -					[format](auto pair) {
> -						return pair.second.v4l2Formats.single == format ||
> -						       pair.second.v4l2Formats.multi == format;
> -					});
> -	if (info == pixelFormatInfo.end())
> -		return pixelFormatInfoInvalid;
> -
> -	return info->second;
> +	return info(format.toPixelFormat());
>  }
>  
>  /**

Patch
diff mbox series

diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 283ecb3d89d8..53207b734143 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -987,22 +987,14 @@  const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
 }
 
 /**
- * \brief Retrieve information about a pixel format
+ * \brief Retrieve information about a V4L2 pixel format
  * \param[in] format The V4L2 pixel format
  * \return The PixelFormatInfo describing the V4L2 \a format if known, or an
  * invalid PixelFormatInfo otherwise
  */
 const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
 {
-	const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
-					[format](auto pair) {
-						return pair.second.v4l2Formats.single == format ||
-						       pair.second.v4l2Formats.multi == format;
-					});
-	if (info == pixelFormatInfo.end())
-		return pixelFormatInfoInvalid;
-
-	return info->second;
+	return info(format.toPixelFormat());
 }
 
 /**