From patchwork Sat Jul 23 09:53:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 16741 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 8D5FEBE173 for ; Sat, 23 Jul 2022 09:53:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 43C9F63318; Sat, 23 Jul 2022 11:53:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658570034; bh=bMoHreOwzOKKMc0amupIX1iTjk8koHqdj2oVGPGBVYc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=NT7yABd0KbQmChDxw6H+u4IJcFR+q3wN/FuJri+kh56dy+H2fDZG1On14V14EHWQ1 qfJBAoBeXECy/6WuiyfT9lG262753pbi/za8qexSF91KWq0nkiewQp2CkSzfE+m5nP MvSGRdyf8rC9WdfwKSubQfPuxAsiSRdjIhrZDXDBT66IGnn1ucCZqU7WMBovKsWomD SExSgVtMmAquVmaJLMYSXdkGifLgaToxEf1UxlltkOySSPB69a6zGBIDiZLpUB1aZn SZf6PPRH/MAaj1p+8qMDWgczMTmlTur4x2Ry1F0ZVK9f9EJqF5SvWYFYezzb73FdNz e+avTcTYTANxw== Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C2806330E for ; Sat, 23 Jul 2022 11:53:53 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 98CAD1BF209; Sat, 23 Jul 2022 09:53:48 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Sat, 23 Jul 2022 11:53:24 +0200 Message-Id: <20220723095330.43542-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095330.43542-1-jacopo@jmondi.org> References: <20220723095330.43542-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/8] libcamera: formats: Search PixelFormatInfo on multiple formats 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: jozef@mlich.cz, Pavel Machek Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The PixelFormatInfo::info(const V4L2PixelFormat &format) function returns the PixelFormatInfo associated with a V4L2 pixel format. As we prepare to associate multiple V4L2 formats to a single PixelFormatInfo rework the function to search the given V4L2 format in a list. Signed-off-by: Jacopo Mondi --- src/libcamera/formats.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index f7e9adc7ff77..86fc698a0f4e 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -994,10 +994,19 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format) */ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) { + auto matchFormats = [&format](const std::vector &formats) { + const auto &it = std::find_if(formats.begin(), formats.end(), + [&format](const V4L2PixelFormat &fmt) { + return format == fmt; + }); + + return it == formats.end() ? false : true; + }; + const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(), - [format](auto pair) { - return pair.second.v4l2Formats.single[0] == format || - pair.second.v4l2Formats.multi[0] == format; + [&matchFormats](auto &pair) { + return matchFormats(pair.second.v4l2Formats.single) || + matchFormats(pair.second.v4l2Formats.multi); }); if (info == pixelFormatInfo.end()) return pixelFormatInfoInvalid;