[libcamera-devel,v3,3/5] libcamera: Overload ==/!= operators for BayerFormats
diff mbox series

Message ID 20210126184854.46156-4-sebastian.fricke@posteo.net
State Accepted
Headers show
Series
  • Improve BayerFormat class
Related show

Commit Message

Sebastian Fricke Jan. 26, 2021, 6:48 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@posteo.net>
---
 include/libcamera/internal/bayer_format.h |  6 ++++++
 src/libcamera/bayer_format.cpp            | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

Comments

Laurent Pinchart Jan. 26, 2021, 11:03 p.m. UTC | #1
Hi Sebastian,

Thank you for the patch.

On Tue, Jan 26, 2021 at 07:48:52PM +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@posteo.net>

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

> ---
>  include/libcamera/internal/bayer_format.h |  6 ++++++
>  src/libcamera/bayer_format.cpp            | 17 +++++++++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h
> index 62814154..5b8c1dc9 100644
> --- a/include/libcamera/internal/bayer_format.h
> +++ b/include/libcamera/internal/bayer_format.h
> @@ -57,6 +57,12 @@ 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 1acf91d4..d4e7f142 100644
> --- a/src/libcamera/bayer_format.cpp
> +++ b/src/libcamera/bayer_format.cpp
> @@ -215,6 +215,23 @@ std::string BayerFormat::toString() const
>  	return result;
>  }
>  
> +/**
> + * \brief Compare two BayerFormats for equality
> + * \return True if order, bitDepth and packing are equal, otherwise false.

s/\.$//

Same below. I'll update when applying the patches.

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

> + */
> +bool operator==(const BayerFormat &lhs, const BayerFormat &rhs)
> +{
> +	return lhs.order == rhs.order && lhs.bitDepth == rhs.bitDepth &&
> +	       lhs.packing == rhs.packing;
> +}
> +
> +/**
> + * \fn bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)
> + * \brief Compare two BayerFormats for inequality
> + * \return True if either order, bitdepth or packing are not equal, otherwise
> + * false.
> + */
> +
>  /**
>   * \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 62814154..5b8c1dc9 100644
--- a/include/libcamera/internal/bayer_format.h
+++ b/include/libcamera/internal/bayer_format.h
@@ -57,6 +57,12 @@  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 1acf91d4..d4e7f142 100644
--- a/src/libcamera/bayer_format.cpp
+++ b/src/libcamera/bayer_format.cpp
@@ -215,6 +215,23 @@  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;
+}
+
+/**
+ * \fn bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)
+ * \brief Compare two BayerFormats for inequality
+ * \return True if either order, bitdepth or packing are not equal, otherwise
+ * false.
+ */
+
 /**
  * \brief Convert a BayerFormat into the corresponding V4L2PixelFormat
  * \return The V4L2PixelFormat corresponding to this BayerFormat