From patchwork Mon Nov 21 15:44:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17825 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 6EB9ABE08B for ; Mon, 21 Nov 2022 15:44:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3509B63325; Mon, 21 Nov 2022 16:44:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669045471; bh=/xob/2lXFWXaYu+2N0ziwYBo59RWstBN6r3+VQ2RiU8=; 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=BBRwieOI2Y4AGOhT3KbTy/he0qwmEfbiLm3kdOlF+WPCBLXc8Iw9VgWEHCYpbLtdE hHp3XGdpJjgjcDeWDFeDoVwksiSxruDkoKF51B87/ABG/upMoKb1RAvKuCp4PUHeUE Qde1SETPITAJqm/eCr4VBXMWf/2VQnXVRGu/cQUch+NBWfwbxGbrrSrBPfjOte7BdE vfRhU80hX5fJO1bF7olJ1gT0PchzMWFzJS2d4vTvQCvtNMfhw8iLDZB41u2kBlQrgu hc8r26yPdHRFiUa4HvysBzkeLAzvXU8EHTmMfRlMJcV3QigAfXcodKrrcCPRWX1czI ak0ULu6BjNNlg== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9023E6331C for ; Mon, 21 Nov 2022 16:44:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GR9SnSoq"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id j5-20020a05600c410500b003cfa9c0ea76so9304606wmi.3 for ; Mon, 21 Nov 2022 07:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=UblEo6hJaTrKvOBggprdXkJpOr0kkAuYVeBqmTZc4r0=; b=GR9SnSoqTTEueipSYNwDD3IRVz6ZDcqLdbpv0GmQXQMMJjREGfjNL2Y+9H57h4okCI xM8Wc5ItmCXpS+oQ6ns9ZPBtE4kviE9Zm/dxgDr0VjzlD5AFE/yaYK8T5tjH5/0lvd3G Tx17X4vUkrDoslb3mXD3HNBk7z0ELQ2lhfa9iyqScOTI9Z+SS9x9nMedm4QEOaJailIs MGQk5G2OOYtgUYGM0kns+yVNMSt6n2huvc7eCAch0cQURXRh7SIwZp1sjubquOmdckqN QonklYSJCOf4b4gM4HXlFIr9nXViTGA2m2P5z6eMS/X7CuHcUZhlm3u3in6eX8p14oJa 8dZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UblEo6hJaTrKvOBggprdXkJpOr0kkAuYVeBqmTZc4r0=; b=LkJ5XcB8En2+/9MEcczQbnr92361aAuMriuuVSKYC90O+Ioek29aSQzdtAU5PYxw1y hFcesmLAAhU4FzLrdNHNEqYpipnllXwi0lXLMRsqZNidgr7V46VLBn8cNEuEeAvt8E8f dfDmjPIUpkbCfYMuILc23ysvr7L35bTQIUPT1vG4ykr39QccOP+l8AMEgOW/ahTT/iJ0 XGq4l0G1dsZTJWlm1JD9vUnQPuYhXtvMQeDGSb3saGdpb6rakoYBPdq2jcJCk3jOvzhs K4rDqmDSrhRQ4nn7w9oGwAqKARak6nrbPV0vKTo4NYnUnuIDj5+T11OpuSGn2dh34YJs BI9A== X-Gm-Message-State: ANoB5plWcZfX7R+AX2QjC/DMBmgb+jQRgd6gUgxws+v8fpFJL++ivJpc 1ClnBjtFKhsOT/eUtutx4Icb931Yko36Jg== X-Google-Smtp-Source: AA0mqf7GBBb1B/gIxZzMsSuMu/dnZOYlyDlRGTVhW0l/doCF91l8XvhlhEQtEPpw/Ayj4nukbDPxFA== X-Received: by 2002:a7b:c4d8:0:b0:3cf:9bcd:5009 with SMTP id g24-20020a7bc4d8000000b003cf9bcd5009mr4565495wmk.196.1669045468844; Mon, 21 Nov 2022 07:44:28 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id t11-20020adff60b000000b0022e035a4e93sm11742257wrp.87.2022.11.21.07.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 07:44:28 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Nov 2022 15:44:19 +0000 Message-Id: <20221121154421.11732-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221121154421.11732-1-david.plowman@raspberrypi.com> References: <20221121154421.11732-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] libcamera: v4l2_device: Add setTransform method to set a device's flip controls 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The setTransform method provides a convenient way of setting the V4L2 device's horizontal and vertical flip controls (where these are available) according to a libcamera Transform. Additionally, the caller can ask not to set the controls but merely find out whether the transform is supported by the device. Signed-off-by: David Plowman --- include/libcamera/internal/v4l2_device.h | 3 ++ src/libcamera/v4l2_device.cpp | 37 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 75304be1..09f627de 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -21,6 +21,7 @@ #include #include +#include #include "libcamera/internal/formats.h" @@ -49,6 +50,8 @@ public: void updateControlInfo(); + Transform setTransform(Transform transform, bool test = false); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index c17b323f..34b17079 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -674,6 +674,43 @@ void V4L2Device::updateControlInfo() } } +/* + * \brief Set or test setting the device's flip controls according to \a transform + * \param[in] transform Transform to request + * \param[in] test If true, merely test what would be set, otherwise actually set it + * + * This function checks whether a given \a transform is supported by the device's + * V4L2_CID_HFLIP and V4L2_CID_VFLIP controls and optionally sets them. + * + * If \a test is true, it merely checks what the device can accept and returns what + * would be programmed into the device. If \a test is false, then the device is + * actually programmed with updated flip values too. + * + * \return The transform that has been or would be set + */ +Transform V4L2Device::setTransform(Transform transform, bool test) +{ + Transform actualTransform = Transform::Identity; + ControlList controls; + + if (controlInfo(V4L2_CID_HFLIP)) { + Transform hflip = transform & Transform::HFlip; + actualTransform |= hflip; + controls.set(V4L2_CID_HFLIP, static_cast(!!hflip)); + } + + if (controlInfo(V4L2_CID_VFLIP)) { + Transform vflip = transform & Transform::VFlip; + actualTransform |= vflip; + controls.set(V4L2_CID_HFLIP, static_cast(!!vflip)); + } + + if (!test) + setControls(&controls); + + return actualTransform; +} + /* * \brief Update the value of the first \a count V4L2 controls in \a ctrls using * values in \a v4l2Ctrls