From patchwork Mon Jun 28 16:32:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12729 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 A1916C3220 for ; Mon, 28 Jun 2021 16:32:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 62E8D684DA; Mon, 28 Jun 2021 18:32:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Wru5bwY/"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B06B1684D6 for ; Mon, 28 Jun 2021 18:32:51 +0200 (CEST) Received: by mail-pj1-x1029.google.com with SMTP id bb20so10499811pjb.3 for ; Mon, 28 Jun 2021 09:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1oIGze6zan6MqI7rIizV5leq038W9m+8OGcqWq3kOx4=; b=Wru5bwY/zQ1qFf7h0Qz4UEdcnbszkwJVW/WguyHeN3uB7Gxb4ybxIzHGt1JIiJ2yuB Hvjw1rQPMgwhddzIgmKHxtXG93w+W2wgo64gdV2C9FVNtoW7dQS/mko4Zfrtu9zIZ0Qx m55GQYqmJgfklT/Miwy/uUg0lG1pbTdBqmmdI= 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=1oIGze6zan6MqI7rIizV5leq038W9m+8OGcqWq3kOx4=; b=IlCDU9tE9G8pk3LHODMmg55UBG2EbuV83JeekJuQjbzAc9B3G/DE7rSgu3tLRj/pPY TgC3x2F+tXgDDbK4Z2N/x/+5VvvgQm4bwcxF23GJbICK5cvsusUWdfAlyfXKSeMVaaJM 3dmZ7T1ynCF0In4peAXhvQQGdvwb80/AuDz//Zv/s9cPthh6FH9iqxqL0OHrJr+EO5NQ aDuIUr7cttng/7X816YavXg3/V3Mdxler9kkYNu5tMPlLyFpx4qdI8GY/ZgmTAgFKAyO wWBmMtrL8XIMW/TroVA/m2yL2+FSrUAz12jEeGi8zox9pTvRZeaiwA9xRrZUm6YNSi8o YJyA== X-Gm-Message-State: AOAM531Sa91A29/Ta2n7uQ1P8+8oPfil83fxszdT/bL2DKH+4ufAmQ6c scY1vQ45HoDRFQ+kiAU200EW6dTsx98RMQ== X-Google-Smtp-Source: ABdhPJxgb/BilbfgRS3ctdWl6ROXSOy/B6OSAxFr92aOG+Horwue2SopcHfHBZf+RvNPeIXjz5i+rw== X-Received: by 2002:a17:902:f688:b029:128:e3ab:a868 with SMTP id l8-20020a170902f688b0290128e3aba868mr4343000plg.67.1624897969892; Mon, 28 Jun 2021 09:32:49 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a147:1cb:e226:4ed9]) by smtp.gmail.com with ESMTPSA id gg5sm5134201pjb.42.2021.06.28.09.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 09:32:49 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Jun 2021 01:32:36 +0900 Message-Id: <20210628163237.3194582-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210628163237.3194582-1-hiroh@chromium.org> References: <20210628163237.3194582-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: camera_sensor: Reverse the key and value of test pattern mode map 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 key and value of the test pattern mode are originally the index of v4l2 control and the corresponding test pattern mode control value. This key and value are useful in the initialization for reporting available test pattern modes. However, the map of the reversed key and value is much more useful in applying a requested test pattern mode. Reverses the key and value of the map as the initialization is one time but the test pattern mode request will be multiple times. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 15 ++++++++++-- src/libcamera/camera_sensor_properties.cpp | 28 +++++++++++----------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 94dcf4f9..ee53adf3 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -320,11 +320,22 @@ void CameraSensor::initTestPatternModes( return; } + /* + * Create a map that associates the V4L2 control index to the test + * pattern mode by reversing the testPatternModes map provided by the + * camera sensor properties. This makes it easier to verify if the + * control index is supported in the below for loop that creates the + * list of supported test patterns. + */ + std::map indexToTestPatternMode; + for (const auto& it : testPatternModes) + indexToTestPatternMode[it.second] = it.first; + for (const ControlValue &value : v4l2TestPattern->second.values()) { const int32_t index = value.get(); - const auto it = testPatternModes.find(index); - if (it == testPatternModes.end()) { + const auto it = indexToTestPatternMode.find(index); + if (it == indexToTestPatternMode.end()) { LOG(CameraSensor, Debug) << "Test pattern mode " << index << " ignored"; continue; diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp index 7d8ba9e9..a4b6565c 100644 --- a/src/libcamera/camera_sensor_properties.cpp +++ b/src/libcamera/camera_sensor_properties.cpp @@ -38,9 +38,9 @@ LOG_DEFINE_CATEGORY(CameraSensorProperties) * \brief The physical size of a pixel, including pixel edges, in nanometers. * * \var CameraSensorProperties::testPatternModes - * \brief Map that associates the indexes of the sensor test pattern modes as - * returned by V4L2_CID_TEST_PATTERN with the corresponding TestPattern - * control value + * \brief Map that associates the TestPattern control value with the indexes of + * the corresponding sensor test pattern modes as returned by + * V4L2_CID_TEST_PATTERN. */ /** @@ -55,11 +55,11 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen { "imx219", { .unitCellSize = { 1120, 1120 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 1, controls::draft::TestPatternModeColorBars }, - { 2, controls::draft::TestPatternModeSolidColor }, - { 3, controls::draft::TestPatternModeColorBarsFadeToGray }, - { 4, controls::draft::TestPatternModePn9 }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeColorBars, 1 }, + { controls::draft::TestPatternModeSolidColor, 2 }, + { controls::draft::TestPatternModeColorBarsFadeToGray, 3 }, + { controls::draft::TestPatternModePn9, 4 }, }, } }, { "imx258", { @@ -75,15 +75,15 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen { "ov5670", { .unitCellSize = { 1120, 1120 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 1, controls::draft::TestPatternModeColorBars }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeColorBars, 1 }, }, } }, { "ov13858", { .unitCellSize = { 1120, 1120 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 1, controls::draft::TestPatternModeColorBars }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeColorBars, 1 }, }, } }, { "ov5647", { @@ -93,8 +93,8 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen { "ov5693", { .unitCellSize = { 1400, 1400 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 2, controls::draft::TestPatternModeColorBars }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeColorBars, 2 }, /* * No corresponding test pattern mode for * 1: "Random data" and 3: "Colour Bars with From patchwork Mon Jun 28 16:32:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12730 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 74E7EC3220 for ; Mon, 28 Jun 2021 16:32:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB2A8684D6; Mon, 28 Jun 2021 18:32:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ACOlRrJf"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2375560508 for ; Mon, 28 Jun 2021 18:32:53 +0200 (CEST) Received: by mail-pj1-x1029.google.com with SMTP id kt19so2582356pjb.2 for ; Mon, 28 Jun 2021 09:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w8tjquK+IcBSMPTy8zTwYyPWYtVo4Tqk+xeA6vSCsBM=; b=ACOlRrJfG+FqoBLb5YvR9IQRzb+NebHuDKpaviod0k9C1ZNSDGf2GObtmvKGnuXwVg Qc42xzA/7Y7pTIp6ZhLH0MuF9JtERkxsuheEaZh+52jSrQfyGUScZ+JEmt1EzQg6dMGA NFbEZGnXmR4F5o2sKaPbD/OoNtZWVGQ+2OzmU= 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=w8tjquK+IcBSMPTy8zTwYyPWYtVo4Tqk+xeA6vSCsBM=; b=kYkfQBxNBF9wEe3vUgRyxlbi5V9J1W5SHzrqUc50/tD+NnR7gWCMknAS2Lu5E3CYhs SL0LYtODkdiCfQPrAe7ZAFFLNrMwADdP/2tjOfZbo1oYePg3NIVEjRvSJJf52rIpQQjV 586lnRYFMMeqzSvUcO1NHrCdZwLOxm2GdjOhL6OTxBIypP1j5exXC7U5z2UorzCAuJPM XzDcv4pJAtsH6doT7m2AM5qTcx/YcUlONCaMWp1YyezMGQ2Kyg9QODiIOpGGKyy8ejHJ DxX8HjSKk+6kfn9u5zTyYGLcV4usPQcwqYpa644rp3WQX+brMi8j+PGoRaYIdcwXbA2Y ciBg== X-Gm-Message-State: AOAM5316CXwOYFcjDIEns08ih6u91Xm8H9MXKV7l1yPZFBcE3DtLpvni mJdqkCUtr7EVKwBaLKRcYp5107AGuT+y6A== X-Google-Smtp-Source: ABdhPJwohq1jfVlAV1EHbip3KsfUXjHZHE3yl1i03yM9E+cattKFPEwWCcCw1Zcqmf/WsB3EOcMbNg== X-Received: by 2002:a17:902:aa0a:b029:128:c224:4f0a with SMTP id be10-20020a170902aa0ab0290128c2244f0amr10741423plb.58.1624897971406; Mon, 28 Jun 2021 09:32:51 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a147:1cb:e226:4ed9]) by smtp.gmail.com with ESMTPSA id gg5sm5134201pjb.42.2021.06.28.09.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 09:32:50 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Jun 2021 01:32:37 +0900 Message-Id: <20210628163237.3194582-3-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210628163237.3194582-1-hiroh@chromium.org> References: <20210628163237.3194582-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: camera_sensor: Enable to set a test pattern mode 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" Provides a function to set the camera sensor a test pattern mode. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/camera_sensor.h | 2 ++ src/libcamera/camera_sensor.cpp | 35 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index db12b07e..4ecce6c9 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -44,6 +44,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(int32_t testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -85,6 +86,7 @@ private: std::vector mbusCodes_; std::vector sizes_; std::vector testPatternModes_; + int32_t testPatternMode_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index ee53adf3..be2d32e3 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -54,8 +54,8 @@ LOG_DEFINE_CATEGORY(CameraSensor) * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr), - properties_(properties::properties) + : entity_(entity), pad_(UINT_MAX), testPatternMode_(-1), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -515,6 +515,37 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \brief Set the camera sensor a specified controls::TestPatternMode + * \param[in] testPatternMode test pattern mode control value to set the camera + * sensor + * + * \return 0 on success or a negative error code otherwise + */ +int CameraSensor::setTestPatternMode(int32_t testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + const CameraSensorProperties *props = CameraSensorProperties::get(model_); + if (!props) + return -EINVAL; + + auto it = props->testPatternModes.find(testPatternMode); + ASSERT(it != props->testPatternModes.end()); + + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, it->second); + + int ret = setControls(&ctrls); + if (ret) + return ret; + + testPatternMode_ = testPatternMode; + + return 0; +} + /** * \brief Retrieve the best sensor format for a desired output * \param[in] mbusCodes The list of acceptable media bus codes