From patchwork Fri Aug 21 15:56:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 9351 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 D2501BE174 for ; Fri, 21 Aug 2020 15:57:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1CEFD626D3; Fri, 21 Aug 2020 17:57:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dmpYDFhn"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 357B661B4F for ; Fri, 21 Aug 2020 17:57:05 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id g75so2316877wme.4 for ; Fri, 21 Aug 2020 08:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yc0n4NwlChACJCfwMFnscjpJL7xovCWYjrqOiaomR8Y=; b=dmpYDFhnYSonRiSE32rqFQWMmkiKCaO1OCkkJXllooy28+uZGMO3hYTZxc4Qn8GkjM 68TW0H2nZMp2VocU9yaJV/IRrWB2+hR8nUw7mIWaQVj1RY+iqQwMu0ZoG7o7/fIoyZYt k25jbsqSPGXv1iJ6bb/LhXDNp11KYONXVXAjPGB5qONht2mJ6iIVpNEQq12Epe1XgEsR JUI/K5AycfFrJJXobGOQm0CcUAvT489JVQZ1axJ8BPWwGG+pvOiHpD/Ye6ticnUX3VTQ RJswvF81tGQYgIyNZ2zWErtQ+2WeZFTD1+yFhvJSxI80x+lBSSczkCFggOLa1PHbv1Zt p66Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yc0n4NwlChACJCfwMFnscjpJL7xovCWYjrqOiaomR8Y=; b=VSUTftc2rTls2g5nfnUlTu0lkvbiL+wCwXuq5MUTdjv1X3JIijAUQ/1OHEBJjKFlDR 9ndxJZ34NvtcwGkn5XB8hENwoWDAsWzOq1FDfEK/m9ntK/Tc7z5qUbRmX+twt204jFSH XSUHZujfbm/fDQxcNnrUu5kT2XJ7ZhHDqKasJvZZq4GPxVtwWzjVaOJtb/AF2LkZrkpS 8Ax8J1sdB4/hRhLvfhWaJLvX0Gv4GmilHrXzP9c16SKxcnNXK05baWVZOPZlAXHnGZr6 23V68VVyBGXpmIJJAZ8aEl+cn08CLuUempbL+3U+9AfaCiBX4lHcLppBCM2HgnKv7ots mA0A== X-Gm-Message-State: AOAM533pbSqVUZQCLPqWtErPxyOXQanR7DDY4qAKy0wWJzwS42T7sVex 2p1AMK5wWN9JSz9/w0FvY7wQfT1aeOdLiQ== X-Google-Smtp-Source: ABdhPJyK4zmQa1TRe8iEuv3+b11YxvvdCn49FDRO+lSj4rvPzn/x2Dww8B4kujAsF7pg2TDxBlVjQw== X-Received: by 2002:a1c:ab8b:: with SMTP id u133mr3695642wme.108.1598025424347; Fri, 21 Aug 2020 08:57:04 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id l11sm5627385wme.11.2020.08.21.08.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 08:57:03 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 21 Aug 2020 16:56:39 +0100 Message-Id: <20200821155641.11839-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200821155641.11839-1-david.plowman@raspberrypi.com> References: <20200821155641.11839-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/5] libcamera: raspberrypi: Set camera flips correctly from user transform 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" The Raspberry Pi pipeline handler allows all transforms except those involving a transpose. The user transform is combined with any inherent rotation of the camera, and the camera's H and V flip bits are set accordingly. Signed-off-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 236aa5c..a3f8438 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -324,6 +324,8 @@ public: uint32_t expectedSequence_; bool sensorMetadata_; + Transform transform_; + /* * All the functions in this class are called from a single calling * thread. So, we do not need to have any mutex to protect access to any @@ -400,8 +402,27 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() if (config_.empty()) return Invalid; - if (transform != Transform::Identity) { - transform = Transform::Identity; + /* + * What if the platform has a non-90 degree rotation? We can't even + * "adjust" the configuration and carry on. Alternatively, raising an + * error means the platform can never run. Let's just print a warning + * and continue regardless; the rotation is effectively set to zero. + */ + int32_t rotation = data_->sensor_->properties().get(properties::Rotation); + bool success; + Transform combined = transform * transformFromRotation(rotation, &success); + if (!success) + LOG(RPI, Warning) << "Invalid rotation of " << rotation + << " degrees - ignoring"; + + /* + * We combine the platform and user transform, but must "adjust away" + * any combined result that includes a transform, as we can't do those. + * Flipping the transpose bit in either input transform causes the + * corresponding bit in the combined result to flip. + */ + if (!!(combined & Transform::Transpose)) { + transform ^= Transform::Transpose; status = Adjusted; } @@ -610,6 +631,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) for (auto const stream : data->streams_) stream->reset(); + /* We will want to know the transform requested by the application. */ + data->transform_ = config->transform; + Size maxSize, sensorSize; unsigned int maxIndex = 0; bool rawStream = false; @@ -1174,8 +1198,10 @@ int RPiCameraData::configureIPA() /* Configure the H/V flip controls based on the sensor rotation. */ ControlList ctrls(unicam_[Unicam::Image].dev()->controls()); int32_t rotation = sensor_->properties().get(properties::Rotation); - ctrls.set(V4L2_CID_HFLIP, static_cast(!!rotation)); - ctrls.set(V4L2_CID_VFLIP, static_cast(!!rotation)); + /* The rotation was already checked in RPiCameraConfiguration::validate. */ + Transform combined = transform_ * transformFromRotation(rotation); + ctrls.set(V4L2_CID_HFLIP, static_cast(!!(combined & Transform::HFlip))); + ctrls.set(V4L2_CID_VFLIP, static_cast(!!(combined & Transform::VFlip))); unicam_[Unicam::Image].dev()->setControls(&ctrls); }