From patchwork Thu Jul 7 15:03:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16573 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 6A427BD1F1 for ; Thu, 7 Jul 2022 15:03:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8155C6048D; Thu, 7 Jul 2022 17:03:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657206215; bh=YjLFLMawFqx4ktHg3snvp3H1fxzHguA1o6Y9LJI0U/Y=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LbvEMdpTgFNvQfq7loH3KdpOlJ/EOXntYKUUKAwcdVNLP2jUl/S4/6gKh8yqbS0VA fN2Qqwwn/TYGXGtEftEFrar4uk5S5s0VKyPPKstDWPvTenjyjhRitg7dn9hS8XpXfE aCYoBcdIKCJeh/uXnvLZn+2NKmHvLKE3p0oW0VRegcDoApmaFGXAP4UhYOMOHNxaRa qtrKeKrH8h8cACgHzpmPNMkXANI0MhGek1yhUKi+2KsntSVJfYuzsskiul6NNtqC2y kVVX56kDLMNxscyruPivthUBK+o15b7FGc5V79tr3vxRNpx5uXO5xB8MPSIDb5Zplx cWtH+44nG1Exw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3E93960400 for ; Thu, 7 Jul 2022 17:03:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="osFyxhUS"; dkim-atps=neutral Received: from pyrite.rasen.tech (softbank036240121080.bbtec.net [36.240.121.80]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C31896CA; Thu, 7 Jul 2022 17:03:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657206214; bh=YjLFLMawFqx4ktHg3snvp3H1fxzHguA1o6Y9LJI0U/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=osFyxhUSCsDWV4D9+mM7V/4PE3FHb7ctSMfnz+4pZUPknQQn/O6pBPVMoMhTdydbX ju/dKWSCW2C9nXNU6SLdTRgRUkbu8+Bt0JYDU6KSDm8LupJ+ab4H72dBnsWK0QLB4Y SSjIX6GrN6BZ/HlV02O+4lGb9b9hQfO2zQq66hAs= To: libcamera-devel@lists.libcamera.org Date: Fri, 8 Jul 2022 00:03:08 +0900 Message-Id: <20220707150310.3645858-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220707150310.3645858-1-paul.elder@ideasonboard.com> References: <20220707150310.3645858-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] libcamera: v4l2_pixelformat: Use multiplanar if single is unavailable 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: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Some formats, such as YVU422 (but *not* YUV422), YUV444, and YVU444, have only a multiplanar v4l2 format and no singleplanar format. When using V4L2PixelFormat::fromPixelFormat() to convert a libcamera format to V4L2PixelFormat, the default is to fetch the singleplanar format, and for those three formats an invalid format will be returned. The caller shouldn't be expected to check first if it should request the singleplanar or multiplanar version (that's the whole point of V4L2PixelFormat::fromPixelFormat()), so the solution that this patch implements is if fetching singleplanar/multiplanar fails, try fetching the other one. The side effect is that as most formats have only singleplanar v4l2 format and no multiplanar format, if a multiplanar format is request for these formats then the singleplanar one will be automatically returned. Since currently all callers of V4L2PixelFormat::fromPixelFormat() use the default singleplanar call, it is reasoned that this is not an issue. Signed-off-by: Paul Elder --- src/libcamera/v4l2_pixelformat.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 58fc4e9d..0d2bc350 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -321,7 +321,14 @@ V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat, if (!info.isValid()) return V4L2PixelFormat(); - return multiplanar ? info.v4l2Formats.multi : info.v4l2Formats.single; + V4L2PixelFormat ret = multiplanar ? info.v4l2Formats.multi + : info.v4l2Formats.single; + /* Try the other of multi/single if the proper one doesn't exist */ + if (!ret.isValid()) + ret = multiplanar ? info.v4l2Formats.single + : info.v4l2Formats.multi; + + return ret; } /**