From patchwork Fri Jul 31 14:37:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 27526 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 6DF2ABDE4C for ; Fri, 31 Jul 2026 14:37:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 199AB67FD2; Fri, 31 Jul 2026 16:37:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Sx2j95aI"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 04AA865F9F for ; Fri, 31 Jul 2026 16:37:52 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:2585:5eb2:203:5933]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F58322E; Fri, 31 Jul 2026 16:36:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1785508606; bh=3SqVZwJFp/iDrdIcSq4pB4FBSSBCGWiY6hixo2qyZ9Q=; h=From:To:Cc:Subject:Date:From; b=Sx2j95aI5pi9oHqA9mv1zG0xLbzSPTOvJwHxzn1K5sTrr8kBSdsH6pqwcfFeaCBTs gcOxrD7mWvuYkL/j5b7r80ZD2eWIBq8nSr261IDG2e3YfucWJIhGSD6uYxcrhEeuVl CcTHyV66hY0NHIX0NAKAtb1zOa+k7ACll3xDTvmY= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug 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 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" CameraSensorLegacy supports flipping on the sensor side only if the driver supports V4L2_CID_HFLIP and V4L2_CID_VFLIP. In cases where a driver only supports a single flip mode, flipping support gets disabled completely. This is unexpected and annoying when validating sensor drivers. Fix that by handling vertical and horizontal flips separately. Signed-off-by: Stefan Klug --- Hi all, I had this patch somewhere in my tree for a long time. Now I stumbled over this issue again and had to manually rebase the changes. So maybe it is time to upstream :-) Best regards, Stefan src/libcamera/sensor/camera_sensor_legacy.cpp | 72 +++++++++++++------ 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp index 6a683821f219..0f8e3c8cf251 100644 --- a/src/libcamera/sensor/camera_sensor_legacy.cpp +++ b/src/libcamera/sensor/camera_sensor_legacy.cpp @@ -133,7 +133,8 @@ private: Size pixelArraySize_; Rectangle activeArea_; const BayerFormat *bayerFormat_; - bool supportFlips_; + bool supportHFlips_; + bool supportVFlips_; bool flipsAlterBayerOrder_; Orientation mountingOrientation_; @@ -153,7 +154,7 @@ private: CameraSensorLegacy::CameraSensorLegacy(const MediaEntity *entity) : entity_(entity), pad_(UINT_MAX), staticProps_(nullptr), - bayerFormat_(nullptr), supportFlips_(false), + bayerFormat_(nullptr), supportHFlips_(false), supportVFlips_(false), flipsAlterBayerOrder_(false), properties_(properties::properties) { } @@ -365,19 +366,37 @@ int CameraSensorLegacy::validateSensorDriver() * \todo Handle horizontal and vertical flips independently. */ 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 && !(hflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY) && - vflipInfo && !(vflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY)) { - supportFlips_ = true; + if (hflipInfo && !(hflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY)) { + supportHFlips_ = true; - if (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT || - vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT) + if (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT) flipsAlterBayerOrder_ = true; + } else { + LOG(CameraSensor, Debug) + << "Camera sensor does not support horizontal flip"; } - if (!supportFlips_) + const struct v4l2_query_ext_ctrl *vflipInfo = subdev_->controlInfo(V4L2_CID_VFLIP); + if (vflipInfo && !(vflipInfo->flags & V4L2_CTRL_FLAG_READ_ONLY)) { + supportVFlips_ = true; + + if (vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT) + flipsAlterBayerOrder_ = true; + } else { LOG(CameraSensor, Debug) - << "Camera sensor does not support horizontal/vertical flip"; + << "Camera sensor does not support vertical flip"; + } + + if (supportHFlips_ && supportVFlips_ && + ((vflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT) != + (hflipInfo->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT))) { + LOG(CameraSensor, Error) + << "Flips have different alter bayer order properties." + << " Disable flipping altogether"; + supportHFlips_ = false; + supportVFlips_ = false; + flipsAlterBayerOrder_ = false; + } /* * Make sure the required selection targets are supported. @@ -759,11 +778,20 @@ CameraSensorLegacy::getFormat(Span mbusCodes, int CameraSensorLegacy::setFormat(V4L2SubdeviceFormat *format, Transform transform) { /* Configure flips if the sensor supports that. */ - if (supportFlips_) { + if (supportHFlips_) { ControlList flipCtrls(subdev_->controls()); flipCtrls.set(V4L2_CID_HFLIP, static_cast(!!(transform & Transform::HFlip))); + + int ret = subdev_->setControls(&flipCtrls); + if (ret) + return ret; + } + + if (supportVFlips_) { + ControlList flipCtrls(subdev_->controls()); + flipCtrls.set(V4L2_CID_VFLIP, static_cast(!!(transform & Transform::VFlip))); @@ -936,15 +964,6 @@ int CameraSensorLegacy::sensorInfo(IPACameraSensorInfo *info) const Transform CameraSensorLegacy::computeTransform(Orientation *orientation) const { - /* - * If we cannot do any flips we cannot change the native camera mounting - * orientation. - */ - if (!supportFlips_) { - *orientation = mountingOrientation_; - return Transform::Identity; - } - /* * Now compute the required transform to obtain 'orientation' starting * from the mounting rotation. @@ -955,6 +974,19 @@ Transform CameraSensorLegacy::computeTransform(Orientation *orientation) const */ Transform transform = *orientation / mountingOrientation_; + /* + * If we cannot do the required flips, fall back to identity. + */ + if (!supportHFlips_ & !!(transform & Transform::HFlip)) { + *orientation = mountingOrientation_; + return Transform::Identity; + } + + if (!supportVFlips_ & !!(transform & Transform::VFlip)) { + *orientation = mountingOrientation_; + return Transform::Identity; + } + /* * If transform contains any Transpose we cannot do it, so adjust * 'orientation' to report the image native orientation and return Identity.