From patchwork Thu Nov 3 10:40:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17751 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 C12FABD16B for ; Thu, 3 Nov 2022 10:40:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 355796307E; Thu, 3 Nov 2022 11:40:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667472038; bh=LaIhUXXzGrnIPHHMkC4s4z6uzHZMYuLgbu2UnjfMX2M=; 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=iLAMuaq3fre2wmwCsgRncaMJgVzeFKnf0/qszZ7fobRMNyFjP9Q+urPUnOsuEO1K+ tgIEqFy0spqVoJGXUIF8EIIlUXo9LMnvorLkrtzPwXboRlRnpTusGMWUWt9ME2YDh7 h1hfNKh4bG/ZEim1pPCf3qna/3TuZ/Zi0h7enKZcvSKwzSV4tUlSpTrm1/ztEjcbQO XjqFt1BnFkrYFn5MTwZ2fwlrzrOzVycuIHZq2t2025vxDRCnDF4IVyU7oJGoVdYMYM 96HVYPJmuwgJT/uZe10qgNxrQ/T6wj0C4CZ94RgmiSzDDouxSYcA8qj9BPSdAhcFbv QNVS71vI2rKzQ== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97A4963079 for ; Thu, 3 Nov 2022 11:40:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="S/gV4A4m"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id k8so2149189wrh.1 for ; Thu, 03 Nov 2022 03:40:34 -0700 (PDT) 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=4oWVlNVD+BhXaNoojUjft82Db7px57l5q5o4NalLCOU=; b=S/gV4A4mnys4csuvqcw+/zWhqKSmt1MMQl8dGXPGtJiCE2K8r1i3qhc5bYNJhadVKI Mhkg7j04y39+xiYLCIh6m/DRGjR9DwFOFsp2Prx4XapjdN73aCfkDL0b+m/4JzBxLb4a iVAdTsZm8b5uxfg65EhP+cOXM4KqhfXbg1oRN5oP6Q+PyHd1Fo0EFVTumbw8oMOsl2nl lkGisv82mxo8aX4oRpj1lc90Pevkir1nvsVEwcFgw31L9lV4LWQSVtW4ZJrZmoN7F5z9 wvYIiqjLBH8xqMYVyHTMdqUItY5+y2bNxlGFMd93HOpURwpf5wyFiHjfix+8lJNXUNYU C8VA== 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=4oWVlNVD+BhXaNoojUjft82Db7px57l5q5o4NalLCOU=; b=IUhUI5bxG+tbJI++YFFn6D+h78jYL7BXyYv/lYM3tyca7PonxBF2ImDwGUC6glwKOT 2Vj0Y5LeHs7fjCda099jpTce1WHomwqJnBp5Uz64m81sJp01iTBVERB164jfWvyks0Bi O6TglgyxAqgAdFsCNqextQkr1m2FK3bHHvN3qp0zePefbUfAkSt2OXUmgzoRXf2T7u44 Jqh5HisI2BzcNe3yIT0/x4MBX58rWb1JLQrRiedYgieDD8d4hrWQ3KaUFH6iTfcD29RB Wcly/PjLk1pTUdW6/Vyl5plfEZjAUeAH704+nGNszpWbhh7OTWRgENamzqkU10NVzmEX +bbA== X-Gm-Message-State: ACrzQf0R2rER89NC/FfaVnBnU0lPuRaZ/saYZI9kmZ7Y0t1ta/3esG3l THQLJCYJFuCmqTgtBo3BT7VWbcYDuiMhUA== X-Google-Smtp-Source: AMsMyM7RQlK85eyj6IuOjngut6Q+KBcr97ekiXL6FZvhg+dcXIzfIlAGMvNOQzL/j+P5oPPtXyZLcg== X-Received: by 2002:a5d:6b03:0:b0:236:d441:8f4e with SMTP id v3-20020a5d6b03000000b00236d4418f4emr11806556wrw.123.1667472033923; Thu, 03 Nov 2022 03:40:33 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id f15-20020a5d50cf000000b0022e36c1113fsm516363wrt.13.2022.11.03.03.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 03:40:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Nov 2022 10:40:27 +0000 Message-Id: <20221103104027.4197-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221103104027.4197-1-david.plowman@raspberrypi.com> References: <20221103104027.4197-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/2] 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 --- src/libcamera/camera_sensor.cpp | 51 +++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 572a313a..6670dfb9 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,51 @@ 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; + bool hasHflip = subdev_->controls().find(V4L2_CID_HFLIP) != subdev_->controls().end(); + bool hasVflip = subdev_->controls().find(V4L2_CID_VFLIP) != subdev_->controls().end(); + if (hasHflip) + flipCtrlIds.push_back(V4L2_CID_HFLIP); + if (hasVflip) + 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 (hasHflip && flipCtrls.get(V4L2_CID_HFLIP).get()) { + const struct v4l2_query_ext_ctrl *extCtrl = subdev_->controlInfo(V4L2_CID_HFLIP); + if (extCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT) + transform |= Transform::HFlip; + } + if (hasVflip && flipCtrls.get(V4L2_CID_VFLIP).get()) { + const struct v4l2_query_ext_ctrl *extCtrl = subdev_->controlInfo(V4L2_CID_VFLIP); + if (extCtrl->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); + bool valid = true; + + if (bayerFormat.isValid()) + mbusCode = bayerFormat.transform(transform).toMbusCode(valid); + + if (valid) + 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;