From patchwork Fri Jan 22 12:01:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fabian_W=C3=BCthrich?= X-Patchwork-Id: 10957 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 DD781BD808 for ; Fri, 22 Jan 2021 12:01:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 56E9768255; Fri, 22 Jan 2021 13:01:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=fabwu.ch header.i=@fabwu.ch header.b="jaUULQYs"; dkim-atps=neutral Received: from gusto4.metanet.ch (gusto4.metanet.ch [80.74.154.158]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8767A68248 for ; Fri, 22 Jan 2021 13:01:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by gusto4.metanet.ch (Postfix) with ESMTPSA id 27B324F01728; Fri, 22 Jan 2021 13:01:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fabwu.ch; s=default; t=1611316906; bh=/kt3TwhPTK4OgetHDL6VB2Jgad+PEvVhZ/Jozj3Hlag=; h=From:To:Subject; b=jaUULQYsYyWduoY2Cu7y+PoLrxC3nlSl+uDqjc38k3xjCvXYr+vYNfxmJyUCYqXSS HVI1TTAPetcuY+Az2/qv8E63V0dwGq0M5Fp3xGl+XnxH4+AXvLkdtSAUjveVCebGGP 4QgoQHFm2wvjXktLeUZh7UyIoYvkVZ3onb5iv6IA= Authentication-Results: gusto.metanet.ch; spf=pass (sender IP is 2001:1715:9d9c:4e40:649e:8d07:9d6c:59c2) smtp.mailfrom=me@fabwu.ch smtp.helo=localhost Received-SPF: pass (gusto.metanet.ch: connection is authenticated) From: =?utf-8?q?Fabian_W=C3=BCthrich?= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jan 2021 13:01:32 +0100 Message-Id: <20210122120132.3717-1-me@fabwu.ch> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210116150257.2970-1-me@fabwu.ch> References: <20210116150257.2970-1-me@fabwu.ch> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] libcamera: ipu3: Add rotation to ipu3 pipeline 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" Use the same transformation logic as in the raspberry pipeline to implement rotations in the ipu3 pipeline. Tested on a Surface Book 2 with an experimental driver for OV5693. Signed-off-by: Fabian Wüthrich Reviewed-by: Kieran Bingham --- Changes in v2: - Cache rotationTransform in CameraData - Use separate controls for sensor Changes in v3: - Default rotation to 0 if sensor doesn't expose it src/libcamera/pipeline/ipu3/ipu3.cpp | 90 +++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 73304ea7..d620acf3 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,15 @@ public: Stream outStream_; Stream vfStream_; Stream rawStream_; + + /* Save transformation given by the sensor rotation */ + Transform rotationTransform_; + + /* + * Manage horizontal and vertical flips supported (or not) by the + * sensor. + */ + bool supportsFlips_; }; class IPU3CameraConfiguration : public CameraConfiguration @@ -74,6 +84,9 @@ public: const StreamConfiguration &cio2Format() const { return cio2Configuration_; } const ImgUDevice::PipeConfig imguConfig() const { return pipeConfig_; } + /* Cache the combinedTransform_ that will be applied to the sensor */ + Transform combinedTransform_; + private: /* * The IPU3CameraData instance is guaranteed to be valid as long as the @@ -143,11 +156,49 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() if (config_.empty()) return Invalid; - if (transform != Transform::Identity) { - transform = Transform::Identity; + Transform combined = transform * data_->rotationTransform_; + + /* + * We combine the platform and user transform, but must "adjust away" + * any combined result that includes a transposition, as we can't do those. + * In this case, flipping only the transpose bit is helpful to + * applications - they either get the transform they requested, or have + * to do a simple transpose themselves (they don't have to worry about + * the other possible cases). + */ + if (!!(combined & Transform::Transpose)) { + /* + * Flipping the transpose bit in "transform" flips it in the + * combined result too (as it's the last thing that happens), + * which is of course clearing it. + */ + transform ^= Transform::Transpose; + combined &= ~Transform::Transpose; + status = Adjusted; + } + + /* + * We also check if the sensor doesn't do h/vflips at all, in which + * case we clear them, and the application will have to do everything. + */ + if (!data_->supportsFlips_ && !!combined) { + /* + * If the sensor can do no transforms, then combined must be + * changed to the identity. The only user transform that gives + * rise to this is the inverse of the rotation. (Recall that + * combined = transform * rotationTransform.) + */ + transform = -data_->rotationTransform_; + combined = Transform::Identity; status = Adjusted; } + /* + * Store the final combined transform that configure() will need to + * apply to the sensor to save us working it out again. + */ + combinedTransform_ = combined; + /* Cap the number of entries to the available streams. */ if (config_.size() > IPU3_MAX_STREAMS) { config_.resize(IPU3_MAX_STREAMS); @@ -540,6 +591,19 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) return ret; } + /* + * Configure the H/V flip controls based on the combination of + * the sensor and user transform. + */ + if (data->supportsFlips_) { + ControlList sensor_ctrls(cio2->sensor()->controls()); + sensor_ctrls.set(V4L2_CID_HFLIP, + static_cast(!!(config->combinedTransform_ & Transform::HFlip))); + sensor_ctrls.set(V4L2_CID_VFLIP, + static_cast(!!(config->combinedTransform_ & Transform::VFlip))); + cio2->sensor()->setControls(&sensor_ctrls); + } + return 0; } @@ -775,9 +839,31 @@ int PipelineHandlerIPU3::registerCameras() /* Initialize the camera properties. */ data->properties_ = cio2->sensor()->properties(); + /* Convert the sensor rotation to a transformation */ + int32_t rotation; + if (data->properties_.contains(properties::Rotation)) { + rotation = data->properties_.get(properties::Rotation); + } else { + /* If sensor driver doesn't expose rotation, default rotation to 0 */ + rotation = 0; + LOG(IPU3, Warning) << "Rotation control not exposed by " << cio2->sensor()->id() + << ". Assume rotation 0."; + } + + bool success; + data->rotationTransform_ = transformFromRotation(rotation, &success); + if (!success) + LOG(IPU3, Warning) << "Invalid rotation of " << rotation << " degrees - ignoring"; + /* Initialze the camera controls. */ data->controlInfo_ = IPU3Controls; + ControlList ctrls = cio2->sensor()->getControls({ V4L2_CID_HFLIP }); + if (!ctrls.empty()) { + /* We assume it will support vflips too... */ + data->supportsFlips_ = true; + } + /** * \todo Dynamically assign ImgU and output devices to each * stream and camera; as of now, limit support to two cameras