{"id":17767,"url":"https://patchwork.libcamera.org/api/1.1/patches/17767/?format=json","web_url":"https://patchwork.libcamera.org/patch/17767/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20221110144556.7858-3-david.plowman@raspberrypi.com>","date":"2022-11-10T14:45:52","name":"[libcamera-devel,2/6] libcamera: camera_sensor: Do not clear camera flips when listing formats","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d26a71a20e64b161c078b7b9c9f93670179f7674","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17767/mbox/","series":[{"id":3602,"url":"https://patchwork.libcamera.org/api/1.1/series/3602/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3602","date":"2022-11-10T14:45:50","name":"Resolve invalid attempts to set sensor flip controls","version":1,"mbox":"https://patchwork.libcamera.org/series/3602/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17767/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17767/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 B2AA5BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Nov 2022 14:46:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5E5C26308B;\n\tThu, 10 Nov 2022 15:46:07 +0100 (CET)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 311D56308A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Nov 2022 15:46:05 +0100 (CET)","by mail-wm1-x32c.google.com with SMTP id\n\t187-20020a1c02c4000000b003cf9c3f3b80so3593223wmc.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Nov 2022 06:46:05 -0800 (PST)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:e4a2:3070:eea4:e434])\n\tby smtp.gmail.com with ESMTPSA id\n\tu24-20020a7bc058000000b003b476cabf1csm5249759wmc.26.2022.11.10.06.46.03\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 10 Nov 2022 06:46:03 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1668091567;\n\tbh=7grIAjYXQ3Ea0xXqemCp3t/taCJfdbnjQ0iJFL17Fas=;\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=tUPFdeuCjYO+9Lzk2+Bem1adlel8899J+YXxNJzbZEHhWBqTCzbCo7EAadvt+PXze\n\tCu62RKdYm1nRF5wxuENtil4gqw5VQ7vTKvcpXZANl3OTz2lUBK64Ci/2TxH4iF9hAj\n\tNaJagvVR0NRAjKfk+JIxuqlS4P3ybZlDDOt2Svp3TL5s2omrrcYKzUk6EjNPzjUDhk\n\t39gRbw/gDHNReLjcL9BZcGPuLOiUwwtA/tPYFiWW5qNa6k7iodr71nN8bE75MIYu4H\n\t47O0zzfvYMb5+yasQR4dbaKkNOx6aDQSg3e4/4jv8KlIGu05lK7J5D9Tt0Ql+d1Cei\n\tt6WpMUMZAsqeQ==","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=c/XUPzGRn61e9q+kM7sM57KDqq6wnGYdRwWL5ZbwlIY=;\n\tb=P8W9msFQGrKSoiyGovEsGCFmfbnE/ntGB+H0J4SBjooOBV3qS1FYINY5Scz5R2fA3Q\n\tly3Q/T1k2ldz1WjhO9X3QTsZf3B239cge1nQvPbOiccwwMJSguWrtLNH8XltFtW9rTh2\n\trEokQD3rq5gunaIZEonKDTpcmxMKBMK/m+beRMwejgx3F8Hdw+zvw8yQRQb0vQ02cEF5\n\t4rt/tDmDNZ5R8GyMxSdBpxX0a1JmLcC19p0nqGAw6+oVljhGsy9ksGj5HIkuwhe6bCMK\n\t37ppJbQZ1OHFNUqbTi2DNZAhGsPP5nBWoVXqdcacRMH9XSrK9Vxh2590JhJTXyJLVgd5\n\tCudA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"P8W9msFQ\"; 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=c/XUPzGRn61e9q+kM7sM57KDqq6wnGYdRwWL5ZbwlIY=;\n\tb=dWz+HtOU/AaNDgcVLUK4J7/ira5EHBzamNAqPD0bvv0dakQGMNZlbhOJIlERUAodtc\n\ttx4cxjM4gmJFphqH13vY0zldu3fjlRJv7XYzRaKXUI0E6WXiICx0PRwJUZ0C9A/ewKHv\n\th9HWuK4B0xPYTvE+Zq7rv2J3Hs/Uj6DWArJDRI9f4BkrCh23ZLKjBRDJbhnKPyaYGVpe\n\tPh4DQtFwN2nGq9rgzA6w5N/bhYRUbgGH11LOqTBV8YRltxyO8A7SP6CdJljgHxMFr/kM\n\tQieAZFy2iiN0URpanuyjfqWdRUddD/QKd2GEuSN67pgwCpIslGXW59MT+NpQgaGKUN6t\n\tiRJA==","X-Gm-Message-State":"ACrzQf0RGVttUbHXtxzbipvL1XKLIXYl1cJPKxq0p+G2blwG/D3T29CQ\n\tqpRd+M1+R+CjDOgIfMCn1XW2Ux7tnxMjHQ==","X-Google-Smtp-Source":"AMsMyM52jYe7srS8FbqHHdc0I8/1eNJVDQuMSjhcPZ5iJ8tl+whpLiJLlDysPc0grjvtW0wuCkO9LQ==","X-Received":"by 2002:a1c:6a17:0:b0:3cf:9d32:db2e with SMTP id\n\tf23-20020a1c6a17000000b003cf9d32db2emr19514721wmc.62.1668091564034; \n\tThu, 10 Nov 2022 06:46:04 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 10 Nov 2022 14:45:52 +0000","Message-Id":"<20221110144556.7858-3-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/6] 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 | 49 ++++++++++++++++++++++++++-------\n 1 file changed, 39 insertions(+), 10 deletions(-)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 572a313a..cbac9e78 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,45 @@ 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+\tconst struct v4l2_query_ext_ctrl *hflipInfo = subdev_->controlInfo(V4L2_CID_HFLIP);\n+\tconst struct v4l2_query_ext_ctrl *vflipInfo = subdev_->controlInfo(V4L2_CID_VFLIP);\n+\tif (hflipInfo)\n+\t\tflipCtrlIds.push_back(V4L2_CID_HFLIP);\n+\tif (vflipInfo)\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 (hflipInfo && flipCtrls.get(V4L2_CID_HFLIP).get<int>() &&\n+\t    (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT))\n+\t\ttransform |= Transform::HFlip;\n+\tif (vflipInfo && flipCtrls.get(V4L2_CID_VFLIP).get<int>() &&\n+\t    (vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT))\n+\t\ttransform |= Transform::VFlip;\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+\n+\t\tif (bayerFormat.isValid())\n+\t\t\tmbusCode = bayerFormat.transform(transform).toMbusCode();\n+\n+\t\tif (mbusCode)\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@@ -189,7 +218,7 @@ int CameraSensor::init()\n \t * \\todo The control API ought to have a flag to specify if a control\n \t * is read-only which could be used below.\n \t */\n-\tconst ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK);\n+\tconst ControlInfo hblank = subdev_->controls().at(V4L2_CID_HBLANK);\n \tconst int32_t hblankMin = hblank.min().get<int32_t>();\n \tconst int32_t hblankMax = hblank.max().get<int32_t>();\n \n","prefixes":["libcamera-devel","2/6"]}