From patchwork Thu Nov 10 14:45:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17768 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 5B5F8BE08B for ; Thu, 10 Nov 2022 14:46:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B38363094; Thu, 10 Nov 2022 15:46:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1668091569; 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=WpeXrLD5CPm62piMs4UAwYQv+RzQ+VlQroM0ITmSKctwiM3wKv9iGpkv1j7ubswUj I/Da9h6jINB5zB1YBn79UJPD/xvP5ixX+A6iDrMA5gio7WOVicvQp7U3qxxA9bd+9U 7I1qjWiY6BEG0KxgOUi5XQ5dxNqA8fVvNG5V7XcNEJkTgJIzttfuJI9VrDa2A0iBqC 2qUmjzenKn55LjSHI0P5WhatY/B5pqA5SDaaf0JOu126oJBwmwm66jlFKtrI5D0gSE pRPxv/TgjTk3HV5+S2ee6qPxcNrLlAdr9t4L31MvnRTdX7G+JYcLuWy0nJ39+8x8J4 yi238+POQWQUA== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D5A7D63075 for ; Thu, 10 Nov 2022 15:46:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DaGaZgbw"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id h9so2637504wrt.0 for ; Thu, 10 Nov 2022 06:46:05 -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=DaGaZgbwQo7L0PL3AIfkdqD0vlSeX3cidsIqvo4G2YXAjM0e0pc/jST/dBu9qL6uQc cDaf6hm1IHNHhx1R3ehLB5OkvnCu5uAhuzUB4DFpDEp5qoGmEcuyBvFQ8np/CuUCrfNi 63oBDqnwA+EDc29aA5vDFHwGWERI1y2ht3Hak2pJfUFvTrwgdSvc741GKNUYI4Zm0exE UtZnapI9y8+KXqjEvq9q2UjwVKBQjnzlcO4cI6NTmhkV3zkeIyvBzhQrD7NYtVQ3fKLO I3FO/xZinzHxLGTxA74cFPv4jcYgl7p3wg5zGT++uKdWKILl15szUxpN+MKOyhMSj9XP hAZQ== 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=BoLXo/wk9nfEhO/SjFkNqJxGH14jdGzUEwqLHItQ4sMn2rKW8r+743vH1zJDkxwNP8 rVIrEhaNXMmb00I8EjwWM2i4YLos0x7l8vAjgs6x0HUOEQGupqVSBI2wUOW60ZZVpX0s q4TnMXsoZxNFKrgwiTDtQs5DXWH0ikpaKsREsX7BY4MvXxMmgZ9sdzv7YAkHKyANmzLB I+0EYHsiu/kDUkDN1DJbhEcp3YzVwYNZHyx4PtTvs1eDbpTX5g3yx6SRDSDfAabcItC8 spNhTvXsCXdgIMEOSJXanK7zuzjVqpZwz0Dj944nck2RR5uoleYXRrg0Phs/iMrZqIUT lhAg== X-Gm-Message-State: ACrzQf3GW7CbOmktlc3VhOUhqkERA4/s3Wi/MZFFbC7Or2vT48zgsNcl dAihmVgWKinAeY1ZM6IsdQwiXZUYlR8Cig== X-Google-Smtp-Source: AMsMyM6LtC2baKMH+5sNxtA8LHewenjI7wZ6u2hJsdW/ggQuA98nlAx6BXjIYS40ZXlmJKRGhEzYOA== X-Received: by 2002:adf:db10:0:b0:231:bcaa:313b with SMTP id s16-20020adfdb10000000b00231bcaa313bmr39191143wri.142.1668091565174; Thu, 10 Nov 2022 06:46:05 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id u24-20020a7bc058000000b003b476cabf1csm5249759wmc.26.2022.11.10.06.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 06:46:04 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 10 Nov 2022 14:45:53 +0000 Message-Id: <20221110144556.7858-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221110144556.7858-1-david.plowman@raspberrypi.com> References: <20221110144556.7858-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/6] 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