From patchwork Mon Nov 21 15:44:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17823 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 8BC74BE08B for ; Mon, 21 Nov 2022 15:44:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 579A86331A; Mon, 21 Nov 2022 16:44:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669045470; bh=QeE2XrkMAXBq+xIM6/xevcr7Oh2p3OxWkukLjNSxJy0=; 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=dxA1cyVSg/zweQUFx+YYsoAgyVuf0v4nIJ3toXEg9Jcc23LEvKvxy7FaQrA3n8/F/ ksqlVOCPQj1kae8lnMf8DRK/Rdv9jmUR0amaPZlGx/IV50kUpbcSVDmsfWfRr54ca3 ml4zpMGGa3svUwSpUVrmxujN5f0dOf75TbB+HWlxUlHiHuWXOP1FyeZj8PLVFujiir Q8Yjd9+dVlki4VFeHBdJjRHqMDoF6MkmbruuwwgiL3J/gFg0Q1Np+rE3WDVE7e2SgC zxHVSTQKjfglFa6qkjeYMxZgtwNLn5Jf5tZUEjPJtvlJ5t9GEIBoUajKIDRXfedVHn K/yazX600qYng== 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 CFD3E6331C for ; Mon, 21 Nov 2022 16:44:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SehATThx"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id s5so3250814wru.1 for ; Mon, 21 Nov 2022 07:44:27 -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=sEHYM3NRf6pMdIrl/YwUGcydrfNxZgsax8Tl7eXR3Tw=; b=SehATThxw9vxrhAuyH7ysnmC28L3/sknBySspmz29B6DqXBQCaWXJTIFU7c2+Y7vKr g6jkQa6FZ8GPDEB/nERMAG14TXF7TH0TL7k94Oc5HZMcVUtV8kAvv5BuOngfKBxMgPEV 2JLEjCxzpT9/02XmFM9Z/Q0noBFplJI3oynSlrXErJCYRdrbf9vk/FDiNWE4TDDyTakL ezTe/EEEm+WQUj+FZPTlUwdW3I17GgWvJyjT9KX8aCyEi99WcntK8x4wDoMvFSubGVz/ LttiR9gzxr7/CQs5kr964ohqDywX6F2ZpiIbyzREMIFDcd5v5b5JTaU4jflwxgMl2lwH WO8g== 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=sEHYM3NRf6pMdIrl/YwUGcydrfNxZgsax8Tl7eXR3Tw=; b=4LuNeCJEE5QkxgIIrnrp/EMIwYX3SCqN5u3iFGbw+Kh5IwxsNWOQ1SmQFhVjtSfdFq iY3AXMuFvollExL1o5x0gN1Z35XL5Qza6xyHnNDlNbEuRQoQPeuNUo4Mu3KRDh0CogLx JJtAA8LnTPo8pDu5OO2F/zI+6Z2rtlN9IP2yLl2m8is4coGfeyY9MUB/vS6PFxZeFtDk nzwj7Ts4aTslCUsot66qXakWrBoHnuTNPjJ9QVcVbUFTgB1xgG9xa0kIzpO/HaRdcFHT DvxvcBKOSLbJmalW1hDbPVze7/SFUr/Y2UkCAmk31qofI0gtyFEd4iWT0Xnl+hpRch2b R+Kw== X-Gm-Message-State: ANoB5pmQ7VO4y+38Lzi/gsFTOMoTu5C0pMDhEPZ75nV39x6akM86vJ7T S8cQ9cup6ARenjtG2dGYo7xZl0pgAoxaJg== X-Google-Smtp-Source: AA0mqf6zQnJqzgf/nomMAwRoqEhDmCE+X6/J2RNtRHIuS3sHPGcjZNqD95LoFnKvoBz/TO93FmucYQ== X-Received: by 2002:adf:ebc6:0:b0:241:c6d8:be83 with SMTP id v6-20020adfebc6000000b00241c6d8be83mr3671748wrn.454.1669045466951; Mon, 21 Nov 2022 07:44:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 07:44:26 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Nov 2022 15:44:17 +0000 Message-Id: <20221121154421.11732-2-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 1/5] libcamera: bayer_format: Add toMbusCode method 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" This makes it easier to perform transformations on Bayer type mbus codes by converting them to a BayerFormat, doing the transform, and then converting them back again. Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 78ba3969..3601dccb 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -47,6 +47,7 @@ public: } static const BayerFormat &fromMbusCode(unsigned int mbusCode); + unsigned int toMbusCode() const; bool isValid() const { return bitDepth != 0; } std::string toString() const; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index f27cc166..fdbc4af1 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -226,6 +226,17 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode) return it->second; } +/** + * \brief Retrieve the media bus code corresponding this this BayerFormat + * \return The corresponding media bus code, or zero if none was found + */ +unsigned int BayerFormat::toMbusCode() const +{ + auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(), + [this](const auto &i) { return i.second == *this; }); + return it != mbusCodeToBayer.end() ? it->first : 0; +} + /** * \fn BayerFormat::isValid() * \brief Return whether a BayerFormat is valid From patchwork Mon Nov 21 15:44:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17824 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 8F789BE08B for ; Mon, 21 Nov 2022 15:44:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CEE806331F; Mon, 21 Nov 2022 16:44:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669045470; bh=ElKufu7CMYATkuoiRAVdVvcfz+UvtRZPr92j7IB7HfU=; 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=31PEPtlXqQctIGSD+8bZHipmGItUUAD7/zitxH+Im/qWkhV2QXnpHhuzHn/WJQA55 IMoNx6d40sJ8S+XQP+vYHE2sMqIXnokpO0ut9JgLFGqo0abaBrySyd1Yk7L3umcF0J 1HKURnun3CR54pCbj3yTTFB9eHgaZ3nstsR2hZhdP49Dl/xg4JdGs+/i55JQ42HVv6 pP4cBXNMtDPIGoBd+MsG8M5rLwYVuzWFhhh5BAVSP67+LbpHWOsNusv+vgCkEaAOUE sEssguG+WR4BAIHtlfJxExketGLbaeDgGUr6yaGLIMhnkK0Nfs8gvaM7EwQqRYXPBR W/3bwQIuo963g== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A429963311 for ; Mon, 21 Nov 2022 16:44:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="tm44CIB5"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id i64-20020a1c3b43000000b003d016c21100so3479843wma.3 for ; Mon, 21 Nov 2022 07:44:28 -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=eZWGHVFGF7J1lGK7ZZU9Tff95PuQzoZ9l1symSVcbtA=; b=tm44CIB5IuCJuH5JD4u3iC+a2vOmjVZzqqhFHovCFdHF+byGhy7GhRDhvCd5coCo2y yghgLci/H+r0ARvKOrVV/Fv2xyBbN6OVOaH1yNavbt5zRyvfEQubciGioNist5rBIvIt OPzcG8wG48i2mCVjE7Ik8MDo3Y+qr1zqF9xsGYRF2Ek7nbr2PiIhHY2XwPOEcN4vb/Gp Ks42gaA43bFnSjKvZ4uYjkUP+nmWdKR6TC8JWKDm5UETQwbsrIPbLS0+V+cAyRyEBvSC SfLDo1FHc3ueOJ7UKJlP0Am/GfdxHqnOA+nZt22Lm80+htn0PTH4JQ7geIlJeXKRgabz vXKA== 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=eZWGHVFGF7J1lGK7ZZU9Tff95PuQzoZ9l1symSVcbtA=; b=cNYgYRMpaat5ZFtUagYhrccyWqQs+TpNRv6M/PrcF3qPr3RKUUeEoDiXp4Aygy++Km gzLznCU6oZikh6Yn6RMrA7dJO1kChkWtvMXVqxNtaVvKNLFQgwCRuK4Le1f8sR6YeKl0 2WZM9aWFIRM/bBTr+CaHXt+iogxcH++eHoAzM1mM+WGlZkAEOErhDszQpl15Vr65PBAU bpsRLIsLoUkVDjUCiGA/6kY5hEoWI7j4mJqCzy5Dun5wxghDO2LNpTDFe+UoJx78sEKx 1DkKtnYldfqPo3Hj5CWwuesXf7VqzdVK0F9dHzX6RKg5o6XHGtRZ7lB3ZAkNuxmsp5Jg uC7g== X-Gm-Message-State: ANoB5pk9V7YRXsz2NxVpMHTasNzoWcJsWeVxo9/A32voIqspg449WyVn /wsNT00bkadZ477R6s8azjgG8QPRfBBSXw== X-Google-Smtp-Source: AA0mqf4g+bJ9A7Bu9fHMTfU+RU7RDJdrH9LAK5p5kYo9tyBC9HIbRFfsJmJzxaAaoGpOpxozx4zqPw== X-Received: by 2002:a7b:ce8c:0:b0:3cf:8b2d:8cbc with SMTP id q12-20020a7bce8c000000b003cf8b2d8cbcmr2279440wmj.89.1669045467956; Mon, 21 Nov 2022 07:44:27 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 07:44:27 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Nov 2022 15:44:18 +0000 Message-Id: <20221121154421.11732-3-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 2/5] libcamera: camera_sensor: Do not clear camera flips when listing 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously the code used to clear the camnera's h and v flip bits when enumerating the supported formats so as to obtain any Bayer formats in the sensor's native (untransformed) orientation. However this fails when the camera is already in use elsewhere. Instead, we query the current state of the flip bits and transform the formats - which we obtain in their flipped orientation - back into their native orientation to be stored. Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 49 ++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 572a313a..cbac9e78 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -19,6 +19,8 @@ #include +#include + #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor_properties.h" @@ -108,18 +110,45 @@ int CameraSensor::init() return ret; /* - * Clear any flips to be sure we get the "native" Bayer order. This is - * harmless for sensors where the flips don't affect the Bayer order. + * We want to get the native mbus codes for the sensor, without any flips. + * We can't clear any flips here, so we have to read the current values + * (if the flip controls exist), decide whether they actually modify any + * output Bayer pattern, and finally undo their effect on the formats. + * + * First, check if the flip controls exist and if so read them. */ - ControlList ctrls(subdev_->controls()); - if (subdev_->controls().find(V4L2_CID_HFLIP) != subdev_->controls().end()) - ctrls.set(V4L2_CID_HFLIP, 0); - if (subdev_->controls().find(V4L2_CID_VFLIP) != subdev_->controls().end()) - ctrls.set(V4L2_CID_VFLIP, 0); - subdev_->setControls(&ctrls); + std::vector flipCtrlIds; + const struct v4l2_query_ext_ctrl *hflipInfo = subdev_->controlInfo(V4L2_CID_HFLIP); + const struct v4l2_query_ext_ctrl *vflipInfo = subdev_->controlInfo(V4L2_CID_VFLIP); + if (hflipInfo) + flipCtrlIds.push_back(V4L2_CID_HFLIP); + if (vflipInfo) + flipCtrlIds.push_back(V4L2_CID_VFLIP); + ControlList flipCtrls = subdev_->getControls(flipCtrlIds); + + /* Now construct a transform that would undo any flips. */ + Transform transform = Transform::Identity; + if (hflipInfo && flipCtrls.get(V4L2_CID_HFLIP).get() && + (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)) + transform |= Transform::HFlip; + if (vflipInfo && flipCtrls.get(V4L2_CID_VFLIP).get() && + (vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)) + transform |= Transform::VFlip; + + /* Finally get the formats, and apply the transform to the mbus codes. */ + auto formats = subdev_->formats(pad_); + for (const auto &format : formats) { + unsigned int mbusCode = format.first; + BayerFormat bayerFormat = BayerFormat::fromMbusCode(mbusCode); + + if (bayerFormat.isValid()) + mbusCode = bayerFormat.transform(transform).toMbusCode(); + + if (mbusCode) + formats_[mbusCode] = std::move(format.second); + } /* Enumerate, sort and cache media bus codes and sizes. */ - formats_ = subdev_->formats(pad_); if (formats_.empty()) { LOG(CameraSensor, Error) << "No image format found"; return -EINVAL; @@ -189,7 +218,7 @@ int CameraSensor::init() * \todo The control API ought to have a flag to specify if a control * is read-only which could be used below. */ - const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); + const ControlInfo hblank = subdev_->controls().at(V4L2_CID_HBLANK); const int32_t hblankMin = hblank.min().get(); const int32_t hblankMax = hblank.max().get(); 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 From patchwork Mon Nov 21 15:44:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17826 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 6AD6BBE08B for ; Mon, 21 Nov 2022 15:44:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 23EB46331D; Mon, 21 Nov 2022 16:44:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669045474; bh=wC/eouBOvKoHq7yHhH+rO6xXi0AvXprsYlXej4tsNSA=; 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=PsfOga6tkH9R3v56uXpOYi8g1QTGWKBDi93dp6wPd9Lgs7VH6Oma6ZdXRkMVcmrtR MCeyQ1F2Zrvogs3JVOZ3z4yBKrG5WWJ8eeWY8pcj1/+zdoL3BQ1ZIkoXvb6gYSZCWk Dg/koOB4kzEJxqNtD9D01mzx2hliXzQopcu1rMJulLSX2dz3UpaevK6wDTqyfc+tA0 FkFAhK7dxqL5nJK259Insmjzf8lZJt87M3luewzFvn1WkZiB2QHDQ8atISPC4qbpld z6662x0cdhNsxHCpRKJCygvl5HAltpbNl3jDhach5IvUbwMaqTISs1oE69s6OJjVFY eKj1ra/ge6AvA== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A5BF263321 for ; Mon, 21 Nov 2022 16:44:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZT6ZAYtp"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id m7-20020a05600c090700b003cf8a105d9eso9300877wmp.5 for ; Mon, 21 Nov 2022 07:44:30 -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=quSfxEw9Fkkx4YktgHt5yQsthxWzdQOrtAnA/xUQP+c=; b=ZT6ZAYtp9glbfNNZTNICrOkpInDgzxTRMxjuJM8C0wZAfnoYjUO1D1cKLRAaKlzOq8 YJ/L31Vbve1VJ1wlfKimER9LjnPkKPWjnXCwgnFuIVgousXwNaQJrIDQHFT9QlbIPBz9 MGesCvdkIE4d6xMvd1O4exDll0QEKMXWh7mpBFuz4U0K4rbgwuq4XxNfl9aMI9W1fXd5 dqrWGP66xZ0L1c3d5cMieYXLKFqSFnb8NQ+Qo6LaOiMRq6Wr5lIW6llprNWcipqPpWS7 U75zfKYhrbDsScqHV94V1U3AnPFbv6dcUPEe7asKUFoGF40LV+6MP0Jb3fKoTPsWITRW OWYA== 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=quSfxEw9Fkkx4YktgHt5yQsthxWzdQOrtAnA/xUQP+c=; b=Zj3lNl8L+mfi5wPLChP77oJFIASl638EnFrzV1B9tLvFcLo7Tinrr8EpCAdTP7mhxz ZMuZi7NIs9BGjmlqYLslHR9lH0bV6UOAnYUukqRxO46uz4EySkBaCXLbeLS88IcKU0j9 GxCTQelWlQYIR32pKY44JrJTKABcm1o4PFrBXwAWZGPda2Z2MtJPUxgb8pj52YJoQtu8 CUnpI9B1vhOqVruY+gxUTsackhHJAwBMKGt8GK5ISvndaFobRovfQjViF+8jz9Z2N+KG QI6SOGioyXQzn4Pdo4PZrCPov8zP0aAEoMA++36jFvKV7ti3doJrVtIpy4BvXpAhpNlr QeeQ== X-Gm-Message-State: ANoB5pl8fPt5VZ/c1ibmeijPF+zonSy0fnLqWz5S7p4kkSNvg3qnf4wO 7AO4q3ulg1rQ1V4E9lDSVcWNWJaSKGiM+Q== X-Google-Smtp-Source: AA0mqf4c0jTGN+VOM4QDuEdhqyN+8yCLNLCCczIG1idMBgQUorO+mlPf0wwE0Gew3R1l8fHu3KoMlA== X-Received: by 2002:a05:600c:3d8f:b0:3cf:6a4c:af8b with SMTP id bi15-20020a05600c3d8f00b003cf6a4caf8bmr17364274wmb.115.1669045469956; Mon, 21 Nov 2022 07:44:29 -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:29 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Nov 2022 15:44:20 +0000 Message-Id: <20221121154421.11732-5-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 4/5] libcamera: pipeline: simple: Set device's flip controls as previously 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" Set the horizontal and vertical flip controls by calling the device's setTransform method now that this no longer happens in CameraSensor::init(). The aim here is to preserve the previous behaviour. Signed-off-by: David Plowman --- src/libcamera/pipeline/simple/simple.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index a32de7f3..f25a8cc1 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -1120,6 +1120,9 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c) if (ret < 0) return ret; + /* Set up the video device's horizontal and vertical flips. */ + video->setTransform(c->transform); + /* Configure the video node. */ V4L2PixelFormat videoFormat = video->toV4L2PixelFormat(pipeConfig->captureFormat); From patchwork Mon Nov 21 15:44:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17827 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 22256BE08B for ; Mon, 21 Nov 2022 15:44:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D50096331F; Mon, 21 Nov 2022 16:44:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669045474; bh=bh9I5bRKF0w2MeqEa0N4v8iZ5H0zEkddiVq8N8dlwCM=; 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=z607aPOfgUnzHc02tBm+PeifNhJgtfjTYVpWBOumsHnkbpm9+uHgI1EO/2wL/CXde wFt5yUObdnbQnc3ug2WOzyfp/0EDYxuL6JdlVbwQnrgYK6ih8uh/qk3wCX5ou5gLF7 Vqz32h5Cdngl9xOlSJ8QrQgUwHmvgopIjx7sfXbO27pZW4PGGFukHjikOBdcjvAhtg 9/YQR2H980VixMsaWane0ku0ex0fczTxohWI9+bB4AooCvEGSdljmoZiQc6FYFB6OL w6if4qcUbdr00sMq1uNbRpG+SLYJsWGTZD5J7T7YaCyTlA2DQoYAEyZc2l3WIa1GTn EBvNaG4UkZynw== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 573236331D for ; Mon, 21 Nov 2022 16:44:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="WfgnXriR"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id x17so7005145wrn.6 for ; Mon, 21 Nov 2022 07:44:31 -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=41Mcjs494HINUeN/gt5bpH1WI2znT1tO4uWTxfMQSOU=; b=WfgnXriR+ocVLgADu71vi804rwTPNipJW/FWp85EJV8jq3O+vhU8+XpQob5fs7rBBH 54Up3Qa0TUco7uU5g59XwrzyyXiJmBtdoqRKb564eh6F4Mdd29O/I/9HY5b0/cCNswPS ZIhGiO/OdlMTHmCF+uU3DKF3Aa+8E7ja0ZuSfWZVPhLDFeYz77h06fKmGfXUyWfwClRy Knxg0icDYmZDKAPwolDvZI6jKJDJxR+3xMrP0DWfouJdxmR1xxsC2Mbc9VuDdv0gq9A/ wdov/RXHLHb5Qbebu08DPuCBz5M6V9ZKz9Vf/riu49CAsnFf10nqcQXgW+0I7/nFzFba ajYA== 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=41Mcjs494HINUeN/gt5bpH1WI2znT1tO4uWTxfMQSOU=; b=hDITbpCk7z1ELTxtLXPoVmXDVKhY1dYoe3UBPYus4RwYpMMHDEtNOXsR4xUeItePsh 0u30e47LKNEJ4j83uTwPolXvRKVymlhXHnoHCqObiQEtH/UZdIOajaWTSGrBhnQtwEkx bJyFsBkQE7KF4aL9ThavXFmtNHqgK20o+79sivBGXF1GfW1YKZf3M+SD1gv66PoJBH5r ACsGdyeYfDUmc75xB5yY2WJ+eds40KuUbztA51Gqgpozmuub14Eda9VPRb+cV9YL5eYn 9qHNoJ9HfGpZOnRQ8URsSiHBneeVAGKcV3hJEenFWCRf+GtM77JGM/DnDzozY99LKJ4m UAKw== X-Gm-Message-State: ANoB5pk9mrhZvwEy9LGt/7QwLd9/zbZIyUtIIR5UpvH50B4c+RskBepH bnVR5/gz/bJuUP3DHA0JjcN8Egpw6lg8pA== X-Google-Smtp-Source: AA0mqf4Z+lSas8hDiclCmDBwClgyYZ1eBq2i2tgoUJvsylsb8hJ0yPRIV8Km2a7UnWmc7965y4qDww== X-Received: by 2002:adf:f38a:0:b0:236:5270:7347 with SMTP id m10-20020adff38a000000b0023652707347mr11828327wro.35.1669045470730; Mon, 21 Nov 2022 07:44:30 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 07:44:30 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 21 Nov 2022 15:44:21 +0000 Message-Id: <20221121154421.11732-6-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 5/5] libcamera: pipeline: rkisp1: Set device's flip controls as previously 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" Set the horizontal and vertical flip controls by calling the device's setTransform method now that this no longer happens in CameraSensor::init(). The aim here is to preserve the previous behaviour. Signed-off-by: David Plowman --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 3d3a7086..f144fabd 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -632,6 +632,9 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) if (ret) return ret; + /* Set up the device's horizontal and vertical flips. */ + sensor->device()->setTransform(c->transform); + /* * Configure the format on the sensor output and propagate it through * the pipeline.