{"id":17751,"url":"https://patchwork.libcamera.org/api/patches/17751/?format=json","web_url":"https://patchwork.libcamera.org/patch/17751/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221103104027.4197-3-david.plowman@raspberrypi.com>","date":"2022-11-03T10:40:27","name":"[libcamera-devel,RFC,2/2] libcamera: camera_sensor: Do not clear camera flips when listing formats","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2566cd0665d945f6e49bc51e12f528adb99ea91c","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17751/mbox/","series":[{"id":3595,"url":"https://patchwork.libcamera.org/api/series/3595/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3595","date":"2022-11-03T10:40:25","name":"Resolve invalid attempts to set sensor flip controls","version":1,"mbox":"https://patchwork.libcamera.org/series/3595/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17751/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17751/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C12FABD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  3 Nov 2022 10:40:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 355796307E;\n\tThu,  3 Nov 2022 11:40:38 +0100 (CET)","from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 97A4963079\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Nov 2022 11:40:34 +0100 (CET)","by mail-wr1-x433.google.com with SMTP id k8so2149189wrh.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 03 Nov 2022 03:40:34 -0700 (PDT)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tf15-20020a5d50cf000000b0022e36c1113fsm516363wrt.13.2022.11.03.03.40.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 03 Nov 2022 03:40:33 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1667472038;\n\tbh=LaIhUXXzGrnIPHHMkC4s4z6uzHZMYuLgbu2UnjfMX2M=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=iLAMuaq3fre2wmwCsgRncaMJgVzeFKnf0/qszZ7fobRMNyFjP9Q+urPUnOsuEO1K+\n\ttgIEqFy0spqVoJGXUIF8EIIlUXo9LMnvorLkrtzPwXboRlRnpTusGMWUWt9ME2YDh7\n\th1hfNKh4bG/ZEim1pPCf3qna/3TuZ/Zi0h7enKZcvSKwzSV4tUlSpTrm1/ztEjcbQO\n\tXjqFt1BnFkrYFn5MTwZ2fwlrzrOzVycuIHZq2t2025vxDRCnDF4IVyU7oJGoVdYMYM\n\t96HVYPJmuwgJT/uZe10qgNxrQ/T6wj0C4CZ94RgmiSzDDouxSYcA8qj9BPSdAhcFbv\n\tQNVS71vI2rKzQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=4oWVlNVD+BhXaNoojUjft82Db7px57l5q5o4NalLCOU=;\n\tb=S/gV4A4mnys4csuvqcw+/zWhqKSmt1MMQl8dGXPGtJiCE2K8r1i3qhc5bYNJhadVKI\n\tMhkg7j04y39+xiYLCIh6m/DRGjR9DwFOFsp2Prx4XapjdN73aCfkDL0b+m/4JzBxLb4a\n\tiVAdTsZm8b5uxfg65EhP+cOXM4KqhfXbg1oRN5oP6Q+PyHd1Fo0EFVTumbw8oMOsl2nl\n\tlkGisv82mxo8aX4oRpj1lc90Pevkir1nvsVEwcFgw31L9lV4LWQSVtW4ZJrZmoN7F5z9\n\twvYIiqjLBH8xqMYVyHTMdqUItY5+y2bNxlGFMd93HOpURwpf5wyFiHjfix+8lJNXUNYU\n\tC8VA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"S/gV4A4m\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=4oWVlNVD+BhXaNoojUjft82Db7px57l5q5o4NalLCOU=;\n\tb=IUhUI5bxG+tbJI++YFFn6D+h78jYL7BXyYv/lYM3tyca7PonxBF2ImDwGUC6glwKOT\n\t2Vj0Y5LeHs7fjCda099jpTce1WHomwqJnBp5Uz64m81sJp01iTBVERB164jfWvyks0Bi\n\tO6TglgyxAqgAdFsCNqextQkr1m2FK3bHHvN3qp0zePefbUfAkSt2OXUmgzoRXf2T7u44\n\tJqh5HisI2BzcNe3yIT0/x4MBX58rWb1JLQrRiedYgieDD8d4hrWQ3KaUFH6iTfcD29RB\n\tWcly/PjLk1pTUdW6/Vyl5plfEZjAUeAH704+nGNszpWbhh7OTWRgENamzqkU10NVzmEX\n\t+bbA==","X-Gm-Message-State":"ACrzQf0R2rER89NC/FfaVnBnU0lPuRaZ/saYZI9kmZ7Y0t1ta/3esG3l\n\tTHQLJCYJFuCmqTgtBo3BT7VWbcYDuiMhUA==","X-Google-Smtp-Source":"AMsMyM7RQlK85eyj6IuOjngut6Q+KBcr97ekiXL6FZvhg+dcXIzfIlAGMvNOQzL/j+P5oPPtXyZLcg==","X-Received":"by 2002:a5d:6b03:0:b0:236:d441:8f4e with SMTP id\n\tv3-20020a5d6b03000000b00236d4418f4emr11806556wrw.123.1667472033923; \n\tThu, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH 2/2] libcamera: camera_sensor: Do not\n\tclear camera flips when listing formats","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Previously the code used to clear the camnera's h and v flip bits when\nenumerating the supported formats so as to obtain any Bayer formats in\nthe sensor's native (untransformed) orientation. However this fails\nwhen the camera is already in use elsewhere.\n\nInstead, we query the current state of the flip bits and transform the\nformats - which we obtain in their flipped orientation - back into\ntheir native orientation to be stored.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/libcamera/camera_sensor.cpp | 51 +++++++++++++++++++++++++++------\n 1 file changed, 43 insertions(+), 8 deletions(-)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 572a313a..6670dfb9 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -19,6 +19,8 @@\n \n #include <libcamera/base/utils.h>\n \n+#include <libcamera/transform.h>\n+\n #include \"libcamera/internal/bayer_format.h\"\n #include \"libcamera/internal/camera_lens.h\"\n #include \"libcamera/internal/camera_sensor_properties.h\"\n@@ -108,18 +110,51 @@ int CameraSensor::init()\n \t\treturn ret;\n \n \t/*\n-\t * Clear any flips to be sure we get the \"native\" Bayer order. This is\n-\t * harmless for sensors where the flips don't affect the Bayer order.\n+\t * We want to get the native mbus codes for the sensor, without any flips.\n+\t * We can't clear any flips here, so we have to read the current values\n+\t * (if the flip controls exist), decide whether they actually modify any\n+\t * output Bayer pattern, and finally undo their effect on the formats.\n+\t *\n+\t * First, check if the flip controls exist and if so read them.\n \t */\n \tControlList ctrls(subdev_->controls());\n-\tif (subdev_->controls().find(V4L2_CID_HFLIP) != subdev_->controls().end())\n-\t\tctrls.set(V4L2_CID_HFLIP, 0);\n-\tif (subdev_->controls().find(V4L2_CID_VFLIP) != subdev_->controls().end())\n-\t\tctrls.set(V4L2_CID_VFLIP, 0);\n-\tsubdev_->setControls(&ctrls);\n+\tstd::vector<uint32_t> flipCtrlIds;\n+\tbool hasHflip = subdev_->controls().find(V4L2_CID_HFLIP) != subdev_->controls().end();\n+\tbool hasVflip = subdev_->controls().find(V4L2_CID_VFLIP) != subdev_->controls().end();\n+\tif (hasHflip)\n+\t\tflipCtrlIds.push_back(V4L2_CID_HFLIP);\n+\tif (hasVflip)\n+\t\tflipCtrlIds.push_back(V4L2_CID_VFLIP);\n+\tControlList flipCtrls = subdev_->getControls(flipCtrlIds);\n+\n+\t/* Now construct a transform that would undo any flips. */\n+\tTransform transform = Transform::Identity;\n+\tif (hasHflip && flipCtrls.get(V4L2_CID_HFLIP).get<int>()) {\n+\t\tconst struct v4l2_query_ext_ctrl *extCtrl = subdev_->controlInfo(V4L2_CID_HFLIP);\n+\t\tif (extCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)\n+\t\t\ttransform |= Transform::HFlip;\n+\t}\n+\tif (hasVflip && flipCtrls.get(V4L2_CID_VFLIP).get<int>()) {\n+\t\tconst struct v4l2_query_ext_ctrl *extCtrl = subdev_->controlInfo(V4L2_CID_VFLIP);\n+\t\tif (extCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)\n+\t\t\ttransform |= Transform::VFlip;\n+\t}\n+\n+\t/* Finally get the formats, and apply the transform to the mbus codes. */\n+\tauto formats = subdev_->formats(pad_);\n+\tfor (const auto &format : formats) {\n+\t\tunsigned int mbusCode = format.first;\n+\t\tBayerFormat bayerFormat = BayerFormat::fromMbusCode(mbusCode);\n+\t\tbool valid = true;\n+\n+\t\tif (bayerFormat.isValid())\n+\t\t\tmbusCode = bayerFormat.transform(transform).toMbusCode(valid);\n+\n+\t\tif (valid)\n+\t\t\tformats_[mbusCode] = std::move(format.second);\n+\t}\n \n \t/* Enumerate, sort and cache media bus codes and sizes. */\n-\tformats_ = subdev_->formats(pad_);\n \tif (formats_.empty()) {\n \t\tLOG(CameraSensor, Error) << \"No image format found\";\n \t\treturn -EINVAL;\n","prefixes":["libcamera-devel","RFC","2/2"]}