From patchwork Mon Feb 8 15:07:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11194 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 E1211BD160 for ; Mon, 8 Feb 2021 15:08:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AFD3F60D2D; Mon, 8 Feb 2021 16:08:13 +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="g70WEax7"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AE8860D2D for ; Mon, 8 Feb 2021 16:08:12 +0100 (CET) Received: by mail-wm1-x334.google.com with SMTP id o24so5816737wmh.5 for ; Mon, 08 Feb 2021 07:08:12 -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=KHB2EKmGz+hGJNbn8Yl7NuwoNezMZZa7kmvh9ntqrA0=; b=g70WEax7RWFeh8eOumjUKGhZJVzWxqenlLMQk6lzTJqK3H/xaRlvAq1ntltQaZ9U5x Z0SzFa8OZ0+A58aEvdVlpQtB+bBxJn9UfBfPcqkaO5SBcJpIP17AgIJW1A0vjznKsnyJ zr+4coTTERkBgnFxr9Dc0L4vNTN+vcbgu3AtR2TVjNGC3vYFCzusrRoqO8Qs92phxpnd ybxunRdn1VJT658IubxXrA83JzEQSZqVYqmbsebGytYqgfoftNSx43CCla9Tiwk6D/YF oz/enBR2FIhqpLifIRQeNiA1Thsiu3/9fUJ2Zil7hxgUMGnzK/y1ncYChoF5GOYuaQhM aLvA== 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=KHB2EKmGz+hGJNbn8Yl7NuwoNezMZZa7kmvh9ntqrA0=; b=DFd6qqEkInDEHgkzM8N2LZBxZk002bgMptR3F36E1uvfdp9g95jc73RK1L+gl2IuJH mtRzkfRqbNi3JV3O8DtXEh11ocp5uwW6g1E/Q0CwRx4/imi57zoQE0q0ub3c9szQhLdD lI/+ww1093FN+yWBDhkTN3m7TfFpbwoSPDtpjO8s9rMnTzDAOlxJmFdTRbqTOxWKfpah B6AG9E8RlirPOCxRKJT2IJOhaAdo65PVSRCDBS3h1jhaz8mBTwdJKsgAQtGJ4UlhtOBk TQOJxEzM+Uzk87KceAKphdc2V66Dmd3R5G5MyKf1JamvDmDBquJg7ZixCtfHNXKlH0Xj n26w== X-Gm-Message-State: AOAM533t7EI8uh/Rj+tyO7W7Vr33gYDoYpj4cmAlC2f4b7pHNx6HOnW4 OHnmOvT3q4qPqwYEAWp2PUKZzWzhZvERgvYG X-Google-Smtp-Source: ABdhPJw7HxlbPGXkDZr3Aj35UM/MVV5iZZA0NGzJf5ZGEW164FdG1LELaWyKOxy/hLkiqkUiWjnw8g== X-Received: by 2002:a1c:e90d:: with SMTP id q13mr14919707wmc.136.1612796891643; Mon, 08 Feb 2021 07:08:11 -0800 (PST) Received: from naush-laptop.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id a17sm31261389wrx.63.2021.02.08.07.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 07:08:10 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 15:07:38 +0000 Message-Id: <20210208150738.2293520-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210208150738.2293520-1-naush@raspberrypi.com> References: <20210208150738.2293520-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 6/6] ipa: raspberrypi: Handle control::NoiseReductionMode in the controller 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 application provided noise reduction mode gets passed into the denoise controller. The denoise controller in turn returns the mode to the IPA which now sets up the colour denoise processing appropriately. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Naushir Patuck --- include/libcamera/ipa/raspberrypi.h | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 57 ++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index d333c2edfa53..ee673a4651a6 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -76,6 +76,7 @@ static const ControlInfoMap Controls = { { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, { &controls::FrameDurations, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, + { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, }; } /* namespace RPi */ diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index e76688a7b323..ef8b19baa754 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -43,6 +43,7 @@ #include "contrast_algorithm.hpp" #include "contrast_status.h" #include "controller.hpp" +#include "denoise_algorithm.hpp" #include "denoise_status.h" #include "dpc_status.h" #include "focus_status.h" @@ -573,6 +574,7 @@ bool IPARPi::validateIspControls() V4L2_CID_USER_BCM2835_ISP_SHARPEN, V4L2_CID_USER_BCM2835_ISP_DPC, V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, + V4L2_CID_USER_BCM2835_ISP_CDN, }; for (auto c : ctrls) { @@ -622,6 +624,14 @@ static const std::map AwbModeTable = { { controls::AwbCustom, "custom" }, }; +static const std::map DenoiseModeTable = { + { controls::draft::NoiseReductionModeOff, RPiController::DenoiseMode::Off }, + { controls::draft::NoiseReductionModeFast, RPiController::DenoiseMode::ColourFast }, + { controls::draft::NoiseReductionModeHighQuality, RPiController::DenoiseMode::ColourHighQuality }, + { controls::draft::NoiseReductionModeMinimal, RPiController::DenoiseMode::ColourOff }, + { controls::draft::NoiseReductionModeZSL, RPiController::DenoiseMode::ColourHighQuality }, +}; + void IPARPi::queueRequest(const ControlList &controls) { /* Clear the return metadata buffer. */ @@ -889,6 +899,29 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::NOISE_REDUCTION_MODE: { + RPiController::DenoiseAlgorithm *sdn = dynamic_cast( + controller_.GetAlgorithm("SDN")); + ASSERT(sdn); + + int32_t idx = ctrl.second.get(); + auto mode = DenoiseModeTable.find(idx); + if (mode != DenoiseModeTable.end()) { + sdn->SetMode(mode->second); + + /* + * \todo If the colour denoise is not going to run due to an + * analysis image resolution or format mismatch, we should + * report the status correctly in the metadata. + */ + libcameraMetadata_.set(controls::draft::NoiseReductionMode, idx); + } else { + LOG(IPARPI, Error) << "Noise reduction mode " << idx + << " not recognised"; + } + break; + } + default: LOG(IPARPI, Warning) << "Ctrl " << controls::controls.at(ctrl.first)->name() @@ -1173,18 +1206,40 @@ void IPARPi::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls) void IPARPi::applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList &ctrls) { + using RPiController::DenoiseMode; + bcm2835_isp_denoise denoise; + DenoiseMode mode = static_cast(denoiseStatus->mode); - denoise.enabled = 1; + denoise.enabled = mode != DenoiseMode::Off; denoise.constant = denoiseStatus->noise_constant; denoise.slope.num = 1000 * denoiseStatus->noise_slope; denoise.slope.den = 1000; denoise.strength.num = 1000 * denoiseStatus->strength; denoise.strength.den = 1000; + /* Set the CDN mode to match the SDN operating mode. */ + bcm2835_isp_cdn cdn; + switch (mode) { + case DenoiseMode::ColourFast: + cdn.enabled = 1; + cdn.mode = CDN_MODE_FAST; + break; + case DenoiseMode::ColourHighQuality: + cdn.enabled = 1; + cdn.mode = CDN_MODE_HIGH_QUALITY; + break; + default: + cdn.enabled = 0; + } + ControlValue c(Span{ reinterpret_cast(&denoise), sizeof(denoise) }); ctrls.set(V4L2_CID_USER_BCM2835_ISP_DENOISE, c); + + c = ControlValue(Span{ reinterpret_cast(&cdn), + sizeof(cdn) }); + ctrls.set(V4L2_CID_USER_BCM2835_ISP_CDN, c); } void IPARPi::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls)