From patchwork Thu Jan 13 14:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15279 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 006D9C325A for ; Thu, 13 Jan 2022 14:16:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 81887605A8; Thu, 13 Jan 2022 15:16:06 +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="YnJ6M6i0"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C40A5604F4 for ; Thu, 13 Jan 2022 15:16:03 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id r28so10395199wrc.3 for ; Thu, 13 Jan 2022 06:16:03 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=1gghCCn3+u5hZC9uavWRxTF4TMcfMQGnUBz1f6/Oh/0=; b=YnJ6M6i0juUtUBdIosECvCj7DTXwnT5YpypjXgaf/n5sWBIo5+y4K9TKeUSLYaYYAf 8UU7yzCxI7aJ+3MN5JN5jBUSlEygdLmu+FHWEQQyHGlJVDbpvlqci/HxTHagVNwNwXh5 upeABzcrenoQcit5R9FQT0DhcPtPMBv3t4qzuGTwx8lITVotngTmjinrS6Spbcdv9cq/ DXu6BY0Zv9QFb3HwFLUjz6N/weiC9K9ceePs/ps2vaZvCEvNJGarh7Gh1LrSWOLyPTY6 lRgdAhSLUBqUUcAm+QUN5VdXZX2iSk3gURa11Wl5ODOfMoQvk9D53xtkSe9xg6LD4KtH CiBg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=1gghCCn3+u5hZC9uavWRxTF4TMcfMQGnUBz1f6/Oh/0=; b=MQvcqul7GgdK26HbfRDifNPSoakHq4PPr6k3Icc15bQtxA+Zvst6D9EDHhOkFxbBV+ R8MgyeJJSX41XnJIjSaf2FFx2aVZk3n77AxSTbwqv+W72T2IbO7oYmN50Xy/GZ+q/1v6 gf9SwWhhPaDDQW7jStj77hmrIgANZ6OJQPMWzK1i8/Be/wbINo6Ei2j6UVWiSdxE2A8n OTSBIAzuMzBrCmukx1g47tg03RRLw6UG2Wqlg/oS2+I2wIaZiMv74ChG6V5Nf+XHzCDP B4P6HGZTP3ipgKj4NZughAwnk9yD0bzH3aegi/5q8R6JzXgxBTkrv7ViM2ghOaRKBfy+ S6+g== X-Gm-Message-State: AOAM53288/KAn48HX+uAPlH+4GEoM7OUiZUSDSCkW0+7YGRu+giigd8A Nx2Tm1J09+DWSb+q9QKkrqIRQXmVUGyLf4uN X-Google-Smtp-Source: ABdhPJzXS103rFB6gTOQizdBRDwOoL8U1BL5epkL90/aQdd3ymnBF8BRYP2/c5On/tP/aGw0BobrGw== X-Received: by 2002:a5d:688c:: with SMTP id h12mr4281225wru.421.1642083363223; Thu, 13 Jan 2022 06:16:03 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id b2sm3284584wrd.35.2022.01.13.06.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 06:16:02 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 13 Jan 2022 14:15:57 +0000 Message-Id: <20220113141558.5805-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113141558.5805-1-david.plowman@raspberrypi.com> References: <20220113141558.5805-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: camera_sensor: Clear camera flips after opening the device 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" We clear the V4L2_CID_HFLIP and V4L2_CID_VFLIP controls immediately after opening the camera device. This means the camera's Bayer format and mbus codes will be in the sensor's "native" order, and we document this to be the case so that it can be relied upon. Clearing the flips is harmless where sensor flips do not affect the Bayer order. This also fixes a bug in the Raspberry Pi pipeline handler where the native Bayer order was being computed wrongly, but the new behaviour here will be helpful to other pipeline handlers too. A subsequent commit will tidy up the Raspberry Pi pipeline handler in this area as it can now be simplified. Signed-off-by: David Plowman Fixes: 83a512816189 (pipeline: raspberrypi: Convert the pipeline handler to use media controller) Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/libcamera/camera_sensor.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index c3999d35..64f7f12c 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -107,6 +107,17 @@ int CameraSensor::init() if (ret < 0) return ret; + /* + * Clear any flips to be sure we get the "native" Bayer order. This is + * harmless for sensors where the flips don't affect the Bayer order. + */ + ControlList ctrls(subdev_->controls()); + if (subdev_->controls().find(V4L2_CID_HFLIP) != subdev_->controls().end()) + ctrls.set(V4L2_CID_HFLIP, 0); + if (subdev_->controls().find(V4L2_CID_VFLIP) != subdev_->controls().end()) + ctrls.set(V4L2_CID_VFLIP, 0); + subdev_->setControls(&ctrls); + /* Enumerate, sort and cache media bus codes and sizes. */ formats_ = subdev_->formats(pad_); if (formats_.empty()) { @@ -461,6 +472,11 @@ int CameraSensor::initProperties() /** * \fn CameraSensor::mbusCodes() * \brief Retrieve the media bus codes supported by the camera sensor + * + * Any Bayer formats are listed using the sensor's native Bayer order, + * that is, with the effect of V4L2_CID_HFLIP and V4L2_CID_VFLIP undone + * (where these controls exist). + * * \return The supported media bus codes sorted in increasing order */