From patchwork Wed Jan 12 09:27:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15274 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 25606BE080 for ; Wed, 12 Jan 2022 09:28:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6A0206021A; Wed, 12 Jan 2022 10:28:09 +0100 (CET) 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="Yc9UjF97"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 908E86017F for ; Wed, 12 Jan 2022 10:28:07 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id k30so2991444wrd.9 for ; Wed, 12 Jan 2022 01:28:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gZAC2Lz05eFBKK7Ypc3hgH3kMVoPSHbH61oPuuXgT7w=; b=Yc9UjF97Bd3hpYUumx8TrzUeX0PMCjeBHNg8uoomOn9peGqJRhuyBBbrnsfEkR7R0q NNFNoJKDCs8OQIg0FHdoNu0/GXWro6cEnth6D85Bb0nfchvCUkjhjhbeNleFOdgsyK++ Bi70ri4TpIRv/wF42XbDAQrVwPjSygjRmigzfjgIeQumz2B5zaZ4+9zhfUGgAXX5zTRn pd7l601E288jaJyeaBX/Tu4uon5WgbTjYHJPxOWr2aINKGLnE4IW/uMncqSyiqi3f3KV RkkFb57DQGtUySa37RziRSNCPJwNQhTcpkPSqYNg3gRoDvHkDZMseJSc2/VI/yM+EhHy 10VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gZAC2Lz05eFBKK7Ypc3hgH3kMVoPSHbH61oPuuXgT7w=; b=iez0Aim9ICMCvkUdctZQEhn111BpKgia6XUcU2yl6FN7RSSVZhy5Xvg7qmqA36Q9zS bohewp8pSrOPtYLHIpF1d5BpOgveRKao9AFz0tr9GxZ0UEiN2IB7CEeM+nbFrg1ugwid deo4XIZW8XHIUf8boTcneXisKDAHZRiQGaM12+4189wucOOj13xl3eBu/sQe21splgRF xgEbMUHFeGT+YMA51EEHKahVUzex4T8HVd/+clizv9UPNKEMmH0Vw3+sBZMRcixakug9 sQ+ZLlcDf1x2iuGrcU/Znv5hD1teZet+hRx1Ho6gej2yewRgO/GNACu/vJm8y9n/McNd QG7Q== X-Gm-Message-State: AOAM530JaWpMMu9OnRn2rtzzNcOrBHrmdPtC8q9O3h/MqEJCgEl6mRGX yPsuC0WKXB9J390zauNoTcFQwy+HMWAQ6Gno X-Google-Smtp-Source: ABdhPJzqhBNIQwX5ZIUh4hNNhJTPABHyMUOmSX7L7m9SFKKbuRYhbAzJcU4HmDNvvEai7C815jraSw== X-Received: by 2002:adf:f784:: with SMTP id q4mr7612070wrp.655.1641979686917; Wed, 12 Jan 2022 01:28:06 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id m1sm994901wrp.81.2022.01.12.01.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 01:28:06 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jan 2022 09:27:58 +0000 Message-Id: <20220112092758.4726-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] pipeline: raspberrypi: Fix calculation of sensor's native Bayer order 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" This bug crept in when the pipeline handler was converted to use media controller. Previously the sensor's hflip and vflip were being cleared before querying the sensor for its "native" Bayer order. Now, though, the sensor's available formats are cached before we can clear these bits. Instead, we deduce the transform equivalent to the current hflip and vflip settings, and apply its inverse to the Bayer formats that we now have, thereby giving us the untransformed Bayer order that we want. The practical consequence of this was that the Bayer order stored in DNG files was frequently wrong. Signed-off-by: David Plowman Fixes: 83a512816189 ("pipeline: raspberrypi: Convert the pipeline handler to use media controller") --- .../pipeline/raspberrypi/raspberrypi.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 49d7ff23..c1fb9666 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1279,20 +1279,24 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me * Thirdly, what is the "native" Bayer order, when no transforms are * applied? * - * As part of answering the final question, we reset the camera to - * no transform at all. + * We note that the format list has already been populated with + * whatever flips are currently set, so to answer the final question + * we get the current Bayer order and undo the transform implied by + * the current flip settings. */ const V4L2Subdevice *sensor = data->sensor_->device(); const struct v4l2_query_ext_ctrl *hflipCtrl = sensor->controlInfo(V4L2_CID_HFLIP); + Transform currentTransform = Transform::Identity; if (hflipCtrl) { /* We assume it will support vflips too... */ data->supportsFlips_ = true; data->flipsAlterBayerOrder_ = hflipCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT; - ControlList ctrls(data->sensor_->controls()); - ctrls.set(V4L2_CID_HFLIP, 0); - ctrls.set(V4L2_CID_VFLIP, 0); - data->setSensorControls(ctrls); + ControlList ctrls = data->sensor_->getControls({ V4L2_CID_HFLIP, V4L2_CID_VFLIP }); + if (ctrls.get(V4L2_CID_HFLIP).get()) + currentTransform ^= Transform::HFlip; + if (ctrls.get(V4L2_CID_VFLIP).get()) + currentTransform ^= Transform::VFlip; } /* Look for a valid Bayer format. */ @@ -1307,7 +1311,10 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me LOG(RPI, Error) << "No Bayer format found"; return -EINVAL; } - data->nativeBayerOrder_ = bayerFormat.order; + /* Applying the inverse transform will give us the native order. */ + BayerFormat nativeBayerFormat = bayerFormat.transform(-currentTransform); + data->nativeBayerOrder_ = nativeBayerFormat.order; + LOG(RPI, Debug) << "Native Bayer format is " << nativeBayerFormat.toString(); /* * List the available streams an application may request. At present, we