[libcamera-devel,v2,2/4] libcamera: Overload ==/!= operators for BayerFormats
diff mbox series

Message ID 20201231155336.7058-3-sebastian.fricke.linux@gmail.com
State Superseded
Headers show
Series
  • Improve BayerFormat class
Related show

Commit Message

Sebastian Fricke Dec. 31, 2020, 3:53 p.m. UTC
Enable to test two Bayer formats for equality by checking if the order
of the color channels, the bit depth of the pattern, and the packing
scheme match. Additionally, add the reverse operation (!=), which negates
the equality test result.

Signed-off-by: Sebastian Fricke <sebastian.fricke.linux@gmail.com>
---
 include/libcamera/internal/bayer_format.h |  7 +++++++
 src/libcamera/bayer_format.cpp            | 10 ++++++++++
 2 files changed, 17 insertions(+)

Comments

Laurent Pinchart Jan. 11, 2021, 12:54 a.m. UTC | #1
Hi Sebastian,

Thank you for the patch.

On Thu, Dec 31, 2020 at 04:53:34PM +0100, Sebastian Fricke wrote:
> Enable to test two Bayer formats for equality by checking if the order
> of the color channels, the bit depth of the pattern, and the packing
> scheme match. Additionally, add the reverse operation (!=), which negates
> the equality test result.
> 
> Signed-off-by: Sebastian Fricke <sebastian.fricke.linux@gmail.com>
> ---
>  include/libcamera/internal/bayer_format.h |  7 +++++++
>  src/libcamera/bayer_format.cpp            | 10 ++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
> index 8efe1382..298756e3 100644
> --- a/include/libcamera/internal/bayer_format.h
> +++ b/include/libcamera/internal/bayer_format.h
> @@ -57,6 +57,13 @@ public:
>  	Packing packing;
>  };
>  
> +bool operator==(const BayerFormat &lhs, const BayerFormat &rhs);
> +static inline bool operator!=(const BayerFormat &lhs,
> +			      const BayerFormat &rhs)

This holds on a single line.

> +{
> +	return !(lhs == rhs);
> +}
> +
>  } /* namespace libcamera */
>  
>  #endif /* __LIBCAMERA_INTERNAL_BAYER_FORMAT_H__ */
> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
> index 26065b66..b8635e15 100644
> --- a/src/libcamera/bayer_format.cpp
> +++ b/src/libcamera/bayer_format.cpp
> @@ -160,6 +160,16 @@ std::string BayerFormat::toString() const
>  	return result;
>  }
>  
> +/**
> + * \brief Compare two BayerFormats for equality
> + * \return True if order, bitDepth and packing are equal, otherwise false
> + */
> +bool operator==(const BayerFormat &lhs, const BayerFormat &rhs)
> +{
> +	return lhs.order == rhs.order && lhs.bitDepth == rhs.bitDepth &&
> +	       lhs.packing == rhs.packing;
> +}

You should also document operator!=().

> +
>  /**
>   * \brief Convert a BayerFormat into the corresponding V4L2PixelFormat
>   * \return The V4L2PixelFormat corresponding to this BayerFormat

Patch
diff mbox series

diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
index 8efe1382..298756e3 100644
--- a/include/libcamera/internal/bayer_format.h
+++ b/include/libcamera/internal/bayer_format.h
@@ -57,6 +57,13 @@  public:
 	Packing packing;
 };
 
+bool operator==(const BayerFormat &lhs, const BayerFormat &rhs);
+static inline bool operator!=(const BayerFormat &lhs,
+			      const BayerFormat &rhs)
+{
+	return !(lhs == rhs);
+}
+
 } /* namespace libcamera */
 
 #endif /* __LIBCAMERA_INTERNAL_BAYER_FORMAT_H__ */
diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp
index 26065b66..b8635e15 100644
--- a/src/libcamera/bayer_format.cpp
+++ b/src/libcamera/bayer_format.cpp
@@ -160,6 +160,16 @@  std::string BayerFormat::toString() const
 	return result;
 }
 
+/**
+ * \brief Compare two BayerFormats for equality
+ * \return True if order, bitDepth and packing are equal, otherwise false
+ */
+bool operator==(const BayerFormat &lhs, const BayerFormat &rhs)
+{
+	return lhs.order == rhs.order && lhs.bitDepth == rhs.bitDepth &&
+	       lhs.packing == rhs.packing;
+}
+
 /**
  * \brief Convert a BayerFormat into the corresponding V4L2PixelFormat
  * \return The V4L2PixelFormat corresponding to this BayerFormat