From patchwork Mon Dec 16 09:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 22342 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 3B3B6C32F9 for ; Mon, 16 Dec 2024 09:49:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D40C767F4B; Mon, 16 Dec 2024 10:49:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="b66yOzdm"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB1F567F37 for ; Mon, 16 Dec 2024 10:49:47 +0100 (CET) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:c11a:e451:861f:3d32]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 25B0713C; Mon, 16 Dec 2024 10:49:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1734342551; bh=3X1l0S7FU7rnri+PjbJnCb/fhBaoVVV92NksVAM+Vag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b66yOzdm/x9LtN0mM/eD6Ozv7G7p/zNhYN7uGFVf8MAZTOXXXVjsMETcm2CSl1heD 7xKCBJLPJNVc5rYk27OZYiT6DNL3d+mOXc6+s9IbTHyuqHyiC2meo/k2xH2a7A301G eCj7k6XeZnXBly78+sBDk+Ls1Eb0PMGkFETVP374= From: Paul Elder To: libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com, stefan.klug@ideasonboard.com Cc: Paul Elder Subject: [PATCH v2 2/2] ipa: rkisp1: Add Lux algorithm module Date: Mon, 16 Dec 2024 18:49:33 +0900 Message-Id: <20241216094933.198027-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241216094933.198027-1-paul.elder@ideasonboard.com> References: <20241216094933.198027-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 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" Add a lux algorithm module to rkisp1 IPA for estimating the lux level of an image. This is reported in metadata, as well as saved in the frame context so that other algorithms (mainly AGC) can use its value. It does not set any controls. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham --- Changes in v2: - fix bitrot - fixes corresponding to changes in the previous patch --- src/ipa/rkisp1/algorithms/lux.cpp | 76 +++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/lux.h | 39 ++++++++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/ipa_context.h | 1 + 4 files changed, 117 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/lux.cpp create mode 100644 src/ipa/rkisp1/algorithms/lux.h diff --git a/src/ipa/rkisp1/algorithms/lux.cpp b/src/ipa/rkisp1/algorithms/lux.cpp new file mode 100644 index 000000000000..333167b15f64 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/lux.cpp @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas On Board + * + * lux.cpp - RkISP1 Lux control + */ + +#include "lux.h" + +#include +#include + +#include + +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "libipa/histogram.h" +#include "libipa/lux.h" + +/** + * \file lux.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class Lux + * \brief RkISP1 Lux control + * + * The Lux algorithm is responsible for estimating the lux level of the image. + * It doesn't take or generate any controls, but it provides a lux level for + * other algorithms (such as AGC) to use. + */ + +LOG_DEFINE_CATEGORY(RkISP1Lux) + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) +{ + lux_.setBinSize(65535); + return lux_.readYaml(tuningData); +} + +/** + * \copydoc libcamera::ipa::Algorithm::process + */ +void Lux::process(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + const rkisp1_stat_buffer *stats, + ControlList &metadata) +{ + utils::Duration exposureTime = context.configuration.sensor.lineDuration + * frameContext.sensor.exposure; + double gain = frameContext.sensor.gain; + + const rkisp1_cif_isp_stat *params = &stats->params; + Histogram yHist({ params->hist.hist_bins, context.hw->numHistogramBins }, + [](uint32_t x) { return x >> 4; }); + + double lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist); + frameContext.agc.lux = lux; + metadata.set(controls::Lux, lux); +} + +REGISTER_IPA_ALGORITHM(Lux, "Lux") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/lux.h b/src/ipa/rkisp1/algorithms/lux.h new file mode 100644 index 000000000000..ea98c29120eb --- /dev/null +++ b/src/ipa/rkisp1/algorithms/lux.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas On Board + * + * lux.h - RkISP1 Lux control + */ + +#pragma once + +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "libipa/lux.h" + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class Lux : public Algorithm +{ +public: + Lux() = default; + ~Lux() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void process(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const rkisp1_stat_buffer *stats, + ControlList &metadata) override; + +private: + ipa::Lux lux_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 1734a6675f78..c66b0b70b82f 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -12,4 +12,5 @@ rkisp1_ipa_algorithms = files([ 'goc.cpp', 'gsl.cpp', 'lsc.cpp', + 'lux.cpp', ]) diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index deb8c196f1b8..e7bdc51bfa4c 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -130,6 +130,7 @@ struct IPAFrameContext : public FrameContext { controls::AeMeteringModeEnum meteringMode; utils::Duration maxFrameDuration; bool updateMetering; + double lux; } agc; struct {