[{"id":25521,"web_url":"https://patchwork.libcamera.org/comment/25521/","msgid":"<20221021070439.GO3874866@pyrite.rasen.tech>","date":"2022-10-21T07:04:39","subject":"Re: [libcamera-devel] [PATCH v2 2/3] ipa: rkisp1: Fill AGC and AWB\n\tmetadata","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"On Wed, Oct 19, 2022 at 11:56:13PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> Fill the frame metadata in the AGC and AWB algorithm's prepare()\n\ns/prepare/process/\n\n> function. Additional metadata for other algorithms will be addressed\n> later.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n> Changes since v1:\n> \n> - Report the ColourTemperature and FrameDuration controls as well\n> ---\n>  src/ipa/rkisp1/algorithms/agc.cpp | 15 ++++++++++++++-\n>  src/ipa/rkisp1/algorithms/awb.cpp |  9 ++++++++-\n>  src/ipa/rkisp1/ipa_context.cpp    |  3 +++\n>  src/ipa/rkisp1/ipa_context.h      |  1 +\n>  src/ipa/rkisp1/rkisp1.cpp         |  2 ++\n>  5 files changed, 28 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index 37cd10f9b302..b4fc7aed4d9d 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -14,6 +14,7 @@\n>  #include <libcamera/base/log.h>\n>  #include <libcamera/base/utils.h>\n>  \n> +#include <libcamera/control_ids.h>\n>  #include <libcamera/ipa/core_ipa_interface.h>\n>  \n>  #include \"libipa/histogram.h\"\n> @@ -290,7 +291,7 @@ double Agc::measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const\n>   */\n>  void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>  \t\t  IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats,\n> -\t\t  [[maybe_unused]] ControlList &metadata)\n> +\t\t  ControlList &metadata)\n>  {\n>  \t/*\n>  \t * \\todo Verify that the exposure and gain applied by the sensor for\n> @@ -333,6 +334,18 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>  \n>  \tcomputeExposure(context, frameContext, yGain, iqMeanGain);\n>  \tframeCount_++;\n> +\n> +\tutils::Duration exposureTime = context.configuration.sensor.lineDuration\n> +\t\t\t\t     * frameContext.sensor.exposure;\n> +\tmetadata.set(controls::AnalogueGain, frameContext.sensor.gain);\n> +\tmetadata.set(controls::ExposureTime, exposureTime.get<std::micro>());\n> +\n> +\t/* \\todo Use VBlank value calculated from each frame exposure. */\n> +\tuint32_t vTotal = context.configuration.sensor.size.height\n> +\t\t\t+ context.configuration.sensor.defVBlank;\n> +\tutils::Duration frameDuration = context.configuration.sensor.lineDuration\n> +\t\t\t\t      * vTotal;\n> +\tmetadata.set(controls::FrameDuration, frameDuration.get<std::micro>());\n>  }\n>  \n>  /**\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index f597ded800c2..083c2d982c52 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -209,7 +209,7 @@ void Awb::process(IPAContext &context,\n>  \t\t  [[maybe_unused]] const uint32_t frame,\n>  \t\t  IPAFrameContext &frameContext,\n>  \t\t  const rkisp1_stat_buffer *stats,\n> -\t\t  [[maybe_unused]] ControlList &metadata)\n> +\t\t  ControlList &metadata)\n>  {\n>  \tconst rkisp1_cif_isp_stat *params = &stats->params;\n>  \tconst rkisp1_cif_isp_awb_stat *awb = &params->awb;\n> @@ -307,6 +307,13 @@ void Awb::process(IPAContext &context,\n>  \n>  \tframeContext.awb.temperatureK = activeState.awb.temperatureK;\n>  \n> +\tmetadata.set(controls::AwbEnable, frameContext.awb.autoEnabled);\n> +\tmetadata.set(controls::ColourGains, {\n> +\t\t\tstatic_cast<float>(frameContext.awb.gains.red),\n> +\t\t\tstatic_cast<float>(frameContext.awb.gains.blue)\n> +\t\t});\n> +\tmetadata.set(controls::ColourTemperature, frameContext.awb.temperatureK);\n> +\n>  \tLOG(RkISP1Awb, Debug) << std::showpoint\n>  \t\t<< \"Means [\" << redMean << \", \" << greenMean << \", \" << blueMean\n>  \t\t<< \"], gains [\" << activeState.awb.gains.automatic.red << \", \"\n> diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\n> index b00dc29c1713..3c14cf3476ce 100644\n> --- a/src/ipa/rkisp1/ipa_context.cpp\n> +++ b/src/ipa/rkisp1/ipa_context.cpp\n> @@ -77,6 +77,9 @@ namespace libcamera::ipa::rkisp1 {\n>   * \\var IPASessionConfiguration::sensor\n>   * \\brief Sensor-specific configuration of the IPA\n>   *\n> + * \\var IPASessionConfiguration::sensor.defVBlank\n> + * \\brief The default vblank value of the sensor\n> + *\n>   * \\var IPASessionConfiguration::sensor.lineDuration\n>   * \\brief Line duration in microseconds\n>   *\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index c85d8abeca71..60e8a7e11196 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -39,6 +39,7 @@ struct IPASessionConfiguration {\n>  \t} lsc;\n>  \n>  \tstruct {\n> +\t\tint32_t defVBlank;\n>  \t\tutils::Duration lineDuration;\n>  \t\tSize size;\n>  \t} sensor;\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 494d8c891509..069c901bb141 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -244,6 +244,8 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info,\n>  \t/* Set the hardware revision for the algorithms. */\n>  \tcontext_.configuration.hw.revision = hwRevision_;\n>  \n> +\tconst ControlInfo vBlank = ctrls_.find(V4L2_CID_VBLANK)->second;\n> +\tcontext_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>();\n>  \tcontext_.configuration.sensor.size = info.outputSize;\n>  \tcontext_.configuration.sensor.lineDuration = info.minLineLength * 1.0s / info.pixelRate;\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0DD62BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 21 Oct 2022 07:04:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6E3B762EBB;\n\tFri, 21 Oct 2022 09:04:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4BCBF604E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Oct 2022 09:04:48 +0200 (CEST)","from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BADCEEE6;\n\tFri, 21 Oct 2022 09:04:46 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666335890;\n\tbh=V8KeJImtxOJvF0gZFIYyxq2JPA7vNNplwAzVfyhmQrE=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=TWmOmvc9PrS7hHvoyLg4/f/9lU04lT8ni9CqikFiW1QH+dZrhTIYEAd72s5qgNsyz\n\tPYYhQkYoFDCQu4UsPZ1Eu1yM0546I7ZD9Yz2QzKvqNMMwZV8RzdEwJZ3ommitZLqv4\n\tw5AZK6340Jmhlz5TZIpB9hXynGAo5YffdqzOanybHXQPIaiT+z28r845Rx7IE/Xo9B\n\tMMSj8BfPrbW0r2Cr1RGAiwFd8PyqgxvXLqgngXC6WBtoKvF5+ixXFJxd30HsElmq9z\n\tPsg6UmsYaqAHabfKr/3RFih9hFiwmgHMFMdrHcavp8LGdIpcy60375aURUphkuOkkJ\n\tmoQTmlCn2UVvg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666335887;\n\tbh=V8KeJImtxOJvF0gZFIYyxq2JPA7vNNplwAzVfyhmQrE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IeSYyeAsiqrAHj1pUTbMGfB6gf6Ezpf+DZFLweklhZ2/2aE4+cJ0Ed6AJjSWw8V3u\n\tCyMX/69iR1/Oeda2lSq9Lwl000unPhatoBmHy0YZF2KBFxjcYMzbpq5GpTYxG2VVKu\n\t637NHi3hz8NvEU6OAGOxH1r9yAFy/EvmFaKDEkCg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"IeSYyeAs\"; dkim-atps=neutral","Date":"Fri, 21 Oct 2022 16:04:39 +0900","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20221021070439.GO3874866@pyrite.rasen.tech>","References":"<20221019205614.25751-1-laurent.pinchart@ideasonboard.com>\n\t<20221019205614.25751-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20221019205614.25751-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 2/3] ipa: rkisp1: Fill AGC and AWB\n\tmetadata","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]