From patchwork Wed Oct 9 19:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21577 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A5327C32DE for ; Wed, 9 Oct 2024 20:01:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5059965370; Wed, 9 Oct 2024 22:01:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Zt5UK26O"; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9894665371 for ; Wed, 9 Oct 2024 22:01:50 +0200 (CEST) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-20c71603217so1017185ad.3 for ; Wed, 09 Oct 2024 13:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728504109; x=1729108909; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FzDPFap4kC8SjqgFVhU4rzrHQGySD0ECn6sh9n9qdjo=; b=Zt5UK26ONuRzvmOilFsQNZ4cm5P0j8kWV9AIi/NOyPfKifYFVdKwyoEtyRbzBANxrq nonJIOUXsOhCCqVpqluVSaOzECTxxJ5twJ+OBxM9QmnaOkKb1uMc0ywGRDI9q5TurxCi 7ReyBSiyo6ZZEUMzM8JPk0u2C/9LVyhr0piGM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728504109; x=1729108909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzDPFap4kC8SjqgFVhU4rzrHQGySD0ECn6sh9n9qdjo=; b=XRJRX5w0h/9nxy0OKJpGGyc2smLbsnXJ3veoNDVeMTksgqIq1WrlMyJOhUcggCt4Rk 8mRaz/r68hrkGxbnhRAQymk6PauQC0dejSnm/LDQaUAGo82mqGOc8Si5hsCGTyfU/bl0 TY16D4Wone97RSAdKTwVBUNMeNFdgQnfpyl2UsArGc0hFWrN1CNbS0ql7hbrjba63NC0 HAz0EEkfON8cQDuo0gDmgBfndLAop98JJgDeSewMqWMsWMDnGGP5M9/HiIiRFvSawmRW jByMHkZxXnH4UwbeFfaHEbSC+x/AgcInDU1hE2wP+M4H8ZQ3bnezI0CYqBGyotWqbMJQ CtpA== X-Gm-Message-State: AOJu0YzfERPDKmvJ+nlCMMrMIjjHJlU4x+HCqBxu/+hNo4Rdosu+JJMR qJhJn4+t3VL9cNWyyOOQEPOIFh6cNBvDTo7pPT2kmKmyReD6WWRidA3Yw/FLflE2x6efOFJplzY = X-Google-Smtp-Source: AGHT+IEAwepNwtV5eH07CGknu+YhldCcgagEV2bbwQE4CabV+7plUxv5j4I8pg1uZvQcRPf3U6LRuw== X-Received: by 2002:a17:903:22cb:b0:20c:5404:ed6e with SMTP id d9443c01a7336-20c636db24emr48379505ad.8.1728504108794; Wed, 09 Oct 2024 13:01:48 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c54056b07sm30370205ad.64.2024.10.09.13.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 13:01:48 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yunke Cao , Han-Lin Chen , Harvey Yang Subject: [PATCH 1/2] libcamera: v4l2: Implement the equality and inequality operators for V4L2DeviceFormat Date: Wed, 9 Oct 2024 19:58:50 +0000 Message-ID: <20241009200142.3213065-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog In-Reply-To: <20241009200142.3213065-1-chenghaoyang@chromium.org> References: <20241009200142.3213065-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Yunke Cao The comparators allow us to compare format directly instead of comparing each field. Signed-off-by: Yunke Cao Co-developed-by: Han-Lin Chen Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- 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