From patchwork Fri Aug 28 14:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 9420 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 012C9BF019 for ; Fri, 28 Aug 2020 14:41:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD8B8628EE; Fri, 28 Aug 2020 16:41:24 +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="ApAztjra"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 21B6E62919 for ; Fri, 28 Aug 2020 16:41:21 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id o21so1147145wmc.0 for ; Fri, 28 Aug 2020 07:41:21 -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=5RQ8Tgj+C3/uKLvM1ptBLXMv3MS0gQ7Sq45idn4oLKg=; b=ApAztjraLYr+3faisoVdCNOg2X8Py+eGRLufcnbvR9e1BGr5lmVRGdcb80K9Xq/rKp YOM0kfTzY4Em9/gd8p1TK/FSKPQHaUwd47kAUJ2f4VBZYO9OCBZX95gYoFe/netsD3na zObHrWAwO/nwBT0OtPJVOpL/2ga99v4oN3v6k58Dt2P5AiNCb271uWp8u3r7OhDtPpUe cS0l/N2hPccqKfWHBTIU/80ijc/E3NhoQ2Dy5+kWS0BGZwD5lkc4IbdhFBdklgfwc+At zKC+8aZ176rM6jmMZ2K9QsmkdrK8Am6So1KCJ6hOJGsAf58930qdUnflPfFn24E8C61g 9N8g== 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=5RQ8Tgj+C3/uKLvM1ptBLXMv3MS0gQ7Sq45idn4oLKg=; b=lMN3C+yXHpT2C+1PhlEFZQtIOSIpYLe6WDlqDUIKqi+N19khwo/wQz7lqD5jiqUK7h b1wCWO1dCi1zJGbiQ3uPc/V8yc+DyA6Y9TqS16A/5EYmytZSyzZICNK590WqD82iw2dw Ypl9P1Na4YMzLN7X+X7WYTgnexaaw2bpPVQRSGIrj8KBfvlhbwfJrAq+G5YjGXzIpP4T S0F3+68CrAUhnSm+Hs1FlAK56zon/HgSqZ3xI/fpmxWCVGHez+xnUcs/DvPFtqJckGEO JIYiYrKeuVIa67PeprrOxH1yrlM7I4aVXXKSHpFndDENp3suhzwiX3VtlzObiVkHIXxf u1wQ== X-Gm-Message-State: AOAM530hT3aaqhDie/HeEbZy46F8VkHgX4XneHRB/JIy5vfnAmfkudts SzvwyjiLXZsg1MKfZPrhhzx47o5WyWfkkQ== X-Google-Smtp-Source: ABdhPJwMb30vppxLRTVGB+HspBbQcQPPjZqC7mUKxAr9v07ZzWWpVo5ySB4ZjbK6WegdsBKWzvO4Vg== X-Received: by 2002:a1c:2501:: with SMTP id l1mr2148725wml.16.1598625680577; Fri, 28 Aug 2020 07:41:20 -0700 (PDT) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id s12sm2493724wmj.26.2020.08.28.07.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 07:41:19 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 28 Aug 2020 15:41:08 +0100 Message-Id: <20200828144110.17303-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200828144110.17303-1-david.plowman@raspberrypi.com> References: <20200828144110.17303-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/7] 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 | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index dc36f53..6ea1432 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -400,20 +400,46 @@ 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. + * 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 + * combined result too (as it's the last thing that happens). + */ + transform ^= Transform::Transpose; + combined ^= Transform::Transpose; status = Adjusted; } /* - * Configure the H/V flip controls based on the sensor rotation. We do - * this here so that the sensor has the correct Bayer format that will - * get advertised in the configuration of any raw streams. + * Configure the H/V flip controls based on the combination of the + * sensor rotation and the user transform. We do this here so that the + * sensor has the correct Bayer format that will get advertised in the + * configuration of any raw streams. */ ControlList ctrls(data_->unicam_[Unicam::Image].dev()->controls()); - int32_t rotation = data_->sensor_->properties().get(properties::Rotation); - ctrls.set(V4L2_CID_HFLIP, static_cast(!!rotation)); - ctrls.set(V4L2_CID_VFLIP, static_cast(!!rotation)); + ctrls.set(V4L2_CID_HFLIP, static_cast(!!(combined & Transform::HFlip))); + ctrls.set(V4L2_CID_VFLIP, static_cast(!!(combined & Transform::VFlip))); data_->unicam_[Unicam::Image].dev()->setControls(&ctrls); unsigned int rawCount = 0, outCount = 0, count = 0, maxIndex = 0;