[PATCH 1/2] libcamera: v4l2: Implement the equality and inequality operators for V4L2DeviceFormat
Harvey Yang
chenghaoyang at chromium.org
Wed Oct 9 21:58:50 CEST 2024
From: Yunke Cao <yunkec at chromium.org>
The comparators allow us to compare format directly instead of
comparing each field.
Signed-off-by: Yunke Cao <yunkec at chromium.org>
Co-developed-by: Han-Lin Chen <hanlinchen at chromium.org>
Signed-off-by: Han-Lin Chen <hanlinchen at chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang at chromium.org>
Signed-off-by: Harvey Yang <chenghaoyang at chromium.org>
---
include/libcamera/internal/v4l2_videodevice.h | 6 +++++
src/libcamera/v4l2_videodevice.cpp | 27 +++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
index f021c2a01..9f53e37cd 100644
--- a/include/libcamera/internal/v4l2_videodevice.h
+++ b/include/libcamera/internal/v4l2_videodevice.h
@@ -182,6 +182,12 @@ public:
const std::string toString() const;
};
+bool operator==(const V4L2DeviceFormat &lhs, const V4L2DeviceFormat &rhs);
+static inline bool operator!=(const V4L2DeviceFormat &lhs, const V4L2DeviceFormat &rhs)
+{
+ return !(lhs == rhs);
+}
+
std::ostream &operator<<(std::ostream &out, const V4L2DeviceFormat &f);
class V4L2VideoDevice : public V4L2Device
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 14eba0561..1110fb535 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -437,6 +437,33 @@ const std::string V4L2DeviceFormat::toString() const
return ss.str();
}
+/**
+ * \brief Compare V4L2DeviceFormat for equality
+ * \return True if the two formats are identical, false otherwise
+ */
+bool operator==(const V4L2DeviceFormat &lhs, const V4L2DeviceFormat &rhs)
+{
+ if (!(lhs.fourcc == rhs.fourcc &&
+ lhs.size == rhs.size &&
+ lhs.colorSpace == rhs.colorSpace &&
+ lhs.planesCount == rhs.planesCount))
+ return false;
+
+ for (unsigned int i = 0; i < lhs.planesCount; ++i) {
+ if (lhs.planes[i].size != rhs.planes[i].size ||
+ lhs.planes[i].bpl != rhs.planes[i].bpl)
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * \fn bool operator!=(const V4L2DeviceFormat &lhs, const V4L2DeviceFormat &rhs)
+ * \brief Comparetwo formats for inequality
+ * \return True if the two formats are not identical, false otherwise
+ */
+
/**
* \brief Insert a text representation of a V4L2DeviceFormat into an output
* stream
--
2.47.0.rc0.187.ge670bccf7e-goog
More information about the libcamera-devel
mailing list