From patchwork Thu Jul 2 23:11:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8567 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 83BFEBE905 for ; Thu, 2 Jul 2020 23:11:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 86E0260C5F; Fri, 3 Jul 2020 01:11:14 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D39B2609C7 for ; Fri, 3 Jul 2020 01:11:12 +0200 (CEST) X-Halon-ID: 51ebd0f5-bcb9-11ea-8fb8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 51ebd0f5-bcb9-11ea-8fb8-005056917f90; Fri, 03 Jul 2020 01:11:12 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 01:11:06 +0200 Message-Id: <20200702231107.1800602-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200702231107.1800602-1-niklas.soderlund@ragnatech.se> References: <20200702231107.1800602-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/2] libcamera: utils: Add map_keys() function 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: Laurent Pinchart Add a map_keys() function to the utils namespace to extract keys from a map. Signed-off-by: Laurent Pinchart [Niklas: change return type to std::vector instead of std::set] Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- include/libcamera/internal/utils.h | 10 ++++++++++ src/libcamera/utils.cpp | 7 +++++++ test/utils.cpp | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h index 0953423ee8d04466..8d026cc6c0fe777a 100644 --- a/include/libcamera/internal/utils.h +++ b/include/libcamera/internal/utils.h @@ -15,6 +15,7 @@ #include #include #include +#include #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) @@ -36,6 +37,15 @@ const char *basename(const char *path); char *secure_getenv(const char *name); std::string dirname(const std::string &path); +template +std::vector map_keys(const T &map) +{ + std::vector keys; + std::transform(map.begin(), map.end(), std::back_inserter(keys), + [](const auto &value) { return value.first; }); + return keys; +} + template unsigned int set_overlap(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index d55338fe681a8516..0567328fe31ba6f9 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -127,6 +127,13 @@ std::string dirname(const std::string &path) return path.substr(0, pos + 1); } +/** + * \fn std::vector map_keys(const T &map) + * \brief Retrieve the keys of a std::map<> + * \param[in] map The map whose keys to retrieve + * \return A std::vector<> containing the keys of \a map + */ + /** * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1, * InputIt2 first2, InputIt2 last2) diff --git a/test/utils.cpp b/test/utils.cpp index 66b91f1203e1f4e8..f482e6a1d829edbd 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -144,6 +145,27 @@ protected: if (TestPass != testDirname()) return TestFail; + + /* utils::map_keys() test. */ + const std::map map{ + { "zero", 0 }, + { "one", 1 }, + { "two", 2 }, + }; + std::vector expectedKeys{ + "zero", + "one", + "two", + }; + + std::sort(expectedKeys.begin(), expectedKeys.end()); + + const std::vector keys = utils::map_keys(map); + if (keys != expectedKeys) { + cerr << "utils::map_keys() test failed" << endl; + return TestFail; + } + return TestPass; } }; From patchwork Thu Jul 2 23:11:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8568 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 DF56DC2E69 for ; Thu, 2 Jul 2020 23:11:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A2DAE60C62; Fri, 3 Jul 2020 01:11:14 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B3B4603B3 for ; Fri, 3 Jul 2020 01:11:13 +0200 (CEST) X-Halon-ID: 524d1ce1-bcb9-11ea-8fb8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 524d1ce1-bcb9-11ea-8fb8-005056917f90; Fri, 03 Jul 2020 01:11:12 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 01:11:07 +0200 Message-Id: <20200702231107.1800602-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200702231107.1800602-1-niklas.soderlund@ragnatech.se> References: <20200702231107.1800602-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/2] libcamera: ipu3: cio2: Make use of utils::map_keys() helper 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" Use a helper instead of local code to retrieve all keys from a map. Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/cio2.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 97a434a73b2855e5..cb8c80a4a9ca538a 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -94,11 +94,7 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) * utils::set_overlap requires the ranges to be sorted, keep the * cio2Codes vector sorted in ascending order. */ - std::vector cio2Codes; - cio2Codes.reserve(mbusCodesToInfo.size()); - std::transform(mbusCodesToInfo.begin(), mbusCodesToInfo.end(), - std::back_inserter(cio2Codes), - [](auto &pair) { return pair.first; }); + std::vector cio2Codes = utils::map_keys(mbusCodesToInfo); const std::vector &sensorCodes = sensor_->mbusCodes(); if (!utils::set_overlap(sensorCodes.begin(), sensorCodes.end(), cio2Codes.begin(), cio2Codes.end())) { @@ -138,12 +134,7 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat) * Apply the selected format to the sensor, the CSI-2 receiver and * the CIO2 output device. */ - std::vector mbusCodes; - mbusCodes.reserve(mbusCodesToInfo.size()); - std::transform(mbusCodesToInfo.begin(), mbusCodesToInfo.end(), - std::back_inserter(mbusCodes), - [](auto &pair) { return pair.first; }); - + std::vector mbusCodes = utils::map_keys(mbusCodesToInfo); sensorFormat = sensor_->getFormat(mbusCodes, size); ret = sensor_->setFormat(&sensorFormat); if (ret) @@ -182,11 +173,7 @@ CIO2Device::generateConfiguration(Size size) const size = sensor_->resolution(); /* Query the sensor static information for closest match. */ - std::vector mbusCodes; - std::transform(mbusCodesToInfo.begin(), mbusCodesToInfo.end(), - std::back_inserter(mbusCodes), - [](auto &pair) { return pair.first; }); - + std::vector mbusCodes = utils::map_keys(mbusCodesToInfo); V4L2SubdeviceFormat sensorFormat = sensor_->getFormat(mbusCodes, size); if (!sensorFormat.mbus_code) { LOG(IPU3, Error) << "Sensor does not support mbus code";