{"id":27526,"url":"https://patchwork.libcamera.org/api/patches/27526/?format=json","web_url":"https://patchwork.libcamera.org/patch/27526/","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":"<20260731143741.689779-1-stefan.klug@ideasonboard.com>","date":"2026-07-31T14:37:01","name":"sensor: camera_sensor_legacy: Support separate H/V flips","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4394751b1eee428bd9a37bf33a559a3d4d64cb3a","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27526/mbox/","series":[{"id":6096,"url":"https://patchwork.libcamera.org/api/series/6096/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6096","date":"2026-07-31T14:37:01","name":"sensor: camera_sensor_legacy: Support separate H/V flips","version":1,"mbox":"https://patchwork.libcamera.org/series/6096/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27526/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27526/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 6DF2ABDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Jul 2026 14:37:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 199AB67FD2;\n\tFri, 31 Jul 2026 16:37:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 04AA865F9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Jul 2026 16:37:52 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:2585:5eb2:203:5933])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F58322E;\n\tFri, 31 Jul 2026 16:36:46 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Sx2j95aI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1785508606;\n\tbh=3SqVZwJFp/iDrdIcSq4pB4FBSSBCGWiY6hixo2qyZ9Q=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=Sx2j95aI5pi9oHqA9mv1zG0xLbzSPTOvJwHxzn1K5sTrr8kBSdsH6pqwcfFeaCBTs\n\tgcOxrD7mWvuYkL/j5b7r80ZD2eWIBq8nSr261IDG2e3YfucWJIhGSD6uYxcrhEeuVl\n\tCcTHyV66hY0NHIX0NAKAtb1zOa+k7ACll3xDTvmY=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH] sensor: camera_sensor_legacy: Support separate H/V flips","Date":"Fri, 31 Jul 2026 16:37:01 +0200","Message-ID":"<20260731143741.689779-1-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.53.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"CameraSensorLegacy supports flipping on the sensor side only if the\ndriver supports V4L2_CID_HFLIP and V4L2_CID_VFLIP. In cases where a\ndriver only supports a single flip mode, flipping support gets disabled\ncompletely. This is unexpected and annoying when validating sensor\ndrivers.\n\nFix that by handling vertical and horizontal flips separately.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\nHi all,\n\nI had this patch somewhere in my tree for a long time. Now I stumbled\nover this issue again and had to manually rebase the changes. So maybe\nit is time to upstream :-)\n\nBest regards,\nStefan\n\n src/libcamera/sensor/camera_sensor_legacy.cpp | 72 +++++++++++++------\n 1 file changed, 52 insertions(+), 20 deletions(-)","diff":"diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp\nindex 6a683821f219..0f8e3c8cf251 100644\n--- a/src/libcamera/sensor/camera_sensor_legacy.cpp\n+++ b/src/libcamera/sensor/camera_sensor_legacy.cpp\n@@ -133,7 +133,8 @@ private:\n \tSize pixelArraySize_;\n \tRectangle activeArea_;\n \tconst BayerFormat *bayerFormat_;\n-\tbool supportFlips_;\n+\tbool supportHFlips_;\n+\tbool supportVFlips_;\n \tbool flipsAlterBayerOrder_;\n \tOrientation mountingOrientation_;\n \n@@ -153,7 +154,7 @@ private:\n \n CameraSensorLegacy::CameraSensorLegacy(const MediaEntity *entity)\n \t: entity_(entity), pad_(UINT_MAX), staticProps_(nullptr),\n-\t  bayerFormat_(nullptr), supportFlips_(false),\n+\t  bayerFormat_(nullptr), supportHFlips_(false), supportVFlips_(false),\n \t  flipsAlterBayerOrder_(false), properties_(properties::properties)\n {\n }\n@@ -365,19 +366,37 @@ int CameraSensorLegacy::validateSensorDriver()\n \t * \\todo Handle horizontal and vertical flips independently.\n \t */\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 && !(hflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY) &&\n-\t    vflipInfo && !(vflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY)) {\n-\t\tsupportFlips_ = true;\n+\tif (hflipInfo && !(hflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY)) {\n+\t\tsupportHFlips_ = true;\n \n-\t\tif (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT ||\n-\t\t    vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)\n+\t\tif (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)\n \t\t\tflipsAlterBayerOrder_ = true;\n+\t} else {\n+\t\tLOG(CameraSensor, Debug)\n+\t\t\t<< \"Camera sensor does not support horizontal flip\";\n \t}\n \n-\tif (!supportFlips_)\n+\tconst struct v4l2_query_ext_ctrl *vflipInfo = subdev_->controlInfo(V4L2_CID_VFLIP);\n+\tif (vflipInfo && !(vflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY)) {\n+\t\tsupportVFlips_ = true;\n+\n+\t\tif (vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT)\n+\t\t\tflipsAlterBayerOrder_ = true;\n+\t} else {\n \t\tLOG(CameraSensor, Debug)\n-\t\t\t<< \"Camera sensor does not support horizontal/vertical flip\";\n+\t\t\t<< \"Camera sensor does not support vertical flip\";\n+\t}\n+\n+\tif (supportHFlips_ && supportVFlips_ &&\n+\t    ((vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT) !=\n+\t     (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT))) {\n+\t\tLOG(CameraSensor, Error)\n+\t\t\t<< \"Flips have different alter bayer order properties.\"\n+\t\t\t<< \" Disable flipping altogether\";\n+\t\tsupportHFlips_ = false;\n+\t\tsupportVFlips_ = false;\n+\t\tflipsAlterBayerOrder_ = false;\n+\t}\n \n \t/*\n \t * Make sure the required selection targets are supported.\n@@ -759,11 +778,20 @@ CameraSensorLegacy::getFormat(Span<const unsigned int> mbusCodes,\n int CameraSensorLegacy::setFormat(V4L2SubdeviceFormat *format, Transform transform)\n {\n \t/* Configure flips if the sensor supports that. */\n-\tif (supportFlips_) {\n+\tif (supportHFlips_) {\n \t\tControlList flipCtrls(subdev_->controls());\n \n \t\tflipCtrls.set(V4L2_CID_HFLIP,\n \t\t\t      static_cast<int32_t>(!!(transform & Transform::HFlip)));\n+\n+\t\tint ret = subdev_->setControls(&flipCtrls);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tif (supportVFlips_) {\n+\t\tControlList flipCtrls(subdev_->controls());\n+\n \t\tflipCtrls.set(V4L2_CID_VFLIP,\n \t\t\t      static_cast<int32_t>(!!(transform & Transform::VFlip)));\n \n@@ -936,15 +964,6 @@ int CameraSensorLegacy::sensorInfo(IPACameraSensorInfo *info) const\n \n Transform CameraSensorLegacy::computeTransform(Orientation *orientation) const\n {\n-\t/*\n-\t * If we cannot do any flips we cannot change the native camera mounting\n-\t * orientation.\n-\t */\n-\tif (!supportFlips_) {\n-\t\t*orientation = mountingOrientation_;\n-\t\treturn Transform::Identity;\n-\t}\n-\n \t/*\n \t * Now compute the required transform to obtain 'orientation' starting\n \t * from the mounting rotation.\n@@ -955,6 +974,19 @@ Transform CameraSensorLegacy::computeTransform(Orientation *orientation) const\n \t */\n \tTransform transform = *orientation / mountingOrientation_;\n \n+\t/*\n+\t * If we cannot do the required flips, fall back to identity.\n+\t */\n+\tif (!supportHFlips_ & !!(transform & Transform::HFlip)) {\n+\t\t*orientation = mountingOrientation_;\n+\t\treturn Transform::Identity;\n+\t}\n+\n+\tif (!supportVFlips_ & !!(transform & Transform::VFlip)) {\n+\t\t*orientation = mountingOrientation_;\n+\t\treturn Transform::Identity;\n+\t}\n+\n \t/*\n \t * If transform contains any Transpose we cannot do it, so adjust\n \t * 'orientation' to report the image native orientation and return Identity.\n","prefixes":[]}