From patchwork Mon Oct 4 06:58:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14033 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 88D16BDC71 for ; Mon, 4 Oct 2021 06:59:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 23CD8691B9; Mon, 4 Oct 2021 08:59:07 +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="RJfDEX+E"; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E98F96023E for ; Mon, 4 Oct 2021 08:59:05 +0200 (CEST) Received: by mail-pl1-x62e.google.com with SMTP id w14so1111453pll.2 for ; Sun, 03 Oct 2021 23:59:05 -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:mime-version :content-transfer-encoding; bh=xQmaGeXiHTrah0AUxYVVDTLlXk3afoDbyWp6LDdsmaY=; b=RJfDEX+EQRLa9v37Wol7pcHbxdoL4KX+B7Fx1oYjRgs4+JOSikebL0H5Y57Cw/BD98 xcFsOYy5Bsv6SoFAyfQrfc6JdiwE48bCZn+Fey0Bs1AdCXPIhQtPNjF7Hde3JLCQu4Hg HCjgfWGk+QQ8zu2yN/y8Y3l5gjzUaSK46Zr3s= 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=xQmaGeXiHTrah0AUxYVVDTLlXk3afoDbyWp6LDdsmaY=; b=aMlzAeIBgnDtJLDsDqVcKiFodvZcq7fxffat7bvykPIUp3eq+OHNj4gm7qsB4uTz3S SWumENyC+YIh8DWrHSXkhi8B9EI0HFVvnDtO3Dm7ptBWzTTsJ8zUv1iIIClRZ+Kz3pCx MRqnJjGhSsk7014K8u7Dgn0pbEgmCDX6LrGh/tDRdu4kGCmiwGR8HDTAq+A6Y3XEBOUe hxk4PhxhIztkRBRjAAG0+cGlvIWNXi4Hrai6Fkvj1UtJE5O3zG8fQLcUrQGV2FHPUuP/ lSCUKfzk4qkzilYOKIsUJg2Z33YcJsbtgLGVbqySDrFYFK159XB/dU8zq07YD68JtxM6 yObA== X-Gm-Message-State: AOAM532M+yWb99dVFxetzgjCabHKOLxUuiKr2xTawPp0+i8jXLshBzrS cOnYWEgfUP+jmEIWNc4HrhSbit+n+FDvug== X-Google-Smtp-Source: ABdhPJwO8b6ntMqMu8Jr856ujwq9B7yJCcL2FuqV4tsW4djjQ8MNHCWUX11xKkAVUaVgX2KaG4CAuw== X-Received: by 2002:a17:902:dacf:b0:13e:ab53:87dc with SMTP id q15-20020a170902dacf00b0013eab5387dcmr8020872plx.78.1633330743715; Sun, 03 Oct 2021 23:59:03 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:15ef:e4fd:2730:ca53]) by smtp.gmail.com with ESMTPSA id l10sm12899336pff.119.2021.10.03.23.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 23:59:03 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 4 Oct 2021 15:58:56 +0900 Message-Id: <20211004065856.3512141-1-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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 | 52 +++++++++++----------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 87668509..e5844c04 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 39bb282d..48305ac4 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 { "hi846", { .unitCellSize = { 1120, 1120 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 1, controls::draft::TestPatternModeSolidColor }, - { 2, controls::draft::TestPatternModeColorBars }, - { 3, controls::draft::TestPatternModeColorBarsFadeToGray }, - { 4, controls::draft::TestPatternModePn9 }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeSolidColor, 1 }, + { controls::draft::TestPatternModeColorBars, 2 }, + { controls::draft::TestPatternModeColorBarsFadeToGray, 3 }, + { controls::draft::TestPatternModePn9, 4 }, /* * No corresponding test pattern mode for: * 5: "Gradient Horizontal" @@ -73,21 +73,21 @@ 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", { .unitCellSize = { 1120, 1120 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 1, controls::draft::TestPatternModeSolidColor }, - { 2, controls::draft::TestPatternModeColorBars }, - { 3, controls::draft::TestPatternModeColorBarsFadeToGray }, - { 4, controls::draft::TestPatternModePn9 }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeSolidColor, 1 }, + { controls::draft::TestPatternModeColorBars, 2 }, + { controls::draft::TestPatternModeColorBarsFadeToGray, 3 }, + { controls::draft::TestPatternModePn9, 4 }, }, } }, { "ov5647", { @@ -97,15 +97,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 }, }, } }, { "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 @@ -116,8 +116,8 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen { "ov8865", { .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" @@ -130,8 +130,8 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen { "ov13858", { .unitCellSize = { 1120, 1120 }, .testPatternModes = { - { 0, controls::draft::TestPatternModeOff }, - { 1, controls::draft::TestPatternModeColorBars }, + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeColorBars, 1 }, }, } }, };