From patchwork Fri Jan 29 15:11:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11066 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 BB325BD808 for ; Fri, 29 Jan 2021 15:12:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8C191683C0; Fri, 29 Jan 2021 16:12:08 +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="rXa9LedQ"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D4637683B5 for ; Fri, 29 Jan 2021 16:12:06 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id f16so7093987wmq.5 for ; Fri, 29 Jan 2021 07:12:06 -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=LmT4odllwsOAcspD1V4FNjd+YRe6YykQ2WFPVm9Zw2Y=; b=rXa9LedQ2IYmeIAbrEpK/MCTPh8oDLIqnWyXTFV/kCOsu3Qaa8WNHJmJvK2NeuEACc 0D7XByR2/FCp/SXZAEduo4GC/uOavtLa4AMHcZsw19dZdpGMF5+8TUeiVeC6GPwpwxUu xYjDfpUv/5Oy96gZ1zrSsVQZjMUGV5UL78IpdTz9BoS9xtfM3c1b+ZqIdxObH3a7VjOD IYpi+9+kGvN9OIb6o1sbTiASHc/9TgZ/r+nltwnmzOCOayftoFOuF1bR7qehWAgCgFbe UfmOHN2QT2IIFSqlN0gaJob87RDJCW4H3m9jTGfeWjhKMI8So4rKDe5tovP293Etz/wB pTAQ== 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=LmT4odllwsOAcspD1V4FNjd+YRe6YykQ2WFPVm9Zw2Y=; b=Tw4lW+VCp1EzPWph3TEFnx92NF8QEIm0EIy+wT11CcTajuHWdIbqIEfd7wnvQ07KUc rBlgw3BzGchpgccCgQi9Jmcb3kUaC/bESXMSFYf8gp3Lcn3x0CJEVniyK7x31rP9AA/Z KM5jFQDAG4/StQbBqLqMbX9RXjGTwhOcQm9vAfNoe2c9KeD+0NVNS2ZwjNuc6ihVL6St nDVPCVUb0E310CXrL/smAJVyjiDTqDKrAN0DYMdYsSkmJzAtC/OH3RFzyvMTaFLB6j/b gILr4dU/CqWnEFVqQO7HSYexWdPL36A2Cm37rx3xU/z0IU1eFGzPj2OC3977pNmAEgkR +u2g== X-Gm-Message-State: AOAM530uWCbBOacGKzHvjcGKwqgTvDI4n6Qy9mnUdf6Vo8bOK/CPMgeQ 8li/YChBOd2yuTHG6s5l/hr1k3Hld7mDgUKz X-Google-Smtp-Source: ABdhPJyvAdQC1C7oF4PnFc4fj3r9hGZXDOC4oSlUupZCnVzeZO1Heg1EpyRKpYOaRBEqbW19fcqZxg== X-Received: by 2002:a7b:c246:: with SMTP id b6mr4340791wmj.118.1611933126297; Fri, 29 Jan 2021 07:12:06 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id f13sm6517461wmf.1.2021.01.29.07.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 07:12:05 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 29 Jan 2021 15:11:54 +0000 Message-Id: <20210129151154.1051163-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210129151154.1051163-1-naush@raspberrypi.com> References: <20210129151154.1051163-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 --- include/libcamera/ipa/raspberrypi.h | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 51 ++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index 1de36039cee0..3be79fc5ed73 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -66,6 +66,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(1000, 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 220cf174aa4f..862c52bde082 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" @@ -565,6 +566,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) { @@ -614,6 +616,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. */ @@ -836,6 +846,23 @@ 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); + 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() @@ -1085,18 +1112,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)