From patchwork Tue Aug 16 05:31:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17137 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 09462C3272 for ; Tue, 16 Aug 2022 05:31:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ABFA961FC0; Tue, 16 Aug 2022 07:31:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660627894; bh=arLGGRczZwQIDsYmTtxFShV4WKy8weslHHHnXpAj8d0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dX9dAeo04gDFqwqi3pxD5p0kieLg2H6u5RALHj0PbfSzlevqoacxgNR9uT6WcVgUm 8qXhuVvVrMV0uFtaHE7VsZ0xSRp7NyZfFFcfDODapXyYg80gDfWdVClnPgRT4pqijG yiMgXi7w1gvGdHGbGcONVTjNGAjsb8FoXA7okFWp3iH1aGVAt46urTMozcjKaAueB7 aQT0L8kgGfpX8xygnbfllYLtGJ7ofA00k6gwhUMzHL3PRhtB/slo5dgwTbtncnheWT TEn8cXhTo26BPq15gVdJ+7jZRl226X0IcxC8aJpJJ7tgz7GcbE/o/o8OObDR/MTHF2 B9WT39kyQMB5g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B69DC603E3 for ; Tue, 16 Aug 2022 07:31:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ThqdmoY7"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 90DA2496; Tue, 16 Aug 2022 07:31:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660627892; bh=arLGGRczZwQIDsYmTtxFShV4WKy8weslHHHnXpAj8d0=; h=From:To:Cc:Subject:Date:From; b=ThqdmoY74XbccID4IqIz3KcxyvulK+jjw4clL7Btt0wyIu+fODkDgNqgFPd3OabCV pPWE3tIRGnRoIRqEOATPGGLNNeGx4cGDQQ8H9q9xY0x4GC/puaq7e0/1dz/6Nu0Itk LHmfiJkuhWZ5+Y1qsdqA8BGu7pQE7BiXs9G/8qYg= To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Aug 2022 14:31:23 +0900 Message-Id: <20220816053123.1100015-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: rkisp1: Add manual color gains 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for manually controlling the color gains on the rkisp1 IPA. To that end, add and plumb the AwbEnable and ColourGains controls. As per-frame controls aren't supported yet in the rkisp1 IPA, simply apply and perform checks on the controls immediately. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- src/ipa/rkisp1/algorithms/awb.cpp | 36 +++++++++++++++++++++++++++++-- src/ipa/rkisp1/algorithms/awb.h | 3 +++ src/ipa/rkisp1/ipa_context.h | 1 + src/ipa/rkisp1/rkisp1.cpp | 6 ++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 9f00364d..dcb4b2c9 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -12,6 +12,7 @@ #include +#include #include /** @@ -38,6 +39,7 @@ int Awb::configure(IPAContext &context, context.frameContext.awb.gains.red = 1.0; context.frameContext.awb.gains.blue = 1.0; context.frameContext.awb.gains.green = 1.0; + context.frameContext.awb.enabled = true; /* * Define the measurement window for AWB as a centered rectangle @@ -116,6 +118,34 @@ void Awb::prepare(IPAContext &context, rkisp1_params_cfg *params) params->module_ens |= RKISP1_CIF_ISP_MODULE_AWB; } +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Awb::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + auto &awb = context.frameContext.awb; + + const auto &awbEnable = controls.get(controls::AwbEnable); + if (awbEnable) { + awb.enabled = *awbEnable; + + LOG(RkISP1Awb, Debug) + << (*awbEnable ? "Enabling" : "Disabling") << " AWB"; + } + + const auto &colourGains = controls.get(controls::ColourGains); + if (colourGains && !awb.enabled) { + awb.gains.red = (*colourGains)[0]; + awb.gains.blue = (*colourGains)[1]; + + LOG(RkISP1Awb, Debug) + << "Set colour gains to red: " << (*colourGains)[0] + << " blue: " << (*colourGains)[1]; + } +} + /** * \copydoc libcamera::ipa::Algorithm::process */ @@ -164,8 +194,10 @@ void Awb::process([[maybe_unused]] IPAContext &context, * Gain values are unsigned integer value, range 0 to 4 with 8 bit * fractional part. */ - frameContext.awb.gains.red = std::clamp(redGain, 0.0, 1023.0 / 256); - frameContext.awb.gains.blue = std::clamp(blueGain, 0.0, 1023.0 / 256); + if (frameContext.awb.enabled) { + frameContext.awb.gains.red = std::clamp(redGain, 0.0, 1023.0 / 256); + frameContext.awb.gains.blue = std::clamp(blueGain, 0.0, 1023.0 / 256); + } /* Hardcode the green gain to 1.0. */ frameContext.awb.gains.green = 1.0; diff --git a/src/ipa/rkisp1/algorithms/awb.h b/src/ipa/rkisp1/algorithms/awb.h index 667a8beb..4332fac7 100644 --- a/src/ipa/rkisp1/algorithms/awb.h +++ b/src/ipa/rkisp1/algorithms/awb.h @@ -21,6 +21,9 @@ public: int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + void queueRequest(IPAContext &context, + const uint32_t frame, + const ControlList &controls); void process(IPAContext &context, IPAFrameContext *frameCtx, const rkisp1_stat_buffer *stats) override; diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 2bdb6a81..fe258b2e 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -55,6 +55,7 @@ struct IPAFrameContext { } gains; double temperatureK; + bool enabled; } awb; struct { diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 17d42d38..55752988 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -89,9 +89,15 @@ private: namespace { +std::array minColourGains = { 0.0f, 0.0f }; +std::array maxColourGains = { 3.996f, 3.996f }; + /* List of controls handled by the RkISP1 IPA */ const ControlInfoMap::Map rkisp1Controls{ { &controls::AeEnable, ControlInfo(false, true) }, + { &controls::AwbEnable, ControlInfo(false, true) }, + { &controls::ColourGains, ControlInfo(Span(minColourGains), + Span(maxColourGains)) }, { &controls::Brightness, ControlInfo(-1.0f, 0.993f) }, { &controls::Contrast, ControlInfo(0.0f, 1.993f) }, { &controls::Saturation, ControlInfo(0.0f, 1.993f) },